1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2003 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "util/u_math.h"
29bf215546Sopenharmony_ci#include "util/u_memory.h"
30bf215546Sopenharmony_ci#include "pipe/p_shader_tokens.h"
31bf215546Sopenharmony_ci#include "draw/draw_context.h"
32bf215546Sopenharmony_ci#include "draw/draw_vertex.h"
33bf215546Sopenharmony_ci#include "draw/draw_private.h"
34bf215546Sopenharmony_ci#include "lp_context.h"
35bf215546Sopenharmony_ci#include "lp_screen.h"
36bf215546Sopenharmony_ci#include "lp_setup.h"
37bf215546Sopenharmony_ci#include "lp_state.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci/**
42bf215546Sopenharmony_ci * The vertex info describes how to convert the post-transformed vertices
43bf215546Sopenharmony_ci * (simple float[][4]) used by the 'draw' module into vertices for
44bf215546Sopenharmony_ci * rasterization.
45bf215546Sopenharmony_ci *
46bf215546Sopenharmony_ci * This function validates the vertex layout.
47bf215546Sopenharmony_ci */
48bf215546Sopenharmony_cistatic void
49bf215546Sopenharmony_cicompute_vertex_info(struct llvmpipe_context *llvmpipe)
50bf215546Sopenharmony_ci{
51bf215546Sopenharmony_ci   const struct tgsi_shader_info *fsInfo = &llvmpipe->fs->info.base;
52bf215546Sopenharmony_ci   struct vertex_info *vinfo = &llvmpipe->vertex_info;
53bf215546Sopenharmony_ci   int vs_index;
54bf215546Sopenharmony_ci   uint i;
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci   draw_prepare_shader_outputs(llvmpipe->draw);
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   /*
59bf215546Sopenharmony_ci    * Those can't actually be 0 (because pos is always at 0).
60bf215546Sopenharmony_ci    * But use ints anyway to avoid confusion (in vs outputs, they
61bf215546Sopenharmony_ci    * can very well be at pos 0).
62bf215546Sopenharmony_ci    */
63bf215546Sopenharmony_ci   llvmpipe->color_slot[0] = -1;
64bf215546Sopenharmony_ci   llvmpipe->color_slot[1] = -1;
65bf215546Sopenharmony_ci   llvmpipe->bcolor_slot[0] = -1;
66bf215546Sopenharmony_ci   llvmpipe->bcolor_slot[1] = -1;
67bf215546Sopenharmony_ci   llvmpipe->viewport_index_slot = -1;
68bf215546Sopenharmony_ci   llvmpipe->layer_slot = -1;
69bf215546Sopenharmony_ci   llvmpipe->face_slot = -1;
70bf215546Sopenharmony_ci   llvmpipe->psize_slot = -1;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   /*
73bf215546Sopenharmony_ci    * Match FS inputs against VS outputs, emitting the necessary
74bf215546Sopenharmony_ci    * attributes.  Could cache these structs and look them up with a
75bf215546Sopenharmony_ci    * combination of fragment shader, vertex shader ids.
76bf215546Sopenharmony_ci    */
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ci   vinfo->num_attribs = 0;
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci   vs_index = draw_find_shader_output(llvmpipe->draw,
81bf215546Sopenharmony_ci                                      TGSI_SEMANTIC_POSITION, 0);
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci   draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci   for (i = 0; i < fsInfo->num_inputs; i++) {
86bf215546Sopenharmony_ci      /*
87bf215546Sopenharmony_ci       * Search for each input in current vs output:
88bf215546Sopenharmony_ci       */
89bf215546Sopenharmony_ci      vs_index = draw_find_shader_output(llvmpipe->draw,
90bf215546Sopenharmony_ci                                         fsInfo->input_semantic_name[i],
91bf215546Sopenharmony_ci                                         fsInfo->input_semantic_index[i]);
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci      if (fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_COLOR &&
94bf215546Sopenharmony_ci          fsInfo->input_semantic_index[i] < 2) {
95bf215546Sopenharmony_ci         int idx = fsInfo->input_semantic_index[i];
96bf215546Sopenharmony_ci         llvmpipe->color_slot[idx] = (int)vinfo->num_attribs;
97bf215546Sopenharmony_ci      }
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci      if (fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_FACE) {
100bf215546Sopenharmony_ci         llvmpipe->face_slot = (int)vinfo->num_attribs;
101bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
102bf215546Sopenharmony_ci      /*
103bf215546Sopenharmony_ci       * For vp index and layer, if the fs requires them but the vs doesn't
104bf215546Sopenharmony_ci       * provide them, draw (vbuf) will give us the required 0 (slot -1).
105bf215546Sopenharmony_ci       * (This means in this case we'll also use those slots in setup, which
106bf215546Sopenharmony_ci       * isn't necessary but they'll contain the correct (0) value.)
107bf215546Sopenharmony_ci       */
108bf215546Sopenharmony_ci      } else if (fsInfo->input_semantic_name[i] ==
109bf215546Sopenharmony_ci                 TGSI_SEMANTIC_VIEWPORT_INDEX) {
110bf215546Sopenharmony_ci         llvmpipe->viewport_index_slot = (int)vinfo->num_attribs;
111bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
112bf215546Sopenharmony_ci      } else if (fsInfo->input_semantic_name[i] == TGSI_SEMANTIC_LAYER) {
113bf215546Sopenharmony_ci         llvmpipe->layer_slot = (int)vinfo->num_attribs;
114bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
115bf215546Sopenharmony_ci      } else {
116bf215546Sopenharmony_ci         /*
117bf215546Sopenharmony_ci          * Note that we'd actually want to skip position (as we won't use
118bf215546Sopenharmony_ci          * the attribute in the fs) but can't. The reason is that we don't
119bf215546Sopenharmony_ci          * actually have an input/output map for setup (even though it looks
120bf215546Sopenharmony_ci          * like we do...). Could adjust for this though even without a map
121bf215546Sopenharmony_ci          * (in llvmpipe_create_fs_state()).
122bf215546Sopenharmony_ci          */
123bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
124bf215546Sopenharmony_ci      }
125bf215546Sopenharmony_ci   }
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   /* Figure out if we need bcolor as well.
128bf215546Sopenharmony_ci    */
129bf215546Sopenharmony_ci   for (i = 0; i < 2; i++) {
130bf215546Sopenharmony_ci      vs_index = draw_find_shader_output(llvmpipe->draw,
131bf215546Sopenharmony_ci                                         TGSI_SEMANTIC_BCOLOR, i);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci      if (vs_index >= 0) {
134bf215546Sopenharmony_ci         llvmpipe->bcolor_slot[i] = (int)vinfo->num_attribs;
135bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
136bf215546Sopenharmony_ci      }
137bf215546Sopenharmony_ci   }
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   /* Figure out if we need pointsize as well.
140bf215546Sopenharmony_ci    */
141bf215546Sopenharmony_ci   vs_index = draw_find_shader_output(llvmpipe->draw,
142bf215546Sopenharmony_ci                                      TGSI_SEMANTIC_PSIZE, 0);
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_ci   if (vs_index >= 0) {
145bf215546Sopenharmony_ci      llvmpipe->psize_slot = (int)vinfo->num_attribs;
146bf215546Sopenharmony_ci      draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
147bf215546Sopenharmony_ci   }
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci   /* Figure out if we need viewport index (if it wasn't already in fs input) */
150bf215546Sopenharmony_ci   if (llvmpipe->viewport_index_slot < 0) {
151bf215546Sopenharmony_ci      vs_index = draw_find_shader_output(llvmpipe->draw,
152bf215546Sopenharmony_ci                                         TGSI_SEMANTIC_VIEWPORT_INDEX,
153bf215546Sopenharmony_ci                                         0);
154bf215546Sopenharmony_ci      if (vs_index >= 0) {
155bf215546Sopenharmony_ci         llvmpipe->viewport_index_slot =(int)vinfo->num_attribs;
156bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
157bf215546Sopenharmony_ci      }
158bf215546Sopenharmony_ci   }
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci   /* Figure out if we need layer (if it wasn't already in fs input) */
161bf215546Sopenharmony_ci   if (llvmpipe->layer_slot < 0) {
162bf215546Sopenharmony_ci      vs_index = draw_find_shader_output(llvmpipe->draw,
163bf215546Sopenharmony_ci                                         TGSI_SEMANTIC_LAYER,
164bf215546Sopenharmony_ci                                         0);
165bf215546Sopenharmony_ci      if (vs_index >= 0) {
166bf215546Sopenharmony_ci         llvmpipe->layer_slot = (int)vinfo->num_attribs;
167bf215546Sopenharmony_ci         draw_emit_vertex_attr(vinfo, EMIT_4F, vs_index);
168bf215546Sopenharmony_ci      }
169bf215546Sopenharmony_ci   }
170bf215546Sopenharmony_ci
171bf215546Sopenharmony_ci   draw_compute_vertex_size(vinfo);
172bf215546Sopenharmony_ci   lp_setup_set_vertex_info(llvmpipe->setup, vinfo);
173bf215546Sopenharmony_ci}
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_cistatic void
177bf215546Sopenharmony_cicheck_linear_rasterizer(struct llvmpipe_context *lp)
178bf215546Sopenharmony_ci{
179bf215546Sopenharmony_ci   boolean bgr8;
180bf215546Sopenharmony_ci   boolean permit_linear;
181bf215546Sopenharmony_ci   boolean single_vp;
182bf215546Sopenharmony_ci   boolean clipping_changed = FALSE;
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ci   bgr8 = (lp->framebuffer.nr_cbufs == 1 && lp->framebuffer.cbufs[0] &&
185bf215546Sopenharmony_ci           util_res_sample_count(lp->framebuffer.cbufs[0]->texture) == 1 &&
186bf215546Sopenharmony_ci           lp->framebuffer.cbufs[0]->texture->target == PIPE_TEXTURE_2D &&
187bf215546Sopenharmony_ci           (lp->framebuffer.cbufs[0]->format == PIPE_FORMAT_B8G8R8A8_UNORM ||
188bf215546Sopenharmony_ci            lp->framebuffer.cbufs[0]->format == PIPE_FORMAT_B8G8R8X8_UNORM));
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci   /* permit_linear means guardband, hence fake scissor, which we can only
191bf215546Sopenharmony_ci    * handle if there's just one vp. */
192bf215546Sopenharmony_ci   single_vp = lp->viewport_index_slot < 0;
193bf215546Sopenharmony_ci   permit_linear = (!lp->framebuffer.zsbuf &&
194bf215546Sopenharmony_ci                    bgr8 &&
195bf215546Sopenharmony_ci                    single_vp);
196bf215546Sopenharmony_ci
197bf215546Sopenharmony_ci   /* Tell draw that we're happy doing our own x/y clipping.
198bf215546Sopenharmony_ci    */
199bf215546Sopenharmony_ci   if (lp->permit_linear_rasterizer != permit_linear) {
200bf215546Sopenharmony_ci      lp->permit_linear_rasterizer = permit_linear;
201bf215546Sopenharmony_ci      lp_setup_set_linear_mode(lp->setup, permit_linear);
202bf215546Sopenharmony_ci      clipping_changed = TRUE;
203bf215546Sopenharmony_ci   }
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci   if (lp->single_vp != single_vp) {
206bf215546Sopenharmony_ci      lp->single_vp = single_vp;
207bf215546Sopenharmony_ci      clipping_changed = TRUE;
208bf215546Sopenharmony_ci   }
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci   /* Disable xy clipping in linear mode.
211bf215546Sopenharmony_ci    *
212bf215546Sopenharmony_ci    * Use a guard band if we don't have zsbuf.  Could enable
213bf215546Sopenharmony_ci    * guardband always - this just to be conservative.
214bf215546Sopenharmony_ci    *
215bf215546Sopenharmony_ci    * Because we have a layering violation where the draw module emits
216bf215546Sopenharmony_ci    * state changes to the driver while we're already inside a draw
217bf215546Sopenharmony_ci    * call, need to be careful about when we make calls back to the
218bf215546Sopenharmony_ci    * draw module.  Hence the clipping_changed flag which is as much
219bf215546Sopenharmony_ci    * to prevent flush recursion as it is to short-circuit noop state
220bf215546Sopenharmony_ci    * changes.
221bf215546Sopenharmony_ci    */
222bf215546Sopenharmony_ci   if (clipping_changed) {
223bf215546Sopenharmony_ci      draw_set_driver_clipping(lp->draw,
224bf215546Sopenharmony_ci                               FALSE,
225bf215546Sopenharmony_ci                               FALSE,
226bf215546Sopenharmony_ci                               permit_linear,
227bf215546Sopenharmony_ci                               single_vp);
228bf215546Sopenharmony_ci   }
229bf215546Sopenharmony_ci}
230bf215546Sopenharmony_ci
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci/**
233bf215546Sopenharmony_ci * Handle state changes before clears.
234bf215546Sopenharmony_ci * Called just prior to clearing (pipe::clear()).
235bf215546Sopenharmony_ci */
236bf215546Sopenharmony_civoid
237bf215546Sopenharmony_cillvmpipe_update_derived_clear(struct llvmpipe_context *llvmpipe)
238bf215546Sopenharmony_ci{
239bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_FS |
240bf215546Sopenharmony_ci                          LP_NEW_FRAMEBUFFER))
241bf215546Sopenharmony_ci      check_linear_rasterizer(llvmpipe);
242bf215546Sopenharmony_ci}
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ci/**
246bf215546Sopenharmony_ci * Handle state changes.
247bf215546Sopenharmony_ci * Called just prior to drawing anything (pipe::draw_arrays(), etc).
248bf215546Sopenharmony_ci *
249bf215546Sopenharmony_ci * Hopefully this will remain quite simple, otherwise need to pull in
250bf215546Sopenharmony_ci * something like the gallium frontend mechanism.
251bf215546Sopenharmony_ci */
252bf215546Sopenharmony_civoid
253bf215546Sopenharmony_cillvmpipe_update_derived(struct llvmpipe_context *llvmpipe)
254bf215546Sopenharmony_ci{
255bf215546Sopenharmony_ci   struct llvmpipe_screen *lp_screen = llvmpipe_screen(llvmpipe->pipe.screen);
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ci   /* Check for updated textures.
258bf215546Sopenharmony_ci    */
259bf215546Sopenharmony_ci   if (llvmpipe->tex_timestamp != lp_screen->timestamp) {
260bf215546Sopenharmony_ci      llvmpipe->tex_timestamp = lp_screen->timestamp;
261bf215546Sopenharmony_ci      llvmpipe->dirty |= LP_NEW_SAMPLER_VIEW;
262bf215546Sopenharmony_ci   }
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci   /* This needs LP_NEW_RASTERIZER because of draw_prepare_shader_outputs(). */
265bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_RASTERIZER |
266bf215546Sopenharmony_ci                          LP_NEW_FS |
267bf215546Sopenharmony_ci                          LP_NEW_GS |
268bf215546Sopenharmony_ci                          LP_NEW_TCS |
269bf215546Sopenharmony_ci                          LP_NEW_TES |
270bf215546Sopenharmony_ci                          LP_NEW_VS))
271bf215546Sopenharmony_ci      compute_vertex_info(llvmpipe);
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_FS |
274bf215546Sopenharmony_ci                          LP_NEW_FRAMEBUFFER |
275bf215546Sopenharmony_ci                          LP_NEW_BLEND |
276bf215546Sopenharmony_ci                          LP_NEW_SCISSOR |
277bf215546Sopenharmony_ci                          LP_NEW_DEPTH_STENCIL_ALPHA |
278bf215546Sopenharmony_ci                          LP_NEW_RASTERIZER |
279bf215546Sopenharmony_ci                          LP_NEW_SAMPLER |
280bf215546Sopenharmony_ci                          LP_NEW_SAMPLER_VIEW |
281bf215546Sopenharmony_ci                          LP_NEW_OCCLUSION_QUERY))
282bf215546Sopenharmony_ci      llvmpipe_update_fs(llvmpipe);
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_FS |
285bf215546Sopenharmony_ci                          LP_NEW_FRAMEBUFFER |
286bf215546Sopenharmony_ci                          LP_NEW_RASTERIZER |
287bf215546Sopenharmony_ci                          LP_NEW_SAMPLE_MASK |
288bf215546Sopenharmony_ci                          LP_NEW_DEPTH_STENCIL_ALPHA)) {
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_ci      /*
291bf215546Sopenharmony_ci       * Rasterization is disabled if there is no pixel shader and
292bf215546Sopenharmony_ci       * both depth and stencil testing are disabled:
293bf215546Sopenharmony_ci       * http://msdn.microsoft.com/en-us/library/windows/desktop/bb205125
294bf215546Sopenharmony_ci       * FIXME: set rasterizer_discard in state tracker instead.
295bf215546Sopenharmony_ci       */
296bf215546Sopenharmony_ci      boolean null_fs = !llvmpipe->fs ||
297bf215546Sopenharmony_ci                        llvmpipe->fs->info.base.num_instructions <= 1;
298bf215546Sopenharmony_ci      boolean discard =
299bf215546Sopenharmony_ci         (llvmpipe->sample_mask) == 0 ||
300bf215546Sopenharmony_ci         (llvmpipe->rasterizer ? llvmpipe->rasterizer->rasterizer_discard : FALSE) ||
301bf215546Sopenharmony_ci         (null_fs &&
302bf215546Sopenharmony_ci          !llvmpipe->depth_stencil->depth_enabled &&
303bf215546Sopenharmony_ci          !llvmpipe->depth_stencil->stencil[0].enabled);
304bf215546Sopenharmony_ci      lp_setup_set_rasterizer_discard(llvmpipe->setup, discard);
305bf215546Sopenharmony_ci   }
306bf215546Sopenharmony_ci
307bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_FS |
308bf215546Sopenharmony_ci                          LP_NEW_FRAMEBUFFER |
309bf215546Sopenharmony_ci                          LP_NEW_RASTERIZER))
310bf215546Sopenharmony_ci      llvmpipe_update_setup(llvmpipe);
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_SAMPLE_MASK)
313bf215546Sopenharmony_ci      lp_setup_set_sample_mask(llvmpipe->setup, llvmpipe->sample_mask);
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_BLEND_COLOR)
316bf215546Sopenharmony_ci      lp_setup_set_blend_color(llvmpipe->setup,
317bf215546Sopenharmony_ci                               &llvmpipe->blend_color);
318bf215546Sopenharmony_ci
319bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_SCISSOR)
320bf215546Sopenharmony_ci      lp_setup_set_scissors(llvmpipe->setup, llvmpipe->scissors);
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA) {
323bf215546Sopenharmony_ci      lp_setup_set_alpha_ref_value(llvmpipe->setup,
324bf215546Sopenharmony_ci                                   llvmpipe->depth_stencil->alpha_ref_value);
325bf215546Sopenharmony_ci      lp_setup_set_stencil_ref_values(llvmpipe->setup,
326bf215546Sopenharmony_ci                                      llvmpipe->stencil_ref.ref_value);
327bf215546Sopenharmony_ci   }
328bf215546Sopenharmony_ci
329bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_FS_CONSTANTS)
330bf215546Sopenharmony_ci      lp_setup_set_fs_constants(llvmpipe->setup,
331bf215546Sopenharmony_ci                                ARRAY_SIZE(llvmpipe->constants[PIPE_SHADER_FRAGMENT]),
332bf215546Sopenharmony_ci                                llvmpipe->constants[PIPE_SHADER_FRAGMENT]);
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_FS_SSBOS)
335bf215546Sopenharmony_ci      lp_setup_set_fs_ssbos(llvmpipe->setup,
336bf215546Sopenharmony_ci                            ARRAY_SIZE(llvmpipe->ssbos[PIPE_SHADER_FRAGMENT]),
337bf215546Sopenharmony_ci                            llvmpipe->ssbos[PIPE_SHADER_FRAGMENT], llvmpipe->fs_ssbo_write_mask);
338bf215546Sopenharmony_ci
339bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_FS_IMAGES)
340bf215546Sopenharmony_ci      lp_setup_set_fs_images(llvmpipe->setup,
341bf215546Sopenharmony_ci                             ARRAY_SIZE(llvmpipe->images[PIPE_SHADER_FRAGMENT]),
342bf215546Sopenharmony_ci                             llvmpipe->images[PIPE_SHADER_FRAGMENT]);
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_SAMPLER_VIEW))
345bf215546Sopenharmony_ci      lp_setup_set_fragment_sampler_views(llvmpipe->setup,
346bf215546Sopenharmony_ci                                          llvmpipe->num_sampler_views[PIPE_SHADER_FRAGMENT],
347bf215546Sopenharmony_ci                                          llvmpipe->sampler_views[PIPE_SHADER_FRAGMENT]);
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_ci   if (llvmpipe->dirty & (LP_NEW_SAMPLER))
350bf215546Sopenharmony_ci      lp_setup_set_fragment_sampler_state(llvmpipe->setup,
351bf215546Sopenharmony_ci                                          llvmpipe->num_samplers[PIPE_SHADER_FRAGMENT],
352bf215546Sopenharmony_ci                                          llvmpipe->samplers[PIPE_SHADER_FRAGMENT]);
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   if (llvmpipe->dirty & LP_NEW_VIEWPORT) {
355bf215546Sopenharmony_ci      /*
356bf215546Sopenharmony_ci       * Update setup and fragment's view of the active viewport state.
357bf215546Sopenharmony_ci       *
358bf215546Sopenharmony_ci       * XXX TODO: It is possible to only loop over the active viewports
359bf215546Sopenharmony_ci       *           instead of all viewports (PIPE_MAX_VIEWPORTS).
360bf215546Sopenharmony_ci       */
361bf215546Sopenharmony_ci      lp_setup_set_viewports(llvmpipe->setup,
362bf215546Sopenharmony_ci                             PIPE_MAX_VIEWPORTS,
363bf215546Sopenharmony_ci                             llvmpipe->viewports);
364bf215546Sopenharmony_ci   }
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci   llvmpipe_update_derived_clear(llvmpipe);
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci   llvmpipe->dirty = 0;
369bf215546Sopenharmony_ci}
370bf215546Sopenharmony_ci
371