From 153064f2c74978eebacad05a70887ba1d4061b53 Mon Sep 17 00:00:00 2001 From: FrostyLeaves <654065929@qq.com> Date: Wed, 22 Nov 2023 22:21:13 +0800 Subject: [PATCH] fix: Support SV_ViewID keywords for hlsl. --- Test/baseResults/hlsl.multiView.frag.out | 121 +++++++++++++++++++++++ Test/hlsl.multiView.frag | 5 + glslang/HLSL/hlslParseHelper.cpp | 2 + glslang/HLSL/hlslScanContext.cpp | 1 + gtests/Hlsl.FromFile.cpp | 1 + 5 files changed, 130 insertions(+) create mode 100644 Test/baseResults/hlsl.multiView.frag.out create mode 100644 Test/hlsl.multiView.frag diff --git a/Test/baseResults/hlsl.multiView.frag.out b/Test/baseResults/hlsl.multiView.frag.out new file mode 100644 index 00000000..32e669ca --- /dev/null +++ b/Test/baseResults/hlsl.multiView.frag.out @@ -0,0 +1,121 @@ +hlsl.multiView.frag +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:3 Function Definition: @main(u1; ( temp 4-component vector of float) +0:3 Function Parameters: +0:3 'ViewIndex' ( in uint) +0:? Sequence +0:4 Branch: Return with expression +0:4 Construct vec4 ( temp 4-component vector of float) +0:4 Convert uint to float ( temp float) +0:4 'ViewIndex' ( in uint) +0:4 Constant: +0:4 0.000000 +0:4 Constant: +0:4 0.000000 +0:4 Constant: +0:4 0.000000 +0:3 Function Definition: main( ( temp void) +0:3 Function Parameters: +0:? Sequence +0:3 move second child to first child ( temp uint) +0:? 'ViewIndex' ( temp uint) +0:? 'ViewIndex' ( flat in uint ViewIndex) +0:3 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:3 Function Call: @main(u1; ( temp 4-component vector of float) +0:? 'ViewIndex' ( temp uint) +0:? Linker Objects +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:? 'ViewIndex' ( flat in uint ViewIndex) + + +Linked fragment stage: + + +Shader version: 500 +gl_FragCoord origin is upper left +0:? Sequence +0:3 Function Definition: @main(u1; ( temp 4-component vector of float) +0:3 Function Parameters: +0:3 'ViewIndex' ( in uint) +0:? Sequence +0:4 Branch: Return with expression +0:4 Construct vec4 ( temp 4-component vector of float) +0:4 Convert uint to float ( temp float) +0:4 'ViewIndex' ( in uint) +0:4 Constant: +0:4 0.000000 +0:4 Constant: +0:4 0.000000 +0:4 Constant: +0:4 0.000000 +0:3 Function Definition: main( ( temp void) +0:3 Function Parameters: +0:? Sequence +0:3 move second child to first child ( temp uint) +0:? 'ViewIndex' ( temp uint) +0:? 'ViewIndex' ( flat in uint ViewIndex) +0:3 move second child to first child ( temp 4-component vector of float) +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:3 Function Call: @main(u1; ( temp 4-component vector of float) +0:? 'ViewIndex' ( temp uint) +0:? Linker Objects +0:? '@entryPointOutput' (layout( location=0) out 4-component vector of float) +0:? 'ViewIndex' ( flat in uint ViewIndex) + +// Module Version 10000 +// Generated by (magic number): 8000b +// Id's are bound by 29 + + Capability Shader + Capability MultiView + Extension "SPV_KHR_multiview" + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 22 25 + ExecutionMode 4 OriginUpperLeft + Source HLSL 500 + Name 4 "main" + Name 12 "@main(u1;" + Name 11 "ViewIndex" + Name 20 "ViewIndex" + Name 22 "ViewIndex" + Name 25 "@entryPointOutput" + Name 26 "param" + Decorate 22(ViewIndex) Flat + Decorate 22(ViewIndex) BuiltIn ViewIndex + Decorate 25(@entryPointOutput) Location 0 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 0 + 7: TypePointer Function 6(int) + 8: TypeFloat 32 + 9: TypeVector 8(float) 4 + 10: TypeFunction 9(fvec4) 7(ptr) + 16: 8(float) Constant 0 + 21: TypePointer Input 6(int) + 22(ViewIndex): 21(ptr) Variable Input + 24: TypePointer Output 9(fvec4) +25(@entryPointOutput): 24(ptr) Variable Output + 4(main): 2 Function None 3 + 5: Label + 20(ViewIndex): 7(ptr) Variable Function + 26(param): 7(ptr) Variable Function + 23: 6(int) Load 22(ViewIndex) + Store 20(ViewIndex) 23 + 27: 6(int) Load 20(ViewIndex) + Store 26(param) 27 + 28: 9(fvec4) FunctionCall 12(@main(u1;) 26(param) + Store 25(@entryPointOutput) 28 + Return + FunctionEnd + 12(@main(u1;): 9(fvec4) Function None 10 + 11(ViewIndex): 7(ptr) FunctionParameter + 13: Label + 14: 6(int) Load 11(ViewIndex) + 15: 8(float) ConvertUToF 14 + 17: 9(fvec4) CompositeConstruct 15 16 16 16 + ReturnValue 17 + FunctionEnd diff --git a/Test/hlsl.multiView.frag b/Test/hlsl.multiView.frag new file mode 100644 index 00000000..79e388d6 --- /dev/null +++ b/Test/hlsl.multiView.frag @@ -0,0 +1,5 @@ + +float4 main(uint ViewIndex : SV_ViewID) +{ + return float4(ViewIndex, 0.0f, 0.0f, 0.0f); +} diff --git a/glslang/HLSL/hlslParseHelper.cpp b/glslang/HLSL/hlslParseHelper.cpp index ac0dee50..b0fb5f46 100644 --- a/glslang/HLSL/hlslParseHelper.cpp +++ b/glslang/HLSL/hlslParseHelper.cpp @@ -9551,6 +9551,8 @@ bool HlslParseContext::isInputBuiltIn(const TQualifier& qualifier) const return language == EShLangTessEvaluation; case EbvTessCoord: return language == EShLangTessEvaluation; + case EbvViewIndex: + return language != EShLangCompute; default: return false; } diff --git a/glslang/HLSL/hlslScanContext.cpp b/glslang/HLSL/hlslScanContext.cpp index 823b17aa..e9edb619 100644 --- a/glslang/HLSL/hlslScanContext.cpp +++ b/glslang/HLSL/hlslScanContext.cpp @@ -512,6 +512,7 @@ void HlslScanContext::fillInKeywordMap() (*SemanticMap)["SV_PRIMITIVEID"] = EbvPrimitiveId; (*SemanticMap)["SV_OUTPUTCONTROLPOINTID"] = EbvInvocationId; (*SemanticMap)["SV_ISFRONTFACE"] = EbvFace; + (*SemanticMap)["SV_VIEWID"] = EbvViewIndex; (*SemanticMap)["SV_INSTANCEID"] = EbvInstanceIndex; (*SemanticMap)["SV_INSIDETESSFACTOR"] = EbvTessLevelInner; (*SemanticMap)["SV_GSINSTANCEID"] = EbvInvocationId; diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 9f324955..5d0d2d6b 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -318,6 +318,7 @@ INSTANTIATE_TEST_SUITE_P( {"hlsl.mul-truncate.frag", "main"}, {"hlsl.multiEntry.vert", "RealEntrypoint"}, {"hlsl.multiReturn.frag", "main"}, + {"hlsl.multiView.frag", "main"}, {"hlsl.matrixindex.frag", "main"}, {"hlsl.nonstaticMemberFunction.frag", "main"}, {"hlsl.numericsuffixes.frag", "main"},