summaryrefslogtreecommitdiff
path: root/lib/mesa/src/intel
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2019-01-29 10:56:39 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2019-01-29 10:56:39 +0000
commit4c6c2f3abf99b7d35025c01ed53eaf0de2036f50 (patch)
tree94a40dfa93ed7a6f0b034b61413ee36302a57730 /lib/mesa/src/intel
parent6a8047b1fe1d951d83d4be78ca1971e2f5793254 (diff)
Import Mesa 18.3.2
Diffstat (limited to 'lib/mesa/src/intel')
-rw-r--r--lib/mesa/src/intel/vulkan/anv_nir_add_base_work_group_id.c84
1 files changed, 57 insertions, 27 deletions
diff --git a/lib/mesa/src/intel/vulkan/anv_nir_add_base_work_group_id.c b/lib/mesa/src/intel/vulkan/anv_nir_add_base_work_group_id.c
index 1283cb73e..a7c290bb5 100644
--- a/lib/mesa/src/intel/vulkan/anv_nir_add_base_work_group_id.c
+++ b/lib/mesa/src/intel/vulkan/anv_nir_add_base_work_group_id.c
@@ -25,39 +25,69 @@
#include "nir/nir_builder.h"
#include "compiler/brw_compiler.h"
-static bool
-anv_nir_add_base_work_group_id_instr(nir_builder *b,
- nir_instr *instr,
- UNUSED void *cb_data)
+bool
+anv_nir_add_base_work_group_id(nir_shader *shader,
+ struct brw_cs_prog_data *prog_data)
{
- if (instr->type != nir_instr_type_intrinsic)
- return false;
+ assert(shader->info.stage == MESA_SHADER_COMPUTE);
- nir_intrinsic_instr *load_id = nir_instr_as_intrinsic(instr);
- if (load_id->intrinsic != nir_intrinsic_load_workgroup_id)
- return false;
+ nir_builder b;
+ int base_id_offset = -1;
+ bool progress = false;
+ nir_foreach_function(function, shader) {
+ if (!function->impl)
+ continue;
- b->cursor = nir_after_instr(&load_id->instr);
+ nir_builder_init(&b, function->impl);
- nir_ssa_def *load_base =
- nir_load_push_constant(b, 3, 32, nir_imm_int(b, 0),
- .base = offsetof(struct anv_push_constants, cs.base_work_group_id),
- .range = 3 * sizeof(uint32_t));
+ nir_foreach_block(block, function->impl) {
+ nir_foreach_instr_safe(instr, block) {
+ if (instr->type != nir_instr_type_intrinsic)
+ continue;
- nir_ssa_def *id = nir_iadd(b, &load_id->dest.ssa, load_base);
+ nir_intrinsic_instr *load_id = nir_instr_as_intrinsic(instr);
+ if (load_id->intrinsic != nir_intrinsic_load_work_group_id)
+ continue;
- nir_ssa_def_rewrite_uses_after(&load_id->dest.ssa, id, id->parent_instr);
- return true;
-}
+ b.cursor = nir_after_instr(&load_id->instr);
-bool
-anv_nir_add_base_work_group_id(nir_shader *shader)
-{
- assert(shader->info.stage == MESA_SHADER_COMPUTE);
+ if (base_id_offset < 0) {
+ /* If we don't have a set of BASE_WORK_GROUP_ID params,
+ * add them.
+ */
+ assert(shader->num_uniforms == prog_data->base.nr_params * 4);
+ uint32_t *param =
+ brw_stage_prog_data_add_params(&prog_data->base, 3);
+ param[0] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X;
+ param[1] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y;
+ param[2] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z;
+
+ base_id_offset = shader->num_uniforms;
+ shader->num_uniforms += 12;
+ }
+
+ nir_intrinsic_instr *load_base =
+ nir_intrinsic_instr_create(shader, nir_intrinsic_load_uniform);
+ load_base->num_components = 3;
+ load_base->src[0] = nir_src_for_ssa(nir_imm_int(&b, 0));
+ nir_ssa_dest_init(&load_base->instr, &load_base->dest, 3, 32, NULL);
+ nir_intrinsic_set_base(load_base, base_id_offset);
+ nir_intrinsic_set_range(load_base, 3 * sizeof(uint32_t));
+ nir_builder_instr_insert(&b, &load_base->instr);
+
+ nir_ssa_def *id = nir_iadd(&b, &load_id->dest.ssa,
+ &load_base->dest.ssa);
+
+ nir_ssa_def_rewrite_uses_after(&load_id->dest.ssa,
+ nir_src_for_ssa(id),
+ id->parent_instr);
+ progress = true;
+ }
+ }
+
+ nir_metadata_preserve(function->impl, nir_metadata_block_index |
+ nir_metadata_dominance);
+ }
- return nir_shader_instructions_pass(shader,
- anv_nir_add_base_work_group_id_instr,
- nir_metadata_block_index |
- nir_metadata_dominance,
- NULL);
+ return progress;
}