Fix: GL: Race condition in shader compilation
The patch strings did not have thread safe initialization. The string might hav been returned null or incomplete which might trigger compilation errors.
This commit is contained in:
@@ -1027,79 +1027,73 @@ bool GLShader::do_geometry_shader_injection(const shader::ShaderCreateInfo *info
|
||||
static StringRefNull glsl_patch_default_get()
|
||||
{
|
||||
/** Used for shader patching. Init once. */
|
||||
static std::string patch;
|
||||
if (!patch.empty()) {
|
||||
return patch;
|
||||
}
|
||||
static std::string patch = []() {
|
||||
std::stringstream ss;
|
||||
/* Version need to go first. */
|
||||
if (epoxy_gl_version() >= 43) {
|
||||
ss << "#version 430\n";
|
||||
}
|
||||
else {
|
||||
ss << "#version 330\n";
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
/* Version need to go first. */
|
||||
if (epoxy_gl_version() >= 43) {
|
||||
ss << "#version 430\n";
|
||||
}
|
||||
else {
|
||||
ss << "#version 330\n";
|
||||
}
|
||||
/* Enable extensions for features that are not part of our base GLSL version
|
||||
* don't use an extension for something already available! */
|
||||
if (GLContext::shader_draw_parameters_support) {
|
||||
ss << "#extension GL_ARB_shader_draw_parameters : enable\n";
|
||||
ss << "#define GPU_ARB_shader_draw_parameters\n";
|
||||
ss << "#define gpu_BaseInstance gl_BaseInstanceARB\n";
|
||||
}
|
||||
if (GLContext::layered_rendering_support) {
|
||||
ss << "#extension GL_ARB_shader_viewport_layer_array: enable\n";
|
||||
}
|
||||
if (GLContext::native_barycentric_support) {
|
||||
ss << "#extension GL_AMD_shader_explicit_vertex_parameter: enable\n";
|
||||
}
|
||||
if (GLContext::framebuffer_fetch_support) {
|
||||
ss << "#extension GL_EXT_shader_framebuffer_fetch: enable\n";
|
||||
}
|
||||
if (GPU_stencil_export_support()) {
|
||||
ss << "#extension GL_ARB_shader_stencil_export: enable\n";
|
||||
ss << "#define GPU_ARB_shader_stencil_export\n";
|
||||
}
|
||||
|
||||
/* Enable extensions for features that are not part of our base GLSL version
|
||||
* don't use an extension for something already available! */
|
||||
if (GLContext::shader_draw_parameters_support) {
|
||||
ss << "#extension GL_ARB_shader_draw_parameters : enable\n";
|
||||
ss << "#define GPU_ARB_shader_draw_parameters\n";
|
||||
ss << "#define gpu_BaseInstance gl_BaseInstanceARB\n";
|
||||
}
|
||||
if (GLContext::layered_rendering_support) {
|
||||
ss << "#extension GL_ARB_shader_viewport_layer_array: enable\n";
|
||||
}
|
||||
if (GLContext::native_barycentric_support) {
|
||||
ss << "#extension GL_AMD_shader_explicit_vertex_parameter: enable\n";
|
||||
}
|
||||
if (GLContext::framebuffer_fetch_support) {
|
||||
ss << "#extension GL_EXT_shader_framebuffer_fetch: enable\n";
|
||||
}
|
||||
if (GPU_stencil_export_support()) {
|
||||
ss << "#extension GL_ARB_shader_stencil_export: enable\n";
|
||||
ss << "#define GPU_ARB_shader_stencil_export\n";
|
||||
}
|
||||
/* Fallbacks. */
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
ss << "uniform int gpu_BaseInstance;\n";
|
||||
}
|
||||
|
||||
/* Fallbacks. */
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
ss << "uniform int gpu_BaseInstance;\n";
|
||||
}
|
||||
/* Vulkan GLSL compatibility. */
|
||||
ss << "#define gpu_InstanceIndex (gl_InstanceID + gpu_BaseInstance)\n";
|
||||
ss << "#define gpu_EmitVertex EmitVertex\n";
|
||||
|
||||
/* Vulkan GLSL compatibility. */
|
||||
ss << "#define gpu_InstanceIndex (gl_InstanceID + gpu_BaseInstance)\n";
|
||||
ss << "#define gpu_EmitVertex EmitVertex\n";
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
/* GLSL Backend Lib. */
|
||||
ss << datatoc_glsl_shader_defines_glsl;
|
||||
|
||||
/* GLSL Backend Lib. */
|
||||
ss << datatoc_glsl_shader_defines_glsl;
|
||||
|
||||
patch = ss.str();
|
||||
return ss.str();
|
||||
}();
|
||||
return patch;
|
||||
}
|
||||
|
||||
static StringRefNull glsl_patch_compute_get()
|
||||
{
|
||||
/** Used for shader patching. Init once. */
|
||||
static std::string patch;
|
||||
if (!patch.empty()) {
|
||||
return patch;
|
||||
}
|
||||
static std::string patch = []() {
|
||||
std::stringstream ss;
|
||||
/* Version need to go first. */
|
||||
ss << "#version 430\n";
|
||||
ss << "#extension GL_ARB_compute_shader :enable\n";
|
||||
|
||||
std::stringstream ss;
|
||||
/* Version need to go first. */
|
||||
ss << "#version 430\n";
|
||||
ss << "#extension GL_ARB_compute_shader :enable\n";
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
|
||||
/* Array compatibility. */
|
||||
ss << "#define gpu_Array(_type) _type[]\n";
|
||||
ss << datatoc_glsl_shader_defines_glsl;
|
||||
|
||||
ss << datatoc_glsl_shader_defines_glsl;
|
||||
|
||||
patch = ss.str();
|
||||
return ss.str();
|
||||
}();
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user