Skip to content

Commit d1929f3

Browse files
authored
Add new SpirvToolsDisassemble API interface + Improve Doc on existing API interface (KhronosGroup#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.
1 parent f05c076 commit d1929f3

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
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_target_env::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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
#ifndef GLSLANG_SPV_TOOLS_H
4242
#define GLSLANG_SPV_TOOLS_H
4343

44-
#ifdef ENABLE_OPT
44+
#if ENABLE_OPT
4545
#include <vector>
4646
#include <ostream>
47+
#include "spirv-tools/libspirv.h"
4748
#endif
4849

4950
#include "glslang/MachineIndependent/localintermediate.h"
@@ -62,11 +63,15 @@ struct SpvOptions {
6263
bool validate;
6364
};
6465

65-
#ifdef ENABLE_OPT
66+
#if 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ target_include_directories(glslang-default-resource-limits
4141
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
4242
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
4343

44-
4544
set(SOURCES StandAlone.cpp DirStackFileIncluder.h)
4645

4746
add_executable(glslangValidator ${SOURCES})
@@ -70,6 +69,12 @@ target_include_directories(glslangValidator PUBLIC
7069
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../External>
7170
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/External>)
7271

72+
if(ENABLE_OPT)
73+
target_include_directories(glslangValidator
74+
PRIVATE ${spirv-tools_SOURCE_DIR}/include
75+
)
76+
endif(ENABLE_OPT)
77+
7378
if(ENABLE_SPVREMAPPER)
7479
set(REMAPPER_SOURCES spirv-remap.cpp)
7580
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
88+
PRIVATE ${spirv-tools_SOURCE_DIR}/include
89+
)
90+
endif(ENABLE_OPT)
91+
8692
set(LIBRARIES
8793
glslang OSDependent OGLCompiler glslang
8894
SPIRV glslang-default-resource-limits)

0 commit comments

Comments
 (0)