Skip to content

Commit a845641

Browse files
author
steve-lunarg
committed
WIP: SPV Remapper: add remapper test framework
1 parent 4c3a7fd commit a845641

File tree

52 files changed

+3067
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3067
-9
lines changed

README-spirv-remap.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ options. See REMAPPING AND OPTIMIZATION OPTIONS.
9898
On error, the function supplied to registerErrorHandler() will be invoked.
9999
This can be a standard C/C++ function, a lambda function, or a functor.
100100
The default handler simply calls exit(5); The error handler is a static
101-
members, so need only be set up once, not once per spirvbin_t instance.
101+
member, so need only be set up once, not once per spirvbin_t instance.
102102

103103
Log messages are supplied to registerLogHandler(). By default, log
104104
messages are eaten silently. The log handler is also a static member.

SPIRV/CMakeLists.txt

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@ set(SOURCES
33
InReadableOrder.cpp
44
Logger.cpp
55
SpvBuilder.cpp
6-
SPVRemapper.cpp
76
doc.cpp
87
disassemble.cpp)
98

9+
set(SPVREMAP_SOURCES
10+
SPVRemapper.cpp
11+
doc.cpp)
12+
1013
set(HEADERS
1114
spirv.hpp
1215
GLSL.std.450.h
1316
GlslangToSpv.h
1417
Logger.h
1518
SpvBuilder.h
16-
SPVRemapper.h
1719
spvIR.h
1820
doc.h
1921
disassemble.h)
2022

23+
set(SPVREMAP_HEADERS
24+
SPVRemapper.h
25+
doc.h)
26+
2127
if(ENABLE_AMD_EXTENSIONS)
2228
set(HEADERS
2329
GLSL.ext.AMD.h)
@@ -26,9 +32,13 @@ endif(ENABLE_AMD_EXTENSIONS)
2632
add_library(SPIRV STATIC ${SOURCES} ${HEADERS})
2733
set_property(TARGET SPIRV PROPERTY FOLDER glslang)
2834

