From 2eed8236d07d50f35c466d723651d86284c60161 Mon Sep 17 00:00:00 2001 From: pheonix Date: Sun, 27 Sep 2020 16:53:18 -0700 Subject: [PATCH] Add more flexible SpirvToolsDisassemble interface to allow specifying spv_target_env for disassembly output. (#2406) Improve documentation on existing SpirvToolsDisassemble interface. Fix cmake build scripts to account for `spirv-tools` external when -DENABLE_OPT=ON --- SPIRV/SpvTools.cpp | 12 +++++++++--- SPIRV/SpvTools.h | 7 ++++++- StandAlone/CMakeLists.txt | 6 ++++++ gtests/CMakeLists.txt | 6 ++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/SPIRV/SpvTools.cpp b/SPIRV/SpvTools.cpp index 112ac33..fce1fb9 100644 --- a/SPIRV/SpvTools.cpp +++ b/SPIRV/SpvTools.cpp @@ -44,7 +44,6 @@ #include "SpvTools.h" #include "spirv-tools/optimizer.hpp" -#include "spirv-tools/libspirv.h" namespace glslang { @@ -114,11 +113,18 @@ void OptimizerMesssageConsumer(spv_message_level_t level, const char *source, out << std::endl; } -// Use the SPIRV-Tools disassembler to print SPIR-V. +// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment. void SpirvToolsDisassemble(std::ostream& out, const std::vector& spirv) { + SpirvToolsDisassemble(out, spirv, SPV_ENV_UNIVERSAL_1_3); +} + +// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment. +void SpirvToolsDisassemble(std::ostream& out, const std::vector& spirv, + spv_target_env requested_context) +{ // disassemble - spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3); + spv_context context = spvContextCreate(requested_context); spv_text text; spv_diagnostic diagnostic = nullptr; spvBinaryToText(context, spirv.data(), spirv.size(), diff --git a/SPIRV/SpvTools.h b/SPIRV/SpvTools.h index 7779dfa..691c9ef 100644 --- a/SPIRV/SpvTools.h +++ b/SPIRV/SpvTools.h @@ -44,6 +44,7 @@ #ifdef ENABLE_OPT #include #include +#include "spirv-tools/libspirv.h" #endif #include "glslang/MachineIndependent/localintermediate.h" @@ -64,9 +65,13 @@ struct SpvOptions { #ifdef ENABLE_OPT -// Use the SPIRV-Tools disassembler to print SPIR-V. +// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment. void SpirvToolsDisassemble(std::ostream& out, const std::vector& spirv); +// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment. +void SpirvToolsDisassemble(std::ostream& out, const std::vector& spirv, + spv_target_env requested_context); + // Apply the SPIRV-Tools validator to generated SPIR-V. void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector& spirv, spv::SpvBuildLogger*, bool prelegalization); diff --git a/StandAlone/CMakeLists.txt b/StandAlone/CMakeLists.txt index 8038c04..decfac5 100644 --- a/StandAlone/CMakeLists.txt +++ b/StandAlone/CMakeLists.txt @@ -70,6 +70,12 @@ target_include_directories(glslangValidator PUBLIC $ $) +if(ENABLE_OPT) +target_include_directories(glslangValidator PUBLIC + $ + $) +endif() + if(ENABLE_SPVREMAPPER) set(REMAPPER_SOURCES spirv-remap.cpp) add_executable(spirv-remap ${REMAPPER_SOURCES}) diff --git a/gtests/CMakeLists.txt b/gtests/CMakeLists.txt index 6c48d9c..f489c9d 100644 --- a/gtests/CMakeLists.txt +++ b/gtests/CMakeLists.txt @@ -83,6 +83,12 @@ if(BUILD_TESTING) ${gmock_SOURCE_DIR}/include ${gtest_SOURCE_DIR}/include) + if(ENABLE_OPT) + target_include_directories(glslangtests PUBLIC + $ + $) + endif() + set(LIBRARIES glslang OSDependent OGLCompiler glslang SPIRV glslang-default-resource-limits) -- 2.7.4