HLSL: Add an Includer to handle #include.

This commit is contained in:
John Kessenich
2017-05-22 15:00:42 -06:00
parent 44d2728e3d
commit 3494b4da9b
22 changed files with 362 additions and 19 deletions

1
Test/bar.h Normal file
View File

@@ -0,0 +1 @@
float4 i1;

View File

@@ -0,0 +1,75 @@
../Test/hlsl.include.vert
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 44
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" 42
Source HLSL 500
Name 4 "main"
Name 9 "@main("
Name 11 "$Global"
MemberName 11($Global) 0 "i1"
MemberName 11($Global) 1 "i2"
MemberName 11($Global) 2 "i4"
MemberName 11($Global) 3 "i3"
MemberName 11($Global) 4 "i6"
MemberName 11($Global) 5 "i5"
Name 13 ""
Name 42 "@entryPointOutput"
MemberDecorate 11($Global) 0 Offset 0
MemberDecorate 11($Global) 1 Offset 16
MemberDecorate 11($Global) 2 Offset 32
MemberDecorate 11($Global) 3 Offset 48
MemberDecorate 11($Global) 4 Offset 64
MemberDecorate 11($Global) 5 Offset 80
Decorate 11($Global) Block
Decorate 13 DescriptorSet 0
Decorate 42(@entryPointOutput) BuiltIn Position
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypeFunction 7(fvec4)
11($Global): TypeStruct 7(fvec4) 7(fvec4) 7(fvec4) 7(fvec4) 7(fvec4) 7(fvec4)
12: TypePointer Uniform 11($Global)
13: 12(ptr) Variable Uniform
14: TypeInt 32 1
15: 14(int) Constant 0
16: TypePointer Uniform 7(fvec4)
19: 14(int) Constant 1
23: 14(int) Constant 3
27: 14(int) Constant 2
31: 14(int) Constant 5
35: 14(int) Constant 4
41: TypePointer Output 7(fvec4)
42(@entryPointOutput): 41(ptr) Variable Output
4(main): 2 Function None 3
5: Label
43: 7(fvec4) FunctionCall 9(@main()
Store 42(@entryPointOutput) 43
Return
FunctionEnd
9(@main(): 7(fvec4) Function None 8
10: Label
17: 16(ptr) AccessChain 13 15
18: 7(fvec4) Load 17
20: 16(ptr) AccessChain 13 19
21: 7(fvec4) Load 20
22: 7(fvec4) FAdd 18 21
24: 16(ptr) AccessChain 13 23
25: 7(fvec4) Load 24
26: 7(fvec4) FAdd 22 25
28: 16(ptr) AccessChain 13 27
29: 7(fvec4) Load 28
30: 7(fvec4) FAdd 26 29
32: 16(ptr) AccessChain 13 31
33: 7(fvec4) Load 32
34: 7(fvec4) FAdd 30 33
36: 16(ptr) AccessChain 13 35
37: 7(fvec4) Load 36
38: 7(fvec4) FAdd 34 37
ReturnValue 38
FunctionEnd

View File

@@ -0,0 +1,10 @@
hlsl.includeNegative.vert
ERROR: ./foo.h:1: '#error' : should not be included
ERROR: ./inc2/../foo.h:1: '#error' : should not be included
ERROR: ./parentBad:3: '#error' : bad parent
ERROR: hlsl.includeNegative.vert:7: '#error' : in main
hlsl.includeNegative.vert(8): error at column 0, HLSL parsing failed.
ERROR: 5 compilation errors. No code generated.
SPIR-V is not generated for failed compile or link

View File

@@ -0,0 +1,69 @@
include.vert
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
Shader version: 450
Requested GL_GOOGLE_cpp_style_line_directive
Requested GL_GOOGLE_include_directive
0:? Sequence
0:13 Function Definition: main( ( global void)
0:13 Function Parameters:
0:15 Sequence
0:15 move second child to first child ( temp 4-component vector of float)
0:15 'color' ( smooth out 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 'i1' ( global 4-component vector of float)
0:15 'i2' ( global 4-component vector of float)
0:15 'i3' ( global 4-component vector of float)
0:15 'i4' ( global 4-component vector of float)
0:15 'i5' ( global 4-component vector of float)
0:15 'i6' ( global 4-component vector of float)
0:? Linker Objects
0:? 'i1' ( global 4-component vector of float)
0:? 'i2' ( global 4-component vector of float)
0:? 'i4' ( global 4-component vector of float)
0:? 'i3' ( global 4-component vector of float)
0:? 'i6' ( global 4-component vector of float)
0:? 'i5' ( global 4-component vector of float)
0:? 'color' ( smooth out 4-component vector of float)
0:? 'gl_VertexID' ( gl_VertexId int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId)
Linked vertex stage:
Shader version: 450
Requested GL_GOOGLE_cpp_style_line_directive
Requested GL_GOOGLE_include_directive
0:? Sequence
0:13 Function Definition: main( ( global void)
0:13 Function Parameters:
0:15 Sequence
0:15 move second child to first child ( temp 4-component vector of float)
0:15 'color' ( smooth out 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 add ( temp 4-component vector of float)
0:15 'i1' ( global 4-component vector of float)
0:15 'i2' ( global 4-component vector of float)
0:15 'i3' ( global 4-component vector of float)
0:15 'i4' ( global 4-component vector of float)
0:15 'i5' ( global 4-component vector of float)
0:15 'i6' ( global 4-component vector of float)
0:? Linker Objects
0:? 'i1' ( global 4-component vector of float)
0:? 'i2' ( global 4-component vector of float)
0:? 'i4' ( global 4-component vector of float)
0:? 'i3' ( global 4-component vector of float)
0:? 'i6' ( global 4-component vector of float)
0:? 'i5' ( global 4-component vector of float)
0:? 'color' ( smooth out 4-component vector of float)
0:? 'gl_VertexID' ( gl_VertexId int VertexId)
0:? 'gl_InstanceID' ( gl_InstanceId int InstanceId)

1
Test/foo.h Normal file
View File

@@ -0,0 +1 @@
#error should not be included

8
Test/hlsl.include.vert Normal file
View File

@@ -0,0 +1,8 @@
#include "bar.h"
#include "./inc1/bar.h"
#include "inc2\bar.h"
float4 main() : SV_Position
{
return i1 + i2 + i3 + i4 + i5 + i6;
}

View File

@@ -0,0 +1,8 @@
#include "foo.h"
#include "inc2/../foo.h"
#include "inc1/badInc.h"
float4 main() : SV_Position
{
#error in main
}

1
Test/inc1/badInc.h Normal file
View File

@@ -0,0 +1 @@
#include "parentBad"

3
Test/inc1/bar.h Normal file
View File

@@ -0,0 +1,3 @@
float4 i2;
#include "foo.h"

3
Test/inc1/foo.h Normal file
View File

@@ -0,0 +1,3 @@
#include "parent.h"
float4 i3;

2
Test/inc2/bar.h Normal file
View File

@@ -0,0 +1,2 @@
#include "foo.h"
float4 i5;

1
Test/inc2/foo.h Normal file
View File

@@ -0,0 +1 @@
float4 i6;

16
Test/include.vert Normal file
View File

@@ -0,0 +1,16 @@
#version 450
#extension GL_GOOGLE_include_directive : enable
#define float4 vec4
#include "bar.h"
#include "./inc1/bar.h"
#include "inc2\bar.h"
out vec4 color;
void main()
{
color = i1 + i2 + i3 + i4 + i5 + i6;
}

1
Test/parent.h Normal file
View File

@@ -0,0 +1 @@
float4 i4;

3
Test/parentBad Normal file
View File

@@ -0,0 +1,3 @@
int a;
#error bad parent

View File

@@ -106,6 +106,17 @@ echo Testing SPV Debug Information
$EXE -g -H spv.debugInfo.frag > $TARGETDIR/spv.debugInfo.frag.out
diff -b $BASEDIR/spv.debugInfo.frag.out $TARGETDIR/spv.debugInfo.frag.out || HASERROR=1
#
# Testing Includer
#
echo Testing Includer
$EXE -D -e main -H ../Test/hlsl.include.vert > $TARGETDIR/hlsl.include.vert.out
diff -b $BASEDIR/hlsl.include.vert.out $TARGETDIR/hlsl.include.vert.out || HASERROR=1
$EXE -D -e main -H hlsl.includeNegative.vert > $TARGETDIR/hlsl.includeNegative.vert.out
diff -b $BASEDIR/hlsl.includeNegative.vert.out $TARGETDIR/hlsl.includeNegative.vert.out || HASERROR=1
$EXE -l -i include.vert > $TARGETDIR/include.vert.out
diff -b $BASEDIR/include.vert.out $TARGETDIR/include.vert.out || HASERROR=1
#
# Final checking
#