/**
* 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)
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;
}
/**
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;
+ }
}
/**
/**
* 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)
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;
}
/**
&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)
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;
}
/**
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)
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;
}
/**
{
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,
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;
}
/**
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;
+ }
}
/**
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.
*
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;
}
}
}
}
-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)
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
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
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)
{
}
}
-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);
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,
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,
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;