#include "util/u_upload_mgr.h"
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
+#include "intel/common/gen_disasm.h"
#include "intel/compiler/brw_compiler.h"
#include "intel/compiler/brw_eu.h"
#include "intel/compiler/brw_nir.h"
return NULL;
}
+void
+iris_delete_shader_variants(struct iris_context *ice,
+ struct iris_uncompiled_shader *ish)
+{
+ struct hash_table *cache = ice->shaders.cache;
+ gl_shader_stage stage = ish->nir->info.stage;
+ enum iris_program_cache_id cache_id = stage;
+
+ hash_table_foreach(cache, entry) {
+ const struct keybox *keybox = entry->key;
+ const struct brw_base_prog_key *key = (const void *)keybox->data;
+
+ if (keybox->cache_id == cache_id &&
+ key->program_string_id == ish->program_id) {
+ struct iris_compiled_shader *shader = entry->data;
+
+ _mesa_hash_table_remove(cache, entry);
+
+ /* Shader variants may still be bound in the context even after
+ * the API-facing shader has been deleted. In particular, a draw
+ * may not have triggered iris_update_compiled_shaders() yet. In
+ * that case, we may be referring to that shader's VUE map, stream
+ * output settings, and so on. We also like to compare the old and
+ * new shader programs when swapping them out to flag dirty state.
+ *
+ * So, it's hazardous to delete a bound shader variant. We avoid
+ * doing so, choosing to instead move "deleted" shader variants to
+ * a list, deferring the actual deletion until they're not bound.
+ *
+ * For simplicity, we always move deleted variants to the list,
+ * even if we could delete them immediately. We'll then process
+ * the list, catching both these variants and any others.
+ */
+ list_addtail(&shader->link, &ice->shaders.deleted_variants[stage]);
+ }
+ }
+
+ /* Process any pending deferred variant deletions. */
+ list_for_each_entry_safe(struct iris_compiled_shader, shader,
+ &ice->shaders.deleted_variants[stage], link) {
+ /* If the shader is still bound, defer deletion. */
+ if (ice->shaders.prog[stage] == shader)
+ continue;
+
+ list_del(&shader->link);
+
+ /* Actually delete the variant. */
+ pipe_resource_reference(&shader->assembly.res, NULL);
+ ralloc_free(shader);
+ }
+}
+
+
/**
* Look for an existing entry in the cache that has identical assembly code.
*
uint32_t *streamout,
enum brw_param_builtin *system_values,
unsigned num_system_values,
+ unsigned kernel_input_size,
unsigned num_cbufs,
const struct iris_binding_table *bt)
{
struct hash_table *cache = ice->shaders.cache;
+ struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;
struct iris_compiled_shader *shader =
rzalloc_size(cache, sizeof(struct iris_compiled_shader) +
- ice->vtbl.derived_program_state_size(cache_id));
+ screen->vtbl.derived_program_state_size(cache_id));
const struct iris_compiled_shader *existing =
find_existing_assembly(cache, assembly, prog_data->program_size);
memcpy(shader->map, assembly, prog_data->program_size);
}
+ list_inithead(&shader->link);
+
shader->prog_data = prog_data;
shader->streamout = streamout;
shader->system_values = system_values;
shader->num_system_values = num_system_values;
+ shader->kernel_input_size = kernel_input_size;
shader->num_cbufs = num_cbufs;
shader->bt = *bt;
ralloc_steal(shader, shader->system_values);
/* Store the 3DSTATE shader packets and other derived state. */
- ice->vtbl.store_derived_program_state(ice, cache_id, shader);
+ screen->vtbl.store_derived_program_state(ice, cache_id, shader);
struct keybox *keybox = make_keybox(shader, cache_id, key, key_size);
_mesa_hash_table_insert(ice->shaders.cache, keybox, shader);
iris_bo_offset_from_base_address(bo) + shader->assembly.offset;
*((void **) prog_data_out) = shader->prog_data;
- iris_use_pinned_bo(batch, bo, false);
+ iris_use_pinned_bo(batch, bo, false, IRIS_DOMAIN_NONE);
return true;
}
struct iris_compiled_shader *shader =
iris_upload_shader(ice, IRIS_CACHE_BLORP, key_size, key, kernel,
- prog_data, NULL, NULL, 0, 0, &bt);
+ prog_data, NULL, NULL, 0, 0, 0, &bt);
struct iris_bo *bo = iris_resource_bo(shader->assembly.res);
*kernel_out =
iris_bo_offset_from_base_address(bo) + shader->assembly.offset;
*((void **) prog_data_out) = shader->prog_data;
- iris_use_pinned_bo(batch, bo, false);
+ iris_use_pinned_bo(batch, bo, false, IRIS_DOMAIN_NONE);
return true;
}
ice->shaders.uploader =
u_upload_create(&ice->ctx, 16384, PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE,
IRIS_RESOURCE_FLAG_SHADER_MEMZONE);
+
+ for (int i = 0; i < MESA_SHADER_STAGES; i++)
+ list_inithead(&ice->shaders.deleted_variants[i]);
}
void
{
for (int i = 0; i < MESA_SHADER_STAGES; i++) {
ice->shaders.prog[i] = NULL;
+
+ list_for_each_entry_safe(struct iris_compiled_shader, shader,
+ &ice->shaders.deleted_variants[i], link) {
+ pipe_resource_reference(&shader->assembly.res, NULL);
+ }
}
hash_table_foreach(ice->shaders.cache, entry) {
const struct keybox *keybox = entry->key;
struct iris_compiled_shader *shader = entry->data;
fprintf(stderr, "%s:\n", cache_name(keybox->cache_id));
- brw_disassemble(devinfo, shader->map, 0,
- shader->prog_data->program_size, stderr);
+ gen_disassemble(devinfo, shader->map, 0, stderr);
}
}