From cf05bb506a075c9e3b8a3c374b928ff0367c49b2 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 8 Nov 2017 09:54:22 +1100 Subject: [PATCH] glsl: drop cache_fallback MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This turned out to be a dead end, it is much easier and less error prone to just cache the IR used by the drivers backend e.g. TGSI or NIR. Cc: "17.2 17.3" Reviewed-by: Tapani Pälli Reviewed-by: Kenneth Graunke --- src/compiler/glsl/link_uniforms.cpp | 15 +---- src/compiler/glsl/linker.cpp | 85 +++++++++++++---------------- src/compiler/glsl/shader_cache.cpp | 2 +- src/mesa/main/mtypes.h | 7 +-- src/mesa/main/shaderobj.c | 23 ++++---- 5 files changed, 55 insertions(+), 77 deletions(-) diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index 7d141549f55..3da015eb7fd 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -1400,13 +1400,6 @@ link_assign_uniform_storage(struct gl_context *ctx, sizeof(shader->Program->sh.SamplerTargets)); } - /* If this is a fallback compile for a cache miss we already have the - * correct uniform mappings and we don't want to reinitialise uniforms so - * just return now. - */ - if (prog->data->cache_fallback) - return; - #ifndef NDEBUG for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) { assert(prog->data->UniformStorage[i].storage != NULL || @@ -1431,11 +1424,9 @@ void link_assign_uniform_locations(struct gl_shader_program *prog, struct gl_context *ctx) { - if (!prog->data->cache_fallback) { - ralloc_free(prog->data->UniformStorage); - prog->data->UniformStorage = NULL; - prog->data->NumUniformStorage = 0; - } + ralloc_free(prog->data->UniformStorage); + prog->data->UniformStorage = NULL; + prog->data->NumUniformStorage = 0; if (prog->UniformHash != NULL) { prog->UniformHash->clear(); diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 3b8734fc8b8..cb2a6c7892a 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -2264,8 +2264,7 @@ link_intrastage_shaders(void *mem_ctx, return NULL; } - if (!prog->data->cache_fallback) - _mesa_reference_shader_program_data(ctx, &gl_prog->sh.data, prog->data); + _mesa_reference_shader_program_data(ctx, &gl_prog->sh.data, prog->data); /* Don't use _mesa_reference_program() just take ownership */ linked->Program = gl_prog; @@ -2322,34 +2321,32 @@ link_intrastage_shaders(void *mem_ctx, v.run(linked->ir); v.fixup_unnamed_interface_types(); - if (!prog->data->cache_fallback) { - /* Link up uniform blocks defined within this stage. */ - link_uniform_blocks(mem_ctx, ctx, prog, linked, &ubo_blocks, - &num_ubo_blocks, &ssbo_blocks, &num_ssbo_blocks); + /* Link up uniform blocks defined within this stage. */ + link_uniform_blocks(mem_ctx, ctx, prog, linked, &ubo_blocks, + &num_ubo_blocks, &ssbo_blocks, &num_ssbo_blocks); - if (!prog->data->LinkStatus) { - _mesa_delete_linked_shader(ctx, linked); - return NULL; - } + if (!prog->data->LinkStatus) { + _mesa_delete_linked_shader(ctx, linked); + return NULL; + } - /* Copy ubo blocks to linked shader list */ - linked->Program->sh.UniformBlocks = - ralloc_array(linked, gl_uniform_block *, num_ubo_blocks); - ralloc_steal(linked, ubo_blocks); - for (unsigned i = 0; i < num_ubo_blocks; i++) { - linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i]; - } - linked->Program->info.num_ubos = num_ubo_blocks; - - /* Copy ssbo blocks to linked shader list */ - linked->Program->sh.ShaderStorageBlocks = - ralloc_array(linked, gl_uniform_block *, num_ssbo_blocks); - ralloc_steal(linked, ssbo_blocks); - for (unsigned i = 0; i < num_ssbo_blocks; i++) { - linked->Program->sh.ShaderStorageBlocks[i] = &ssbo_blocks[i]; - } - linked->Program->info.num_ssbos = num_ssbo_blocks; + /* Copy ubo blocks to linked shader list */ + linked->Program->sh.UniformBlocks = + ralloc_array(linked, gl_uniform_block *, num_ubo_blocks); + ralloc_steal(linked, ubo_blocks); + for (unsigned i = 0; i < num_ubo_blocks; i++) { + linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i]; + } + linked->Program->info.num_ubos = num_ubo_blocks; + + /* Copy ssbo blocks to linked shader list */ + linked->Program->sh.ShaderStorageBlocks = + ralloc_array(linked, gl_uniform_block *, num_ssbo_blocks); + ralloc_steal(linked, ssbo_blocks); + for (unsigned i = 0; i < num_ssbo_blocks; i++) { + linked->Program->sh.ShaderStorageBlocks[i] = &ssbo_blocks[i]; } + linked->Program->info.num_ssbos = num_ssbo_blocks; /* At this point linked should contain all of the linked IR, so * validate it to make sure nothing went wrong. @@ -4639,14 +4636,12 @@ link_and_validate_uniforms(struct gl_context *ctx, update_array_sizes(prog); link_assign_uniform_locations(prog, ctx); - if (!prog->data->cache_fallback) { - link_assign_atomic_counter_resources(ctx, prog); - link_calculate_subroutine_compat(prog); - check_resources(ctx, prog); - check_subroutine_resources(prog); - check_image_resources(ctx, prog); - link_check_atomic_counter_resources(ctx, prog); - } + link_assign_atomic_counter_resources(ctx, prog); + link_calculate_subroutine_compat(prog); + check_resources(ctx, prog); + check_subroutine_resources(prog); + check_image_resources(ctx, prog); + link_check_atomic_counter_resources(ctx, prog); } static bool @@ -4960,10 +4955,8 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) last = i; } - if (!prog->data->cache_fallback) { - check_explicit_uniform_locations(ctx, prog); - link_assign_subroutine_types(prog); - } + check_explicit_uniform_locations(ctx, prog); + link_assign_subroutine_types(prog); if (!prog->data->LinkStatus) goto done; @@ -5028,15 +5021,13 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if (prog->SeparateShader) disable_varying_optimizations_for_sso(prog); - if (!prog->data->cache_fallback) { - /* Process UBOs */ - if (!interstage_cross_validate_uniform_blocks(prog, false)) - goto done; + /* Process UBOs */ + if (!interstage_cross_validate_uniform_blocks(prog, false)) + goto done; - /* Process SSBOs */ - if (!interstage_cross_validate_uniform_blocks(prog, true)) - goto done; - } + /* Process SSBOs */ + if (!interstage_cross_validate_uniform_blocks(prog, true)) + goto done; /* Do common optimization before assigning storage for attributes, * uniforms, and varyings. Later optimization could possibly make diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index 8fd2774bdfa..89da19914fe 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -1299,7 +1299,7 @@ shader_cache_read_program_metadata(struct gl_context *ctx, return false; struct disk_cache *cache = ctx->Cache; - if (!cache || prog->data->cache_fallback || prog->data->skip_cache) + if (!cache || prog->data->skip_cache) return false; /* Include bindings when creating sha1. These bindings change the resulting diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 2acf64eb56d..a6931649aa0 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -2872,12 +2872,11 @@ struct gl_shader_program_data unsigned NumUniformDataSlots; union gl_constant_value *UniformDataSlots; - bool cache_fallback; - /* TODO: This used by Gallium drivers to skip the cache on tgsi fallback. * All structures (gl_program, uniform storage, etc) will get recreated - * even though we have already loaded them from cache. Once the i965 cache - * lands we should switch to using the cache_fallback support. + * even though we have already loaded them from cache. We should instead + * switch to storing the GLSL metadata and TGSI IR in a single cache item + * like the i965 driver does with NIR. */ bool skip_cache; GLboolean Validated; diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c index b9d1079a35a..e2103bcde49 100644 --- a/src/mesa/main/shaderobj.c +++ b/src/mesa/main/shaderobj.c @@ -327,7 +327,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx, shProg->data->linked_stages = 0; - if (shProg->data->UniformStorage && !shProg->data->cache_fallback) { + if (shProg->data->UniformStorage) { for (unsigned i = 0; i < shProg->data->NumUniformStorage; ++i) _mesa_uniform_detach_all_driver_storage(&shProg->data-> UniformStorage[i]); @@ -336,7 +336,7 @@ _mesa_clear_shader_program_data(struct gl_context *ctx, shProg->data->UniformStorage = NULL; } - if (shProg->UniformRemapTable && !shProg->data->cache_fallback) { + if (shProg->UniformRemapTable) { ralloc_free(shProg->UniformRemapTable); shProg->NumUniformRemapTable = 0; shProg->UniformRemapTable = NULL; @@ -351,17 +351,15 @@ _mesa_clear_shader_program_data(struct gl_context *ctx, ralloc_free(shProg->data->InfoLog); shProg->data->InfoLog = ralloc_strdup(shProg->data, ""); - if (!shProg->data->cache_fallback) { - ralloc_free(shProg->data->UniformBlocks); - shProg->data->UniformBlocks = NULL; - shProg->data->NumUniformBlocks = 0; + ralloc_free(shProg->data->UniformBlocks); + shProg->data->UniformBlocks = NULL; + shProg->data->NumUniformBlocks = 0; - ralloc_free(shProg->data->ShaderStorageBlocks); - shProg->data->ShaderStorageBlocks = NULL; - shProg->data->NumShaderStorageBlocks = 0; - } + ralloc_free(shProg->data->ShaderStorageBlocks); + shProg->data->ShaderStorageBlocks = NULL; + shProg->data->NumShaderStorageBlocks = 0; - if (shProg->data->AtomicBuffers && !shProg->data->cache_fallback) { + if (shProg->data->AtomicBuffers) { ralloc_free(shProg->data->AtomicBuffers); shProg->data->AtomicBuffers = NULL; shProg->data->NumAtomicBuffers = 0; @@ -434,8 +432,7 @@ _mesa_delete_shader_program(struct gl_context *ctx, struct gl_shader_program *shProg) { _mesa_free_shader_program_data(ctx, shProg); - if (!shProg->data->cache_fallback) - _mesa_reference_shader_program_data(ctx, &shProg->data, NULL); + _mesa_reference_shader_program_data(ctx, &shProg->data, NULL); ralloc_free(shProg); } -- 2.30.2