2 * Copyright © 2015 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 "brw_vec4_gs_visitor.h"
30 vec4_gs_visitor::nir_setup_inputs(nir_shader
*shader
)
32 nir_inputs
= ralloc_array(mem_ctx
, src_reg
, shader
->num_inputs
);
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
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
;
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
;
70 vec4_gs_visitor::nir_setup_system_value_intrinsic(nir_intrinsic_instr
*instr
)
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
,
83 vec4_visitor::nir_setup_system_value_intrinsic(instr
);
89 vec4_gs_visitor::nir_emit_intrinsic(nir_intrinsic_instr
*instr
)
94 switch (instr
->intrinsic
) {
95 case nir_intrinsic_emit_vertex
: {
96 int stream_id
= instr
->const_index
[0];
97 gs_emit_vertex(stream_id
);
101 case nir_intrinsic_end_primitive
:
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
));
115 vec4_visitor::nir_emit_intrinsic(instr
);