i965/nir/gs: Handle geometry shaders inputs
[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(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(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 }