mesa: replace _NEW_EVAL with vbo_exec_update_eval_maps
[mesa.git] / src / mesa / main / state.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /**
27 * \file state.c
28 * State management.
29 *
30 * This file manages recalculation of derived values in struct gl_context.
31 */
32
33
34 #include "glheader.h"
35 #include "mtypes.h"
36 #include "arrayobj.h"
37 #include "context.h"
38 #include "debug.h"
39 #include "macros.h"
40 #include "ffvertex_prog.h"
41 #include "framebuffer.h"
42 #include "light.h"
43 #include "matrix.h"
44 #include "pixel.h"
45 #include "program/program.h"
46 #include "program/prog_parameter.h"
47 #include "shaderobj.h"
48 #include "state.h"
49 #include "stencil.h"
50 #include "texenvprogram.h"
51 #include "texobj.h"
52 #include "texstate.h"
53 #include "varray.h"
54 #include "vbo/vbo.h"
55 #include "viewport.h"
56 #include "blend.h"
57
58
59 void
60 _mesa_update_allow_draw_out_of_order(struct gl_context *ctx)
61 {
62 /* Out-of-order drawing is useful when vertex array draws and immediate
63 * mode are interleaved.
64 *
65 * Example with 3 draws:
66 * glBegin();
67 * glVertex();
68 * glEnd();
69 * glDrawElements();
70 * glBegin();
71 * glVertex();
72 * glEnd();
73 *
74 * Out-of-order drawing changes the execution order like this:
75 * glDrawElements();
76 * glBegin();
77 * glVertex();
78 * glVertex();
79 * glEnd();
80 *
81 * If out-of-order draws are enabled, immediate mode vertices are not
82 * flushed before glDrawElements, resulting in fewer draws and lower CPU
83 * overhead. This helps workstation applications.
84 *
85 * This is a simplified version of out-of-order determination to catch
86 * common cases.
87 *
88 * RadeonSI has a complete and more complicated out-of-order determination
89 * for driver-internal reasons.
90 */
91 /* Only the compatibility profile with immediate mode needs this. */
92 if (ctx->API != API_OPENGL_COMPAT || !ctx->Const.AllowDrawOutOfOrder)
93 return;
94
95 /* If all of these are NULL, GLSL is disabled. */
96 struct gl_program *vs =
97 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
98 struct gl_program *tcs =
99 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
100 struct gl_program *tes =
101 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
102 struct gl_program *gs =
103 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
104 struct gl_program *fs =
105 ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
106 GLenum16 depth_func = ctx->Depth.Func;
107
108 /* Z fighting and any primitives with equal Z shouldn't be reordered
109 * with LESS/LEQUAL/GREATER/GEQUAL functions.
110 *
111 * When drawing 2 primitive with equal Z:
112 * - with LEQUAL/GEQUAL, the last primitive wins the Z test.
113 * - with LESS/GREATER, the first primitive wins the Z test.
114 *
115 * Here we ignore that on the basis that such cases don't occur in real
116 * apps, and we they do occur, they occur with blending where out-of-order
117 * drawing is always disabled.
118 */
119 bool previous_state = ctx->_AllowDrawOutOfOrder;
120 ctx->_AllowDrawOutOfOrder =
121 ctx->DrawBuffer &&
122 ctx->DrawBuffer->Visual.depthBits &&
123 ctx->Depth.Test &&
124 ctx->Depth.Mask &&
125 (depth_func == GL_NEVER ||
126 depth_func == GL_LESS ||
127 depth_func == GL_LEQUAL ||
128 depth_func == GL_GREATER ||
129 depth_func == GL_GEQUAL) &&
130 (!ctx->DrawBuffer->Visual.stencilBits ||
131 !ctx->Stencil.Enabled) &&
132 (!ctx->Color.ColorMask ||
133 (!ctx->Color.BlendEnabled &&
134 (!ctx->Color.ColorLogicOpEnabled ||
135 ctx->Color._LogicOp == COLOR_LOGICOP_COPY))) &&
136 (!vs || !vs->info.writes_memory) &&
137 (!tes || !tes->info.writes_memory) &&
138 (!tcs || !tcs->info.writes_memory) &&
139 (!gs || !gs->info.writes_memory) &&
140 (!fs || !fs->info.writes_memory || !fs->info.fs.early_fragment_tests);
141
142 /* If we are disabling out-of-order drawing, we need to flush queued
143 * vertices.
144 */
145 if (previous_state && !ctx->_AllowDrawOutOfOrder)
146 FLUSH_VERTICES(ctx, 0);
147 }
148
149
150 /**
151 * Update the ctx->*Program._Current pointers to point to the
152 * current/active programs.
153 *
154 * Programs may come from 3 sources: GLSL shaders, ARB/NV_vertex/fragment
155 * programs or programs derived from fixed-function state.
156 *
157 * This function needs to be called after texture state validation in case
158 * we're generating a fragment program from fixed-function texture state.
159 *
160 * \return bitfield which will indicate _NEW_PROGRAM state if a new vertex
161 * or fragment program is being used.
162 */
163 static GLbitfield
164 update_program(struct gl_context *ctx)
165 {
166 struct gl_program *vsProg =
167 ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX];
168 struct gl_program *tcsProg =
169 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL];
170 struct gl_program *tesProg =
171 ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
172 struct gl_program *gsProg =
173 ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY];
174 struct gl_program *fsProg =
175 ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT];
176 struct gl_program *csProg =
177 ctx->_Shader->CurrentProgram[MESA_SHADER_COMPUTE];
178 const struct gl_program *prevVP = ctx->VertexProgram._Current;
179 const struct gl_program *prevFP = ctx->FragmentProgram._Current;
180 const struct gl_program *prevGP = ctx->GeometryProgram._Current;
181 const struct gl_program *prevTCP = ctx->TessCtrlProgram._Current;
182 const struct gl_program *prevTEP = ctx->TessEvalProgram._Current;
183 const struct gl_program *prevCP = ctx->ComputeProgram._Current;
184
185 /*
186 * Set the ctx->VertexProgram._Current and ctx->FragmentProgram._Current
187 * pointers to the programs that should be used for rendering. If either
188 * is NULL, use fixed-function code paths.
189 *
190 * These programs may come from several sources. The priority is as
191 * follows:
192 * 1. OpenGL 2.0/ARB vertex/fragment shaders
193 * 2. ARB/NV vertex/fragment programs
194 * 3. ATI fragment shader
195 * 4. Programs derived from fixed-function state.
196 *
197 * Note: it's possible for a vertex shader to get used with a fragment
198 * program (and vice versa) here, but in practice that shouldn't ever
199 * come up, or matter.
200 */
201
202 if (fsProg) {
203 /* Use GLSL fragment shader */
204 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current, fsProg);
205 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
206 NULL);
207 }
208 else if (_mesa_arb_fragment_program_enabled(ctx)) {
209 /* Use user-defined fragment program */
210 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
211 ctx->FragmentProgram.Current);
212 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
213 NULL);
214 }
215 else if (_mesa_ati_fragment_shader_enabled(ctx) &&
216 ctx->ATIFragmentShader.Current->Program) {
217 /* Use the enabled ATI fragment shader's associated program */
218 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
219 ctx->ATIFragmentShader.Current->Program);
220 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
221 NULL);
222 }
223 else if (ctx->FragmentProgram._MaintainTexEnvProgram) {
224 /* Use fragment program generated from fixed-function state */
225 struct gl_shader_program *f = _mesa_get_fixed_func_fragment_program(ctx);
226
227 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current,
228 f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
229 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
230 f->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program);
231 }
232 else {
233 /* No fragment program */
234 _mesa_reference_program(ctx, &ctx->FragmentProgram._Current, NULL);
235 _mesa_reference_program(ctx, &ctx->FragmentProgram._TexEnvProgram,
236 NULL);
237 }
238
239 if (gsProg) {
240 /* Use GLSL geometry shader */
241 _mesa_reference_program(ctx, &ctx->GeometryProgram._Current, gsProg);
242 } else {
243 /* No geometry program */
244 _mesa_reference_program(ctx, &ctx->GeometryProgram._Current, NULL);
245 }
246
247 if (tesProg) {
248 /* Use GLSL tessellation evaluation shader */
249 _mesa_reference_program(ctx, &ctx->TessEvalProgram._Current, tesProg);
250 }
251 else {
252 /* No tessellation evaluation program */
253 _mesa_reference_program(ctx, &ctx->TessEvalProgram._Current, NULL);
254 }
255
256 if (tcsProg) {
257 /* Use GLSL tessellation control shader */
258 _mesa_reference_program(ctx, &ctx->TessCtrlProgram._Current, tcsProg);
259 }
260 else {
261 /* No tessellation control program */
262 _mesa_reference_program(ctx, &ctx->TessCtrlProgram._Current, NULL);
263 }
264
265 /* Examine vertex program after fragment program as
266 * _mesa_get_fixed_func_vertex_program() needs to know active
267 * fragprog inputs.
268 */
269 if (vsProg) {
270 /* Use GLSL vertex shader */
271 assert(VP_MODE_SHADER == ctx->VertexProgram._VPMode);
272 _mesa_reference_program(ctx, &ctx->VertexProgram._Current, vsProg);
273 }
274 else if (_mesa_arb_vertex_program_enabled(ctx)) {
275 /* Use user-defined vertex program */
276 assert(VP_MODE_SHADER == ctx->VertexProgram._VPMode);
277 _mesa_reference_program(ctx, &ctx->VertexProgram._Current,
278 ctx->VertexProgram.Current);
279 }
280 else if (ctx->VertexProgram._MaintainTnlProgram) {
281 /* Use vertex program generated from fixed-function state */
282 assert(VP_MODE_FF == ctx->VertexProgram._VPMode);
283 _mesa_reference_program(ctx, &ctx->VertexProgram._Current,
284 _mesa_get_fixed_func_vertex_program(ctx));
285 _mesa_reference_program(ctx, &ctx->VertexProgram._TnlProgram,
286 ctx->VertexProgram._Current);
287 }
288 else {
289 /* no vertex program */
290 assert(VP_MODE_FF == ctx->VertexProgram._VPMode);
291 _mesa_reference_program(ctx, &ctx->VertexProgram._Current, NULL);
292 }
293
294 if (csProg) {
295 /* Use GLSL compute shader */
296 _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, csProg);
297 } else {
298 /* no compute program */
299 _mesa_reference_program(ctx, &ctx->ComputeProgram._Current, NULL);
300 }
301
302 /* Let the driver know what's happening:
303 */
304 if (ctx->FragmentProgram._Current != prevFP ||
305 ctx->VertexProgram._Current != prevVP ||
306 ctx->GeometryProgram._Current != prevGP ||
307 ctx->TessEvalProgram._Current != prevTEP ||
308 ctx->TessCtrlProgram._Current != prevTCP ||
309 ctx->ComputeProgram._Current != prevCP)
310 return _NEW_PROGRAM;
311
312 return 0;
313 }
314
315
316 static GLbitfield
317 update_single_program_constants(struct gl_context *ctx,
318 struct gl_program *prog,
319 gl_shader_stage stage)
320 {
321 if (prog) {
322 const struct gl_program_parameter_list *params = prog->Parameters;
323 if (params && params->StateFlags & ctx->NewState) {
324 if (ctx->DriverFlags.NewShaderConstants[stage])
325 ctx->NewDriverState |= ctx->DriverFlags.NewShaderConstants[stage];
326 else
327 return _NEW_PROGRAM_CONSTANTS;
328 }
329 }
330 return 0;
331 }
332
333
334 /**
335 * This updates fixed-func state constants such as gl_ModelViewMatrix.
336 * Examine shader constants and return either _NEW_PROGRAM_CONSTANTS or 0.
337 */
338 static GLbitfield
339 update_program_constants(struct gl_context *ctx)
340 {
341 GLbitfield new_state =
342 update_single_program_constants(ctx, ctx->VertexProgram._Current,
343 MESA_SHADER_VERTEX) |
344 update_single_program_constants(ctx, ctx->FragmentProgram._Current,
345 MESA_SHADER_FRAGMENT);
346
347 if (ctx->API == API_OPENGL_COMPAT &&
348 ctx->Const.GLSLVersionCompat >= 150) {
349 new_state |=
350 update_single_program_constants(ctx, ctx->GeometryProgram._Current,
351 MESA_SHADER_GEOMETRY);
352
353 if (_mesa_has_ARB_tessellation_shader(ctx)) {
354 new_state |=
355 update_single_program_constants(ctx, ctx->TessCtrlProgram._Current,
356 MESA_SHADER_TESS_CTRL) |
357 update_single_program_constants(ctx, ctx->TessEvalProgram._Current,
358 MESA_SHADER_TESS_EVAL);
359 }
360 }
361
362 return new_state;
363 }
364
365
366 /**
367 * Compute derived GL state.
368 * If __struct gl_contextRec::NewState is non-zero then this function \b must
369 * be called before rendering anything.
370 *
371 * Calls dd_function_table::UpdateState to perform any internal state
372 * management necessary.
373 *
374 * \sa _mesa_update_modelview_project(), _mesa_update_texture(),
375 * _mesa_update_buffer_bounds(),
376 * _mesa_update_lighting() and _mesa_update_tnl_spaces().
377 */
378 void
379 _mesa_update_state_locked( struct gl_context *ctx )
380 {
381 GLbitfield new_state = ctx->NewState;
382 GLbitfield new_prog_state = 0x0;
383 const GLbitfield computed_states = ~(_NEW_CURRENT_ATTRIB | _NEW_LINE);
384
385 /* we can skip a bunch of state validation checks if the dirty
386 * state matches one or more bits in 'computed_states'.
387 */
388 if ((new_state & computed_states) == 0)
389 goto out;
390
391 if (MESA_VERBOSE & VERBOSE_STATE)
392 _mesa_print_state("_mesa_update_state", new_state);
393
394 if (new_state & _NEW_BUFFERS)
395 _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer);
396
397 /* Handle Core and Compatibility contexts separately. */
398 if (ctx->API == API_OPENGL_COMPAT ||
399 ctx->API == API_OPENGLES) {
400 GLbitfield prog_flags = _NEW_PROGRAM;
401
402 /* Determine which state flags effect vertex/fragment program state */
403 if (ctx->FragmentProgram._MaintainTexEnvProgram) {
404 prog_flags |= (_NEW_BUFFERS | _NEW_TEXTURE_OBJECT | _NEW_FOG |
405 _NEW_VARYING_VP_INPUTS | _NEW_LIGHT | _NEW_POINT |
406 _NEW_RENDERMODE | _NEW_PROGRAM | _NEW_FRAG_CLAMP |
407 _NEW_COLOR | _NEW_TEXTURE_STATE);
408 }
409 if (ctx->VertexProgram._MaintainTnlProgram) {
410 prog_flags |= (_NEW_VARYING_VP_INPUTS | _NEW_TEXTURE_OBJECT |
411 _NEW_TEXTURE_MATRIX | _NEW_TRANSFORM | _NEW_POINT |
412 _NEW_FOG | _NEW_LIGHT | _NEW_TEXTURE_STATE |
413 _MESA_NEW_NEED_EYE_COORDS);
414 }
415
416 /*
417 * Now update derived state info
418 */
419 if (new_state & (_NEW_MODELVIEW|_NEW_PROJECTION))
420 _mesa_update_modelview_project( ctx, new_state );
421
422 if (new_state & _NEW_TEXTURE_MATRIX)
423 _mesa_update_texture_matrices(ctx);
424
425 if (new_state & (_NEW_TEXTURE_OBJECT | _NEW_TEXTURE_STATE | _NEW_PROGRAM))
426 _mesa_update_texture_state(ctx);
427
428 if (new_state & _NEW_LIGHT)
429 _mesa_update_lighting(ctx);
430
431 if (new_state & _NEW_PIXEL)
432 _mesa_update_pixel( ctx );
433
434 /* ctx->_NeedEyeCoords is now up to date.
435 *
436 * If the truth value of this variable has changed, update for the
437 * new lighting space and recompute the positions of lights and the
438 * normal transform.
439 *
440 * If the lighting space hasn't changed, may still need to recompute
441 * light positions & normal transforms for other reasons.
442 */
443 if (new_state & _MESA_NEW_NEED_EYE_COORDS)
444 _mesa_update_tnl_spaces( ctx, new_state );
445
446 if (new_state & prog_flags) {
447 /* When we generate programs from fixed-function vertex/fragment state
448 * this call may generate/bind a new program. If so, we need to
449 * propogate the _NEW_PROGRAM flag to the driver.
450 */
451 new_prog_state |= update_program(ctx);
452 }
453 } else {
454 /* GL Core and GLES 2/3 contexts */
455 if (new_state & (_NEW_TEXTURE_OBJECT | _NEW_PROGRAM))
456 _mesa_update_texture_state(ctx);
457
458 if (new_state & _NEW_PROGRAM)
459 update_program(ctx);
460 }
461
462 out:
463 new_prog_state |= update_program_constants(ctx);
464
465 ctx->NewState |= new_prog_state;
466
467 /*
468 * Give the driver a chance to act upon the new_state flags.
469 * The driver might plug in different span functions, for example.
470 * Also, this is where the driver can invalidate the state of any
471 * active modules (such as swrast_setup, swrast, tnl, etc).
472 */
473 ctx->Driver.UpdateState(ctx);
474 ctx->NewState = 0;
475 }
476
477
478 /* This is the usual entrypoint for state updates:
479 */
480 void
481 _mesa_update_state( struct gl_context *ctx )
482 {
483 _mesa_lock_context_textures(ctx);
484 _mesa_update_state_locked(ctx);
485 _mesa_unlock_context_textures(ctx);
486 }
487
488
489
490
491 /**
492 * Want to figure out which fragment program inputs are actually
493 * constant/current values from ctx->Current. These should be
494 * referenced as a tracked state variable rather than a fragment
495 * program input, to save the overhead of putting a constant value in
496 * every submitted vertex, transferring it to hardware, interpolating
497 * it across the triangle, etc...
498 *
499 * When there is a VP bound, just use vp->outputs. But when we're
500 * generating vp from fixed function state, basically want to
501 * calculate:
502 *
503 * vp_out_2_fp_in( vp_in_2_vp_out( varying_inputs ) |
504 * potential_vp_outputs )
505 *
506 * Where potential_vp_outputs is calculated by looking at enabled
507 * texgen, etc.
508 *
509 * The generated fragment program should then only declare inputs that
510 * may vary or otherwise differ from the ctx->Current values.
511 * Otherwise, the fp should track them as state values instead.
512 */
513 static void
514 set_varying_vp_inputs(struct gl_context *ctx, GLbitfield varying_inputs)
515 {
516 /*
517 * The gl_context::varying_vp_inputs value is only used when in
518 * VP_MODE_FF mode.
519 */
520 if (VP_MODE_FF != ctx->VertexProgram._VPMode)
521 return;
522
523 /* Only fixed-func generated programs ever uses varying_vp_inputs. */
524 if (!ctx->VertexProgram._MaintainTnlProgram &&
525 !ctx->FragmentProgram._MaintainTexEnvProgram)
526 return;
527
528 if (ctx->varying_vp_inputs != varying_inputs) {
529 ctx->varying_vp_inputs = varying_inputs;
530 ctx->NewState |= _NEW_VARYING_VP_INPUTS;
531 }
532 }
533
534
535 /**
536 * Used by drivers to tell core Mesa that the driver is going to
537 * install/ use its own vertex program. In particular, this will
538 * prevent generated fragment programs from using state vars instead
539 * of ordinary varyings/inputs.
540 */
541 void
542 _mesa_set_vp_override(struct gl_context *ctx, GLboolean flag)
543 {
544 if (ctx->VertexProgram._Overriden != flag) {
545 ctx->VertexProgram._Overriden = flag;
546
547 /* Set one of the bits which will trigger fragment program
548 * regeneration:
549 */
550 ctx->NewState |= _NEW_PROGRAM;
551 }
552 }
553
554
555 static void
556 set_vertex_processing_mode(struct gl_context *ctx, gl_vertex_processing_mode m)
557 {
558 if (ctx->VertexProgram._VPMode == m)
559 return;
560
561 /* On change we may get new maps into the current values */
562 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
563
564 /* Finally memorize the value */
565 ctx->VertexProgram._VPMode = m;
566
567 /* Since we only track the varying inputs while being in fixed function
568 * vertex processing mode, we may need to recheck for the
569 * _NEW_VARYING_VP_INPUTS bit.
570 */
571 set_varying_vp_inputs(ctx, ctx->Array._DrawVAOEnabledAttribs);
572 }
573
574
575 /**
576 * Update ctx->VertexProgram._VPMode.
577 * This is to distinguish whether we're running
578 * a vertex program/shader,
579 * a fixed-function TNL program or
580 * a fixed function vertex transformation without any program.
581 */
582 void
583 _mesa_update_vertex_processing_mode(struct gl_context *ctx)
584 {
585 if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX])
586 set_vertex_processing_mode(ctx, VP_MODE_SHADER);
587 else if (_mesa_arb_vertex_program_enabled(ctx))
588 set_vertex_processing_mode(ctx, VP_MODE_SHADER);
589 else
590 set_vertex_processing_mode(ctx, VP_MODE_FF);
591 }
592
593
594 /**
595 * Set the _DrawVAO and the net enabled arrays.
596 * The vao->_Enabled bitmask is transformed due to position/generic0
597 * as stored in vao->_AttributeMapMode. Then the filter bitmask is applied
598 * to filter out arrays unwanted for the currently executed draw operation.
599 * For example, the generic attributes are masked out form the _DrawVAO's
600 * enabled arrays when a fixed function array draw is executed.
601 */
602 void
603 _mesa_set_draw_vao(struct gl_context *ctx, struct gl_vertex_array_object *vao,
604 GLbitfield filter)
605 {
606 struct gl_vertex_array_object **ptr = &ctx->Array._DrawVAO;
607 bool new_array = false;
608 if (*ptr != vao) {
609 _mesa_reference_vao_(ctx, ptr, vao);
610
611 new_array = true;
612 }
613
614 if (vao->NewArrays) {
615 _mesa_update_vao_derived_arrays(ctx, vao);
616 vao->NewArrays = 0;
617
618 new_array = true;
619 }
620
621 /* May shuffle the position and generic0 bits around, filter out unwanted */
622 const GLbitfield enabled = filter & _mesa_get_vao_vp_inputs(vao);
623 if (ctx->Array._DrawVAOEnabledAttribs != enabled)
624 new_array = true;
625
626 if (new_array)
627 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
628
629 ctx->Array._DrawVAOEnabledAttribs = enabled;
630 set_varying_vp_inputs(ctx, enabled);
631 }