0
votes

I have an HLSL shader that is giving an unexpected error when I add a particular variable to a constant buffer. The entire shader is below. To rule everything out I included the entire shader.

The error occurs when I add the NewVariable to the third constant buffer.

I haven't found this in documentation, but can I not perform the following packing where a vector starts part-way into the c0 vector?

float1 var1 : packoffset( c0.x );
float3 var2 : packoffset( c0.yzw );

I get the poorly documented error X3530 (ERR_BIND_INVALID). MSDN says, "Invalid binding operation was performed. For example, buffers can only be bound to one slot or one constant offset; invalid register specification because a particular binding was expected but didn't occur; can't mix packoffset elements with nonpackoffset elements in a cbuffer." This error message really doesn't tell me what is wrong and the pack offset looks correct to me.

cbuffer SceneGlobals : register( b0 )
{
    int NumAmbientLights : packoffset( c0 );
    int NumDirectionalLights : packoffset( c0.y );
    int NumPointLights : packoffset( c0.z );
    int NumSpotLights : packoffset( c0.w );
}

cbuffer FrameGlobals : register( b1 )
{
    float Time : packoffset( c0 );
    float Timestep : packoffset( c0.y );
    int NumCameras : packoffset( c0.z );
    float4 CameraPosition[1] : packoffset( c1 );
    float4x4 CameraView[1] : packoffset( c2 );
    float4x4 CameraProjection[1] : packoffset( c6 );
    float4x4 CameraViewProjection[1] : packoffset( c10 );
}

cbuffer ObjectGlobals : register( b2 )
{
    int ActiveCamera : packoffset( c0 );
    int3 NewVariable : packoffset( c0.yzw ); // ERROR OCCURS HERE
}


struct InputStruct
{
    float4 Position : POSITION;
    float4 Color : COLOR;
};

struct OutputStruct
{ 
    float4 Position : SV_POSITION0;
    float4 Color : COLOR0;
    float4 Normal : NORMAL0;
    float4 WorldPos : POSITION0;
    float4 TexCoords : TEXCOORD0;
};

OutputStruct VS( InputStruct Input )
{
    OutputStruct Output = (OutputStruct)0;
    Output.Position = mul(CameraViewProjection[ActiveCamera], Input.Position);
    Output.Color = Input.Color;
    return Output;
}
1

1 Answers

0
votes

packoffset is exactly what it sounds like: an offset, not a range. This means it simply indicates where your variable should start. xyz refers to 3 different locations, but naturally, you can't start a variable in 3 locations and this is why your getting an error. What you realy want is for your new variable to start at y, so try packoffset(c0.y) instead of c0.yzw