Jump to content


constant buffers direct x 11


3 replies to this topic

#1 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2725 posts

Posted 11 May 2012 - 07:45 AM

for some reason

struct CB0
{
VEC brush_pos;
float brush_radius;
MAT wvp;
MAT view;
float zoff;
VEC col;
VEC chunk_pos;
float tex_size;
};

(system struct)

doesnt match up with

cbuffer cb0 : register( b1 )
{
float3 brush_pos;
float brush_radius;
matrix wvp;
matrix view;
float zoff;
float3 col;
float3 chunk_pos;
float tex_size;
};

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)
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 11 May 2012 - 04:25 PM

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?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2725 posts

Posted 11 May 2012 - 05:28 PM

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.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#4 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2725 posts

Posted 11 May 2012 - 05:36 PM

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.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users