Skip to content

Commit c897c3b

Browse files
authored
Add new SpirvToolsDisassemble API interface + Improve Doc on existing API interface (KhronosGroup#2442)
* 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. * Add spirv_tools/include path where there is an ENABLE_OPT=1 in the BUILD.gn configuration.
1 parent 56350ca commit c897c3b

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

BUILD.gn

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,18 @@ template("glslang_sources_common") {
246246
]
247247
}
248248

249+
include_dirs = [ "${target_gen_dir}/include" ]
250+
249251
deps = [ ":glslang_build_info" ]
250252

251253
if (invoker.enable_opt) {
252254
deps += [
253255
"${spirv_tools_dir}:spvtools_opt",
254256
"${spirv_tools_dir}:spvtools_val",
255257
]
258+
include_dirs += [ "${spirv_tools_dir}/include" ]
256259
}
257260

258-
include_dirs = [ "${target_gen_dir}/include" ]
259-
260261
configs -= _configs_to_remove
261262
configs += _configs_to_add
262263
}
@@ -302,7 +303,10 @@ executable("glslang_validator") {
302303
]
303304
public_configs = [ ":glslang_hlsl" ]
304305

305-
include_dirs = [ "${target_gen_dir}/include" ]
306+
include_dirs = [
307+
"${target_gen_dir}/include",
308+
"${spirv_tools_dir}/include",
309+
]
306310

307311
configs -= _configs_to_remove
308312
configs += _configs_to_add
@@ -313,6 +317,8 @@ executable("spirv-remap") {
313317
defines = [ "ENABLE_OPT=1" ]
314318
deps = [ ":glslang_sources" ]
315319

320+
include_dirs += [ "${spirv_tools_dir}/include" ]
321+
316322
configs -= _configs_to_remove
317323
configs += _configs_to_add
318324
}

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)