2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 #include "nir/nir_builder.h"
26 #include "compiler/brw_compiler.h"
29 anv_nir_add_base_work_group_id(nir_shader
*shader
,
30 struct brw_cs_prog_data
*prog_data
)
32 assert(shader
->info
.stage
== MESA_SHADER_COMPUTE
);
35 int base_id_offset
= -1;
36 bool progress
= false;
37 nir_foreach_function(function
, shader
) {
41 nir_builder_init(&b
, function
->impl
);
43 nir_foreach_block(block
, function
->impl
) {
44 nir_foreach_instr_safe(instr
, block
) {
45 if (instr
->type
!= nir_instr_type_intrinsic
)
48 nir_intrinsic_instr
*load_id
= nir_instr_as_intrinsic(instr
);
49 if (load_id
->intrinsic
!= nir_intrinsic_load_work_group_id
)
52 b
.cursor
= nir_after_instr(&load_id
->instr
);
54 if (base_id_offset
< 0) {
55 /* If we don't have a set of BASE_WORK_GROUP_ID params,
58 assert(shader
->num_uniforms
== prog_data
->base
.nr_params
* 4);
60 brw_stage_prog_data_add_params(&prog_data
->base
, 3);
61 param
[0] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X
;
62 param
[1] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y
;
63 param
[2] = BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z
;
65 base_id_offset
= shader
->num_uniforms
;
66 shader
->num_uniforms
+= 12;
69 nir_intrinsic_instr
*load_base
=
70 nir_intrinsic_instr_create(shader
, nir_intrinsic_load_uniform
);
71 load_base
->num_components
= 3;
72 load_base
->src
[0] = nir_src_for_ssa(nir_imm_int(&b
, 0));
73 nir_ssa_dest_init(&load_base
->instr
, &load_base
->dest
, 3, 32, NULL
);
74 nir_intrinsic_set_base(load_base
, base_id_offset
);
75 nir_intrinsic_set_range(load_base
, 3 * sizeof(uint32_t));
76 nir_builder_instr_insert(&b
, &load_base
->instr
);
78 nir_ssa_def
*id
= nir_iadd(&b
, &load_id
->dest
.ssa
,
79 &load_base
->dest
.ssa
);
81 nir_ssa_def_rewrite_uses_after(&load_id
->dest
.ssa
,
88 nir_metadata_preserve(function
->impl
, nir_metadata_block_index
|
89 nir_metadata_dominance
);