Jump to content

  • Log In with Google      Sign In   
  • Create Account


はとぶ

Member Since 23 Oct 2000
Offline Last Active Aug 15 2014 11:17 PM

Posts I've Made

In Topic: Using some ConstantBuffer values causing CreateShader to fail

18 August 2013 - 06:34 PM

In the end the problem was that I wasn't loading the compiled shader as a binary file, so, sometimes the file read was interrupted before the actual end, thus the CreateVertexShader() caused an E_INVALIDARG because the size of the vs data did not match the actual size of the shader.

 

dogh!...

 

anyways!... thanks for the help!


In Topic: Using some ConstantBuffer values causing CreateShader to fail

18 August 2013 - 10:56 AM

Thankyou MJP,

 

Didn't know about the debug layer until now, I think I better start from there!

 

thanks!


In Topic: Using some ConstantBuffer values causing CreateShader to fail

17 August 2013 - 08:38 PM

Thanks Juliean,

 

In this particular case I'm precompiling the shader (I'm targeting Win8, so no effects framework, etc), and then I'm loading the compiled data to my app.

 

However, the error is not at compile time (it compiles just fine), but at creation time when calling:

g_pDirect3D->CreateVertexShader( pVSData, vsSize, nullptr, &g_pVertexShader );

So it just doesn't make sense to me that by using "sin( value0 )"  the shader compiles, creates and runs without problems, but when using "sin( value1 )" the shader still compiles fine but cannot be created.

 

I just don't know what might be causing it unsure.png

 

 

thanks!


In Topic: constant buffer data layout mismatch between app/shader

17 August 2013 - 05:09 PM

just to complete the post (for anyone else who might run into the same problem and founds this post).

 

After making some experiments with the data layout, it looks like when using more then one data type whose length is less that 16-bytes, the GPU packs them into the same 16-byte "array".

 

What I mean is:

 

If you want to pass properly the data to a constant buffer like this in your shader:

buffer cbPerFrame : register (b0)
{
    float value1;
    float value2;
    float4x4 value3;
};

.

I first thought on giving each independent value a padding like this:

struct ConstantBuffer
{
    float value1;
    float value1_dummy[3];
    float value2;
    float value2_dummy[3];
    Matrix value3;
};

.

Expecting the GPU would read the data with a layout like this:

V1 xx xx xx
V2 xx xx xx
V3 V3 V3 V3
V3 V3 V3 V3
V3 V3 V3 V3
V3 V3 V3 V3

.

However, it turned out that what the GPU is expecting is something like this:

V1 V2 xx xx
V3 V3 V3 V3
V3 V3 V3 V3
V3 V3 V3 V3
V3 V3 V3 V3

.

So, you would have to write your C++ struct like this:

struct ConstantBuffer
{
    float value1;
    float value2;
    float value2_dummy[2];
    Matrix value3;
};

=)

 

just wanted to point it out if anyone runs into the same trouble =P

 

Cheers!


In Topic: constant buffer data layout mismatch between app/shader

17 August 2013 - 04:01 AM

Aahhh!... thankyou Hodgman, unbird.

 

yeah, it was the padding on the C++ struct the one causing all the trouble.

 

uhmmm... so I think I will need to find a nice way to force every variable in the C++ structure to be aligned to 16-bytes.

 

Thanks!


PARTNERS