fix: Support SV_ViewID keywords for hlsl.

This commit is contained in:
FrostyLeaves 2023-11-22 22:21:13 +08:00 committed by arcady-lunarg
parent 7c5fb5c1a8
commit 153064f2c7
5 changed files with 130 additions and 0 deletions

View File

@ -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

5
Test/hlsl.multiView.frag Normal file
View File

@ -0,0 +1,5 @@
float4 main(uint ViewIndex : SV_ViewID)
{
return float4(ViewIndex, 0.0f, 0.0f, 0.0f);
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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"},