1
\$\begingroup\$

I have a simple HLSL shader with a few constant buffers, 1 of them holding an array of Light structs which causes my display driver to crash when the array size goes over 3.

Does anybody have an idea what causes my display driver to crash when MAX_LIGHTS is higher than 3? I don't believe I am exceeding the maximum allowed number of elements right? Which is supposed to be somewhere near 4096 elements). I also don't think I have set up my constant buffer wrong. It is a multiple of 16.

(I have excluded the other 3 constant buffers because these are not so interesting. They only contain world/view/proj matrices.)

I don't mind posting more code, if required.

#define MAX_LIGHTS 4 // Black Geometry / Crash
//#define MAX_LIGHTS 3 // Properly Shaded & Textured Geometry / No Crash

struct Light {

    // 16
    float4 lightPosition;

    // 32
    float4 lightDirection;

    // 48
    float4 lightColor;

    // 52
    float lightRange;

    // 56
    float lightIntensity;

    // 60
    float lightIsEnabled;

    // 64
    uint lightType;
};

cbuffer CBLights : register(b3) {
    Light lights[MAX_LIGHTS];
    uint numLights;
    float cbLightsPadding1;
    float cbLightsPadding2;
    float cbLightsPadding3;
};
\$\endgroup\$
4
  • \$\begingroup\$ did you try updatesubresource(CB, data), I would also use a shaderresourceview for you light buffer and set it up as a structured buffer not a CB. try setting it like this Light lights[4]; if you must use a CB. 4096 is the max size in bytes so you can have 1000 float4x4 or 4000 float4 \$\endgroup\$ Jan 7, 2017 at 1:09
  • \$\begingroup\$ Thanks for your comment. (Please check my edit) using UpdateResource() instead of Map() gives the same result (all objects are rendered in black). I will try your suggestion to use a structured buffer. I would still like to know the reason why all my objects are rendered in black though when I use over 3 lights. I'm currently debugging and will let everyone know when I find the cause. \$\endgroup\$ Jan 7, 2017 at 2:00
  • \$\begingroup\$ You should make an answer to your question and then start a new one about the black objects. Just to keep it all neat and stuff :) \$\endgroup\$ Jan 7, 2017 at 2:02
  • \$\begingroup\$ Thanks for noticing. I will do that next time. I found the solution to my problem (see my answer). \$\endgroup\$ Jan 7, 2017 at 3:51

1 Answer 1

1
\$\begingroup\$

The crash was because I did set numLights to an extremely large number by accident. However, I still had a similar problem; all my objects were rendered in black when I used > 3 lights. The geometry went black when the light array size (in bytes) went over 256.

The black geometry problem was caused by my c++ code. Somewhere I have a GetSize() function which returns the size of a constant buffer parameter as an uint8. So when the parameter size became larger than 256, it returned an incorrect value. Edited to return a uint16 type.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .