• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2017 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 #include "anv_nir.h"
25 #include "nir/nir_builder.h"
26 #include "compiler/brw_compiler.h"
27 
28 static bool
anv_nir_add_base_work_group_id_instr(nir_builder * b,nir_instr * instr,UNUSED void * cb_data)29 anv_nir_add_base_work_group_id_instr(nir_builder *b,
30                                      nir_instr *instr,
31                                      UNUSED void *cb_data)
32 {
33    if (instr->type != nir_instr_type_intrinsic)
34       return false;
35 
36    nir_intrinsic_instr *load_id = nir_instr_as_intrinsic(instr);
37    if (load_id->intrinsic != nir_intrinsic_load_workgroup_id)
38       return false;
39 
40    b->cursor = nir_after_instr(&load_id->instr);
41 
42    nir_ssa_def *load_base =
43       nir_load_push_constant(b, 3, 32, nir_imm_int(b, 0),
44                              .base = offsetof(struct anv_push_constants, cs.base_work_group_id),
45                              .range = 3 * sizeof(uint32_t));
46 
47    nir_ssa_def *id = nir_iadd(b, &load_id->dest.ssa, load_base);
48 
49    nir_ssa_def_rewrite_uses_after(&load_id->dest.ssa, id, id->parent_instr);
50    return true;
51 }
52 
53 bool
anv_nir_add_base_work_group_id(nir_shader * shader)54 anv_nir_add_base_work_group_id(nir_shader *shader)
55 {
56    assert(shader->info.stage == MESA_SHADER_COMPUTE);
57 
58    return nir_shader_instructions_pass(shader,
59                                        anv_nir_add_base_work_group_id_instr,
60                                        nir_metadata_block_index |
61                                        nir_metadata_dominance,
62                                        NULL);
63 }
64