From a4bd66f85473e44b4a841c2f349fb8f52005de7d Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Fri, 19 Jun 2020 09:42:04 +0100 Subject: [PATCH] GLES2 Batching - prevent baking on VERTEX use in a shader Using the operator += in a shader is classified as an 'assign', and so is classified as a write rather than a read. This means that we need to prevent vertex baking on either a write or read (i.e. on usage), rather than just on reads. --- drivers/gles2/rasterizer_storage_gles2.cpp | 7 +++---- drivers/gles2/rasterizer_storage_gles2.h | 2 +- drivers/gles2/shader_compiler_gles2.cpp | 4 ---- drivers/gles2/shader_compiler_gles2.h | 1 - 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/gles2/rasterizer_storage_gles2.cpp b/drivers/gles2/rasterizer_storage_gles2.cpp index 01db597452a..518cbd782bc 100644 --- a/drivers/gles2/rasterizer_storage_gles2.cpp +++ b/drivers/gles2/rasterizer_storage_gles2.cpp @@ -1426,7 +1426,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { p_shader->canvas_item.uses_time = false; p_shader->canvas_item.uses_modulate = false; p_shader->canvas_item.uses_color = false; - p_shader->canvas_item.reads_vertex = false; + p_shader->canvas_item.uses_vertex = false; p_shader->canvas_item.batch_flags = 0; shaders.actions_canvas.render_mode_values["blend_add"] = Pair(&p_shader->canvas_item.blend_mode, Shader::CanvasItem::BLEND_MODE_ADD); @@ -1444,8 +1444,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { shaders.actions_canvas.usage_flag_pointers["TIME"] = &p_shader->canvas_item.uses_time; shaders.actions_canvas.usage_flag_pointers["MODULATE"] = &p_shader->canvas_item.uses_modulate; shaders.actions_canvas.usage_flag_pointers["COLOR"] = &p_shader->canvas_item.uses_color; - - shaders.actions_canvas.read_flag_pointers["VERTEX"] = &p_shader->canvas_item.reads_vertex; + shaders.actions_canvas.usage_flag_pointers["VERTEX"] = &p_shader->canvas_item.uses_vertex; actions = &shaders.actions_canvas; actions->uniforms = &p_shader->uniforms; @@ -1538,7 +1537,7 @@ void RasterizerStorageGLES2::_update_shader(Shader *p_shader) const { if (p_shader->canvas_item.uses_modulate | p_shader->canvas_item.uses_color) { p_shader->canvas_item.batch_flags |= Shader::CanvasItem::PREVENT_COLOR_BAKING; } - if (p_shader->canvas_item.reads_vertex) { + if (p_shader->canvas_item.uses_vertex) { p_shader->canvas_item.batch_flags |= Shader::CanvasItem::PREVENT_VERTEX_BAKING; } } diff --git a/drivers/gles2/rasterizer_storage_gles2.h b/drivers/gles2/rasterizer_storage_gles2.h index f27e979928c..88119b77529 100644 --- a/drivers/gles2/rasterizer_storage_gles2.h +++ b/drivers/gles2/rasterizer_storage_gles2.h @@ -461,7 +461,7 @@ public: bool uses_time; bool uses_modulate; bool uses_color; - bool reads_vertex; + bool uses_vertex; } canvas_item; diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 7c9e0c1b982..55e07321255 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -486,10 +486,6 @@ String ShaderCompilerGLES2::_dump_node_code(SL::Node *p_node, int p_level, Gener *p_actions.write_flag_pointers[var_node->name] = true; } - if (!p_assigning && p_actions.read_flag_pointers.has(var_node->name)) { - *p_actions.read_flag_pointers[var_node->name] = true; - } - if (p_default_actions.usage_defines.has(var_node->name) && !used_name_defines.has(var_node->name)) { String define = p_default_actions.usage_defines[var_node->name]; String node_name = define.substr(1, define.length()); diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h index a8c096418e7..71bf8e9fd90 100644 --- a/drivers/gles2/shader_compiler_gles2.h +++ b/drivers/gles2/shader_compiler_gles2.h @@ -44,7 +44,6 @@ public: Map > render_mode_values; Map render_mode_flags; Map usage_flag_pointers; - Map read_flag_pointers; Map write_flag_pointers; Map *uniforms;