2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keithw@vmware.com>
34 #include "brw_context.h"
35 #include "brw_state.h"
36 #include "drivers/common/meta.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_buffers.h"
40 #include "brw_ff_gs.h"
44 #include "main/framebuffer.h"
46 static const struct brw_tracked_state
*gen4_atoms
[] =
48 &brw_interpolation_map
,
50 &brw_clip_prog
, /* must do before state base address */
51 &brw_sf_prog
, /* must do before state base address */
53 /* Once all the programs are done, we know how large urb entry
54 * sizes need to be and can decide if we need to change the urb
58 &brw_recalculate_urb_fence
,
63 /* Surface state setup. Must come before the VS/WM unit. The binding
64 * table upload must be last.
66 &brw_vs_pull_constants
,
67 &brw_wm_pull_constants
,
68 &brw_renderbuffer_surfaces
,
69 &brw_texture_surfaces
,
70 &brw_vs_binding_table
,
71 &brw_wm_binding_table
,
76 /* These set up state for brw_psp_urb_cbs */
80 &brw_vs_unit
, /* always required, enabled or not */
87 &brw_state_base_address
,
89 &brw_binding_table_pointers
,
90 &brw_blend_constant_color
,
95 &brw_polygon_stipple_offset
,
98 &brw_aa_line_parameters
,
103 &brw_indices
, /* must come before brw_vertices */
110 static const struct brw_tracked_state
*gen6_atoms
[] =
115 /* Command packets: */
117 /* must do before binding table pointers, cc state ptrs */
118 &brw_state_base_address
,
121 &gen6_viewport_state
, /* must do after *_vp stages */
124 &gen6_blend_state
, /* must do before cc unit */
125 &gen6_color_calc_state
, /* must do before cc unit */
126 &gen6_depth_stencil_state
, /* must do before cc unit */
128 &gen6_vs_push_constants
, /* Before vs_state */
129 &gen6_gs_push_constants
, /* Before gs_state */
130 &gen6_wm_push_constants
, /* Before wm_state */
132 /* Surface state setup. Must come before the VS/WM unit. The binding
133 * table upload must be last.
135 &brw_vs_pull_constants
,
136 &brw_vs_ubo_surfaces
,
137 &brw_gs_pull_constants
,
138 &brw_gs_ubo_surfaces
,
139 &brw_wm_pull_constants
,
140 &brw_wm_ubo_surfaces
,
141 &gen6_renderbuffer_surfaces
,
142 &brw_texture_surfaces
,
144 &brw_vs_binding_table
,
145 &gen6_gs_binding_table
,
146 &brw_wm_binding_table
,
152 &gen6_multisample_state
,
162 &gen6_binding_table_pointers
,
166 &brw_polygon_stipple
,
167 &brw_polygon_stipple_offset
,
170 &brw_aa_line_parameters
,
174 &brw_indices
, /* must come before brw_vertices */
179 static const struct brw_tracked_state
*gen7_render_atoms
[] =
181 /* Command packets: */
183 /* must do before binding table pointers, cc state ptrs */
184 &brw_state_base_address
,
187 &gen7_sf_clip_viewport
,
189 &gen7_push_constant_space
,
191 &gen6_blend_state
, /* must do before cc unit */
192 &gen6_color_calc_state
, /* must do before cc unit */
193 &gen6_depth_stencil_state
, /* must do before cc unit */
195 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Haswell */
197 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
198 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
199 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
201 &gen6_vs_push_constants
, /* Before vs_state */
202 &gen6_gs_push_constants
, /* Before gs_state */
203 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
205 /* Surface state setup. Must come before the VS/WM unit. The binding
206 * table upload must be last.
208 &brw_vs_pull_constants
,
209 &brw_vs_ubo_surfaces
,
210 &brw_vs_abo_surfaces
,
211 &brw_gs_pull_constants
,
212 &brw_gs_ubo_surfaces
,
213 &brw_gs_abo_surfaces
,
214 &brw_wm_pull_constants
,
215 &brw_wm_ubo_surfaces
,
216 &brw_wm_abo_surfaces
,
217 &gen6_renderbuffer_surfaces
,
218 &brw_texture_surfaces
,
219 &brw_vs_binding_table
,
220 &brw_gs_binding_table
,
221 &brw_wm_binding_table
,
226 &gen6_multisample_state
,
228 &gen7_disable_stages
,
242 &brw_polygon_stipple
,
243 &brw_polygon_stipple_offset
,
246 &brw_aa_line_parameters
,
250 &brw_indices
, /* must come before brw_vertices */
257 static const struct brw_tracked_state
*gen7_compute_atoms
[] =
259 &brw_state_base_address
,
260 &brw_cs_image_surfaces
,
261 &gen7_cs_push_constants
,
262 &brw_cs_abo_surfaces
,
263 &brw_texture_surfaces
,
264 &brw_cs_work_groups_surface
,
268 static const struct brw_tracked_state
*gen8_render_atoms
[] =
270 /* Command packets: */
271 &gen8_state_base_address
,
274 &gen8_sf_clip_viewport
,
276 &gen7_push_constant_space
,
279 &gen6_color_calc_state
,
281 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Broadwell */
283 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
284 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
285 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
287 &gen6_vs_push_constants
, /* Before vs_state */
288 &gen6_gs_push_constants
, /* Before gs_state */
289 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
291 /* Surface state setup. Must come before the VS/WM unit. The binding
292 * table upload must be last.
294 &brw_vs_pull_constants
,
295 &brw_vs_ubo_surfaces
,
296 &brw_vs_abo_surfaces
,
297 &brw_gs_pull_constants
,
298 &brw_gs_ubo_surfaces
,
299 &brw_gs_abo_surfaces
,
300 &brw_wm_pull_constants
,
301 &brw_wm_ubo_surfaces
,
302 &brw_wm_abo_surfaces
,
303 &gen6_renderbuffer_surfaces
,
304 &brw_texture_surfaces
,
305 &brw_vs_binding_table
,
306 &brw_gs_binding_table
,
307 &brw_wm_binding_table
,
312 &gen8_multisample_state
,
314 &gen8_disable_stages
,
325 &gen8_wm_depth_stencil
,
332 &brw_polygon_stipple
,
333 &brw_polygon_stipple_offset
,
336 &brw_aa_line_parameters
,
350 static const struct brw_tracked_state
*gen8_compute_atoms
[] =
352 &gen8_state_base_address
,
353 &brw_cs_image_surfaces
,
354 &gen7_cs_push_constants
,
355 &brw_cs_abo_surfaces
,
356 &brw_texture_surfaces
,
357 &brw_cs_work_groups_surface
,
362 brw_upload_initial_gpu_state(struct brw_context
*brw
)
364 /* On platforms with hardware contexts, we can set our initial GPU state
365 * right away rather than doing it via state atoms. This saves a small
366 * amount of overhead on every draw call.
372 brw_emit_post_sync_nonzero_flush(brw
);
374 brw_upload_invariant_state(brw
);
376 /* Recommended optimization for Victim Cache eviction in pixel backend. */
379 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
380 OUT_BATCH(GEN7_CACHE_MODE_1
);
381 OUT_BATCH((GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
<< 16) |
382 GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
);
387 gen8_emit_3dstate_sample_pattern(brw
);
391 static inline const struct brw_tracked_state
*
392 brw_get_pipeline_atoms(struct brw_context
*brw
,
393 enum brw_pipeline pipeline
)
396 case BRW_RENDER_PIPELINE
:
397 return brw
->render_atoms
;
398 case BRW_COMPUTE_PIPELINE
:
399 return brw
->compute_atoms
;
401 STATIC_ASSERT(BRW_NUM_PIPELINES
== 2);
402 unreachable("Unsupported pipeline");
408 brw_copy_pipeline_atoms(struct brw_context
*brw
,
409 enum brw_pipeline pipeline
,
410 const struct brw_tracked_state
**atoms
,
413 /* This is to work around brw_context::atoms being declared const. We want
414 * it to be const, but it needs to be initialized somehow!
416 struct brw_tracked_state
*context_atoms
=
417 (struct brw_tracked_state
*) brw_get_pipeline_atoms(brw
, pipeline
);
419 for (int i
= 0; i
< num_atoms
; i
++) {
420 context_atoms
[i
] = *atoms
[i
];
421 assert(context_atoms
[i
].dirty
.mesa
| context_atoms
[i
].dirty
.brw
);
422 assert(context_atoms
[i
].emit
);
425 brw
->num_atoms
[pipeline
] = num_atoms
;
428 void brw_init_state( struct brw_context
*brw
)
430 struct gl_context
*ctx
= &brw
->ctx
;
432 /* Force the first brw_select_pipeline to emit pipeline select */
433 brw
->last_pipeline
= BRW_NUM_PIPELINES
;
435 STATIC_ASSERT(ARRAY_SIZE(gen4_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
436 STATIC_ASSERT(ARRAY_SIZE(gen6_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
437 STATIC_ASSERT(ARRAY_SIZE(gen7_render_atoms
) <=
438 ARRAY_SIZE(brw
->render_atoms
));
439 STATIC_ASSERT(ARRAY_SIZE(gen8_render_atoms
) <=
440 ARRAY_SIZE(brw
->render_atoms
));
441 STATIC_ASSERT(ARRAY_SIZE(gen7_compute_atoms
) <=
442 ARRAY_SIZE(brw
->compute_atoms
));
443 STATIC_ASSERT(ARRAY_SIZE(gen8_compute_atoms
) <=
444 ARRAY_SIZE(brw
->compute_atoms
));
446 brw_init_caches(brw
);
449 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
451 ARRAY_SIZE(gen8_render_atoms
));
452 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
454 ARRAY_SIZE(gen8_compute_atoms
));
455 } else if (brw
->gen
== 7) {
456 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
458 ARRAY_SIZE(gen7_render_atoms
));
459 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
461 ARRAY_SIZE(gen7_compute_atoms
));
462 } else if (brw
->gen
== 6) {
463 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
464 gen6_atoms
, ARRAY_SIZE(gen6_atoms
));
466 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
467 gen4_atoms
, ARRAY_SIZE(gen4_atoms
));
470 brw_upload_initial_gpu_state(brw
);
472 brw
->NewGLState
= ~0;
473 brw
->ctx
.NewDriverState
= ~0ull;
475 /* ~0 is a nonsensical value which won't match anything we program, so
476 * the programming will take effect on the first time around.
478 brw
->pma_stall_bits
= ~0;
480 /* Make sure that brw->ctx.NewDriverState has enough bits to hold all possible
483 STATIC_ASSERT(BRW_NUM_STATE_BITS
<= 8 * sizeof(brw
->ctx
.NewDriverState
));
485 ctx
->DriverFlags
.NewTransformFeedback
= BRW_NEW_TRANSFORM_FEEDBACK
;
486 ctx
->DriverFlags
.NewTransformFeedbackProg
= BRW_NEW_TRANSFORM_FEEDBACK
;
487 ctx
->DriverFlags
.NewRasterizerDiscard
= BRW_NEW_RASTERIZER_DISCARD
;
488 ctx
->DriverFlags
.NewUniformBuffer
= BRW_NEW_UNIFORM_BUFFER
;
489 ctx
->DriverFlags
.NewShaderStorageBuffer
= BRW_NEW_UNIFORM_BUFFER
;
490 ctx
->DriverFlags
.NewTextureBuffer
= BRW_NEW_TEXTURE_BUFFER
;
491 ctx
->DriverFlags
.NewAtomicBuffer
= BRW_NEW_ATOMIC_BUFFER
;
492 ctx
->DriverFlags
.NewImageUnits
= BRW_NEW_IMAGE_UNITS
;
496 void brw_destroy_state( struct brw_context
*brw
)
498 brw_destroy_caches(brw
);
501 /***********************************************************************
505 check_state(const struct brw_state_flags
*a
, const struct brw_state_flags
*b
)
507 return ((a
->mesa
& b
->mesa
) | (a
->brw
& b
->brw
)) != 0;
510 static void accumulate_state( struct brw_state_flags
*a
,
511 const struct brw_state_flags
*b
)
518 static void xor_states( struct brw_state_flags
*result
,
519 const struct brw_state_flags
*a
,
520 const struct brw_state_flags
*b
)
522 result
->mesa
= a
->mesa
^ b
->mesa
;
523 result
->brw
= a
->brw
^ b
->brw
;
526 struct dirty_bit_map
{
532 #define DEFINE_BIT(name) {name, #name, 0}
534 static struct dirty_bit_map mesa_bits
[] = {
535 DEFINE_BIT(_NEW_MODELVIEW
),
536 DEFINE_BIT(_NEW_PROJECTION
),
537 DEFINE_BIT(_NEW_TEXTURE_MATRIX
),
538 DEFINE_BIT(_NEW_COLOR
),
539 DEFINE_BIT(_NEW_DEPTH
),
540 DEFINE_BIT(_NEW_EVAL
),
541 DEFINE_BIT(_NEW_FOG
),
542 DEFINE_BIT(_NEW_HINT
),
543 DEFINE_BIT(_NEW_LIGHT
),
544 DEFINE_BIT(_NEW_LINE
),
545 DEFINE_BIT(_NEW_PIXEL
),
546 DEFINE_BIT(_NEW_POINT
),
547 DEFINE_BIT(_NEW_POLYGON
),
548 DEFINE_BIT(_NEW_POLYGONSTIPPLE
),
549 DEFINE_BIT(_NEW_SCISSOR
),
550 DEFINE_BIT(_NEW_STENCIL
),
551 DEFINE_BIT(_NEW_TEXTURE
),
552 DEFINE_BIT(_NEW_TRANSFORM
),
553 DEFINE_BIT(_NEW_VIEWPORT
),
554 DEFINE_BIT(_NEW_ARRAY
),
555 DEFINE_BIT(_NEW_RENDERMODE
),
556 DEFINE_BIT(_NEW_BUFFERS
),
557 DEFINE_BIT(_NEW_CURRENT_ATTRIB
),
558 DEFINE_BIT(_NEW_MULTISAMPLE
),
559 DEFINE_BIT(_NEW_TRACK_MATRIX
),
560 DEFINE_BIT(_NEW_PROGRAM
),
561 DEFINE_BIT(_NEW_PROGRAM_CONSTANTS
),
562 DEFINE_BIT(_NEW_BUFFER_OBJECT
),
563 DEFINE_BIT(_NEW_FRAG_CLAMP
),
564 /* Avoid sign extension problems. */
565 {(unsigned) _NEW_VARYING_VP_INPUTS
, "_NEW_VARYING_VP_INPUTS", 0},
569 static struct dirty_bit_map brw_bits
[] = {
570 DEFINE_BIT(BRW_NEW_FS_PROG_DATA
),
571 DEFINE_BIT(BRW_NEW_BLORP_BLIT_PROG_DATA
),
572 DEFINE_BIT(BRW_NEW_SF_PROG_DATA
),
573 DEFINE_BIT(BRW_NEW_VS_PROG_DATA
),
574 DEFINE_BIT(BRW_NEW_FF_GS_PROG_DATA
),
575 DEFINE_BIT(BRW_NEW_GS_PROG_DATA
),
576 DEFINE_BIT(BRW_NEW_CLIP_PROG_DATA
),
577 DEFINE_BIT(BRW_NEW_CS_PROG_DATA
),
578 DEFINE_BIT(BRW_NEW_URB_FENCE
),
579 DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM
),
580 DEFINE_BIT(BRW_NEW_GEOMETRY_PROGRAM
),
581 DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM
),
582 DEFINE_BIT(BRW_NEW_CURBE_OFFSETS
),
583 DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE
),
584 DEFINE_BIT(BRW_NEW_PRIMITIVE
),
585 DEFINE_BIT(BRW_NEW_CONTEXT
),
586 DEFINE_BIT(BRW_NEW_PSP
),
587 DEFINE_BIT(BRW_NEW_SURFACES
),
588 DEFINE_BIT(BRW_NEW_VS_BINDING_TABLE
),
589 DEFINE_BIT(BRW_NEW_GS_BINDING_TABLE
),
590 DEFINE_BIT(BRW_NEW_PS_BINDING_TABLE
),
591 DEFINE_BIT(BRW_NEW_INDICES
),
592 DEFINE_BIT(BRW_NEW_VERTICES
),
593 DEFINE_BIT(BRW_NEW_BATCH
),
594 DEFINE_BIT(BRW_NEW_INDEX_BUFFER
),
595 DEFINE_BIT(BRW_NEW_VS_CONSTBUF
),
596 DEFINE_BIT(BRW_NEW_GS_CONSTBUF
),
597 DEFINE_BIT(BRW_NEW_PROGRAM_CACHE
),
598 DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS
),
599 DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT
),
600 DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK
),
601 DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD
),
602 DEFINE_BIT(BRW_NEW_STATS_WM
),
603 DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER
),
604 DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER
),
605 DEFINE_BIT(BRW_NEW_IMAGE_UNITS
),
606 DEFINE_BIT(BRW_NEW_META_IN_PROGRESS
),
607 DEFINE_BIT(BRW_NEW_INTERPOLATION_MAP
),
608 DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION
),
609 DEFINE_BIT(BRW_NEW_NUM_SAMPLES
),
610 DEFINE_BIT(BRW_NEW_TEXTURE_BUFFER
),
611 DEFINE_BIT(BRW_NEW_GEN4_UNIT_STATE
),
612 DEFINE_BIT(BRW_NEW_CC_VP
),
613 DEFINE_BIT(BRW_NEW_SF_VP
),
614 DEFINE_BIT(BRW_NEW_CLIP_VP
),
615 DEFINE_BIT(BRW_NEW_SAMPLER_STATE_TABLE
),
616 DEFINE_BIT(BRW_NEW_VS_ATTRIB_WORKAROUNDS
),
617 DEFINE_BIT(BRW_NEW_COMPUTE_PROGRAM
),
618 DEFINE_BIT(BRW_NEW_CS_WORK_GROUPS
),
623 brw_update_dirty_count(struct dirty_bit_map
*bit_map
, uint64_t bits
)
625 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
626 if (bit_map
[i
].bit
& bits
)
632 brw_print_dirty_count(struct dirty_bit_map
*bit_map
)
634 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
635 if (bit_map
[i
].count
> 1) {
636 fprintf(stderr
, "0x%016lx: %12d (%s)\n",
637 bit_map
[i
].bit
, bit_map
[i
].count
, bit_map
[i
].name
);
643 brw_upload_programs(struct brw_context
*brw
,
644 enum brw_pipeline pipeline
)
646 if (pipeline
== BRW_RENDER_PIPELINE
) {
647 brw_upload_vs_prog(brw
);
650 brw_upload_ff_gs_prog(brw
);
652 brw_upload_gs_prog(brw
);
654 /* Update the VUE map for data exiting the GS stage of the pipeline.
655 * This comes from the last enabled shader stage.
657 GLbitfield64 old_slots
= brw
->vue_map_geom_out
.slots_valid
;
658 bool old_separate
= brw
->vue_map_geom_out
.separate
;
659 if (brw
->geometry_program
)
660 brw
->vue_map_geom_out
= brw
->gs
.prog_data
->base
.vue_map
;
662 brw
->vue_map_geom_out
= brw
->vs
.prog_data
->base
.vue_map
;
664 /* If the layout has changed, signal BRW_NEW_VUE_MAP_GEOM_OUT. */
665 if (old_slots
!= brw
->vue_map_geom_out
.slots_valid
||
666 old_separate
!= brw
->vue_map_geom_out
.separate
)
667 brw
->ctx
.NewDriverState
|= BRW_NEW_VUE_MAP_GEOM_OUT
;
669 brw_upload_wm_prog(brw
);
670 } else if (pipeline
== BRW_COMPUTE_PIPELINE
) {
671 brw_upload_cs_prog(brw
);
676 merge_ctx_state(struct brw_context
*brw
,
677 struct brw_state_flags
*state
)
679 state
->mesa
|= brw
->NewGLState
;
680 state
->brw
|= brw
->ctx
.NewDriverState
;
684 check_and_emit_atom(struct brw_context
*brw
,
685 struct brw_state_flags
*state
,
686 const struct brw_tracked_state
*atom
)
688 if (check_state(state
, &atom
->dirty
)) {
690 merge_ctx_state(brw
, state
);
695 brw_upload_pipeline_state(struct brw_context
*brw
,
696 enum brw_pipeline pipeline
)
698 struct gl_context
*ctx
= &brw
->ctx
;
700 static int dirty_count
= 0;
701 struct brw_state_flags state
= brw
->state
.pipelines
[pipeline
];
702 unsigned int fb_samples
= _mesa_geometric_samples(ctx
->DrawBuffer
);
704 brw_select_pipeline(brw
, pipeline
);
707 /* Always re-emit all state. */
708 brw
->NewGLState
= ~0;
709 ctx
->NewDriverState
= ~0ull;
712 if (pipeline
== BRW_RENDER_PIPELINE
) {
713 if (brw
->fragment_program
!= ctx
->FragmentProgram
._Current
) {
714 brw
->fragment_program
= ctx
->FragmentProgram
._Current
;
715 brw
->ctx
.NewDriverState
|= BRW_NEW_FRAGMENT_PROGRAM
;
718 if (brw
->geometry_program
!= ctx
->GeometryProgram
._Current
) {
719 brw
->geometry_program
= ctx
->GeometryProgram
._Current
;
720 brw
->ctx
.NewDriverState
|= BRW_NEW_GEOMETRY_PROGRAM
;
723 if (brw
->vertex_program
!= ctx
->VertexProgram
._Current
) {
724 brw
->vertex_program
= ctx
->VertexProgram
._Current
;
725 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTEX_PROGRAM
;
729 if (brw
->compute_program
!= ctx
->ComputeProgram
._Current
) {
730 brw
->compute_program
= ctx
->ComputeProgram
._Current
;
731 brw
->ctx
.NewDriverState
|= BRW_NEW_COMPUTE_PROGRAM
;
734 if (brw
->meta_in_progress
!= _mesa_meta_in_progress(ctx
)) {
735 brw
->meta_in_progress
= _mesa_meta_in_progress(ctx
);
736 brw
->ctx
.NewDriverState
|= BRW_NEW_META_IN_PROGRESS
;
739 if (brw
->num_samples
!= fb_samples
) {
740 brw
->num_samples
= fb_samples
;
741 brw
->ctx
.NewDriverState
|= BRW_NEW_NUM_SAMPLES
;
744 /* Exit early if no state is flagged as dirty */
745 merge_ctx_state(brw
, &state
);
746 if ((state
.mesa
| state
.brw
) == 0)
749 /* Emit Sandybridge workaround flushes on every primitive, for safety. */
751 brw_emit_post_sync_nonzero_flush(brw
);
753 brw_upload_programs(brw
, pipeline
);
754 merge_ctx_state(brw
, &state
);
756 const struct brw_tracked_state
*atoms
=
757 brw_get_pipeline_atoms(brw
, pipeline
);
758 const int num_atoms
= brw
->num_atoms
[pipeline
];
760 if (unlikely(INTEL_DEBUG
)) {
761 /* Debug version which enforces various sanity checks on the
762 * state flags which are generated and checked to help ensure
763 * state atoms are ordered correctly in the list.
765 struct brw_state_flags examined
, prev
;
766 memset(&examined
, 0, sizeof(examined
));
769 for (i
= 0; i
< num_atoms
; i
++) {
770 const struct brw_tracked_state
*atom
= &atoms
[i
];
771 struct brw_state_flags generated
;
773 check_and_emit_atom(brw
, &state
, atom
);
775 accumulate_state(&examined
, &atom
->dirty
);
777 /* generated = (prev ^ state)
778 * if (examined & generated)
781 xor_states(&generated
, &prev
, &state
);
782 assert(!check_state(&examined
, &generated
));
787 for (i
= 0; i
< num_atoms
; i
++) {
788 const struct brw_tracked_state
*atom
= &atoms
[i
];
790 check_and_emit_atom(brw
, &state
, atom
);
794 if (unlikely(INTEL_DEBUG
& DEBUG_STATE
)) {
795 STATIC_ASSERT(ARRAY_SIZE(brw_bits
) == BRW_NUM_STATE_BITS
+ 1);
797 brw_update_dirty_count(mesa_bits
, state
.mesa
);
798 brw_update_dirty_count(brw_bits
, state
.brw
);
799 if (dirty_count
++ % 1000 == 0) {
800 brw_print_dirty_count(mesa_bits
);
801 brw_print_dirty_count(brw_bits
);
802 fprintf(stderr
, "\n");
807 /***********************************************************************
810 void brw_upload_render_state(struct brw_context
*brw
)
812 brw_upload_pipeline_state(brw
, BRW_RENDER_PIPELINE
);
816 brw_pipeline_state_finished(struct brw_context
*brw
,
817 enum brw_pipeline pipeline
)
819 /* Save all dirty state into the other pipelines */
820 for (unsigned i
= 0; i
< BRW_NUM_PIPELINES
; i
++) {
822 brw
->state
.pipelines
[i
].mesa
|= brw
->NewGLState
;
823 brw
->state
.pipelines
[i
].brw
|= brw
->ctx
.NewDriverState
;
825 memset(&brw
->state
.pipelines
[i
], 0, sizeof(struct brw_state_flags
));
830 brw
->ctx
.NewDriverState
= 0ull;
834 * Clear dirty bits to account for the fact that the state emitted by
835 * brw_upload_render_state() has been committed to the hardware. This is a
836 * separate call from brw_upload_render_state() because it's possible that
837 * after the call to brw_upload_render_state(), we will discover that we've
838 * run out of aperture space, and need to rewind the batch buffer to the state
839 * it had before the brw_upload_render_state() call.
842 brw_render_state_finished(struct brw_context
*brw
)
844 brw_pipeline_state_finished(brw
, BRW_RENDER_PIPELINE
);
848 brw_upload_compute_state(struct brw_context
*brw
)
850 brw_upload_pipeline_state(brw
, BRW_COMPUTE_PIPELINE
);
854 brw_compute_state_finished(struct brw_context
*brw
)
856 brw_pipeline_state_finished(brw
, BRW_COMPUTE_PIPELINE
);