mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-08 19:40:06 +00:00
Interface and naming improvements:
- the new C++ style interface now stands on its own, with the addition of glslang::InitializeProcess() and glslang::FinalizeProcess() - more "global" pool names from a decade ago are fixed to be thread names - StandAlone.cpp fully uses one of the old-style interface or new C++ style interface git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@23851 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
parent
5b0f13acbc
commit
c36e1d8e51
@ -94,7 +94,7 @@ bool InitThread()
|
||||
if (OS_GetTLSValue(ThreadInitializeIndex) != 0)
|
||||
return true;
|
||||
|
||||
InitializeGlobalPools();
|
||||
InitializeMemoryPools();
|
||||
|
||||
if (! OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {
|
||||
assert(0 && "InitThread(): Unable to set init flag.");
|
||||
|
@ -591,12 +591,6 @@ int C_DECL main(int argc, char* argv[])
|
||||
bool compileFailed = false;
|
||||
bool linkFailed = false;
|
||||
|
||||
// Init for front-end proper
|
||||
ShInitialize();
|
||||
|
||||
// Init for standalone
|
||||
glslang::InitGlobalLock();
|
||||
|
||||
if (! ProcessArguments(argc, argv)) {
|
||||
usage();
|
||||
return EFailUsage;
|
||||
@ -620,9 +614,13 @@ int C_DECL main(int argc, char* argv[])
|
||||
// 1) linking all arguments together, single-threaded, new C++ interface
|
||||
// 2) independent arguments, can be tackled by multiple asynchronous threads, for testing thread safety, using the old handle interface
|
||||
//
|
||||
if (Options & EOptionsLinkProgram)
|
||||
if (Options & EOptionsLinkProgram) {
|
||||
glslang::InitializeProcess();
|
||||
CompileAndLinkShaders();
|
||||
else {
|
||||
glslang::FinalizeProcess();
|
||||
} else {
|
||||
ShInitialize();
|
||||
|
||||
bool printShaderNames = Worklist.size() > 1;
|
||||
|
||||
if (Options & EOptionMultiThreaded) {
|
||||
@ -650,6 +648,8 @@ int C_DECL main(int argc, char* argv[])
|
||||
delete Work[w];
|
||||
}
|
||||
}
|
||||
|
||||
ShFinalize();
|
||||
}
|
||||
|
||||
if (Delay)
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
namespace glslang {
|
||||
|
||||
void InitializeGlobalPools();
|
||||
void InitializeMemoryPools();
|
||||
void FreeGlobalPools();
|
||||
bool InitializePoolIndex();
|
||||
void FreePoolIndex();
|
||||
|
@ -252,9 +252,9 @@ private:
|
||||
typedef TPoolAllocator* PoolAllocatorPointer;
|
||||
extern TPoolAllocator& GetThreadPoolAllocator();
|
||||
|
||||
struct TThreadGlobalPools
|
||||
struct TThreadMemoryPools
|
||||
{
|
||||
TPoolAllocator* globalPoolAllocator;
|
||||
TPoolAllocator* threadPoolAllocator;
|
||||
};
|
||||
|
||||
void SetThreadPoolAllocator(TPoolAllocator& poolAllocator);
|
||||
|
@ -459,7 +459,7 @@ protected:
|
||||
class TIntermSymbol : public TIntermTyped {
|
||||
public:
|
||||
// if symbol is initialized as symbol(sym), the memory comes from the poolallocator of sym. If sym comes from
|
||||
// per process globalpoolallocator, then it causes increased memory usage per compile
|
||||
// per process threadPoolAllocator, then it causes increased memory usage per compile
|
||||
// it is essential to use "symbol = sym" to assign to symbol
|
||||
TIntermSymbol(int i, const TString& n, const TType& t) :
|
||||
TIntermTyped(t), id(i) { name = n;}
|
||||
|
@ -42,17 +42,17 @@ namespace glslang {
|
||||
|
||||
OS_TLSIndex PoolIndex;
|
||||
|
||||
void InitializeGlobalPools()
|
||||
void InitializeMemoryPools()
|
||||
{
|
||||
TThreadGlobalPools* globalPools = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
|
||||
if (globalPools)
|
||||
TThreadMemoryPools* pools = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
|
||||
if (pools)
|
||||
return;
|
||||
|
||||
TPoolAllocator *globalPoolAllocator = new TPoolAllocator();
|
||||
TPoolAllocator *threadPoolAllocator = new TPoolAllocator();
|
||||
|
||||
TThreadGlobalPools* threadData = new TThreadGlobalPools();
|
||||
TThreadMemoryPools* threadData = new TThreadMemoryPools();
|
||||
|
||||
threadData->globalPoolAllocator = globalPoolAllocator;
|
||||
threadData->threadPoolAllocator = threadPoolAllocator;
|
||||
|
||||
OS_SetTLSValue(PoolIndex, threadData);
|
||||
}
|
||||
@ -60,7 +60,7 @@ void InitializeGlobalPools()
|
||||
void FreeGlobalPools()
|
||||
{
|
||||
// Release the allocated memory for this thread.
|
||||
TThreadGlobalPools* globalPools = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
|
||||
TThreadMemoryPools* globalPools = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
|
||||
if (! globalPools)
|
||||
return;
|
||||
|
||||
@ -86,16 +86,16 @@ void FreePoolIndex()
|
||||
|
||||
TPoolAllocator& GetThreadPoolAllocator()
|
||||
{
|
||||
TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
|
||||
TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
|
||||
|
||||
return *threadData->globalPoolAllocator;
|
||||
return *threadData->threadPoolAllocator;
|
||||
}
|
||||
|
||||
void SetThreadPoolAllocator(TPoolAllocator& poolAllocator)
|
||||
{
|
||||
TThreadGlobalPools* threadData = static_cast<TThreadGlobalPools*>(OS_GetTLSValue(PoolIndex));
|
||||
TThreadMemoryPools* threadData = static_cast<TThreadMemoryPools*>(OS_GetTLSValue(PoolIndex));
|
||||
|
||||
threadData->globalPoolAllocator = &poolAllocator;
|
||||
threadData->threadPoolAllocator = &poolAllocator;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -538,6 +538,8 @@ bool CompileDeferred(
|
||||
//
|
||||
int ShInitialize()
|
||||
{
|
||||
glslang::InitGlobalLock();
|
||||
|
||||
if (! InitProcess())
|
||||
return 0;
|
||||
|
||||
@ -546,7 +548,7 @@ int ShInitialize()
|
||||
|
||||
glslang::TScanContext::fillInKeywordMap();
|
||||
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
@ -909,6 +911,16 @@ int ShGetUniformLocation(const ShHandle handle, const char* name)
|
||||
|
||||
namespace glslang {
|
||||
|
||||
bool InitializeProcess()
|
||||
{
|
||||
return ShInitialize() != 0;
|
||||
}
|
||||
|
||||
void FinalizeProcess()
|
||||
{
|
||||
ShFinalize();
|
||||
}
|
||||
|
||||
class TDeferredCompiler : public TCompiler {
|
||||
public:
|
||||
TDeferredCompiler(EShLanguage s, TInfoSink& i) : TCompiler(s, i) { }
|
||||
|
@ -267,6 +267,20 @@ class TIntermediate;
|
||||
class TProgram;
|
||||
class TPoolAllocator;
|
||||
|
||||
// Call this exactly once per process before using anything else
|
||||
bool InitializeProcess();
|
||||
|
||||
// Call once per process to tear down everything
|
||||
void FinalizeProcess();
|
||||
|
||||
// Make one TShader per shader that you will link into a program. Then
|
||||
// provide the shader through setStrings(), then call parse(), then query
|
||||
// the info logs.
|
||||
//
|
||||
// N.B.: Does not yet support having the same TShader instance being linked multiple programs.
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TShader {
|
||||
public:
|
||||
explicit TShader(EShLanguage);
|
||||
@ -291,6 +305,12 @@ private:
|
||||
TShader& operator=(TShader&);
|
||||
};
|
||||
|
||||
// Make one TProgram per set of shaders that will get linked together. Add all
|
||||
// the shaders that are to be linked together. After calling shader.parse()
|
||||
// for all shaders, call link().
|
||||
//
|
||||
// N.B.: Destruct a linked program *before* destructing the shaders linked into it.
|
||||
//
|
||||
class TProgram {
|
||||
public:
|
||||
TProgram();
|
||||
@ -314,5 +334,4 @@ private:
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
|
||||
#endif // _COMPILER_INTERFACE_INCLUDED_
|
||||
|
Loading…
Reference in New Issue
Block a user