【问题标题】:Direct3D Shader Internal Compiler Error X8000: Invalid BytecodeDirect3D 着色器内部编译器错误 X8000:无效字节码
【发布时间】:2019-09-23 12:26:53
【问题描述】:

在编译这个简单的像素着色器时:

Texture2D tex0 : register(t0);
Texture2D tex1 : register(t1);

SamplerState s : register(s0);

float4 main(float2 tc : TEXCOORD0) : SV_TARGET
{
    Texture2D tex = tex0;
    if (tc.x > 0.5)
    {
        tex = tex1;
    }
    return tex.SampleLevel(s, tc, 0);
}

使用命令行fxc.exe /T ps_4_0 hello.hlsl我得到:

Microsoft (R) Direct3D Shader Compiler 10.1 (using C:\Windows Kits\10\bin\10.0.17763.0\x86\D3DCOMPILER_47.dll)
Copyright (C) 2013 Microsoft. All rights reserved.

error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Invalid operand type for operand #3 of opcode #8 (counts are 1-based).
error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Can't continue validation - aborting.

我做错了什么?

【问题讨论】:

    标签: direct3d hlsl


    【解决方案1】:

    内部编译器错误在这里不是一个有用的错误,但是您上面使用的模式并不是大多数人编写的。如果您将其编写为,则相同的着色器可以工作:

    Texture2D tex0 : register(t0);
    Texture2D tex1 : register(t1);
    
    SamplerState s : register(s0);
    
    float4 main(float2 tc : TEXCOORD0) : SV_TARGET
    {
        if (tc.x > 0.5)
        {
            return tex1.SampleLevel(s, tc, 0);
        }
        else
        {
            return tex0.SampleLevel(s, tc, 0);
        }
    }
    

    请注意,Shader Model 6 的 DXIL 编译器在这种情况下会返回更合理的错误:

    错误:本地资源不能保证映射到唯一的全局资源。使用 /Zi 作为源位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      相关资源
      最近更新 更多