diff options
author | Kenneth Graunke <[email protected]> | 2018-11-21 18:15:28 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2019-02-21 10:26:10 -0800 |
commit | ed4ffb971585908e7bdd8ec1bfffbc6f7b06bd10 (patch) | |
tree | bba066ac74e6c3224b96000d4d2d4332e2178b3a /src | |
parent | 701a6b6006dad914c885c0b3c130fe47da2d5f54 (diff) |
iris: rework program cache interface
This exposes iris_upload_shader() without having to bind it, which will
be useful for precompiles. It also lets us examine the old programs and
flag dirty bits at a higher level, rather than cramming all that
knowledge into the cache layer.
Diffstat (limited to 'src')
-rw-r--r-- | src/gallium/drivers/iris/iris_context.h | 17 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_program.c | 177 | ||||
-rw-r--r-- | src/gallium/drivers/iris/iris_program_cache.c | 91 |
3 files changed, 131 insertions, 154 deletions
diff --git a/src/gallium/drivers/iris/iris_context.h b/src/gallium/drivers/iris/iris_context.h index ce5fffb171e..5bec8c35666 100644 --- a/src/gallium/drivers/iris/iris_context.h +++ b/src/gallium/drivers/iris/iris_context.h @@ -581,11 +581,10 @@ uint32_t iris_get_scratch_space(struct iris_context *ice, void iris_init_program_cache(struct iris_context *ice); void iris_destroy_program_cache(struct iris_context *ice); void iris_print_program_cache(struct iris_context *ice); -bool iris_bind_cached_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id, - const void *key); -void iris_unbind_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id); +struct iris_compiled_shader *iris_find_cached_shader(struct iris_context *ice, + enum iris_program_cache_id, + uint32_t key_size, + const void *key); struct iris_compiled_shader *iris_upload_shader(struct iris_context *ice, enum iris_program_cache_id, uint32_t key_size, @@ -595,14 +594,6 @@ struct iris_compiled_shader *iris_upload_shader(struct iris_context *ice, uint32_t *streamout, enum brw_param_builtin *sysv, unsigned num_system_values); -void iris_upload_and_bind_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id, - const void *key, - const void *assembly, - struct brw_stage_prog_data *prog_data, - uint32_t *streamout, - enum brw_param_builtin *system_values, - unsigned num_system_values); const void *iris_find_previous_compile(const struct iris_context *ice, enum iris_program_cache_id cache_id, unsigned program_string_id); diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index 9fc98a971ab..663a45c4a21 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -605,7 +605,7 @@ iris_setup_uniforms(const struct brw_compiler *compiler, /** * Compile a vertex shader, and upload the assembly. */ -static bool +static struct iris_compiled_shader * iris_compile_vs(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_vs_prog_key *key) @@ -664,11 +664,12 @@ iris_compile_vs(struct iris_context *ice, ice->vtbl.create_so_decl_list(&ish->stream_output, &vue_prog_data->vue_map); - iris_upload_and_bind_shader(ice, IRIS_CACHE_VS, key, program, prog_data, - so_decls, system_values, num_system_values); + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_VS, sizeof(*key), key, program, + prog_data, so_decls, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } /** @@ -685,10 +686,20 @@ iris_update_compiled_vs(struct iris_context *ice) struct brw_vs_prog_key key = { .program_string_id = ish->program_id }; ice->vtbl.populate_vs_key(ice, &ish->nir->info, &key); - if (iris_bind_cached_shader(ice, IRIS_CACHE_VS, &key)) - return; + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_VS]; + struct iris_compiled_shader *shader = + iris_find_cached_shader(ice, IRIS_CACHE_VS, sizeof(key), &key); + + if (!shader) + shader = iris_compile_vs(ice, ish, &key); - UNUSED bool success = iris_compile_vs(ice, ish, &key); + if (old != shader) { + ice->shaders.prog[IRIS_CACHE_VS] = shader; + ice->state.dirty |= IRIS_DIRTY_VS | + IRIS_DIRTY_BINDINGS_VS | + IRIS_DIRTY_CONSTANTS_VS | + IRIS_DIRTY_VF_SGVS; + } } /** @@ -756,7 +767,7 @@ get_unified_tess_slots(const struct iris_context *ice, /** * Compile a tessellation control shader, and upload the assembly. */ -static bool +static struct iris_compiled_shader * iris_compile_tcs(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_tcs_prog_key *key) @@ -802,11 +813,12 @@ iris_compile_tcs(struct iris_context *ice, return false; } - iris_upload_and_bind_shader(ice, IRIS_CACHE_TCS, key, program, prog_data, - NULL, system_values, num_system_values); + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_TCS, sizeof(*key), key, program, + prog_data, NULL, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } /** @@ -831,16 +843,25 @@ iris_update_compiled_tcs(struct iris_context *ice) &key.patch_outputs_written); ice->vtbl.populate_tcs_key(ice, &key); - if (iris_bind_cached_shader(ice, IRIS_CACHE_TCS, &key)) - return; + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_TCS]; + struct iris_compiled_shader *shader = + iris_find_cached_shader(ice, IRIS_CACHE_TCS, sizeof(key), &key); + + if (!shader) + shader = iris_compile_tcs(ice, tcs, &key); - UNUSED bool success = iris_compile_tcs(ice, tcs, &key); + if (old != shader) { + ice->shaders.prog[IRIS_CACHE_TCS] = shader; + ice->state.dirty |= IRIS_DIRTY_TCS | + IRIS_DIRTY_BINDINGS_TCS | + IRIS_DIRTY_CONSTANTS_TCS; + } } /** * Compile a tessellation evaluation shader, and upload the assembly. */ -static bool +static struct iris_compiled_shader * iris_compile_tes(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_tes_prog_key *key) @@ -882,11 +903,13 @@ iris_compile_tes(struct iris_context *ice, ice->vtbl.create_so_decl_list(&ish->stream_output, &vue_prog_data->vue_map); - iris_upload_and_bind_shader(ice, IRIS_CACHE_TES, key, program, prog_data, - so_decls, system_values, num_system_values); + + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_TES, sizeof(*key), key, program, + prog_data, so_decls, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } /** @@ -904,16 +927,25 @@ iris_update_compiled_tes(struct iris_context *ice) get_unified_tess_slots(ice, &key.inputs_read, &key.patch_inputs_read); ice->vtbl.populate_tes_key(ice, &key); - if (iris_bind_cached_shader(ice, IRIS_CACHE_TES, &key)) - return; + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_TES]; + struct iris_compiled_shader *shader = + iris_find_cached_shader(ice, IRIS_CACHE_TES, sizeof(key), &key); + + if (!shader) + shader = iris_compile_tes(ice, ish, &key); - UNUSED bool success = iris_compile_tes(ice, ish, &key); + if (old != shader) { + ice->shaders.prog[IRIS_CACHE_TES] = shader; + ice->state.dirty |= IRIS_DIRTY_TES | + IRIS_DIRTY_BINDINGS_TES | + IRIS_DIRTY_CONSTANTS_TES; + } } /** * Compile a geometry shader, and upload the assembly. */ -static bool +static struct iris_compiled_shader * iris_compile_gs(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_gs_prog_key *key) @@ -955,11 +987,12 @@ iris_compile_gs(struct iris_context *ice, ice->vtbl.create_so_decl_list(&ish->stream_output, &vue_prog_data->vue_map); - iris_upload_and_bind_shader(ice, IRIS_CACHE_GS, key, program, prog_data, - so_decls, system_values, num_system_values); + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_GS, sizeof(*key), key, program, + prog_data, so_decls, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } /** @@ -972,25 +1005,32 @@ iris_update_compiled_gs(struct iris_context *ice) { struct iris_uncompiled_shader *ish = ice->shaders.uncompiled[MESA_SHADER_GEOMETRY]; + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_GS]; + struct iris_compiled_shader *shader = NULL; - if (!ish) { - iris_unbind_shader(ice, IRIS_CACHE_GS); - return; - } + if (ish) { + struct brw_gs_prog_key key = { .program_string_id = ish->program_id }; + ice->vtbl.populate_gs_key(ice, &key); - struct brw_gs_prog_key key = { .program_string_id = ish->program_id }; - ice->vtbl.populate_gs_key(ice, &key); + shader = + iris_find_cached_shader(ice, IRIS_CACHE_GS, sizeof(key), &key); - if (iris_bind_cached_shader(ice, IRIS_CACHE_GS, &key)) - return; + if (!shader) + shader = iris_compile_gs(ice, ish, &key); + } - UNUSED bool success = iris_compile_gs(ice, ish, &key); + if (old != shader) { + ice->shaders.prog[IRIS_CACHE_GS] = shader; + ice->state.dirty |= IRIS_DIRTY_GS | + IRIS_DIRTY_BINDINGS_GS | + IRIS_DIRTY_CONSTANTS_GS; + } } /** * Compile a fragment (pixel) shader, and upload the assembly. */ -static bool +static struct iris_compiled_shader * iris_compile_fs(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_wm_prog_key *key, @@ -1026,13 +1066,12 @@ iris_compile_fs(struct iris_context *ice, return false; } - //brw_alloc_stage_scratch(brw, &brw->wm.base, prog_data.base.total_scratch); - - iris_upload_and_bind_shader(ice, IRIS_CACHE_FS, key, program, prog_data, - NULL, system_values, num_system_values); + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_FS, sizeof(*key), key, program, + prog_data, NULL, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } /** @@ -1051,11 +1090,24 @@ iris_update_compiled_fs(struct iris_context *ice) if (ish->nos & IRIS_NOS_LAST_VUE_MAP) key.input_slots_valid = ice->shaders.last_vue_map->slots_valid; - if (iris_bind_cached_shader(ice, IRIS_CACHE_FS, &key)) - return; - - UNUSED bool success = - iris_compile_fs(ice, ish, &key, ice->shaders.last_vue_map); + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_FS]; + struct iris_compiled_shader *shader = + iris_find_cached_shader(ice, IRIS_CACHE_FS, sizeof(key), &key); + + if (!shader) + shader = iris_compile_fs(ice, ish, &key, ice->shaders.last_vue_map); + + if (old != shader) { + // XXX: only need to flag CLIP if barycentric has NONPERSPECTIVE + // toggles. might be able to avoid flagging SBE too. + ice->shaders.prog[IRIS_CACHE_FS] = shader; + ice->state.dirty |= IRIS_DIRTY_FS | + IRIS_DIRTY_BINDINGS_FS | + IRIS_DIRTY_CONSTANTS_FS | + IRIS_DIRTY_WM | + IRIS_DIRTY_CLIP | + IRIS_DIRTY_SBE; + } } /** @@ -1123,6 +1175,9 @@ get_vue_prog_data(struct iris_context *ice, gl_shader_stage stage) return (void *) ice->shaders.prog[stage]->prog_data; } +// XXX: iris_compiled_shaders are space-leaking :( +// XXX: do remember to unbind them if deleting them. + /** * Update the current shader variants for the given state. * @@ -1148,8 +1203,12 @@ iris_update_compiled_shaders(struct iris_context *ice) iris_update_compiled_tcs(ice); iris_update_compiled_tes(ice); } else { - iris_unbind_shader(ice, IRIS_CACHE_TCS); - iris_unbind_shader(ice, IRIS_CACHE_TES); + ice->shaders.prog[IRIS_CACHE_TCS] = NULL; + ice->shaders.prog[IRIS_CACHE_TES] = NULL; + ice->state.dirty |= + IRIS_DIRTY_TCS | IRIS_DIRTY_TES | + IRIS_DIRTY_BINDINGS_TCS | IRIS_DIRTY_BINDINGS_TES | + IRIS_DIRTY_CONSTANTS_TCS | IRIS_DIRTY_CONSTANTS_TES; } } @@ -1183,7 +1242,7 @@ iris_update_compiled_shaders(struct iris_context *ice) } } -static bool +static struct iris_compiled_shader * iris_compile_cs(struct iris_context *ice, struct iris_uncompiled_shader *ish, const struct brw_cs_prog_key *key) @@ -1220,11 +1279,12 @@ iris_compile_cs(struct iris_context *ice, return false; } - iris_upload_and_bind_shader(ice, IRIS_CACHE_CS, key, program, prog_data, - NULL, system_values, num_system_values); + struct iris_compiled_shader *shader = + iris_upload_shader(ice, IRIS_CACHE_CS, sizeof(*key), key, program, + prog_data, NULL, system_values, num_system_values); ralloc_free(mem_ctx); - return true; + return shader; } void @@ -1236,10 +1296,19 @@ iris_update_compiled_compute_shader(struct iris_context *ice) struct brw_cs_prog_key key = { .program_string_id = ish->program_id }; ice->vtbl.populate_cs_key(ice, &key); - if (iris_bind_cached_shader(ice, IRIS_CACHE_CS, &key)) - return; + struct iris_compiled_shader *old = ice->shaders.prog[IRIS_CACHE_CS]; + struct iris_compiled_shader *shader = + iris_find_cached_shader(ice, IRIS_CACHE_CS, sizeof(key), &key); - UNUSED bool success = iris_compile_cs(ice, ish, &key); + if (!shader) + shader = iris_compile_cs(ice, ish, &key); + + if (old != shader) { + ice->shaders.prog[IRIS_CACHE_CS] = shader; + ice->state.dirty |= IRIS_DIRTY_CS | + IRIS_DIRTY_BINDINGS_CS | + IRIS_DIRTY_CONSTANTS_CS; + } } void diff --git a/src/gallium/drivers/iris/iris_program_cache.c b/src/gallium/drivers/iris/iris_program_cache.c index 294471493d3..44a38f1b4aa 100644 --- a/src/gallium/drivers/iris/iris_program_cache.c +++ b/src/gallium/drivers/iris/iris_program_cache.c @@ -101,26 +101,6 @@ keybox_equals(const void *void_a, const void *void_b) return memcmp(a->data, b->data, a->size) == 0; } -static uint64_t -dirty_flag_for_cache(enum iris_program_cache_id cache_id) -{ - assert(cache_id <= MESA_SHADER_STAGES); - - uint64_t flags = (IRIS_DIRTY_VS | - IRIS_DIRTY_BINDINGS_VS | - IRIS_DIRTY_CONSTANTS_VS) << cache_id; - // XXX: ugly... - // XXX: move this flagging out to a higher level, allow comparison of - // XXX: new and old programs to decide what bits to twiddle - // XXX: CLIP: toggle if barycentric modes has any NONPERSPECTIVE or not - if (cache_id == IRIS_CACHE_FS) - flags |= IRIS_DIRTY_WM | IRIS_DIRTY_CLIP | IRIS_DIRTY_SBE; - if (cache_id == IRIS_CACHE_VS) - flags |= IRIS_DIRTY_VF_SGVS; - - return flags; -} - static unsigned get_program_string_id(enum iris_program_cache_id cache_id, const void *key) { @@ -142,11 +122,11 @@ get_program_string_id(enum iris_program_cache_id cache_id, const void *key) } } -static struct iris_compiled_shader * +struct iris_compiled_shader * iris_find_cached_shader(struct iris_context *ice, enum iris_program_cache_id cache_id, - const void *key, - uint32_t key_size) + uint32_t key_size, + const void *key) { struct keybox *keybox = make_keybox(ice->shaders.cache, cache_id, key, key_size); @@ -158,43 +138,6 @@ iris_find_cached_shader(struct iris_context *ice, return entry ? entry->data : NULL; } -/** - * Looks for a program in the cache and binds it. - * - * If no program was found, returns false and leaves the binding alone. - */ -bool -iris_bind_cached_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id, - const void *key) -{ - unsigned key_size = key_size_for_cache(cache_id); - struct iris_compiled_shader *shader = - iris_find_cached_shader(ice, cache_id, key, key_size); - - if (!shader) - return false; - - // XXX: why memcmp? - if (!ice->shaders.prog[cache_id] || - memcmp(shader, ice->shaders.prog[cache_id], sizeof(*shader)) != 0) { - ice->shaders.prog[cache_id] = shader; - ice->state.dirty |= dirty_flag_for_cache(cache_id); - } - - return true; -} - -void -iris_unbind_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id) -{ - if (ice->shaders.prog[cache_id]) { - ice->shaders.prog[cache_id] = NULL; - ice->state.dirty |= dirty_flag_for_cache(cache_id); - } -} - const void * iris_find_previous_compile(const struct iris_context *ice, enum iris_program_cache_id cache_id, @@ -288,32 +231,6 @@ iris_upload_shader(struct iris_context *ice, return shader; } -/** - * Upload a new shader to the program cache, and bind it for use. - * - * \param prog_data must be ralloc'd and will be stolen. - */ -void -iris_upload_and_bind_shader(struct iris_context *ice, - enum iris_program_cache_id cache_id, - const void *key, - const void *assembly, - struct brw_stage_prog_data *prog_data, - uint32_t *streamout, - enum brw_param_builtin *system_values, - unsigned num_system_values) -{ - assert(cache_id != IRIS_CACHE_BLORP); - - struct iris_compiled_shader *shader = - iris_upload_shader(ice, cache_id, key_size_for_cache(cache_id), key, - assembly, prog_data, streamout, system_values, - num_system_values); - - ice->shaders.prog[cache_id] = shader; - ice->state.dirty |= dirty_flag_for_cache(cache_id); -} - bool iris_blorp_lookup_shader(struct blorp_batch *blorp_batch, const void *key, uint32_t key_size, @@ -323,7 +240,7 @@ iris_blorp_lookup_shader(struct blorp_batch *blorp_batch, struct iris_context *ice = blorp->driver_ctx; struct iris_batch *batch = blorp_batch->driver_batch; struct iris_compiled_shader *shader = - iris_find_cached_shader(ice, IRIS_CACHE_BLORP, key, key_size); + iris_find_cached_shader(ice, IRIS_CACHE_BLORP, key_size, key); if (!shader) return false; |