Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_clear.c
4565 views
1
/*
2
* Copyright © 2017 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 shall be included
12
* in all copies or substantial portions of the Software.
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
* DEALINGS IN THE SOFTWARE.
21
*/
22
23
#include <stdio.h>
24
#include <errno.h>
25
#include "pipe/p_defines.h"
26
#include "pipe/p_state.h"
27
#include "pipe/p_context.h"
28
#include "pipe/p_screen.h"
29
#include "util/u_inlines.h"
30
#include "util/format/u_format.h"
31
#include "util/u_upload_mgr.h"
32
#include "util/ralloc.h"
33
#include "iris_context.h"
34
#include "iris_resource.h"
35
#include "iris_screen.h"
36
#include "intel/compiler/brw_compiler.h"
37
38
static bool
39
iris_is_color_fast_clear_compatible(struct iris_context *ice,
40
enum isl_format format,
41
const union isl_color_value color)
42
{
43
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
44
const struct intel_device_info *devinfo = &batch->screen->devinfo;
45
46
if (isl_format_has_int_channel(format)) {
47
perf_debug(&ice->dbg, "Integer fast clear not enabled for %s\n",
48
isl_format_get_name(format));
49
return false;
50
}
51
52
for (int i = 0; i < 4; i++) {
53
if (!isl_format_has_color_component(format, i)) {
54
continue;
55
}
56
57
if (devinfo->ver < 9 &&
58
color.f32[i] != 0.0f && color.f32[i] != 1.0f) {
59
return false;
60
}
61
}
62
63
return true;
64
}
65
66
static bool
67
can_fast_clear_color(struct iris_context *ice,
68
struct pipe_resource *p_res,
69
unsigned level,
70
const struct pipe_box *box,
71
bool render_condition_enabled,
72
enum isl_format render_format,
73
union isl_color_value color)
74
{
75
struct iris_resource *res = (void *) p_res;
76
77
if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)
78
return false;
79
80
if (!isl_aux_usage_has_fast_clears(res->aux.usage))
81
return false;
82
83
/* Check for partial clear */
84
if (box->x > 0 || box->y > 0 ||
85
box->width < minify(p_res->width0, level) ||
86
box->height < minify(p_res->height0, level)) {
87
return false;
88
}
89
90
/* Avoid conditional fast clears to maintain correct tracking of the aux
91
* state (see iris_resource_finish_write for more info). Note that partial
92
* fast clears (if they existed) would not pose a problem with conditional
93
* rendering.
94
*/
95
if (render_condition_enabled &&
96
ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {
97
return false;
98
}
99
100
/* Disable sRGB fast-clears for non-0/1 color values. For texturing and
101
* draw calls, HW expects the clear color to be in two different color
102
* spaces after sRGB fast-clears - sRGB in the former and linear in the
103
* latter. By limiting the allowable values to 0/1, both color space
104
* requirements are satisfied.
105
*/
106
if (isl_format_is_srgb(render_format) &&
107
!isl_color_value_is_zero_one(color, render_format)) {
108
return false;
109
}
110
111
/* We store clear colors as floats or uints as needed. If there are
112
* texture views in play, the formats will not properly be respected
113
* during resolves because the resolve operations only know about the
114
* resource and not the renderbuffer.
115
*/
116
if (!iris_render_formats_color_compatible(render_format, res->surf.format,
117
color)) {
118
return false;
119
}
120
121
if (!iris_is_color_fast_clear_compatible(ice, res->surf.format, color))
122
return false;
123
124
/* The RENDER_SURFACE_STATE page for TGL says:
125
*
126
* For an 8 bpp surface with NUM_MULTISAMPLES = 1, Surface Width not
127
* multiple of 64 pixels and more than 1 mip level in the view, Fast Clear
128
* is not supported when AUX_CCS_E is set in this field.
129
*
130
* The granularity of a fast-clear is one CCS element. For an 8 bpp primary
131
* surface, this maps to 32px x 4rows. Due to the surface layout parameters,
132
* if LOD0's width isn't a multiple of 64px, LOD1 and LOD2+ will share CCS
133
* elements. Assuming LOD2 exists, don't fast-clear any level above LOD0
134
* to avoid stomping on other LODs.
135
*/
136
if (level > 0 && util_format_get_blocksizebits(p_res->format) == 8 &&
137
res->aux.usage == ISL_AUX_USAGE_GFX12_CCS_E && p_res->width0 % 64) {
138
return false;
139
}
140
141
return true;
142
}
143
144
static union isl_color_value
145
convert_clear_color(enum pipe_format format,
146
const union pipe_color_union *color)
147
{
148
/* pipe_color_union and isl_color_value are interchangeable */
149
union isl_color_value override_color = *(union isl_color_value *)color;
150
151
const struct util_format_description *desc =
152
util_format_description(format);
153
unsigned colormask = util_format_colormask(desc);
154
155
if (util_format_is_intensity(format) ||
156
util_format_is_luminance(format)) {
157
override_color.u32[1] = override_color.u32[0];
158
override_color.u32[2] = override_color.u32[0];
159
if (util_format_is_intensity(format))
160
override_color.u32[3] = override_color.u32[0];
161
} else {
162
for (int chan = 0; chan < 3; chan++) {
163
if (!(colormask & (1 << chan)))
164
override_color.u32[chan] = 0;
165
}
166
}
167
168
if (util_format_is_unorm(format)) {
169
for (int i = 0; i < 4; i++)
170
override_color.f32[i] = SATURATE(override_color.f32[i]);
171
} else if (util_format_is_snorm(format)) {
172
for (int i = 0; i < 4; i++)
173
override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f);
174
} else if (util_format_is_pure_uint(format)) {
175
for (int i = 0; i < 4; i++) {
176
unsigned bits = util_format_get_component_bits(
177
format, UTIL_FORMAT_COLORSPACE_RGB, i);
178
if (bits < 32) {
179
uint32_t max = (1u << bits) - 1;
180
override_color.u32[i] = MIN2(override_color.u32[i], max);
181
}
182
}
183
} else if (util_format_is_pure_sint(format)) {
184
for (int i = 0; i < 4; i++) {
185
unsigned bits = util_format_get_component_bits(
186
format, UTIL_FORMAT_COLORSPACE_RGB, i);
187
if (bits > 0 && bits < 32) {
188
int32_t max = (1 << (bits - 1)) - 1;
189
int32_t min = -(1 << (bits - 1));
190
override_color.i32[i] = CLAMP(override_color.i32[i], min, max);
191
}
192
}
193
} else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||
194
format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
195
/* these packed float formats only store unsigned values */
196
for (int i = 0; i < 4; i++)
197
override_color.f32[i] = MAX2(override_color.f32[i], 0.0f);
198
}
199
200
if (!(colormask & 1 << 3)) {
201
if (util_format_is_pure_integer(format))
202
override_color.u32[3] = 1;
203
else
204
override_color.f32[3] = 1.0f;
205
}
206
207
return override_color;
208
}
209
210
static void
211
fast_clear_color(struct iris_context *ice,
212
struct iris_resource *res,
213
unsigned level,
214
const struct pipe_box *box,
215
enum isl_format format,
216
union isl_color_value color)
217
{
218
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
219
struct pipe_resource *p_res = (void *) res;
220
221
bool color_changed = !!memcmp(&res->aux.clear_color, &color,
222
sizeof(color));
223
224
if (color_changed) {
225
/* If we are clearing to a new clear value, we need to resolve fast
226
* clears from other levels/layers first, since we can't have different
227
* levels/layers with different fast clear colors.
228
*/
229
for (unsigned res_lvl = 0; res_lvl < res->surf.levels; res_lvl++) {
230
const unsigned level_layers =
231
iris_get_num_logical_layers(res, res_lvl);
232
for (unsigned layer = 0; layer < level_layers; layer++) {
233
if (res_lvl == level &&
234
layer >= box->z &&
235
layer < box->z + box->depth) {
236
/* We're going to clear this layer anyway. Leave it alone. */
237
continue;
238
}
239
240
enum isl_aux_state aux_state =
241
iris_resource_get_aux_state(res, res_lvl, layer);
242
243
if (aux_state != ISL_AUX_STATE_CLEAR &&
244
aux_state != ISL_AUX_STATE_PARTIAL_CLEAR &&
245
aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
246
/* This slice doesn't have any fast-cleared bits. */
247
continue;
248
}
249
250
/* If we got here, then the level may have fast-clear bits that use
251
* the old clear value. We need to do a color resolve to get rid
252
* of their use of the clear color before we can change it.
253
* Fortunately, few applications ever change their clear color at
254
* different levels/layers, so this shouldn't happen often.
255
*/
256
iris_resource_prepare_access(ice, res,
257
res_lvl, 1, layer, 1,
258
res->aux.usage,
259
false);
260
perf_debug(&ice->dbg,
261
"Resolving resource (%p) level %d, layer %d: color changing from "
262
"(%0.2f, %0.2f, %0.2f, %0.2f) to "
263
"(%0.2f, %0.2f, %0.2f, %0.2f)\n",
264
res, res_lvl, layer,
265
res->aux.clear_color.f32[0],
266
res->aux.clear_color.f32[1],
267
res->aux.clear_color.f32[2],
268
res->aux.clear_color.f32[3],
269
color.f32[0], color.f32[1], color.f32[2], color.f32[3]);
270
}
271
}
272
}
273
274
iris_resource_set_clear_color(ice, res, color);
275
276
/* If the buffer is already in ISL_AUX_STATE_CLEAR, and the color hasn't
277
* changed, the clear is redundant and can be skipped.
278
*/
279
const enum isl_aux_state aux_state =
280
iris_resource_get_aux_state(res, level, box->z);
281
if (!color_changed && box->depth == 1 && aux_state == ISL_AUX_STATE_CLEAR)
282
return;
283
284
/* Ivybridge PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":
285
*
286
* "Any transition from any value in {Clear, Render, Resolve} to a
287
* different value in {Clear, Render, Resolve} requires end of pipe
288
* synchronization."
289
*
290
* In other words, fast clear ops are not properly synchronized with
291
* other drawing. We need to use a PIPE_CONTROL to ensure that the
292
* contents of the previous draw hit the render target before we resolve
293
* and again afterwards to ensure that the resolve is complete before we
294
* do any more regular drawing.
295
*/
296
iris_emit_end_of_pipe_sync(batch,
297
"fast clear: pre-flush",
298
PIPE_CONTROL_RENDER_TARGET_FLUSH |
299
PIPE_CONTROL_TILE_CACHE_FLUSH);
300
301
iris_batch_sync_region_start(batch);
302
303
/* If we reach this point, we need to fast clear to change the state to
304
* ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both).
305
*/
306
enum blorp_batch_flags blorp_flags = 0;
307
blorp_flags |= color_changed ? 0 : BLORP_BATCH_NO_UPDATE_CLEAR_COLOR;
308
309
struct blorp_batch blorp_batch;
310
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
311
312
struct blorp_surf surf;
313
iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,
314
p_res, res->aux.usage, level, true);
315
316
blorp_fast_clear(&blorp_batch, &surf, format, ISL_SWIZZLE_IDENTITY,
317
level, box->z, box->depth,
318
box->x, box->y, box->x + box->width,
319
box->y + box->height);
320
blorp_batch_finish(&blorp_batch);
321
iris_emit_end_of_pipe_sync(batch,
322
"fast clear: post flush",
323
PIPE_CONTROL_RENDER_TARGET_FLUSH);
324
iris_batch_sync_region_end(batch);
325
326
iris_resource_set_aux_state(ice, res, level, box->z,
327
box->depth, ISL_AUX_STATE_CLEAR);
328
ice->state.dirty |= IRIS_DIRTY_RENDER_BUFFER;
329
ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;
330
return;
331
}
332
333
static void
334
clear_color(struct iris_context *ice,
335
struct pipe_resource *p_res,
336
unsigned level,
337
const struct pipe_box *box,
338
bool render_condition_enabled,
339
enum isl_format format,
340
struct isl_swizzle swizzle,
341
union isl_color_value color)
342
{
343
struct iris_resource *res = (void *) p_res;
344
345
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
346
const struct intel_device_info *devinfo = &batch->screen->devinfo;
347
enum blorp_batch_flags blorp_flags = 0;
348
349
if (render_condition_enabled) {
350
if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)
351
return;
352
353
if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)
354
blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
355
}
356
357
if (p_res->target == PIPE_BUFFER)
358
util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);
359
360
iris_batch_maybe_flush(batch, 1500);
361
362
bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box,
363
render_condition_enabled,
364
format, color);
365
if (can_fast_clear) {
366
fast_clear_color(ice, res, level, box, format, color);
367
return;
368
}
369
370
bool color_write_disable[4] = { false, false, false, false };
371
enum isl_aux_usage aux_usage =
372
iris_resource_render_aux_usage(ice, res, level, format, false);
373
374
iris_resource_prepare_render(ice, res, level, box->z, box->depth,
375
aux_usage);
376
iris_emit_buffer_barrier_for(batch, res->bo, IRIS_DOMAIN_RENDER_WRITE);
377
378
struct blorp_surf surf;
379
iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,
380
p_res, aux_usage, level, true);
381
382
iris_batch_sync_region_start(batch);
383
384
struct blorp_batch blorp_batch;
385
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
386
387
if (!isl_format_supports_rendering(devinfo, format) &&
388
isl_format_is_rgbx(format))
389
format = isl_format_rgbx_to_rgba(format);
390
391
blorp_clear(&blorp_batch, &surf, format, swizzle,
392
level, box->z, box->depth, box->x, box->y,
393
box->x + box->width, box->y + box->height,
394
color, color_write_disable);
395
396
blorp_batch_finish(&blorp_batch);
397
iris_batch_sync_region_end(batch);
398
399
iris_flush_and_dirty_for_history(ice, batch, res,
400
PIPE_CONTROL_RENDER_TARGET_FLUSH,
401
"cache history: post color clear");
402
403
iris_resource_finish_render(ice, res, level,
404
box->z, box->depth, aux_usage);
405
}
406
407
static bool
408
can_fast_clear_depth(struct iris_context *ice,
409
struct iris_resource *res,
410
unsigned level,
411
const struct pipe_box *box,
412
bool render_condition_enabled,
413
float depth)
414
{
415
struct pipe_resource *p_res = (void *) res;
416
struct pipe_context *ctx = (void *) ice;
417
struct iris_screen *screen = (void *) ctx->screen;
418
const struct intel_device_info *devinfo = &screen->devinfo;
419
420
if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)
421
return false;
422
423
/* Check for partial clears */
424
if (box->x > 0 || box->y > 0 ||
425
box->width < u_minify(p_res->width0, level) ||
426
box->height < u_minify(p_res->height0, level)) {
427
return false;
428
}
429
430
/* Avoid conditional fast clears to maintain correct tracking of the aux
431
* state (see iris_resource_finish_write for more info). Note that partial
432
* fast clears would not pose a problem with conditional rendering.
433
*/
434
if (render_condition_enabled &&
435
ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {
436
return false;
437
}
438
439
if (!iris_resource_level_has_hiz(res, level))
440
return false;
441
442
if (!blorp_can_hiz_clear_depth(devinfo, &res->surf, res->aux.usage,
443
level, box->z, box->x, box->y,
444
box->x + box->width,
445
box->y + box->height)) {
446
return false;
447
}
448
449
return true;
450
}
451
452
static void
453
fast_clear_depth(struct iris_context *ice,
454
struct iris_resource *res,
455
unsigned level,
456
const struct pipe_box *box,
457
float depth)
458
{
459
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
460
461
bool update_clear_depth = false;
462
463
/* If we're clearing to a new clear value, then we need to resolve any clear
464
* flags out of the HiZ buffer into the real depth buffer.
465
*/
466
if (res->aux.clear_color.f32[0] != depth) {
467
for (unsigned res_level = 0; res_level < res->surf.levels; res_level++) {
468
const unsigned level_layers =
469
iris_get_num_logical_layers(res, res_level);
470
for (unsigned layer = 0; layer < level_layers; layer++) {
471
if (res_level == level &&
472
layer >= box->z &&
473
layer < box->z + box->depth) {
474
/* We're going to clear this layer anyway. Leave it alone. */
475
continue;
476
}
477
478
enum isl_aux_state aux_state =
479
iris_resource_get_aux_state(res, res_level, layer);
480
481
if (aux_state != ISL_AUX_STATE_CLEAR &&
482
aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
483
/* This slice doesn't have any fast-cleared bits. */
484
continue;
485
}
486
487
/* If we got here, then the level may have fast-clear bits that
488
* use the old clear value. We need to do a depth resolve to get
489
* rid of their use of the clear value before we can change it.
490
* Fortunately, few applications ever change their depth clear
491
* value so this shouldn't happen often.
492
*/
493
iris_hiz_exec(ice, batch, res, res_level, layer, 1,
494
ISL_AUX_OP_FULL_RESOLVE, false);
495
iris_resource_set_aux_state(ice, res, res_level, layer, 1,
496
ISL_AUX_STATE_RESOLVED);
497
iris_emit_pipe_control_flush(batch, "hiz op: post depth resolve",
498
PIPE_CONTROL_TILE_CACHE_FLUSH);
499
}
500
}
501
const union isl_color_value clear_value = { .f32 = {depth, } };
502
iris_resource_set_clear_color(ice, res, clear_value);
503
update_clear_depth = true;
504
}
505
506
for (unsigned l = 0; l < box->depth; l++) {
507
enum isl_aux_state aux_state =
508
iris_resource_get_aux_state(res, level, box->z + l);
509
if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) {
510
if (aux_state == ISL_AUX_STATE_CLEAR) {
511
perf_debug(&ice->dbg, "Performing HiZ clear just to update the "
512
"depth clear value\n");
513
}
514
iris_hiz_exec(ice, batch, res, level,
515
box->z + l, 1, ISL_AUX_OP_FAST_CLEAR,
516
update_clear_depth);
517
}
518
}
519
520
iris_resource_set_aux_state(ice, res, level, box->z, box->depth,
521
ISL_AUX_STATE_CLEAR);
522
ice->state.dirty |= IRIS_DIRTY_DEPTH_BUFFER;
523
ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;
524
}
525
526
static void
527
clear_depth_stencil(struct iris_context *ice,
528
struct pipe_resource *p_res,
529
unsigned level,
530
const struct pipe_box *box,
531
bool render_condition_enabled,
532
bool clear_depth,
533
bool clear_stencil,
534
float depth,
535
uint8_t stencil)
536
{
537
struct iris_resource *res = (void *) p_res;
538
539
struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
540
enum blorp_batch_flags blorp_flags = 0;
541
542
if (render_condition_enabled) {
543
if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)
544
return;
545
546
if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)
547
blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
548
}
549
550
iris_batch_maybe_flush(batch, 1500);
551
552
struct iris_resource *z_res;
553
struct iris_resource *stencil_res;
554
struct blorp_surf z_surf;
555
struct blorp_surf stencil_surf;
556
557
iris_get_depth_stencil_resources(p_res, &z_res, &stencil_res);
558
if (z_res && clear_depth &&
559
can_fast_clear_depth(ice, z_res, level, box, render_condition_enabled,
560
depth)) {
561
fast_clear_depth(ice, z_res, level, box, depth);
562
iris_flush_and_dirty_for_history(ice, batch, res, 0,
563
"cache history: post fast Z clear");
564
clear_depth = false;
565
z_res = false;
566
}
567
568
/* At this point, we might have fast cleared the depth buffer. So if there's
569
* no stencil clear pending, return early.
570
*/
571
if (!(clear_depth || (clear_stencil && stencil_res))) {
572
return;
573
}
574
575
if (clear_depth && z_res) {
576
const enum isl_aux_usage aux_usage =
577
iris_resource_render_aux_usage(ice, z_res, level, z_res->surf.format,
578
false);
579
iris_resource_prepare_render(ice, z_res, level, box->z, box->depth,
580
aux_usage);
581
iris_emit_buffer_barrier_for(batch, z_res->bo, IRIS_DOMAIN_DEPTH_WRITE);
582
iris_blorp_surf_for_resource(&batch->screen->isl_dev, &z_surf,
583
&z_res->base.b, aux_usage, level, true);
584
}
585
586
uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0;
587
if (stencil_mask) {
588
iris_resource_prepare_access(ice, stencil_res, level, 1, box->z,
589
box->depth, stencil_res->aux.usage, false);
590
iris_emit_buffer_barrier_for(batch, stencil_res->bo,
591
IRIS_DOMAIN_DEPTH_WRITE);
592
iris_blorp_surf_for_resource(&batch->screen->isl_dev,
593
&stencil_surf, &stencil_res->base.b,
594
stencil_res->aux.usage, level, true);
595
}
596
597
iris_batch_sync_region_start(batch);
598
599
struct blorp_batch blorp_batch;
600
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
601
602
blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf,
603
level, box->z, box->depth,
604
box->x, box->y,
605
box->x + box->width,
606
box->y + box->height,
607
clear_depth && z_res, depth,
608
stencil_mask, stencil);
609
610
blorp_batch_finish(&blorp_batch);
611
iris_batch_sync_region_end(batch);
612
613
iris_flush_and_dirty_for_history(ice, batch, res,
614
PIPE_CONTROL_TILE_CACHE_FLUSH,
615
"cache history: post slow ZS clear");
616
617
if (clear_depth && z_res) {
618
iris_resource_finish_render(ice, z_res, level, box->z, box->depth,
619
z_surf.aux_usage);
620
}
621
622
if (stencil_mask) {
623
iris_resource_finish_write(ice, stencil_res, level, box->z, box->depth,
624
stencil_res->aux.usage);
625
}
626
}
627
628
/**
629
* The pipe->clear() driver hook.
630
*
631
* This clears buffers attached to the current draw framebuffer.
632
*/
633
static void
634
iris_clear(struct pipe_context *ctx,
635
unsigned buffers,
636
const struct pipe_scissor_state *scissor_state,
637
const union pipe_color_union *p_color,
638
double depth,
639
unsigned stencil)
640
{
641
struct iris_context *ice = (void *) ctx;
642
struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;
643
644
assert(buffers != 0);
645
646
struct pipe_box box = {
647
.width = cso_fb->width,
648
.height = cso_fb->height,
649
};
650
651
if (scissor_state) {
652
box.x = scissor_state->minx;
653
box.y = scissor_state->miny;
654
box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx);
655
box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny);
656
}
657
658
if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
659
struct pipe_surface *psurf = cso_fb->zsbuf;
660
661
box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;
662
box.z = psurf->u.tex.first_layer,
663
clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true,
664
buffers & PIPE_CLEAR_DEPTH,
665
buffers & PIPE_CLEAR_STENCIL,
666
depth, stencil);
667
}
668
669
if (buffers & PIPE_CLEAR_COLOR) {
670
for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {
671
if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
672
struct pipe_surface *psurf = cso_fb->cbufs[i];
673
struct iris_surface *isurf = (void *) psurf;
674
box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,
675
box.z = psurf->u.tex.first_layer,
676
677
clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
678
true, isurf->view.format, isurf->view.swizzle,
679
convert_clear_color(psurf->format, p_color));
680
}
681
}
682
}
683
}
684
685
/**
686
* The pipe->clear_texture() driver hook.
687
*
688
* This clears the given texture resource.
689
*/
690
static void
691
iris_clear_texture(struct pipe_context *ctx,
692
struct pipe_resource *p_res,
693
unsigned level,
694
const struct pipe_box *box,
695
const void *data)
696
{
697
struct iris_context *ice = (void *) ctx;
698
struct iris_screen *screen = (void *) ctx->screen;
699
struct iris_resource *res = (void *) p_res;
700
const struct intel_device_info *devinfo = &screen->devinfo;
701
702
if (iris_resource_unfinished_aux_import(res))
703
iris_resource_finish_aux_import(ctx->screen, res);
704
705
if (util_format_is_depth_or_stencil(p_res->format)) {
706
const struct util_format_unpack_description *unpack =
707
util_format_unpack_description(p_res->format);
708
709
float depth = 0.0;
710
uint8_t stencil = 0;
711
712
if (unpack->unpack_z_float)
713
util_format_unpack_z_float(p_res->format, &depth, data, 1);
714
715
if (unpack->unpack_s_8uint)
716
util_format_unpack_s_8uint(p_res->format, &stencil, data, 1);
717
718
clear_depth_stencil(ice, p_res, level, box, true, true, true,
719
depth, stencil);
720
} else {
721
union isl_color_value color;
722
struct iris_resource *res = (void *) p_res;
723
enum isl_format format = res->surf.format;
724
725
if (!isl_format_supports_rendering(devinfo, format)) {
726
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
727
// XXX: actually just get_copy_format_for_bpb from BLORP
728
// XXX: don't cut and paste this
729
switch (fmtl->bpb) {
730
case 8: format = ISL_FORMAT_R8_UINT; break;
731
case 16: format = ISL_FORMAT_R8G8_UINT; break;
732
case 24: format = ISL_FORMAT_R8G8B8_UINT; break;
733
case 32: format = ISL_FORMAT_R8G8B8A8_UINT; break;
734
case 48: format = ISL_FORMAT_R16G16B16_UINT; break;
735
case 64: format = ISL_FORMAT_R16G16B16A16_UINT; break;
736
case 96: format = ISL_FORMAT_R32G32B32_UINT; break;
737
case 128: format = ISL_FORMAT_R32G32B32A32_UINT; break;
738
default:
739
unreachable("Unknown format bpb");
740
}
741
742
/* No aux surfaces for non-renderable surfaces */
743
assert(res->aux.usage == ISL_AUX_USAGE_NONE);
744
}
745
746
isl_color_value_unpack(&color, format, data);
747
748
clear_color(ice, p_res, level, box, true, format,
749
ISL_SWIZZLE_IDENTITY, color);
750
}
751
}
752
753
/**
754
* The pipe->clear_render_target() driver hook.
755
*
756
* This clears the given render target surface.
757
*/
758
static void
759
iris_clear_render_target(struct pipe_context *ctx,
760
struct pipe_surface *psurf,
761
const union pipe_color_union *p_color,
762
unsigned dst_x, unsigned dst_y,
763
unsigned width, unsigned height,
764
bool render_condition_enabled)
765
{
766
struct iris_context *ice = (void *) ctx;
767
struct iris_surface *isurf = (void *) psurf;
768
struct pipe_box box = {
769
.x = dst_x,
770
.y = dst_y,
771
.z = psurf->u.tex.first_layer,
772
.width = width,
773
.height = height,
774
.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
775
};
776
777
clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
778
render_condition_enabled,
779
isurf->view.format, isurf->view.swizzle,
780
convert_clear_color(psurf->format, p_color));
781
}
782
783
/**
784
* The pipe->clear_depth_stencil() driver hook.
785
*
786
* This clears the given depth/stencil surface.
787
*/
788
static void
789
iris_clear_depth_stencil(struct pipe_context *ctx,
790
struct pipe_surface *psurf,
791
unsigned flags,
792
double depth,
793
unsigned stencil,
794
unsigned dst_x, unsigned dst_y,
795
unsigned width, unsigned height,
796
bool render_condition_enabled)
797
{
798
struct iris_context *ice = (void *) ctx;
799
struct pipe_box box = {
800
.x = dst_x,
801
.y = dst_y,
802
.z = psurf->u.tex.first_layer,
803
.width = width,
804
.height = height,
805
.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
806
};
807
808
assert(util_format_is_depth_or_stencil(psurf->texture->format));
809
810
clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box,
811
render_condition_enabled,
812
flags & PIPE_CLEAR_DEPTH, flags & PIPE_CLEAR_STENCIL,
813
depth, stencil);
814
}
815
816
void
817
iris_init_clear_functions(struct pipe_context *ctx)
818
{
819
ctx->clear = iris_clear;
820
ctx->clear_texture = iris_clear_texture;
821
ctx->clear_render_target = iris_clear_render_target;
822
ctx->clear_depth_stencil = iris_clear_depth_stencil;
823
}
824
825