You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HLSL 6.0顶点着色器返回不匹配类型无报错,求技术解答

问题分析:返回类型不匹配却无编译报错的情况

这是DXC编译器的bug,并非HLSL允许的特性,理由如下:

  • HLSL是强类型语言,函数声明的返回类型必须与实际返回的类型严格一致。即便两个结构体的内存总大小相同,但它们是完全独立的类型定义,编译器必须触发类型不匹配的错误提示。
  • 两个结构体的语义绑定存在本质差异:lerpBlit的TEXCOORD0是float3类型,而lerpLine的TEXCOORD0是float,还额外定义了TEXCOORD1、TEXCOORD2语义。这种返回类型不匹配会导致顶点着色器输出到渲染管线的数据完全错位,属于严重逻辑错误,编译器理应对此进行拦截。
  • 正常情况下,DXC编译器遇到此类问题会抛出类似error X3000: invalid return type的编译错误,你使用的1.7.2207版本未触发警告/错误,属于编译器的疏漏。

建议将该问题上报至DirectXShaderCompiler的官方代码仓库,附上测试代码、编译器版本及复现步骤。

测试代码

struct vinBake
{
    float4      Position        : ATTRIB0;      // local position of the vertex
    float4      Color           : ATTRIB1;      // color channels
    float3      TexCoord        : ATTRIB2;      // UV Texture Coordinates (z value represents texture index, if used)
    float4      Prop            : ATTRIB3;      // enhanced logic properties
    float4      Attr            : ATTRIB4;      // enhanced logic attributes
};
struct lerpBlit
{
    float4      ClipPos         : SV_POSITION;  // projected clip-space screen position of vertex
    float4      Diffuse         : COLOR0;       // diffuse color
    float3      Tex             : TEXCOORD0;    // tex coords (x,y) + texture array index (z)
};
struct lerpLine
{
    float4      ClipPos         : SV_POSITION;  // projected clip-space screen position of vertex
    float4      Diffuse         : COLOR0;       // diffuse color
    float       Factor          : TEXCOORD0;    // factor value of this position (0->1)
    float       Thickness       : TEXCOORD1;    // thickness of line
    float       Feather         : TEXCOORD2;    // falloff of line
};
lerpBlit main(vinBake vin)
{
    lerpLine pin;
    pin.ClipPos = float4(0,0,0,1);
    pin.Diffuse = float4(1,1,1,1);
    pin.Factor = 0;
    pin.Thickness = 0;
    pin.Feather = 0;
    return pin;
}

内容的提问来源于stack exchange,提问作者Robert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 07:05:22