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_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
200 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
201 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
202 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
204 &gen6_vs_push_constants
, /* Before vs_state */
205 &gen7_tcs_push_constants
,
206 &gen7_tes_push_constants
,
207 &gen6_gs_push_constants
, /* Before gs_state */
208 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
210 /* Surface state setup. Must come before the VS/WM unit. The binding
211 * table upload must be last.
213 &brw_vs_pull_constants
,
214 &brw_vs_ubo_surfaces
,
215 &brw_vs_abo_surfaces
,
216 &brw_tcs_pull_constants
,
217 &brw_tcs_ubo_surfaces
,
218 &brw_tcs_abo_surfaces
,
219 &brw_tes_pull_constants
,
220 &brw_tes_ubo_surfaces
,
221 &brw_tes_abo_surfaces
,
222 &brw_gs_pull_constants
,
223 &brw_gs_ubo_surfaces
,
224 &brw_gs_abo_surfaces
,
225 &brw_wm_pull_constants
,
226 &brw_wm_ubo_surfaces
,
227 &brw_wm_abo_surfaces
,
228 &gen6_renderbuffer_surfaces
,
229 &brw_texture_surfaces
,
230 &brw_vs_binding_table
,
231 &brw_tcs_binding_table
,
232 &brw_tes_binding_table
,
233 &brw_gs_binding_table
,
234 &brw_wm_binding_table
,
241 &gen6_multisample_state
,
259 &brw_polygon_stipple
,
260 &brw_polygon_stipple_offset
,
263 &brw_aa_line_parameters
,
267 &brw_indices
, /* must come before brw_vertices */
274 static const struct brw_tracked_state
*gen7_compute_atoms
[] =
276 &brw_state_base_address
,
278 &brw_cs_image_surfaces
,
279 &gen7_cs_push_constants
,
280 &brw_cs_pull_constants
,
281 &brw_cs_ubo_surfaces
,
282 &brw_cs_abo_surfaces
,
283 &brw_texture_surfaces
,
284 &brw_cs_work_groups_surface
,
288 static const struct brw_tracked_state
*gen8_render_atoms
[] =
290 /* Command packets: */
291 &gen8_state_base_address
,
294 &gen8_sf_clip_viewport
,
297 &gen7_push_constant_space
,
300 &gen6_color_calc_state
,
302 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Broadwell */
304 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
305 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
306 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
307 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
308 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
310 &gen6_vs_push_constants
, /* Before vs_state */
311 &gen7_tcs_push_constants
,
312 &gen7_tes_push_constants
,
313 &gen6_gs_push_constants
, /* Before gs_state */
314 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
316 /* Surface state setup. Must come before the VS/WM unit. The binding
317 * table upload must be last.
319 &brw_vs_pull_constants
,
320 &brw_vs_ubo_surfaces
,
321 &brw_vs_abo_surfaces
,
322 &brw_tcs_pull_constants
,
323 &brw_tcs_ubo_surfaces
,
324 &brw_tcs_abo_surfaces
,
325 &brw_tes_pull_constants
,
326 &brw_tes_ubo_surfaces
,
327 &brw_tes_abo_surfaces
,
328 &brw_gs_pull_constants
,
329 &brw_gs_ubo_surfaces
,
330 &brw_gs_abo_surfaces
,
331 &brw_wm_pull_constants
,
332 &brw_wm_ubo_surfaces
,
333 &brw_wm_abo_surfaces
,
334 &gen6_renderbuffer_surfaces
,
335 &brw_texture_surfaces
,
336 &brw_vs_binding_table
,
337 &brw_tcs_binding_table
,
338 &brw_tes_binding_table
,
339 &brw_gs_binding_table
,
340 &brw_wm_binding_table
,
347 &gen8_multisample_state
,
349 &gen8_disable_stages
,
363 &gen8_wm_depth_stencil
,
370 &brw_polygon_stipple
,
371 &brw_polygon_stipple_offset
,
374 &brw_aa_line_parameters
,
388 static const struct brw_tracked_state
*gen8_compute_atoms
[] =
390 &gen8_state_base_address
,
392 &brw_cs_image_surfaces
,
393 &gen7_cs_push_constants
,
394 &brw_cs_pull_constants
,
395 &brw_cs_ubo_surfaces
,
396 &brw_cs_abo_surfaces
,
397 &brw_texture_surfaces
,
398 &brw_cs_work_groups_surface
,
403 brw_upload_initial_gpu_state(struct brw_context
*brw
)
405 /* On platforms with hardware contexts, we can set our initial GPU state
406 * right away rather than doing it via state atoms. This saves a small
407 * amount of overhead on every draw call.
413 brw_emit_post_sync_nonzero_flush(brw
);
415 brw_upload_invariant_state(brw
);
417 /* Recommended optimization for Victim Cache eviction in pixel backend. */
420 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
421 OUT_BATCH(GEN7_CACHE_MODE_1
);
422 OUT_BATCH(REG_MASK(GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
) |
423 GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
);
428 gen8_emit_3dstate_sample_pattern(brw
);
432 static inline const struct brw_tracked_state
*
433 brw_get_pipeline_atoms(struct brw_context
*brw
,
434 enum brw_pipeline pipeline
)
437 case BRW_RENDER_PIPELINE
:
438 return brw
->render_atoms
;
439 case BRW_COMPUTE_PIPELINE
:
440 return brw
->compute_atoms
;
442 STATIC_ASSERT(BRW_NUM_PIPELINES
== 2);
443 unreachable("Unsupported pipeline");
449 brw_copy_pipeline_atoms(struct brw_context
*brw
,
450 enum brw_pipeline pipeline
,
451 const struct brw_tracked_state
**atoms
,
454 /* This is to work around brw_context::atoms being declared const. We want
455 * it to be const, but it needs to be initialized somehow!
457 struct brw_tracked_state
*context_atoms
=
458 (struct brw_tracked_state
*) brw_get_pipeline_atoms(brw
, pipeline
);
460 for (int i
= 0; i
< num_atoms
; i
++) {
461 context_atoms
[i
] = *atoms
[i
];
462 assert(context_atoms
[i
].dirty
.mesa
| context_atoms
[i
].dirty
.brw
);
463 assert(context_atoms
[i
].emit
);
466 brw
->num_atoms
[pipeline
] = num_atoms
;
469 void brw_init_state( struct brw_context
*brw
)
471 struct gl_context
*ctx
= &brw
->ctx
;
473 /* Force the first brw_select_pipeline to emit pipeline select */
474 brw
->last_pipeline
= BRW_NUM_PIPELINES
;
476 STATIC_ASSERT(ARRAY_SIZE(gen4_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
477 STATIC_ASSERT(ARRAY_SIZE(gen6_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
478 STATIC_ASSERT(ARRAY_SIZE(gen7_render_atoms
) <=
479 ARRAY_SIZE(brw
->render_atoms
));
480 STATIC_ASSERT(ARRAY_SIZE(gen8_render_atoms
) <=
481 ARRAY_SIZE(brw
->render_atoms
));
482 STATIC_ASSERT(ARRAY_SIZE(gen7_compute_atoms
) <=
483 ARRAY_SIZE(brw
->compute_atoms
));
484 STATIC_ASSERT(ARRAY_SIZE(gen8_compute_atoms
) <=
485 ARRAY_SIZE(brw
->compute_atoms
));
487 brw_init_caches(brw
);
490 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
492 ARRAY_SIZE(gen8_render_atoms
));
493 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
495 ARRAY_SIZE(gen8_compute_atoms
));
496 } else if (brw
->gen
== 7) {
497 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
499 ARRAY_SIZE(gen7_render_atoms
));
500 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
502 ARRAY_SIZE(gen7_compute_atoms
));
503 } else if (brw
->gen
== 6) {
504 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
505 gen6_atoms
, ARRAY_SIZE(gen6_atoms
));
507 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
508 gen4_atoms
, ARRAY_SIZE(gen4_atoms
));
511 brw_upload_initial_gpu_state(brw
);
513 brw
->NewGLState
= ~0;
514 brw
->ctx
.NewDriverState
= ~0ull;
516 /* ~0 is a nonsensical value which won't match anything we program, so
517 * the programming will take effect on the first time around.
519 brw
->pma_stall_bits
= ~0;
521 /* Make sure that brw->ctx.NewDriverState has enough bits to hold all possible
524 STATIC_ASSERT(BRW_NUM_STATE_BITS
<= 8 * sizeof(brw
->ctx
.NewDriverState
));
526 ctx
->DriverFlags
.NewTransformFeedback
= BRW_NEW_TRANSFORM_FEEDBACK
;
527 ctx
->DriverFlags
.NewTransformFeedbackProg
= BRW_NEW_TRANSFORM_FEEDBACK
;
528 ctx
->DriverFlags
.NewRasterizerDiscard
= BRW_NEW_RASTERIZER_DISCARD
;
529 ctx
->DriverFlags
.NewUniformBuffer
= BRW_NEW_UNIFORM_BUFFER
;
530 ctx
->DriverFlags
.NewShaderStorageBuffer
= BRW_NEW_UNIFORM_BUFFER
;
531 ctx
->DriverFlags
.NewTextureBuffer
= BRW_NEW_TEXTURE_BUFFER
;
532 ctx
->DriverFlags
.NewAtomicBuffer
= BRW_NEW_ATOMIC_BUFFER
;
533 ctx
->DriverFlags
.NewImageUnits
= BRW_NEW_IMAGE_UNITS
;
534 ctx
->DriverFlags
.NewDefaultTessLevels
= BRW_NEW_DEFAULT_TESS_LEVELS
;
538 void brw_destroy_state( struct brw_context
*brw
)
540 brw_destroy_caches(brw
);
543 /***********************************************************************
547 check_state(const struct brw_state_flags
*a
, const struct brw_state_flags
*b
)
549 return ((a
->mesa
& b
->mesa
) | (a
->brw
& b
->brw
)) != 0;
552 static void accumulate_state( struct brw_state_flags
*a
,
553 const struct brw_state_flags
*b
)
560 static void xor_states( struct brw_state_flags
*result
,
561 const struct brw_state_flags
*a
,
562 const struct brw_state_flags
*b
)
564 result
->mesa
= a
->mesa
^ b
->mesa
;
565 result
->brw
= a
->brw
^ b
->brw
;
568 struct dirty_bit_map
{
574 #define DEFINE_BIT(name) {name, #name, 0}
576 static struct dirty_bit_map mesa_bits
[] = {
577 DEFINE_BIT(_NEW_MODELVIEW
),
578 DEFINE_BIT(_NEW_PROJECTION
),
579 DEFINE_BIT(_NEW_TEXTURE_MATRIX
),
580 DEFINE_BIT(_NEW_COLOR
),
581 DEFINE_BIT(_NEW_DEPTH
),
582 DEFINE_BIT(_NEW_EVAL
),
583 DEFINE_BIT(_NEW_FOG
),
584 DEFINE_BIT(_NEW_HINT
),
585 DEFINE_BIT(_NEW_LIGHT
),
586 DEFINE_BIT(_NEW_LINE
),
587 DEFINE_BIT(_NEW_PIXEL
),
588 DEFINE_BIT(_NEW_POINT
),
589 DEFINE_BIT(_NEW_POLYGON
),
590 DEFINE_BIT(_NEW_POLYGONSTIPPLE
),
591 DEFINE_BIT(_NEW_SCISSOR
),
592 DEFINE_BIT(_NEW_STENCIL
),
593 DEFINE_BIT(_NEW_TEXTURE
),
594 DEFINE_BIT(_NEW_TRANSFORM
),
595 DEFINE_BIT(_NEW_VIEWPORT
),
596 DEFINE_BIT(_NEW_ARRAY
),
597 DEFINE_BIT(_NEW_RENDERMODE
),
598 DEFINE_BIT(_NEW_BUFFERS
),
599 DEFINE_BIT(_NEW_CURRENT_ATTRIB
),
600 DEFINE_BIT(_NEW_MULTISAMPLE
),
601 DEFINE_BIT(_NEW_TRACK_MATRIX
),
602 DEFINE_BIT(_NEW_PROGRAM
),
603 DEFINE_BIT(_NEW_PROGRAM_CONSTANTS
),
604 DEFINE_BIT(_NEW_BUFFER_OBJECT
),
605 DEFINE_BIT(_NEW_FRAG_CLAMP
),
606 /* Avoid sign extension problems. */
607 {(unsigned) _NEW_VARYING_VP_INPUTS
, "_NEW_VARYING_VP_INPUTS", 0},
611 static struct dirty_bit_map brw_bits
[] = {
612 DEFINE_BIT(BRW_NEW_FS_PROG_DATA
),
613 DEFINE_BIT(BRW_NEW_BLORP_BLIT_PROG_DATA
),
614 DEFINE_BIT(BRW_NEW_SF_PROG_DATA
),
615 DEFINE_BIT(BRW_NEW_VS_PROG_DATA
),
616 DEFINE_BIT(BRW_NEW_FF_GS_PROG_DATA
),
617 DEFINE_BIT(BRW_NEW_GS_PROG_DATA
),
618 DEFINE_BIT(BRW_NEW_TCS_PROG_DATA
),
619 DEFINE_BIT(BRW_NEW_TES_PROG_DATA
),
620 DEFINE_BIT(BRW_NEW_CLIP_PROG_DATA
),
621 DEFINE_BIT(BRW_NEW_CS_PROG_DATA
),
622 DEFINE_BIT(BRW_NEW_URB_FENCE
),
623 DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM
),
624 DEFINE_BIT(BRW_NEW_GEOMETRY_PROGRAM
),
625 DEFINE_BIT(BRW_NEW_TESS_PROGRAMS
),
626 DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM
),
627 DEFINE_BIT(BRW_NEW_CURBE_OFFSETS
),
628 DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE
),
629 DEFINE_BIT(BRW_NEW_PATCH_PRIMITIVE
),
630 DEFINE_BIT(BRW_NEW_PRIMITIVE
),
631 DEFINE_BIT(BRW_NEW_CONTEXT
),
632 DEFINE_BIT(BRW_NEW_PSP
),
633 DEFINE_BIT(BRW_NEW_SURFACES
),
634 DEFINE_BIT(BRW_NEW_BINDING_TABLE_POINTERS
),
635 DEFINE_BIT(BRW_NEW_INDICES
),
636 DEFINE_BIT(BRW_NEW_VERTICES
),
637 DEFINE_BIT(BRW_NEW_DEFAULT_TESS_LEVELS
),
638 DEFINE_BIT(BRW_NEW_BATCH
),
639 DEFINE_BIT(BRW_NEW_INDEX_BUFFER
),
640 DEFINE_BIT(BRW_NEW_VS_CONSTBUF
),
641 DEFINE_BIT(BRW_NEW_TCS_CONSTBUF
),
642 DEFINE_BIT(BRW_NEW_TES_CONSTBUF
),
643 DEFINE_BIT(BRW_NEW_GS_CONSTBUF
),
644 DEFINE_BIT(BRW_NEW_PROGRAM_CACHE
),
645 DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS
),
646 DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT
),
647 DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK
),
648 DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD
),
649 DEFINE_BIT(BRW_NEW_STATS_WM
),
650 DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER
),
651 DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER
),
652 DEFINE_BIT(BRW_NEW_IMAGE_UNITS
),
653 DEFINE_BIT(BRW_NEW_META_IN_PROGRESS
),
654 DEFINE_BIT(BRW_NEW_INTERPOLATION_MAP
),
655 DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION
),
656 DEFINE_BIT(BRW_NEW_NUM_SAMPLES
),
657 DEFINE_BIT(BRW_NEW_TEXTURE_BUFFER
),
658 DEFINE_BIT(BRW_NEW_GEN4_UNIT_STATE
),
659 DEFINE_BIT(BRW_NEW_CC_VP
),
660 DEFINE_BIT(BRW_NEW_SF_VP
),
661 DEFINE_BIT(BRW_NEW_CLIP_VP
),
662 DEFINE_BIT(BRW_NEW_SAMPLER_STATE_TABLE
),
663 DEFINE_BIT(BRW_NEW_VS_ATTRIB_WORKAROUNDS
),
664 DEFINE_BIT(BRW_NEW_COMPUTE_PROGRAM
),
665 DEFINE_BIT(BRW_NEW_CS_WORK_GROUPS
),
666 DEFINE_BIT(BRW_NEW_URB_SIZE
),
671 brw_update_dirty_count(struct dirty_bit_map
*bit_map
, uint64_t bits
)
673 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
674 if (bit_map
[i
].bit
& bits
)
680 brw_print_dirty_count(struct dirty_bit_map
*bit_map
)
682 for (int i
= 0; bit_map
[i
].bit
!= 0; i
++) {
683 if (bit_map
[i
].count
> 1) {
684 fprintf(stderr
, "0x%016lx: %12d (%s)\n",
685 bit_map
[i
].bit
, bit_map
[i
].count
, bit_map
[i
].name
);
691 brw_upload_tess_programs(struct brw_context
*brw
)
693 if (brw
->tess_eval_program
) {
694 uint64_t per_vertex_slots
= brw
->tess_eval_program
->Base
.InputsRead
;
695 uint32_t per_patch_slots
=
696 brw
->tess_eval_program
->Base
.PatchInputsRead
;
698 /* The TCS may have additional outputs which aren't read by the
699 * TES (possibly for cross-thread communication). These need to
700 * be stored in the Patch URB Entry as well.
702 if (brw
->tess_ctrl_program
) {
703 per_vertex_slots
|= brw
->tess_ctrl_program
->Base
.OutputsWritten
;
705 brw
->tess_ctrl_program
->Base
.PatchOutputsWritten
;
708 brw_upload_tcs_prog(brw
, per_vertex_slots
, per_patch_slots
);
709 brw_upload_tes_prog(brw
, per_vertex_slots
, per_patch_slots
);
711 brw
->tcs
.prog_data
= NULL
;
712 brw
->tcs
.base
.prog_data
= NULL
;
713 brw
->tes
.prog_data
= NULL
;
714 brw
->tes
.base
.prog_data
= NULL
;
719 brw_upload_programs(struct brw_context
*brw
,
720 enum brw_pipeline pipeline
)
722 if (pipeline
== BRW_RENDER_PIPELINE
) {
723 brw_upload_vs_prog(brw
);
724 brw_upload_tess_programs(brw
);
727 brw_upload_ff_gs_prog(brw
);
729 brw_upload_gs_prog(brw
);
731 /* Update the VUE map for data exiting the GS stage of the pipeline.
732 * This comes from the last enabled shader stage.
734 GLbitfield64 old_slots
= brw
->vue_map_geom_out
.slots_valid
;
735 bool old_separate
= brw
->vue_map_geom_out
.separate
;
736 if (brw
->geometry_program
)
737 brw
->vue_map_geom_out
= brw
->gs
.prog_data
->base
.vue_map
;
738 else if (brw
->tess_eval_program
)
739 brw
->vue_map_geom_out
= brw
->tes
.prog_data
->base
.vue_map
;
741 brw
->vue_map_geom_out
= brw
->vs
.prog_data
->base
.vue_map
;
743 /* If the layout has changed, signal BRW_NEW_VUE_MAP_GEOM_OUT. */
744 if (old_slots
!= brw
->vue_map_geom_out
.slots_valid
||
745 old_separate
!= brw
->vue_map_geom_out
.separate
)
746 brw
->ctx
.NewDriverState
|= BRW_NEW_VUE_MAP_GEOM_OUT
;
748 brw_upload_wm_prog(brw
);
749 } else if (pipeline
== BRW_COMPUTE_PIPELINE
) {
750 brw_upload_cs_prog(brw
);
755 merge_ctx_state(struct brw_context
*brw
,
756 struct brw_state_flags
*state
)
758 state
->mesa
|= brw
->NewGLState
;
759 state
->brw
|= brw
->ctx
.NewDriverState
;
763 check_and_emit_atom(struct brw_context
*brw
,
764 struct brw_state_flags
*state
,
765 const struct brw_tracked_state
*atom
)
767 if (check_state(state
, &atom
->dirty
)) {
769 merge_ctx_state(brw
, state
);
774 brw_upload_pipeline_state(struct brw_context
*brw
,
775 enum brw_pipeline pipeline
)
777 struct gl_context
*ctx
= &brw
->ctx
;
779 static int dirty_count
= 0;
780 struct brw_state_flags state
= brw
->state
.pipelines
[pipeline
];
781 unsigned int fb_samples
= _mesa_geometric_samples(ctx
->DrawBuffer
);
783 brw_select_pipeline(brw
, pipeline
);
786 /* Always re-emit all state. */
787 brw
->NewGLState
= ~0;
788 ctx
->NewDriverState
= ~0ull;
791 if (pipeline
== BRW_RENDER_PIPELINE
) {
792 if (brw
->fragment_program
!= ctx
->FragmentProgram
._Current
) {
793 brw
->fragment_program
= ctx
->FragmentProgram
._Current
;
794 brw
->ctx
.NewDriverState
|= BRW_NEW_FRAGMENT_PROGRAM
;
797 if (brw
->tess_eval_program
!= ctx
->TessEvalProgram
._Current
) {
798 brw
->tess_eval_program
= ctx
->TessEvalProgram
._Current
;
799 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
802 if (brw
->tess_ctrl_program
!= ctx
->TessCtrlProgram
._Current
) {
803 brw
->tess_ctrl_program
= ctx
->TessCtrlProgram
._Current
;
804 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
807 if (brw
->geometry_program
!= ctx
->GeometryProgram
._Current
) {
808 brw
->geometry_program
= ctx
->GeometryProgram
._Current
;
809 brw
->ctx
.NewDriverState
|= BRW_NEW_GEOMETRY_PROGRAM
;
812 if (brw
->vertex_program
!= ctx
->VertexProgram
._Current
) {
813 brw
->vertex_program
= ctx
->VertexProgram
._Current
;
814 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTEX_PROGRAM
;
818 if (brw
->compute_program
!= ctx
->ComputeProgram
._Current
) {
819 brw
->compute_program
= ctx
->ComputeProgram
._Current
;
820 brw
->ctx
.NewDriverState
|= BRW_NEW_COMPUTE_PROGRAM
;
823 if (brw
->meta_in_progress
!= _mesa_meta_in_progress(ctx
)) {
824 brw
->meta_in_progress
= _mesa_meta_in_progress(ctx
);
825 brw
->ctx
.NewDriverState
|= BRW_NEW_META_IN_PROGRESS
;
828 if (brw
->num_samples
!= fb_samples
) {
829 brw
->num_samples
= fb_samples
;
830 brw
->ctx
.NewDriverState
|= BRW_NEW_NUM_SAMPLES
;
833 /* Exit early if no state is flagged as dirty */
834 merge_ctx_state(brw
, &state
);
835 if ((state
.mesa
| state
.brw
) == 0)
838 /* Emit Sandybridge workaround flushes on every primitive, for safety. */
840 brw_emit_post_sync_nonzero_flush(brw
);
842 brw_upload_programs(brw
, pipeline
);
843 merge_ctx_state(brw
, &state
);
845 const struct brw_tracked_state
*atoms
=
846 brw_get_pipeline_atoms(brw
, pipeline
);
847 const int num_atoms
= brw
->num_atoms
[pipeline
];
849 if (unlikely(INTEL_DEBUG
)) {
850 /* Debug version which enforces various sanity checks on the
851 * state flags which are generated and checked to help ensure
852 * state atoms are ordered correctly in the list.
854 struct brw_state_flags examined
, prev
;
855 memset(&examined
, 0, sizeof(examined
));
858 for (i
= 0; i
< num_atoms
; i
++) {
859 const struct brw_tracked_state
*atom
= &atoms
[i
];
860 struct brw_state_flags generated
;
862 check_and_emit_atom(brw
, &state
, atom
);
864 accumulate_state(&examined
, &atom
->dirty
);
866 /* generated = (prev ^ state)
867 * if (examined & generated)
870 xor_states(&generated
, &prev
, &state
);
871 assert(!check_state(&examined
, &generated
));
876 for (i
= 0; i
< num_atoms
; i
++) {
877 const struct brw_tracked_state
*atom
= &atoms
[i
];
879 check_and_emit_atom(brw
, &state
, atom
);
883 if (unlikely(INTEL_DEBUG
& DEBUG_STATE
)) {
884 STATIC_ASSERT(ARRAY_SIZE(brw_bits
) == BRW_NUM_STATE_BITS
+ 1);
886 brw_update_dirty_count(mesa_bits
, state
.mesa
);
887 brw_update_dirty_count(brw_bits
, state
.brw
);
888 if (dirty_count
++ % 1000 == 0) {
889 brw_print_dirty_count(mesa_bits
);
890 brw_print_dirty_count(brw_bits
);
891 fprintf(stderr
, "\n");
896 /***********************************************************************
899 void brw_upload_render_state(struct brw_context
*brw
)
901 brw_upload_pipeline_state(brw
, BRW_RENDER_PIPELINE
);
905 brw_pipeline_state_finished(struct brw_context
*brw
,
906 enum brw_pipeline pipeline
)
908 /* Save all dirty state into the other pipelines */
909 for (unsigned i
= 0; i
< BRW_NUM_PIPELINES
; i
++) {
911 brw
->state
.pipelines
[i
].mesa
|= brw
->NewGLState
;
912 brw
->state
.pipelines
[i
].brw
|= brw
->ctx
.NewDriverState
;
914 memset(&brw
->state
.pipelines
[i
], 0, sizeof(struct brw_state_flags
));
919 brw
->ctx
.NewDriverState
= 0ull;
923 * Clear dirty bits to account for the fact that the state emitted by
924 * brw_upload_render_state() has been committed to the hardware. This is a
925 * separate call from brw_upload_render_state() because it's possible that
926 * after the call to brw_upload_render_state(), we will discover that we've
927 * run out of aperture space, and need to rewind the batch buffer to the state
928 * it had before the brw_upload_render_state() call.
931 brw_render_state_finished(struct brw_context
*brw
)
933 brw_pipeline_state_finished(brw
, BRW_RENDER_PIPELINE
);
937 brw_upload_compute_state(struct brw_context
*brw
)
939 brw_upload_pipeline_state(brw
, BRW_COMPUTE_PIPELINE
);
943 brw_compute_state_finished(struct brw_context
*brw
)
945 brw_pipeline_state_finished(brw
, BRW_COMPUTE_PIPELINE
);