Direct3D 着色器内部编译器错误 X8000:无效的字节码
Direct3D Shader Internal Compiler Error X8000: Invalid Bytecode
编译这个简单的像素着色器时:
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\bin.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.
我做错了什么?
内部编译器错误在这里不是有用的错误,但您在上面使用的模式并不是大多数人编写的。如果您将其编写为:
,则相同的着色器会起作用
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 编译器 returns 在这种情况下是一个更明智的错误:
error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.
编译这个简单的像素着色器时:
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\bin.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.
我做错了什么?
内部编译器错误在这里不是有用的错误,但您在上面使用的模式并不是大多数人编写的。如果您将其编写为:
,则相同的着色器会起作用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 编译器 returns 在这种情况下是一个更明智的错误:
error: local resource not guaranteed to map to unique global resource. Use /Zi for source location.