i965: Calculate thread_count in brw_alloc_stage_scratch
[mesa.git] / src / mesa / drivers / dri / i965 / brw_state_upload.c
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
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:
13
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.
17
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.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32
33
34 #include "brw_context.h"
35 #include "brw_defines.h"
36 #include "brw_state.h"
37 #include "brw_program.h"
38 #include "drivers/common/meta.h"
39 #include "intel_batchbuffer.h"
40 #include "intel_buffers.h"
41 #include "brw_vs.h"
42 #include "brw_ff_gs.h"
43 #include "brw_gs.h"
44 #include "brw_wm.h"
45 #include "brw_cs.h"
46 #include "main/framebuffer.h"
47
48 static void
49 brw_upload_initial_gpu_state(struct brw_context *brw)
50 {
51 const struct gen_device_info *devinfo = &brw->screen->devinfo;
52
53 /* On platforms with hardware contexts, we can set our initial GPU state
54 * right away rather than doing it via state atoms. This saves a small
55 * amount of overhead on every draw call.
56 */
57 if (!brw->hw_ctx)
58 return;
59
60 if (devinfo->gen == 6)
61 brw_emit_post_sync_nonzero_flush(brw);
62
63 brw_upload_invariant_state(brw);
64
65 if (devinfo->gen == 9) {
66 /* Recommended optimizations for Victim Cache eviction and floating
67 * point blending.
68 */
69 BEGIN_BATCH(3);
70 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
71 OUT_BATCH(GEN7_CACHE_MODE_1);
72 OUT_BATCH(REG_MASK(GEN9_FLOAT_BLEND_OPTIMIZATION_ENABLE) |
73 REG_MASK(GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC) |
74 GEN9_FLOAT_BLEND_OPTIMIZATION_ENABLE |
75 GEN9_PARTIAL_RESOLVE_DISABLE_IN_VC);
76 ADVANCE_BATCH();
77
78 if (gen_device_info_is_9lp(devinfo)) {
79 BEGIN_BATCH(3);
80 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
81 OUT_BATCH(GEN7_GT_MODE);
82 OUT_BATCH(GEN9_SUBSLICE_HASHING_MASK_BITS |
83 GEN9_SUBSLICE_HASHING_16x16);
84 ADVANCE_BATCH();
85 }
86 }
87
88 if (devinfo->gen >= 8) {
89 gen8_emit_3dstate_sample_pattern(brw);
90
91 BEGIN_BATCH(5);
92 OUT_BATCH(_3DSTATE_WM_HZ_OP << 16 | (5 - 2));
93 OUT_BATCH(0);
94 OUT_BATCH(0);
95 OUT_BATCH(0);
96 OUT_BATCH(0);
97 ADVANCE_BATCH();
98
99 BEGIN_BATCH(2);
100 OUT_BATCH(_3DSTATE_WM_CHROMAKEY << 16 | (2 - 2));
101 OUT_BATCH(0);
102 ADVANCE_BATCH();
103 }
104 }
105
106 static inline const struct brw_tracked_state *
107 brw_get_pipeline_atoms(struct brw_context *brw,
108 enum brw_pipeline pipeline)
109 {
110 switch (pipeline) {
111 case BRW_RENDER_PIPELINE:
112 return brw->render_atoms;
113 case BRW_COMPUTE_PIPELINE:
114 return brw->compute_atoms;
115 default:
116 STATIC_ASSERT(BRW_NUM_PIPELINES == 2);
117 unreachable("Unsupported pipeline");
118 return NULL;
119 }
120 }
121
122 void
123 brw_copy_pipeline_atoms(struct brw_context *brw,
124 enum brw_pipeline pipeline,
125 const struct brw_tracked_state **atoms,
126 int num_atoms)
127 {
128 /* This is to work around brw_context::atoms being declared const. We want
129 * it to be const, but it needs to be initialized somehow!
130 */
131 struct brw_tracked_state *context_atoms =
132 (struct brw_tracked_state *) brw_get_pipeline_atoms(brw, pipeline);
133
134 for (int i = 0; i < num_atoms; i++) {
135 context_atoms[i] = *atoms[i];
136 assert(context_atoms[i].dirty.mesa | context_atoms[i].dirty.brw);
137 assert(context_atoms[i].emit);
138 }
139
140 brw->num_atoms[pipeline] = num_atoms;
141 }
142
143 void brw_init_state( struct brw_context *brw )
144 {
145 struct gl_context *ctx = &brw->ctx;
146 const struct gen_device_info *devinfo = &brw->screen->devinfo;
147
148 /* Force the first brw_select_pipeline to emit pipeline select */
149 brw->last_pipeline = BRW_NUM_PIPELINES;
150
151 brw_init_caches(brw);
152
153 if (devinfo->gen >= 10)
154 gen10_init_atoms(brw);
155 else if (devinfo->gen >= 9)
156 gen9_init_atoms(brw);
157 else if (devinfo->gen >= 8)
158 gen8_init_atoms(brw);
159 else if (devinfo->is_haswell)
160 gen75_init_atoms(brw);
161 else if (devinfo->gen >= 7)
162 gen7_init_atoms(brw);
163 else if (devinfo->gen >= 6)
164 gen6_init_atoms(brw);
165 else if (devinfo->gen >= 5)
166 gen5_init_atoms(brw);
167 else if (devinfo->is_g4x)
168 gen45_init_atoms(brw);
169 else
170 gen4_init_atoms(brw);
171
172 brw_upload_initial_gpu_state(brw);
173
174 brw->NewGLState = ~0;
175 brw->ctx.NewDriverState = ~0ull;
176
177 /* ~0 is a nonsensical value which won't match anything we program, so
178 * the programming will take effect on the first time around.
179 */
180 brw->pma_stall_bits = ~0;
181
182 /* Make sure that brw->ctx.NewDriverState has enough bits to hold all possible
183 * dirty flags.
184 */
185 STATIC_ASSERT(BRW_NUM_STATE_BITS <= 8 * sizeof(brw->ctx.NewDriverState));
186
187 ctx->DriverFlags.NewTransformFeedback = BRW_NEW_TRANSFORM_FEEDBACK;
188 ctx->DriverFlags.NewTransformFeedbackProg = BRW_NEW_TRANSFORM_FEEDBACK;
189 ctx->DriverFlags.NewRasterizerDiscard = BRW_NEW_RASTERIZER_DISCARD;
190 ctx->DriverFlags.NewUniformBuffer = BRW_NEW_UNIFORM_BUFFER;
191 ctx->DriverFlags.NewShaderStorageBuffer = BRW_NEW_UNIFORM_BUFFER;
192 ctx->DriverFlags.NewTextureBuffer = BRW_NEW_TEXTURE_BUFFER;
193 ctx->DriverFlags.NewAtomicBuffer = BRW_NEW_ATOMIC_BUFFER;
194 ctx->DriverFlags.NewImageUnits = BRW_NEW_IMAGE_UNITS;
195 ctx->DriverFlags.NewDefaultTessLevels = BRW_NEW_DEFAULT_TESS_LEVELS;
196 ctx->DriverFlags.NewIntelConservativeRasterization = BRW_NEW_CONSERVATIVE_RASTERIZATION;
197 }
198
199
200 void brw_destroy_state( struct brw_context *brw )
201 {
202 brw_destroy_caches(brw);
203 }
204
205 /***********************************************************************
206 */
207
208 static bool
209 check_state(const struct brw_state_flags *a, const struct brw_state_flags *b)
210 {
211 return ((a->mesa & b->mesa) | (a->brw & b->brw)) != 0;
212 }
213
214 static void accumulate_state( struct brw_state_flags *a,
215 const struct brw_state_flags *b )
216 {
217 a->mesa |= b->mesa;
218 a->brw |= b->brw;
219 }
220
221
222 static void xor_states( struct brw_state_flags *result,
223 const struct brw_state_flags *a,
224 const struct brw_state_flags *b )
225 {
226 result->mesa = a->mesa ^ b->mesa;
227 result->brw = a->brw ^ b->brw;
228 }
229
230 struct dirty_bit_map {
231 uint64_t bit;
232 char *name;
233 uint32_t count;
234 };
235
236 #define DEFINE_BIT(name) {name, #name, 0}
237
238 static struct dirty_bit_map mesa_bits[] = {
239 DEFINE_BIT(_NEW_MODELVIEW),
240 DEFINE_BIT(_NEW_PROJECTION),
241 DEFINE_BIT(_NEW_TEXTURE_MATRIX),
242 DEFINE_BIT(_NEW_COLOR),
243 DEFINE_BIT(_NEW_DEPTH),
244 DEFINE_BIT(_NEW_EVAL),
245 DEFINE_BIT(_NEW_FOG),
246 DEFINE_BIT(_NEW_HINT),
247 DEFINE_BIT(_NEW_LIGHT),
248 DEFINE_BIT(_NEW_LINE),
249 DEFINE_BIT(_NEW_PIXEL),
250 DEFINE_BIT(_NEW_POINT),
251 DEFINE_BIT(_NEW_POLYGON),
252 DEFINE_BIT(_NEW_POLYGONSTIPPLE),
253 DEFINE_BIT(_NEW_SCISSOR),
254 DEFINE_BIT(_NEW_STENCIL),
255 DEFINE_BIT(_NEW_TEXTURE_OBJECT),
256 DEFINE_BIT(_NEW_TRANSFORM),
257 DEFINE_BIT(_NEW_VIEWPORT),
258 DEFINE_BIT(_NEW_TEXTURE_STATE),
259 DEFINE_BIT(_NEW_ARRAY),
260 DEFINE_BIT(_NEW_RENDERMODE),
261 DEFINE_BIT(_NEW_BUFFERS),
262 DEFINE_BIT(_NEW_CURRENT_ATTRIB),
263 DEFINE_BIT(_NEW_MULTISAMPLE),
264 DEFINE_BIT(_NEW_TRACK_MATRIX),
265 DEFINE_BIT(_NEW_PROGRAM),
266 DEFINE_BIT(_NEW_PROGRAM_CONSTANTS),
267 DEFINE_BIT(_NEW_FRAG_CLAMP),
268 /* Avoid sign extension problems. */
269 {(unsigned) _NEW_VARYING_VP_INPUTS, "_NEW_VARYING_VP_INPUTS", 0},
270 {0, 0, 0}
271 };
272
273 static struct dirty_bit_map brw_bits[] = {
274 DEFINE_BIT(BRW_NEW_FS_PROG_DATA),
275 DEFINE_BIT(BRW_NEW_BLORP_BLIT_PROG_DATA),
276 DEFINE_BIT(BRW_NEW_SF_PROG_DATA),
277 DEFINE_BIT(BRW_NEW_VS_PROG_DATA),
278 DEFINE_BIT(BRW_NEW_FF_GS_PROG_DATA),
279 DEFINE_BIT(BRW_NEW_GS_PROG_DATA),
280 DEFINE_BIT(BRW_NEW_TCS_PROG_DATA),
281 DEFINE_BIT(BRW_NEW_TES_PROG_DATA),
282 DEFINE_BIT(BRW_NEW_CLIP_PROG_DATA),
283 DEFINE_BIT(BRW_NEW_CS_PROG_DATA),
284 DEFINE_BIT(BRW_NEW_URB_FENCE),
285 DEFINE_BIT(BRW_NEW_FRAGMENT_PROGRAM),
286 DEFINE_BIT(BRW_NEW_GEOMETRY_PROGRAM),
287 DEFINE_BIT(BRW_NEW_TESS_PROGRAMS),
288 DEFINE_BIT(BRW_NEW_VERTEX_PROGRAM),
289 DEFINE_BIT(BRW_NEW_REDUCED_PRIMITIVE),
290 DEFINE_BIT(BRW_NEW_PATCH_PRIMITIVE),
291 DEFINE_BIT(BRW_NEW_PRIMITIVE),
292 DEFINE_BIT(BRW_NEW_CONTEXT),
293 DEFINE_BIT(BRW_NEW_PSP),
294 DEFINE_BIT(BRW_NEW_SURFACES),
295 DEFINE_BIT(BRW_NEW_BINDING_TABLE_POINTERS),
296 DEFINE_BIT(BRW_NEW_INDICES),
297 DEFINE_BIT(BRW_NEW_VERTICES),
298 DEFINE_BIT(BRW_NEW_DEFAULT_TESS_LEVELS),
299 DEFINE_BIT(BRW_NEW_BATCH),
300 DEFINE_BIT(BRW_NEW_INDEX_BUFFER),
301 DEFINE_BIT(BRW_NEW_VS_CONSTBUF),
302 DEFINE_BIT(BRW_NEW_TCS_CONSTBUF),
303 DEFINE_BIT(BRW_NEW_TES_CONSTBUF),
304 DEFINE_BIT(BRW_NEW_GS_CONSTBUF),
305 DEFINE_BIT(BRW_NEW_PROGRAM_CACHE),
306 DEFINE_BIT(BRW_NEW_STATE_BASE_ADDRESS),
307 DEFINE_BIT(BRW_NEW_VUE_MAP_GEOM_OUT),
308 DEFINE_BIT(BRW_NEW_TRANSFORM_FEEDBACK),
309 DEFINE_BIT(BRW_NEW_RASTERIZER_DISCARD),
310 DEFINE_BIT(BRW_NEW_STATS_WM),
311 DEFINE_BIT(BRW_NEW_UNIFORM_BUFFER),
312 DEFINE_BIT(BRW_NEW_ATOMIC_BUFFER),
313 DEFINE_BIT(BRW_NEW_IMAGE_UNITS),
314 DEFINE_BIT(BRW_NEW_META_IN_PROGRESS),
315 DEFINE_BIT(BRW_NEW_PUSH_CONSTANT_ALLOCATION),
316 DEFINE_BIT(BRW_NEW_NUM_SAMPLES),
317 DEFINE_BIT(BRW_NEW_TEXTURE_BUFFER),
318 DEFINE_BIT(BRW_NEW_GEN4_UNIT_STATE),
319 DEFINE_BIT(BRW_NEW_CC_VP),
320 DEFINE_BIT(BRW_NEW_SF_VP),
321 DEFINE_BIT(BRW_NEW_CLIP_VP),
322 DEFINE_BIT(BRW_NEW_SAMPLER_STATE_TABLE),
323 DEFINE_BIT(BRW_NEW_VS_ATTRIB_WORKAROUNDS),
324 DEFINE_BIT(BRW_NEW_COMPUTE_PROGRAM),
325 DEFINE_BIT(BRW_NEW_CS_WORK_GROUPS),
326 DEFINE_BIT(BRW_NEW_URB_SIZE),
327 DEFINE_BIT(BRW_NEW_CC_STATE),
328 DEFINE_BIT(BRW_NEW_BLORP),
329 DEFINE_BIT(BRW_NEW_VIEWPORT_COUNT),
330 DEFINE_BIT(BRW_NEW_CONSERVATIVE_RASTERIZATION),
331 DEFINE_BIT(BRW_NEW_DRAW_CALL),
332 DEFINE_BIT(BRW_NEW_AUX_STATE),
333 {0, 0, 0}
334 };
335
336 static void
337 brw_update_dirty_count(struct dirty_bit_map *bit_map, uint64_t bits)
338 {
339 for (int i = 0; bit_map[i].bit != 0; i++) {
340 if (bit_map[i].bit & bits)
341 bit_map[i].count++;
342 }
343 }
344
345 static void
346 brw_print_dirty_count(struct dirty_bit_map *bit_map)
347 {
348 for (int i = 0; bit_map[i].bit != 0; i++) {
349 if (bit_map[i].count > 1) {
350 fprintf(stderr, "0x%016"PRIx64": %12d (%s)\n",
351 bit_map[i].bit, bit_map[i].count, bit_map[i].name);
352 }
353 }
354 }
355
356 static inline void
357 brw_upload_tess_programs(struct brw_context *brw)
358 {
359 if (brw->programs[MESA_SHADER_TESS_EVAL]) {
360 brw_upload_tcs_prog(brw);
361 brw_upload_tes_prog(brw);
362 } else {
363 brw->tcs.base.prog_data = NULL;
364 brw->tes.base.prog_data = NULL;
365 }
366 }
367
368 static inline void
369 brw_upload_programs(struct brw_context *brw,
370 enum brw_pipeline pipeline)
371 {
372 struct gl_context *ctx = &brw->ctx;
373 const struct gen_device_info *devinfo = &brw->screen->devinfo;
374
375 if (pipeline == BRW_RENDER_PIPELINE) {
376 brw_upload_vs_prog(brw);
377 brw_upload_tess_programs(brw);
378
379 if (brw->programs[MESA_SHADER_GEOMETRY]) {
380 brw_upload_gs_prog(brw);
381 } else {
382 brw->gs.base.prog_data = NULL;
383 if (devinfo->gen < 7)
384 brw_upload_ff_gs_prog(brw);
385 }
386
387 /* Update the VUE map for data exiting the GS stage of the pipeline.
388 * This comes from the last enabled shader stage.
389 */
390 GLbitfield64 old_slots = brw->vue_map_geom_out.slots_valid;
391 bool old_separate = brw->vue_map_geom_out.separate;
392 struct brw_vue_prog_data *vue_prog_data;
393 if (brw->programs[MESA_SHADER_GEOMETRY])
394 vue_prog_data = brw_vue_prog_data(brw->gs.base.prog_data);
395 else if (brw->programs[MESA_SHADER_TESS_EVAL])
396 vue_prog_data = brw_vue_prog_data(brw->tes.base.prog_data);
397 else
398 vue_prog_data = brw_vue_prog_data(brw->vs.base.prog_data);
399
400 brw->vue_map_geom_out = vue_prog_data->vue_map;
401
402 /* If the layout has changed, signal BRW_NEW_VUE_MAP_GEOM_OUT. */
403 if (old_slots != brw->vue_map_geom_out.slots_valid ||
404 old_separate != brw->vue_map_geom_out.separate)
405 brw->ctx.NewDriverState |= BRW_NEW_VUE_MAP_GEOM_OUT;
406
407 if ((old_slots ^ brw->vue_map_geom_out.slots_valid) &
408 VARYING_BIT_VIEWPORT) {
409 ctx->NewDriverState |= BRW_NEW_VIEWPORT_COUNT;
410 brw->clip.viewport_count =
411 (brw->vue_map_geom_out.slots_valid & VARYING_BIT_VIEWPORT) ?
412 ctx->Const.MaxViewports : 1;
413 }
414
415 brw_upload_wm_prog(brw);
416
417 if (devinfo->gen < 6) {
418 brw_upload_clip_prog(brw);
419 brw_upload_sf_prog(brw);
420 }
421 } else if (pipeline == BRW_COMPUTE_PIPELINE) {
422 brw_upload_cs_prog(brw);
423 }
424 }
425
426 static inline void
427 merge_ctx_state(struct brw_context *brw,
428 struct brw_state_flags *state)
429 {
430 state->mesa |= brw->NewGLState;
431 state->brw |= brw->ctx.NewDriverState;
432 }
433
434 static ALWAYS_INLINE void
435 check_and_emit_atom(struct brw_context *brw,
436 struct brw_state_flags *state,
437 const struct brw_tracked_state *atom)
438 {
439 if (check_state(state, &atom->dirty)) {
440 atom->emit(brw);
441 merge_ctx_state(brw, state);
442 }
443 }
444
445 static inline void
446 brw_upload_pipeline_state(struct brw_context *brw,
447 enum brw_pipeline pipeline)
448 {
449 const struct gen_device_info *devinfo = &brw->screen->devinfo;
450 struct gl_context *ctx = &brw->ctx;
451 int i;
452 static int dirty_count = 0;
453 struct brw_state_flags state = brw->state.pipelines[pipeline];
454 const unsigned fb_samples =
455 MAX2(_mesa_geometric_samples(ctx->DrawBuffer), 1);
456
457 brw_select_pipeline(brw, pipeline);
458
459 if (unlikely(INTEL_DEBUG & DEBUG_REEMIT)) {
460 /* Always re-emit all state. */
461 brw->NewGLState = ~0;
462 ctx->NewDriverState = ~0ull;
463 }
464
465 if (pipeline == BRW_RENDER_PIPELINE) {
466 if (brw->programs[MESA_SHADER_FRAGMENT] !=
467 ctx->FragmentProgram._Current) {
468 brw->programs[MESA_SHADER_FRAGMENT] = ctx->FragmentProgram._Current;
469 brw->ctx.NewDriverState |= BRW_NEW_FRAGMENT_PROGRAM;
470 }
471
472 if (brw->programs[MESA_SHADER_TESS_EVAL] !=
473 ctx->TessEvalProgram._Current) {
474 brw->programs[MESA_SHADER_TESS_EVAL] = ctx->TessEvalProgram._Current;
475 brw->ctx.NewDriverState |= BRW_NEW_TESS_PROGRAMS;
476 }
477
478 if (brw->programs[MESA_SHADER_TESS_CTRL] !=
479 ctx->TessCtrlProgram._Current) {
480 brw->programs[MESA_SHADER_TESS_CTRL] = ctx->TessCtrlProgram._Current;
481 brw->ctx.NewDriverState |= BRW_NEW_TESS_PROGRAMS;
482 }
483
484 if (brw->programs[MESA_SHADER_GEOMETRY] !=
485 ctx->GeometryProgram._Current) {
486 brw->programs[MESA_SHADER_GEOMETRY] = ctx->GeometryProgram._Current;
487 brw->ctx.NewDriverState |= BRW_NEW_GEOMETRY_PROGRAM;
488 }
489
490 if (brw->programs[MESA_SHADER_VERTEX] != ctx->VertexProgram._Current) {
491 brw->programs[MESA_SHADER_VERTEX] = ctx->VertexProgram._Current;
492 brw->ctx.NewDriverState |= BRW_NEW_VERTEX_PROGRAM;
493 }
494 }
495
496 if (brw->programs[MESA_SHADER_COMPUTE] != ctx->ComputeProgram._Current) {
497 brw->programs[MESA_SHADER_COMPUTE] = ctx->ComputeProgram._Current;
498 brw->ctx.NewDriverState |= BRW_NEW_COMPUTE_PROGRAM;
499 }
500
501 if (brw->meta_in_progress != _mesa_meta_in_progress(ctx)) {
502 brw->meta_in_progress = _mesa_meta_in_progress(ctx);
503 brw->ctx.NewDriverState |= BRW_NEW_META_IN_PROGRESS;
504 }
505
506 if (brw->num_samples != fb_samples) {
507 brw->num_samples = fb_samples;
508 brw->ctx.NewDriverState |= BRW_NEW_NUM_SAMPLES;
509 }
510
511 /* Exit early if no state is flagged as dirty */
512 merge_ctx_state(brw, &state);
513 if ((state.mesa | state.brw) == 0)
514 return;
515
516 /* Emit Sandybridge workaround flushes on every primitive, for safety. */
517 if (devinfo->gen == 6)
518 brw_emit_post_sync_nonzero_flush(brw);
519
520 brw_upload_programs(brw, pipeline);
521 merge_ctx_state(brw, &state);
522
523 brw_upload_state_base_address(brw);
524
525 const struct brw_tracked_state *atoms =
526 brw_get_pipeline_atoms(brw, pipeline);
527 const int num_atoms = brw->num_atoms[pipeline];
528
529 if (unlikely(INTEL_DEBUG)) {
530 /* Debug version which enforces various sanity checks on the
531 * state flags which are generated and checked to help ensure
532 * state atoms are ordered correctly in the list.
533 */
534 struct brw_state_flags examined, prev;
535 memset(&examined, 0, sizeof(examined));
536 prev = state;
537
538 for (i = 0; i < num_atoms; i++) {
539 const struct brw_tracked_state *atom = &atoms[i];
540 struct brw_state_flags generated;
541
542 check_and_emit_atom(brw, &state, atom);
543
544 accumulate_state(&examined, &atom->dirty);
545
546 /* generated = (prev ^ state)
547 * if (examined & generated)
548 * fail;
549 */
550 xor_states(&generated, &prev, &state);
551 assert(!check_state(&examined, &generated));
552 prev = state;
553 }
554 }
555 else {
556 for (i = 0; i < num_atoms; i++) {
557 const struct brw_tracked_state *atom = &atoms[i];
558
559 check_and_emit_atom(brw, &state, atom);
560 }
561 }
562
563 if (unlikely(INTEL_DEBUG & DEBUG_STATE)) {
564 STATIC_ASSERT(ARRAY_SIZE(brw_bits) == BRW_NUM_STATE_BITS + 1);
565
566 brw_update_dirty_count(mesa_bits, state.mesa);
567 brw_update_dirty_count(brw_bits, state.brw);
568 if (dirty_count++ % 1000 == 0) {
569 brw_print_dirty_count(mesa_bits);
570 brw_print_dirty_count(brw_bits);
571 fprintf(stderr, "\n");
572 }
573 }
574 }
575
576 /***********************************************************************
577 * Emit all state:
578 */
579 void brw_upload_render_state(struct brw_context *brw)
580 {
581 brw_upload_pipeline_state(brw, BRW_RENDER_PIPELINE);
582 }
583
584 static inline void
585 brw_pipeline_state_finished(struct brw_context *brw,
586 enum brw_pipeline pipeline)
587 {
588 /* Save all dirty state into the other pipelines */
589 for (unsigned i = 0; i < BRW_NUM_PIPELINES; i++) {
590 if (i != pipeline) {
591 brw->state.pipelines[i].mesa |= brw->NewGLState;
592 brw->state.pipelines[i].brw |= brw->ctx.NewDriverState;
593 } else {
594 memset(&brw->state.pipelines[i], 0, sizeof(struct brw_state_flags));
595 }
596 }
597
598 brw->NewGLState = 0;
599 brw->ctx.NewDriverState = 0ull;
600 }
601
602 /**
603 * Clear dirty bits to account for the fact that the state emitted by
604 * brw_upload_render_state() has been committed to the hardware. This is a
605 * separate call from brw_upload_render_state() because it's possible that
606 * after the call to brw_upload_render_state(), we will discover that we've
607 * run out of aperture space, and need to rewind the batch buffer to the state
608 * it had before the brw_upload_render_state() call.
609 */
610 void
611 brw_render_state_finished(struct brw_context *brw)
612 {
613 brw_pipeline_state_finished(brw, BRW_RENDER_PIPELINE);
614 }
615
616 void
617 brw_upload_compute_state(struct brw_context *brw)
618 {
619 brw_upload_pipeline_state(brw, BRW_COMPUTE_PIPELINE);
620 }
621
622 void
623 brw_compute_state_finished(struct brw_context *brw)
624 {
625 brw_pipeline_state_finished(brw, BRW_COMPUTE_PIPELINE);
626 }