Jump to content
  • Advertisement
Sign in to follow this  

shader vertex inputs calculations

This topic is 2072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know that in vertex shader 2.0 and 3.0 there might be max 256 inputs (each float4 type). So we might introduce 4x256=1024 float data into vertex shader. I have two questions?

1.) How much texture input use float data?

2.) I am able to allocate 1039 floats, please see below my calculations and I don't see anything wrong in my application. However when I add one float4 more  (introduce matrix F[61] insetad of F[60]) then I see that it doesn't work as expected.

So maybe there are max 260 (1040 floats) vertex shader registers not 256???


My vertex shader inputs:

uniform extern float4x4 MatWorld;  //16 floats
uniform extern float4x4 MatWorldInvTrans;  //32 floats use till now
uniform extern float4x4 MatWVP; //48 floats use till now
uniform extern float4x4 F[60]; //60*4*4+12 = 960+48=1008 floats use till now
uniform extern float3 toCam; //1011

struct Mtrl
float4 Ambient; //1015
float4 Diffuse; //1019
float4 Specular; //1023
float Power; //1024
struct LightStr
float4 Ambient; //1028
float4 Diffuse; //1032
float4 Specular; //1036
float3 Direction; //1039

uniform extern Mtrl mtrl;
uniform extern LightStr lightStr;

uniform extern texture textura; //probably also uses some data however I don't know how much
sampler Sampl = sampler_state
Texture = <textura>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;


Share this post

Link to post
Share on other sites

Haven't done DX9 in years, but -

256 is the minimum requirements. You can call GetCaps() and check the value of MaxVertexShaderConst to get the actual number of registers your GPU supports.


Also note that there are some alignment issues. LightStr::Direction will actually take space of 4 floats, as well as Mtrl::Power - each register is 4 floats, regardless of the actual data type used. You need to count registers, not floats.


Textures do not consume CB registers, they have their own register-set.


[EDIT] - This is the SM4.0 HLSL constant buffer packing rules. I see no reason why DX9 HLSL packing rules should be different.

Edited by N.I.B.

Share this post

Link to post
Share on other sites

The DX9 rules for packing are the same, the runtime will try to pack all it can into a single float4 but it will not be smart about this, if the constant doesn't fit in the previous float4 it will start a new one. This is why you often stuff certain data in the w component of other vectors when they arent needed.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!