From c897c3bc239a957f1a62557b1ddeee781250fa78 Mon Sep 17 00:00:00 2001 From: pheonix Date: Mon, 2 Nov 2020 13:40:50 -0800 Subject: [PATCH] Add new SpirvToolsDisassemble API interface + Improve Doc on existing API interface (#2442) * Add new SpirvToolsDisassemble API interface + Improve Doc on existing API interface (#2408) * Add more flexible SpirvToolsDisassemble interface to allow specifying spv_target_env for disassembly output. Improve documentation on existing SpirvToolsDisassemble interface. * Update pre-processor check - following existing ENABLE_OPT checks. * Fix not-found header paths for glslangValidator and glslangtests. * Add spirv_tools/include path where there is an ENABLE_OPT=1 in the BUILD.gn configuration. --- BUILD.gn | 12 +++++++++--- SPIRV/SpvTools.cpp | 12 +++++++++--- SPIRV/SpvTools.h | 11 ++++++++--- StandAlone/CMakeLists.txt | 7 ++++++- gtests/CMakeLists.txt | 6 ++++++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 29256c43..a23ff967 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -246,6 +246,8 @@ template("glslang_sources_common") { ] } + include_dirs = [ "${target_gen_dir}/include" ] + deps = [ ":glslang_build_info" ] if (invoker.enable_opt) { @@ -253,10 +255,9 @@ template("glslang_sources_common") { "${spirv_tools_dir}:spvtools_opt", "${spirv_tools_dir}:spvtools_val", ] + include_dirs += [ "${spirv_tools_dir}/include" ] } - include_dirs = [ "${target_gen_dir}/include" ] - configs -= _configs_to_remove configs += _configs_to_add } @@ -302,7 +303,10 @@ executable("glslang_validator") { ] public_configs = [ ":glslang_hlsl" ] - include_dirs = [ "${target_gen_dir}/include" ] + include_dirs = [ + "${target_gen_dir}/include", + "${spirv_tools_dir}/include", + ] configs -= _configs_to_remove configs += _configs_to_add @@ -313,6 +317,8 @@ executable("spirv-remap") { defines = [ "ENABLE_OPT=1" ] deps = [ ":glslang_sources" ] + include_dirs += [ "${spirv_tools_dir}/include" ] + configs -= _configs_to_remove configs += _configs_to_add } diff --git a/SPIRV/SpvTools.cpp b/SPIRV/SpvTools.cpp index 8ba97992..16d051a9 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_target_env::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 7779dfa7..3fb3cbac 100644 --- a/SPIRV/SpvTools.h +++ b/SPIRV/SpvTools.h @@ -41,9 +41,10 @@ #ifndef GLSLANG_SPV_TOOLS_H #define GLSLANG_SPV_TOOLS_H -#ifdef ENABLE_OPT +#if ENABLE_OPT #include #include +#include "spirv-tools/libspirv.h" #endif #include "glslang/MachineIndependent/localintermediate.h" @@ -62,11 +63,15 @@ struct SpvOptions { bool validate; }; -#ifdef ENABLE_OPT +#if 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 8038c043..bff9ab61 100644 --- a/StandAlone/CMakeLists.txt +++ b/StandAlone/CMakeLists.txt @@ -41,7 +41,6 @@ target_include_directories(glslang-default-resource-limits PUBLIC $ PUBLIC $) - set(SOURCES StandAlone.cpp DirStackFileIncluder.h) add_executable(glslangValidator ${SOURCES}) @@ -70,6 +69,12 @@ target_include_directories(glslangValidator PUBLIC $ $) +if(ENABLE_OPT) + target_include_directories(glslangValidator + PRIVATE ${spirv-tools_SOURCE_DIR}/include + ) +endif(ENABLE_OPT) + 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 6c48d9c2..0617ff85 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 + PRIVATE ${spirv-tools_SOURCE_DIR}/include + ) + endif(ENABLE_OPT) + set(LIBRARIES glslang OSDependent OGLCompiler glslang SPIRV glslang-default-resource-limits)