Skip to content

Commit 2eed823

Browse files
authored
Add more flexible SpirvToolsDisassemble interface to allow specifying spv_target_env for disassembly output. (KhronosGroup#2406)
Improve documentation on existing SpirvToolsDisassemble interface. Fix cmake build scripts to account for `spirv-tools` external when -DENABLE_OPT=ON
1 parent d0e7ed3 commit 2eed823

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

SPIRV/SpvTools.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
#include "SpvTools.h"
4646
#include "spirv-tools/optimizer.hpp"
47-
#include "spirv-tools/libspirv.h"
4847

4948
namespace glslang {
5049

@@ -114,11 +113,18 @@ void OptimizerMesssageConsumer(spv_message_level_t level, const char *source,
114113
out << std::endl;
115114
}
116115

117-
// Use the SPIRV-Tools disassembler to print SPIR-V.
116+
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
118117
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv)
118+
{
119+
SpirvToolsDisassemble(out, spirv, SPV_ENV_UNIVERSAL_1_3);
120+
}
121+
122+
// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
123+
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
124+
spv_target_env requested_context)
119125
{
120126
// disassemble
121-
spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_3);
127+
spv_context context = spvContextCreate(requested_context);
122128
spv_text text;
123129
spv_diagnostic diagnostic = nullptr;
124130
spvBinaryToText(context, spirv.data(), spirv.size(),

SPIRV/SpvTools.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#ifdef ENABLE_OPT
4545
#include <vector>
4646
#include <ostream>
47+
#include "spirv-tools/libspirv.h"
4748
#endif
4849

4950
#include "glslang/MachineIndependent/localintermediate.h"
@@ -64,9 +65,13 @@ struct SpvOptions {
6465

6566
#ifdef ENABLE_OPT
6667

67-
// Use the SPIRV-Tools disassembler to print SPIR-V.
68+
// Use the SPIRV-Tools disassembler to print SPIR-V using a SPV_ENV_UNIVERSAL_1_3 environment.
6869
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv);
6970

71+
// Use the SPIRV-Tools disassembler to print SPIR-V with a provided SPIR-V environment.
72+
void SpirvToolsDisassemble(std::ostream& out, const std::vector<unsigned int>& spirv,
73+
spv_target_env requested_context);
74+
7075
// Apply the SPIRV-Tools validator to generated SPIR-V.
7176
void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector<unsigned int>& spirv,
7277
spv::SpvBuildLogger*, bool prelegalization);

StandAlone/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ target_include_directories(glslangValidator PUBLIC
7070
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
7171
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
7272

73+
if(ENABLE_OPT)
74+
target_include_directories(glslangValidator PUBLIC
75+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External/spirv-tools/include>
76+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External/spirv-tools/include>)
77+
endif()
78+
7379
if(ENABLE_SPVREMAPPER)
7480
set(REMAPPER_SOURCES spirv-remap.cpp)
7581
add_executable(spirv-remap ${REMAPPER_SOURCES})

gtests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ if(BUILD_TESTING)
8383
${gmock_SOURCE_DIR}/include
8484
${gtest_SOURCE_DIR}/include)
8585

86+
if(ENABLE_OPT)
87+
target_include_directories(glslangtests PUBLIC
88+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External/spirv-tools/include>
89+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External/spirv-tools/include>)
90+
endif()
91+
8692
set(LIBRARIES
8793
glslang OSDependent OGLCompiler glslang
8894
SPIRV glslang-default-resource-limits)

0 commit comments

Comments
 (0)