Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
cb42541e
Commit
cb42541e
authored
Nov 12, 2017
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memory: Remove the need for per-thread tear down.
Make key objects using the memory pool own their own pool and delete it, such that there is not generic per-thread pool to manage.
parent
ff8e59f5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
130 deletions
+17
-130
InitializeDll.cpp
OGLCompilersDLL/InitializeDll.cpp
+3
-46
InitializeDll.h
OGLCompilersDLL/InitializeDll.h
+0
-2
InitializeGlobals.h
glslang/Include/InitializeGlobals.h
+0
-4
ShHandle.h
glslang/Include/ShHandle.h
+5
-2
PoolAlloc.cpp
glslang/MachineIndependent/PoolAlloc.cpp
+2
-51
ShaderLang.cpp
glslang/MachineIndependent/ShaderLang.cpp
+7
-24
ossource.cpp
glslang/OSDependent/Unix/ossource.cpp
+0
-1
No files found.
OGLCompilersDLL/InitializeDll.cpp
View file @
cb42541e
...
@@ -38,8 +38,8 @@
...
@@ -38,8 +38,8 @@
#include "InitializeDll.h"
#include "InitializeDll.h"
#include "../glslang/Include/InitializeGlobals.h"
#include "../glslang/Include/InitializeGlobals.h"
#include "../glslang/Public/ShaderLang.h"
#include "../glslang/Public/ShaderLang.h"
#include "../glslang/Include/PoolAlloc.h"
namespace
glslang
{
namespace
glslang
{
...
@@ -105,57 +105,14 @@ bool InitThread()
...
@@ -105,57 +105,14 @@ bool InitThread()
if
(
OS_GetTLSValue
(
ThreadInitializeIndex
)
!=
0
)
if
(
OS_GetTLSValue
(
ThreadInitializeIndex
)
!=
0
)
return
true
;
return
true
;
InitializeMemoryPools
();
if
(
!
OS_SetTLSValue
(
ThreadInitializeIndex
,
(
void
*
)
1
))
{
if
(
!
OS_SetTLSValue
(
ThreadInitializeIndex
,
(
void
*
)
1
))
{
assert
(
0
&&
"InitThread(): Unable to set init flag."
);
assert
(
0
&&
"InitThread(): Unable to set init flag."
);
return
false
;
return
false
;
}
}
return
true
;
glslang
::
SetThreadPoolAllocator
(
nullptr
);
}
// Thread-scoped tear down. Needs to be done by all but the last
// thread, which calls DetachProcess() instead.
// NB. TODO: Not currently being executed by each thread.
bool
DetachThread
()
{
bool
success
=
true
;
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
return
true
;
//
// Function is re-entrant and this thread may not have been initialized.
//
if
(
OS_GetTLSValue
(
ThreadInitializeIndex
)
!=
0
)
{
if
(
!
OS_SetTLSValue
(
ThreadInitializeIndex
,
(
void
*
)
0
))
{
assert
(
0
&&
"DetachThread(): Unable to clear init flag."
);
success
=
false
;
}
FreeMemoryPools
();
return
true
;
}
return
success
;
}
// Process-scoped tear down. Needs to be done by final thread in process.
bool
DetachProcess
()
{
bool
success
=
true
;
if
(
ThreadInitializeIndex
==
OS_INVALID_TLS_INDEX
)
return
true
;
success
=
DetachThread
();
FreePoolIndex
();
OS_FreeTLSIndex
(
ThreadInitializeIndex
);
ThreadInitializeIndex
=
OS_INVALID_TLS_INDEX
;
return
success
;
}
}
}
// end namespace glslang
}
// end namespace glslang
OGLCompilersDLL/InitializeDll.h
View file @
cb42541e
...
@@ -40,8 +40,6 @@ namespace glslang {
...
@@ -40,8 +40,6 @@ namespace glslang {
bool
InitProcess
();
bool
InitProcess
();
bool
InitThread
();
bool
InitThread
();
bool
DetachThread
();
// TODO: use this or remove it; ideally make it unneeded
bool
DetachProcess
();
}
// end namespace glslang
}
// end namespace glslang
...
...
glslang/Include/InitializeGlobals.h
View file @
cb42541e
...
@@ -37,11 +37,7 @@
...
@@ -37,11 +37,7 @@
namespace
glslang
{
namespace
glslang
{
void
InitializeMemoryPools
();
void
FreeMemoryPools
();
bool
InitializePoolIndex
();
bool
InitializePoolIndex
();
void
FreePoolIndex
();
}
// end namespace glslang
}
// end namespace glslang
...
...
glslang/Include/ShHandle.h
View file @
cb42541e
...
@@ -56,11 +56,14 @@ class TUniformMap;
...
@@ -56,11 +56,14 @@ class TUniformMap;
//
//
class
TShHandleBase
{
class
TShHandleBase
{
public
:
public
:
TShHandleBase
()
{
}
TShHandleBase
()
{
pool
=
new
glslang
::
TPoolAllocator
;
}
virtual
~
TShHandleBase
()
{
}
virtual
~
TShHandleBase
()
{
delete
pool
;
}
virtual
TCompiler
*
getAsCompiler
()
{
return
0
;
}
virtual
TCompiler
*
getAsCompiler
()
{
return
0
;
}
virtual
TLinker
*
getAsLinker
()
{
return
0
;
}
virtual
TLinker
*
getAsLinker
()
{
return
0
;
}
virtual
TUniformMap
*
getAsUniformMap
()
{
return
0
;
}
virtual
TUniformMap
*
getAsUniformMap
()
{
return
0
;
}
virtual
glslang
::
TPoolAllocator
*
getPool
()
const
{
return
pool
;
}
private
:
glslang
::
TPoolAllocator
*
pool
;
};
};
//
//
...
...
glslang/MachineIndependent/PoolAlloc.cpp
View file @
cb42541e
...
@@ -43,35 +43,16 @@ namespace glslang {
...
@@ -43,35 +43,16 @@ namespace glslang {
// Process-wide TLS index
// Process-wide TLS index
OS_TLSIndex
PoolIndex
;
OS_TLSIndex
PoolIndex
;
// Per-thread structure holding pool pointers.
struct
TThreadMemoryPools
{
TPoolAllocator
*
threadPoolAllocator
;
// the current pool
TPoolAllocator
*
initialMemoryPool
;
// the original pool owned by this thread (this file), to be freed here as well
};
// Return the thread-specific pool pointers.
TThreadMemoryPools
*
GetThreadMemoryPools
()
{
return
static_cast
<
TThreadMemoryPools
*>
(
OS_GetTLSValue
(
PoolIndex
));
}
// Set the thread-specific pool pointers.
void
SetThreadMemoryPools
(
TThreadMemoryPools
*
pools
)
{
OS_SetTLSValue
(
PoolIndex
,
pools
);
}
// Return the thread-specific current pool.
// Return the thread-specific current pool.
TPoolAllocator
&
GetThreadPoolAllocator
()
TPoolAllocator
&
GetThreadPoolAllocator
()
{
{
return
*
GetThreadMemoryPools
()
->
threadPoolAllocator
;
return
*
static_cast
<
TPoolAllocator
*>
(
OS_GetTLSValue
(
PoolIndex
))
;
}
}
// Set the thread-specific current pool.
// Set the thread-specific current pool.
void
SetThreadPoolAllocator
(
TPoolAllocator
*
poolAllocator
)
void
SetThreadPoolAllocator
(
TPoolAllocator
*
poolAllocator
)
{
{
GetThreadMemoryPools
()
->
threadPoolAllocator
=
poolAllocator
;
OS_SetTLSValue
(
PoolIndex
,
poolAllocator
)
;
}
}
// Process-wide set up of the TLS pool storage.
// Process-wide set up of the TLS pool storage.
...
@@ -81,39 +62,9 @@ bool InitializePoolIndex()
...
@@ -81,39 +62,9 @@ bool InitializePoolIndex()
if
((
PoolIndex
=
OS_AllocTLSIndex
())
==
OS_INVALID_TLS_INDEX
)
if
((
PoolIndex
=
OS_AllocTLSIndex
())
==
OS_INVALID_TLS_INDEX
)
return
false
;
return
false
;
SetThreadMemoryPools
(
nullptr
);
return
true
;
return
true
;
}
}
// Process-wide tear down of the TLS pool storage.
void
FreePoolIndex
()
{
// Release the TLS index.
OS_FreeTLSIndex
(
PoolIndex
);
}
// Per-thread set up of the memory pools.
void
InitializeMemoryPools
()
{
if
(
GetThreadMemoryPools
()
==
nullptr
)
{
SetThreadMemoryPools
(
new
TThreadMemoryPools
());
GetThreadMemoryPools
()
->
initialMemoryPool
=
new
TPoolAllocator
();
SetThreadPoolAllocator
(
GetThreadMemoryPools
()
->
initialMemoryPool
);
}
}
// Per-thread tear down of the memory pools.
void
FreeMemoryPools
()
{
if
(
GetThreadMemoryPools
()
!=
nullptr
)
{
if
(
GetThreadMemoryPools
()
->
initialMemoryPool
!=
nullptr
)
delete
GetThreadMemoryPools
()
->
initialMemoryPool
;
delete
GetThreadMemoryPools
();
SetThreadMemoryPools
(
nullptr
);
}
}
//
//
// Implement the functionality of the TPoolAllocator class, which
// Implement the functionality of the TPoolAllocator class, which
// is documented in PoolAlloc.h.
// is documented in PoolAlloc.h.
...
...
glslang/MachineIndependent/ShaderLang.cpp
View file @
cb42541e
...
@@ -722,9 +722,6 @@ bool ProcessDeferred(
...
@@ -722,9 +722,6 @@ bool ProcessDeferred(
const
std
::
string
sourceEntryPointName
=
""
,
const
std
::
string
sourceEntryPointName
=
""
,
const
TEnvironment
*
environment
=
nullptr
)
// optional way of fully setting all versions, overriding the above
const
TEnvironment
*
environment
=
nullptr
)
// optional way of fully setting all versions, overriding the above
{
{
if
(
!
InitThread
())
return
false
;
// This must be undone (.pop()) by the caller, after it finishes consuming the created tree.
// This must be undone (.pop()) by the caller, after it finishes consuming the created tree.
GetThreadPoolAllocator
().
push
();
GetThreadPoolAllocator
().
push
();
...
@@ -1299,7 +1296,7 @@ int __fastcall ShFinalize()
...
@@ -1299,7 +1296,7 @@ int __fastcall ShFinalize()
glslang
::
HlslScanContext
::
deleteKeywordMap
();
glslang
::
HlslScanContext
::
deleteKeywordMap
();
#endif
#endif
return
DetachProcess
()
?
1
:
0
;
return
1
;
}
}
//
//
...
@@ -1332,6 +1329,8 @@ int ShCompile(
...
@@ -1332,6 +1329,8 @@ int ShCompile(
if
(
compiler
==
0
)
if
(
compiler
==
0
)
return
0
;
return
0
;
SetThreadPoolAllocator
(
compiler
->
getPool
());
compiler
->
infoSink
.
info
.
erase
();
compiler
->
infoSink
.
info
.
erase
();
compiler
->
infoSink
.
debug
.
erase
();
compiler
->
infoSink
.
debug
.
erase
();
...
@@ -1389,6 +1388,8 @@ int ShLinkExt(
...
@@ -1389,6 +1388,8 @@ int ShLinkExt(
TShHandleBase
*
base
=
reinterpret_cast
<
TShHandleBase
*>
(
linkHandle
);
TShHandleBase
*
base
=
reinterpret_cast
<
TShHandleBase
*>
(
linkHandle
);
TLinker
*
linker
=
static_cast
<
TLinker
*>
(
base
->
getAsLinker
());
TLinker
*
linker
=
static_cast
<
TLinker
*>
(
base
->
getAsLinker
());
SetThreadPoolAllocator
(
linker
->
getPool
());
if
(
linker
==
0
)
if
(
linker
==
0
)
return
0
;
return
0
;
...
@@ -1423,9 +1424,6 @@ void ShSetEncryptionMethod(ShHandle handle)
...
@@ -1423,9 +1424,6 @@ void ShSetEncryptionMethod(ShHandle handle)
//
//
const
char
*
ShGetInfoLog
(
const
ShHandle
handle
)
const
char
*
ShGetInfoLog
(
const
ShHandle
handle
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
0
;
return
0
;
...
@@ -1449,9 +1447,6 @@ const char* ShGetInfoLog(const ShHandle handle)
...
@@ -1449,9 +1447,6 @@ const char* ShGetInfoLog(const ShHandle handle)
//
//
const
void
*
ShGetExecutable
(
const
ShHandle
handle
)
const
void
*
ShGetExecutable
(
const
ShHandle
handle
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
0
;
return
0
;
...
@@ -1474,9 +1469,6 @@ const void* ShGetExecutable(const ShHandle handle)
...
@@ -1474,9 +1469,6 @@ const void* ShGetExecutable(const ShHandle handle)
//
//
int
ShSetVirtualAttributeBindings
(
const
ShHandle
handle
,
const
ShBindingTable
*
table
)
int
ShSetVirtualAttributeBindings
(
const
ShHandle
handle
,
const
ShBindingTable
*
table
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
0
;
return
0
;
...
@@ -1496,9 +1488,6 @@ int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* t
...
@@ -1496,9 +1488,6 @@ int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* t
//
//
int
ShSetFixedAttributeBindings
(
const
ShHandle
handle
,
const
ShBindingTable
*
table
)
int
ShSetFixedAttributeBindings
(
const
ShHandle
handle
,
const
ShBindingTable
*
table
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
0
;
return
0
;
...
@@ -1517,9 +1506,6 @@ int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* tab
...
@@ -1517,9 +1506,6 @@ int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* tab
//
//
int
ShExcludeAttributes
(
const
ShHandle
handle
,
int
*
attributes
,
int
count
)
int
ShExcludeAttributes
(
const
ShHandle
handle
,
int
*
attributes
,
int
count
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
0
;
return
0
;
...
@@ -1541,9 +1527,6 @@ int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)
...
@@ -1541,9 +1527,6 @@ int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)
//
//
int
ShGetUniformLocation
(
const
ShHandle
handle
,
const
char
*
name
)
int
ShGetUniformLocation
(
const
ShHandle
handle
,
const
char
*
name
)
{
{
if
(
!
InitThread
())
return
0
;
if
(
handle
==
0
)
if
(
handle
==
0
)
return
-
1
;
return
-
1
;
...
@@ -1707,8 +1690,8 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion
...
@@ -1707,8 +1690,8 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion
{
{
if
(
!
InitThread
())
if
(
!
InitThread
())
return
false
;
return
false
;
SetThreadPoolAllocator
(
pool
);
SetThreadPoolAllocator
(
pool
);
if
(
!
preamble
)
if
(
!
preamble
)
preamble
=
""
;
preamble
=
""
;
...
@@ -1730,8 +1713,8 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources,
...
@@ -1730,8 +1713,8 @@ bool TShader::preprocess(const TBuiltInResource* builtInResources,
{
{
if
(
!
InitThread
())
if
(
!
InitThread
())
return
false
;
return
false
;
SetThreadPoolAllocator
(
pool
);
SetThreadPoolAllocator
(
pool
);
if
(
!
preamble
)
if
(
!
preamble
)
preamble
=
""
;
preamble
=
""
;
...
...
glslang/OSDependent/Unix/ossource.cpp
View file @
cb42541e
...
@@ -56,7 +56,6 @@ namespace glslang {
...
@@ -56,7 +56,6 @@ namespace glslang {
//
//
static
void
DetachThreadLinux
(
void
*
)
static
void
DetachThreadLinux
(
void
*
)
{
{
DetachThread
();
}
}
//
//
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment