rouncer at May 11th, 2012 03:45 — #1
for some reason
doesnt match up with
cbuffer cb0 : register( b1 )
in the shader... like it unaligns or something, what could cause this? (even though this example works, but sometimes when i add a variable all hell breaks loose)
reedbeta at May 11th, 2012 12:25 — #2
Yes, HLSL has specific rules for alignment of vector quantities in constant buffers, which can result in differing alignment to what you'd get in C/C++. This page explains the rules. Basically, you cannot split a vector (like a float3) across a 16-byte (4-float) boundary, so padding will be added to prevent this. You often have to add this padding to the C/C++ version of the struct yourself.
How are your VEC, MAT and "matrix" types defined?
rouncer at May 11th, 2012 13:28 — #3
ahhh thanks man! i was always troubled by this for a long time... i thought something screwy was going on.
VEC is the 3 component vector, and MAT is a 4x4... so i guess the 3 component vector was the strange one.
rouncer at May 11th, 2012 13:36 — #4
i get it, so you cant put two 3 component vectors in a row (sometimes), cause it crosses a 16 byte boundary... ? you can if it doesnt. if you look at the structure provided, youll see i havent crossed a boundary, just with naive trial and error, i see now.
thanks reed - you the man.