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.
31 vec4_vs_visitor::emit_prolog()
37 vec4_vs_visitor::make_reg_for_system_value(int location
,
38 const glsl_type
*type
)
40 /* VertexID is stored by the VF as the last vertex element, but
41 * we don't represent it with a flag in inputs_read, so we call
42 * it VERT_ATTRIB_MAX, which setup_attributes() picks up on.
44 dst_reg
*reg
= new(mem_ctx
) dst_reg(ATTR
, VERT_ATTRIB_MAX
);
47 case SYSTEM_VALUE_BASE_VERTEX
:
48 reg
->writemask
= WRITEMASK_X
;
49 vs_prog_data
->uses_basevertex
= true;
51 case SYSTEM_VALUE_BASE_INSTANCE
:
52 reg
->writemask
= WRITEMASK_Y
;
53 vs_prog_data
->uses_baseinstance
= true;
55 case SYSTEM_VALUE_VERTEX_ID
:
56 case SYSTEM_VALUE_VERTEX_ID_ZERO_BASE
:
57 reg
->writemask
= WRITEMASK_Z
;
58 vs_prog_data
->uses_vertexid
= true;
60 case SYSTEM_VALUE_INSTANCE_ID
:
61 reg
->writemask
= WRITEMASK_W
;
62 vs_prog_data
->uses_instanceid
= true;
64 case SYSTEM_VALUE_DRAW_ID
:
65 reg
= new(mem_ctx
) dst_reg(ATTR
, VERT_ATTRIB_MAX
+ 1);
66 reg
->writemask
= WRITEMASK_X
;
67 vs_prog_data
->uses_drawid
= true;
70 unreachable("not reached");
78 vec4_vs_visitor::emit_urb_write_header(int mrf
)
80 /* No need to do anything for VS; an implied write to this MRF will be
81 * performed by VS_OPCODE_URB_WRITE.
88 vec4_vs_visitor::emit_urb_write_opcode(bool complete
)
90 /* For VS, the URB writes end the thread. */
92 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
)
93 emit_shader_time_end();
96 vec4_instruction
*inst
= emit(VS_OPCODE_URB_WRITE
);
97 inst
->urb_write_flags
= complete
?
98 BRW_URB_WRITE_EOT_COMPLETE
: BRW_URB_WRITE_NO_FLAGS
;
105 vec4_vs_visitor::emit_urb_slot(dst_reg reg
, int varying
)
107 reg
.type
= BRW_REGISTER_TYPE_F
;
108 output_reg
[varying
].type
= reg
.type
;
111 case VARYING_SLOT_COL0
:
112 case VARYING_SLOT_COL1
:
113 case VARYING_SLOT_BFC0
:
114 case VARYING_SLOT_BFC1
: {
115 /* These built-in varyings are only supported in compatibility mode,
116 * and we only support GS in core profile. So, this must be a vertex
119 vec4_instruction
*inst
= emit_generic_urb_slot(reg
, varying
);
120 if (inst
&& key
->clamp_vertex_color
)
121 inst
->saturate
= true;
125 return vec4_visitor::emit_urb_slot(reg
, varying
);
131 vec4_vs_visitor::emit_clip_distances(dst_reg reg
, int offset
)
133 /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special Variables):
135 * "If a linked set of shaders forming the vertex stage contains no
136 * static write to gl_ClipVertex or gl_ClipDistance, but the
137 * application has requested clipping against user clip planes through
138 * the API, then the coordinate written to gl_Position is used for
139 * comparison against the user clip planes."
141 * This function is only called if the shader didn't write to
142 * gl_ClipDistance. Accordingly, we use gl_ClipVertex to perform clipping
143 * if the user wrote to it; otherwise we use gl_Position.
145 gl_varying_slot clip_vertex
= VARYING_SLOT_CLIP_VERTEX
;
146 if (!(prog_data
->vue_map
.slots_valid
& VARYING_BIT_CLIP_VERTEX
)) {
147 clip_vertex
= VARYING_SLOT_POS
;
150 for (int i
= 0; i
+ offset
< key
->nr_userclip_plane_consts
&& i
< 4;
152 reg
.writemask
= 1 << i
;
154 src_reg(output_reg
[clip_vertex
]),
155 src_reg(this->userplane
[i
+ offset
])));
161 vec4_vs_visitor::setup_uniform_clipplane_values()
163 for (int i
= 0; i
< key
->nr_userclip_plane_consts
; ++i
) {
164 this->userplane
[i
] = dst_reg(UNIFORM
, this->uniforms
);
165 this->userplane
[i
].type
= BRW_REGISTER_TYPE_F
;
166 for (int j
= 0; j
< 4; ++j
) {
167 stage_prog_data
->param
[this->uniforms
* 4 + j
] =
168 (gl_constant_value
*) &clip_planes
[i
][j
];
176 vec4_vs_visitor::emit_thread_end()
178 setup_uniform_clipplane_values();
180 /* Lower legacy ff and ClipVertex clipping to clip distances */
181 if (key
->nr_userclip_plane_consts
> 0) {
182 current_annotation
= "user clip distances";
184 output_reg
[VARYING_SLOT_CLIP_DIST0
] = dst_reg(this, glsl_type::vec4_type
);
185 output_reg
[VARYING_SLOT_CLIP_DIST1
] = dst_reg(this, glsl_type::vec4_type
);
187 emit_clip_distances(output_reg
[VARYING_SLOT_CLIP_DIST0
], 0);
188 emit_clip_distances(output_reg
[VARYING_SLOT_CLIP_DIST1
], 4);
191 /* For VS, we always end the thread by emitting a single vertex.
192 * emit_urb_write_opcode() will take care of setting the eot flag on the
199 vec4_vs_visitor::vec4_vs_visitor(const struct brw_compiler
*compiler
,
201 const struct brw_vs_prog_key
*key
,
202 struct brw_vs_prog_data
*vs_prog_data
,
203 const nir_shader
*shader
,
204 gl_clip_plane
*clip_planes
,
206 int shader_time_index
,
207 bool use_legacy_snorm_formula
)
208 : vec4_visitor(compiler
, log_data
, &key
->tex
, &vs_prog_data
->base
, shader
,
209 mem_ctx
, false /* no_spills */, shader_time_index
),
211 vs_prog_data(vs_prog_data
),
212 clip_planes(clip_planes
),
213 use_legacy_snorm_formula(use_legacy_snorm_formula
)
218 } /* namespace brw */