Skip to content

Commit

Permalink
gi: remove unnecessary glslang initialization tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
pablode committed Aug 1, 2024
1 parent 58b322c commit 0ec1446
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 42 deletions.
34 changes: 7 additions & 27 deletions src/gi/impl/GlslShaderCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,17 @@ namespace gtl
}
};

static bool s_glslangInitialized = false;

bool GiGlslShaderCompiler::init()
{
if (s_glslangInitialized)
{
assert(false);
return true;
}

s_glslangInitialized = glslang::InitializeProcess();

return s_glslangInitialized;
}

void GiGlslShaderCompiler::deinit()
GiGlslShaderCompiler::GiGlslShaderCompiler(const fs::path& shaderPath)
: m_fileIncluder(std::make_shared<_FileIncluder>(shaderPath))
{
if (!s_glslangInitialized)
{
assert(false);
return;
}

glslang::FinalizeProcess();

s_glslangInitialized = false;
// glslang requires this static initialization, however it internally
// ref-counts and is thread-safe. The return value seems to be unused.
[[maybe_unused]] int r = glslang::InitializeProcess();
}

GiGlslShaderCompiler::GiGlslShaderCompiler(const fs::path& shaderPath)
: m_fileIncluder(std::make_shared<_FileIncluder>(shaderPath))
GiGlslShaderCompiler::~GiGlslShaderCompiler()
{
glslang::FinalizeProcess(); // see above
}

bool GiGlslShaderCompiler::compileGlslToSpv(ShaderStage stage,
Expand Down
6 changes: 2 additions & 4 deletions src/gi/impl/GlslShaderCompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ namespace gtl
public:
GiGlslShaderCompiler(const fs::path& shaderPath);

~GiGlslShaderCompiler();

public:
bool compileGlslToSpv(ShaderStage stage,
std::string_view source,
std::vector<uint8_t>& spv);

static bool init();

static void deinit();

private:
std::shared_ptr<class _FileIncluder> m_fileIncluder;
};
Expand Down
9 changes: 0 additions & 9 deletions src/gi/impl/GlslShaderGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,11 @@ namespace gtl
return false;
}

if (!GiGlslShaderCompiler::init())
{
return false;
}
m_shaderCompiler = std::make_shared<GiGlslShaderCompiler>(m_shaderPath);

return true;
}

GiGlslShaderGen::~GiGlslShaderGen()
{
GiGlslShaderCompiler::deinit();
}

void _sgGenerateCommonDefines(GiGlslStitcher& stitcher, const GiGlslShaderGen::CommonShaderParams& params)
{
#if defined(NDEBUG) || defined(__APPLE__)
Expand Down
2 changes: 0 additions & 2 deletions src/gi/impl/GlslShaderGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ namespace gtl
public:
bool init(std::string_view shaderPath, McRuntime& runtime);

~GiGlslShaderGen();

public:
struct MaterialGenInfo
{
Expand Down

0 comments on commit 0ec1446

Please sign in to comment.