【问题标题】:HLSL Constant Buffer Packing Unexpected ErrorHLSL 常量缓冲区打包意外错误
【发布时间】:2014-12-04 17:52:39
【问题描述】:

我有一个 HLSL 着色器,当我将特定变量添加到常量缓冲区时,它会给出意外错误。整个着色器在下面。为了排除一切,我包括了整个着色器。

NewVariable添加到第三个常量缓冲区时出现错误。

我在文档中没有找到这一点,但我可以不执行以下打包,其中向量开始部分进入 c0 向量?

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

我收到记录不充分的错误 X3530 (ERR_BIND_INVALID)。 MSDN 说,“执行了无效的绑定操作。例如,缓冲区只能绑定到一个插槽或一个常量偏移量;无效的寄存器规范,因为预期的特定绑定但没有发生;不能将 packoffset 元素与 nonpackoffset 元素混合在 cbuffer 中。”这个错误消息并没有告诉我什么是错误的,并且包偏移量在我看来是正确的。

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;
}

【问题讨论】:

    标签: directx-11 hlsl


    【解决方案1】:

    packoffset 正是它听起来的样子:一个偏移量,而不是一个范围。这意味着它只是指示您的变量应该从哪里开始。 xyz 指的是 3 个不同的位置,但自然地,您不能在 3 个位置启动变量,这就是您收到错误的原因。你真正想要的是你的新变量从 y 开始,所以试试 packoffset(c0.y) 而不是 c0.yzw

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 2016-07-17
      相关资源
      最近更新 更多