-
Couldn't load subscription status.
- Fork 615
Description
Summary
Semantic labels for stage inputs and outputs appear to be incorrect. For example, a POSITION input was incorrectly labeled as TEXCOORD0.
Erroneous Output
cbuffer _25_27 : register(b0)
{
float4 _27_m0[4] : packoffset(c0);
float4 _27_m1[4] : packoffset(c4);
float4 _27_m2 : packoffset(c8);
};
static float4 gl_Position;
static float4 _9;
static float2 vs_TEXCOORD0;
static float3 _18;
static float3 _41;
struct SPIRV_Cross_Input
{
float3 _41 : TEXCOORD0;
float3 _18 : TEXCOORD1;
};
struct SPIRV_Cross_Output
{
float2 vs_TEXCOORD0 : TEXCOORD0;
float4 _9 : TEXCOORD1;
float4 gl_Position : SV_Position;
};
static float4 _40;
static float4 _68;
void vert_main()
{
_9 = float4(0.0f, 0.0f, 0.0f, 1.0f);
vs_TEXCOORD0 = (_18.xy * _27_m2.xy) + _27_m2.zw;
_40 = _41.yyyy * _27_m0[1];
_40 = (_27_m0[0] * _41.xxxx) + _40;
_40 = (_27_m0[2] * _41.zzzz) + _40;
_40 += _27_m0[3];
_68 = _40.yyyy * _27_m1[1];
_68 = (_27_m1[0] * _40.xxxx) + _68;
_68 = (_27_m1[2] * _40.zzzz) + _68;
gl_Position = (_27_m1[3] * _40.wwww) + _68;
gl_Position.y = -gl_Position.y;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
_18 = stage_input._18;
_41 = stage_input._41;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output._9 = _9;
stage_output.vs_TEXCOORD0 = vs_TEXCOORD0;
return stage_output;
}Expected Output
cbuffer _25_27 : register(b0)
{
float4 _27_m0[4] : packoffset(c0); // object to world matrix
float4 _27_m1[4] : packoffset(c4); // view projection matrix
float4 _27_m2 : packoffset(c8); // _MainTex_ST
};
static float4 gl_Position;
static float4 _9;
static float2 vs_TEXCOORD0;
static float3 _18;
static float3 _41;
struct SPIRV_Cross_Input
{
float3 _41 : POSITION; // Not TEXCOORD0
float3 _18 : TEXCOORD0; // Not TEXCOORD1
};
struct SPIRV_Cross_Output
{
float2 vs_TEXCOORD0 : TEXCOORD0;
float4 _9 : COLOR0; // Not TEXCOORD1
float4 gl_Position : SV_Position;
};
static float4 _40;
static float4 _68;
void vert_main()
{
_9 = float4(0.0f, 0.0f, 0.0f, 1.0f);
vs_TEXCOORD0 = (_18.xy * _27_m2.xy) + _27_m2.zw;
_40 = _41.yyyy * _27_m0[1];
_40 = (_27_m0[0] * _41.xxxx) + _40;
_40 = (_27_m0[2] * _41.zzzz) + _40;
_40 += _27_m0[3];
_68 = _40.yyyy * _27_m1[1];
_68 = (_27_m1[0] * _40.xxxx) + _68;
_68 = (_27_m1[2] * _40.zzzz) + _68;
gl_Position = (_27_m1[3] * _40.wwww) + _68;
gl_Position.y = -gl_Position.y;
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
_18 = stage_input._18;
_41 = stage_input._41;
vert_main();
SPIRV_Cross_Output stage_output;
stage_output.gl_Position = gl_Position;
stage_output._9 = _9;
stage_output.vs_TEXCOORD0 = vs_TEXCOORD0;
return stage_output;
}Reproduction
With the current latest commit (cb71abe):
./spirv-cross.exe Blob_1_Data_0_Snippet_0.spv --hlsl --shader-model 40
Additional Context
I'm investigating the issue and am willing to submit a pull request. However, I'm brand new to working in this codebase and would appreciate any and all guidance.
Related
- [Discussion] HLSL vertex shader input semantics from attribute names #163
- HLSL Vertex Attribute remap #320
- Add support for new HLSL semantic/counter buffer decorations. #509
- Getting the HLSL Semantic Name using the Reflection API #1687
- How to Relection Hlsl semantic name #1713
- HLSL: Add option to bind vertex input smemantics by name. #2045
- Cannot get hlsl stage input semantic string #2202
After reading these, I feel like my issue might be caused by a lack of information in the Spir-V file about semantics. With some additional investigation, I discovered HLSLVertexAttributeRemap and CompilerHLSL::add_vertex_attribute_remap, which allows setting semantics for inputs. I have some questions:
CompilerHLSL::add_vertex_attribute_remaplets me set the semantics for stage inputs. Is there any way to set stage outputs?- Setting the
UserSemanticorHlslSemanticGoogleseems to do nothing. Should they affect the program output?