35+
add_library(SPVRemapper STATIC ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
36+
set_property(TARGET SPVRemapper PROPERTY FOLDER glslang)
37+
2938
if(WIN32)
3039
source_group("Source" FILES ${SOURCES} ${HEADERS})
40+
source_group("Source" FILES ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
3141
endif(WIN32)
3242

33-
install(TARGETS SPIRV
43+
install(TARGETS SPIRV SPVRemapper
3444
ARCHIVE DESTINATION lib)

SPIRV/SPVRemapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class spirvbin_t : public spirvbin_base_t
8282
public:
8383
spirvbin_t(int /*verbose = 0*/) { }
8484

85-
void remap(std::vector<unsigned int>& /*spv*/, unsigned int /*opts = 0*/)
85+
void remap(std::vector<std::uint32_t>& /*spv*/, unsigned int /*opts = 0*/)
8686
{
8787
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
8888
exit(5);

SPIRV/disassemble.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ void SpirvStream::outputIndent()
217217

218218
void SpirvStream::formatId(Id id, std::stringstream& idStream)
219219
{
220-
if (id >= bound)
221-
Kill(out, "Bad <id>");
222-
223220
if (id != 0) {
221+
// On instructions with no IDs, this is called with "0", which does not
222+
// have to be within ID bounds on null shaders.
223+
if (id >= bound)
224+
Kill(out, "Bad <id>");
225+
224226
idStream << id;
225227
if (idDescriptor[id].size() > 0)
226228
idStream << "(" << idDescriptor[id] << ")";
@@ -334,7 +336,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
334336
idDescriptor[resultId] = (const char*)(&stream[word]);
335337
}
336338
else {
337-
if (idDescriptor[resultId].size() == 0) {
339+
if (resultId != 0 && idDescriptor[resultId].size() == 0) {
338340
switch (opCode) {
339341
case OpTypeInt:
340342
idDescriptor[resultId] = "int";

StandAlone/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(LIBRARIES
2424
OSDependent
2525
HLSL
2626
SPIRV
27+
SPVRemapper
2728
glslang-default-resource-limits)
2829

2930
if(WIN32)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
remap.basic.dcefunc.frag
2+
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
3+
4+
5+
Linked fragment stage:
6+
7+
8+
// Module Version 10000
9+
// Generated by (magic number): 80001
10+
// Id's are bound by 19
11+
12+
Capability Shader
13+
1: ExtInstImport "GLSL.std.450"
14+
MemoryModel Logical GLSL450
15+
EntryPoint Fragment 4 "main" 14 16
16+
ExecutionMode 4 OriginUpperLeft
17+
Source GLSL 450
18+
Name 4 "main"
19+
Name 9 "dead_fn("
20+
Name 14 "outf4"
21+
Name 16 "inf"
22+
2: TypeVoid
23+
3: TypeFunction 2
24+
6: TypeFloat 32
25+
7: TypeVector 6(float) 3
26+
8: TypeFunction 7(fvec3)
27+
10: 6(float) Constant 0
28+
11: 7(fvec3) ConstantComposite 10 10 10
29+
12: TypeVector 6(float) 4
30+
13: TypePointer Output 12(fvec4)
31+
14(outf4): 13(ptr) Variable Output
32+
15: TypePointer Input 6(float)
33+
16(inf): 15(ptr) Variable Input
34+
4(main): 2 Function None 3
35+
5: Label
36+
17: 6(float) Load 16(inf)
37+
18: 12(fvec4) CompositeConstruct 17 17 17 17
38+
Store 14(outf4) 18
39+
Return
40+
FunctionEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
remap.basic.dcevartype.frag
2+
ERROR: #version: ES shaders for Vulkan SPIR-V require version 310 or higher
3+
Warning, version 310 is not yet complete; most version-specific features are present, but some are missing.
4+
ERROR: 1 compilation errors. No code generated.
5+
6+
7+
8+
Linked fragment stage:
9+
10+
ERROR: Linking fragment stage: Missing entry point: Each stage requires one "void main()" entry point
11+
12+
SPIR-V is not generated for failed compile or link
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
remap.basic.everything.frag
2+
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
3+
4+
5+
Linked fragment stage:
6+
7+
8+
// Module Version 10000
9+
// Generated by (magic number): 80001
10+
// Id's are bound by 24969
11+
12+
Capability Shader
13+
1: ExtInstImport "GLSL.std.450"
14+
MemoryModel Logical GLSL450
15+
EntryPoint Fragment 5663 "main" 4539 3773
16+
ExecutionMode 5663 OriginUpperLeft
17+
8: TypeVoid
18+
1282: TypeFunction 8
19+
13: TypeFloat 32
20+
29: TypeVector 13(float) 4
21+
666: TypePointer Output 29(fvec4)
22+
4539: 666(ptr) Variable Output
23+
650: TypePointer Input 13(float)
24+
3773: 650(ptr) Variable Input
25+
5663: 8 Function None 1282
26+
24968: Label
27+
17486: 13(float) Load 3773
28+
17691: 29(fvec4) CompositeConstruct 17486 17486 17486 17486
29+
Store 4539 17691
30+
Return
31+
FunctionEnd
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
remap.basic.none.frag
2+
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
3+
4+
5+
Linked fragment stage:
6+
7+
8+
// Module Version 10000
9+
// Generated by (magic number): 80001
10+
// Id's are bound by 20
11+
12+
Capability Shader
13+
1: ExtInstImport "GLSL.std.450"
14+
MemoryModel Logical GLSL450
15+
EntryPoint Fragment 4 "main" 15 17
16+
ExecutionMode 4 OriginUpperLeft
17+
Source GLSL 450
18+
Name 4 "main"
19+
Name 9 "dead_fn("
20+
Name 15 "outf4"
21+
Name 17 "inf"
22+
2: TypeVoid
23+
3: TypeFunction 2
24+
6: TypeFloat 32
25+
7: TypeVector 6(float) 3
26+
8: TypeFunction 7(fvec3)
27+
11: 6(float) Constant 0
28+
12: 7(fvec3) ConstantComposite 11 11 11
29+
13: TypeVector 6(float) 4
30+
14: TypePointer Output 13(fvec4)
31+
15(outf4): 14(ptr) Variable Output
32+
16: TypePointer Input 6(float)
33+
17(inf): 16(ptr) Variable Input
34+
4(main): 2 Function None 3
35+
5: Label
36+
18: 6(float) Load 17(inf)
37+
19: 13(fvec4) CompositeConstruct 18 18 18 18
38+
Store 15(outf4) 19
39+
Return
40+
FunctionEnd
41+
9(dead_fn(): 7(fvec3) Function None 8
42+
10: Label
43+
ReturnValue 12
44+
FunctionEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
remap.basic.strip.frag
2+
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
3+
4+
5+
Linked fragment stage:
6+
7+
8+
// Module Version 10000
9+
// Generated by (magic number): 80001
10+
// Id's are bound by 20
11+
12+
Capability Shader
13+
1: ExtInstImport "GLSL.std.450"
14+
MemoryModel Logical GLSL450
15+
EntryPoint Fragment 4 "main" 15 17
16+
ExecutionMode 4 OriginUpperLeft
17+
2: TypeVoid
18+
3: TypeFunction 2
19+
6: TypeFloat 32
20+
7: TypeVector 6(float) 3
21+
8: TypeFunction 7(fvec3)
22+
11: 6(float) Constant 0
23+
12: 7(fvec3) ConstantComposite 11 11 11
24+
13: TypeVector 6(float) 4
25+
14: TypePointer Output 13(fvec4)
26+
15: 14(ptr) Variable Output
27+
16: TypePointer Input 6(float)
28+
17: 16(ptr) Variable Input
29+
4: 2 Function None 3
30+
5: Label
31+
18: 6(float) Load 17
32+
19: 13(fvec4) CompositeConstruct 18 18 18 18
33+
Store 15 19
34+
Return
35+
FunctionEnd
36+
9: 7(fvec3) Function None 8
37+
10: Label
38+
ReturnValue 12
39+
FunctionEnd

0 commit comments

Comments
 (0)