From b1fac200c40d9c067ba77dd68010975905eb7b3c Mon Sep 17 00:00:00 2001 From: Arcady Goldmints-Orlov Date: Fri, 23 Aug 2024 19:12:45 -0400 Subject: [PATCH] Add symbol visibility annotations to symbols in SPIRV/ Symbols in the SPIRV/ directory that are meant to be part of the public API of glslangnow have GLSLANG_EXPORT annotations that make sure they will be accessible when building glslang as a shared library if -fvisibility=hidden is enabled. --- SPIRV/GlslangToSpv.h | 17 +++++++++-------- SPIRV/Logger.h | 3 ++- SPIRV/SpvTools.h | 39 +++++++++++++++++++++------------------ SPIRV/disassemble.h | 4 +++- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/SPIRV/GlslangToSpv.h b/SPIRV/GlslangToSpv.h index 95ea891bfe..9fb4f3fff7 100644 --- a/SPIRV/GlslangToSpv.h +++ b/SPIRV/GlslangToSpv.h @@ -39,6 +39,7 @@ #include #include "Logger.h" +#include "glslang/Include/visibility.h" namespace glslang { class TIntermediate; @@ -56,13 +57,13 @@ struct SpvOptions { bool optimizerAllowExpandedIDBound{false}; }; -void GetSpirvVersion(std::string&); -int GetSpirvGeneratorVersion(); -void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector& spirv, - SpvOptions* options = nullptr); -void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector& spirv, - spv::SpvBuildLogger* logger, SpvOptions* options = nullptr); -bool OutputSpvBin(const std::vector& spirv, const char* baseName); -bool OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName); +GLSLANG_EXPORT void GetSpirvVersion(std::string&); +GLSLANG_EXPORT int GetSpirvGeneratorVersion(); +GLSLANG_EXPORT void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector& spirv, + SpvOptions* options = nullptr); +GLSLANG_EXPORT void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector& spirv, + spv::SpvBuildLogger* logger, SpvOptions* options = nullptr); +GLSLANG_EXPORT bool OutputSpvBin(const std::vector& spirv, const char* baseName); +GLSLANG_EXPORT bool OutputSpvHex(const std::vector& spirv, const char* baseName, const char* varName); } diff --git a/SPIRV/Logger.h b/SPIRV/Logger.h index 2e4ddaf517..dece1c4b52 100644 --- a/SPIRV/Logger.h +++ b/SPIRV/Logger.h @@ -37,6 +37,7 @@ #include #include +#include "glslang/Include/visibility.h" namespace spv { @@ -58,7 +59,7 @@ class SpvBuildLogger { // Returns all messages accumulated in the order of: // TBD functionalities, missing functionalities, warnings, errors. - std::string getAllMessages() const; + GLSLANG_EXPORT std::string getAllMessages() const; private: SpvBuildLogger(const SpvBuildLogger&); diff --git a/SPIRV/SpvTools.h b/SPIRV/SpvTools.h index a72d652c57..a238427033 100644 --- a/SPIRV/SpvTools.h +++ b/SPIRV/SpvTools.h @@ -49,6 +49,7 @@ #endif #include "glslang/MachineIndependent/Versions.h" +#include "glslang/Include/visibility.h" #include "GlslangToSpv.h" #include "Logger.h" @@ -59,44 +60,46 @@ namespace glslang { class TIntermediate; // Translate glslang's view of target versioning to what SPIRV-Tools uses. -spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger); +GLSLANG_EXPORT spv_target_env MapToSpirvToolsEnv(const SpvVersion& spvVersion, spv::SpvBuildLogger* logger); // 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); +GLSLANG_EXPORT 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); +GLSLANG_EXPORT 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); +GLSLANG_EXPORT void SpirvToolsValidate(const glslang::TIntermediate& intermediate, std::vector& spirv, + spv::SpvBuildLogger*, bool prelegalization); // Apply the SPIRV-Tools optimizer to generated SPIR-V. HLSL SPIR-V is legalized in the process. -void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector& spirv, - spv::SpvBuildLogger*, const SpvOptions*); +GLSLANG_EXPORT void SpirvToolsTransform(const glslang::TIntermediate& intermediate, std::vector& spirv, + spv::SpvBuildLogger*, const SpvOptions*); // Apply the SPIRV-Tools EliminateDeadInputComponents pass to generated SPIR-V. Put result in |spirv|. -void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector& spirv, - spv::SpvBuildLogger*); +GLSLANG_EXPORT void SpirvToolsEliminateDeadInputComponents(spv_target_env target_env, std::vector& spirv, + spv::SpvBuildLogger*); // Apply the SPIRV-Tools AnalyzeDeadOutputStores pass to generated SPIR-V. Put result in |live_locs|. // Return true if the result is valid. -bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector& spirv, - std::unordered_set* live_locs, - std::unordered_set* live_builtins, spv::SpvBuildLogger*); +GLSLANG_EXPORT bool SpirvToolsAnalyzeDeadOutputStores(spv_target_env target_env, std::vector& spirv, + std::unordered_set* live_locs, + std::unordered_set* live_builtins, + spv::SpvBuildLogger*); // Apply the SPIRV-Tools EliminateDeadOutputStores and AggressiveDeadCodeElimination passes to generated SPIR-V using // |live_locs|. Put result in |spirv|. -void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector& spirv, - std::unordered_set* live_locs, - std::unordered_set* live_builtins, spv::SpvBuildLogger*); +GLSLANG_EXPORT void SpirvToolsEliminateDeadOutputStores(spv_target_env target_env, std::vector& spirv, + std::unordered_set* live_locs, + std::unordered_set* live_builtins, + spv::SpvBuildLogger*); // Apply the SPIRV-Tools optimizer to strip debug info from SPIR-V. This is implicitly done by // SpirvToolsTransform if spvOptions->stripDebugInfo is set, but can be called separately if // optimization is disabled. -void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate, - std::vector& spirv, spv::SpvBuildLogger*); +GLSLANG_EXPORT void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate, + std::vector& spirv, spv::SpvBuildLogger*); #endif diff --git a/SPIRV/disassemble.h b/SPIRV/disassemble.h index b6a4635775..3bded14f2f 100644 --- a/SPIRV/disassemble.h +++ b/SPIRV/disassemble.h @@ -43,10 +43,12 @@ #include #include +#include "glslang/Include/visibility.h" + namespace spv { // disassemble with glslang custom disassembler - void Disassemble(std::ostream& out, const std::vector&); + GLSLANG_EXPORT void Disassemble(std::ostream& out, const std::vector&); } // end namespace spv