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
,
190 &gen7_push_constant_space
,
192 &gen6_blend_state
, /* must do before cc unit */
193 &gen6_color_calc_state
, /* must do before cc unit */
194 &gen6_depth_stencil_state
, /* must do before cc unit */
196 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Haswell */
198 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
199 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
200 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
202 &gen6_vs_push_constants
, /* Before vs_state */
203 &gen6_gs_push_constants
, /* Before gs_state */
204 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
206 /* Surface state setup. Must come before the VS/WM unit. The binding
207 * table upload must be last.
209 &brw_vs_pull_constants
,
210 &brw_vs_ubo_surfaces
,
211 &brw_vs_abo_surfaces
,
212 &brw_gs_pull_constants
,
213 &brw_gs_ubo_surfaces
,
214 &brw_gs_abo_surfaces
,
215 &brw_wm_pull_constants
,
216 &brw_wm_ubo_surfaces
,
217 &brw_wm_abo_surfaces
,
218 &gen6_renderbuffer_surfaces
,
219 &brw_texture_surfaces
,
220 &brw_vs_binding_table
,
221 &brw_gs_binding_table
,
222 &brw_wm_binding_table
,
227 &gen6_multisample_state
,
245 &brw_polygon_stipple
,
246 &brw_polygon_stipple_offset
,
249 &brw_aa_line_parameters
,
253 &brw_indices
, /* must come before brw_vertices */
260 static const struct brw_tracked_state
*gen7_compute_atoms
[] =
262 &brw_state_base_address
,
264 &brw_cs_image_surfaces
,
265 &gen7_cs_push_constants
,
266 &brw_cs_pull_constants
,
267 &brw_cs_ubo_surfaces
,
268 &brw_cs_abo_surfaces
,
269 &brw_texture_surfaces
,
270 &brw_cs_work_groups_surface
,
274 static const struct brw_tracked_state
*gen8_render_atoms
[] =
276 /* Command packets: */
277 &gen8_state_base_address
,
280 &gen8_sf_clip_viewport
,
283 &gen7_push_constant_space
,
286 &gen6_color_calc_state
,
288 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Broadwell */
290 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
291 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
292 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
293 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
294 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
296 &gen6_vs_push_constants
, /* Before vs_state */
297 &gen7_tcs_push_constants
,
298 &gen7_tes_push_constants
,
299 &gen6_gs_push_constants
, /* Before gs_state */
300 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
302 /* Surface state setup. Must come before the VS/WM unit. The binding
303 * table upload must be last.
305 &brw_vs_pull_constants
,
306 &brw_vs_ubo_surfaces
,
307 &brw_vs_abo_surfaces
,
308 &brw_tcs_pull_constants
,
309 &brw_tcs_ubo_surfaces
,
310 &brw_tcs_abo_surfaces
,
311 &brw_tes_pull_constants
,
312 &brw_tes_ubo_surfaces
,
313 &brw_tes_abo_surfaces
,
314 &brw_gs_pull_constants
,
315 &brw_gs_ubo_surfaces
,
316 &brw_gs_abo_surfaces
,
317 &brw_wm_pull_constants
,
318 &brw_wm_ubo_surfaces
,
319 &brw_wm_abo_surfaces
,
320 &gen6_renderbuffer_surfaces
,
321 &brw_texture_surfaces
,
322 &brw_vs_binding_table
,
323 &brw_tcs_binding_table
,
324 &brw_tes_binding_table
,
325 &brw_gs_binding_table
,
326 &brw_wm_binding_table
,
333 &gen8_multisample_state
,
335 &gen8_disable_stages
,
349 &gen8_wm_depth_stencil
,
356 &brw_polygon_stipple
,
357 &brw_polygon_stipple_offset
,
360 &brw_aa_line_parameters
,
374 static const struct brw_tracked_state
*gen8_compute_atoms
[] =
376 &gen8_state_base_address
,
378 &brw_cs_image_surfaces
,
379 &gen7_cs_push_constants
,
380 &brw_cs_pull_constants
,
381 &brw_cs_ubo_surfaces
,
382 &brw_cs_abo_surfaces
,
383 &brw_texture_surfaces
,
384 &brw_cs_work_groups_surface
,
389 brw_upload_initial_gpu_state(struct brw_context
*brw
)
391 /* On platforms with hardware contexts, we can set our initial GPU state
392 * right away rather than doing it via state atoms. This saves a small
393 * amount of overhead on every draw call.
399 brw_emit_post_sync_nonzero_flush(brw
);
401 brw_upload_invariant_state(brw
);
403 /* Recommended optimization for Victim Cache eviction in pixel backend. */
406 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
407 OUT_BATCH(GEN7_CACHE_MODE_1
);
408 OUT_BATCH(REG_MASK(GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
) |
409 GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
);
414 gen8_emit_3dstate_sample_pattern(brw
);
418 static inline const struct brw_tracked_state
*
419 brw_get_pipeline_atoms(struct brw_context
*brw
,
420 enum brw_pipeline pipeline
)
423 case BRW_RENDER_PIPELINE
:
424 return brw
->render_atoms
;
425 case BRW_COMPUTE_PIPELINE
:
426 return brw
->compute_atoms
;
428 STATIC_ASSERT(BRW_NUM_PIPELINES
== 2);
429 unreachable("Unsupported pipeline");
435 brw_copy_pipeline_atoms(struct brw_context
*brw
,
436 enum brw_pipeline pipeline
,
437 const struct brw_tracked_state
**atoms
,
440 /* This is to work around brw_context::atoms being declared const. We want
441 * it to be const, but it needs to be initialized somehow!
443 struct brw_tracked_state
*context_atoms
=
444 (struct brw_tracked_state
*) brw_get_pipeline_atoms(brw
, pipeline
);
446 for (int i
= 0; i
< num_atoms
; i
++) {
447 context_atoms
[i
] = *atoms
[i
];
448 assert(context_atoms
[i
].dirty
.mesa
| context_atoms
[i
].dirty
.brw
);
449 assert(context_atoms
[i
].emit
);
452 brw
->num_atoms
[pipeline
] = num_atoms
;
455 void brw_init_state( struct brw_context
*brw
)
457 struct gl_context
*ctx
= &brw
->ctx
;
459 /* Force the first brw_select_pipeline to emit pipeline select */
460 brw
->last_pipeline
= BRW_NUM_PIPELINES
;
462 STATIC_ASSERT(ARRAY_SIZE(gen4_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
463 STATIC_ASSERT(ARRAY_SIZE(gen6_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
464 STATIC_ASSERT(ARRAY_SIZE(gen7_render_atoms
) <=
465 ARRAY_SIZE(brw
->render_atoms
));
466 STATIC_ASSERT(ARRAY_SIZE(gen8_render_atoms
) <=
467 ARRAY_SIZE(brw
->render_atoms
));
468 STATIC_ASSERT(ARRAY_SIZE(gen7_compute_atoms
) <=
469 ARRAY_SIZE(brw
->compute_atoms
));
470 STATIC_ASSERT(ARRAY_SIZE(gen8_compute_atoms
) <=
471 ARRAY_SIZE(brw
->compute_atoms
));
473 brw_init_caches(brw
);
476 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
478 ARRAY_SIZE(gen8_render_atoms
));
479 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
481 ARRAY_SIZE(gen8_compute_atoms
));
482 } else if (brw
->gen
== 7) {
483 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
485 ARRAY_SIZE(gen7_render_atoms
));
486 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
488 ARRAY_SIZE(gen7_compute_atoms
));
489 } else if (brw
->gen
== 6) {
490 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
491 gen6_atoms
, ARRAY_SIZE(gen6_atoms
));
493 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
494 gen4_atoms
, ARRAY_SIZE(gen4_atoms
));
497 brw_upload_initial_gpu_state(brw
);
499 brw
->NewGLState
= ~0;
500 brw
->ctx
.NewDriverState
= ~0ull;
502 /* ~0 is a nonsensical value which won't match anything we program, so
503 * the programming will take effect on the first time around.
505 brw
->pma_stall_bits
= ~0;
507 /* Make sure that brw->ctx.NewDriverState has enough bits to hold all possible
510 STATIC_ASSERT(BRW_NUM_STATE_BITS
<= 8 * sizeof(brw
->ctx
.NewDriverState
));
512 ctx
->DriverFlags
.NewTransformFeedback
= BRW_NEW_TRANSFORM_FEEDBACK
;
513 ctx
->DriverFlags
.NewTransformFeedbackProg
= BRW_NEW_TRANSFORM_FEEDBACK
;
514 ctx
->DriverFlags
.NewRasterizerDiscard
= BRW_NEW_RASTERIZER_DISCARD
;
515 ctx
->DriverFlags
.NewUniformBuffer
= BRW_NEW_UNIFORM_BUFFER
;
516 ctx
->DriverFlags
.NewShaderStorageBuffer
= BRW_NEW_UNIFORM_BUFFER
;
517 ctx
->DriverFlags
.NewTextureBuffer
= BRW_NEW_TEXTURE_BUFFER
;
518 ctx
->DriverFlags
.NewAtomicBuffer
= BRW_NEW_ATOMIC_BUFFER
;
519 ctx
->DriverFlags
.NewImageUnits
= BRW_NEW_IMAGE_UNITS
;
520 ctx
->DriverFlags
.NewDefaultTessLevels
= BRW_NEW_DEFAULT_TESS_LEVELS
;
524 void brw_destroy_state( struct brw_context
*brw
)
526 brw_destroy_caches(brw
);
529 /***********************************************************************
533 check_state(const struct brw_state_flags
*a
, const struct brw_state_flags
*b
)
535 return ((a
->mesa
& b
->mesa
) | (a
->brw
& b
->brw
)) != 0;
538 static void accumulate_state( struct brw_state_flags
*a
,
539 const struct brw_state_flags
*b
)
546 static void xor_states( struct brw_state_flags
*result
,
547 const struct brw_state_flags
*a
,
548 const struct brw_state_flags
*b
)
550 result
->mesa
= a
->mesa
^ b
->mesa
;
551 result
->brw
= a
->brw
^ b
->brw
;
554 struct dirty_bit_map
{
560 #define DEFINE_BIT(name) {name, #name, 0}
562 static struct dirty_bit_map mesa_bits
[] = {
563 DEFINE_BIT(_NEW_MODELVIEW
),
564 DEFINE_BIT(_NEW_PROJECTION
),
565 DEFINE_BIT(_NEW_TEXTURE_MATRIX
),
566 DEFINE_BIT(_NEW_COLOR
),
567 DEFINE_BIT(_NEW_DEPTH
),
568 DEFINE_BIT(_NEW_EVAL
),
569 DEFINE_BIT(_NEW_FOG
),
570 DEFINE_BIT(_NEW_HINT
),
571 DEFINE_BIT(_NEW_LIGHT
),
572 DEFINE_BIT(_NEW_LINE
),
573 DEFINE_BIT(_NEW_PIXEL
),
574 DEFINE_BIT(_NEW_POINT
),
575 DEFINE_BIT(_NEW_POLYGON
),
576 DEFINE_BIT(_NEW_POLYGONSTIPPLE
),
577 DEFINE_BIT(_NEW_SCISSOR
),
578 DEFINE_BIT(_NEW_STENCIL
),
579 DEFINE_BIT(_NEW_TEXTURE
),
580 DEFINE_BIT(_NEW_TRANSFORM
),
581 DEFINE_BIT(_NEW_VIEWPORT
),
582 DEFINE_BIT(_NEW_ARRAY
),
583 DEFINE_BIT(_NEW_RENDERMODE
),
584 DEFINE_BIT(_NEW_BUFFERS
),
585 DEFINE_BIT(_NEW_CURRENT_ATTRIB
),
586 DEFINE_BIT(_NEW_MULTISAMPLE
),
587 DEFINE_BIT(_NEW_TRACK_MATRIX
),
588 DEFINE_BIT(_NEW_PROGRAM
),
589 DEFINE_BIT(_NEW_PROGRAM_CONSTANTS
),
590 DEFINE_BIT(_NEW_BUFFER_OBJECT
),
591 DEFINE_BIT(_NEW_FRAG_CLAMP
),
592 /* Avoid sign extension problems. */
593 {(unsigned) _NEW_VARYING_VP_INPUTS
, "_NEW_VARYING_VP_INPUTS", 0},
597 static struct dirty_bit_map brw_bits
[] = {
598 DEFINE_BIT(BRW_NEW_FS_PROG_DATA
),
599 DEFINE_BIT(BRW_NEW_BLORP_BLIT_PROG_DATA
),
600 DEFINE_BIT(BRW_NEW_SF_PROG_DATA
),
601 DEFINE_BIT(BRW_NEW_VS_PROG_DATA
),
602 DEFINE_BIT(BRW_NEW_FF_GS_PROG_DATA
),
603 DEFINE_BIT(BRW_NEW_GS_PROG_DATA
),
604 DEFINE_BIT(BRW_NEW_TCS_PROG_DATA
),
605 DEFINE_BIT(BRW_NEW_TES_PROG_DATA
),
606 DEFINE_BIT(BRW_NEW_CLIP_PROG_DATA
),
607 DEFINE_BIT(BRW_NEW_CS_PROG_DATA
),
608 DEFINE_BIT(BRW_NEW_URB_FENCE
),
609 DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM
),
610 DEFINE_BIT(BRW_NEW_GEOMETRY_PROGRAM
),
611 DEFINE_BIT(BRW_NEW_TESS_PROGRAMS
),
612 DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM
),
613 DEFINE_BIT(BRW_NEW_CURBE_OFFSETS
),
614 DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE
),
615 DEFINE_BIT(BRW_NEW_PATCH_PRIMITIVE
),
616 DEFINE_BIT(BRW_NEW_PRIMITIVE
),
617 DEFINE_BIT(BRW_NEW_CONTEXT
),
618 DEFINE_BIT(BRW_NEW_PSP
),
619 DEFINE_BIT(BRW_NEW_SURFACES
),
620 DEFINE_BIT(BRW_NEW_BINDING_TABLE_POINTERS
),
621 DEFINE_BIT(BRW_NEW_INDICES
),
622 DEFINE_BIT(BRW_NEW_VERTICES
),
623 DEFINE_BIT(BRW_NEW_DEFAULT_TESS_LEVELS
),
624 DEFINE_BIT(BRW_NEW_BATCH
),
625 DEFINE_BIT(BRW_NEW_INDEX_BUFFER
),
626 DEFINE_BIT(BRW_NEW_VS_CONSTBUF
),
627 DEFINE_BIT(BRW_NEW_TCS_CONSTBUF
),
628 DEFINE_BIT(BRW_NEW_TES_CONSTBUF
),
629 DEFINE_BIT(BRW_NEW_GS_CONSTBUF
),
630 DEFINE_BIT(BRW_NEW_PROGRAM_CACHE
),
631 DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS
),
632 DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT
),
633 DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK
),
634 DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD
),
635 DEFINE_BIT(BRW_NEW_STATS_WM
),
636 DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER
),
637 DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER
),
638 DEFINE_BIT(BRW_NEW_IMAGE_UNITS
),
639 DEFINE_BIT(BRW_NEW_META_IN_PROGRESS
),
640 DEFINE_BIT(BRW_NEW_INTERPOLATION_MAP
),
641 DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION
),
642 DEFINE_BIT(BRW_NEW_NUM_SAMPLES
),
643 DEFINE_BIT(BRW_NEW_TEXTURE_BUFFER
),
644 DEFINE_BIT(BRW_NEW_GEN4_UNIT_STATE
),
645 DEFINE_BIT(BRW_NEW_CC_VP
),
646 DEFINE_BIT(BRW_NEW_SF_VP
),
647 DEFINE_BIT(BRW_NEW_CLIP_VP
),
648 DEFINE_BIT(BRW_NEW_SAMPLER_STATE_TABLE
),
649 DEFINE_BIT(BRW_NEW_VS_ATTRIB_WORKAROUNDS
),
650 DEFINE_BIT(BRW_NEW_COMPUTE_PROGRAM
),
651 DEFINE_BIT(BRW_NEW_CS_WORK_GROUPS
),
652 DEFINE_BIT(BRW_NEW_URB_SIZE
),
657 brw_update_dirty_count(struct dirty_bit_map
*bit_map
, uint64_t bits
)
659 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
660 if (bit_map
[i
].bit
& bits
)
666 brw_print_dirty_count(struct dirty_bit_map
*bit_map
)
668 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
669 if (bit_map
[i
].count
> 1) {
670 fprintf(stderr
, "0x%016lx: %12d (%s)\n",
671 bit_map
[i
].bit
, bit_map
[i
].count
, bit_map
[i
].name
);
677 brw_upload_tess_programs(struct brw_context
*brw
)
679 if (brw
->tess_eval_program
) {
680 uint64_t per_vertex_slots
= brw
->tess_eval_program
->Base
.InputsRead
;
681 uint32_t per_patch_slots
=
682 brw
->tess_eval_program
->Base
.PatchInputsRead
;
684 /* The TCS may have additional outputs which aren't read by the
685 * TES (possibly for cross-thread communication). These need to
686 * be stored in the Patch URB Entry as well.
688 if (brw
->tess_ctrl_program
) {
689 per_vertex_slots
|= brw
->tess_ctrl_program
->Base
.OutputsWritten
;
691 brw
->tess_ctrl_program
->Base
.PatchOutputsWritten
;
694 brw_upload_tcs_prog(brw
, per_vertex_slots
, per_patch_slots
);
695 brw_upload_tes_prog(brw
, per_vertex_slots
, per_patch_slots
);
697 brw
->tcs
.prog_data
= NULL
;
698 brw
->tcs
.base
.prog_data
= NULL
;
699 brw
->tes
.prog_data
= NULL
;
700 brw
->tes
.base
.prog_data
= NULL
;
705 brw_upload_programs(struct brw_context
*brw
,
706 enum brw_pipeline pipeline
)
708 if (pipeline
== BRW_RENDER_PIPELINE
) {
709 brw_upload_vs_prog(brw
);
710 brw_upload_tess_programs(brw
);
713 brw_upload_ff_gs_prog(brw
);
715 brw_upload_gs_prog(brw
);
717 /* Update the VUE map for data exiting the GS stage of the pipeline.
718 * This comes from the last enabled shader stage.
720 GLbitfield64 old_slots
= brw
->vue_map_geom_out
.slots_valid
;
721 bool old_separate
= brw
->vue_map_geom_out
.separate
;
722 if (brw
->geometry_program
)
723 brw
->vue_map_geom_out
= brw
->gs
.prog_data
->base
.vue_map
;
724 else if (brw
->tess_eval_program
)
725 brw
->vue_map_geom_out
= brw
->tes
.prog_data
->base
.vue_map
;
727 brw
->vue_map_geom_out
= brw
->vs
.prog_data
->base
.vue_map
;
729 /* If the layout has changed, signal BRW_NEW_VUE_MAP_GEOM_OUT. */
730 if (old_slots
!= brw
->vue_map_geom_out
.slots_valid
||
731 old_separate
!= brw
->vue_map_geom_out
.separate
)
732 brw
->ctx
.NewDriverState
|= BRW_NEW_VUE_MAP_GEOM_OUT
;
734 brw_upload_wm_prog(brw
);
735 } else if (pipeline
== BRW_COMPUTE_PIPELINE
) {
736 brw_upload_cs_prog(brw
);
741 merge_ctx_state(struct brw_context
*brw
,
742 struct brw_state_flags
*state
)
744 state
->mesa
|= brw
->NewGLState
;
745 state
->brw
|= brw
->ctx
.NewDriverState
;
749 check_and_emit_atom(struct brw_context
*brw
,
750 struct brw_state_flags
*state
,
751 const struct brw_tracked_state
*atom
)
753 if (check_state(state
, &atom
->dirty
)) {
755 merge_ctx_state(brw
, state
);
760 brw_upload_pipeline_state(struct brw_context
*brw
,
761 enum brw_pipeline pipeline
)
763 struct gl_context
*ctx
= &brw
->ctx
;
765 static int dirty_count
= 0;
766 struct brw_state_flags state
= brw
->state
.pipelines
[pipeline
];
767 unsigned int fb_samples
= _mesa_geometric_samples(ctx
->DrawBuffer
);
769 brw_select_pipeline(brw
, pipeline
);
772 /* Always re-emit all state. */
773 brw
->NewGLState
= ~0;
774 ctx
->NewDriverState
= ~0ull;
777 if (pipeline
== BRW_RENDER_PIPELINE
) {
778 if (brw
->fragment_program
!= ctx
->FragmentProgram
._Current
) {
779 brw
->fragment_program
= ctx
->FragmentProgram
._Current
;
780 brw
->ctx
.NewDriverState
|= BRW_NEW_FRAGMENT_PROGRAM
;
783 if (brw
->tess_eval_program
!= ctx
->TessEvalProgram
._Current
) {
784 brw
->tess_eval_program
= ctx
->TessEvalProgram
._Current
;
785 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
788 if (brw
->tess_ctrl_program
!= ctx
->TessCtrlProgram
._Current
) {
789 brw
->tess_ctrl_program
= ctx
->TessCtrlProgram
._Current
;
790 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
793 if (brw
->geometry_program
!= ctx
->GeometryProgram
._Current
) {
794 brw
->geometry_program
= ctx
->GeometryProgram
._Current
;
795 brw
->ctx
.NewDriverState
|= BRW_NEW_GEOMETRY_PROGRAM
;
798 if (brw
->vertex_program
!= ctx
->VertexProgram
._Current
) {
799 brw
->vertex_program
= ctx
->VertexProgram
._Current
;
800 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTEX_PROGRAM
;
804 if (brw
->compute_program
!= ctx
->ComputeProgram
._Current
) {
805 brw
->compute_program
= ctx
->ComputeProgram
._Current
;
806 brw
->ctx
.NewDriverState
|= BRW_NEW_COMPUTE_PROGRAM
;
809 if (brw
->meta_in_progress
!= _mesa_meta_in_progress(ctx
)) {
810 brw
->meta_in_progress
= _mesa_meta_in_progress(ctx
);
811 brw
->ctx
.NewDriverState
|= BRW_NEW_META_IN_PROGRESS
;
814 if (brw
->num_samples
!= fb_samples
) {
815 brw
->num_samples
= fb_samples
;
816 brw
->ctx
.NewDriverState
|= BRW_NEW_NUM_SAMPLES
;
819 /* Exit early if no state is flagged as dirty */
820 merge_ctx_state(brw
, &state
);
821 if ((state
.mesa
| state
.brw
) == 0)
824 /* Emit Sandybridge workaround flushes on every primitive, for safety. */
826 brw_emit_post_sync_nonzero_flush(brw
);
828 brw_upload_programs(brw
, pipeline
);
829 merge_ctx_state(brw
, &state
);
831 const struct brw_tracked_state
*atoms
=
832 brw_get_pipeline_atoms(brw
, pipeline
);
833 const int num_atoms
= brw
->num_atoms
[pipeline
];
835 if (unlikely(INTEL_DEBUG
)) {
836 /* Debug version which enforces various sanity checks on the
837 * state flags which are generated and checked to help ensure
838 * state atoms are ordered correctly in the list.
840 struct brw_state_flags examined
, prev
;
841 memset(&examined
, 0, sizeof(examined
));
844 for (i
= 0; i
< num_atoms
; i
++) {
845 const struct brw_tracked_state
*atom
= &atoms
[i
];
846 struct brw_state_flags generated
;
848 check_and_emit_atom(brw
, &state
, atom
);
850 accumulate_state(&examined
, &atom
->dirty
);
852 /* generated = (prev ^ state)
853 * if (examined & generated)
856 xor_states(&generated
, &prev
, &state
);
857 assert(!check_state(&examined
, &generated
));
862 for (i
= 0; i
< num_atoms
; i
++) {
863 const struct brw_tracked_state
*atom
= &atoms
[i
];
865 check_and_emit_atom(brw
, &state
, atom
);
869 if (unlikely(INTEL_DEBUG
& DEBUG_STATE
)) {
870 STATIC_ASSERT(ARRAY_SIZE(brw_bits
) == BRW_NUM_STATE_BITS
+ 1);
872 brw_update_dirty_count(mesa_bits
, state
.mesa
);
873 brw_update_dirty_count(brw_bits
, state
.brw
);
874 if (dirty_count
++ % 1000 == 0) {
875 brw_print_dirty_count(mesa_bits
);
876 brw_print_dirty_count(brw_bits
);
877 fprintf(stderr
, "\n");
882 /***********************************************************************
885 void brw_upload_render_state(struct brw_context
*brw
)
887 brw_upload_pipeline_state(brw
, BRW_RENDER_PIPELINE
);
891 brw_pipeline_state_finished(struct brw_context
*brw
,
892 enum brw_pipeline pipeline
)
894 /* Save all dirty state into the other pipelines */
895 for (unsigned i
= 0; i
< BRW_NUM_PIPELINES
; i
++) {
897 brw
->state
.pipelines
[i
].mesa
|= brw
->NewGLState
;
898 brw
->state
.pipelines
[i
].brw
|= brw
->ctx
.NewDriverState
;
900 memset(&brw
->state
.pipelines
[i
], 0, sizeof(struct brw_state_flags
));
905 brw
->ctx
.NewDriverState
= 0ull;
909 * Clear dirty bits to account for the fact that the state emitted by
910 * brw_upload_render_state() has been committed to the hardware. This is a
911 * separate call from brw_upload_render_state() because it's possible that
912 * after the call to brw_upload_render_state(), we will discover that we've
913 * run out of aperture space, and need to rewind the batch buffer to the state
914 * it had before the brw_upload_render_state() call.
917 brw_render_state_finished(struct brw_context
*brw
)
919 brw_pipeline_state_finished(brw
, BRW_RENDER_PIPELINE
);
923 brw_upload_compute_state(struct brw_context
*brw
)
925 brw_upload_pipeline_state(brw
, BRW_COMPUTE_PIPELINE
);
929 brw_compute_state_finished(struct brw_context
*brw
)
931 brw_pipeline_state_finished(brw
, BRW_COMPUTE_PIPELINE
);