xref: /aosp_15_r20/external/mesa3d/src/intel/compiler/elk/elk_vec4_gs_nir.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2015 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 "elk_vec4_gs_visitor.h"
25 
26 namespace elk {
27 
28 void
nir_emit_intrinsic(nir_intrinsic_instr * instr)29 vec4_gs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)
30 {
31    dst_reg dest;
32    src_reg src;
33 
34    switch (instr->intrinsic) {
35    case nir_intrinsic_load_per_vertex_input: {
36       assert(instr->def.bit_size == 32);
37       /* The EmitNoIndirectInput flag guarantees our vertex index will
38        * be constant.  We should handle indirects someday.
39        */
40       const unsigned vertex = nir_src_as_uint(instr->src[0]);
41       const unsigned offset_reg = nir_src_as_uint(instr->src[1]);
42 
43       const unsigned input_array_stride = prog_data->urb_read_length * 2;
44 
45       /* Make up a type...we have no way of knowing... */
46       const glsl_type *const type = glsl_ivec_type(instr->num_components);
47 
48       src = src_reg(ATTR, input_array_stride * vertex +
49                     nir_intrinsic_base(instr) + offset_reg,
50                     type);
51       src.swizzle = ELK_SWZ_COMP_INPUT(nir_intrinsic_component(instr));
52 
53       dest = get_nir_def(instr->def, src.type);
54       dest.writemask = elk_writemask_for_size(instr->num_components);
55       emit(MOV(dest, src));
56       break;
57    }
58 
59    case nir_intrinsic_load_input:
60       unreachable("nir_lower_io should have produced per_vertex intrinsics");
61 
62    case nir_intrinsic_emit_vertex_with_counter:
63       this->vertex_count =
64          retype(get_nir_src(instr->src[0], 1), ELK_REGISTER_TYPE_UD);
65       gs_emit_vertex(nir_intrinsic_stream_id(instr));
66       break;
67 
68    case nir_intrinsic_end_primitive_with_counter:
69       this->vertex_count =
70          retype(get_nir_src(instr->src[0], 1), ELK_REGISTER_TYPE_UD);
71       gs_end_primitive();
72       break;
73 
74    case nir_intrinsic_set_vertex_and_primitive_count:
75       this->vertex_count =
76          retype(get_nir_src(instr->src[0], 1), ELK_REGISTER_TYPE_UD);
77       break;
78 
79    case nir_intrinsic_load_primitive_id:
80       assert(gs_prog_data->include_primitive_id);
81       dest = get_nir_def(instr->def, ELK_REGISTER_TYPE_D);
82       emit(MOV(dest, retype(elk_vec4_grf(1, 0), ELK_REGISTER_TYPE_D)));
83       break;
84 
85    case nir_intrinsic_load_invocation_id: {
86       dest = get_nir_def(instr->def, ELK_REGISTER_TYPE_D);
87       if (gs_prog_data->invocations > 1)
88          emit(ELK_GS_OPCODE_GET_INSTANCE_ID, dest);
89       else
90          emit(MOV(dest, elk_imm_ud(0)));
91       break;
92    }
93 
94    default:
95       vec4_visitor::nir_emit_intrinsic(instr);
96    }
97 }
98 }
99