GLShader: Fix buffer overflow caused by workaround uniform
In order to use a workaround builtin uniform, we need to count it just like other uniforms and give it some space in the name buffer. This also fixes extensions being added after the uniform declaration. All `#extension` directives are now part of the gl backend.
This commit is contained in:
@@ -887,10 +887,7 @@ struct GPUShader *EEVEE_shaders_volumes_integration_sh_get()
|
||||
datatoc_volumetric_geom_glsl,
|
||||
datatoc_volumetric_integration_frag_glsl,
|
||||
e_data.lib,
|
||||
USE_VOLUME_OPTI ? "#extension GL_ARB_shader_image_load_store: enable\n"
|
||||
"#extension GL_ARB_shading_language_420pack: enable\n"
|
||||
"#define USE_VOLUME_OPTI\n" SHADER_DEFINES :
|
||||
SHADER_DEFINES);
|
||||
USE_VOLUME_OPTI ? "#define USE_VOLUME_OPTI\n" SHADER_DEFINES : SHADER_DEFINES);
|
||||
}
|
||||
return e_data.volumetric_integration_sh;
|
||||
}
|
||||
|
||||
@@ -385,7 +385,7 @@ GPUShader *OVERLAY_shader_armature_sphere(bool use_outline)
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
const GPUShaderConfigData *sh_cfg = &GPU_shader_cfg_data[draw_ctx->sh_cfg];
|
||||
OVERLAY_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg];
|
||||
const char extensions[] = "#extension GL_ARB_conservative_depth : enable\n";
|
||||
const char extensions[] = "";
|
||||
if (use_outline && !sh_data->armature_sphere_outline) {
|
||||
sh_data->armature_sphere_outline = GPU_shader_create_from_arrays({
|
||||
.vert = (const char *[]){sh_cfg->lib,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#extension GL_ARB_gpu_shader5 : enable
|
||||
|
||||
#ifdef GL_ARB_gpu_shader5
|
||||
# define USE_INVOC_EXT
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#extension GL_ARB_gpu_shader5 : enable
|
||||
|
||||
#ifdef GL_ARB_gpu_shader5
|
||||
# define USE_INVOC_EXT
|
||||
#endif
|
||||
|
||||
@@ -587,6 +587,18 @@ static char *glsl_patch_default_get()
|
||||
STR_CONCAT(patch, slen, "#extension GL_ARB_texture_cube_map_array : enable\n");
|
||||
STR_CONCAT(patch, slen, "#define GPU_ARB_texture_cube_map_array\n");
|
||||
}
|
||||
if (GLEW_ARB_conservative_depth) {
|
||||
STR_CONCAT(patch, slen, "#extension GL_ARB_conservative_depth : enable\n");
|
||||
}
|
||||
if (GPU_shader_image_load_store_support()) {
|
||||
STR_CONCAT(patch, slen, "#extension GL_ARB_shader_image_load_store: enable\n");
|
||||
STR_CONCAT(patch, slen, "#extension GL_ARB_shading_language_420pack: enable\n");
|
||||
}
|
||||
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
/* Fallback: Emulate base instance using a uniform. */
|
||||
STR_CONCAT(patch, slen, "uniform int gpu_BaseInstance;\n");
|
||||
}
|
||||
|
||||
/* Fallbacks. */
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
|
||||
@@ -355,13 +355,28 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
|
||||
}
|
||||
}
|
||||
|
||||
size_t workaround_names_size = 0;
|
||||
Vector<StringRefNull> workaround_uniform_names;
|
||||
auto check_enabled_uniform = [&](const char *uniform_name) {
|
||||
if (glGetUniformLocation(program, uniform_name) != -1) {
|
||||
workaround_uniform_names.append(uniform_name);
|
||||
workaround_names_size += StringRefNull(uniform_name).size() + 1;
|
||||
uniform_len_++;
|
||||
}
|
||||
};
|
||||
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
check_enabled_uniform("gpu_BaseInstance");
|
||||
}
|
||||
|
||||
BLI_assert_msg(ubo_len_ <= 16, "enabled_ubo_mask_ is uint16_t");
|
||||
|
||||
int input_tot_len = attr_len_ + ubo_len_ + uniform_len_ + ssbo_len_;
|
||||
inputs_ = (ShaderInput *)MEM_callocN(sizeof(ShaderInput) * input_tot_len, __func__);
|
||||
ShaderInput *input = inputs_;
|
||||
|
||||
name_buffer_ = (char *)MEM_mallocN(info.interface_names_size_, "name_buffer");
|
||||
name_buffer_ = (char *)MEM_mallocN(info.interface_names_size_ + workaround_names_size,
|
||||
"name_buffer");
|
||||
uint32_t name_buffer_offset = 0;
|
||||
|
||||
/* Necessary to make #glUniform works. TODO(fclem) Remove. */
|
||||
@@ -430,6 +445,14 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
|
||||
input++;
|
||||
}
|
||||
|
||||
/* Compatibility uniforms. */
|
||||
for (auto &name : workaround_uniform_names) {
|
||||
copy_input_name(input, name, name_buffer_, name_buffer_offset);
|
||||
input->location = glGetUniformLocation(program, name_buffer_ + input->name_offset);
|
||||
input->binding = -1;
|
||||
input++;
|
||||
}
|
||||
|
||||
/* SSBOs */
|
||||
for (const ShaderCreateInfo::Resource &res : all_resources) {
|
||||
if (res.bind_type == ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER) {
|
||||
@@ -440,14 +463,6 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
|
||||
}
|
||||
}
|
||||
|
||||
/* Compatibility uniforms. */
|
||||
if (!GLContext::shader_draw_parameters_support) {
|
||||
input->location = glGetUniformLocation(program, "gpu_BaseInstance");
|
||||
copy_input_name(input, "gpu_BaseInstance", name_buffer_, name_buffer_offset);
|
||||
input->binding = -1;
|
||||
input++;
|
||||
}
|
||||
|
||||
/* Builtin Uniforms */
|
||||
for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORMS; u_int++) {
|
||||
GPUUniformBuiltin u = static_cast<GPUUniformBuiltin>(u_int);
|
||||
|
||||
Reference in New Issue
Block a user