Strip debug info from SPIR-V binaries
authorPyry Haulos <phaulos@google.com>
Thu, 21 Jul 2016 21:38:04 +0000 (14:38 -0700)
committerPyry Haulos <phaulos@google.com>
Fri, 29 Jul 2016 16:38:36 +0000 (09:38 -0700)
This requires updating glslang to fix ID remapping problem in SPIR-V
remapper.

Fixes #391

external/fetch_sources.py
external/vulkancts/framework/vulkan/vkGlslToSpirV.cpp
external/vulkancts/framework/vulkan/vkGlslToSpirV.hpp
external/vulkancts/framework/vulkan/vkPrograms.cpp

index 7f16b25..6a68bf5 100644 (file)
@@ -174,7 +174,7 @@ PACKAGES = [
                "spirv-tools"),
        GitRepo(
                "https://github.com/KhronosGroup/glslang.git",
-               "d02dc5d05ad1f63db8d37fda9928a4d59e3c132d",
+               "b8d2a006d1688a8590b5ae2a8df1aba1e6fbed0b",
                "glslang"),
 ]
 
index 8f1c10c..c2740a3 100644 (file)
@@ -32,6 +32,7 @@
 #if defined(DEQP_HAVE_GLSLANG)
 #      include "SPIRV/GlslangToSpv.h"
 #      include "SPIRV/disassemble.h"
+#      include "SPIRV/SPVRemapper.h"
 #      include "SPIRV/doc.h"
 #      include "glslang/Include/InfoSink.h"
 #      include "glslang/Include/ShHandle.h"
@@ -271,6 +272,16 @@ bool compileGlslToSpirV (const glu::ProgramSources& program, std::vector<deUint3
        TCU_THROW(InternalError, "Can't compile empty program");
 }
 
+void stripSpirVDebugInfo (const size_t numSrcInstrs, const deUint32* srcInstrs, std::vector<deUint32>* dst)
+{
+       spv::spirvbin_t remapper;
+
+       // glslang operates in-place
+       dst->resize(numSrcInstrs);
+       std::copy(srcInstrs, srcInstrs+numSrcInstrs, dst->begin());
+       remapper.remap(*dst, spv::spirvbin_base_t::STRIP);
+}
+
 #else // defined(DEQP_HAVE_GLSLANG)
 
 bool compileGlslToSpirV (const glu::ProgramSources&, std::vector<deUint32>*, glu::ShaderProgramInfo*)
@@ -278,6 +289,11 @@ bool compileGlslToSpirV (const glu::ProgramSources&, std::vector<deUint32>*, glu
        TCU_THROW(NotSupportedError, "GLSL to SPIR-V compilation not supported (DEQP_HAVE_GLSLANG not defined)");
 }
 
+void stripSpirVDebugInfo (const size_t, const deUint32*, std::vector<deUint32>*)
+{
+       TCU_THROW(NotSupportedError, "SPIR-V stripping not supported (DEQP_HAVE_GLSLANG not defined)");
+}
+
 #endif // defined(DEQP_HAVE_GLSLANG)
 
 } // vk
index e3fb112..a32ace9 100644 (file)
@@ -47,6 +47,18 @@ namespace vk
  *//*--------------------------------------------------------------------*/
 bool   compileGlslToSpirV              (const glu::ProgramSources& src, std::vector<deUint32>* dst, glu::ShaderProgramInfo* buildInfo);
 
+/*--------------------------------------------------------------------*//*!
+ * \brief Strip SPIR-V binary
+ * \param src
+ * \param dst
+ *
+ * Removes OpName and OpMemberName opcodes from SPIR-V binary
+ *
+ * If deqp was built without glslang (and thus compiler is not available)
+ * tcu::NotSupportedError will be thrown instead.
+ *//*--------------------------------------------------------------------*/
+void   stripSpirVDebugInfo             (const size_t numSrcInstrs, const deUint32* srcInstrs, std::vector<deUint32>* dst);
+
 } // vk
 
 #endif // _VKGLSLTOSPIRV_HPP
index 4d0a567..325f431 100644 (file)
@@ -110,8 +110,16 @@ ProgramBinary* buildProgram (const glu::ProgramSources& program, ProgramFormat b
        {
                vector<deUint32> binary;
 
-               if (!compileGlslToSpirV(program, &binary, buildInfo))
-                       TCU_THROW(InternalError, "Compiling GLSL to SPIR-V failed");
+               {
+                       vector<deUint32> nonStrippedBinary;
+
+                       if (!compileGlslToSpirV(program, &nonStrippedBinary, buildInfo))
+                               TCU_THROW(InternalError, "Compiling GLSL to SPIR-V failed");
+
+                       TCU_CHECK_INTERNAL(!nonStrippedBinary.empty());
+                       stripSpirVDebugInfo(nonStrippedBinary.size(), &nonStrippedBinary[0], &binary);
+                       TCU_CHECK_INTERNAL(!binary.empty());
+               }
 
                if (validateBinary)
                {