glslang icon indicating copy to clipboard operation
glslang copied to clipboard

Remove global state

Open haasn opened this issue 8 years ago • 4 comments

Using global state (ShInitialize, InitGlobalLock, PerProcessGPA etc.) is bad API design and makes using glslang in multi-threaded applications both risky and difficult.

You should group this global state into a “context” struct and pass it around explicitly where needed.

haasn avatar Aug 10 '17 17:08 haasn

It would be great if this context could be available to the C API too.

ghost avatar Aug 10 '17 19:08 ghost

See #976 which is a plan to at least partially address this. Would be great to have some feedback on it.

If there is still a problem with global state, we need a proposal for fixing it without breaking existing uses, but rather deprecating current use, leaving an overlap between current use and a safer model.

johnkslang avatar Aug 11 '17 07:08 johnkslang

Well, the "old" APIs, which require global context, could probably be easily emulated. You'd just have the init functions create a global object or such.

I admit I'm unfamiliar with the implementation, though.

ghost avatar Aug 11 '17 08:08 ghost

Another piece of removing global state, or rather converting it to constant data: https://github.com/KhronosGroup/glslang/pull/3720. The only global data left are the symbol tables and the global PoolAllocator.

arcady-lunarg avatar Sep 10 '24 16:09 arcady-lunarg