intel/blorp: Handle clearing of A4B4G4R4 on all platforms
[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
29 #include "blorp_priv.h"
30 #include "brw_defines.h"
31
32 #include "compiler/nir/nir_builder.h"
33
34 #define FILE_DEBUG_FLAG DEBUG_BLORP
35
36 struct brw_blorp_const_color_prog_key
37 {
38 enum blorp_shader_type shader_type; /* Must be BLORP_SHADER_TYPE_CLEAR */
39 bool use_simd16_replicated_data;
40 bool pad[3];
41 };
42
43 static void
44 blorp_params_get_clear_kernel(struct blorp_context *blorp,
45 struct blorp_params *params,
46 bool use_replicated_data)
47 {
48 const struct brw_blorp_const_color_prog_key blorp_key = {
49 .shader_type = BLORP_SHADER_TYPE_CLEAR,
50 .use_simd16_replicated_data = use_replicated_data,
51 };
52
53 if (blorp->lookup_shader(blorp, &blorp_key, sizeof(blorp_key),
54 &params->wm_prog_kernel, &params->wm_prog_data))
55 return;
56
57 void *mem_ctx = ralloc_context(NULL);
58
59 nir_builder b;
60 nir_builder_init_simple_shader(&b, mem_ctx, MESA_SHADER_FRAGMENT, NULL);
61 b.shader->info->name = ralloc_strdup(b.shader, "BLORP-clear");
62
63 nir_variable *v_color =
64 BLORP_CREATE_NIR_INPUT(b.shader, clear_color, glsl_vec4_type());
65
66 nir_variable *frag_color = nir_variable_create(b.shader, nir_var_shader_out,
67 glsl_vec4_type(),
68 "gl_FragColor");
69 frag_color->data.location = FRAG_RESULT_COLOR;
70
71 nir_copy_var(&b, frag_color, v_color);
72
73 struct brw_wm_prog_key wm_key;
74 brw_blorp_init_wm_prog_key(&wm_key);
75
76 struct brw_wm_prog_data prog_data;
77 unsigned program_size;
78 const unsigned *program =
79 blorp_compile_fs(blorp, mem_ctx, b.shader, &wm_key, use_replicated_data,
80 &prog_data, &program_size);
81
82 blorp->upload_shader(blorp, &blorp_key, sizeof(blorp_key),
83 program, program_size,
84 &prog_data.base, sizeof(prog_data),
85 &params->wm_prog_kernel, &params->wm_prog_data);
86
87 ralloc_free(mem_ctx);
88 }
89
90 struct layer_offset_vs_key {
91 enum blorp_shader_type shader_type;
92 unsigned num_inputs;
93 };
94
95 /* In the case of doing attachment clears, we are using a surface state that
96 * is handed to us so we can't set (and don't even know) the base array layer.
97 * In order to do a layered clear in this scenario, we need some way of adding
98 * the base array layer to the instance id. Unfortunately, our hardware has
99 * no real concept of "base instance", so we have to do it manually in a
100 * vertex shader.
101 */
102 static void
103 blorp_params_get_layer_offset_vs(struct blorp_context *blorp,
104 struct blorp_params *params)
105 {
106 struct layer_offset_vs_key blorp_key = {
107 .shader_type = BLORP_SHADER_TYPE_LAYER_OFFSET_VS,
108 };
109
110 if (params->wm_prog_data)
111 blorp_key.num_inputs = params->wm_prog_data->num_varying_inputs;
112
113 if (blorp->lookup_shader(blorp, &blorp_key, sizeof(blorp_key),
114 &params->vs_prog_kernel, &params->vs_prog_data))
115 return;
116
117 void *mem_ctx = ralloc_context(NULL);
118
119 nir_builder b;
120 nir_builder_init_simple_shader(&b, mem_ctx, MESA_SHADER_VERTEX, NULL);
121 b.shader->info->name = ralloc_strdup(b.shader, "BLORP-layer-offset-vs");
122
123 const struct glsl_type *uvec4_type = glsl_vector_type(GLSL_TYPE_UINT, 4);
124
125 /* First we deal with the header which has instance and base instance */
126 nir_variable *a_header = nir_variable_create(b.shader, nir_var_shader_in,
127 uvec4_type, "header");
128 a_header->data.location = VERT_ATTRIB_GENERIC0;
129
130 nir_variable *v_layer = nir_variable_create(b.shader, nir_var_shader_out,
131 glsl_int_type(), "layer_id");
132 v_layer->data.location = VARYING_SLOT_LAYER;
133
134 /* Compute the layer id */
135 nir_ssa_def *header = nir_load_var(&b, a_header);
136 nir_ssa_def *base_layer = nir_channel(&b, header, 0);
137 nir_ssa_def *instance = nir_channel(&b, header, 1);
138 nir_store_var(&b, v_layer, nir_iadd(&b, instance, base_layer), 0x1);
139
140 /* Then we copy the vertex from the next slot to VARYING_SLOT_POS */
141 nir_variable *a_vertex = nir_variable_create(b.shader, nir_var_shader_in,
142 glsl_vec4_type(), "a_vertex");
143 a_vertex->data.location = VERT_ATTRIB_GENERIC1;
144
145 nir_variable *v_pos = nir_variable_create(b.shader, nir_var_shader_out,
146 glsl_vec4_type(), "v_pos");
147 v_pos->data.location = VARYING_SLOT_POS;
148
149 nir_copy_var(&b, v_pos, a_vertex);
150
151 /* Then we copy everything else */
152 for (unsigned i = 0; i < blorp_key.num_inputs; i++) {
153 nir_variable *a_in = nir_variable_create(b.shader, nir_var_shader_in,
154 uvec4_type, "input");
155 a_in->data.location = VERT_ATTRIB_GENERIC2 + i;
156
157 nir_variable *v_out = nir_variable_create(b.shader, nir_var_shader_out,
158 uvec4_type, "output");
159 v_out->data.location = VARYING_SLOT_VAR0 + i;
160
161 nir_copy_var(&b, v_out, a_in);
162 }
163
164 struct brw_vs_prog_data vs_prog_data;
165 memset(&vs_prog_data, 0, sizeof(vs_prog_data));
166
167 unsigned program_size;
168 const unsigned *program =
169 blorp_compile_vs(blorp, mem_ctx, b.shader, &vs_prog_data, &program_size);
170
171 blorp->upload_shader(blorp, &blorp_key, sizeof(blorp_key),
172 program, program_size,
173 &vs_prog_data.base.base, sizeof(vs_prog_data),
174 &params->vs_prog_kernel, &params->vs_prog_data);
175
176 ralloc_free(mem_ctx);
177 }
178
179 /* The x0, y0, x1, and y1 parameters must already be populated with the render
180 * area of the framebuffer to be cleared.
181 */
182 static void
183 get_fast_clear_rect(const struct isl_device *dev,
184 const struct isl_surf *aux_surf,
185 unsigned *x0, unsigned *y0,
186 unsigned *x1, unsigned *y1)
187 {
188 unsigned int x_align, y_align;
189 unsigned int x_scaledown, y_scaledown;
190
191 /* Only single sampled surfaces need to (and actually can) be resolved. */
192 if (aux_surf->usage == ISL_SURF_USAGE_CCS_BIT) {
193 /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
194 * Target(s)", beneath the "Fast Color Clear" bullet (p327):
195 *
196 * Clear pass must have a clear rectangle that must follow
197 * alignment rules in terms of pixels and lines as shown in the
198 * table below. Further, the clear-rectangle height and width
199 * must be multiple of the following dimensions. If the height
200 * and width of the render target being cleared do not meet these
201 * requirements, an MCS buffer can be created such that it
202 * follows the requirement and covers the RT.
203 *
204 * The alignment size in the table that follows is related to the
205 * alignment size that is baked into the CCS surface format but with X
206 * alignment multiplied by 16 and Y alignment multiplied by 32.
207 */
208 x_align = isl_format_get_layout(aux_surf->format)->bw;
209 y_align = isl_format_get_layout(aux_surf->format)->bh;
210
211 x_align *= 16;
212
213 /* SKL+ line alignment requirement for Y-tiled are half those of the prior
214 * generations.
215 */
216 if (dev->info->gen >= 9)
217 y_align *= 16;
218 else
219 y_align *= 32;
220
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 * In order to optimize the performance MCS buffer (when bound to
225 * 1X RT) clear similarly to MCS buffer clear for MSRT case,
226 * clear rect is required to be scaled by the following factors
227 * in the horizontal and vertical directions:
228 *
229 * The X and Y scale down factors in the table that follows are each
230 * equal to half the alignment value computed above.
231 */
232 x_scaledown = x_align / 2;
233 y_scaledown = y_align / 2;
234
235 /* From BSpec: 3D-Media-GPGPU Engine > 3D Pipeline > Pixel > Pixel
236 * Backend > MCS Buffer for Render Target(s) [DevIVB+] > Table "Color
237 * Clear of Non-MultiSampled Render Target Restrictions":
238 *
239 * Clear rectangle must be aligned to two times the number of
240 * pixels in the table shown below due to 16x16 hashing across the
241 * slice.
242 */
243 x_align *= 2;
244 y_align *= 2;
245 } else {
246 assert(aux_surf->usage == ISL_SURF_USAGE_MCS_BIT);
247
248 /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
249 * Target(s)", beneath the "MSAA Compression" bullet (p326):
250 *
251 * Clear pass for this case requires that scaled down primitive
252 * is sent down with upper left co-ordinate to coincide with
253 * actual rectangle being cleared. For MSAA, clear rectangle’s
254 * height and width need to as show in the following table in
255 * terms of (width,height) of the RT.
256 *
257 * MSAA Width of Clear Rect Height of Clear Rect
258 * 2X Ceil(1/8*width) Ceil(1/2*height)
259 * 4X Ceil(1/8*width) Ceil(1/2*height)
260 * 8X Ceil(1/2*width) Ceil(1/2*height)
261 * 16X width Ceil(1/2*height)
262 *
263 * The text "with upper left co-ordinate to coincide with actual
264 * rectangle being cleared" is a little confusing--it seems to imply
265 * that to clear a rectangle from (x,y) to (x+w,y+h), one needs to
266 * feed the pipeline using the rectangle (x,y) to
267 * (x+Ceil(w/N),y+Ceil(h/2)), where N is either 2 or 8 depending on
268 * the number of samples. Experiments indicate that this is not
269 * quite correct; actually, what the hardware appears to do is to
270 * align whatever rectangle is sent down the pipeline to the nearest
271 * multiple of 2x2 blocks, and then scale it up by a factor of N
272 * horizontally and 2 vertically. So the resulting alignment is 4
273 * vertically and either 4 or 16 horizontally, and the scaledown
274 * factor is 2 vertically and either 2 or 8 horizontally.
275 */
276 switch (aux_surf->format) {
277 case ISL_FORMAT_MCS_2X:
278 case ISL_FORMAT_MCS_4X:
279 x_scaledown = 8;
280 break;
281 case ISL_FORMAT_MCS_8X:
282 x_scaledown = 2;
283 break;
284 case ISL_FORMAT_MCS_16X:
285 x_scaledown = 1;
286 break;
287 default:
288 unreachable("Unexpected MCS format for fast clear");
289 }
290 y_scaledown = 2;
291 x_align = x_scaledown * 2;
292 y_align = y_scaledown * 2;
293 }
294
295 *x0 = ROUND_DOWN_TO(*x0, x_align) / x_scaledown;
296 *y0 = ROUND_DOWN_TO(*y0, y_align) / y_scaledown;
297 *x1 = ALIGN(*x1, x_align) / x_scaledown;
298 *y1 = ALIGN(*y1, y_align) / y_scaledown;
299 }
300
301 void
302 blorp_fast_clear(struct blorp_batch *batch,
303 const struct blorp_surf *surf, enum isl_format format,
304 uint32_t level, uint32_t start_layer, uint32_t num_layers,
305 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
306 {
307 struct blorp_params params;
308 blorp_params_init(&params);
309 params.num_layers = num_layers;
310
311 params.x0 = x0;
312 params.y0 = y0;
313 params.x1 = x1;
314 params.y1 = y1;
315
316 memset(&params.wm_inputs.clear_color, 0xff, 4*sizeof(float));
317 params.fast_clear_op = BLORP_FAST_CLEAR_OP_CLEAR;
318
319 get_fast_clear_rect(batch->blorp->isl_dev, surf->aux_surf,
320 &params.x0, &params.y0, &params.x1, &params.y1);
321
322 blorp_params_get_clear_kernel(batch->blorp, &params, true);
323
324 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
325 start_layer, format, true);
326 params.num_samples = params.dst.surf.samples;
327
328 batch->blorp->exec(batch, &params);
329 }
330
331
332 void
333 blorp_clear(struct blorp_batch *batch,
334 const struct blorp_surf *surf,
335 enum isl_format format, struct isl_swizzle swizzle,
336 uint32_t level, uint32_t start_layer, uint32_t num_layers,
337 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
338 union isl_color_value clear_color,
339 const bool color_write_disable[4])
340 {
341 struct blorp_params params;
342 blorp_params_init(&params);
343
344 params.x0 = x0;
345 params.y0 = y0;
346 params.x1 = x1;
347 params.y1 = y1;
348
349 if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
350 clear_color.u32[0] = float3_to_rgb9e5(clear_color.f32);
351 format = ISL_FORMAT_R32_UINT;
352 } else if (format == ISL_FORMAT_A4B4G4R4_UNORM) {
353 /* Broadwell and earlier cannot render to this format so we need to work
354 * around it by swapping the colors around and using B4G4R4A4 instead.
355 */
356
357 /* First, we apply the swizzle. */
358 union isl_color_value old;
359 assert((unsigned)(swizzle.r - ISL_CHANNEL_SELECT_RED) < 4);
360 assert((unsigned)(swizzle.g - ISL_CHANNEL_SELECT_RED) < 4);
361 assert((unsigned)(swizzle.b - ISL_CHANNEL_SELECT_RED) < 4);
362 assert((unsigned)(swizzle.a - ISL_CHANNEL_SELECT_RED) < 4);
363 old.u32[swizzle.r - ISL_CHANNEL_SELECT_RED] = clear_color.u32[0];
364 old.u32[swizzle.g - ISL_CHANNEL_SELECT_RED] = clear_color.u32[1];
365 old.u32[swizzle.b - ISL_CHANNEL_SELECT_RED] = clear_color.u32[2];
366 old.u32[swizzle.a - ISL_CHANNEL_SELECT_RED] = clear_color.u32[3];
367 swizzle = ISL_SWIZZLE_IDENTITY;
368
369 /* Now we re-order for the new format */
370 clear_color.u32[0] = old.u32[1];
371 clear_color.u32[1] = old.u32[2];
372 clear_color.u32[2] = old.u32[3];
373 clear_color.u32[3] = old.u32[0];
374 format = ISL_FORMAT_B4G4R4A4_UNORM;
375 }
376
377 memcpy(&params.wm_inputs.clear_color, clear_color.f32, sizeof(float) * 4);
378
379 bool use_simd16_replicated_data = true;
380
381 /* From the SNB PRM (Vol4_Part1):
382 *
383 * "Replicated data (Message Type = 111) is only supported when
384 * accessing tiled memory. Using this Message Type to access linear
385 * (untiled) memory is UNDEFINED."
386 */
387 if (surf->surf->tiling == ISL_TILING_LINEAR)
388 use_simd16_replicated_data = false;
389
390 /* Constant color writes ignore everyting in blend and color calculator
391 * state. This is not documented.
392 */
393 if (color_write_disable) {
394 for (unsigned i = 0; i < 4; i++) {
395 params.color_write_disable[i] = color_write_disable[i];
396 if (color_write_disable[i])
397 use_simd16_replicated_data = false;
398 }
399 }
400
401 blorp_params_get_clear_kernel(batch->blorp, &params,
402 use_simd16_replicated_data);
403
404 while (num_layers > 0) {
405 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf, level,
406 start_layer, format, true);
407 params.dst.view.swizzle = swizzle;
408
409 params.num_samples = params.dst.surf.samples;
410
411 /* We may be restricted on the number of layers we can bind at any one
412 * time. In particular, Sandy Bridge has a maximum number of layers of
413 * 512 but a maximum 3D texture size is much larger.
414 */
415 params.num_layers = MIN2(params.dst.view.array_len, num_layers);
416 batch->blorp->exec(batch, &params);
417
418 start_layer += params.num_layers;
419 num_layers -= params.num_layers;
420 }
421 }
422
423 void
424 blorp_clear_depth_stencil(struct blorp_batch *batch,
425 const struct blorp_surf *depth,
426 const struct blorp_surf *stencil,
427 uint32_t level, uint32_t start_layer,
428 uint32_t num_layers,
429 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
430 bool clear_depth, float depth_value,
431 uint8_t stencil_mask, uint8_t stencil_value)
432 {
433 struct blorp_params params;
434 blorp_params_init(&params);
435
436 params.x0 = x0;
437 params.y0 = y0;
438 params.x1 = x1;
439 params.y1 = y1;
440
441 while (num_layers > 0) {
442 params.num_layers = num_layers;
443
444 if (stencil_mask) {
445 brw_blorp_surface_info_init(batch->blorp, &params.stencil, stencil,
446 level, start_layer,
447 ISL_FORMAT_UNSUPPORTED, true);
448 params.stencil_mask = stencil_mask;
449 params.stencil_ref = stencil_value;
450
451 params.dst.surf.samples = params.stencil.surf.samples;
452 params.dst.surf.logical_level0_px =
453 params.stencil.surf.logical_level0_px;
454 params.dst.view = params.depth.view;
455
456 params.num_samples = params.stencil.surf.samples;
457
458 /* We may be restricted on the number of layers we can bind at any
459 * one time. In particular, Sandy Bridge has a maximum number of
460 * layers of 512 but a maximum 3D texture size is much larger.
461 */
462 if (params.stencil.view.array_len < params.num_layers)
463 params.num_layers = params.stencil.view.array_len;
464 }
465
466 if (clear_depth) {
467 brw_blorp_surface_info_init(batch->blorp, &params.depth, depth,
468 level, start_layer,
469 ISL_FORMAT_UNSUPPORTED, true);
470 params.z = depth_value;
471 params.depth_format =
472 isl_format_get_depth_format(depth->surf->format, false);
473
474 params.dst.surf.samples = params.depth.surf.samples;
475 params.dst.surf.logical_level0_px =
476 params.depth.surf.logical_level0_px;
477 params.dst.view = params.depth.view;
478
479 params.num_samples = params.depth.surf.samples;
480
481 /* We may be restricted on the number of layers we can bind at any
482 * one time. In particular, Sandy Bridge has a maximum number of
483 * layers of 512 but a maximum 3D texture size is much larger.
484 */
485 if (params.depth.view.array_len < params.num_layers)
486 params.num_layers = params.depth.view.array_len;
487 }
488
489 batch->blorp->exec(batch, &params);
490
491 start_layer += params.num_layers;
492 num_layers -= params.num_layers;
493 }
494 }
495
496 bool
497 blorp_can_hiz_clear_depth(uint8_t gen, enum isl_format format,
498 uint32_t num_samples,
499 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1)
500 {
501 /* This function currently doesn't support any gen prior to gen8 */
502 assert(gen >= 8);
503
504 if (gen == 8 && format == ISL_FORMAT_R16_UNORM) {
505 /* Apply the D16 alignment restrictions. On BDW, HiZ has an 8x4 sample
506 * block with the following property: as the number of samples increases,
507 * the number of pixels representable by this block decreases by a factor
508 * of the sample dimensions. Sample dimensions scale following the MSAA
509 * interleaved pattern.
510 *
511 * Sample|Sample|Pixel
512 * Count |Dim |Dim
513 * ===================
514 * 1 | 1x1 | 8x4
515 * 2 | 2x1 | 4x4
516 * 4 | 2x2 | 4x2
517 * 8 | 4x2 | 2x2
518 * 16 | 4x4 | 2x1
519 *
520 * Table: Pixel Dimensions in a HiZ Sample Block Pre-SKL
521 */
522 const struct isl_extent2d sa_block_dim =
523 isl_get_interleaved_msaa_px_size_sa(num_samples);
524 const uint8_t align_px_w = 8 / sa_block_dim.w;
525 const uint8_t align_px_h = 4 / sa_block_dim.h;
526
527 /* Fast depth clears clear an entire sample block at a time. As a result,
528 * the rectangle must be aligned to the dimensions of the encompassing
529 * pixel block for a successful operation.
530 *
531 * Fast clears can still work if the upper-left corner is aligned and the
532 * bottom-rigtht corner touches the edge of a depth buffer whose extent
533 * is unaligned. This is because each miplevel in the depth buffer is
534 * padded by the Pixel Dim (similar to a standard compressed texture).
535 * In this case, the clear rectangle could be padded by to match the full
536 * depth buffer extent but to support multiple clearing techniques, we
537 * chose to be unaware of the depth buffer's extent and thus don't handle
538 * this case.
539 */
540 if (x0 % align_px_w || y0 % align_px_h ||
541 x1 % align_px_w || y1 % align_px_h)
542 return false;
543 }
544 return true;
545 }
546
547 /* Given a depth stencil attachment, this function performs a fast depth clear
548 * on a depth portion and a regular clear on the stencil portion. When
549 * performing a fast depth clear on the depth portion, the HiZ buffer is simply
550 * tagged as cleared so the depth clear value is not actually needed.
551 */
552 void
553 blorp_gen8_hiz_clear_attachments(struct blorp_batch *batch,
554 uint32_t num_samples,
555 uint32_t x0, uint32_t y0,
556 uint32_t x1, uint32_t y1,
557 bool clear_depth, bool clear_stencil,
558 uint8_t stencil_value)
559 {
560 assert(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL);
561
562 struct blorp_params params;
563 blorp_params_init(&params);
564 params.num_layers = 1;
565 params.hiz_op = BLORP_HIZ_OP_DEPTH_CLEAR;
566 params.x0 = x0;
567 params.y0 = y0;
568 params.x1 = x1;
569 params.y1 = y1;
570 params.num_samples = num_samples;
571 params.depth.enabled = clear_depth;
572 params.stencil.enabled = clear_stencil;
573 params.stencil_ref = stencil_value;
574 batch->blorp->exec(batch, &params);
575 }
576
577 /** Clear active color/depth/stencili attachments
578 *
579 * This function performs a clear operation on the currently bound
580 * color/depth/stencil attachments. It is assumed that any information passed
581 * in here is valid, consistent, and in-bounds relative to the currently
582 * attached depth/stencil. The binding_table_offset parameter is the 32-bit
583 * offset relative to surface state base address where pre-baked binding table
584 * that we are to use lives. If clear_color is false, binding_table_offset
585 * must point to a binding table with one entry which is a valid null surface
586 * that matches the currently bound depth and stencil.
587 */
588 void
589 blorp_clear_attachments(struct blorp_batch *batch,
590 uint32_t binding_table_offset,
591 enum isl_format depth_format,
592 uint32_t num_samples,
593 uint32_t start_layer, uint32_t num_layers,
594 uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1,
595 bool clear_color, union isl_color_value color_value,
596 bool clear_depth, float depth_value,
597 uint8_t stencil_mask, uint8_t stencil_value)
598 {
599 struct blorp_params params;
600 blorp_params_init(&params);
601
602 assert(batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL);
603
604 params.x0 = x0;
605 params.y0 = y0;
606 params.x1 = x1;
607 params.y1 = y1;
608
609 params.use_pre_baked_binding_table = true;
610 params.pre_baked_binding_table_offset = binding_table_offset;
611
612 params.num_layers = num_layers;
613 params.num_samples = num_samples;
614
615 if (clear_color) {
616 params.dst.enabled = true;
617
618 memcpy(&params.wm_inputs.clear_color, color_value.f32, sizeof(float) * 4);
619
620 /* Unfortunately, without knowing whether or not our destination surface
621 * is tiled or not, we have to assume it may be linear. This means no
622 * SIMD16_REPDATA for us. :-(
623 */
624 blorp_params_get_clear_kernel(batch->blorp, &params, false);
625 }
626
627 if (clear_depth) {
628 params.depth.enabled = true;
629
630 params.z = depth_value;
631 params.depth_format = isl_format_get_depth_format(depth_format, false);
632 }
633
634 if (stencil_mask) {
635 params.stencil.enabled = true;
636
637 params.stencil_mask = stencil_mask;
638 params.stencil_ref = stencil_value;
639 }
640
641 blorp_params_get_layer_offset_vs(batch->blorp, &params);
642 params.vs_inputs.base_layer = start_layer;
643
644 batch->blorp->exec(batch, &params);
645 }
646
647 void
648 blorp_ccs_resolve(struct blorp_batch *batch,
649 struct blorp_surf *surf, uint32_t level, uint32_t layer,
650 enum isl_format format,
651 enum blorp_fast_clear_op resolve_op)
652 {
653 struct blorp_params params;
654 blorp_params_init(&params);
655
656 /* Layered and mipmapped fast clear is only available from Gen8 onwards. */
657 assert(ISL_DEV_GEN(batch->blorp->isl_dev) >= 8 ||
658 (level == 0 && layer == 0));
659
660 brw_blorp_surface_info_init(batch->blorp, &params.dst, surf,
661 level, layer, format, true);
662
663 /* From the Ivy Bridge PRM, Vol2 Part1 11.9 "Render Target Resolve":
664 *
665 * A rectangle primitive must be scaled down by the following factors
666 * with respect to render target being resolved.
667 *
668 * The scaledown factors in the table that follows are related to the block
669 * size of the CCS format. For IVB and HSW, we divide by two, for BDW we
670 * multiply by 8 and 16. On Sky Lake, we multiply by 8.
671 */
672 const struct isl_format_layout *aux_fmtl =
673 isl_format_get_layout(params.dst.aux_surf.format);
674 assert(aux_fmtl->txc == ISL_TXC_CCS);
675
676 unsigned x_scaledown, y_scaledown;
677 if (ISL_DEV_GEN(batch->blorp->isl_dev) >= 9) {
678 x_scaledown = aux_fmtl->bw * 8;
679 y_scaledown = aux_fmtl->bh * 8;
680 } else if (ISL_DEV_GEN(batch->blorp->isl_dev) >= 8) {
681 x_scaledown = aux_fmtl->bw * 8;
682 y_scaledown = aux_fmtl->bh * 16;
683 } else {
684 x_scaledown = aux_fmtl->bw / 2;
685 y_scaledown = aux_fmtl->bh / 2;
686 }
687 params.x0 = params.y0 = 0;
688 params.x1 = minify(params.dst.aux_surf.logical_level0_px.width, level);
689 params.y1 = minify(params.dst.aux_surf.logical_level0_px.height, level);
690 params.x1 = ALIGN(params.x1, x_scaledown) / x_scaledown;
691 params.y1 = ALIGN(params.y1, y_scaledown) / y_scaledown;
692
693 if (batch->blorp->isl_dev->info->gen >= 9) {
694 assert(resolve_op == BLORP_FAST_CLEAR_OP_RESOLVE_FULL ||
695 resolve_op == BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL);
696 } else {
697 /* Broadwell and earlier do not have a partial resolve */
698 assert(resolve_op == BLORP_FAST_CLEAR_OP_RESOLVE_FULL);
699 }
700 params.fast_clear_op = resolve_op;
701
702 /* Note: there is no need to initialize push constants because it doesn't
703 * matter what data gets dispatched to the render target. However, we must
704 * ensure that the fragment shader delivers the data using the "replicated
705 * color" message.
706 */
707
708 blorp_params_get_clear_kernel(batch->blorp, &params, true);
709
710 batch->blorp->exec(batch, &params);
711 }