为什么在针对ps_4_0时不支持颜色作为输出语义,而在vs_4_0中受支持?

问题描述 投票:0回答:1

以下面的代码为例

struct vsout
{
  float4 pos : position;
  float4 clr : color;
};

cbuffer dmy : register(b0)
{
  float4x4 mat;
};

vsout vsmain(
  float4 pos : position,
  float2 tex : texcoord,
  float4 clr : color)
{
  vsout o;
  o.pos = mul(mat,pos);
  o.clr = clr;
  return o;
}

struct psout
{
  float4 clr : color;
};

psout psmain(
  float4 clr : color )
{
  psout o;
  o.clr = clr;
  return o;
}

fxc /Evsmain /Tvs_4_0 demo.hlsl,确定fxc /Epsmain /Tps_4_0 demo.hlsl,失败将psout更改为

struct psout
{
   float4 clr : sv_target;
};

fxc /Epsmain /Tps_4_0 demo.hlsl,确定根据本文档,https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics颜色对于d3d9及更高版本是有效的语义。我正在使用的fxc是D3DCOMPILER_47.dll。这是怎么发生的?非常感谢!!!

directx-9
1个回答
0
投票

您正在构建时没有/Gec标志,因此HLSL编译器不允许“向后兼容”行为。

在“顶点着色器”情况下为“颜色”是一种顶点语义,在大多数情况下为“用户定义”语义。

“ COLOR”也是有效的“用户定义”语义,用于绑定Vertex Shader输出和Pixel Shader输入。

为了严格兼容,您需要使用SV_Target作为像素着色器的输出。

理想情况下,对于顶点着色器输入,也将使用SV_Position而不是Position,但是您必须匹配输入布局中提供的任何内容。 VS和PS之间使用的任何内容也必须保持一致。

如果将/Gec添加到像素着色器命令行,则它将生成,因为它支持较旧的Direct3D 9样式:fxc /Epsmain /Gec /Tps_4_0 demo.hlsl

请参见Microsoft Docs

© www.soinside.com 2019 - 2024. All rights reserved.