SPV: Fix #1575, fix #1593: Support HLSL #line

SPIR-V OpLines now contain filenames from HLSL-style #lines.
This commit is contained in:
greg-lunarg 2018-12-07 17:36:33 -07:00 committed by John Kessenich
parent 127cea5c9a
commit 5d43c4aac7
18 changed files with 754 additions and 39 deletions

View file

@ -0,0 +1,183 @@
hlsl.pp.line2.frag
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 80
Capability Shader
2: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 5 "MainPs" 71 75
ExecutionMode 5 OriginUpperLeft
1: String "hlsl.pp.line2.frag"
17: String "foo.frag"
32: String "foo.h"
42: String "foo2.h"
Source HLSL 500 1 "// OpModuleProcessed auto-map-locations
// OpModuleProcessed auto-map-bindings
// OpModuleProcessed entry-point MainPs
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed keep-uncalled
// OpModuleProcessed hlsl-offsets
#line 1
#line 1 "foo.frag"
Texture2D g_tColor[ 128 ] ;
layout (push_constant) cbuffer PerViewConstantBuffer_t
{
uint g_nDataIdx;
uint g_nDataIdx2;
bool g_B;
} ;
SamplerState g_sAniso;
struct PS_INPUT
{
float2 vTextureCoords : TEXCOORD2 ;
} ;
struct PS_OUTPUT
{
float4 vColor : SV_Target0 ;
} ;
PS_OUTPUT MainPs ( PS_INPUT i )
{
PS_OUTPUT ps_output ;
uint u;
#line 47
if (g_B)
#line 3 "foo.h"
u = g_nDataIdx;
else
#line 67
u = g_nDataIdx2;
#line 7 "foo2.h"
ps_output . vColor = g_tColor [ u ] . Sample ( g_sAniso , i . vTextureCoords . xy );
#line 105
return ps_output ;
}
"
Name 5 "MainPs"
Name 9 "PS_INPUT"
MemberName 9(PS_INPUT) 0 "vTextureCoords"
Name 12 "PS_OUTPUT"
MemberName 12(PS_OUTPUT) 0 "vColor"
Name 15 "@MainPs(struct-PS_INPUT-vf21;"
Name 14 "i"
Name 19 "PerViewConstantBuffer_t"
MemberName 19(PerViewConstantBuffer_t) 0 "g_nDataIdx"
MemberName 19(PerViewConstantBuffer_t) 1 "g_nDataIdx2"
MemberName 19(PerViewConstantBuffer_t) 2 "g_B"
Name 21 ""
Name 34 "u"
Name 44 "ps_output"
Name 49 "g_tColor"
Name 56 "g_sAniso"
Name 69 "i"
Name 71 "i.vTextureCoords"
Name 75 "@entryPointOutput.vColor"
Name 76 "param"
MemberDecorate 19(PerViewConstantBuffer_t) 0 Offset 0
MemberDecorate 19(PerViewConstantBuffer_t) 1 Offset 4
MemberDecorate 19(PerViewConstantBuffer_t) 2 Offset 8
Decorate 19(PerViewConstantBuffer_t) Block
Decorate 49(g_tColor) DescriptorSet 0
Decorate 56(g_sAniso) DescriptorSet 0
Decorate 71(i.vTextureCoords) Location 0
Decorate 75(@entryPointOutput.vColor) Location 0
3: TypeVoid
4: TypeFunction 3
7: TypeFloat 32
8: TypeVector 7(float) 2
9(PS_INPUT): TypeStruct 8(fvec2)
10: TypePointer Function 9(PS_INPUT)
11: TypeVector 7(float) 4
12(PS_OUTPUT): TypeStruct 11(fvec4)
13: TypeFunction 12(PS_OUTPUT) 10(ptr)
18: TypeInt 32 0
19(PerViewConstantBuffer_t): TypeStruct 18(int) 18(int) 18(int)
20: TypePointer PushConstant 19(PerViewConstantBuffer_t)
21: 20(ptr) Variable PushConstant
22: TypeInt 32 1
23: 22(int) Constant 2
24: TypePointer PushConstant 18(int)
27: TypeBool
28: 18(int) Constant 0
33: TypePointer Function 18(int)
35: 22(int) Constant 0
39: 22(int) Constant 1
43: TypePointer Function 12(PS_OUTPUT)
45: TypeImage 7(float) 2D sampled format:Unknown
46: 18(int) Constant 128
47: TypeArray 45 46
48: TypePointer UniformConstant 47
49(g_tColor): 48(ptr) Variable UniformConstant
51: TypePointer UniformConstant 45
54: TypeSampler
55: TypePointer UniformConstant 54
56(g_sAniso): 55(ptr) Variable UniformConstant
58: TypeSampledImage 45
60: TypePointer Function 8(fvec2)
64: TypePointer Function 11(fvec4)
70: TypePointer Input 8(fvec2)
71(i.vTextureCoords): 70(ptr) Variable Input
74: TypePointer Output 11(fvec4)
75(@entryPointOutput.vColor): 74(ptr) Variable Output
5(MainPs): 3 Function None 4
6: Label
69(i): 10(ptr) Variable Function
76(param): 10(ptr) Variable Function
Line 17 23 0
72: 8(fvec2) Load 71(i.vTextureCoords)
73: 60(ptr) AccessChain 69(i) 35
Store 73 72
77: 9(PS_INPUT) Load 69(i)
Store 76(param) 77
78:12(PS_OUTPUT) FunctionCall 15(@MainPs(struct-PS_INPUT-vf21;) 76(param)
79: 11(fvec4) CompositeExtract 78 0
Store 75(@entryPointOutput.vColor) 79
Return
FunctionEnd
15(@MainPs(struct-PS_INPUT-vf21;):12(PS_OUTPUT) Function None 13
14(i): 10(ptr) FunctionParameter
16: Label
34(u): 33(ptr) Variable Function
44(ps_output): 43(ptr) Variable Function
Line 17 47 0
25: 24(ptr) AccessChain 21 23
26: 18(int) Load 25
29: 27(bool) INotEqual 26 28
SelectionMerge 31 None
BranchConditional 29 30 38
30: Label
Line 32 3 0
36: 24(ptr) AccessChain 21 35
37: 18(int) Load 36
Store 34(u) 37
Branch 31
38: Label
Line 32 67 0
40: 24(ptr) AccessChain 21 39
41: 18(int) Load 40
Store 34(u) 41
Branch 31
31: Label
Line 42 7 0
50: 18(int) Load 34(u)
52: 51(ptr) AccessChain 49(g_tColor) 50
53: 45 Load 52
57: 54 Load 56(g_sAniso)
59: 58 SampledImage 53 57
61: 60(ptr) AccessChain 14(i) 35
62: 8(fvec2) Load 61
63: 11(fvec4) ImageSampleImplicitLod 59 62
65: 64(ptr) AccessChain 44(ps_output) 35
Store 65 63
Line 42 105 0
66:12(PS_OUTPUT) Load 44(ps_output)
ReturnValue 66
FunctionEnd

View file

@ -0,0 +1,172 @@
hlsl.pp.line3.frag
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 78
Capability Shader
2: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 5 "MainPs" 69 73
ExecutionMode 5 OriginUpperLeft
1: String "hlsl.pp.line3.frag"
31: String "./i1.h"
Source HLSL 500 1 "// OpModuleProcessed entry-point MainPs
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed hlsl-offsets
#line 1
Texture2D g_tColor[ 128 ] ;
layout (push_constant) cbuffer PerViewConstantBuffer_t
{
uint g_nDataIdx;
uint g_nDataIdx2;
bool g_B;
} ;
SamplerState g_sAniso;
struct PS_INPUT
{
float2 vTextureCoords : TEXCOORD2 ;
} ;
struct PS_OUTPUT
{
float4 vColor : SV_Target0 ;
} ;
PS_OUTPUT MainPs ( PS_INPUT i )
{
PS_OUTPUT ps_output ;
uint u;
if (g_B)
#include "i1.h"
else
u = g_nDataIdx2;
ps_output . vColor = g_tColor [ u ] . Sample ( g_sAniso , i . vTextureCoords . xy );
return ps_output ;
}
"
Name 5 "MainPs"
Name 9 "PS_INPUT"
MemberName 9(PS_INPUT) 0 "vTextureCoords"
Name 12 "PS_OUTPUT"
MemberName 12(PS_OUTPUT) 0 "vColor"
Name 15 "@MainPs(struct-PS_INPUT-vf21;"
Name 14 "i"
Name 18 "PerViewConstantBuffer_t"
MemberName 18(PerViewConstantBuffer_t) 0 "g_nDataIdx"
MemberName 18(PerViewConstantBuffer_t) 1 "g_nDataIdx2"
MemberName 18(PerViewConstantBuffer_t) 2 "g_B"
Name 20 ""
Name 33 "u"
Name 42 "ps_output"
Name 47 "g_tColor"
Name 54 "g_sAniso"
Name 67 "i"
Name 69 "i.vTextureCoords"
Name 73 "@entryPointOutput.vColor"
Name 74 "param"
MemberDecorate 18(PerViewConstantBuffer_t) 0 Offset 0
MemberDecorate 18(PerViewConstantBuffer_t) 1 Offset 4
MemberDecorate 18(PerViewConstantBuffer_t) 2 Offset 8
Decorate 18(PerViewConstantBuffer_t) Block
Decorate 47(g_tColor) DescriptorSet 0
Decorate 54(g_sAniso) DescriptorSet 0
Decorate 69(i.vTextureCoords) Location 0
Decorate 73(@entryPointOutput.vColor) Location 0
3: TypeVoid
4: TypeFunction 3
7: TypeFloat 32
8: TypeVector 7(float) 2
9(PS_INPUT): TypeStruct 8(fvec2)
10: TypePointer Function 9(PS_INPUT)
11: TypeVector 7(float) 4
12(PS_OUTPUT): TypeStruct 11(fvec4)
13: TypeFunction 12(PS_OUTPUT) 10(ptr)
17: TypeInt 32 0
18(PerViewConstantBuffer_t): TypeStruct 17(int) 17(int) 17(int)
19: TypePointer PushConstant 18(PerViewConstantBuffer_t)
20: 19(ptr) Variable PushConstant
21: TypeInt 32 1
22: 21(int) Constant 2
23: TypePointer PushConstant 17(int)
26: TypeBool
27: 17(int) Constant 0
32: TypePointer Function 17(int)
34: 21(int) Constant 0
38: 21(int) Constant 1
41: TypePointer Function 12(PS_OUTPUT)
43: TypeImage 7(float) 2D sampled format:Unknown
44: 17(int) Constant 128
45: TypeArray 43 44
46: TypePointer UniformConstant 45
47(g_tColor): 46(ptr) Variable UniformConstant
49: TypePointer UniformConstant 43
52: TypeSampler
53: TypePointer UniformConstant 52
54(g_sAniso): 53(ptr) Variable UniformConstant
56: TypeSampledImage 43
58: TypePointer Function 8(fvec2)
62: TypePointer Function 11(fvec4)
68: TypePointer Input 8(fvec2)
69(i.vTextureCoords): 68(ptr) Variable Input
72: TypePointer Output 11(fvec4)
73(@entryPointOutput.vColor): 72(ptr) Variable Output
5(MainPs): 3 Function None 4
6: Label
67(i): 10(ptr) Variable Function
74(param): 10(ptr) Variable Function
Line 1 23 0
70: 8(fvec2) Load 69(i.vTextureCoords)
71: 58(ptr) AccessChain 67(i) 34
Store 71 70
75: 9(PS_INPUT) Load 67(i)
Store 74(param) 75
76:12(PS_OUTPUT) FunctionCall 15(@MainPs(struct-PS_INPUT-vf21;) 74(param)
77: 11(fvec4) CompositeExtract 76 0
Store 73(@entryPointOutput.vColor) 77
Return
FunctionEnd
15(@MainPs(struct-PS_INPUT-vf21;):12(PS_OUTPUT) Function None 13
14(i): 10(ptr) FunctionParameter
16: Label
33(u): 32(ptr) Variable Function
42(ps_output): 41(ptr) Variable Function
Line 1 27 0
24: 23(ptr) AccessChain 20 22
25: 17(int) Load 24
28: 26(bool) INotEqual 25 27
SelectionMerge 30 None
BranchConditional 28 29 37
29: Label
Line 31 1 0
35: 23(ptr) AccessChain 20 34
36: 17(int) Load 35
Store 33(u) 36
Branch 30
37: Label
Line 1 30 0
39: 23(ptr) AccessChain 20 38
40: 17(int) Load 39
Store 33(u) 40
Branch 30
30: Label
Line 1 31 0
48: 17(int) Load 33(u)
50: 49(ptr) AccessChain 47(g_tColor) 48
51: 43 Load 50
55: 52 Load 54(g_sAniso)
57: 56 SampledImage 51 55
59: 58(ptr) AccessChain 14(i) 34
60: 8(fvec2) Load 59
61: 11(fvec4) ImageSampleImplicitLod 57 60
63: 62(ptr) AccessChain 42(ps_output) 34
Store 63 61
Line 1 32 0
64:12(PS_OUTPUT) Load 42(ps_output)
ReturnValue 64
FunctionEnd

View file

@ -0,0 +1,144 @@
spv.pp.line.frag
WARNING: spv.pp.line.frag:6: varying deprecated in version 130; may be removed in future release
WARNING: spv.pp.line.frag:7: varying deprecated in version 130; may be removed in future release
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 65
Capability Shader
Capability Sampled1D
2: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 5 "main" 41 53 56 59
ExecutionMode 5 OriginUpperLeft
1: String "spv.pp.line.frag"
Source GLSL 140 1 "// OpModuleProcessed auto-map-locations
// OpModuleProcessed auto-map-bindings
// OpModuleProcessed client vulkan100
// OpModuleProcessed target-env vulkan1.0
// OpModuleProcessed keep-uncalled
// OpModuleProcessed entry-point main
#line 1
#version 140
uniform sampler1D texSampler1D;
uniform sampler2D texSampler2D;
varying float blend;
varying vec4 u;
in vec2 coords2D;
void main()
{
float blendscale = 1.789;
float bias = 2.0;
float coords1D = 1.789;
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
#line 53
color += texture (texSampler1D, coords1D);
color += texture (texSampler1D, coords1D, bias);
#line 102
color += texture (texSampler2D, coords2D);
color += texture (texSampler2D, coords2D, bias);
gl_FragColor = mix(color, u, blend * blendscale);
}
"
Name 5 "main"
Name 9 "blendscale"
Name 11 "bias"
Name 13 "coords1D"
Name 16 "color"
Name 22 "texSampler1D"
Name 37 "texSampler2D"
Name 41 "coords2D"
Name 53 "gl_FragColor"
Name 56 "u"
Name 59 "blend"
Decorate 22(texSampler1D) DescriptorSet 0
Decorate 37(texSampler2D) DescriptorSet 0
Decorate 53(gl_FragColor) Location 0
3: TypeVoid
4: TypeFunction 3
7: TypeFloat 32
8: TypePointer Function 7(float)
10: 7(float) Constant 1071971828
12: 7(float) Constant 1073741824
14: TypeVector 7(float) 4
15: TypePointer Function 14(fvec4)
17: 7(float) Constant 0
18: 14(fvec4) ConstantComposite 17 17 17 17
19: TypeImage 7(float) 1D sampled format:Unknown
20: TypeSampledImage 19
21: TypePointer UniformConstant 20
22(texSampler1D): 21(ptr) Variable UniformConstant
34: TypeImage 7(float) 2D sampled format:Unknown
35: TypeSampledImage 34
36: TypePointer UniformConstant 35
37(texSampler2D): 36(ptr) Variable UniformConstant
39: TypeVector 7(float) 2
40: TypePointer Input 39(fvec2)
41(coords2D): 40(ptr) Variable Input
52: TypePointer Output 14(fvec4)
53(gl_FragColor): 52(ptr) Variable Output
55: TypePointer Input 14(fvec4)
56(u): 55(ptr) Variable Input
58: TypePointer Input 7(float)
59(blend): 58(ptr) Variable Input
5(main): 3 Function None 4
6: Label
9(blendscale): 8(ptr) Variable Function
11(bias): 8(ptr) Variable Function
13(coords1D): 8(ptr) Variable Function
16(color): 15(ptr) Variable Function
Line 1 13 0
Store 9(blendscale) 10
Line 1 14 0
Store 11(bias) 12
Line 1 15 0
Store 13(coords1D) 10
Line 1 16 0
Store 16(color) 18
Line 1 54 0
23: 20 Load 22(texSampler1D)
24: 7(float) Load 13(coords1D)
25: 14(fvec4) ImageSampleImplicitLod 23 24
26: 14(fvec4) Load 16(color)
27: 14(fvec4) FAdd 26 25
Store 16(color) 27
Line 1 55 0
28: 20 Load 22(texSampler1D)
29: 7(float) Load 13(coords1D)
30: 7(float) Load 11(bias)
31: 14(fvec4) ImageSampleImplicitLod 28 29 Bias 30
32: 14(fvec4) Load 16(color)
33: 14(fvec4) FAdd 32 31
Store 16(color) 33
Line 1 103 0
38: 35 Load 37(texSampler2D)
42: 39(fvec2) Load 41(coords2D)
43: 14(fvec4) ImageSampleImplicitLod 38 42
44: 14(fvec4) Load 16(color)
45: 14(fvec4) FAdd 44 43
Store 16(color) 45
Line 1 104 0
46: 35 Load 37(texSampler2D)
47: 39(fvec2) Load 41(coords2D)
48: 7(float) Load 11(bias)
49: 14(fvec4) ImageSampleImplicitLod 46 47 Bias 48
50: 14(fvec4) Load 16(color)
51: 14(fvec4) FAdd 50 49
Store 16(color) 51
Line 1 106 0
54: 14(fvec4) Load 16(color)
57: 14(fvec4) Load 56(u)
60: 7(float) Load 59(blend)
61: 7(float) Load 9(blendscale)
62: 7(float) FMul 60 61
63: 14(fvec4) CompositeConstruct 62 62 62 62
64: 14(fvec4) ExtInst 2(GLSL.std.450) 46(FMix) 54 57 63
Store 53(gl_FragColor) 64
Return
FunctionEnd

40
Test/hlsl.pp.line2.frag Normal file
View file

@ -0,0 +1,40 @@
#line 1 "foo.frag"
Texture2D g_tColor[ 128 ] ;
layout (push_constant) cbuffer PerViewConstantBuffer_t
{
uint g_nDataIdx;
uint g_nDataIdx2;
bool g_B;
} ;
SamplerState g_sAniso;
struct PS_INPUT
{
float2 vTextureCoords : TEXCOORD2 ;
} ;
struct PS_OUTPUT
{
float4 vColor : SV_Target0 ;
} ;
PS_OUTPUT MainPs ( PS_INPUT i )
{
PS_OUTPUT ps_output ;
uint u;
#line 47
if (g_B)
#line 3 "foo.h"
u = g_nDataIdx;
else
#line 67
u = g_nDataIdx2;
#line 7 "foo2.h"
ps_output . vColor = g_tColor [ u ] . Sample ( g_sAniso , i . vTextureCoords . xy );
#line 105
return ps_output ;
}

34
Test/hlsl.pp.line3.frag Normal file
View file

@ -0,0 +1,34 @@
Texture2D g_tColor[ 128 ] ;
layout (push_constant) cbuffer PerViewConstantBuffer_t
{
uint g_nDataIdx;
uint g_nDataIdx2;
bool g_B;
} ;
SamplerState g_sAniso;
struct PS_INPUT
{
float2 vTextureCoords : TEXCOORD2 ;
} ;
struct PS_OUTPUT
{
float4 vColor : SV_Target0 ;
} ;
PS_OUTPUT MainPs ( PS_INPUT i )
{
PS_OUTPUT ps_output ;
uint u;
if (g_B)
#include "i1.h"
else
u = g_nDataIdx2;
ps_output . vColor = g_tColor [ u ] . Sample ( g_sAniso , i . vTextureCoords . xy );
return ps_output ;
}

1
Test/i1.h Normal file
View file

@ -0,0 +1 @@
u = g_nDataIdx;

View file

@ -152,6 +152,8 @@ $EXE -l -i include.vert > $TARGETDIR/include.vert.out
diff -b $BASEDIR/include.vert.out $TARGETDIR/include.vert.out || HASERROR=1
$EXE -D -Od -e main -H -Od -Iinc1/path1 -Iinc1/path2 hlsl.dashI.vert > $TARGETDIR/hlsl.dashI.vert.out
diff -b $BASEDIR/hlsl.dashI.vert.out $TARGETDIR/hlsl.dashI.vert.out || HASERROR=1
$EXE -D -Od -e MainPs -H -Od -g hlsl.pp.line3.frag > $TARGETDIR/hlsl.pp.line3.frag.out
diff -b $BASEDIR/hlsl.pp.line3.frag.out $TARGETDIR/hlsl.pp.line3.frag.out || HASERROR=1
#
# Testing -D and -U

25
Test/spv.pp.line.frag Normal file
View file

@ -0,0 +1,25 @@
#version 140
uniform sampler1D texSampler1D;
uniform sampler2D texSampler2D;
varying float blend;
varying vec4 u;
in vec2 coords2D;
void main()
{
float blendscale = 1.789;
float bias = 2.0;
float coords1D = 1.789;
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
#line 53
color += texture (texSampler1D, coords1D);
color += texture (texSampler1D, coords1D, bias);
#line 102
color += texture (texSampler2D, coords2D);
color += texture (texSampler2D, coords2D, bias);
gl_FragColor = mix(color, u, blend * blendscale);
}