Commit 4217d2ea by John Kessenich

SPIR-V compression: Add stripping and remapping tools for compressibility of generated SPIR-V.

parent 3a44d7fe
...@@ -13,6 +13,10 @@ else(WIN32) ...@@ -13,6 +13,10 @@ else(WIN32)
message("unkown platform") message("unkown platform")
endif(WIN32) endif(WIN32)
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-std=c++11)
endif()
add_subdirectory(glslang) add_subdirectory(glslang)
add_subdirectory(OGLCompilersDLL) add_subdirectory(OGLCompilersDLL)
add_subdirectory(StandAlone) add_subdirectory(StandAlone)
......
...@@ -5,6 +5,7 @@ include_directories(.. ${CMAKE_CURRENT_BINARY_DIR}) ...@@ -5,6 +5,7 @@ include_directories(.. ${CMAKE_CURRENT_BINARY_DIR})
set(SOURCES set(SOURCES
GlslangToSpv.cpp GlslangToSpv.cpp
SpvBuilder.cpp SpvBuilder.cpp
SPVRemapper.cpp
doc.cpp doc.cpp
disassemble.cpp) disassemble.cpp)
...@@ -12,6 +13,7 @@ set(HEADERS ...@@ -12,6 +13,7 @@ set(HEADERS
spirv.h spirv.h
GlslangToSpv.h GlslangToSpv.h
SpvBuilder.h SpvBuilder.h
SPVRemapper.h
spvIR.h spvIR.h
doc.h doc.h
disassemble.h) disassemble.h)
......
...@@ -871,6 +871,14 @@ EnumParameters KernelProfilingInfoParams[KernelProfilingInfoCeiling]; ...@@ -871,6 +871,14 @@ EnumParameters KernelProfilingInfoParams[KernelProfilingInfoCeiling];
// Set up all the parameterizing descriptions of the opcodes, operands, etc. // Set up all the parameterizing descriptions of the opcodes, operands, etc.
void Parameterize() void Parameterize()
{ {
static bool initialized = false;
// only do this once.
if (initialized)
return;
initialized = true;
// Exceptions to having a result <id> and a resulting type <id>. // Exceptions to having a result <id> and a resulting type <id>.
// (Everything is initialized to have both). // (Everything is initialized to have both).
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "../SPIRV/GLSL450Lib.h" #include "../SPIRV/GLSL450Lib.h"
#include "../SPIRV/doc.h" #include "../SPIRV/doc.h"
#include "../SPIRV/disassemble.h" #include "../SPIRV/disassemble.h"
#include "../SPIRV/SPVRemapper.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
...@@ -71,6 +72,8 @@ enum TOptions { ...@@ -71,6 +72,8 @@ enum TOptions {
EOptionSpv = 0x0800, EOptionSpv = 0x0800,
EOptionHumanReadableSpv = 0x1000, EOptionHumanReadableSpv = 0x1000,
EOptionDefaultDesktop = 0x2000, EOptionDefaultDesktop = 0x2000,
EOptionCanonicalizeSpv = 0x4000,
EOptionStripSpv = 0x8000,
}; };
// //
...@@ -481,11 +484,17 @@ bool ProcessArguments(int argc, char* argv[]) ...@@ -481,11 +484,17 @@ bool ProcessArguments(int argc, char* argv[])
for (; argc >= 1; argc--, argv++) { for (; argc >= 1; argc--, argv++) {
Work[argc] = 0; Work[argc] = 0;
if (argv[0][0] == '-') { if (argv[0][0] == '-') {
switch (argv[0][1]) { const char optLetter = argv[0][1];
case 'H':
Options |= EOptionHumanReadableSpv; switch (optLetter) {
// fall through to -V case 'S': // fall through to -V
case 'C': // fall through to -V
case 'H': // fall through to -V
case 'V': case 'V':
if (optLetter == 'H') Options |= EOptionHumanReadableSpv;
if (optLetter == 'S') Options |= EOptionStripSpv;
if (optLetter == 'C') Options |= EOptionCanonicalizeSpv;
Options |= EOptionSpv; Options |= EOptionSpv;
Options |= EOptionLinkProgram; Options |= EOptionLinkProgram;
break; break;
...@@ -660,7 +669,15 @@ void CompileAndLinkShaders() ...@@ -660,7 +669,15 @@ void CompileAndLinkShaders()
case EShLangCompute: name = "comp"; break; case EShLangCompute: name = "comp"; break;
default: name = "unknown"; break; default: name = "unknown"; break;
} }
glslang::OutputSpv(spirv, name); if (Options & (EOptionCanonicalizeSpv | EOptionStripSpv)) {
const unsigned int remapOpts =
((Options & EOptionCanonicalizeSpv) ? (spv::spirvbin_t::ALL_BUT_STRIP) : 0) |
((Options & EOptionStripSpv) ? (spv::spirvbin_t::STRIP) : 0);
spv::Parameterize();
spv::spirvbin_t().remap(spirv, remapOpts);
}
if (Options & EOptionHumanReadableSpv) { if (Options & EOptionHumanReadableSpv) {
spv::Parameterize(); spv::Parameterize();
GLSL_STD_450::GetDebugNames(GlslStd450DebugNames); GLSL_STD_450::GetDebugNames(GlslStd450DebugNames);
...@@ -867,6 +884,8 @@ void usage() ...@@ -867,6 +884,8 @@ void usage()
"To get other information, use one of the following options:\n" "To get other information, use one of the following options:\n"
"(Each option must be specified separately, but can go anywhere in the command line.)\n" "(Each option must be specified separately, but can go anywhere in the command line.)\n"
" -V create SPIR-V in file <stage>.spv\n" " -V create SPIR-V in file <stage>.spv\n"
" -C canonicalize generated SPIR-V: turns on -V\n"
" -S debug-strip SPIR-V: turns on -V\n"
" -H print human readable form of SPIR-V; turns on -V\n" " -H print human readable form of SPIR-V; turns on -V\n"
" -c configuration dump; use to create default configuration file (redirect to a .conf file)\n" " -c configuration dump; use to create default configuration file (redirect to a .conf file)\n"
" -d default to desktop (#version 110) when there is no version in the shader (default is ES version 100)\n" " -d default to desktop (#version 110) when there is no version in the shader (default is ES version 100)\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment