blorp: introduce helper method blorp_nir_init_shader
[mesa.git] / src / intel / blorp / blorp_clear.c
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "util/ralloc.h"
25
26 #include "main/macros.h" /* Needed for MAX3 and MAX2 for format_rgb9e5 */
27 #include "util/format_rgb9e5.h"
28 #include "util/format_srgb.h"
29
30 #include "blorp_priv.h"
31 #include "compiler/brw_eu_defines.h"
32
33 #include "blorp_nir_builder.h"
34
35 #define FILE_DEBUG_FLAG DEBUG_BLORP
36
37 struct brw_blorp_const_color_prog_key
38 {
39 enum blorp_shader_type shader_type; /* Must be BLORP_SHADER_TYPE_CLEAR */
40 bool use_simd16_replicated_data;
41 bool clear_rgb_as_red;
42 bool pad[3];
43 };
44
45 static bool
46 blorp_params_get_clear_kernel(struct blorp_batch *batch,
47 struct blorp_params *params,
48 bool use_replicated_data,
49 bool clear_rgb_as_red)
50 {
51 struct blorp_context *blorp = batch->blorp;
52
53 const struct brw_blorp_const_color_prog_key blorp_key = {
54 .shader_type = BLORP_SHADER_TYPE_CLEAR,
55 .use_simd16_replicated_data = use_replicated_data,
56 .clear_rgb_as_red = clear_rgb_as_red,
57 };
58
59 if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
60 &params->wm_prog_kernel, &params->wm_prog_data))
61 return true;
62
63 void *mem_ctx = ralloc_context(NULL);
64
65 nir_builder b;
66 blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT, "BLORP-clear");
67
68 nir_variable *v_color =
69 BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
70 nir_ssa_def *color = nir_load_var(&b, v_color);
71
72 if (clear_rgb_as_red) {
73 nir_variable *frag_coord =
74 nir_variable_create(b.shader, nir_var_shader_in,
75 glsl_vec4_type(), "gl_FragCoord");
76 frag_coord->data.location = VARYING_SLOT_POS;
77 frag_coord->data.origin_upper_left = true;
78
79 nir_ssa_def *pos = nir_f2i32(&b, nir_load_var(&b, frag_coord));
80 nir_ssa_def *comp = nir_umod(&b, nir_channel(&b, pos, 0),
81 nir_imm_int(&b, 3));
82 nir_ssa_def *color_component =
83 nir_bcsel(&b, nir_ieq(&b, comp, nir_imm_int(&b, 0)),
84 nir_channel(&b, color, 0),
85 nir_bcsel(&b, nir_ieq(&b, comp, nir_imm_int(&b, 1)),
86 nir_channel(&b, color, 1),
87 nir_channel(&b, color, 2)));
88
89 nir_ssa_def *u = nir_ssa_undef(&b, 1, 32);
90 color = nir_vec4(&b, color_component, u, u, u);
91 }
92
93 nir_variable *frag_color = nir_variable_create(b.shader, nir_var_shader_out,
94 glsl_vec4_type(),
95 "gl_FragColor");
96 frag_color->data.location = FRAG_RESULT_COLOR;
97 nir_store_var(&b, frag_color, color, 0xf);
98
99 struct brw_wm_prog_key wm_key;
100 brw_blorp_init_wm_prog_key(&wm_key);
101
102 struct brw_wm_prog_data prog_data;
103 const unsigned *program =
104 blorp_compile_fs(blorp, mem_ctx, b.shader, &wm_key, use_replicated_data,
105 &prog_data);
106
107 bool result =
108 blorp->upload_shader(batch, &blorp_key, sizeof(blorp_key),
109 program, prog_data.base.program_size,
110 &prog_data.base, sizeof(prog_data),
111 &params->wm_prog_kernel, &params->wm_prog_data);
112
113 ralloc_free(mem_ctx);
114 return result;
115 }
116
117 struct layer_offset_vs_key {
118 enum blorp_shader_type shader_type;
119 unsigned num_inputs;
120 };
121
122 /* In the case of doing attachment clears, we are using a surface state that
123 * is handed to us so we can't set (and don't even know) the base array layer.
124 * In order to do a layered clear in this scenario, we need some way of adding
125 * the base array layer to the instance id. Unfortunately, our hardware has
126 * no real concept of "base instance", so we have to do it manually in a
127 * vertex shader.
128 */
129 static bool
130 blorp_params_get_layer_offset_vs(struct blorp_batch *batch,
131 struct blorp_params *params)
132 {
133 struct blorp_context *blorp = batch->blorp;
134 struct layer_offset_vs_key blorp_key = {
135 .shader_type = BLORP_SHADER_TYPE_LAYER_OFFSET_VS,
136 };
137
138 if (params->wm_prog_data)
139 blorp_key.num_inputs = params->wm_prog_data->num_varying_inputs;
140
141 if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
142 &params->vs_prog_kernel, &params->vs_prog_data))
143 return true;
144
145 void *mem_ctx = ralloc_context(NULL);
146
147 nir_builder b;
148 blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_VERTEX, "BLORP-layer-offset-vs");
149
150 const struct glsl_type *uvec4_type = glsl_vector_type(GLSL_TYPE_UINT, 4);
151
152 /* First we deal with the header which has instance and base instance */
153 nir_variable *a_header = nir_variable_create(b.shader, nir_var_shader_in,
154 uvec4_type, "header");
155 a_header->data.location = VERT_ATTRIB_GENERIC0;
156
157 nir_variable *v_layer = nir_variable_create(b.shader, nir_var_shader_out,
158 glsl_int_type(), "layer_id");
159 v_layer->data.location = VARYING_SLOT_LAYER;
160
161 /* Compute the layer id */
162 nir_ssa_def *header = nir_load_var(&b, a_header);
163 nir_ssa_def *base_layer = nir_channel(&b, header, 0);
164 nir_ssa_def *instance = nir_channel(&b, header, 1);
165 nir_store_var(&b, v_layer, nir_iadd(&b, instance, base_layer), 0x1);
166
167 /* Then we copy the vertex from the next slot to VARYING_SLOT_POS */
168 nir_variable *a_vertex = nir_variable_create(b.shader, nir_var_shader_in,
169 glsl_vec4_type(), "a_vertex");
170 a_vertex->data.location = VERT_ATTRIB_GENERIC1;
171
172 nir_variable *v_pos = nir_variable_create(b.shader, nir_var_shader_out,
173 glsl_vec4_type(), "v_pos");
174 v_pos->data.location = VARYING_SLOT_POS;
175
176 nir_copy_var(&b, v_pos, a_vertex);
177
178 /* Then we copy everything else */
179 for (unsigned i = 0; i < blorp_key.num_inputs; i++) {
180 nir_variable *a_in = nir_variable_create(b.shader, nir_var_shader_in,
181 uvec4_type, "input");
182 a_in->data.location = VERT_ATTRIB_GENERIC2 + i;
183
184 nir_variable *v_out = nir_variable_create(b.shader, nir_var_shader_out,
185 uvec4_type, "output");
186 v_out->data.location = VARYING_SLOT_VAR0 + i;
187
188 nir_copy_var(&b, v_out, a_in);
189 }
190
191 struct brw_vs_prog_data vs_prog_data;
192 memset(&vs_prog_data, 0, sizeof(vs_prog_data));
193
194 const unsigned *program =
195 blorp_compile_vs(blorp, mem_ctx, b.shader, &vs_prog_data);
196
197 bool result =
198 blorp->upload_shader(batch, &blorp_key, sizeof(blorp_key),
199 program, vs_prog_data.base.base.program_size,
200 &vs_prog_data.base.base, sizeof(vs_prog_data),
201 &params->vs_prog_kernel, &params->vs_prog_data);
202
203 ralloc_free(mem_ctx);
204 return result;
205 }
206
207 /* The x0, y0, x1, and y1 parameters must already be populated with the render
208 * area of the framebuffer to be cleared.
209 */
210 static void
211 get_fast_clear_rect(const struct isl_device *dev,
212 const struct isl_surf *aux_surf,
213 unsigned *x0, unsigned *y0,
214 unsigned *x1, unsigned *y1)
215 {
216 unsigned int x_align, y_align;
217 unsigned int x_scaledown, y_scaledown;
218
219 /* Only single sampled surfaces need to (and actually can) be resolved. */
220 if (aux_surf->usage == ISL_SURF_USAGE_CCS_BIT) {
221 /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
222 * Target(s)", beneath the "Fast Color Clear" bullet (p327):
223 *
224 * Clear pass must have a clear rectangle that must follow
225 * alignment rules in terms of pixels and lines as shown in the
226 * table below. Further, the clear-rectangle height and width
227 * must be multiple of the following dimensions. If the height
228 * and width of the render target being cleared do not meet these
229 * requirements, an MCS buffer can be created such that it
230 * follows the requirement and covers the RT.
231 *
232 * The alignment size in the table that follows is related to the
233 * alignment size that is baked into the CCS surface format but with X
234 * alignment multiplied by 16 and Y alignment multiplied by 32.
235 */
236 x_align = isl_format_get_layout(aux_surf->format)->bw;
237 y_align = isl_format_get_layout(aux_surf->format)->bh;
238
239 x_align *= 16;
240
241 /* SKL+ line alignment requirement for Y-tiled are half those of the prior
242 * generations.
243 */
244 if (dev->info->gen >= 9)
245 y_align *= 16;
246 else
247 y_align *= 32;
248
249 /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
250 * Target(s)", beneath the "Fast Color Clear" bullet (p327):
251 *
252 * In order to optimize the performance MCS buffer (when bound to
253 * 1X RT) clear similarly to MCS buffer clear for MSRT case,
254 * clear rect is required to be scaled by the following factors
255 * in the horizontal and vertical directions:
256 *
257 * The X and Y scale down factors in the table that follows are each
258 * equal to half the alignment value computed above.
259 */
260 x_scaledown = x_align / 2;
261 y_scaledown = y_align / 2;
262
263 /* From BSpec: 3D-Media-GPGPU Engine > 3D Pipeline > Pixel > Pixel
264 * Backend > MCS Buffer for Render Target(s) [DevIVB+] > Table "Color
265 * Clear of Non-MultiSampled Render Target Restrictions":
266 *
267 * Clear rectangle must be aligned to two times the number of
268 * pixels in the table shown below due to 16x16 hashing across the
269 * slice.
270 */
271 x_align *= 2;
272 y_align *= 2;
273 } else {
274 assert(aux_surf->usage == ISL_SURF_USAGE_MCS_BIT);
275
276 /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
277 * Target(s)", beneath the "MSAA Compression" bullet (p326):
278 *
279 * Clear pass for this case requires that scaled down primitive
280 * is sent down with upper left co-ordinate to coincide with
281 * actual rectangle being cleared. For MSAA, clear rectangle’s
282 * height and width need to as show in the following table in
283 * terms of (width,height) of the RT.
284 *
285 * MSAA Width of Clear Rect Height of Clear Rect
286 * 2X Ceil(1/8*width) Ceil(1/2*height)
287 * 4X Ceil(1/8*width) Ceil(1/2*height)
288 * 8X Ceil(1/2*width) Ceil(1/2*height)
289 * 16X width Ceil(1/2*height)
290 *
291 * The text "with upper left co-ordinate to coincide with actual
292 * rectangle being cleared" is a little confusing--it seems to imply
293 * that to clear a rectangle from (x,y) to (x+w,y+h), one needs to
294 * feed the pipeline using the rectangle (x,y) to
295 * (x+Ceil(w/N),y+Ceil(h/2)), where N is either 2 or 8 depending on
296 * the number of samples. Experiments indicate that this is not
297 * quite correct; actually, what the hardware appears to do is to
298 * align whatever rectangle is sent down the pipeline to the nearest
299 * multiple of 2x2 blocks, and then scale it up by a factor of N
300 * horizontally and 2 vertically. So the resulting alignment is 4
301 * vertically and either 4 or 16 horizontally, and the scaledown
302 * factor is 2 vertically and either 2 or 8 horizontally.
303 */
304 switch (aux_surf->format) {
305 case ISL_FORMAT_MCS_2X:
306 case ISL_FORMAT_MCS_4X:
307 x_scaledown = 8;
308 break;
309 case ISL_FORMAT_MCS_8X:
310 x_scaledown = 2;
311 break;
312 case ISL_FORMAT_MCS_16X:
313 x_scaledown = 1;
314 break;
315 default:
316 unreachable("Unexpected MCS format for fast clear");
317 }
318 y_scaledown = 2;
319 x_align = x_scaledown * 2;
320 y_align = y_scaledown * 2;
321 }
322
323 *x0 = ROUND_DOWN_TO(*x0, x_align) / x_scaledown;
324 *y0 = ROUND_DOWN_TO(*y0, y_align) / y_scaledown;
325 *x1 = ALIGN(*x1, x_align) / x_scaledown;
326 *y1 = ALIGN(*y1, y_align) / y_scaledown;
327 }
328
329 void
330 blorp_fast_clear(struct blorp_batch *batch,
331 const struct blorp_surf *surf, enum isl_format format,
332 uint32_t level, uint32_t start_layer, uint32_t num_layers,
333 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
334 {
335 /* Ensure that all layers undergoing the clear have an auxiliary buffer. */
336 assert(start_layer + num_layers <=
337 MAX2(surf->aux_surf->logical_level0_px.depth >> level,
338 surf->aux_surf->logical_level0_px.array_len));
339
340 struct blorp_params params;
341 blorp_params_init(&params);
342 params.num_layers = num_layers;
343
344 params.x0 = x0;
345 params.y0 = y0;
346 params.x1 = x1;
347 params.y1 = y1;
348
349 memset(&params.wm_inputs.clear_color, 0xff, 4*sizeof(float));
350 params.fast_clear_op = ISL_AUX_OP_FAST_CLEAR;
351
352 get_fast_clear_rect(batch->blorp->isl_dev, surf->aux_surf,
353 &params.x0, &params.y0, &params.x1, &params.y1);
354
355 if (!blorp_params_get_clear_kernel(batch, &params, true, false))
356 return;
357
358 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
359 start_layer, format, true);
360 params.num_samples = params.dst.surf.samples;
361
362 batch->blorp->exec(batch, &params);
363 }
364
365 static union isl_color_value
366 swizzle_color_value(union isl_color_value src, struct isl_swizzle swizzle)
367 {
368 union isl_color_value dst = { .u32 = { 0, } };
369
370 /* We assign colors in ABGR order so that the first one will be taken in
371 * RGBA precedence order. According to the PRM docs for shader channel
372 * select, this matches Haswell hardware behavior.
373 */
374 if ((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4)
375 dst.u32[swizzle.a - ISL_CHANNEL_SELECT_RED] = src.u32[3];
376 if ((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4)
377 dst.u32[swizzle.b - ISL_CHANNEL_SELECT_RED] = src.u32[2];
378 if ((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4)
379 dst.u32[swizzle.g - ISL_CHANNEL_SELECT_RED] = src.u32[1];
380 if ((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4)
381 dst.u32[swizzle.r - ISL_CHANNEL_SELECT_RED] = src.u32[0];
382
383 return dst;
384 }
385
386 void
387 blorp_clear(struct blorp_batch *batch,
388 const struct blorp_surf *surf,
389 enum isl_format format, struct isl_swizzle swizzle,
390 uint32_t level, uint32_t start_layer, uint32_t num_layers,
391 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
392 union isl_color_value clear_color,
393 const bool color_write_disable[4])
394 {
395 struct blorp_params params;
396 blorp_params_init(&params);
397
398 /* Manually apply the clear destination swizzle. This way swizzled clears
399 * will work for swizzles which we can't normally use for rendering and it
400 * also ensures that they work on pre-Haswell hardware which can't swizlle
401 * at all.
402 */
403 clear_color = swizzle_color_value(clear_color, swizzle);
404 swizzle = ISL_SWIZZLE_IDENTITY;
405
406 bool clear_rgb_as_red = false;
407 if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
408 clear_color.u32[0] = float3_to_rgb9e5(clear_color.f32);
409 format = ISL_FORMAT_R32_UINT;
410 } else if (format == ISL_FORMAT_L8_UNORM_SRGB) {
411 clear_color.f32[0] = util_format_linear_to_srgb_float(clear_color.f32[0]);
412 format = ISL_FORMAT_R8_UNORM;
413 } else if (format == ISL_FORMAT_A4B4G4R4_UNORM) {
414 /* Broadwell and earlier cannot render to this format so we need to work
415 * around it by swapping the colors around and using B4G4R4A4 instead.
416 */
417 const struct isl_swizzle ARGB = ISL_SWIZZLE(ALPHA, RED, GREEN, BLUE);
418 clear_color = swizzle_color_value(clear_color, ARGB);
419 format = ISL_FORMAT_B4G4R4A4_UNORM;
420 } else if (isl_format_get_layout(format)->bpb % 3 == 0) {
421 clear_rgb_as_red = true;
422 if (format == ISL_FORMAT_R8G8B8_UNORM_SRGB) {
423 clear_color.f32[0] = util_format_linear_to_srgb_float(clear_color.f32[0]);
424 clear_color.f32[1] = util_format_linear_to_srgb_float(clear_color.f32[1]);
425 clear_color.f32[2] = util_format_linear_to_srgb_float(clear_color.f32[2]);
426 }
427 }
428
429 memcpy(&params.wm_inputs.clear_color, clear_color.f32, sizeof(float) * 4);
430
431 bool use_simd16_replicated_data = true;
432
433 /* From the SNB PRM (Vol4_Part1):
434 *
435 * "Replicated data (Message Type = 111) is only supported when
436 * accessing tiled memory. Using this Message Type to access linear
437 * (untiled) memory is UNDEFINED."
438 */
439 if (surf->surf->tiling == ISL_TILING_LINEAR)
440 use_simd16_replicated_data = false;
441
442 /* Replicated clears don't work yet before gen6 */
443 if (batch->blorp->isl_dev->info->gen < 6)
444 use_simd16_replicated_data = false;
445
446 /* Constant color writes ignore everyting in blend and color calculator
447 * state. This is not documented.
448 */
449 if (color_write_disable) {
450 for (unsigned i = 0; i < 4; i++) {
451 params.color_write_disable[i] = color_write_disable[i];
452 if (color_write_disable[i])
453 use_simd16_replicated_data = false;
454 }
455 }
456
457 if (!blorp_params_get_clear_kernel(batch, &params,
458 use_simd16_replicated_data,
459 clear_rgb_as_red))
460 return;
461
462 if (!blorp_ensure_sf_program(batch, &params))
463 return;
464
465 while (num_layers > 0) {
466 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
467 start_layer, format, true);
468 params.dst.view.swizzle = swizzle;
469
470 params.x0 = x0;
471 params.y0 = y0;
472 params.x1 = x1;
473 params.y1 = y1;
474
475 if (params.dst.tile_x_sa || params.dst.tile_y_sa) {
476 assert(params.dst.surf.samples == 1);
477 assert(num_layers == 1);
478 params.x0 += params.dst.tile_x_sa;
479 params.y0 += params.dst.tile_y_sa;
480 params.x1 += params.dst.tile_x_sa;
481 params.y1 += params.dst.tile_y_sa;
482 }
483
484 /* The MinLOD and MinimumArrayElement don't work properly for cube maps.
485 * Convert them to a single slice on gen4.
486 */
487 if (batch->blorp->isl_dev->info->gen == 4 &&
488 (params.dst.surf.usage & ISL_SURF_USAGE_CUBE_BIT)) {
489 blorp_surf_convert_to_single_slice(batch->blorp->isl_dev, &params.dst);
490 }
491
492 if (clear_rgb_as_red) {
493 surf_fake_rgb_with_red(batch->blorp->isl_dev, &params.dst);
494 params.x0 *= 3;
495 params.x1 *= 3;
496 }
497
498 if (isl_format_is_compressed(params.dst.surf.format)) {
499 blorp_surf_convert_to_uncompressed(batch->blorp->isl_dev, &params.dst,
500 NULL, NULL, NULL, NULL);
501 //&dst_x, &dst_y, &dst_w, &dst_h);
502 }
503
504 if (params.dst.tile_x_sa || params.dst.tile_y_sa) {
505 /* Either we're on gen4 where there is no multisampling or the
506 * surface is compressed which also implies no multisampling.
507 * Therefore, sa == px and we don't need to do a conversion.
508 */
509 assert(params.dst.surf.samples == 1);
510 params.x0 += params.dst.tile_x_sa;
511 params.y0 += params.dst.tile_y_sa;
512 params.x1 += params.dst.tile_x_sa;
513 params.y1 += params.dst.tile_y_sa;
514 }
515
516 params.num_samples = params.dst.surf.samples;
517
518 /* We may be restricted on the number of layers we can bind at any one
519 * time. In particular, Sandy Bridge has a maximum number of layers of
520 * 512 but a maximum 3D texture size is much larger.
521 */
522 params.num_layers = MIN2(params.dst.view.array_len, num_layers);
523
524 const unsigned max_image_width = 16 * 1024;
525 if (params.dst.surf.logical_level0_px.width > max_image_width) {
526 /* Clearing an RGB image as red multiplies the surface width by 3
527 * so it may now be too wide for the hardware surface limits. We
528 * have to break the clear up into pieces in order to clear wide
529 * images.
530 */
531 assert(clear_rgb_as_red);
532 assert(params.dst.surf.dim == ISL_SURF_DIM_2D);
533 assert(params.dst.surf.tiling == ISL_TILING_LINEAR);
534 assert(params.dst.surf.logical_level0_px.depth == 1);
535 assert(params.dst.surf.logical_level0_px.array_len == 1);
536 assert(params.dst.surf.levels == 1);
537 assert(params.dst.surf.samples == 1);
538 assert(params.dst.tile_x_sa == 0 || params.dst.tile_y_sa == 0);
539 assert(params.dst.aux_usage == ISL_AUX_USAGE_NONE);
540
541 /* max_image_width rounded down to a multiple of 3 */
542 const unsigned max_fake_rgb_width = (max_image_width / 3) * 3;
543 const unsigned cpp =
544 isl_format_get_layout(params.dst.surf.format)->bpb / 8;
545
546 params.dst.surf.logical_level0_px.width = max_fake_rgb_width;
547 params.dst.surf.phys_level0_sa.width = max_fake_rgb_width;
548
549 uint32_t orig_x0 = params.x0, orig_x1 = params.x1;
550 uint64_t orig_offset = params.dst.addr.offset;
551 for (uint32_t x = orig_x0; x < orig_x1; x += max_fake_rgb_width) {
552 /* Offset to the surface. It's easy because we're linear */
553 params.dst.addr.offset = orig_offset + x * cpp;
554
555 params.x0 = 0;
556 params.x1 = MIN2(orig_x1 - x, max_image_width);
557
558 batch->blorp->exec(batch, &params);
559 }
560 } else {
561 batch->blorp->exec(batch, &params);
562 }
563
564 start_layer += params.num_layers;
565 num_layers -= params.num_layers;
566 }
567 }
568
569 void
570 blorp_clear_depth_stencil(struct blorp_batch *batch,
571 const struct blorp_surf *depth,
572 const struct blorp_surf *stencil,
573 uint32_t level, uint32_t start_layer,
574 uint32_t num_layers,
575 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
576 bool clear_depth, float depth_value,
577 uint8_t stencil_mask, uint8_t stencil_value)
578 {
579 struct blorp_params params;
580 blorp_params_init(&params);
581
582 params.x0 = x0;
583 params.y0 = y0;
584 params.x1 = x1;
585 params.y1 = y1;
586
587 if (ISL_DEV_GEN(batch->blorp->isl_dev) == 6) {
588 /* For some reason, Sandy Bridge gets occlusion queries wrong if we
589 * don't have a shader. In particular, it records samples even though
590 * we disable statistics in 3DSTATE_WM. Give it the usual clear shader
591 * to work around the issue.
592 */
593 if (!blorp_params_get_clear_kernel(batch, &params, false, false))
594 return;
595 }
596
597 while (num_layers > 0) {
598 params.num_layers = num_layers;
599
600 if (stencil_mask) {
601 brw_blorp_surface_info_init(batch->blorp, &params.stencil, stencil,
602 level, start_layer,
603 ISL_FORMAT_UNSUPPORTED, true);
604 params.stencil_mask = stencil_mask;
605 params.stencil_ref = stencil_value;
606
607 params.dst.surf.samples = params.stencil.surf.samples;
608 params.dst.surf.logical_level0_px =
609 params.stencil.surf.logical_level0_px;
610 params.dst.view = params.depth.view;
611
612 params.num_samples = params.stencil.surf.samples;
613
614 /* We may be restricted on the number of layers we can bind at any
615 * one time. In particular, Sandy Bridge has a maximum number of
616 * layers of 512 but a maximum 3D texture size is much larger.
617 */
618 if (params.stencil.view.array_len < params.num_layers)
619 params.num_layers = params.stencil.view.array_len;
620 }
621
622 if (clear_depth) {
623 brw_blorp_surface_info_init(batch->blorp, &params.depth, depth,
624 level, start_layer,
625 ISL_FORMAT_UNSUPPORTED, true);
626 params.z = depth_value;
627 params.depth_format =
628 isl_format_get_depth_format(depth->surf->format, false);
629
630 params.dst.surf.samples = params.depth.surf.samples;
631 params.dst.surf.logical_level0_px =
632 params.depth.surf.logical_level0_px;
633 params.dst.view = params.depth.view;
634
635 params.num_samples = params.depth.surf.samples;
636
637 /* We may be restricted on the number of layers we can bind at any
638 * one time. In particular, Sandy Bridge has a maximum number of
639 * layers of 512 but a maximum 3D texture size is much larger.
640 */
641 if (params.depth.view.array_len < params.num_layers)
642 params.num_layers = params.depth.view.array_len;
643 }
644
645 batch->blorp->exec(batch, &params);
646
647 start_layer += params.num_layers;
648 num_layers -= params.num_layers;
649 }
650 }
651
652 bool
653 blorp_can_hiz_clear_depth(uint8_t gen, enum isl_format format,
654 uint32_t num_samples,
655 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
656 {
657 /* This function currently doesn't support any gen prior to gen8 */
658 assert(gen >= 8);
659
660 if (gen == 8 && format == ISL_FORMAT_R16_UNORM) {
661 /* Apply the D16 alignment restrictions. On BDW, HiZ has an 8x4 sample
662 * block with the following property: as the number of samples increases,
663 * the number of pixels representable by this block decreases by a factor
664 * of the sample dimensions. Sample dimensions scale following the MSAA
665 * interleaved pattern.
666 *
667 * Sample|Sample|Pixel
668 * Count |Dim |Dim
669 * ===================
670 * 1 | 1x1 | 8x4
671 * 2 | 2x1 | 4x4
672 * 4 | 2x2 | 4x2
673 * 8 | 4x2 | 2x2
674 * 16 | 4x4 | 2x1
675 *
676 * Table: Pixel Dimensions in a HiZ Sample Block Pre-SKL
677 */
678 const struct isl_extent2d sa_block_dim =
679 isl_get_interleaved_msaa_px_size_sa(num_samples);
680 const uint8_t align_px_w = 8 / sa_block_dim.w;
681 const uint8_t align_px_h = 4 / sa_block_dim.h;
682
683 /* Fast depth clears clear an entire sample block at a time. As a result,
684 * the rectangle must be aligned to the dimensions of the encompassing
685 * pixel block for a successful operation.
686 *
687 * Fast clears can still work if the upper-left corner is aligned and the
688 * bottom-rigtht corner touches the edge of a depth buffer whose extent
689 * is unaligned. This is because each miplevel in the depth buffer is
690 * padded by the Pixel Dim (similar to a standard compressed texture).
691 * In this case, the clear rectangle could be padded by to match the full
692 * depth buffer extent but to support multiple clearing techniques, we
693 * chose to be unaware of the depth buffer's extent and thus don't handle
694 * this case.
695 */
696 if (x0 % align_px_w || y0 % align_px_h ||
697 x1 % align_px_w || y1 % align_px_h)
698 return false;
699 }
700 return true;
701 }
702
703 void
704 blorp_hiz_clear_depth_stencil(struct blorp_batch *batch,
705 const struct blorp_surf *depth,
706 const struct blorp_surf *stencil,
707 uint32_t level,
708 uint32_t start_layer, uint32_t num_layers,
709 uint32_t x0, uint32_t y0,
710 uint32_t x1, uint32_t y1,
711 bool clear_depth, float depth_value,
712 bool clear_stencil, uint8_t stencil_value)
713 {
714 struct blorp_params params;
715 blorp_params_init(&params);
716
717 /* This requires WM_HZ_OP which only exists on gen8+ */
718 assert(ISL_DEV_GEN(batch->blorp->isl_dev) >= 8);
719
720 params.hiz_op = ISL_AUX_OP_FAST_CLEAR;
721 params.num_layers = 1;
722
723 params.x0 = x0;
724 params.y0 = y0;
725 params.x1 = x1;
726 params.y1 = y1;
727
728 for (uint32_t l = 0; l < num_layers; l++) {
729 const uint32_t layer = start_layer + l;
730 if (clear_stencil) {
731 brw_blorp_surface_info_init(batch->blorp, &params.stencil, stencil,
732 level, layer,
733 ISL_FORMAT_UNSUPPORTED, true);
734 params.stencil_mask = 0xff;
735 params.stencil_ref = stencil_value;
736 params.num_samples = params.stencil.surf.samples;
737 }
738
739 if (clear_depth) {
740 /* If we're clearing depth, we must have HiZ */
741 assert(depth && depth->aux_usage == ISL_AUX_USAGE_HIZ);
742
743 brw_blorp_surface_info_init(batch->blorp, &params.depth, depth,
744 level, layer,
745 ISL_FORMAT_UNSUPPORTED, true);
746 params.depth.clear_color.f32[0] = depth_value;
747 params.depth_format =
748 isl_format_get_depth_format(depth->surf->format, false);
749 params.num_samples = params.depth.surf.samples;
750 }
751
752 batch->blorp->exec(batch, &params);
753 }
754 }
755
756 /* Given a depth stencil attachment, this function performs a fast depth clear
757 * on a depth portion and a regular clear on the stencil portion. When
758 * performing a fast depth clear on the depth portion, the HiZ buffer is simply
759 * tagged as cleared so the depth clear value is not actually needed.
760 */
761 void
762 blorp_gen8_hiz_clear_attachments(struct blorp_batch *batch,
763 uint32_t num_samples,
764 uint32_t x0, uint32_t y0,
765 uint32_t x1, uint32_t y1,
766 bool clear_depth, bool clear_stencil,
767 uint8_t stencil_value)
768 {
769 assert(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL);
770
771 struct blorp_params params;
772 blorp_params_init(&params);
773 params.num_layers = 1;
774 params.hiz_op = ISL_AUX_OP_FAST_CLEAR;
775 params.x0 = x0;
776 params.y0 = y0;
777 params.x1 = x1;
778 params.y1 = y1;
779 params.num_samples = num_samples;
780 params.depth.enabled = clear_depth;
781 params.stencil.enabled = clear_stencil;
782 params.stencil_ref = stencil_value;
783 batch->blorp->exec(batch, &params);
784 }
785
786 /** Clear active color/depth/stencili attachments
787 *
788 * This function performs a clear operation on the currently bound
789 * color/depth/stencil attachments. It is assumed that any information passed
790 * in here is valid, consistent, and in-bounds relative to the currently
791 * attached depth/stencil. The binding_table_offset parameter is the 32-bit
792 * offset relative to surface state base address where pre-baked binding table
793 * that we are to use lives. If clear_color is false, binding_table_offset
794 * must point to a binding table with one entry which is a valid null surface
795 * that matches the currently bound depth and stencil.
796 */
797 void
798 blorp_clear_attachments(struct blorp_batch *batch,
799 uint32_t binding_table_offset,
800 enum isl_format depth_format,
801 uint32_t num_samples,
802 uint32_t start_layer, uint32_t num_layers,
803 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
804 bool clear_color, union isl_color_value color_value,
805 bool clear_depth, float depth_value,
806 uint8_t stencil_mask, uint8_t stencil_value)
807 {
808 struct blorp_params params;
809 blorp_params_init(&params);
810
811 assert(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL);
812
813 params.x0 = x0;
814 params.y0 = y0;
815 params.x1 = x1;
816 params.y1 = y1;
817
818 params.use_pre_baked_binding_table = true;
819 params.pre_baked_binding_table_offset = binding_table_offset;
820
821 params.num_layers = num_layers;
822 params.num_samples = num_samples;
823
824 if (clear_color) {
825 params.dst.enabled = true;
826
827 memcpy(&params.wm_inputs.clear_color, color_value.f32, sizeof(float) * 4);
828
829 /* Unfortunately, without knowing whether or not our destination surface
830 * is tiled or not, we have to assume it may be linear. This means no
831 * SIMD16_REPDATA for us. :-(
832 */
833 if (!blorp_params_get_clear_kernel(batch, &params, false, false))
834 return;
835 }
836
837 if (clear_depth) {
838 params.depth.enabled = true;
839
840 params.z = depth_value;
841 params.depth_format = isl_format_get_depth_format(depth_format, false);
842 }
843
844 if (stencil_mask) {
845 params.stencil.enabled = true;
846
847 params.stencil_mask = stencil_mask;
848 params.stencil_ref = stencil_value;
849 }
850
851 if (!blorp_params_get_layer_offset_vs(batch, &params))
852 return;
853
854 params.vs_inputs.base_layer = start_layer;
855
856 batch->blorp->exec(batch, &params);
857 }
858
859 void
860 blorp_ccs_resolve(struct blorp_batch *batch,
861 struct blorp_surf *surf, uint32_t level,
862 uint32_t start_layer, uint32_t num_layers,
863 enum isl_format format,
864 enum isl_aux_op resolve_op)
865 {
866 struct blorp_params params;
867
868 blorp_params_init(&params);
869 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf,
870 level, start_layer, format, true);
871
872 /* From the Ivy Bridge PRM, Vol2 Part1 11.9 "Render Target Resolve":
873 *
874 * A rectangle primitive must be scaled down by the following factors
875 * with respect to render target being resolved.
876 *
877 * The scaledown factors in the table that follows are related to the block
878 * size of the CCS format. For IVB and HSW, we divide by two, for BDW we
879 * multiply by 8 and 16. On Sky Lake, we multiply by 8.
880 */
881 const struct isl_format_layout *aux_fmtl =
882 isl_format_get_layout(params.dst.aux_surf.format);
883 assert(aux_fmtl->txc == ISL_TXC_CCS);
884
885 unsigned x_scaledown, y_scaledown;
886 if (ISL_DEV_GEN(batch->blorp->isl_dev) >= 9) {
887 x_scaledown = aux_fmtl->bw * 8;
888 y_scaledown = aux_fmtl->bh * 8;
889 } else if (ISL_DEV_GEN(batch->blorp->isl_dev) >= 8) {
890 x_scaledown = aux_fmtl->bw * 8;
891 y_scaledown = aux_fmtl->bh * 16;
892 } else {
893 x_scaledown = aux_fmtl->bw / 2;
894 y_scaledown = aux_fmtl->bh / 2;
895 }
896 params.x0 = params.y0 = 0;
897 params.x1 = minify(params.dst.aux_surf.logical_level0_px.width, level);
898 params.y1 = minify(params.dst.aux_surf.logical_level0_px.height, level);
899 params.x1 = ALIGN(params.x1, x_scaledown) / x_scaledown;
900 params.y1 = ALIGN(params.y1, y_scaledown) / y_scaledown;
901
902 if (batch->blorp->isl_dev->info->gen >= 9) {
903 assert(resolve_op == ISL_AUX_OP_FULL_RESOLVE ||
904 resolve_op == ISL_AUX_OP_PARTIAL_RESOLVE);
905 } else {
906 /* Broadwell and earlier do not have a partial resolve */
907 assert(resolve_op == ISL_AUX_OP_FULL_RESOLVE);
908 }
909 params.fast_clear_op = resolve_op;
910 params.num_layers = num_layers;
911
912 /* Note: there is no need to initialize push constants because it doesn't
913 * matter what data gets dispatched to the render target. However, we must
914 * ensure that the fragment shader delivers the data using the "replicated
915 * color" message.
916 */
917
918 if (!blorp_params_get_clear_kernel(batch, &params, true, false))
919 return;
920
921 batch->blorp->exec(batch, &params);
922 }
923
924 static nir_ssa_def *
925 blorp_nir_bit(nir_builder *b, nir_ssa_def *src, unsigned bit)
926 {
927 return nir_iand(b, nir_ushr(b, src, nir_imm_int(b, bit)),
928 nir_imm_int(b, 1));
929 }
930
931 struct blorp_mcs_partial_resolve_key
932 {
933 enum blorp_shader_type shader_type;
934 bool indirect_clear_color;
935 bool int_format;
936 uint32_t num_samples;
937 };
938
939 static bool
940 blorp_params_get_mcs_partial_resolve_kernel(struct blorp_batch *batch,
941 struct blorp_params *params)
942 {
943 struct blorp_context *blorp = batch->blorp;
944 const struct blorp_mcs_partial_resolve_key blorp_key = {
945 .shader_type = BLORP_SHADER_TYPE_MCS_PARTIAL_RESOLVE,
946 .indirect_clear_color = params->dst.clear_color_addr.buffer != NULL,
947 .int_format = isl_format_has_int_channel(params->dst.view.format),
948 .num_samples = params->num_samples,
949 };
950
951 if (blorp->lookup_shader(batch, &blorp_key, sizeof(blorp_key),
952 &params->wm_prog_kernel, &params->wm_prog_data))
953 return true;
954
955 void *mem_ctx = ralloc_context(NULL);
956
957 nir_builder b;
958 blorp_nir_init_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT,
959 "BLORP-mcs-partial-resolve");
960
961 nir_variable *v_color =
962 BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
963
964 nir_variable *frag_color =
965 nir_variable_create(b.shader, nir_var_shader_out,
966 glsl_vec4_type(), "gl_FragColor");
967 frag_color->data.location = FRAG_RESULT_COLOR;
968
969 /* Do an MCS fetch and check if it is equal to the magic clear value */
970 nir_ssa_def *mcs =
971 blorp_nir_txf_ms_mcs(&b, nir_f2i32(&b, blorp_nir_frag_coord(&b)),
972 nir_load_layer_id(&b));
973 nir_ssa_def *is_clear =
974 blorp_nir_mcs_is_clear_color(&b, mcs, blorp_key.num_samples);
975
976 /* If we aren't the clear value, discard. */
977 nir_intrinsic_instr *discard =
978 nir_intrinsic_instr_create(b.shader, nir_intrinsic_discard_if);
979 discard->src[0] = nir_src_for_ssa(nir_inot(&b, is_clear));
980 nir_builder_instr_insert(&b, &discard->instr);
981
982 nir_ssa_def *clear_color = nir_load_var(&b, v_color);
983 if (blorp_key.indirect_clear_color && blorp->isl_dev->info->gen <= 8) {
984 /* Gen7-8 clear colors are stored as single 0/1 bits */
985 clear_color = nir_vec4(&b, blorp_nir_bit(&b, clear_color, 31),
986 blorp_nir_bit(&b, clear_color, 30),
987 blorp_nir_bit(&b, clear_color, 29),
988 blorp_nir_bit(&b, clear_color, 28));
989
990 if (!blorp_key.int_format)
991 clear_color = nir_i2f32(&b, clear_color);
992 }
993 nir_store_var(&b, frag_color, clear_color, 0xf);
994
995 struct brw_wm_prog_key wm_key;
996 brw_blorp_init_wm_prog_key(&wm_key);
997 wm_key.tex.compressed_multisample_layout_mask = 1;
998 wm_key.tex.msaa_16 = blorp_key.num_samples == 16;
999 wm_key.multisample_fbo = true;
1000
1001 struct brw_wm_prog_data prog_data;
1002 const unsigned *program =
1003 blorp_compile_fs(blorp, mem_ctx, b.shader, &wm_key, false,
1004 &prog_data);
1005
1006 bool result =
1007 blorp->upload_shader(batch, &blorp_key, sizeof(blorp_key),
1008 program, prog_data.base.program_size,
1009 &prog_data.base, sizeof(prog_data),
1010 &params->wm_prog_kernel, &params->wm_prog_data);
1011
1012 ralloc_free(mem_ctx);
1013 return result;
1014 }
1015
1016 void
1017 blorp_mcs_partial_resolve(struct blorp_batch *batch,
1018 struct blorp_surf *surf,
1019 enum isl_format format,
1020 uint32_t start_layer, uint32_t num_layers)
1021 {
1022 struct blorp_params params;
1023 blorp_params_init(&params);
1024
1025 assert(batch->blorp->isl_dev->info->gen >= 7);
1026
1027 params.x0 = 0;
1028 params.y0 = 0;
1029 params.x1 = surf->surf->logical_level0_px.width;
1030 params.y1 = surf->surf->logical_level0_px.height;
1031
1032 brw_blorp_surface_info_init(batch->blorp, &params.src, surf, 0,
1033 start_layer, format, false);
1034 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, 0,
1035 start_layer, format, true);
1036
1037 params.num_samples = params.dst.surf.samples;
1038 params.num_layers = num_layers;
1039 params.dst_clear_color_as_input = surf->clear_color_addr.buffer != NULL;
1040
1041 memcpy(&params.wm_inputs.clear_color,
1042 surf->clear_color.f32, sizeof(float) * 4);
1043
1044 if (!blorp_params_get_mcs_partial_resolve_kernel(batch, &params))
1045 return;
1046
1047 batch->blorp->exec(batch, &params);
1048 }
1049
1050 /** Clear a CCS to the "uncompressed" state
1051 *
1052 * This pass is the CCS equivalent of a "HiZ resolve". It sets the CCS values
1053 * for a given layer/level of a surface to 0x0 which is the "uncompressed"
1054 * state which tells the sampler to go look at the main surface.
1055 */
1056 void
1057 blorp_ccs_ambiguate(struct blorp_batch *batch,
1058 struct blorp_surf *surf,
1059 uint32_t level, uint32_t layer)
1060 {
1061 struct blorp_params params;
1062 blorp_params_init(&params);
1063
1064 assert(ISL_DEV_GEN(batch->blorp->isl_dev) >= 7);
1065
1066 const struct isl_format_layout *aux_fmtl =
1067 isl_format_get_layout(surf->aux_surf->format);
1068 assert(aux_fmtl->txc == ISL_TXC_CCS);
1069
1070 params.dst = (struct brw_blorp_surface_info) {
1071 .enabled = true,
1072 .addr = surf->aux_addr,
1073 .view = {
1074 .usage = ISL_SURF_USAGE_RENDER_TARGET_BIT,
1075 .format = ISL_FORMAT_R32G32B32A32_UINT,
1076 .base_level = 0,
1077 .base_array_layer = 0,
1078 .levels = 1,
1079 .array_len = 1,
1080 .swizzle = ISL_SWIZZLE_IDENTITY,
1081 },
1082 };
1083
1084 uint32_t z = 0;
1085 if (surf->surf->dim == ISL_SURF_DIM_3D) {
1086 z = layer;
1087 layer = 0;
1088 }
1089
1090 uint32_t offset_B, x_offset_el, y_offset_el;
1091 isl_surf_get_image_offset_el(surf->aux_surf, level, layer, z,
1092 &x_offset_el, &y_offset_el);
1093 isl_tiling_get_intratile_offset_el(surf->aux_surf->tiling, aux_fmtl->bpb,
1094 surf->aux_surf->row_pitch_B,
1095 x_offset_el, y_offset_el,
1096 &offset_B, &x_offset_el, &y_offset_el);
1097 params.dst.addr.offset += offset_B;
1098
1099 const uint32_t width_px =
1100 minify(surf->aux_surf->logical_level0_px.width, level);
1101 const uint32_t height_px =
1102 minify(surf->aux_surf->logical_level0_px.height, level);
1103 const uint32_t width_el = DIV_ROUND_UP(width_px, aux_fmtl->bw);
1104 const uint32_t height_el = DIV_ROUND_UP(height_px, aux_fmtl->bh);
1105
1106 struct isl_tile_info ccs_tile_info;
1107 isl_surf_get_tile_info(surf->aux_surf, &ccs_tile_info);
1108
1109 /* We're going to map it as a regular RGBA32_UINT surface. We need to
1110 * downscale a good deal. We start by computing the area on the CCS to
1111 * clear in units of Y-tiled cache lines.
1112 */
1113 uint32_t x_offset_cl, y_offset_cl, width_cl, height_cl;
1114 if (ISL_DEV_GEN(batch->blorp->isl_dev) >= 8) {
1115 /* From the Sky Lake PRM Vol. 12 in the section on planes:
1116 *
1117 * "The Color Control Surface (CCS) contains the compression status
1118 * of the cache-line pairs. The compression state of the cache-line
1119 * pair is specified by 2 bits in the CCS. Each CCS cache-line
1120 * represents an area on the main surface of 16x16 sets of 128 byte
1121 * Y-tiled cache-line-pairs. CCS is always Y tiled."
1122 *
1123 * Each 2-bit surface element in the CCS corresponds to a single
1124 * cache-line pair in the main surface. This means that 16x16 el block
1125 * in the CCS maps to a Y-tiled cache line. Fortunately, CCS layouts
1126 * are calculated with a very large alignment so we can round up to a
1127 * whole cache line without worrying about overdraw.
1128 */
1129
1130 /* On Broadwell and above, a CCS tile is the same as a Y tile when
1131 * viewed at the cache-line granularity. Fortunately, the horizontal
1132 * and vertical alignment requirements of the CCS are such that we can
1133 * align to an entire cache line without worrying about crossing over
1134 * from one LOD to another.
1135 */
1136 const uint32_t x_el_per_cl = ccs_tile_info.logical_extent_el.w / 8;
1137 const uint32_t y_el_per_cl = ccs_tile_info.logical_extent_el.h / 8;
1138 assert(surf->aux_surf->image_alignment_el.w % x_el_per_cl == 0);
1139 assert(surf->aux_surf->image_alignment_el.h % y_el_per_cl == 0);
1140
1141 assert(x_offset_el % x_el_per_cl == 0);
1142 assert(y_offset_el % y_el_per_cl == 0);
1143 x_offset_cl = x_offset_el / x_el_per_cl;
1144 y_offset_cl = y_offset_el / y_el_per_cl;
1145 width_cl = DIV_ROUND_UP(width_el, x_el_per_cl);
1146 height_cl = DIV_ROUND_UP(height_el, y_el_per_cl);
1147 } else {
1148 /* On gen7, the CCS tiling is not so nice. However, there we are
1149 * guaranteed that we only have a single level and slice so we don't
1150 * have to worry about it and can just align to a whole tile.
1151 */
1152 assert(surf->aux_surf->logical_level0_px.depth == 1);
1153 assert(surf->aux_surf->logical_level0_px.array_len == 1);
1154 assert(x_offset_el == 0 && y_offset_el == 0);
1155 const uint32_t width_tl =
1156 DIV_ROUND_UP(width_el, ccs_tile_info.logical_extent_el.w);
1157 const uint32_t height_tl =
1158 DIV_ROUND_UP(height_el, ccs_tile_info.logical_extent_el.h);
1159 x_offset_cl = 0;
1160 y_offset_cl = 0;
1161 width_cl = width_tl * 8;
1162 height_cl = height_tl * 8;
1163 }
1164
1165 /* We're going to use a RGBA32 format so as to write data as quickly as
1166 * possible. A y-tiled cache line will then be 1x4 px.
1167 */
1168 const uint32_t x_offset_rgba_px = x_offset_cl;
1169 const uint32_t y_offset_rgba_px = y_offset_cl * 4;
1170 const uint32_t width_rgba_px = width_cl;
1171 const uint32_t height_rgba_px = height_cl * 4;
1172
1173 MAYBE_UNUSED bool ok =
1174 isl_surf_init(batch->blorp->isl_dev, &params.dst.surf,
1175 .dim = ISL_SURF_DIM_2D,
1176 .format = ISL_FORMAT_R32G32B32A32_UINT,
1177 .width = width_rgba_px + x_offset_rgba_px,
1178 .height = height_rgba_px + y_offset_rgba_px,
1179 .depth = 1,
1180 .levels = 1,
1181 .array_len = 1,
1182 .samples = 1,
1183 .row_pitch_B = surf->aux_surf->row_pitch_B,
1184 .usage = ISL_SURF_USAGE_RENDER_TARGET_BIT,
1185 .tiling_flags = ISL_TILING_Y0_BIT);
1186 assert(ok);
1187
1188 params.x0 = x_offset_rgba_px;
1189 params.y0 = y_offset_rgba_px;
1190 params.x1 = x_offset_rgba_px + width_rgba_px;
1191 params.y1 = y_offset_rgba_px + height_rgba_px;
1192
1193 /* A CCS value of 0 means "uncompressed." */
1194 memset(&params.wm_inputs.clear_color, 0,
1195 sizeof(params.wm_inputs.clear_color));
1196
1197 if (!blorp_params_get_clear_kernel(batch, &params, true, false))
1198 return;
1199
1200 batch->blorp->exec(batch, &params);
1201 }