Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / mesa / drivers / dri / i965 / brw_vec4_gs_nir.cpp
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 "brw_nir.h"
25 #include "brw_vec4_gs_visitor.h"
26
27 namespace brw {
28
29 void
30 vec4_gs_visitor::nir_setup_inputs(nir_shader *shader)
31 {
32 nir_inputs = ralloc_array(mem_ctx, src_reg, shader->num_inputs);
33
34 foreach_list_typed(nir_variable, var, node, &shader->inputs) {
35 int offset = var->data.driver_location;
36 if (var->type->base_type == GLSL_TYPE_ARRAY) {
37 /* Geometry shader inputs are arrays, but they use an unusual array
38 * layout: instead of all array elements for a given geometry shader
39 * input being stored consecutively, all geometry shader inputs are
40 * interleaved into one giant array. At this stage of compilation, we
41 * assume that the stride of the array is BRW_VARYING_SLOT_COUNT.
42 * Later, setup_attributes() will remap our accesses to the actual
43 * input array.
44 */
45 assert(var->type->length > 0);
46 int length = var->type->length;
47 int size = type_size_vec4(var->type) / length;
48 for (int i = 0; i < length; i++) {
49 int location = var->data.location + i * BRW_VARYING_SLOT_COUNT;
50 for (int j = 0; j < size; j++) {
51 src_reg src = src_reg(ATTR, location + j, var->type);
52 src = retype(src, brw_type_for_base_type(var->type));
53 nir_inputs[offset] = src;
54 offset++;
55 }
56 }
57 } else {
58 int size = type_size_vec4(var->type);
59 for (int i = 0; i < size; i++) {
60 src_reg src = src_reg(ATTR, var->data.location + i, var->type);
61 src = retype(src, brw_type_for_base_type(var->type));
62 nir_inputs[offset] = src;
63 offset++;
64 }
65 }
66 }
67 }
68
69 void
70 vec4_gs_visitor::nir_setup_system_value_intrinsic(nir_intrinsic_instr *instr)
71 {
72 dst_reg *reg;
73
74 switch (instr->intrinsic) {
75 case nir_intrinsic_load_invocation_id:
76 reg = &this->nir_system_values[SYSTEM_VALUE_INVOCATION_ID];
77 if (reg->file == BAD_FILE)
78 *reg = *this->make_reg_for_system_value(SYSTEM_VALUE_INVOCATION_ID,
79 glsl_type::int_type);
80 break;
81
82 default:
83 vec4_visitor::nir_setup_system_value_intrinsic(instr);
84 }
85
86 }
87
88 void
89 vec4_gs_visitor::nir_emit_intrinsic(nir_intrinsic_instr *instr)
90 {
91 dst_reg dest;
92 src_reg src;
93
94 switch (instr->intrinsic) {
95 case nir_intrinsic_emit_vertex: {
96 int stream_id = instr->const_index[0];
97 gs_emit_vertex(stream_id);
98 break;
99 }
100
101 case nir_intrinsic_end_primitive:
102 gs_end_primitive();
103 break;
104
105 case nir_intrinsic_load_invocation_id: {
106 src_reg invocation_id =
107 src_reg(nir_system_values[SYSTEM_VALUE_INVOCATION_ID]);
108 assert(invocation_id.file != BAD_FILE);
109 dest = get_nir_dest(instr->dest, invocation_id.type);
110 emit(MOV(dest, invocation_id));
111 break;
112 }
113
114 default:
115 vec4_visitor::nir_emit_intrinsic(instr);
116 }
117 }
118 }