Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_clear.c
4570 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/u_surface.h"
31
#include "util/format/u_format.h"
32
#include "util/u_upload_mgr.h"
33
#include "util/ralloc.h"
34
#include "crocus_context.h"
35
#include "crocus_resource.h"
36
#include "crocus_screen.h"
37
#include "intel/compiler/brw_compiler.h"
38
#include "util/format_srgb.h"
39
40
static bool
41
crocus_is_color_fast_clear_compatible(struct crocus_context *ice,
42
enum isl_format format,
43
const union isl_color_value color)
44
{
45
if (isl_format_has_int_channel(format)) {
46
perf_debug(&ice->dbg, "Integer fast clear not enabled for %s",
47
isl_format_get_name(format));
48
return false;
49
}
50
51
for (int i = 0; i < 4; i++) {
52
if (!isl_format_has_color_component(format, i)) {
53
continue;
54
}
55
56
if (color.f32[i] != 0.0f && color.f32[i] != 1.0f) {
57
return false;
58
}
59
}
60
61
return true;
62
}
63
64
static bool
65
can_fast_clear_color(struct crocus_context *ice,
66
struct pipe_resource *p_res,
67
unsigned level,
68
const struct pipe_box *box,
69
bool render_condition_enabled,
70
enum isl_format format,
71
enum isl_format render_format,
72
union isl_color_value color)
73
{
74
struct crocus_resource *res = (void *) p_res;
75
76
if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)
77
return false;
78
79
if (!isl_aux_usage_has_fast_clears(res->aux.usage))
80
return false;
81
82
/* Check for partial clear */
83
if (box->x > 0 || box->y > 0 ||
84
box->width < minify(p_res->width0, level) ||
85
box->height < minify(p_res->height0, level)) {
86
return false;
87
}
88
89
/* Avoid conditional fast clears to maintain correct tracking of the aux
90
* state (see iris_resource_finish_write for more info). Note that partial
91
* fast clears (if they existed) would not pose a problem with conditional
92
* rendering.
93
*/
94
if (render_condition_enabled &&
95
ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT) {
96
return false;
97
}
98
99
/* We store clear colors as floats or uints as needed. If there are
100
* texture views in play, the formats will not properly be respected
101
* during resolves because the resolve operations only know about the
102
* resource and not the renderbuffer.
103
*/
104
if (isl_format_srgb_to_linear(render_format) !=
105
isl_format_srgb_to_linear(format)) {
106
return false;
107
}
108
109
/* XXX: if (irb->mt->supports_fast_clear)
110
* see intel_miptree_create_for_dri_image()
111
*/
112
113
if (!crocus_is_color_fast_clear_compatible(ice, format, color))
114
return false;
115
116
return true;
117
}
118
119
static union isl_color_value
120
convert_fast_clear_color(struct crocus_context *ice,
121
struct crocus_resource *res,
122
enum isl_format render_format,
123
const union isl_color_value color)
124
{
125
union isl_color_value override_color = color;
126
struct pipe_resource *p_res = (void *) res;
127
128
const enum pipe_format format = p_res->format;
129
const struct util_format_description *desc =
130
util_format_description(format);
131
unsigned colormask = util_format_colormask(desc);
132
133
if (util_format_is_intensity(format) ||
134
util_format_is_luminance(format) ||
135
util_format_is_luminance_alpha(format)) {
136
override_color.u32[1] = override_color.u32[0];
137
override_color.u32[2] = override_color.u32[0];
138
if (util_format_is_intensity(format))
139
override_color.u32[3] = override_color.u32[0];
140
} else {
141
for (int chan = 0; chan < 3; chan++) {
142
if (!(colormask & (1 << chan)))
143
override_color.u32[chan] = 0;
144
}
145
}
146
147
if (util_format_is_unorm(format)) {
148
for (int i = 0; i < 4; i++)
149
override_color.f32[i] = CLAMP(override_color.f32[i], 0.0f, 1.0f);
150
} else if (util_format_is_snorm(format)) {
151
for (int i = 0; i < 4; i++)
152
override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f);
153
} else if (util_format_is_pure_uint(format)) {
154
for (int i = 0; i < 4; i++) {
155
unsigned bits = util_format_get_component_bits(
156
format, UTIL_FORMAT_COLORSPACE_RGB, i);
157
if (bits < 32) {
158
uint32_t max = (1u << bits) - 1;
159
override_color.u32[i] = MIN2(override_color.u32[i], max);
160
}
161
}
162
} else if (util_format_is_pure_sint(format)) {
163
for (int i = 0; i < 4; i++) {
164
unsigned bits = util_format_get_component_bits(
165
format, UTIL_FORMAT_COLORSPACE_RGB, i);
166
if (bits < 32) {
167
int32_t max = (1 << (bits - 1)) - 1;
168
int32_t min = -(1 << (bits - 1));
169
override_color.i32[i] = CLAMP(override_color.i32[i], min, max);
170
}
171
}
172
} else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||
173
format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
174
/* these packed float formats only store unsigned values */
175
for (int i = 0; i < 4; i++)
176
override_color.f32[i] = MAX2(override_color.f32[i], 0.0f);
177
}
178
179
if (!(colormask & 1 << 3)) {
180
if (util_format_is_pure_integer(format))
181
override_color.u32[3] = 1;
182
else
183
override_color.f32[3] = 1.0f;
184
}
185
186
/* Handle linear to SRGB conversion */
187
if (isl_format_is_srgb(render_format)) {
188
for (int i = 0; i < 3; i++) {
189
override_color.f32[i] =
190
util_format_linear_to_srgb_float(override_color.f32[i]);
191
}
192
}
193
194
return override_color;
195
}
196
197
static void
198
fast_clear_color(struct crocus_context *ice,
199
struct crocus_resource *res,
200
unsigned level,
201
const struct pipe_box *box,
202
enum isl_format format,
203
union isl_color_value color,
204
enum blorp_batch_flags blorp_flags)
205
{
206
struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];
207
struct crocus_screen *screen = batch->screen;
208
struct pipe_resource *p_res = (void *) res;
209
210
color = convert_fast_clear_color(ice, res, format, color);
211
212
bool color_changed = !!memcmp(&res->aux.clear_color, &color,
213
sizeof(color));
214
215
if (color_changed) {
216
/* If we are clearing to a new clear value, we need to resolve fast
217
* clears from other levels/layers first, since we can't have different
218
* levels/layers with different fast clear colors.
219
*/
220
for (unsigned res_lvl = 0; res_lvl < res->surf.levels; res_lvl++) {
221
const unsigned level_layers =
222
crocus_get_num_logical_layers(res, res_lvl);
223
for (unsigned layer = 0; layer < level_layers; layer++) {
224
if (res_lvl == level &&
225
layer >= box->z &&
226
layer < box->z + box->depth) {
227
/* We're going to clear this layer anyway. Leave it alone. */
228
continue;
229
}
230
231
enum isl_aux_state aux_state =
232
crocus_resource_get_aux_state(res, res_lvl, layer);
233
234
if (aux_state != ISL_AUX_STATE_CLEAR &&
235
aux_state != ISL_AUX_STATE_PARTIAL_CLEAR &&
236
aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
237
/* This slice doesn't have any fast-cleared bits. */
238
continue;
239
}
240
241
/* If we got here, then the level may have fast-clear bits that use
242
* the old clear value. We need to do a color resolve to get rid
243
* of their use of the clear color before we can change it.
244
* Fortunately, few applications ever change their clear color at
245
* different levels/layers, so this shouldn't happen often.
246
*/
247
crocus_resource_prepare_access(ice, res,
248
res_lvl, 1, layer, 1,
249
res->aux.usage,
250
false);
251
perf_debug(&ice->dbg,
252
"Resolving resource (%p) level %d, layer %d: color changing from "
253
"(%0.2f, %0.2f, %0.2f, %0.2f) to "
254
"(%0.2f, %0.2f, %0.2f, %0.2f)\n",
255
res, res_lvl, layer,
256
res->aux.clear_color.f32[0],
257
res->aux.clear_color.f32[1],
258
res->aux.clear_color.f32[2],
259
res->aux.clear_color.f32[3],
260
color.f32[0], color.f32[1], color.f32[2], color.f32[3]);
261
}
262
}
263
}
264
265
crocus_resource_set_clear_color(ice, res, color);
266
267
/* If the buffer is already in ISL_AUX_STATE_CLEAR, and the color hasn't
268
* changed, the clear is redundant and can be skipped.
269
*/
270
const enum isl_aux_state aux_state =
271
crocus_resource_get_aux_state(res, level, box->z);
272
if (!color_changed && box->depth == 1 && aux_state == ISL_AUX_STATE_CLEAR)
273
return;
274
275
/* Ivybrigde PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":
276
*
277
* "Any transition from any value in {Clear, Render, Resolve} to a
278
* different value in {Clear, Render, Resolve} requires end of pipe
279
* synchronization."
280
*
281
* In other words, fast clear ops are not properly synchronized with
282
* other drawing. We need to use a PIPE_CONTROL to ensure that the
283
* contents of the previous draw hit the render target before we resolve
284
* and again afterwards to ensure that the resolve is complete before we
285
* do any more regular drawing.
286
*/
287
crocus_emit_end_of_pipe_sync(batch,
288
"fast clear: pre-flush",
289
PIPE_CONTROL_RENDER_TARGET_FLUSH);
290
291
/* If we reach this point, we need to fast clear to change the state to
292
* ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both).
293
*/
294
blorp_flags |= color_changed ? 0 : BLORP_BATCH_NO_UPDATE_CLEAR_COLOR;
295
296
struct blorp_batch blorp_batch;
297
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
298
299
struct blorp_surf surf;
300
crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev, &surf,
301
p_res, res->aux.usage, level, true);
302
303
/* In newer gens (> 9), the hardware will do a linear -> sRGB conversion of
304
* the clear color during the fast clear, if the surface format is of sRGB
305
* type. We use the linear version of the surface format here to prevent
306
* that from happening, since we already do our own linear -> sRGB
307
* conversion in convert_fast_clear_color().
308
*/
309
blorp_fast_clear(&blorp_batch, &surf, isl_format_srgb_to_linear(format),
310
ISL_SWIZZLE_IDENTITY,
311
level, box->z, box->depth,
312
box->x, box->y, box->x + box->width,
313
box->y + box->height);
314
blorp_batch_finish(&blorp_batch);
315
crocus_emit_end_of_pipe_sync(batch,
316
"fast clear: post flush",
317
PIPE_CONTROL_RENDER_TARGET_FLUSH);
318
319
crocus_resource_set_aux_state(ice, res, level, box->z,
320
box->depth, ISL_AUX_STATE_CLEAR);
321
ice->state.stage_dirty |= CROCUS_ALL_STAGE_DIRTY_BINDINGS;
322
return;
323
}
324
325
static void
326
clear_color(struct crocus_context *ice,
327
struct pipe_resource *p_res,
328
unsigned level,
329
const struct pipe_box *box,
330
bool render_condition_enabled,
331
enum isl_format format,
332
struct isl_swizzle swizzle,
333
union isl_color_value color)
334
{
335
struct crocus_resource *res = (void *) p_res;
336
struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];
337
struct crocus_screen *screen = batch->screen;
338
const struct intel_device_info *devinfo = &batch->screen->devinfo;
339
enum blorp_batch_flags blorp_flags = 0;
340
341
if (render_condition_enabled) {
342
if (!crocus_check_conditional_render(ice))
343
return;
344
345
if (ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT)
346
blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
347
}
348
349
if (p_res->target == PIPE_BUFFER)
350
util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);
351
352
crocus_batch_maybe_flush(batch, 1500);
353
354
bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box,
355
render_condition_enabled,
356
res->surf.format, format, color);
357
if (can_fast_clear) {
358
fast_clear_color(ice, res, level, box, format, color,
359
blorp_flags);
360
return;
361
}
362
363
bool color_write_disable[4] = { false, false, false, false };
364
enum isl_aux_usage aux_usage =
365
crocus_resource_render_aux_usage(ice, res, level, format, false);
366
367
crocus_resource_prepare_render(ice, res, level,
368
box->z, box->depth, aux_usage);
369
370
struct blorp_surf surf;
371
crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev, &surf,
372
p_res, aux_usage, level, true);
373
374
struct blorp_batch blorp_batch;
375
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
376
377
if (!isl_format_supports_rendering(devinfo, format) &&
378
isl_format_is_rgbx(format))
379
format = isl_format_rgbx_to_rgba(format);
380
381
blorp_clear(&blorp_batch, &surf, format, swizzle,
382
level, box->z, box->depth, box->x, box->y,
383
box->x + box->width, box->y + box->height,
384
color, color_write_disable);
385
386
blorp_batch_finish(&blorp_batch);
387
crocus_flush_and_dirty_for_history(ice, batch, res,
388
PIPE_CONTROL_RENDER_TARGET_FLUSH,
389
"cache history: post color clear");
390
391
crocus_resource_finish_render(ice, res, level,
392
box->z, box->depth, aux_usage);
393
}
394
395
static bool
396
can_fast_clear_depth(struct crocus_context *ice,
397
struct crocus_resource *res,
398
unsigned level,
399
const struct pipe_box *box,
400
bool render_condition_enabled,
401
float depth)
402
{
403
struct pipe_resource *p_res = (void *) res;
404
struct pipe_context *ctx = (void *) ice;
405
struct crocus_screen *screen = (void *) ctx->screen;
406
const struct intel_device_info *devinfo = &screen->devinfo;
407
408
if (devinfo->ver < 6)
409
return false;
410
411
if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)
412
return false;
413
414
/* Check for partial clears */
415
if (box->x > 0 || box->y > 0 ||
416
box->width < u_minify(p_res->width0, level) ||
417
box->height < u_minify(p_res->height0, level)) {
418
return false;
419
}
420
421
/* Avoid conditional fast clears to maintain correct tracking of the aux
422
* state (see iris_resource_finish_write for more info). Note that partial
423
* fast clears would not pose a problem with conditional rendering.
424
*/
425
if (render_condition_enabled &&
426
ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT) {
427
return false;
428
}
429
430
if (!crocus_resource_level_has_hiz(res, level))
431
return false;
432
433
if (res->base.b.format == PIPE_FORMAT_Z16_UNORM) {
434
/* From the Sandy Bridge PRM, volume 2 part 1, page 314:
435
*
436
* "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be
437
* enabled (the legacy method of clearing must be performed):
438
*
439
* - DevSNB{W/A}]: When depth buffer format is D16_UNORM and the
440
* width of the map (LOD0) is not multiple of 16, fast clear
441
* optimization must be disabled.
442
*/
443
if (devinfo->ver == 6 &&
444
(minify(res->surf.phys_level0_sa.width,
445
level) % 16) != 0)
446
return false;
447
}
448
return true;
449
}
450
451
static void
452
fast_clear_depth(struct crocus_context *ice,
453
struct crocus_resource *res,
454
unsigned level,
455
const struct pipe_box *box,
456
float depth)
457
{
458
struct pipe_resource *p_res = (void *) res;
459
struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];
460
461
/* Quantize the clear value to what can be stored in the actual depth
462
* buffer. This makes the following check more accurate because it now
463
* checks if the actual depth bits will match. It also prevents us from
464
* getting a too-accurate depth value during depth testing or when sampling
465
* with HiZ enabled.
466
*/
467
const unsigned nbits = p_res->format == PIPE_FORMAT_Z16_UNORM ? 16 : 24;
468
const uint32_t depth_max = (1 << nbits) - 1;
469
depth = p_res->format == PIPE_FORMAT_Z32_FLOAT ? depth :
470
(unsigned)(depth * depth_max) / (float)depth_max;
471
472
bool update_clear_depth = false;
473
474
/* If we're clearing to a new clear value, then we need to resolve any clear
475
* flags out of the HiZ buffer into the real depth buffer.
476
*/
477
if (res->aux.clear_color.f32[0] != depth) {
478
for (unsigned res_level = 0; res_level < res->surf.levels; res_level++) {
479
if (!crocus_resource_level_has_hiz(res, res_level))
480
continue;
481
482
const unsigned level_layers =
483
crocus_get_num_logical_layers(res, res_level);
484
for (unsigned layer = 0; layer < level_layers; layer++) {
485
if (res_level == level &&
486
layer >= box->z &&
487
layer < box->z + box->depth) {
488
/* We're going to clear this layer anyway. Leave it alone. */
489
continue;
490
}
491
492
enum isl_aux_state aux_state =
493
crocus_resource_get_aux_state(res, res_level, layer);
494
495
if (aux_state != ISL_AUX_STATE_CLEAR &&
496
aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
497
/* This slice doesn't have any fast-cleared bits. */
498
continue;
499
}
500
501
/* If we got here, then the level may have fast-clear bits that
502
* use the old clear value. We need to do a depth resolve to get
503
* rid of their use of the clear value before we can change it.
504
* Fortunately, few applications ever change their depth clear
505
* value so this shouldn't happen often.
506
*/
507
crocus_hiz_exec(ice, batch, res, res_level, layer, 1,
508
ISL_AUX_OP_FULL_RESOLVE, false);
509
crocus_resource_set_aux_state(ice, res, res_level, layer, 1,
510
ISL_AUX_STATE_RESOLVED);
511
}
512
}
513
const union isl_color_value clear_value = { .f32 = {depth, } };
514
crocus_resource_set_clear_color(ice, res, clear_value);
515
update_clear_depth = true;
516
}
517
518
for (unsigned l = 0; l < box->depth; l++) {
519
enum isl_aux_state aux_state =
520
crocus_resource_level_has_hiz(res, level) ?
521
crocus_resource_get_aux_state(res, level, box->z + l) :
522
ISL_AUX_STATE_AUX_INVALID;
523
if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) {
524
if (aux_state == ISL_AUX_STATE_CLEAR) {
525
perf_debug(&ice->dbg, "Performing HiZ clear just to update the "
526
"depth clear value\n");
527
}
528
crocus_hiz_exec(ice, batch, res, level,
529
box->z + l, 1, ISL_AUX_OP_FAST_CLEAR,
530
update_clear_depth);
531
}
532
}
533
534
crocus_resource_set_aux_state(ice, res, level, box->z, box->depth,
535
ISL_AUX_STATE_CLEAR);
536
ice->state.dirty |= CROCUS_DIRTY_DEPTH_BUFFER;
537
}
538
539
static void
540
clear_depth_stencil(struct crocus_context *ice,
541
struct pipe_resource *p_res,
542
unsigned level,
543
const struct pipe_box *box,
544
bool render_condition_enabled,
545
bool clear_depth,
546
bool clear_stencil,
547
float depth,
548
uint8_t stencil)
549
{
550
struct crocus_resource *res = (void *) p_res;
551
struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];
552
struct crocus_screen *screen = batch->screen;
553
enum blorp_batch_flags blorp_flags = 0;
554
555
if (render_condition_enabled) {
556
if (!crocus_check_conditional_render(ice))
557
return;
558
559
if (ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT)
560
blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
561
}
562
563
crocus_batch_maybe_flush(batch, 1500);
564
565
struct crocus_resource *z_res;
566
struct crocus_resource *stencil_res;
567
struct blorp_surf z_surf;
568
struct blorp_surf stencil_surf;
569
570
crocus_get_depth_stencil_resources(&batch->screen->devinfo, p_res, &z_res, &stencil_res);
571
if (z_res && clear_depth &&
572
can_fast_clear_depth(ice, z_res, level, box, render_condition_enabled,
573
depth)) {
574
fast_clear_depth(ice, z_res, level, box, depth);
575
crocus_flush_and_dirty_for_history(ice, batch, res, 0,
576
"cache history: post fast Z clear");
577
clear_depth = false;
578
z_res = NULL;
579
}
580
581
/* At this point, we might have fast cleared the depth buffer. So if there's
582
* no stencil clear pending, return early.
583
*/
584
if (!(clear_depth || (clear_stencil && stencil_res))) {
585
return;
586
}
587
588
if (clear_depth && z_res) {
589
const enum isl_aux_usage aux_usage =
590
crocus_resource_render_aux_usage(ice, z_res, level, z_res->surf.format,
591
false);
592
crocus_resource_prepare_render(ice, z_res, level, box->z, box->depth,
593
aux_usage);
594
crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev,
595
&z_surf, &z_res->base.b, aux_usage,
596
level, true);
597
}
598
599
struct blorp_batch blorp_batch;
600
blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
601
602
uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0;
603
if (stencil_mask) {
604
crocus_resource_prepare_access(ice, stencil_res, level, 1, box->z,
605
box->depth, stencil_res->aux.usage, false);
606
crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev,
607
&stencil_surf, &stencil_res->base.b,
608
stencil_res->aux.usage, level, true);
609
}
610
611
blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf,
612
level, box->z, box->depth,
613
box->x, box->y,
614
box->x + box->width,
615
box->y + box->height,
616
clear_depth && z_res, depth,
617
stencil_mask, stencil);
618
619
blorp_batch_finish(&blorp_batch);
620
crocus_flush_and_dirty_for_history(ice, batch, res, 0,
621
"cache history: post slow ZS clear");
622
623
if (clear_depth && z_res) {
624
crocus_resource_finish_render(ice, z_res, level,
625
box->z, box->depth, z_surf.aux_usage);
626
}
627
628
if (stencil_mask) {
629
crocus_resource_finish_write(ice, stencil_res, level, box->z, box->depth,
630
stencil_res->aux.usage);
631
}
632
}
633
634
/**
635
* The pipe->clear() driver hook.
636
*
637
* This clears buffers attached to the current draw framebuffer.
638
*/
639
static void
640
crocus_clear(struct pipe_context *ctx,
641
unsigned buffers,
642
const struct pipe_scissor_state *scissor_state,
643
const union pipe_color_union *p_color,
644
double depth,
645
unsigned stencil)
646
{
647
struct crocus_context *ice = (void *) ctx;
648
struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;
649
struct crocus_screen *screen = (void *) ctx->screen;
650
const struct intel_device_info *devinfo = &screen->devinfo;
651
assert(buffers != 0);
652
653
struct pipe_box box = {
654
.width = cso_fb->width,
655
.height = cso_fb->height,
656
};
657
658
if (scissor_state) {
659
box.x = scissor_state->minx;
660
box.y = scissor_state->miny;
661
box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx);
662
box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny);
663
}
664
665
if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
666
if (devinfo->ver < 6) {
667
crocus_blitter_begin(ice, CROCUS_SAVE_FRAGMENT_STATE, true);
668
util_blitter_clear(ice->blitter, cso_fb->width, cso_fb->height,
669
util_framebuffer_get_num_layers(cso_fb),
670
buffers & PIPE_CLEAR_DEPTHSTENCIL, p_color, depth, stencil, false);
671
} else {
672
struct pipe_surface *psurf = cso_fb->zsbuf;
673
box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;
674
box.z = psurf->u.tex.first_layer;
675
676
clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true,
677
buffers & PIPE_CLEAR_DEPTH,
678
buffers & PIPE_CLEAR_STENCIL,
679
depth, stencil);
680
}
681
buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
682
}
683
684
if (buffers & PIPE_CLEAR_COLOR) {
685
/* pipe_color_union and isl_color_value are interchangeable */
686
union isl_color_value *color = (void *) p_color;
687
688
for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {
689
if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
690
struct pipe_surface *psurf = cso_fb->cbufs[i];
691
struct crocus_surface *isurf = (void *) psurf;
692
box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,
693
box.z = psurf->u.tex.first_layer,
694
695
clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
696
true, isurf->view.format, isurf->view.swizzle,
697
*color);
698
}
699
}
700
}
701
}
702
703
/**
704
* The pipe->clear_texture() driver hook.
705
*
706
* This clears the given texture resource.
707
*/
708
static void
709
crocus_clear_texture(struct pipe_context *ctx,
710
struct pipe_resource *p_res,
711
unsigned level,
712
const struct pipe_box *box,
713
const void *data)
714
{
715
struct crocus_context *ice = (void *) ctx;
716
struct crocus_screen *screen = (void *) ctx->screen;
717
const struct intel_device_info *devinfo = &screen->devinfo;
718
struct crocus_resource *res = (void *) p_res;
719
720
if (devinfo->ver < 6) {
721
util_clear_texture(ctx, p_res,
722
level, box, data);
723
return;
724
}
725
726
if (crocus_resource_unfinished_aux_import(res))
727
crocus_resource_finish_aux_import(ctx->screen, res);
728
729
if (util_format_is_depth_or_stencil(p_res->format)) {
730
const struct util_format_unpack_description *fmt_unpack =
731
util_format_unpack_description(p_res->format);
732
733
float depth = 0.0;
734
uint8_t stencil = 0;
735
736
if (fmt_unpack->unpack_z_float)
737
fmt_unpack->unpack_z_float(&depth, 0, data, 0, 1, 1);
738
739
if (fmt_unpack->unpack_s_8uint)
740
fmt_unpack->unpack_s_8uint(&stencil, 0, data, 0, 1, 1);
741
742
clear_depth_stencil(ice, p_res, level, box, true, true, true,
743
depth, stencil);
744
} else {
745
union isl_color_value color;
746
struct crocus_resource *res = (void *) p_res;
747
enum isl_format format = res->surf.format;
748
749
if (!isl_format_supports_rendering(devinfo, format)) {
750
const struct isl_format_layout *fmtl = isl_format_get_layout(format);
751
// XXX: actually just get_copy_format_for_bpb from BLORP
752
// XXX: don't cut and paste this
753
switch (fmtl->bpb) {
754
case 8: format = ISL_FORMAT_R8_UINT; break;
755
case 16: format = ISL_FORMAT_R8G8_UINT; break;
756
case 24: format = ISL_FORMAT_R8G8B8_UINT; break;
757
case 32: format = ISL_FORMAT_R8G8B8A8_UINT; break;
758
case 48: format = ISL_FORMAT_R16G16B16_UINT; break;
759
case 64: format = ISL_FORMAT_R16G16B16A16_UINT; break;
760
case 96: format = ISL_FORMAT_R32G32B32_UINT; break;
761
case 128: format = ISL_FORMAT_R32G32B32A32_UINT; break;
762
default:
763
unreachable("Unknown format bpb");
764
}
765
766
/* No aux surfaces for non-renderable surfaces */
767
assert(res->aux.usage == ISL_AUX_USAGE_NONE);
768
}
769
770
isl_color_value_unpack(&color, format, data);
771
772
clear_color(ice, p_res, level, box, true, format,
773
ISL_SWIZZLE_IDENTITY, color);
774
}
775
}
776
777
/**
778
* The pipe->clear_render_target() driver hook.
779
*
780
* This clears the given render target surface.
781
*/
782
static void
783
crocus_clear_render_target(struct pipe_context *ctx,
784
struct pipe_surface *psurf,
785
const union pipe_color_union *p_color,
786
unsigned dst_x, unsigned dst_y,
787
unsigned width, unsigned height,
788
bool render_condition_enabled)
789
{
790
struct crocus_context *ice = (void *) ctx;
791
struct crocus_surface *isurf = (void *) psurf;
792
struct pipe_box box = {
793
.x = dst_x,
794
.y = dst_y,
795
.z = psurf->u.tex.first_layer,
796
.width = width,
797
.height = height,
798
.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
799
};
800
801
/* pipe_color_union and isl_color_value are interchangeable */
802
union isl_color_value *color = (void *) p_color;
803
804
clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
805
render_condition_enabled,
806
isurf->view.format, isurf->view.swizzle, *color);
807
}
808
809
/**
810
* The pipe->clear_depth_stencil() driver hook.
811
*
812
* This clears the given depth/stencil surface.
813
*/
814
static void
815
crocus_clear_depth_stencil(struct pipe_context *ctx,
816
struct pipe_surface *psurf,
817
unsigned flags,
818
double depth,
819
unsigned stencil,
820
unsigned dst_x, unsigned dst_y,
821
unsigned width, unsigned height,
822
bool render_condition_enabled)
823
{
824
return;
825
#if 0
826
struct crocus_context *ice = (void *) ctx;
827
struct pipe_box box = {
828
.x = dst_x,
829
.y = dst_y,
830
.z = psurf->u.tex.first_layer,
831
.width = width,
832
.height = height,
833
.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
834
};
835
uint32_t blit_flags = 0;
836
837
assert(util_format_is_depth_or_stencil(psurf->texture->format));
838
839
crocus_blitter_begin(ice, CROCUS_SAVE_FRAGMENT_STATE);
840
util_blitter_clear(ice->blitter, width, height,
841
1, flags, NULL, depth, stencil, render_condition_enabled);
842
#if 0
843
clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box,
844
render_condition_enabled,
845
flags & PIPE_CLEAR_DEPTH, flags & PIPE_CLEAR_STENCIL,
846
depth, stencil);
847
#endif
848
#endif
849
}
850
851
void
852
crocus_init_clear_functions(struct pipe_context *ctx)
853
{
854
ctx->clear = crocus_clear;
855
ctx->clear_texture = crocus_clear_texture;
856
ctx->clear_render_target = crocus_clear_render_target;
857
ctx->clear_depth_stencil = crocus_clear_depth_stencil;
858
}
859
860