forked from notaz/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblorp_clear.c
1552 lines (1328 loc) · 59.3 KB
/
blorp_clear.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "util/ralloc.h"
#include "util/macros.h" /* Needed for MAX3 and MAX2 for format_rgb9e5 */
#include "util/format_rgb9e5.h"
#include "util/format_srgb.h"
#include "blorp_priv.h"
#include "compiler/brw_eu_defines.h"
#include "dev/intel_debug.h"
#include "blorp_nir_builder.h"
#define FILE_DEBUG_FLAG DEBUG_BLORP
#pragma pack(push, 1)
struct brw_blorp_const_color_prog_key
{
struct brw_blorp_base_key base;
bool use_simd16_replicated_data;
bool clear_rgb_as_red;
uint8_t local_y;
};
#pragma pack(pop)
static bool
blorp_params_get_clear_kernel_fs(struct blorp_batch *batch,
struct blorp_params *params,
bool use_replicated_data,
bool clear_rgb_as_red)
{
struct blorp_context *blorp = batch->blorp;
const struct brw_blorp_const_color_prog_key blorp_key = {
.base = BRW_BLORP_BASE_KEY_INIT(BLORP_SHADER_TYPE_CLEAR),
.base.shader_pipeline = BLORP_SHADER_PIPELINE_RENDER,
.use_simd16_replicated_data = use_replicated_data,
.clear_rgb_as_red = clear_rgb_as_red,
.local_y = 0,
};
params->shader_type = blorp_key.base.shader_type;
params->shader_pipeline = blorp_key.base.shader_pipeline;
if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
¶ms->wm_prog_kernel, ¶ms->wm_prog_data))
return true;
void *mem_ctx = ralloc_context(NULL);
nir_builder b;
blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT,
blorp_shader_type_to_name(blorp_key.base.shader_type));
nir_variable *v_color =
BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
nir_ssa_def *color = nir_load_var(&b, v_color);
if (clear_rgb_as_red) {
nir_ssa_def *pos = nir_f2i32(&b, nir_load_frag_coord(&b));
nir_ssa_def *comp = nir_umod(&b, nir_channel(&b, pos, 0),
nir_imm_int(&b, 3));
color = nir_pad_vec4(&b, nir_vector_extract(&b, color, comp));
}
nir_variable *frag_color = nir_variable_create(b.shader, nir_var_shader_out,
glsl_vec4_type(),
"gl_FragColor");
frag_color->data.location = FRAG_RESULT_COLOR;
nir_store_var(&b, frag_color, color, 0xf);
struct brw_wm_prog_key wm_key;
brw_blorp_init_wm_prog_key(&wm_key);
struct brw_wm_prog_data prog_data;
const unsigned *program =
blorp_compile_fs(blorp, mem_ctx, b.shader, &wm_key, use_replicated_data,
&prog_data);
bool result =
blorp->upload_shader(batch, MESA_SHADER_FRAGMENT,
&blorp_key, sizeof(blorp_key),
program, prog_data.base.program_size,
&prog_data.base, sizeof(prog_data),
¶ms->wm_prog_kernel, ¶ms->wm_prog_data);
ralloc_free(mem_ctx);
return result;
}
static bool
blorp_params_get_clear_kernel_cs(struct blorp_batch *batch,
struct blorp_params *params,
bool clear_rgb_as_red)
{
struct blorp_context *blorp = batch->blorp;
const struct brw_blorp_const_color_prog_key blorp_key = {
.base = BRW_BLORP_BASE_KEY_INIT(BLORP_SHADER_TYPE_CLEAR),
.base.shader_pipeline = BLORP_SHADER_PIPELINE_COMPUTE,
.use_simd16_replicated_data = false,
.clear_rgb_as_red = clear_rgb_as_red,
.local_y = blorp_get_cs_local_y(params),
};
params->shader_type = blorp_key.base.shader_type;
params->shader_pipeline = blorp_key.base.shader_pipeline;
if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
¶ms->cs_prog_kernel, ¶ms->cs_prog_data))
return true;
void *mem_ctx = ralloc_context(NULL);
nir_builder b;
blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_COMPUTE, "BLORP-gpgpu-clear");
blorp_set_cs_dims(b.shader, blorp_key.local_y);
nir_ssa_def *dst_pos = nir_load_global_invocation_id(&b, 32);
nir_variable *v_color =
BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
nir_ssa_def *color = nir_load_var(&b, v_color);
nir_variable *v_bounds_rect =
BLORP_CREATE_NIR_INPUT(b.shader, bounds_rect, glsl_vec4_type());
nir_ssa_def *bounds_rect = nir_load_var(&b, v_bounds_rect);
nir_ssa_def *in_bounds = blorp_check_in_bounds(&b, bounds_rect, dst_pos);
if (clear_rgb_as_red) {
nir_ssa_def *comp = nir_umod(&b, nir_channel(&b, dst_pos, 0),
nir_imm_int(&b, 3));
color = nir_pad_vec4(&b, nir_vector_extract(&b, color, comp));
}
nir_push_if(&b, in_bounds);
nir_image_store(&b, nir_imm_int(&b, 0),
nir_pad_vector_imm_int(&b, dst_pos, 0, 4),
nir_imm_int(&b, 0),
nir_pad_vector_imm_int(&b, color, 0, 4),
nir_imm_int(&b, 0),
.image_dim = GLSL_SAMPLER_DIM_2D,
.image_array = true,
.access = ACCESS_NON_READABLE);
nir_pop_if(&b, NULL);
struct brw_cs_prog_key cs_key;
brw_blorp_init_cs_prog_key(&cs_key);
struct brw_cs_prog_data prog_data;
const unsigned *program =
blorp_compile_cs(blorp, mem_ctx, b.shader, &cs_key, &prog_data);
bool result =
blorp->upload_shader(batch, MESA_SHADER_COMPUTE,
&blorp_key, sizeof(blorp_key),
program, prog_data.base.program_size,
&prog_data.base, sizeof(prog_data),
¶ms->cs_prog_kernel, ¶ms->cs_prog_data);
ralloc_free(mem_ctx);
return result;
}
static bool
blorp_params_get_clear_kernel(struct blorp_batch *batch,
struct blorp_params *params,
bool use_replicated_data,
bool clear_rgb_as_red)
{
if (batch->flags & BLORP_BATCH_USE_COMPUTE) {
assert(!use_replicated_data);
return blorp_params_get_clear_kernel_cs(batch, params, clear_rgb_as_red);
} else {
return blorp_params_get_clear_kernel_fs(batch, params,
use_replicated_data,
clear_rgb_as_red);
}
}
#pragma pack(push, 1)
struct layer_offset_vs_key {
struct brw_blorp_base_key base;
unsigned num_inputs;
};
#pragma pack(pop)
/* In the case of doing attachment clears, we are using a surface state that
* is handed to us so we can't set (and don't even know) the base array layer.
* In order to do a layered clear in this scenario, we need some way of adding
* the base array layer to the instance id. Unfortunately, our hardware has
* no real concept of "base instance", so we have to do it manually in a
* vertex shader.
*/
static bool
blorp_params_get_layer_offset_vs(struct blorp_batch *batch,
struct blorp_params *params)
{
struct blorp_context *blorp = batch->blorp;
struct layer_offset_vs_key blorp_key = {
.base = BRW_BLORP_BASE_KEY_INIT(BLORP_SHADER_TYPE_LAYER_OFFSET_VS),
};
if (params->wm_prog_data)
blorp_key.num_inputs = params->wm_prog_data->num_varying_inputs;
if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
¶ms->vs_prog_kernel, ¶ms->vs_prog_data))
return true;
void *mem_ctx = ralloc_context(NULL);
nir_builder b;
blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_VERTEX,
blorp_shader_type_to_name(blorp_key.base.shader_type));
const struct glsl_type *uvec4_type = glsl_vector_type(GLSL_TYPE_UINT, 4);
/* First we deal with the header which has instance and base instance */
nir_variable *a_header = nir_variable_create(b.shader, nir_var_shader_in,
uvec4_type, "header");
a_header->data.location = VERT_ATTRIB_GENERIC0;
nir_variable *v_layer = nir_variable_create(b.shader, nir_var_shader_out,
glsl_int_type(), "layer_id");
v_layer->data.location = VARYING_SLOT_LAYER;
/* Compute the layer id */
nir_ssa_def *header = nir_load_var(&b, a_header);
nir_ssa_def *base_layer = nir_channel(&b, header, 0);
nir_ssa_def *instance = nir_channel(&b, header, 1);
nir_store_var(&b, v_layer, nir_iadd(&b, instance, base_layer), 0x1);
/* Then we copy the vertex from the next slot to VARYING_SLOT_POS */
nir_variable *a_vertex = nir_variable_create(b.shader, nir_var_shader_in,
glsl_vec4_type(), "a_vertex");
a_vertex->data.location = VERT_ATTRIB_GENERIC1;
nir_variable *v_pos = nir_variable_create(b.shader, nir_var_shader_out,
glsl_vec4_type(), "v_pos");
v_pos->data.location = VARYING_SLOT_POS;
nir_copy_var(&b, v_pos, a_vertex);
/* Then we copy everything else */
for (unsigned i = 0; i < blorp_key.num_inputs; i++) {
nir_variable *a_in = nir_variable_create(b.shader, nir_var_shader_in,
uvec4_type, "input");
a_in->data.location = VERT_ATTRIB_GENERIC2 + i;
nir_variable *v_out = nir_variable_create(b.shader, nir_var_shader_out,
uvec4_type, "output");
v_out->data.location = VARYING_SLOT_VAR0 + i;
nir_copy_var(&b, v_out, a_in);
}
struct brw_vs_prog_data vs_prog_data;
memset(&vs_prog_data, 0, sizeof(vs_prog_data));
const unsigned *program =
blorp_compile_vs(blorp, mem_ctx, b.shader, &vs_prog_data);
bool result =
blorp->upload_shader(batch, MESA_SHADER_VERTEX,
&blorp_key, sizeof(blorp_key),
program, vs_prog_data.base.base.program_size,
&vs_prog_data.base.base, sizeof(vs_prog_data),
¶ms->vs_prog_kernel, ¶ms->vs_prog_data);
ralloc_free(mem_ctx);
return result;
}
/* The x0, y0, x1, and y1 parameters must already be populated with the render
* area of the framebuffer to be cleared.
*/
static void
get_fast_clear_rect(const struct isl_device *dev,
const struct isl_surf *surf,
const struct isl_surf *aux_surf,
unsigned *x0, unsigned *y0,
unsigned *x1, unsigned *y1)
{
unsigned int x_align, y_align;
unsigned int x_scaledown, y_scaledown;
/* Only single sampled surfaces need to (and actually can) be resolved. */
if (surf->samples == 1) {
if (dev->info->verx10 >= 125) {
assert(surf->tiling == ISL_TILING_4);
/* From Bspec 47709, "MCS/CCS Buffer for Render Target(s)":
*
* SW must ensure that clearing rectangle dimensions cover the
* entire area desired, to accomplish this task initial X/Y
* dimensions need to be rounded up to next multiple of scaledown
* factor before dividing by scale down factor:
*
* The X and Y scale down factors in the table that follows are used
* for both alignment and scaling down.
*/
const uint32_t bs = isl_format_get_layout(surf->format)->bpb / 8;
x_align = x_scaledown = 1024 / bs;
y_align = y_scaledown = 16;
} else {
assert(aux_surf->usage == ISL_SURF_USAGE_CCS_BIT);
/* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
* Target(s)", beneath the "Fast Color Clear" bullet (p327):
*
* Clear pass must have a clear rectangle that must follow
* alignment rules in terms of pixels and lines as shown in the
* table below. Further, the clear-rectangle height and width
* must be multiple of the following dimensions. If the height
* and width of the render target being cleared do not meet these
* requirements, an MCS buffer can be created such that it
* follows the requirement and covers the RT.
*
* The alignment size in the table that follows is related to the
* alignment size that is baked into the CCS surface format but with X
* alignment multiplied by 16 and Y alignment multiplied by 32.
*/
x_align = isl_format_get_layout(aux_surf->format)->bw;
y_align = isl_format_get_layout(aux_surf->format)->bh;
x_align *= 16;
/* The line alignment requirement for Y-tiled is halved at SKL and again
* at TGL.
*/
if (dev->info->ver >= 12)
y_align *= 8;
else if (dev->info->ver >= 9)
y_align *= 16;
else
y_align *= 32;
/* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
* Target(s)", beneath the "Fast Color Clear" bullet (p327):
*
* In order to optimize the performance MCS buffer (when bound to
* 1X RT) clear similarly to MCS buffer clear for MSRT case,
* clear rect is required to be scaled by the following factors
* in the horizontal and vertical directions:
*
* The X and Y scale down factors in the table that follows are each
* equal to half the alignment value computed above.
*/
x_scaledown = x_align / 2;
y_scaledown = y_align / 2;
}
if (ISL_DEV_IS_HASWELL(dev)) {
/* From BSpec: 3D-Media-GPGPU Engine > 3D Pipeline > Pixel > Pixel
* Backend > MCS Buffer for Render Target(s) [DevIVB+] > Table "Color
* Clear of Non-MultiSampled Render Target Restrictions":
*
* Clear rectangle must be aligned to two times the number of
* pixels in the table shown below due to 16x16 hashing across the
* slice.
*
* This restriction is only documented to exist on HSW GT3 but
* empirical evidence suggests that it's also needed GT2.
*/
x_align *= 2;
y_align *= 2;
}
} else {
assert(aux_surf->usage == ISL_SURF_USAGE_MCS_BIT);
/* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
* Target(s)", beneath the "MSAA Compression" bullet (p326):
*
* Clear pass for this case requires that scaled down primitive
* is sent down with upper left coordinate to coincide with
* actual rectangle being cleared. For MSAA, clear rectangle’s
* height and width need to as show in the following table in
* terms of (width,height) of the RT.
*
* MSAA Width of Clear Rect Height of Clear Rect
* 2X Ceil(1/8*width) Ceil(1/2*height)
* 4X Ceil(1/8*width) Ceil(1/2*height)
* 8X Ceil(1/2*width) Ceil(1/2*height)
* 16X width Ceil(1/2*height)
*
* The text "with upper left coordinate to coincide with actual
* rectangle being cleared" is a little confusing--it seems to imply
* that to clear a rectangle from (x,y) to (x+w,y+h), one needs to
* feed the pipeline using the rectangle (x,y) to
* (x+Ceil(w/N),y+Ceil(h/2)), where N is either 2 or 8 depending on
* the number of samples. Experiments indicate that this is not
* quite correct; actually, what the hardware appears to do is to
* align whatever rectangle is sent down the pipeline to the nearest
* multiple of 2x2 blocks, and then scale it up by a factor of N
* horizontally and 2 vertically. So the resulting alignment is 4
* vertically and either 4 or 16 horizontally, and the scaledown
* factor is 2 vertically and either 2 or 8 horizontally.
*/
switch (aux_surf->format) {
case ISL_FORMAT_MCS_2X:
case ISL_FORMAT_MCS_4X:
x_scaledown = 8;
break;
case ISL_FORMAT_MCS_8X:
x_scaledown = 2;
break;
case ISL_FORMAT_MCS_16X:
x_scaledown = 1;
break;
default:
unreachable("Unexpected MCS format for fast clear");
}
y_scaledown = 2;
x_align = x_scaledown * 2;
y_align = y_scaledown * 2;
}
*x0 = ROUND_DOWN_TO(*x0, x_align) / x_scaledown;
*y0 = ROUND_DOWN_TO(*y0, y_align) / y_scaledown;
*x1 = ALIGN(*x1, x_align) / x_scaledown;
*y1 = ALIGN(*y1, y_align) / y_scaledown;
}
void
blorp_fast_clear(struct blorp_batch *batch,
const struct blorp_surf *surf,
enum isl_format format, struct isl_swizzle swizzle,
uint32_t level, uint32_t start_layer, uint32_t num_layers,
uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
{
struct blorp_params params;
blorp_params_init(¶ms);
params.num_layers = num_layers;
assert((batch->flags & BLORP_BATCH_USE_COMPUTE) == 0);
params.x0 = x0;
params.y0 = y0;
params.x1 = x1;
params.y1 = y1;
memset(¶ms.wm_inputs.clear_color, 0xff, 4*sizeof(float));
params.fast_clear_op = ISL_AUX_OP_FAST_CLEAR;
get_fast_clear_rect(batch->blorp->isl_dev, surf->surf, surf->aux_surf,
¶ms.x0, ¶ms.y0, ¶ms.x1, ¶ms.y1);
if (!blorp_params_get_clear_kernel(batch, ¶ms, true, false))
return;
brw_blorp_surface_info_init(batch, ¶ms.dst, surf, level,
start_layer, format, true);
params.num_samples = params.dst.surf.samples;
assert(params.num_samples != 0);
if (params.num_samples == 1)
params.op = BLORP_OP_CCS_COLOR_CLEAR;
else
params.op = BLORP_OP_MCS_COLOR_CLEAR;
/* If a swizzle was provided, we need to swizzle the clear color so that
* the hardware color format conversion will work properly.
*/
params.dst.clear_color =
isl_color_value_swizzle_inv(params.dst.clear_color, swizzle);
batch->blorp->exec(batch, ¶ms);
}
bool
blorp_clear_supports_compute(struct blorp_context *blorp,
uint8_t color_write_disable, bool blend_enabled,
enum isl_aux_usage aux_usage)
{
if (blorp->isl_dev->info->ver < 7)
return false;
if (color_write_disable != 0 || blend_enabled)
return false;
if (blorp->isl_dev->info->ver >= 12) {
return aux_usage == ISL_AUX_USAGE_GFX12_CCS_E ||
aux_usage == ISL_AUX_USAGE_CCS_E ||
aux_usage == ISL_AUX_USAGE_NONE;
} else {
return aux_usage == ISL_AUX_USAGE_NONE;
}
}
void
blorp_clear(struct blorp_batch *batch,
const struct blorp_surf *surf,
enum isl_format format, struct isl_swizzle swizzle,
uint32_t level, uint32_t start_layer, uint32_t num_layers,
uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
union isl_color_value clear_color,
uint8_t color_write_disable)
{
struct blorp_params params;
blorp_params_init(¶ms);
params.op = BLORP_OP_SLOW_COLOR_CLEAR;
const bool compute = batch->flags & BLORP_BATCH_USE_COMPUTE;
if (compute)
assert(blorp_clear_supports_compute(batch->blorp, color_write_disable,
false, surf->aux_usage));
/* Manually apply the clear destination swizzle. This way swizzled clears
* will work for swizzles which we can't normally use for rendering and it
* also ensures that they work on pre-Haswell hardware which can't swizlle
* at all.
*/
clear_color = isl_color_value_swizzle_inv(clear_color, swizzle);
swizzle = ISL_SWIZZLE_IDENTITY;
bool clear_rgb_as_red = false;
if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
clear_color.u32[0] = float3_to_rgb9e5(clear_color.f32);
format = ISL_FORMAT_R32_UINT;
} else if (format == ISL_FORMAT_L8_UNORM_SRGB) {
clear_color.f32[0] = util_format_linear_to_srgb_float(clear_color.f32[0]);
format = ISL_FORMAT_R8_UNORM;
} else if (format == ISL_FORMAT_A4B4G4R4_UNORM) {
/* Broadwell and earlier cannot render to this format so we need to work
* around it by swapping the colors around and using B4G4R4A4 instead.
*/
const struct isl_swizzle ARGB = ISL_SWIZZLE(ALPHA, RED, GREEN, BLUE);
clear_color = isl_color_value_swizzle_inv(clear_color, ARGB);
format = ISL_FORMAT_B4G4R4A4_UNORM;
} else if (isl_format_get_layout(format)->bpb % 3 == 0) {
clear_rgb_as_red = true;
if (format == ISL_FORMAT_R8G8B8_UNORM_SRGB) {
clear_color.f32[0] = util_format_linear_to_srgb_float(clear_color.f32[0]);
clear_color.f32[1] = util_format_linear_to_srgb_float(clear_color.f32[1]);
clear_color.f32[2] = util_format_linear_to_srgb_float(clear_color.f32[2]);
}
}
memcpy(¶ms.wm_inputs.clear_color, clear_color.f32, sizeof(float) * 4);
bool use_simd16_replicated_data = true;
/* From the SNB PRM (Vol4_Part1):
*
* "Replicated data (Message Type = 111) is only supported when
* accessing tiled memory. Using this Message Type to access linear
* (untiled) memory is UNDEFINED."
*/
if (surf->surf->tiling == ISL_TILING_LINEAR)
use_simd16_replicated_data = false;
/* Replicated clears don't work yet before gfx6 */
if (batch->blorp->isl_dev->info->ver < 6)
use_simd16_replicated_data = false;
if (compute)
use_simd16_replicated_data = false;
/* Constant color writes ignore everything in blend and color calculator
* state. This is not documented.
*/
params.color_write_disable = color_write_disable & BITFIELD_MASK(4);
if (color_write_disable)
use_simd16_replicated_data = false;
if (!blorp_params_get_clear_kernel(batch, ¶ms,
use_simd16_replicated_data,
clear_rgb_as_red))
return;
if (!compute && !blorp_ensure_sf_program(batch, ¶ms))
return;
while (num_layers > 0) {
brw_blorp_surface_info_init(batch, ¶ms.dst, surf, level,
start_layer, format, true);
params.dst.view.swizzle = swizzle;
params.x0 = x0;
params.y0 = y0;
params.x1 = x1;
params.y1 = y1;
if (compute) {
params.wm_inputs.bounds_rect.x0 = x0;
params.wm_inputs.bounds_rect.y0 = y0;
params.wm_inputs.bounds_rect.x1 = x1;
params.wm_inputs.bounds_rect.y1 = y1;
}
if (params.dst.tile_x_sa || params.dst.tile_y_sa) {
assert(params.dst.surf.samples == 1);
assert(num_layers == 1);
params.x0 += params.dst.tile_x_sa;
params.y0 += params.dst.tile_y_sa;
params.x1 += params.dst.tile_x_sa;
params.y1 += params.dst.tile_y_sa;
}
/* The MinLOD and MinimumArrayElement don't work properly for cube maps.
* Convert them to a single slice on gfx4.
*/
if (batch->blorp->isl_dev->info->ver == 4 &&
(params.dst.surf.usage & ISL_SURF_USAGE_CUBE_BIT)) {
blorp_surf_convert_to_single_slice(batch->blorp->isl_dev, ¶ms.dst);
}
if (clear_rgb_as_red) {
surf_fake_rgb_with_red(batch->blorp->isl_dev, ¶ms.dst);
params.x0 *= 3;
params.x1 *= 3;
}
if (isl_format_is_compressed(params.dst.surf.format)) {
blorp_surf_convert_to_uncompressed(batch->blorp->isl_dev, ¶ms.dst,
NULL, NULL, NULL, NULL);
//&dst_x, &dst_y, &dst_w, &dst_h);
}
if (params.dst.tile_x_sa || params.dst.tile_y_sa) {
/* Either we're on gfx4 where there is no multisampling or the
* surface is compressed which also implies no multisampling.
* Therefore, sa == px and we don't need to do a conversion.
*/
assert(params.dst.surf.samples == 1);
params.x0 += params.dst.tile_x_sa;
params.y0 += params.dst.tile_y_sa;
params.x1 += params.dst.tile_x_sa;
params.y1 += params.dst.tile_y_sa;
}
params.num_samples = params.dst.surf.samples;
/* We may be restricted on the number of layers we can bind at any one
* time. In particular, Sandy Bridge has a maximum number of layers of
* 512 but a maximum 3D texture size is much larger.
*/
params.num_layers = MIN2(params.dst.view.array_len, num_layers);
const unsigned max_image_width = 16 * 1024;
if (params.dst.surf.logical_level0_px.width > max_image_width) {
/* Clearing an RGB image as red multiplies the surface width by 3
* so it may now be too wide for the hardware surface limits. We
* have to break the clear up into pieces in order to clear wide
* images.
*/
assert(clear_rgb_as_red);
assert(params.dst.surf.dim == ISL_SURF_DIM_2D);
assert(params.dst.surf.tiling == ISL_TILING_LINEAR);
assert(params.dst.surf.logical_level0_px.depth == 1);
assert(params.dst.surf.logical_level0_px.array_len == 1);
assert(params.dst.surf.levels == 1);
assert(params.dst.surf.samples == 1);
assert(params.dst.tile_x_sa == 0 || params.dst.tile_y_sa == 0);
assert(params.dst.aux_usage == ISL_AUX_USAGE_NONE);
/* max_image_width rounded down to a multiple of 3 */
const unsigned max_fake_rgb_width = (max_image_width / 3) * 3;
const unsigned cpp =
isl_format_get_layout(params.dst.surf.format)->bpb / 8;
params.dst.surf.logical_level0_px.width = max_fake_rgb_width;
params.dst.surf.phys_level0_sa.width = max_fake_rgb_width;
uint32_t orig_x0 = params.x0, orig_x1 = params.x1;
uint64_t orig_offset = params.dst.addr.offset;
for (uint32_t x = orig_x0; x < orig_x1; x += max_fake_rgb_width) {
/* Offset to the surface. It's easy because we're linear */
params.dst.addr.offset = orig_offset + x * cpp;
params.x0 = 0;
params.x1 = MIN2(orig_x1 - x, max_image_width);
batch->blorp->exec(batch, ¶ms);
}
} else {
batch->blorp->exec(batch, ¶ms);
}
start_layer += params.num_layers;
num_layers -= params.num_layers;
}
}
static bool
blorp_clear_stencil_as_rgba(struct blorp_batch *batch,
const struct blorp_surf *surf,
uint32_t level, uint32_t start_layer,
uint32_t num_layers,
uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
uint8_t stencil_mask, uint8_t stencil_value)
{
assert((batch->flags & BLORP_BATCH_USE_COMPUTE) == 0);
/* We only support separate W-tiled stencil for now */
if (surf->surf->format != ISL_FORMAT_R8_UINT ||
surf->surf->tiling != ISL_TILING_W)
return false;
/* Stencil mask support would require piles of shader magic */
if (stencil_mask != 0xff)
return false;
if (surf->surf->samples > 1) {
/* Adjust x0, y0, x1, and y1 to be in units of samples */
assert(surf->surf->msaa_layout == ISL_MSAA_LAYOUT_INTERLEAVED);
struct isl_extent2d msaa_px_size_sa =
isl_get_interleaved_msaa_px_size_sa(surf->surf->samples);
x0 *= msaa_px_size_sa.w;
y0 *= msaa_px_size_sa.h;
x1 *= msaa_px_size_sa.w;
y1 *= msaa_px_size_sa.h;
}
/* W-tiles and Y-tiles have the same layout as far as cache lines are
* concerned: both are 8x8 cache lines laid out Y-major. The difference is
* entirely in how the data is arranged within the cache line. W-tiling
* is 8x8 pixels in a swizzled pattern while Y-tiling is 16B by 4 rows
* regardless of image format size. As long as everything is aligned to 8,
* we can just treat the W-tiled image as Y-tiled, ignore the layout
* difference within a cache line, and blast out data.
*/
if (x0 % 8 != 0 || y0 % 8 != 0 || x1 % 8 != 0 || y1 % 8 != 0)
return false;
struct blorp_params params;
blorp_params_init(¶ms);
params.op = BLORP_OP_SLOW_DEPTH_CLEAR;
if (!blorp_params_get_clear_kernel(batch, ¶ms, true, false))
return false;
memset(¶ms.wm_inputs.clear_color, stencil_value,
sizeof(params.wm_inputs.clear_color));
/* The Sandy Bridge PRM Vol. 4 Pt. 2, section 2.11.2.1.1 has the
* following footnote to the format table:
*
* 128 BPE Formats cannot be Tiled Y when used as render targets
*
* We have to use RGBA16_UINT on SNB.
*/
enum isl_format wide_format;
if (ISL_GFX_VER(batch->blorp->isl_dev) <= 6) {
wide_format = ISL_FORMAT_R16G16B16A16_UINT;
/* For RGBA16_UINT, we need to mask the stencil value otherwise, we risk
* clamping giving us the wrong values
*/
for (unsigned i = 0; i < 4; i++)
params.wm_inputs.clear_color[i] &= 0xffff;
} else {
wide_format = ISL_FORMAT_R32G32B32A32_UINT;
}
for (uint32_t a = 0; a < num_layers; a++) {
uint32_t layer = start_layer + a;
brw_blorp_surface_info_init(batch, ¶ms.dst, surf, level,
layer, ISL_FORMAT_UNSUPPORTED, true);
if (surf->surf->samples > 1)
blorp_surf_fake_interleaved_msaa(batch->blorp->isl_dev, ¶ms.dst);
/* Make it Y-tiled */
blorp_surf_retile_w_to_y(batch->blorp->isl_dev, ¶ms.dst);
unsigned wide_Bpp =
isl_format_get_layout(wide_format)->bpb / 8;
params.dst.view.format = params.dst.surf.format = wide_format;
assert(params.dst.surf.logical_level0_px.width % wide_Bpp == 0);
params.dst.surf.logical_level0_px.width /= wide_Bpp;
assert(params.dst.tile_x_sa % wide_Bpp == 0);
params.dst.tile_x_sa /= wide_Bpp;
params.x0 = params.dst.tile_x_sa + x0 / (wide_Bpp / 2);
params.y0 = params.dst.tile_y_sa + y0 / 2;
params.x1 = params.dst.tile_x_sa + x1 / (wide_Bpp / 2);
params.y1 = params.dst.tile_y_sa + y1 / 2;
batch->blorp->exec(batch, ¶ms);
}
return true;
}
void
blorp_clear_depth_stencil(struct blorp_batch *batch,
const struct blorp_surf *depth,
const struct blorp_surf *stencil,
uint32_t level, uint32_t start_layer,
uint32_t num_layers,
uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
bool clear_depth, float depth_value,
uint8_t stencil_mask, uint8_t stencil_value)
{
assert((batch->flags & BLORP_BATCH_USE_COMPUTE) == 0);
if (!clear_depth && blorp_clear_stencil_as_rgba(batch, stencil, level,
start_layer, num_layers,
x0, y0, x1, y1,
stencil_mask,
stencil_value))
return;
struct blorp_params params;
blorp_params_init(¶ms);
params.op = BLORP_OP_SLOW_DEPTH_CLEAR;
params.x0 = x0;
params.y0 = y0;
params.x1 = x1;
params.y1 = y1;
if (ISL_GFX_VER(batch->blorp->isl_dev) == 6) {
/* For some reason, Sandy Bridge gets occlusion queries wrong if we
* don't have a shader. In particular, it records samples even though
* we disable statistics in 3DSTATE_WM. Give it the usual clear shader
* to work around the issue.
*/
if (!blorp_params_get_clear_kernel(batch, ¶ms, false, false))
return;
}
while (num_layers > 0) {
params.num_layers = num_layers;
if (stencil_mask) {
brw_blorp_surface_info_init(batch, ¶ms.stencil, stencil,
level, start_layer,
ISL_FORMAT_UNSUPPORTED, true);
params.stencil_mask = stencil_mask;
params.stencil_ref = stencil_value;
params.dst.surf.samples = params.stencil.surf.samples;
params.dst.surf.logical_level0_px =
params.stencil.surf.logical_level0_px;
params.dst.view = params.stencil.view;
params.num_samples = params.stencil.surf.samples;
/* We may be restricted on the number of layers we can bind at any
* one time. In particular, Sandy Bridge has a maximum number of
* layers of 512 but a maximum 3D texture size is much larger.
*/
if (params.stencil.view.array_len < params.num_layers)
params.num_layers = params.stencil.view.array_len;
}
if (clear_depth) {
brw_blorp_surface_info_init(batch, ¶ms.depth, depth,
level, start_layer,
ISL_FORMAT_UNSUPPORTED, true);
params.z = depth_value;
params.depth_format =
isl_format_get_depth_format(depth->surf->format, false);
params.dst.surf.samples = params.depth.surf.samples;
params.dst.surf.logical_level0_px =
params.depth.surf.logical_level0_px;
params.dst.view = params.depth.view;
params.num_samples = params.depth.surf.samples;
/* We may be restricted on the number of layers we can bind at any
* one time. In particular, Sandy Bridge has a maximum number of
* layers of 512 but a maximum 3D texture size is much larger.
*/
if (params.depth.view.array_len < params.num_layers)
params.num_layers = params.depth.view.array_len;
}
batch->blorp->exec(batch, ¶ms);
start_layer += params.num_layers;
num_layers -= params.num_layers;
}
}
bool
blorp_can_hiz_clear_depth(const struct intel_device_info *devinfo,
const struct isl_surf *surf,
enum isl_aux_usage aux_usage,
uint32_t level, uint32_t layer,
uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
{
/* This function currently doesn't support any gen prior to gfx8 */
assert(devinfo->ver >= 8);
if (devinfo->ver == 8 && surf->format == ISL_FORMAT_R16_UNORM) {
/* From the BDW PRM, Vol 7, "Depth Buffer Clear":
*
* The following restrictions apply only if the depth buffer surface
* type is D16_UNORM and software does not use the “full surf clear”:
*
* If Number of Multisamples is NUMSAMPLES_1, the rectangle must be
* aligned to an 8x4 pixel block relative to the upper left corner of
* the depth buffer, and contain an integer number of these pixel
* blocks, and all 8x4 pixels must be lit.
*
* Alignment requirements for other sample counts are listed, but they
* can all be satisfied by the one mentioned above.
*/
if (x0 % 8 || y0 % 4 || x1 % 8 || y1 % 4)
return false;
} else if (aux_usage == ISL_AUX_USAGE_HIZ_CCS_WT) {
/* We have to set the WM_HZ_OP::FullSurfaceDepthandStencilClear bit
* whenever we clear an uninitialized HIZ buffer (as some drivers
* currently do). However, this bit seems liable to clear 16x8 pixels in
* the ZCS on Gfx12 - greater than the slice alignments for depth
* buffers.
*/
assert(surf->image_alignment_el.w % 16 != 0 ||
surf->image_alignment_el.h % 8 != 0);
/* This is the hypothesis behind some corruption that was seen with the
* amd_vertex_shader_layer-layered-depth-texture-render piglit test.
*
* From the Compressed Depth Buffers section of the Bspec, under the
* Gfx12 texture performant and ZCS columns:
*
* Update with clear at either 16x8 or 8x4 granularity, based on
* fs_clr or otherwise.
*
* There are a number of ways to avoid full surface CCS clears that
* overlap other slices, but for now we choose to disable fast-clears
* when an initializing clear could hit another miplevel.
*
* NOTE: Because the CCS compresses the depth buffer and not a version
* of it that has been rearranged with different alignments (like Gfx8+
* HIZ), we have to make sure that the x0 and y0 are at least 16x8
* aligned in the context of the entire surface.
*/
uint32_t slice_x0, slice_y0, slice_z0, slice_a0;
isl_surf_get_image_offset_el(surf, level,
surf->dim == ISL_SURF_DIM_3D ? 0 : layer,
surf->dim == ISL_SURF_DIM_3D ? layer: 0,
&slice_x0, &slice_y0, &slice_z0, &slice_a0);
assert(slice_z0 == 0 && slice_a0 == 0);
const bool max_x1_y1 =
x1 == u_minify(surf->logical_level0_px.width, level) &&
y1 == u_minify(surf->logical_level0_px.height, level);
const uint32_t haligned_x1 = ALIGN(x1, surf->image_alignment_el.w);
const uint32_t valigned_y1 = ALIGN(y1, surf->image_alignment_el.h);
const bool unaligned = (slice_x0 + x0) % 16 || (slice_y0 + y0) % 8 ||
(max_x1_y1 ? haligned_x1 % 16 || valigned_y1 % 8 :
x1 % 16 || y1 % 8);
const bool partial_clear = x0 > 0 || y0 > 0 || !max_x1_y1;
const bool multislice_surf = surf->levels > 1 ||
surf->logical_level0_px.depth > 1 ||
surf->logical_level0_px.array_len > 1;
if (unaligned && (partial_clear || multislice_surf))
return false;
}
return isl_aux_usage_has_hiz(aux_usage);
}
static bool
blorp_can_clear_full_surface(const struct blorp_surf *depth,
const struct blorp_surf *stencil,
uint32_t level,
uint32_t x0, uint32_t y0,
uint32_t x1, uint32_t y1,
bool clear_depth,
bool clear_stencil)
{
uint32_t width = 0, height = 0;
if (clear_stencil) {
width = u_minify(stencil->surf->logical_level0_px.width, level);
height = u_minify(stencil->surf->logical_level0_px.height, level);
}
if (clear_depth && !(width || height)) {
width = u_minify(depth->surf->logical_level0_px.width, level);
height = u_minify(depth->surf->logical_level0_px.height, level);
}