i965: Use MESA_FORMAT_B8G8R8X8_SRGB for RGB visuals
[mesa.git] / src / mesa / drivers / dri / i965 / gen7_l3_state.c
1 /*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "brw_context.h"
25 #include "brw_defines.h"
26 #include "brw_state.h"
27 #include "intel_batchbuffer.h"
28
29 /**
30 * Chunk of L3 cache reserved for some specific purpose.
31 */
32 enum brw_l3_partition {
33 /** Shared local memory. */
34 L3P_SLM = 0,
35 /** Unified return buffer. */
36 L3P_URB,
37 /** Union of DC and RO. */
38 L3P_ALL,
39 /** Data cluster RW partition. */
40 L3P_DC,
41 /** Union of IS, C and T. */
42 L3P_RO,
43 /** Instruction and state cache. */
44 L3P_IS,
45 /** Constant cache. */
46 L3P_C,
47 /** Texture cache. */
48 L3P_T,
49 /** Number of supported L3 partitions. */
50 NUM_L3P
51 };
52
53 /**
54 * L3 configuration represented as the number of ways allocated for each
55 * partition. \sa get_l3_way_size().
56 */
57 struct brw_l3_config {
58 unsigned n[NUM_L3P];
59 };
60
61 /**
62 * IVB/HSW validated L3 configurations. The first entry will be used as
63 * default by gen7_restore_default_l3_config(), otherwise the ordering is
64 * unimportant.
65 */
66 static const struct brw_l3_config ivb_l3_configs[] = {
67 /* SLM URB ALL DC RO IS C T */
68 {{ 0, 32, 0, 0, 32, 0, 0, 0 }},
69 {{ 0, 32, 0, 16, 16, 0, 0, 0 }},
70 {{ 0, 32, 0, 4, 0, 8, 4, 16 }},
71 {{ 0, 28, 0, 8, 0, 8, 4, 16 }},
72 {{ 0, 28, 0, 16, 0, 8, 4, 8 }},
73 {{ 0, 28, 0, 8, 0, 16, 4, 8 }},
74 {{ 0, 28, 0, 0, 0, 16, 4, 16 }},
75 {{ 0, 32, 0, 0, 0, 16, 0, 16 }},
76 {{ 0, 28, 0, 4, 32, 0, 0, 0 }},
77 {{ 16, 16, 0, 16, 16, 0, 0, 0 }},
78 {{ 16, 16, 0, 8, 0, 8, 8, 8 }},
79 {{ 16, 16, 0, 4, 0, 8, 4, 16 }},
80 {{ 16, 16, 0, 4, 0, 16, 4, 8 }},
81 {{ 16, 16, 0, 0, 32, 0, 0, 0 }},
82 {{ 0 }}
83 };
84
85 /**
86 * VLV validated L3 configurations. \sa ivb_l3_configs.
87 */
88 static const struct brw_l3_config vlv_l3_configs[] = {
89 /* SLM URB ALL DC RO IS C T */
90 {{ 0, 64, 0, 0, 32, 0, 0, 0 }},
91 {{ 0, 80, 0, 0, 16, 0, 0, 0 }},
92 {{ 0, 80, 0, 8, 8, 0, 0, 0 }},
93 {{ 0, 64, 0, 16, 16, 0, 0, 0 }},
94 {{ 0, 60, 0, 4, 32, 0, 0, 0 }},
95 {{ 32, 32, 0, 16, 16, 0, 0, 0 }},
96 {{ 32, 40, 0, 8, 16, 0, 0, 0 }},
97 {{ 32, 40, 0, 16, 8, 0, 0, 0 }},
98 {{ 0 }}
99 };
100
101 /**
102 * BDW validated L3 configurations. \sa ivb_l3_configs.
103 */
104 static const struct brw_l3_config bdw_l3_configs[] = {
105 /* SLM URB ALL DC RO IS C T */
106 {{ 0, 48, 48, 0, 0, 0, 0, 0 }},
107 {{ 0, 48, 0, 16, 32, 0, 0, 0 }},
108 {{ 0, 32, 0, 16, 48, 0, 0, 0 }},
109 {{ 0, 32, 0, 0, 64, 0, 0, 0 }},
110 {{ 0, 32, 64, 0, 0, 0, 0, 0 }},
111 {{ 24, 16, 48, 0, 0, 0, 0, 0 }},
112 {{ 24, 16, 0, 16, 32, 0, 0, 0 }},
113 {{ 24, 16, 0, 32, 16, 0, 0, 0 }},
114 {{ 0 }}
115 };
116
117 /**
118 * CHV/SKL validated L3 configurations. \sa ivb_l3_configs.
119 */
120 static const struct brw_l3_config chv_l3_configs[] = {
121 /* SLM URB ALL DC RO IS C T */
122 {{ 0, 48, 48, 0, 0, 0, 0, 0 }},
123 {{ 0, 48, 0, 16, 32, 0, 0, 0 }},
124 {{ 0, 32, 0, 16, 48, 0, 0, 0 }},
125 {{ 0, 32, 0, 0, 64, 0, 0, 0 }},
126 {{ 0, 32, 64, 0, 0, 0, 0, 0 }},
127 {{ 32, 16, 48, 0, 0, 0, 0, 0 }},
128 {{ 32, 16, 0, 16, 32, 0, 0, 0 }},
129 {{ 32, 16, 0, 32, 16, 0, 0, 0 }},
130 {{ 0 }}
131 };
132
133 /**
134 * Return a zero-terminated array of validated L3 configurations for the
135 * specified device.
136 */
137 static const struct brw_l3_config *
138 get_l3_configs(const struct brw_device_info *devinfo)
139 {
140 switch (devinfo->gen) {
141 case 7:
142 return (devinfo->is_baytrail ? vlv_l3_configs : ivb_l3_configs);
143
144 case 8:
145 return (devinfo->is_cherryview ? chv_l3_configs : bdw_l3_configs);
146
147 case 9:
148 return chv_l3_configs;
149
150 default:
151 unreachable("Not implemented");
152 }
153 }
154
155 /**
156 * Return the size of an L3 way in KB.
157 */
158 static unsigned
159 get_l3_way_size(const struct brw_device_info *devinfo)
160 {
161 if (devinfo->is_baytrail)
162 return 2;
163
164 else if (devinfo->is_cherryview || devinfo->gt == 1)
165 return 4;
166
167 else
168 return 8 * devinfo->num_slices;
169 }
170
171 /**
172 * L3 configuration represented as a vector of weights giving the desired
173 * relative size of each partition. The scale is arbitrary, only the ratios
174 * between weights will have an influence on the selection of the closest L3
175 * configuration.
176 */
177 struct brw_l3_weights {
178 float w[NUM_L3P];
179 };
180
181 /**
182 * L1-normalize a vector of L3 partition weights.
183 */
184 static struct brw_l3_weights
185 norm_l3_weights(struct brw_l3_weights w)
186 {
187 float sz = 0;
188
189 for (unsigned i = 0; i < NUM_L3P; i++)
190 sz += w.w[i];
191
192 for (unsigned i = 0; i < NUM_L3P; i++)
193 w.w[i] /= sz;
194
195 return w;
196 }
197
198 /**
199 * Get the relative partition weights of the specified L3 configuration.
200 */
201 static struct brw_l3_weights
202 get_config_l3_weights(const struct brw_l3_config *cfg)
203 {
204 if (cfg) {
205 struct brw_l3_weights w;
206
207 for (unsigned i = 0; i < NUM_L3P; i++)
208 w.w[i] = cfg->n[i];
209
210 return norm_l3_weights(w);
211 } else {
212 const struct brw_l3_weights w = { { 0 } };
213 return w;
214 }
215 }
216
217 /**
218 * Distance between two L3 configurations represented as vectors of weights.
219 * Usually just the L1 metric except when the two configurations are
220 * considered incompatible in which case the distance will be infinite. Note
221 * that the compatibility condition is asymmetric -- They will be considered
222 * incompatible whenever the reference configuration \p w0 requires SLM, DC,
223 * or URB but \p w1 doesn't provide it.
224 */
225 static float
226 diff_l3_weights(struct brw_l3_weights w0, struct brw_l3_weights w1)
227 {
228 if ((w0.w[L3P_SLM] && !w1.w[L3P_SLM]) ||
229 (w0.w[L3P_DC] && !w1.w[L3P_DC] && !w1.w[L3P_ALL]) ||
230 (w0.w[L3P_URB] && !w1.w[L3P_URB])) {
231 return HUGE_VALF;
232
233 } else {
234 float dw = 0;
235
236 for (unsigned i = 0; i < NUM_L3P; i++)
237 dw += fabs(w0.w[i] - w1.w[i]);
238
239 return dw;
240 }
241 }
242
243 /**
244 * Return the closest validated L3 configuration for the specified device and
245 * weight vector.
246 */
247 static const struct brw_l3_config *
248 get_l3_config(const struct brw_device_info *devinfo, struct brw_l3_weights w0)
249 {
250 const struct brw_l3_config *const cfgs = get_l3_configs(devinfo);
251 const struct brw_l3_config *cfg_best = NULL;
252 float dw_best = HUGE_VALF;
253
254 for (const struct brw_l3_config *cfg = cfgs; cfg->n[L3P_URB]; cfg++) {
255 const float dw = diff_l3_weights(w0, get_config_l3_weights(cfg));
256
257 if (dw < dw_best) {
258 cfg_best = cfg;
259 dw_best = dw;
260 }
261 }
262
263 return cfg_best;
264 }
265
266 /**
267 * Return a reasonable default L3 configuration for the specified device based
268 * on whether SLM and DC are required. In the non-SLM non-DC case the result
269 * is intended to approximately resemble the hardware defaults.
270 */
271 static struct brw_l3_weights
272 get_default_l3_weights(const struct brw_device_info *devinfo,
273 bool needs_dc, bool needs_slm)
274 {
275 struct brw_l3_weights w = {{ 0 }};
276
277 w.w[L3P_SLM] = needs_slm;
278 w.w[L3P_URB] = 1.0;
279
280 if (devinfo->gen >= 8) {
281 w.w[L3P_ALL] = 1.0;
282 } else {
283 w.w[L3P_DC] = needs_dc ? 0.1 : 0;
284 w.w[L3P_RO] = devinfo->is_baytrail ? 0.5 : 1.0;
285 }
286
287 return norm_l3_weights(w);
288 }
289
290 /**
291 * Calculate the desired L3 partitioning based on the current state of the
292 * pipeline. For now this simply returns the conservative defaults calculated
293 * by get_default_l3_weights(), but we could probably do better by gathering
294 * more statistics from the pipeline state (e.g. guess of expected URB usage
295 * and bound surfaces), or by using feed-back from performance counters.
296 */
297 static struct brw_l3_weights
298 get_pipeline_state_l3_weights(const struct brw_context *brw)
299 {
300 const struct brw_stage_state *stage_states[] = {
301 &brw->vs.base, &brw->gs.base, &brw->wm.base, &brw->cs.base
302 };
303 bool needs_dc = false, needs_slm = false;
304
305 for (unsigned i = 0; i < ARRAY_SIZE(stage_states); i++) {
306 const struct gl_shader_program *prog =
307 brw->ctx._Shader->CurrentProgram[stage_states[i]->stage];
308 const struct brw_stage_prog_data *prog_data = stage_states[i]->prog_data;
309
310 needs_dc |= (prog && prog->NumAtomicBuffers) ||
311 (prog_data && (prog_data->total_scratch || prog_data->nr_image_params));
312 needs_slm |= prog_data && prog_data->total_shared;
313 }
314
315 return get_default_l3_weights(brw->intelScreen->devinfo,
316 needs_dc, needs_slm);
317 }
318
319 /**
320 * Program the hardware to use the specified L3 configuration.
321 */
322 static void
323 setup_l3_config(struct brw_context *brw, const struct brw_l3_config *cfg)
324 {
325 const bool has_dc = cfg->n[L3P_DC] || cfg->n[L3P_ALL];
326 const bool has_is = cfg->n[L3P_IS] || cfg->n[L3P_RO] || cfg->n[L3P_ALL];
327 const bool has_c = cfg->n[L3P_C] || cfg->n[L3P_RO] || cfg->n[L3P_ALL];
328 const bool has_t = cfg->n[L3P_T] || cfg->n[L3P_RO] || cfg->n[L3P_ALL];
329 const bool has_slm = cfg->n[L3P_SLM];
330
331 /* According to the hardware docs, the L3 partitioning can only be changed
332 * while the pipeline is completely drained and the caches are flushed,
333 * which involves a first PIPE_CONTROL flush which stalls the pipeline and
334 * initiates invalidation of the relevant caches...
335 */
336 brw_emit_pipe_control_flush(brw,
337 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE |
338 PIPE_CONTROL_CONST_CACHE_INVALIDATE |
339 PIPE_CONTROL_INSTRUCTION_INVALIDATE |
340 PIPE_CONTROL_DATA_CACHE_INVALIDATE |
341 PIPE_CONTROL_NO_WRITE |
342 PIPE_CONTROL_CS_STALL);
343
344 /* ...followed by a second stalling flush which guarantees that
345 * invalidation is complete when the L3 configuration registers are
346 * modified.
347 */
348 brw_emit_pipe_control_flush(brw,
349 PIPE_CONTROL_DATA_CACHE_INVALIDATE |
350 PIPE_CONTROL_NO_WRITE |
351 PIPE_CONTROL_CS_STALL);
352
353 if (brw->gen >= 8) {
354 assert(!cfg->n[L3P_IS] && !cfg->n[L3P_C] && !cfg->n[L3P_T]);
355
356 BEGIN_BATCH(3);
357 OUT_BATCH(MI_LOAD_REGISTER_IMM | (3 - 2));
358
359 /* Set up the L3 partitioning. */
360 OUT_BATCH(GEN8_L3CNTLREG);
361 OUT_BATCH((has_slm ? GEN8_L3CNTLREG_SLM_ENABLE : 0) |
362 SET_FIELD(cfg->n[L3P_URB], GEN8_L3CNTLREG_URB_ALLOC) |
363 SET_FIELD(cfg->n[L3P_RO], GEN8_L3CNTLREG_RO_ALLOC) |
364 SET_FIELD(cfg->n[L3P_DC], GEN8_L3CNTLREG_DC_ALLOC) |
365 SET_FIELD(cfg->n[L3P_ALL], GEN8_L3CNTLREG_ALL_ALLOC));
366
367 ADVANCE_BATCH();
368
369 } else {
370 assert(!cfg->n[L3P_ALL]);
371
372 /* When enabled SLM only uses a portion of the L3 on half of the banks,
373 * the matching space on the remaining banks has to be allocated to a
374 * client (URB for all validated configurations) set to the
375 * lower-bandwidth 2-bank address hashing mode.
376 */
377 const bool urb_low_bw = has_slm && !brw->is_baytrail;
378 assert(!urb_low_bw || cfg->n[L3P_URB] == cfg->n[L3P_SLM]);
379
380 /* Minimum number of ways that can be allocated to the URB. */
381 const unsigned n0_urb = (brw->is_baytrail ? 32 : 0);
382 assert(cfg->n[L3P_URB] >= n0_urb);
383
384 BEGIN_BATCH(7);
385 OUT_BATCH(MI_LOAD_REGISTER_IMM | (7 - 2));
386
387 /* Demote any clients with no ways assigned to LLC. */
388 OUT_BATCH(GEN7_L3SQCREG1);
389 OUT_BATCH((brw->is_haswell ? HSW_L3SQCREG1_SQGHPCI_DEFAULT :
390 brw->is_baytrail ? VLV_L3SQCREG1_SQGHPCI_DEFAULT :
391 IVB_L3SQCREG1_SQGHPCI_DEFAULT) |
392 (has_dc ? 0 : GEN7_L3SQCREG1_CONV_DC_UC) |
393 (has_is ? 0 : GEN7_L3SQCREG1_CONV_IS_UC) |
394 (has_c ? 0 : GEN7_L3SQCREG1_CONV_C_UC) |
395 (has_t ? 0 : GEN7_L3SQCREG1_CONV_T_UC));
396
397 /* Set up the L3 partitioning. */
398 OUT_BATCH(GEN7_L3CNTLREG2);
399 OUT_BATCH((has_slm ? GEN7_L3CNTLREG2_SLM_ENABLE : 0) |
400 SET_FIELD(cfg->n[L3P_URB] - n0_urb, GEN7_L3CNTLREG2_URB_ALLOC) |
401 (urb_low_bw ? GEN7_L3CNTLREG2_URB_LOW_BW : 0) |
402 SET_FIELD(cfg->n[L3P_ALL], GEN7_L3CNTLREG2_ALL_ALLOC) |
403 SET_FIELD(cfg->n[L3P_RO], GEN7_L3CNTLREG2_RO_ALLOC) |
404 SET_FIELD(cfg->n[L3P_DC], GEN7_L3CNTLREG2_DC_ALLOC));
405 OUT_BATCH(GEN7_L3CNTLREG3);
406 OUT_BATCH(SET_FIELD(cfg->n[L3P_IS], GEN7_L3CNTLREG3_IS_ALLOC) |
407 SET_FIELD(cfg->n[L3P_C], GEN7_L3CNTLREG3_C_ALLOC) |
408 SET_FIELD(cfg->n[L3P_T], GEN7_L3CNTLREG3_T_ALLOC));
409
410 ADVANCE_BATCH();
411
412 if (brw->is_haswell && brw->intelScreen->cmd_parser_version >= 4) {
413 /* Enable L3 atomics on HSW if we have a DC partition, otherwise keep
414 * them disabled to avoid crashing the system hard.
415 */
416 BEGIN_BATCH(5);
417 OUT_BATCH(MI_LOAD_REGISTER_IMM | (5 - 2));
418 OUT_BATCH(HSW_SCRATCH1);
419 OUT_BATCH(has_dc ? 0 : HSW_SCRATCH1_L3_ATOMIC_DISABLE);
420 OUT_BATCH(HSW_ROW_CHICKEN3);
421 OUT_BATCH(REG_MASK(HSW_ROW_CHICKEN3_L3_ATOMIC_DISABLE) |
422 (has_dc ? 0 : HSW_ROW_CHICKEN3_L3_ATOMIC_DISABLE));
423 ADVANCE_BATCH();
424 }
425 }
426 }
427
428 /**
429 * Return the unit brw_context::urb::size is expressed in, in KB. \sa
430 * brw_device_info::urb::size.
431 */
432 static unsigned
433 get_urb_size_scale(const struct brw_device_info *devinfo)
434 {
435 return (devinfo->gen >= 8 ? devinfo->num_slices : 1);
436 }
437
438 /**
439 * Update the URB size in the context state for the specified L3
440 * configuration.
441 */
442 static void
443 update_urb_size(struct brw_context *brw, const struct brw_l3_config *cfg)
444 {
445 const struct brw_device_info *devinfo = brw->intelScreen->devinfo;
446 /* From the SKL "L3 Allocation and Programming" documentation:
447 *
448 * "URB is limited to 1008KB due to programming restrictions. This is not
449 * a restriction of the L3 implementation, but of the FF and other clients.
450 * Therefore, in a GT4 implementation it is possible for the programmed
451 * allocation of the L3 data array to provide 3*384KB=1152KB for URB, but
452 * only 1008KB of this will be used."
453 */
454 const unsigned max = (devinfo->gen == 9 ? 1008 : ~0);
455 const unsigned sz =
456 MIN2(max, cfg->n[L3P_URB] * get_l3_way_size(devinfo)) /
457 get_urb_size_scale(devinfo);
458
459 if (brw->urb.size != sz) {
460 brw->urb.size = sz;
461 brw->ctx.NewDriverState |= BRW_NEW_URB_SIZE;
462 }
463 }
464
465 /**
466 * Print out the specified L3 configuration.
467 */
468 static void
469 dump_l3_config(const struct brw_l3_config *cfg)
470 {
471 fprintf(stderr, "SLM=%d URB=%d ALL=%d DC=%d RO=%d IS=%d C=%d T=%d\n",
472 cfg->n[L3P_SLM], cfg->n[L3P_URB], cfg->n[L3P_ALL],
473 cfg->n[L3P_DC], cfg->n[L3P_RO],
474 cfg->n[L3P_IS], cfg->n[L3P_C], cfg->n[L3P_T]);
475 }
476
477 static void
478 emit_l3_state(struct brw_context *brw)
479 {
480 const struct brw_l3_weights w = get_pipeline_state_l3_weights(brw);
481 const float dw = diff_l3_weights(w, get_config_l3_weights(brw->l3.config));
482 /* The distance between any two compatible weight vectors cannot exceed two
483 * due to the triangle inequality.
484 */
485 const float large_dw_threshold = 2.0;
486 /* Somewhat arbitrary, simply makes sure that there will be no repeated
487 * transitions to the same L3 configuration, could probably do better here.
488 */
489 const float small_dw_threshold = 0.5;
490 /* If we're emitting a new batch the caches should already be clean and the
491 * transition should be relatively cheap, so it shouldn't hurt much to use
492 * the smaller threshold. Otherwise use the larger threshold so that we
493 * only reprogram the L3 mid-batch if the most recently programmed
494 * configuration is incompatible with the current pipeline state.
495 */
496 const float dw_threshold = (brw->ctx.NewDriverState & BRW_NEW_BATCH ?
497 small_dw_threshold : large_dw_threshold);
498
499 if (dw > dw_threshold && brw->can_do_pipelined_register_writes) {
500 const struct brw_l3_config *const cfg =
501 get_l3_config(brw->intelScreen->devinfo, w);
502
503 setup_l3_config(brw, cfg);
504 update_urb_size(brw, cfg);
505 brw->l3.config = cfg;
506
507 if (unlikely(INTEL_DEBUG & DEBUG_L3)) {
508 fprintf(stderr, "L3 config transition (%f > %f): ", dw, dw_threshold);
509 dump_l3_config(cfg);
510 }
511 }
512 }
513
514 const struct brw_tracked_state gen7_l3_state = {
515 .dirty = {
516 .mesa = 0,
517 .brw = BRW_NEW_BATCH |
518 BRW_NEW_CS_PROG_DATA |
519 BRW_NEW_FS_PROG_DATA |
520 BRW_NEW_GS_PROG_DATA |
521 BRW_NEW_VS_PROG_DATA,
522 },
523 .emit = emit_l3_state
524 };
525
526 /**
527 * Hack to restore the default L3 configuration.
528 *
529 * This will be called at the end of every batch in order to reset the L3
530 * configuration to the default values for the time being until the kernel is
531 * fixed. Until kernel commit 6702cf16e0ba8b0129f5aa1b6609d4e9c70bc13b
532 * (included in v4.1) we would set the MI_RESTORE_INHIBIT bit when submitting
533 * batch buffers for the default context used by the DDX, which meant that any
534 * context state changed by the GL would leak into the DDX, the assumption
535 * being that the DDX would initialize any state it cares about manually. The
536 * DDX is however not careful enough to program an L3 configuration
537 * explicitly, and it makes assumptions about it (URB size) which won't hold
538 * and cause it to misrender if we let our L3 set-up to leak into the DDX.
539 *
540 * Since v4.1 of the Linux kernel the default context is saved and restored
541 * normally, so it's far less likely for our L3 programming to interfere with
542 * other contexts -- In fact restoring the default L3 configuration at the end
543 * of the batch will be redundant most of the time. A kind of state leak is
544 * still possible though if the context making assumptions about L3 state is
545 * created immediately after our context was active (e.g. without the DDX
546 * default context being scheduled in between) because at present the DRM
547 * doesn't fully initialize the contents of newly created contexts and instead
548 * sets the MI_RESTORE_INHIBIT flag causing it to inherit the state from the
549 * last active context.
550 *
551 * It's possible to realize such a scenario if, say, an X server (or a GL
552 * application using an outdated non-L3-aware Mesa version) is started while
553 * another GL application is running and happens to have modified the L3
554 * configuration, or if no X server is running at all and a GL application
555 * using a non-L3-aware Mesa version is started after another GL application
556 * ran and modified the L3 configuration -- The latter situation can actually
557 * be reproduced easily on IVB in our CI system.
558 */
559 void
560 gen7_restore_default_l3_config(struct brw_context *brw)
561 {
562 const struct brw_device_info *devinfo = brw->intelScreen->devinfo;
563 /* For efficiency assume that the first entry of the array matches the
564 * default configuration.
565 */
566 const struct brw_l3_config *const cfg = get_l3_configs(devinfo);
567 assert(cfg == get_l3_config(devinfo,
568 get_default_l3_weights(devinfo, false, false)));
569
570 if (cfg != brw->l3.config && brw->can_do_pipelined_register_writes) {
571 setup_l3_config(brw, cfg);
572 update_urb_size(brw, cfg);
573 brw->l3.config = cfg;
574 }
575 }