Skip to content

Commit

Permalink
WIP: SPV Remapper: add remapper test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-lunarg committed Aug 25, 2016
1 parent 4c3a7fd commit a845641
Show file tree
Hide file tree
Showing 52 changed files with 3,067 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README-spirv-remap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ options. See REMAPPING AND OPTIMIZATION OPTIONS.
On error, the function supplied to registerErrorHandler() will be invoked.
This can be a standard C/C++ function, a lambda function, or a functor.
The default handler simply calls exit(5); The error handler is a static
members, so need only be set up once, not once per spirvbin_t instance.
member, so need only be set up once, not once per spirvbin_t instance.

Log messages are supplied to registerLogHandler(). By default, log
messages are eaten silently. The log handler is also a static member.
Expand Down
16 changes: 13 additions & 3 deletions SPIRV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ set(SOURCES
InReadableOrder.cpp
Logger.cpp
SpvBuilder.cpp
SPVRemapper.cpp
doc.cpp
disassemble.cpp)

set(SPVREMAP_SOURCES
SPVRemapper.cpp
doc.cpp)

set(HEADERS
spirv.hpp
GLSL.std.450.h
GlslangToSpv.h
Logger.h
SpvBuilder.h
SPVRemapper.h
spvIR.h
doc.h
disassemble.h)

set(SPVREMAP_HEADERS
SPVRemapper.h
doc.h)

if(ENABLE_AMD_EXTENSIONS)
set(HEADERS
GLSL.ext.AMD.h)
Expand All @@ -26,9 +32,13 @@ endif(ENABLE_AMD_EXTENSIONS)
add_library(SPIRV STATIC ${SOURCES} ${HEADERS})
set_property(TARGET SPIRV PROPERTY FOLDER glslang)

