Tag Info

Hot answers tagged


Out of curiosity (and peace of the mind...) I wondered how DirectX decides which attribute from a struct corresponds to the right variable inside an HLSL cbuffer-register(x) (apart from the order/type they are declared with). Purely through memory layout. You give D3D a pointer to a chunk of memory which you claim to be organized in a certain ...


Non-array struct members for constant buffers in HLSL are packed on four byte offsets, as many as it can into 16-byte vectors. If a member would straddle a vector boundary, it starts a new vector. You cannot achieve this with just an alignment and pack directive, you need to have explicit padding in your CPU-side structure to emulate the CB layout rules. ...


Use several constant buffers and group variables together based on how often they change. If your variables are fairly static ( or just huge ) you may be better off converting values into a texture and extracting them in the shader.


There are additional alignment and layout rules for constant buffers. The float3 probably needs padding on the CPU side to get the right stride. Roughly paraphrased, things need to be on 16-byte boundaries.


My assumption based on my experiences with shader reflection in DX11 is that it's mapped by name. If you check out the DX11 shader reflection API you'll see that there is a D3D11_SHADER_VARIABLE_DESC struct that you can rip from the shader. Notice the LPCSTR for the name of the variable. OpenGL also handles variable mapping by name. Of course the best way ...


VSSetConstantBuffers stands for VertexShaderSetConstantBuffers. Hence you also got PSSetConstantBuffers for the pixel shader.


Since you override SpriteBatch's default effect with your own, you are now responsible for setting effect parameters, especially matrices. You probably would like to replicate default SpriteBatch behaviour, so set effect.World to identity, and for projection default SpriteBatch effect uses effect.Projection = Matrix.CreateTranslation(-0.5f, -0.5f, 0) * ...

Only top voted, non community-wiki answers of a minimum length are eligible