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 /* Once all the programs are done, we know how large urb entry
49 * sizes need to be and can decide if we need to change the urb
53 &brw_recalculate_urb_fence
,
58 /* Surface state setup. Must come before the VS/WM unit. The binding
59 * table upload must be last.
61 &brw_vs_pull_constants
,
62 &brw_wm_pull_constants
,
63 &brw_renderbuffer_surfaces
,
64 &brw_renderbuffer_read_surfaces
,
65 &brw_texture_surfaces
,
66 &brw_vs_binding_table
,
67 &brw_wm_binding_table
,
72 /* These set up state for brw_psp_urb_cbs */
76 &brw_vs_unit
, /* always required, enabled or not */
84 &brw_binding_table_pointers
,
85 &brw_blend_constant_color
,
90 &brw_polygon_stipple_offset
,
97 &brw_indices
, /* must come before brw_vertices */
104 static const struct brw_tracked_state
*gen6_atoms
[] =
106 &gen6_sf_and_clip_viewports
,
108 /* Command packets: */
111 &gen6_viewport_state
, /* must do after *_vp stages */
114 &gen6_blend_state
, /* must do before cc unit */
115 &gen6_color_calc_state
, /* must do before cc unit */
116 &gen6_depth_stencil_state
, /* must do before cc unit */
118 &gen6_vs_push_constants
, /* Before vs_state */
119 &gen6_gs_push_constants
, /* Before gs_state */
120 &gen6_wm_push_constants
, /* Before wm_state */
122 /* Surface state setup. Must come before the VS/WM unit. The binding
123 * table upload must be last.
125 &brw_vs_pull_constants
,
126 &brw_vs_ubo_surfaces
,
127 &brw_gs_pull_constants
,
128 &brw_gs_ubo_surfaces
,
129 &brw_wm_pull_constants
,
130 &brw_wm_ubo_surfaces
,
131 &gen6_renderbuffer_surfaces
,
132 &brw_renderbuffer_read_surfaces
,
133 &brw_texture_surfaces
,
135 &brw_vs_binding_table
,
136 &gen6_gs_binding_table
,
137 &brw_wm_binding_table
,
143 &gen6_multisample_state
,
153 &gen6_binding_table_pointers
,
157 &brw_polygon_stipple
,
158 &brw_polygon_stipple_offset
,
164 &brw_indices
, /* must come before brw_vertices */
169 static const struct brw_tracked_state
*gen7_render_atoms
[] =
171 /* Command packets: */
174 &gen7_sf_clip_viewport
,
177 &gen7_push_constant_space
,
179 &gen6_blend_state
, /* must do before cc unit */
180 &gen6_color_calc_state
, /* must do before cc unit */
181 &gen6_depth_stencil_state
, /* must do before cc unit */
183 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Haswell */
185 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
186 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
187 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
188 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
189 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
191 &gen6_vs_push_constants
, /* Before vs_state */
192 &gen7_tcs_push_constants
,
193 &gen7_tes_push_constants
,
194 &gen6_gs_push_constants
, /* Before gs_state */
195 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
197 /* Surface state setup. Must come before the VS/WM unit. The binding
198 * table upload must be last.
200 &brw_vs_pull_constants
,
201 &brw_vs_ubo_surfaces
,
202 &brw_vs_abo_surfaces
,
203 &brw_tcs_pull_constants
,
204 &brw_tcs_ubo_surfaces
,
205 &brw_tcs_abo_surfaces
,
206 &brw_tes_pull_constants
,
207 &brw_tes_ubo_surfaces
,
208 &brw_tes_abo_surfaces
,
209 &brw_gs_pull_constants
,
210 &brw_gs_ubo_surfaces
,
211 &brw_gs_abo_surfaces
,
212 &brw_wm_pull_constants
,
213 &brw_wm_ubo_surfaces
,
214 &brw_wm_abo_surfaces
,
215 &gen6_renderbuffer_surfaces
,
216 &brw_renderbuffer_read_surfaces
,
217 &brw_texture_surfaces
,
218 &brw_vs_binding_table
,
219 &brw_tcs_binding_table
,
220 &brw_tes_binding_table
,
221 &brw_gs_binding_table
,
222 &brw_wm_binding_table
,
229 &gen6_multisample_state
,
247 &brw_polygon_stipple
,
248 &brw_polygon_stipple_offset
,
254 &brw_indices
, /* must come before brw_vertices */
261 static const struct brw_tracked_state
*gen7_compute_atoms
[] =
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_cs_texture_surfaces
,
270 &brw_cs_work_groups_surface
,
275 static const struct brw_tracked_state
*gen8_render_atoms
[] =
278 &gen8_sf_clip_viewport
,
281 &gen7_push_constant_space
,
284 &gen6_color_calc_state
,
286 &gen7_hw_binding_tables
, /* Enable hw-generated binding tables for Broadwell */
288 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
289 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
290 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
291 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
292 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
294 &gen6_vs_push_constants
, /* Before vs_state */
295 &gen7_tcs_push_constants
,
296 &gen7_tes_push_constants
,
297 &gen6_gs_push_constants
, /* Before gs_state */
298 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
300 /* Surface state setup. Must come before the VS/WM unit. The binding
301 * table upload must be last.
303 &brw_vs_pull_constants
,
304 &brw_vs_ubo_surfaces
,
305 &brw_vs_abo_surfaces
,
306 &brw_tcs_pull_constants
,
307 &brw_tcs_ubo_surfaces
,
308 &brw_tcs_abo_surfaces
,
309 &brw_tes_pull_constants
,
310 &brw_tes_ubo_surfaces
,
311 &brw_tes_abo_surfaces
,
312 &brw_gs_pull_constants
,
313 &brw_gs_ubo_surfaces
,
314 &brw_gs_abo_surfaces
,
315 &brw_wm_pull_constants
,
316 &brw_wm_ubo_surfaces
,
317 &brw_wm_abo_surfaces
,
318 &gen6_renderbuffer_surfaces
,
319 &brw_renderbuffer_read_surfaces
,
320 &brw_texture_surfaces
,
321 &brw_vs_binding_table
,
322 &brw_tcs_binding_table
,
323 &brw_tes_binding_table
,
324 &brw_gs_binding_table
,
325 &brw_wm_binding_table
,
332 &gen8_multisample_state
,
347 &gen8_wm_depth_stencil
,
354 &brw_polygon_stipple
,
355 &brw_polygon_stipple_offset
,
371 static const struct brw_tracked_state
*gen8_compute_atoms
[] =
374 &brw_cs_image_surfaces
,
375 &gen7_cs_push_constants
,
376 &brw_cs_pull_constants
,
377 &brw_cs_ubo_surfaces
,
378 &brw_cs_abo_surfaces
,
379 &brw_cs_texture_surfaces
,
380 &brw_cs_work_groups_surface
,
386 brw_upload_initial_gpu_state(struct brw_context
*brw
)
388 /* On platforms with hardware contexts, we can set our initial GPU state
389 * right away rather than doing it via state atoms. This saves a small
390 * amount of overhead on every draw call.
396 brw_emit_post_sync_nonzero_flush(brw
);
398 brw_upload_invariant_state(brw
);
400 /* Recommended optimization for Victim Cache eviction in pixel backend. */
403 OUT_BATCH(MI_LOAD_REGISTER_IMM
| (3 - 2));
404 OUT_BATCH(GEN7_CACHE_MODE_1
);
405 OUT_BATCH(REG_MASK(GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
) |
406 GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC
);
411 gen8_emit_3dstate_sample_pattern(brw
);
414 OUT_BATCH(_3DSTATE_WM_HZ_OP
<< 16 | (5 - 2));
422 OUT_BATCH(_3DSTATE_WM_CHROMAKEY
<< 16 | (2 - 2));
428 static inline const struct brw_tracked_state
*
429 brw_get_pipeline_atoms(struct brw_context
*brw
,
430 enum brw_pipeline pipeline
)
433 case BRW_RENDER_PIPELINE
:
434 return brw
->render_atoms
;
435 case BRW_COMPUTE_PIPELINE
:
436 return brw
->compute_atoms
;
438 STATIC_ASSERT(BRW_NUM_PIPELINES
== 2);
439 unreachable("Unsupported pipeline");
445 brw_copy_pipeline_atoms(struct brw_context
*brw
,
446 enum brw_pipeline pipeline
,
447 const struct brw_tracked_state
**atoms
,
450 /* This is to work around brw_context::atoms being declared const. We want
451 * it to be const, but it needs to be initialized somehow!
453 struct brw_tracked_state
*context_atoms
=
454 (struct brw_tracked_state
*) brw_get_pipeline_atoms(brw
, pipeline
);
456 for (int i
= 0; i
< num_atoms
; i
++) {
457 context_atoms
[i
] = *atoms
[i
];
458 assert(context_atoms
[i
].dirty
.mesa
| context_atoms
[i
].dirty
.brw
);
459 assert(context_atoms
[i
].emit
);
462 brw
->num_atoms
[pipeline
] = num_atoms
;
465 void brw_init_state( struct brw_context
*brw
)
467 struct gl_context
*ctx
= &brw
->ctx
;
469 /* Force the first brw_select_pipeline to emit pipeline select */
470 brw
->last_pipeline
= BRW_NUM_PIPELINES
;
472 STATIC_ASSERT(ARRAY_SIZE(gen4_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
473 STATIC_ASSERT(ARRAY_SIZE(gen6_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
474 STATIC_ASSERT(ARRAY_SIZE(gen7_render_atoms
) <=
475 ARRAY_SIZE(brw
->render_atoms
));
476 STATIC_ASSERT(ARRAY_SIZE(gen8_render_atoms
) <=
477 ARRAY_SIZE(brw
->render_atoms
));
478 STATIC_ASSERT(ARRAY_SIZE(gen7_compute_atoms
) <=
479 ARRAY_SIZE(brw
->compute_atoms
));
480 STATIC_ASSERT(ARRAY_SIZE(gen8_compute_atoms
) <=
481 ARRAY_SIZE(brw
->compute_atoms
));
483 brw_init_caches(brw
);
486 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
488 ARRAY_SIZE(gen8_render_atoms
));
489 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
491 ARRAY_SIZE(gen8_compute_atoms
));
492 } else if (brw
->gen
== 7) {
493 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
495 ARRAY_SIZE(gen7_render_atoms
));
496 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
498 ARRAY_SIZE(gen7_compute_atoms
));
499 } else if (brw
->gen
== 6) {
500 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
501 gen6_atoms
, ARRAY_SIZE(gen6_atoms
));
503 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
504 gen4_atoms
, ARRAY_SIZE(gen4_atoms
));
507 brw_upload_initial_gpu_state(brw
);
509 brw
->NewGLState
= ~0;
510 brw
->ctx
.NewDriverState
= ~0ull;
512 /* ~0 is a nonsensical value which won't match anything we program, so
513 * the programming will take effect on the first time around.
515 brw
->pma_stall_bits
= ~0;
517 /* Make sure that brw->ctx.NewDriverState has enough bits to hold all possible
520 STATIC_ASSERT(BRW_NUM_STATE_BITS
<= 8 * sizeof(brw
->ctx
.NewDriverState
));
522 ctx
->DriverFlags
.NewTransformFeedback
= BRW_NEW_TRANSFORM_FEEDBACK
;
523 ctx
->DriverFlags
.NewTransformFeedbackProg
= BRW_NEW_TRANSFORM_FEEDBACK
;
524 ctx
->DriverFlags
.NewRasterizerDiscard
= BRW_NEW_RASTERIZER_DISCARD
;
525 ctx
->DriverFlags
.NewUniformBuffer
= BRW_NEW_UNIFORM_BUFFER
;
526 ctx
->DriverFlags
.NewShaderStorageBuffer
= BRW_NEW_UNIFORM_BUFFER
;
527 ctx
->DriverFlags
.NewTextureBuffer
= BRW_NEW_TEXTURE_BUFFER
;
528 ctx
->DriverFlags
.NewAtomicBuffer
= BRW_NEW_ATOMIC_BUFFER
;
529 ctx
->DriverFlags
.NewImageUnits
= BRW_NEW_IMAGE_UNITS
;
530 ctx
->DriverFlags
.NewDefaultTessLevels
= BRW_NEW_DEFAULT_TESS_LEVELS
;
531 ctx
->DriverFlags
.NewIntelConservativeRasterization
= BRW_NEW_CONSERVATIVE_RASTERIZATION
;
535 void brw_destroy_state( struct brw_context
*brw
)
537 brw_destroy_caches(brw
);
540 /***********************************************************************
544 check_state(const struct brw_state_flags
*a
, const struct brw_state_flags
*b
)
546 return ((a
->mesa
& b
->mesa
) | (a
->brw
& b
->brw
)) != 0;
549 static void accumulate_state( struct brw_state_flags
*a
,
550 const struct brw_state_flags
*b
)
557 static void xor_states( struct brw_state_flags
*result
,
558 const struct brw_state_flags
*a
,
559 const struct brw_state_flags
*b
)
561 result
->mesa
= a
->mesa
^ b
->mesa
;
562 result
->brw
= a
->brw
^ b
->brw
;
565 struct dirty_bit_map
{
571 #define DEFINE_BIT(name) {name, #name, 0}
573 static struct dirty_bit_map mesa_bits
[] = {
574 DEFINE_BIT(_NEW_MODELVIEW
),
575 DEFINE_BIT(_NEW_PROJECTION
),
576 DEFINE_BIT(_NEW_TEXTURE_MATRIX
),
577 DEFINE_BIT(_NEW_COLOR
),
578 DEFINE_BIT(_NEW_DEPTH
),
579 DEFINE_BIT(_NEW_EVAL
),
580 DEFINE_BIT(_NEW_FOG
),
581 DEFINE_BIT(_NEW_HINT
),
582 DEFINE_BIT(_NEW_LIGHT
),
583 DEFINE_BIT(_NEW_LINE
),
584 DEFINE_BIT(_NEW_PIXEL
),
585 DEFINE_BIT(_NEW_POINT
),
586 DEFINE_BIT(_NEW_POLYGON
),
587 DEFINE_BIT(_NEW_POLYGONSTIPPLE
),
588 DEFINE_BIT(_NEW_SCISSOR
),
589 DEFINE_BIT(_NEW_STENCIL
),
590 DEFINE_BIT(_NEW_TEXTURE
),
591 DEFINE_BIT(_NEW_TRANSFORM
),
592 DEFINE_BIT(_NEW_VIEWPORT
),
593 DEFINE_BIT(_NEW_ARRAY
),
594 DEFINE_BIT(_NEW_RENDERMODE
),
595 DEFINE_BIT(_NEW_BUFFERS
),
596 DEFINE_BIT(_NEW_CURRENT_ATTRIB
),
597 DEFINE_BIT(_NEW_MULTISAMPLE
),
598 DEFINE_BIT(_NEW_TRACK_MATRIX
),
599 DEFINE_BIT(_NEW_PROGRAM
),
600 DEFINE_BIT(_NEW_PROGRAM_CONSTANTS
),
601 DEFINE_BIT(_NEW_BUFFER_OBJECT
),
602 DEFINE_BIT(_NEW_FRAG_CLAMP
),
603 /* Avoid sign extension problems. */
604 {(unsigned) _NEW_VARYING_VP_INPUTS
, "_NEW_VARYING_VP_INPUTS", 0},
608 static struct dirty_bit_map brw_bits
[] = {
609 DEFINE_BIT(BRW_NEW_FS_PROG_DATA
),
610 DEFINE_BIT(BRW_NEW_BLORP_BLIT_PROG_DATA
),
611 DEFINE_BIT(BRW_NEW_SF_PROG_DATA
),
612 DEFINE_BIT(BRW_NEW_VS_PROG_DATA
),
613 DEFINE_BIT(BRW_NEW_FF_GS_PROG_DATA
),
614 DEFINE_BIT(BRW_NEW_GS_PROG_DATA
),
615 DEFINE_BIT(BRW_NEW_TCS_PROG_DATA
),
616 DEFINE_BIT(BRW_NEW_TES_PROG_DATA
),
617 DEFINE_BIT(BRW_NEW_CLIP_PROG_DATA
),
618 DEFINE_BIT(BRW_NEW_CS_PROG_DATA
),
619 DEFINE_BIT(BRW_NEW_URB_FENCE
),
620 DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM
),
621 DEFINE_BIT(BRW_NEW_GEOMETRY_PROGRAM
),
622 DEFINE_BIT(BRW_NEW_TESS_PROGRAMS
),
623 DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM
),
624 DEFINE_BIT(BRW_NEW_CURBE_OFFSETS
),
625 DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE
),
626 DEFINE_BIT(BRW_NEW_PATCH_PRIMITIVE
),
627 DEFINE_BIT(BRW_NEW_PRIMITIVE
),
628 DEFINE_BIT(BRW_NEW_CONTEXT
),
629 DEFINE_BIT(BRW_NEW_PSP
),
630 DEFINE_BIT(BRW_NEW_SURFACES
),
631 DEFINE_BIT(BRW_NEW_BINDING_TABLE_POINTERS
),
632 DEFINE_BIT(BRW_NEW_INDICES
),
633 DEFINE_BIT(BRW_NEW_VERTICES
),
634 DEFINE_BIT(BRW_NEW_DEFAULT_TESS_LEVELS
),
635 DEFINE_BIT(BRW_NEW_BATCH
),
636 DEFINE_BIT(BRW_NEW_INDEX_BUFFER
),
637 DEFINE_BIT(BRW_NEW_VS_CONSTBUF
),
638 DEFINE_BIT(BRW_NEW_TCS_CONSTBUF
),
639 DEFINE_BIT(BRW_NEW_TES_CONSTBUF
),
640 DEFINE_BIT(BRW_NEW_GS_CONSTBUF
),
641 DEFINE_BIT(BRW_NEW_PROGRAM_CACHE
),
642 DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS
),
643 DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT
),
644 DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK
),
645 DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD
),
646 DEFINE_BIT(BRW_NEW_STATS_WM
),
647 DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER
),
648 DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER
),
649 DEFINE_BIT(BRW_NEW_IMAGE_UNITS
),
650 DEFINE_BIT(BRW_NEW_META_IN_PROGRESS
),
651 DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION
),
652 DEFINE_BIT(BRW_NEW_NUM_SAMPLES
),
653 DEFINE_BIT(BRW_NEW_TEXTURE_BUFFER
),
654 DEFINE_BIT(BRW_NEW_GEN4_UNIT_STATE
),
655 DEFINE_BIT(BRW_NEW_CC_VP
),
656 DEFINE_BIT(BRW_NEW_SF_VP
),
657 DEFINE_BIT(BRW_NEW_CLIP_VP
),
658 DEFINE_BIT(BRW_NEW_SAMPLER_STATE_TABLE
),
659 DEFINE_BIT(BRW_NEW_VS_ATTRIB_WORKAROUNDS
),
660 DEFINE_BIT(BRW_NEW_COMPUTE_PROGRAM
),
661 DEFINE_BIT(BRW_NEW_CS_WORK_GROUPS
),
662 DEFINE_BIT(BRW_NEW_URB_SIZE
),
663 DEFINE_BIT(BRW_NEW_CC_STATE
),
664 DEFINE_BIT(BRW_NEW_BLORP
),
665 DEFINE_BIT(BRW_NEW_VIEWPORT_COUNT
),
666 DEFINE_BIT(BRW_NEW_CONSERVATIVE_RASTERIZATION
),
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%016"PRIx64
": %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 brw_upload_tcs_prog(brw
);
695 brw_upload_tes_prog(brw
);
697 brw
->tcs
.base
.prog_data
= NULL
;
698 brw
->tes
.base
.prog_data
= NULL
;
703 brw_upload_programs(struct brw_context
*brw
,
704 enum brw_pipeline pipeline
)
706 struct gl_context
*ctx
= &brw
->ctx
;
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 struct brw_vue_prog_data
*vue_prog_data
;
723 if (brw
->geometry_program
)
724 vue_prog_data
= brw_vue_prog_data(brw
->gs
.base
.prog_data
);
725 else if (brw
->tess_eval_program
)
726 vue_prog_data
= brw_vue_prog_data(brw
->tes
.base
.prog_data
);
728 vue_prog_data
= brw_vue_prog_data(brw
->vs
.base
.prog_data
);
730 brw
->vue_map_geom_out
= vue_prog_data
->vue_map
;
732 /* If the layout has changed, signal BRW_NEW_VUE_MAP_GEOM_OUT. */
733 if (old_slots
!= brw
->vue_map_geom_out
.slots_valid
||
734 old_separate
!= brw
->vue_map_geom_out
.separate
)
735 brw
->ctx
.NewDriverState
|= BRW_NEW_VUE_MAP_GEOM_OUT
;
737 if ((old_slots
^ brw
->vue_map_geom_out
.slots_valid
) &
738 VARYING_BIT_VIEWPORT
) {
739 ctx
->NewDriverState
|= BRW_NEW_VIEWPORT_COUNT
;
740 brw
->clip
.viewport_count
=
741 (brw
->vue_map_geom_out
.slots_valid
& VARYING_BIT_VIEWPORT
) ?
742 ctx
->Const
.MaxViewports
: 1;
745 brw_upload_wm_prog(brw
);
748 brw_upload_clip_prog(brw
);
749 brw_upload_sf_prog(brw
);
751 } else if (pipeline
== BRW_COMPUTE_PIPELINE
) {
752 brw_upload_cs_prog(brw
);
757 merge_ctx_state(struct brw_context
*brw
,
758 struct brw_state_flags
*state
)
760 state
->mesa
|= brw
->NewGLState
;
761 state
->brw
|= brw
->ctx
.NewDriverState
;
765 check_and_emit_atom(struct brw_context
*brw
,
766 struct brw_state_flags
*state
,
767 const struct brw_tracked_state
*atom
)
769 if (check_state(state
, &atom
->dirty
)) {
771 merge_ctx_state(brw
, state
);
776 brw_upload_pipeline_state(struct brw_context
*brw
,
777 enum brw_pipeline pipeline
)
779 struct gl_context
*ctx
= &brw
->ctx
;
781 static int dirty_count
= 0;
782 struct brw_state_flags state
= brw
->state
.pipelines
[pipeline
];
783 unsigned int fb_samples
= _mesa_geometric_samples(ctx
->DrawBuffer
);
785 brw_select_pipeline(brw
, pipeline
);
788 /* Always re-emit all state. */
789 brw
->NewGLState
= ~0;
790 ctx
->NewDriverState
= ~0ull;
793 if (pipeline
== BRW_RENDER_PIPELINE
) {
794 if (brw
->fragment_program
!= ctx
->FragmentProgram
._Current
) {
795 brw
->fragment_program
= ctx
->FragmentProgram
._Current
;
796 brw
->ctx
.NewDriverState
|= BRW_NEW_FRAGMENT_PROGRAM
;
799 if (brw
->tess_eval_program
!= ctx
->TessEvalProgram
._Current
) {
800 brw
->tess_eval_program
= ctx
->TessEvalProgram
._Current
;
801 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
804 if (brw
->tess_ctrl_program
!= ctx
->TessCtrlProgram
._Current
) {
805 brw
->tess_ctrl_program
= ctx
->TessCtrlProgram
._Current
;
806 brw
->ctx
.NewDriverState
|= BRW_NEW_TESS_PROGRAMS
;
809 if (brw
->geometry_program
!= ctx
->GeometryProgram
._Current
) {
810 brw
->geometry_program
= ctx
->GeometryProgram
._Current
;
811 brw
->ctx
.NewDriverState
|= BRW_NEW_GEOMETRY_PROGRAM
;
814 if (brw
->vertex_program
!= ctx
->VertexProgram
._Current
) {
815 brw
->vertex_program
= ctx
->VertexProgram
._Current
;
816 brw
->ctx
.NewDriverState
|= BRW_NEW_VERTEX_PROGRAM
;
820 if (brw
->compute_program
!= ctx
->ComputeProgram
._Current
) {
821 brw
->compute_program
= ctx
->ComputeProgram
._Current
;
822 brw
->ctx
.NewDriverState
|= BRW_NEW_COMPUTE_PROGRAM
;
825 if (brw
->meta_in_progress
!= _mesa_meta_in_progress(ctx
)) {
826 brw
->meta_in_progress
= _mesa_meta_in_progress(ctx
);
827 brw
->ctx
.NewDriverState
|= BRW_NEW_META_IN_PROGRESS
;
830 if (brw
->num_samples
!= fb_samples
) {
831 brw
->num_samples
= fb_samples
;
832 brw
->ctx
.NewDriverState
|= BRW_NEW_NUM_SAMPLES
;
835 /* Exit early if no state is flagged as dirty */
836 merge_ctx_state(brw
, &state
);
837 if ((state
.mesa
| state
.brw
) == 0)
840 /* Emit Sandybridge workaround flushes on every primitive, for safety. */
842 brw_emit_post_sync_nonzero_flush(brw
);
844 brw_upload_programs(brw
, pipeline
);
845 merge_ctx_state(brw
, &state
);
847 brw_upload_state_base_address(brw
);
849 const struct brw_tracked_state
*atoms
=
850 brw_get_pipeline_atoms(brw
, pipeline
);
851 const int num_atoms
= brw
->num_atoms
[pipeline
];
853 if (unlikely(INTEL_DEBUG
)) {
854 /* Debug version which enforces various sanity checks on the
855 * state flags which are generated and checked to help ensure
856 * state atoms are ordered correctly in the list.
858 struct brw_state_flags examined
, prev
;
859 memset(&examined
, 0, sizeof(examined
));
862 for (i
= 0; i
< num_atoms
; i
++) {
863 const struct brw_tracked_state
*atom
= &atoms
[i
];
864 struct brw_state_flags generated
;
866 check_and_emit_atom(brw
, &state
, atom
);
868 accumulate_state(&examined
, &atom
->dirty
);
870 /* generated = (prev ^ state)
871 * if (examined & generated)
874 xor_states(&generated
, &prev
, &state
);
875 assert(!check_state(&examined
, &generated
));
880 for (i
= 0; i
< num_atoms
; i
++) {
881 const struct brw_tracked_state
*atom
= &atoms
[i
];
883 check_and_emit_atom(brw
, &state
, atom
);
887 if (unlikely(INTEL_DEBUG
& DEBUG_STATE
)) {
888 STATIC_ASSERT(ARRAY_SIZE(brw_bits
) == BRW_NUM_STATE_BITS
+ 1);
890 brw_update_dirty_count(mesa_bits
, state
.mesa
);
891 brw_update_dirty_count(brw_bits
, state
.brw
);
892 if (dirty_count
++ % 1000 == 0) {
893 brw_print_dirty_count(mesa_bits
);
894 brw_print_dirty_count(brw_bits
);
895 fprintf(stderr
, "\n");
900 /***********************************************************************
903 void brw_upload_render_state(struct brw_context
*brw
)
905 brw_upload_pipeline_state(brw
, BRW_RENDER_PIPELINE
);
909 brw_pipeline_state_finished(struct brw_context
*brw
,
910 enum brw_pipeline pipeline
)
912 /* Save all dirty state into the other pipelines */
913 for (unsigned i
= 0; i
< BRW_NUM_PIPELINES
; i
++) {
915 brw
->state
.pipelines
[i
].mesa
|= brw
->NewGLState
;
916 brw
->state
.pipelines
[i
].brw
|= brw
->ctx
.NewDriverState
;
918 memset(&brw
->state
.pipelines
[i
], 0, sizeof(struct brw_state_flags
));
923 brw
->ctx
.NewDriverState
= 0ull;
927 * Clear dirty bits to account for the fact that the state emitted by
928 * brw_upload_render_state() has been committed to the hardware. This is a
929 * separate call from brw_upload_render_state() because it's possible that
930 * after the call to brw_upload_render_state(), we will discover that we've
931 * run out of aperture space, and need to rewind the batch buffer to the state
932 * it had before the brw_upload_render_state() call.
935 brw_render_state_finished(struct brw_context
*brw
)
937 brw_pipeline_state_finished(brw
, BRW_RENDER_PIPELINE
);
941 brw_upload_compute_state(struct brw_context
*brw
)
943 brw_upload_pipeline_state(brw
, BRW_COMPUTE_PIPELINE
);
947 brw_compute_state_finished(struct brw_context
*brw
)
949 brw_pipeline_state_finished(brw
, BRW_COMPUTE_PIPELINE
);