add_library(SPVRemapper STATIC ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
set_property(TARGET SPVRemapper PROPERTY FOLDER glslang)

if(WIN32)
source_group("Source" FILES ${SOURCES} ${HEADERS})
source_group("Source" FILES ${SPVREMAP_SOURCES} ${SPVREMAP_HEADERS})
endif(WIN32)

install(TARGETS SPIRV
install(TARGETS SPIRV SPVRemapper
ARCHIVE DESTINATION lib)
2 changes: 1 addition & 1 deletion SPIRV/SPVRemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class spirvbin_t : public spirvbin_base_t
public:
spirvbin_t(int /*verbose = 0*/) { }

void remap(std::vector<unsigned int>& /*spv*/, unsigned int /*opts = 0*/)
void remap(std::vector<std::uint32_t>& /*spv*/, unsigned int /*opts = 0*/)
{
printf("Tool not compiled for C++11, which is required for SPIR-V remapping.\n");
exit(5);
Expand Down
10 changes: 6 additions & 4 deletions SPIRV/disassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ void SpirvStream::outputIndent()

void SpirvStream::formatId(Id id, std::stringstream& idStream)
{
if (id >= bound)
Kill(out, "Bad <id>");

if (id != 0) {
// On instructions with no IDs, this is called with "0", which does not
// have to be within ID bounds on null shaders.
if (id >= bound)
Kill(out, "Bad <id>");

idStream << id;
if (idDescriptor[id].size() > 0)
idStream << "(" << idDescriptor[id] << ")";
Expand Down Expand Up @@ -334,7 +336,7 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
idDescriptor[resultId] = (const char*)(&stream[word]);
}
else {
if (idDescriptor[resultId].size() == 0) {
if (resultId != 0 && idDescriptor[resultId].size() == 0) {
switch (opCode) {
case OpTypeInt:
idDescriptor[resultId] = "int";
Expand Down
1 change: 1 addition & 0 deletions StandAlone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(LIBRARIES
OSDependent
HLSL
SPIRV
SPVRemapper
glslang-default-resource-limits)

if(WIN32)
Expand Down
40 changes: 40 additions & 0 deletions Test/baseResults/remap.basic.dcefunc.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
remap.basic.dcefunc.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.


Linked fragment stage:


// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 19

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 14 16
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Name 9 "dead_fn("
Name 14 "outf4"
Name 16 "inf"
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 3
8: TypeFunction 7(fvec3)
10: 6(float) Constant 0
11: 7(fvec3) ConstantComposite 10 10 10
12: TypeVector 6(float) 4
13: TypePointer Output 12(fvec4)
14(outf4): 13(ptr) Variable Output
15: TypePointer Input 6(float)
16(inf): 15(ptr) Variable Input
4(main): 2 Function None 3
5: Label
17: 6(float) Load 16(inf)
18: 12(fvec4) CompositeConstruct 17 17 17 17
Store 14(outf4) 18
Return
FunctionEnd
12 changes: 12 additions & 0 deletions Test/baseResults/remap.basic.dcevartype.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
remap.basic.dcevartype.frag
ERROR: #version: ES shaders for Vulkan SPIR-V require version 310 or higher
Warning, version 310 is not yet complete; most version-specific features are present, but some are missing.
ERROR: 1 compilation errors. No code generated.



Linked fragment stage:

ERROR: Linking fragment stage: Missing entry point: Each stage requires one "void main()" entry point

SPIR-V is not generated for failed compile or link
31 changes: 31 additions & 0 deletions Test/baseResults/remap.basic.everything.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
remap.basic.everything.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.


Linked fragment stage:


// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 24969

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 5663 "main" 4539 3773
ExecutionMode 5663 OriginUpperLeft
8: TypeVoid
1282: TypeFunction 8
13: TypeFloat 32
29: TypeVector 13(float) 4
666: TypePointer Output 29(fvec4)
4539: 666(ptr) Variable Output
650: TypePointer Input 13(float)
3773: 650(ptr) Variable Input
5663: 8 Function None 1282
24968: Label
17486: 13(float) Load 3773
17691: 29(fvec4) CompositeConstruct 17486 17486 17486 17486
Store 4539 17691
Return
FunctionEnd
44 changes: 44 additions & 0 deletions Test/baseResults/remap.basic.none.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
remap.basic.none.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.


Linked fragment stage:


// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 20

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 15 17
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Name 9 "dead_fn("
Name 15 "outf4"
Name 17 "inf"
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 3
8: TypeFunction 7(fvec3)
11: 6(float) Constant 0
12: 7(fvec3) ConstantComposite 11 11 11
13: TypeVector 6(float) 4
14: TypePointer Output 13(fvec4)
15(outf4): 14(ptr) Variable Output
16: TypePointer Input 6(float)
17(inf): 16(ptr) Variable Input
4(main): 2 Function None 3
5: Label
18: 6(float) Load 17(inf)
19: 13(fvec4) CompositeConstruct 18 18 18 18
Store 15(outf4) 19
Return
FunctionEnd
9(dead_fn(): 7(fvec3) Function None 8
10: Label
ReturnValue 12
FunctionEnd
39 changes: 39 additions & 0 deletions Test/baseResults/remap.basic.strip.frag.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
remap.basic.strip.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.


Linked fragment stage:


// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 20

Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 15 17
ExecutionMode 4 OriginUpperLeft
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 3
8: TypeFunction 7(fvec3)
11: 6(float) Constant 0
12: 7(fvec3) ConstantComposite 11 11 11
13: TypeVector 6(float) 4
14: TypePointer Output 13(fvec4)
15: 14(ptr) Variable Output
16: TypePointer Input 6(float)
17: 16(ptr) Variable Input
4: 2 Function None 3
5: Label
18: 6(float) Load 17
19: 13(fvec4) CompositeConstruct 18 18 18 18
Store 15 19
Return
FunctionEnd
9: 7(fvec3) Function None 8
10: Label
ReturnValue 12
FunctionEnd
Loading

0 comments on commit a845641

Please sign in to comment.