我正在做一些硬件曲面分割并设法获得基本的分割效果,因此尝试继续进行 Phong 曲面分割(用于圆化边缘)。现在,当我想在补丁常量函数中添加额外的输出并写入它们时,但其中之一会引发错误。
struct ConstantOutputType
{
float edges[3] : SV_TessFactor;
float inside : SV_InsideTessFactor;
float3 f3B0 : POSITION0;
float3 f3B1 : POSITION1;
float3 f3B2 : POSITION2;
float3 f3N0 : NORMAL0;
float3 f3N1 : NORMAL1;
float3 f3N2 : NORMAL2;
};
ConstantOutputType PatchConstantFunction(InputPatch<HullInputType, 3> inputPatch, uint patchId : SV_PrimitiveID)
{
ConstantOutputType output = (ConstantOutputType)0;
// Set the tessellation factors for the three edges of the triangle.
output.edges[0] = inputPatch[0].dep;
output.edges[1] = inputPatch[1].dep;
output.edges[2] = inputPatch[2].dep;
// Set the tessellation factor for tessallating inside the triangle.
output.inside = (inputPatch[0].dep + inputPatch[1].dep + inputPatch[2].dep)/3.0f;
output.f3B0 = inputPatch[0].pos.xyz;
output.f3B1 = inputPatch[1].pos.xyz;
output.f3B2 = inputPatch[2].pos.xyz;
//output.f3N0 = inputPatch[0].nor.xyz; <=====This throws the error (setting the normal)
output.f3N1 = inputPatch[1].nor.xyz;
output.f3N2 = inputPatch[2].nor.xyz;
return output;
}
抛出的错误是: 错误 X8000:D3D11 内部编译器错误:无效字节码:寄存器 1 的输入声明的组件与同一寄存器的先前声明重叠。操作码 #47(计数从 1 开始)。 错误 X8000:D3D11 内部编译器错误:无效字节码:无法继续验证 - 中止。 我似乎无法弄清楚它的含义(鉴于这是我第一次尝试外壳着色器)。
如果我注释掉它,它就可以工作,如果我为其设置任意值,它也可以工作(例如:output.f3N0 = float3(0,1,0))。 我还尝试更改变量的语义,但没有帮助。 如果有人能给我一些关于这方面的见解,我将非常高兴。
更新: 根据要求,外壳输入如下:
struct HullInputType
{
float3 pos : POSITION;
float2 tex : TEXCOORD0;
float3 nor : TEXCOORD1;
float dep : TEXCOORD2;
};
最佳答案
好吧,看起来外壳着色器输入结构中的 (float dep : TEXCOORD2;) 是问题所在。可能是因为着色器单元处理 float4 寄存器,所以两个 float3 变量无法连接,但 float2 和 float 被连接到 float4 寄存器。两个float2是一样的,但是float2和float3不能连接,也不会重叠。所以我想我会在 float3 变量中使用 (float2 tex) 发送深度 (float dep) 信息。
这很有趣,尽管它对某人有用。在我的域到像素着色器中,不会以这种方式重叠寄存器。
更新:它不起作用,错误消失了,我可以编译着色器,但是如果我尝试通过从输入结构分配给该变量来使用该变量,那么整个图形渲染就会停止工作(甚至是未分割的调用)。这发生在硬件设备上,在 WARP 上它以某种方式工作。
更新2:现在我通过仅发送 float4 来修复它,但我不喜欢这一点。很奇怪的是,我不必在我的顶点和像素着色器中这样做,也许这是一个故障?或者可能是 GPU 硬件不兼容(Nvidia GT525M)。
关于directx - 外壳着色器中的重叠寄存器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18320789/