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 #include "brw_vec4_vs.h"
26 #include "common/gen_debug.h"
31 vec4_vs_visitor::emit_prolog()
37 vec4_vs_visitor::emit_urb_write_header(int mrf
)
39 /* No need to do anything for VS; an implied write to this MRF will be
40 * performed by VS_OPCODE_URB_WRITE.
47 vec4_vs_visitor::emit_urb_write_opcode(bool complete
)
49 /* For VS, the URB writes end the thread. */
51 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
52 emit_shader_time_end();
55 vec4_instruction
*inst
= emit(VS_OPCODE_URB_WRITE
);
56 inst
->urb_write_flags
= complete
?
57 BRW_URB_WRITE_EOT_COMPLETE
: BRW_URB_WRITE_NO_FLAGS
;
64 vec4_vs_visitor::emit_urb_slot(dst_reg reg
, int varying
)
66 reg
.type
= BRW_REGISTER_TYPE_F
;
67 output_reg
[varying
][0].type
= reg
.type
;
70 case VARYING_SLOT_COL0
:
71 case VARYING_SLOT_COL1
:
72 case VARYING_SLOT_BFC0
:
73 case VARYING_SLOT_BFC1
: {
74 /* These built-in varyings are only supported in compatibility mode,
75 * and we only support GS in core profile. So, this must be a vertex
78 vec4_instruction
*inst
= emit_generic_urb_slot(reg
, varying
, 0);
79 if (inst
&& key
->clamp_vertex_color
)
80 inst
->saturate
= true;
84 return vec4_visitor::emit_urb_slot(reg
, varying
);
90 vec4_vs_visitor::emit_clip_distances(dst_reg reg
, int offset
)
92 /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special Variables):
94 * "If a linked set of shaders forming the vertex stage contains no
95 * static write to gl_ClipVertex or gl_ClipDistance, but the
96 * application has requested clipping against user clip planes through
97 * the API, then the coordinate written to gl_Position is used for
98 * comparison against the user clip planes."
100 * This function is only called if the shader didn't write to
101 * gl_ClipDistance. Accordingly, we use gl_ClipVertex to perform clipping
102 * if the user wrote to it; otherwise we use gl_Position.
104 gl_varying_slot clip_vertex
= VARYING_SLOT_CLIP_VERTEX
;
105 if (!(prog_data
->vue_map
.slots_valid
& VARYING_BIT_CLIP_VERTEX
)) {
106 clip_vertex
= VARYING_SLOT_POS
;
109 for (int i
= 0; i
+ offset
< key
->nr_userclip_plane_consts
&& i
< 4;
111 reg
.writemask
= 1 << i
;
113 src_reg(output_reg
[clip_vertex
][0]),
114 src_reg(this->userplane
[i
+ offset
])));
120 vec4_vs_visitor::setup_uniform_clipplane_values()
122 if (key
->nr_userclip_plane_consts
== 0)
125 assert(stage_prog_data
->nr_params
== (unsigned)this->uniforms
* 4);
126 brw_stage_prog_data_add_params(stage_prog_data
,
127 key
->nr_userclip_plane_consts
* 4);
129 for (int i
= 0; i
< key
->nr_userclip_plane_consts
; ++i
) {
130 this->userplane
[i
] = dst_reg(UNIFORM
, this->uniforms
);
131 this->userplane
[i
].type
= BRW_REGISTER_TYPE_F
;
132 for (int j
= 0; j
< 4; ++j
) {
133 stage_prog_data
->param
[this->uniforms
* 4 + j
] =
134 BRW_PARAM_BUILTIN_CLIP_PLANE(i
, j
);
142 vec4_vs_visitor::emit_thread_end()
144 setup_uniform_clipplane_values();
146 /* Lower legacy ff and ClipVertex clipping to clip distances */
147 if (key
->nr_userclip_plane_consts
> 0) {
148 current_annotation
= "user clip distances";
150 output_reg
[VARYING_SLOT_CLIP_DIST0
][0] =
151 dst_reg(this, glsl_type::vec4_type
);
152 output_reg
[VARYING_SLOT_CLIP_DIST1
][0] =
153 dst_reg(this, glsl_type::vec4_type
);
154 output_num_components
[VARYING_SLOT_CLIP_DIST0
][0] = 4;
155 output_num_components
[VARYING_SLOT_CLIP_DIST1
][0] = 4;
157 emit_clip_distances(output_reg
[VARYING_SLOT_CLIP_DIST0
][0], 0);
158 emit_clip_distances(output_reg
[VARYING_SLOT_CLIP_DIST1
][0], 4);
161 /* For VS, we always end the thread by emitting a single vertex.
162 * emit_urb_write_opcode() will take care of setting the eot flag on the
169 vec4_vs_visitor::vec4_vs_visitor(const struct brw_compiler
*compiler
,
171 const struct brw_vs_prog_key
*key
,
172 struct brw_vs_prog_data
*vs_prog_data
,
173 const nir_shader
*shader
,
175 int shader_time_index
)
176 : vec4_visitor(compiler
, log_data
, &key
->tex
, &vs_prog_data
->base
, shader
,
177 mem_ctx
, false /* no_spills */, shader_time_index
),
179 vs_prog_data(vs_prog_data
)
184 } /* namespace brw */