2 * Copyright © 2013 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
21 * DEALINGS IN THE SOFTWARE.
25 * \file brw_vec4_tes.cpp
27 * Tessellaton evaluation shader specific code derived from the vec4_visitor class.
30 #include "brw_vec4_tes.h"
34 vec4_tes_visitor::vec4_tes_visitor(const struct brw_compiler
*compiler
,
36 const struct brw_tes_prog_key
*key
,
37 struct brw_tes_prog_data
*prog_data
,
38 const nir_shader
*shader
,
40 int shader_time_index
)
41 : vec4_visitor(compiler
, log_data
, &key
->tex
, &prog_data
->base
,
42 shader
, mem_ctx
, false, shader_time_index
)
48 vec4_tes_visitor::make_reg_for_system_value(int location
, const glsl_type
*type
)
54 vec4_tes_visitor::nir_setup_system_value_intrinsic(nir_intrinsic_instr
*instr
)
56 const struct brw_tes_prog_data
*tes_prog_data
=
57 (const struct brw_tes_prog_data
*) prog_data
;
59 switch (instr
->intrinsic
) {
60 case nir_intrinsic_load_tess_level_outer
: {
61 dst_reg
dst(this, glsl_type::vec4_type
);
62 nir_system_values
[SYSTEM_VALUE_TESS_LEVEL_OUTER
] = dst
;
64 dst_reg
temp(this, glsl_type::vec4_type
);
65 vec4_instruction
*read
=
66 emit(VEC4_OPCODE_URB_READ
, temp
, input_read_header
);
68 read
->urb_write_flags
= BRW_URB_WRITE_PER_SLOT_OFFSET
;
69 emit(MOV(dst
, swizzle(src_reg(temp
), BRW_SWIZZLE_WZYX
)));
72 case nir_intrinsic_load_tess_level_inner
: {
73 dst_reg
dst(this, glsl_type::vec2_type
);
74 nir_system_values
[SYSTEM_VALUE_TESS_LEVEL_INNER
] = dst
;
76 /* Set up the message header to reference the proper parts of the URB */
77 dst_reg
temp(this, glsl_type::vec4_type
);
78 vec4_instruction
*read
=
79 emit(VEC4_OPCODE_URB_READ
, temp
, input_read_header
);
80 read
->urb_write_flags
= BRW_URB_WRITE_PER_SLOT_OFFSET
;
81 if (tes_prog_data
->domain
== BRW_TESS_DOMAIN_QUAD
) {
82 emit(MOV(dst
, swizzle(src_reg(temp
), BRW_SWIZZLE_WZYX
)));
85 emit(MOV(dst
, src_reg(temp
)));
90 vec4_visitor::nir_setup_system_value_intrinsic(instr
);
96 vec4_tes_visitor::setup_payload()
100 /* The payload always contains important data in r0 and r1, which contains
101 * the URB handles that are passed on to the URB write at the end
106 reg
= setup_uniforms(reg
);
108 this->first_non_payload_grf
= reg
;
113 vec4_tes_visitor::emit_prolog()
115 input_read_header
= src_reg(this, glsl_type::uvec4_type
);
116 emit(TES_OPCODE_CREATE_INPUT_READ_HEADER
, dst_reg(input_read_header
));
118 this->current_annotation
= NULL
;
123 vec4_tes_visitor::emit_urb_write_header(int mrf
)
125 /* No need to do anything for DS; an implied write to this MRF will be
126 * performed by VS_OPCODE_URB_WRITE.
133 vec4_tes_visitor::emit_urb_write_opcode(bool complete
)
135 /* For DS, the URB writes end the thread. */
137 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
138 emit_shader_time_end();
141 vec4_instruction
*inst
= emit(VS_OPCODE_URB_WRITE
);
142 inst
->urb_write_flags
= complete
?
143 BRW_URB_WRITE_EOT_COMPLETE
: BRW_URB_WRITE_NO_FLAGS
;
149 vec4_tes_visitor::nir_emit_intrinsic(nir_intrinsic_instr
*instr
)
151 switch (instr
->intrinsic
) {
152 case nir_intrinsic_load_tess_coord
:
153 /* gl_TessCoord is part of the payload in g1 channels 0-2 and 4-6. */
154 emit(MOV(get_nir_dest(instr
->dest
, BRW_REGISTER_TYPE_F
),
155 src_reg(brw_vec8_grf(1, 0))));
157 case nir_intrinsic_load_primitive_id
:
158 emit(TES_OPCODE_GET_PRIMITIVE_ID
,
159 get_nir_dest(instr
->dest
, BRW_REGISTER_TYPE_UD
));
162 case nir_intrinsic_load_input
:
163 case nir_intrinsic_load_per_vertex_input
: {
164 src_reg indirect_offset
= get_indirect_offset(instr
);
165 unsigned imm_offset
= instr
->const_index
[0];
166 src_reg header
= input_read_header
;
168 if (indirect_offset
.file
!= BAD_FILE
) {
169 header
= src_reg(this, glsl_type::uvec4_type
);
170 emit(TES_OPCODE_ADD_INDIRECT_URB_OFFSET
, dst_reg(header
),
171 input_read_header
, indirect_offset
);
174 dst_reg
temp(this, glsl_type::ivec4_type
);
175 vec4_instruction
*read
=
176 emit(VEC4_OPCODE_URB_READ
, temp
, src_reg(header
));
177 read
->offset
= imm_offset
;
178 read
->urb_write_flags
= BRW_URB_WRITE_PER_SLOT_OFFSET
;
180 /* Copy to target. We might end up with some funky writemasks landing
181 * in here, but we really don't want them in the above pseudo-ops.
183 dst_reg dst
= get_nir_dest(instr
->dest
, BRW_REGISTER_TYPE_D
);
184 dst
.writemask
= brw_writemask_for_size(instr
->num_components
);
185 emit(MOV(dst
, src_reg(temp
)));
189 vec4_visitor::nir_emit_intrinsic(instr
);
195 vec4_tes_visitor::emit_thread_end()
197 /* For DS, we always end the thread by emitting a single vertex.
198 * emit_urb_write_opcode() will take care of setting the eot flag on the
204 } /* namespace brw */