1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_private.h"
34 #include "lp_context.h"
35 #include "lp_screen.h"
42 * The vertex info describes how to convert the post-transformed vertices
43 * (simple float[][4]) used by the 'draw' module into vertices for
46 * This function validates the vertex layout.
49 compute_vertex_info(struct llvmpipe_context
*llvmpipe
)
51 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
52 struct vertex_info
*vinfo
= &llvmpipe
->vertex_info
;
56 draw_prepare_shader_outputs(llvmpipe
->draw
);
58 llvmpipe
->color_slot
[0] = 0;
59 llvmpipe
->color_slot
[1] = 0;
60 llvmpipe
->bcolor_slot
[0] = 0;
61 llvmpipe
->bcolor_slot
[1] = 0;
62 llvmpipe
->viewport_index_slot
= 0;
63 llvmpipe
->layer_slot
= 0;
64 llvmpipe
->face_slot
= 0;
65 llvmpipe
->psize_slot
= 0;
68 * Match FS inputs against VS outputs, emitting the necessary
69 * attributes. Could cache these structs and look them up with a
70 * combination of fragment shader, vertex shader ids.
73 vinfo
->num_attribs
= 0;
75 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
76 TGSI_SEMANTIC_POSITION
,
79 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, vs_index
);
81 for (i
= 0; i
< lpfs
->info
.base
.num_inputs
; i
++) {
83 * Search for each input in current vs output:
86 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
87 lpfs
->info
.base
.input_semantic_name
[i
],
88 lpfs
->info
.base
.input_semantic_index
[i
]);
90 if (lpfs
->info
.base
.input_semantic_name
[i
] == TGSI_SEMANTIC_COLOR
&&
91 lpfs
->info
.base
.input_semantic_index
[i
] < 2) {
92 int idx
= lpfs
->info
.base
.input_semantic_index
[i
];
93 llvmpipe
->color_slot
[idx
] = vinfo
->num_attribs
;
96 if (lpfs
->info
.base
.input_semantic_name
[i
] == TGSI_SEMANTIC_FACE
) {
97 llvmpipe
->face_slot
= vinfo
->num_attribs
;
98 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
99 } else if (lpfs
->info
.base
.input_semantic_name
[i
] == TGSI_SEMANTIC_PRIMID
) {
100 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
102 * For vp index and layer, if the fs requires them but the vs doesn't
103 * provide them, store the slot - we'll later replace the data directly
104 * with zero (as required by ARB_fragment_layer_viewport). This is
105 * because draw itself just redirects them to whatever was at output 0.
106 * We'll also store the real vpindex/layer slot for setup use.
108 } else if (lpfs
->info
.base
.input_semantic_name
[i
] ==
109 TGSI_SEMANTIC_VIEWPORT_INDEX
) {
111 llvmpipe
->viewport_index_slot
= vinfo
->num_attribs
;
114 llvmpipe
->fake_vpindex_slot
= vinfo
->num_attribs
;
116 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
117 } else if (lpfs
->info
.base
.input_semantic_name
[i
] == TGSI_SEMANTIC_LAYER
) {
119 llvmpipe
->layer_slot
= vinfo
->num_attribs
;
122 llvmpipe
->fake_layer_slot
= vinfo
->num_attribs
;
124 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
127 * Emit the requested fs attribute for all but position.
129 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, vs_index
);
133 /* Figure out if we need bcolor as well.
135 for (i
= 0; i
< 2; i
++) {
136 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
137 TGSI_SEMANTIC_BCOLOR
, i
);
140 llvmpipe
->bcolor_slot
[i
] = vinfo
->num_attribs
;
141 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, vs_index
);
145 /* Figure out if we need pointsize as well.
147 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
148 TGSI_SEMANTIC_PSIZE
, 0);
151 llvmpipe
->psize_slot
= vinfo
->num_attribs
;
152 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
155 /* Figure out if we need viewport index (if it wasn't already in fs input) */
156 if (llvmpipe
->viewport_index_slot
== 0) {
157 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
158 TGSI_SEMANTIC_VIEWPORT_INDEX
,
161 llvmpipe
->viewport_index_slot
= vinfo
->num_attribs
;
162 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
166 /* Figure out if we need layer (if it wasn't already in fs input) */
167 if (llvmpipe
->layer_slot
== 0) {
168 vs_index
= draw_find_shader_output(llvmpipe
->draw
,
172 llvmpipe
->layer_slot
= vinfo
->num_attribs
;
173 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
, vs_index
);
177 draw_compute_vertex_size(vinfo
);
178 lp_setup_set_vertex_info(llvmpipe
->setup
, vinfo
);
183 * Handle state changes.
184 * Called just prior to drawing anything (pipe::draw_arrays(), etc).
186 * Hopefully this will remain quite simple, otherwise need to pull in
187 * something like the state tracker mechanism.
189 void llvmpipe_update_derived( struct llvmpipe_context
*llvmpipe
)
191 struct llvmpipe_screen
*lp_screen
= llvmpipe_screen(llvmpipe
->pipe
.screen
);
193 /* Check for updated textures.
195 if (llvmpipe
->tex_timestamp
!= lp_screen
->timestamp
) {
196 llvmpipe
->tex_timestamp
= lp_screen
->timestamp
;
197 llvmpipe
->dirty
|= LP_NEW_SAMPLER_VIEW
;
200 if (llvmpipe
->dirty
& (LP_NEW_RASTERIZER
|
203 compute_vertex_info( llvmpipe
);
205 if (llvmpipe
->dirty
& (LP_NEW_FS
|
209 LP_NEW_DEPTH_STENCIL_ALPHA
|
212 LP_NEW_SAMPLER_VIEW
|
213 LP_NEW_OCCLUSION_QUERY
))
214 llvmpipe_update_fs( llvmpipe
);
216 if (llvmpipe
->dirty
& (LP_NEW_RASTERIZER
)) {
218 (llvmpipe
->sample_mask
& 1) == 0 ||
219 (llvmpipe
->rasterizer
? llvmpipe
->rasterizer
->rasterizer_discard
: FALSE
);
221 lp_setup_set_rasterizer_discard(llvmpipe
->setup
, discard
);
224 if (llvmpipe
->dirty
& (LP_NEW_FS
|
227 llvmpipe_update_setup( llvmpipe
);
229 if (llvmpipe
->dirty
& LP_NEW_BLEND_COLOR
)
230 lp_setup_set_blend_color(llvmpipe
->setup
,
231 &llvmpipe
->blend_color
);
233 if (llvmpipe
->dirty
& LP_NEW_SCISSOR
)
234 lp_setup_set_scissors(llvmpipe
->setup
, llvmpipe
->scissors
);
236 if (llvmpipe
->dirty
& LP_NEW_DEPTH_STENCIL_ALPHA
) {
237 lp_setup_set_alpha_ref_value(llvmpipe
->setup
,
238 llvmpipe
->depth_stencil
->alpha
.ref_value
);
239 lp_setup_set_stencil_ref_values(llvmpipe
->setup
,
240 llvmpipe
->stencil_ref
.ref_value
);
243 if (llvmpipe
->dirty
& LP_NEW_CONSTANTS
)
244 lp_setup_set_fs_constants(llvmpipe
->setup
,
245 Elements(llvmpipe
->constants
[PIPE_SHADER_FRAGMENT
]),
246 llvmpipe
->constants
[PIPE_SHADER_FRAGMENT
]);
248 if (llvmpipe
->dirty
& (LP_NEW_SAMPLER_VIEW
))
249 lp_setup_set_fragment_sampler_views(llvmpipe
->setup
,
250 llvmpipe
->num_sampler_views
[PIPE_SHADER_FRAGMENT
],
251 llvmpipe
->sampler_views
[PIPE_SHADER_FRAGMENT
]);
253 if (llvmpipe
->dirty
& (LP_NEW_SAMPLER
))
254 lp_setup_set_fragment_sampler_state(llvmpipe
->setup
,
255 llvmpipe
->num_samplers
[PIPE_SHADER_FRAGMENT
],
256 llvmpipe
->samplers
[PIPE_SHADER_FRAGMENT
]);
258 if (llvmpipe
->dirty
& LP_NEW_VIEWPORT
) {
260 * Update setup and fragment's view of the active viewport state.
262 * XXX TODO: It is possible to only loop over the active viewports
263 * instead of all viewports (PIPE_MAX_VIEWPORTS).
265 lp_setup_set_viewports(llvmpipe
->setup
,
267 llvmpipe
->viewports
);