Rationalize naming/access to current thread-local-storage scheme. However, the preprocessor tokenizer is not thread-safe, so this may all change.

Also adding missing test.


git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@22249 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2013-07-02 20:18:59 +00:00
parent 1fde51d3fb
commit 73ed17a87b
10 changed files with 48 additions and 21 deletions

View File

@ -89,7 +89,7 @@ bool InitThread()
InitializeGlobalPools(); InitializeGlobalPools();
if (!InitializeGlobalParseContext()) if (!InitializeThreadParseContext())
return false; return false;
if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) { if (!OS_SetTLSValue(ThreadInitializeIndex, (void *)1)) {

25
Test/precision.vert Normal file
View File

@ -0,0 +1,25 @@
#version 300 es
in vec4 pos;
uniform sampler2D s2D;
uniform samplerCube sCube;
uniform isampler2DArray is2DAbad; // ERROR, no default precision
uniform sampler2DArrayShadow s2dASbad; // ERROR, no default precision
precision highp sampler2D;
precision mediump sampler2DArrayShadow;
uniform sampler2DArrayShadow s2dAS;
uniform isampler2DArray is2DAbad2; // ERROR, still no default precision
uniform sampler2D s2Dhigh;
void main()
{
vec4 t = texture(s2D, vec2(0.1, 0.2));
t += texture(s2Dhigh, vec2(0.1, 0.2));
t += texture(s2dAS, vec4(0.5));
gl_Position = pos;
}

View File

@ -37,7 +37,7 @@
#include "osinclude.h" #include "osinclude.h"
bool InitializeParseContextIndex(); bool InitializeParseContextIndex();
bool InitializeGlobalParseContext(); bool InitializeThreadParseContext();
bool FreeParseContext(); bool FreeParseContext();
bool FreeParseContextIndex(); bool FreeParseContextIndex();

View File

@ -2038,10 +2038,10 @@ bool InitializeParseContextIndex()
return true; return true;
} }
bool InitializeGlobalParseContext() bool InitializeThreadParseContext()
{ {
if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) { if (GlobalParseContextIndex == OS_INVALID_TLS_INDEX) {
assert(0 && "InitializeGlobalParseContext(): Parse Context index not initialized"); assert(0 && "InitializeThreadParseContext(): Parse Context index not initialized");
return false; return false;
} }
@ -2053,7 +2053,7 @@ bool InitializeGlobalParseContext()
TThreadParseContext *lpThreadData = new TThreadParseContext(); TThreadParseContext *lpThreadData = new TThreadParseContext();
if (lpThreadData == 0) { if (lpThreadData == 0) {
assert(0 && "InitializeGlobalParseContext(): Unable to create thread parse context"); assert(0 && "InitializeThreadParseContext(): Unable to create thread parse context");
return false; return false;
} }
@ -2063,7 +2063,7 @@ bool InitializeGlobalParseContext()
return true; return true;
} }
TParseContextPointer& GetGlobalParseContext() TParseContextPointer& ThreadLocalParseContext()
{ {
// //
// Minimal error checking for speed // Minimal error checking for speed

View File

@ -185,8 +185,7 @@ int PaParseComment(int &lineno, TParseContext&);
void ResetFlex(); void ResetFlex();
typedef TParseContext* TParseContextPointer; typedef TParseContext* TParseContextPointer;
extern TParseContextPointer& GetGlobalParseContext(); TParseContextPointer& ThreadLocalParseContext();
#define GlobalParseContext GetGlobalParseContext()
typedef struct TThreadParseContextRec typedef struct TThreadParseContextRec
{ {

View File

@ -100,7 +100,7 @@ bool InitializeSymbolTable(TBuiltInStrings* BuiltInStrings, int version, EProfil
TParseContext parseContext(*symbolTable, intermediate, true, version, profile, language, infoSink); TParseContext parseContext(*symbolTable, intermediate, true, version, profile, language, infoSink);
GlobalParseContext = &parseContext; ThreadLocalParseContext() = &parseContext;
assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel()); assert(symbolTable->isEmpty() || symbolTable->atSharedBuiltInLevel());
@ -259,15 +259,14 @@ bool DeduceProfile(TInfoSink& infoSink, int version, EProfile& profile)
}; // end anonymous namespace for local functions }; // end anonymous namespace for local functions
//
// ShInitialize() should be called exactly once per process, not per thread.
//
int ShInitialize() int ShInitialize()
{ {
if (! InitProcess()) if (! InitProcess())
return 0; return 0;
// TODO: Quality: Thread safety:
// This method should be called once per process. If it's called by multiple threads, then
// we need to have thread synchronization code around the initialization of per process
// global pool allocator
if (! PerProcessGPA) { if (! PerProcessGPA) {
PerProcessGPA = new TPoolAllocator(true); PerProcessGPA = new TPoolAllocator(true);
} }
@ -422,7 +421,7 @@ int ShCompile(
else if (profile == EEsProfile && version >= 300 && versionNotFirst) else if (profile == EEsProfile && version >= 300 && versionNotFirst)
parseContext.error(1, "statement must appear first in ESSL shader; before comments or newlines", "#version", ""); parseContext.error(1, "statement must appear first in ESSL shader; before comments or newlines", "#version", "");
GlobalParseContext = &parseContext; ThreadLocalParseContext() = &parseContext;
ResetFlex(); ResetFlex();
InitPreprocessor(); InitPreprocessor();

View File

@ -724,14 +724,14 @@ void yyerror(const char *s)
if (pc.AfterEOF) { if (pc.AfterEOF) {
if (cpp->tokensBeforeEOF == 1) if (cpp->tokensBeforeEOF == 1)
GlobalParseContext->error(yylineno, "", "pre-mature EOF", s, ""); ThreadLocalParseContext()->error(yylineno, "", "pre-mature EOF", s, "");
} else } else
GlobalParseContext->error(yylineno, "", yytext, s, ""); ThreadLocalParseContext()->error(yylineno, "", yytext, s, "");
} }
void PaReservedWord() void PaReservedWord()
{ {
GlobalParseContext->error(yylineno, "Reserved word.", yytext, "", ""); ThreadLocalParseContext()->error(yylineno, "Reserved word.", yytext, "", "");
} }
int PaIdentOrType(const char* yytext, TParseContext& parseContextLocal, YYSTYPE* pyylval) int PaIdentOrType(const char* yytext, TParseContext& parseContextLocal, YYSTYPE* pyylval)

View File

@ -33,7 +33,7 @@
// //
// //
// This file contains the Linux specific functions // This file contains the Linux-specific functions
// //
#include "osinclude.h" #include "osinclude.h"
#include "InitializeDll.h" #include "InitializeDll.h"

View File

@ -34,7 +34,7 @@
#include "osinclude.h" #include "osinclude.h"
// //
// This file contains contains the window's specific functions // This file contains contains the Window-OS-specific functions
// //
#if !(defined(_WIN32) || defined(_WIN64)) #if !(defined(_WIN32) || defined(_WIN64))

View File

@ -58,13 +58,17 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// //
// Driver must call this first, once, before doing any other // Driver must call this first, once, before doing any other
// compiler/linker operations. // compiler/linker operations.
// //
SH_IMPORT_EXPORT int ShInitialize(); // (Call once per process, not once per thread.)
// //
// Driver should call this at shutdown. SH_IMPORT_EXPORT int ShInitialize();
//
// Driver should call this at process shutdown.
// //
SH_IMPORT_EXPORT int __fastcall ShFinalize(); SH_IMPORT_EXPORT int __fastcall ShFinalize();