From fb5a57ab97279728b6a44641ea72d340058057db Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 4 Apr 2018 11:13:13 +0200 Subject: Fix part of T53497: Eevee stuttering on macOS for the first few seconds of usage. The problem was that textures were assigned to different slots on different draw calls, which caused shader specialization/patching by the driver. So the shader would be compiled over and over until all possible assignments were used. --- source/blender/draw/intern/draw_manager_data.c | 19 ++++++++++++++++++- source/blender/draw/intern/draw_manager_exec.c | 8 ++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'source/blender/draw/intern') diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index b09e45e90f7..23e339bcd8f 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -82,7 +82,24 @@ static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup, int loc, uni->length = length; uni->arraysize = arraysize; - BLI_LINKS_PREPEND(shgroup->uniforms, uni); + /* Insert into list sorted by location so that slots are consistenly assigned + * for different draw calls, to avoid shader specialization/patching by the driver. */ + DRWUniform *next = shgroup->uniforms; + DRWUniform *prev = NULL; + + while (next && loc > next->location) { + prev = next; + next = next->next; + } + + if (prev) { + prev->next = uni; + } + else { + shgroup->uniforms = uni; + } + + uni->next = next; } static void drw_shgroup_builtin_uniform( diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 58cd6ce44c6..e69a1026815 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -861,6 +861,10 @@ static void release_texture_slots(bool with_persist) DST.RST.bound_tex_slots[i] = BIND_NONE; } } + + /* Reset so that slots are consistenly assigned for different shader + * draw calls, to avoid shader specialization/patching by the driver. */ + DST.RST.bind_tex_inc = 0; } static void release_ubo_slots(bool with_persist) @@ -874,6 +878,10 @@ static void release_ubo_slots(bool with_persist) DST.RST.bound_ubo_slots[i] = BIND_NONE; } } + + /* Reset so that slots are consistenly assigned for different shader + * draw calls, to avoid shader specialization/patching by the driver. */ + DST.RST.bind_ubo_inc = 0; } static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state) -- cgit v1.2.3