-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add glslang::Backend to break cyclic dependency
between `HLSL` and `glslang` build targets. Applications now require a call to `glslang::RegisterHLSLBackend()` to enable the HLSL backend. This is implemented in the HLSL library. Fixes building of shared libraries.
- Loading branch information
1 parent
45de441
commit e13b079
Showing
11 changed files
with
330 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// Copyright (C) 2020 Google, Inc. | ||
// | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer in the documentation and/or other materials provided | ||
// with the distribution. | ||
// | ||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
|
||
#include "Backend.h" | ||
#include "ParseHelper.h" | ||
#include "ScanContext.h" | ||
|
||
#include <array> | ||
|
||
namespace glslang { | ||
|
||
namespace { | ||
|
||
class GlslBackend : public Backend { | ||
public: | ||
static GlslBackend instance; | ||
|
||
void Initialize() override { | ||
TScanContext::fillInKeywordMap(); | ||
} | ||
|
||
void Terminate() override { | ||
TScanContext::deleteKeywordMap(); | ||
} | ||
|
||
EShSource Source() const override { | ||
return EShSourceGlsl; | ||
} | ||
|
||
TBuiltInParseables* CreateBuiltInParseables(TInfoSink&) override { | ||
return new TBuiltIns(); | ||
} | ||
|
||
TParseContextBase* CreateParseContext(TSymbolTable& symbolTable, TIntermediate& intermediate, | ||
int version, EProfile profile, | ||
EShLanguage language, TInfoSink& infoSink, | ||
SpvVersion spvVersion, bool forwardCompatible, EShMessages messages, | ||
bool parsingBuiltIns, std::string sourceEntryPointName) override { | ||
if (sourceEntryPointName.size() == 0) | ||
intermediate.setEntryPointName("main"); | ||
TString entryPoint = sourceEntryPointName.c_str(); | ||
return new TParseContext(symbolTable, intermediate, parsingBuiltIns, version, profile, spvVersion, | ||
language, infoSink, forwardCompatible, messages, &entryPoint); | ||
} | ||
}; | ||
|
||
GlslBackend GlslBackend::instance; | ||
|
||
std::array<Backend*, EShSourceCount> backends = {}; | ||
|
||
// Automatically register the GLSL backend when the static initializers are run | ||
// for this compilation unit. | ||
struct AutoRegisterGlslBackend { | ||
AutoRegisterGlslBackend() { Backend::Register(&GlslBackend::instance); } | ||
} autoRegisterGlslBackend; | ||
|
||
} // end anonymous namespace | ||
|
||
void Backend::InitializeAll() { | ||
for (Backend* backend : backends) { | ||
if (backend) { | ||
backend->Initialize(); | ||
} | ||
} | ||
} | ||
|
||
void Backend::TerminateAll() { | ||
for (Backend* backend : backends) { | ||
if (backend) { | ||
backend->Terminate(); | ||
} | ||
} | ||
} | ||
|
||
void Backend::Register(Backend* backend) { | ||
EShSource source = backend->Source(); | ||
backends[source] = backend; | ||
} | ||
|
||
Backend* Backend::Get(EShSource source) { | ||
return backends[source]; | ||
} | ||
|
||
} // end namespace glslang | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// Copyright (C) 2020 Google, Inc. | ||
// | ||
// All rights reserved. | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions | ||
// are met: | ||
// | ||
// Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// Redistributions in binary form must reproduce the above | ||
// copyright notice, this list of conditions and the following | ||
// disclaimer in the documentation and/or other materials provided | ||
// with the distribution. | ||
// | ||
// Neither the name of 3Dlabs Inc. Ltd. nor the names of its | ||
// contributors may be used to endorse or promote products derived | ||
// from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
// | ||
#ifndef _GLSLANG_BACKEND_INCLUDED_ | ||
#define _GLSLANG_BACKEND_INCLUDED_ | ||
|
||
#include "Initialize.h" | ||
|
||
namespace glslang { | ||
|
||
class TParseContextBase; | ||
|
||
// Backend is an interface implemented by a language backend. | ||
// Backends are registered by source (EShSource). | ||
class Backend { | ||
public: | ||
virtual ~Backend() {} | ||
|
||
// Register() registers the backend. | ||
static void Register(Backend*); | ||
|
||
// Get() returns the registered backend for the given source type. | ||
static Backend* Get(EShSource source); | ||
|
||
// InitializeAll() initializes all the registered backends. | ||
static void InitializeAll(); | ||
|
||
// TerminateAll() terminates all the registered backends. | ||
static void TerminateAll(); | ||
|
||
// Initialize() initializes the backend. | ||
// Must be called, once, before any other method (with exception to Source()). | ||
virtual void Initialize() = 0; | ||
|
||
// Terminate() terminates the backend. | ||
// Must be called, once, before process termination. | ||
// No method may be called after calling. | ||
virtual void Terminate() = 0; | ||
|
||
// Source() returns the EShSource that this backend implements. | ||
virtual EShSource Source() const = 0; | ||
|
||
// CreateBuiltInParseables() constructs and returns the parseable strings | ||
// for the given backend. | ||
virtual TBuiltInParseables* CreateBuiltInParseables(TInfoSink& infoSink) = 0; | ||
|
||
// CreateParseContext() constructs and returns the parse context for the | ||
// given backend. | ||
virtual TParseContextBase* CreateParseContext(TSymbolTable& symbolTable, TIntermediate& intermediate, | ||
int version, EProfile profile, | ||
EShLanguage language, TInfoSink& infoSink, | ||
SpvVersion spvVersion, bool forwardCompatible, EShMessages messages, | ||
bool parsingBuiltIns, std::string sourceEntryPointName) = 0; | ||
}; | ||
|
||
} // end namespace glslang | ||
|
||
#endif // _GLSLANG_BACKEND_INCLUDED_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.