19f464c52Smaya/*
29f464c52Smaya * Copyright © 2017 Intel Corporation
39f464c52Smaya *
49f464c52Smaya * Permission is hereby granted, free of charge, to any person obtaining a
59f464c52Smaya * copy of this software and associated documentation files (the "Software"),
69f464c52Smaya * to deal in the Software without restriction, including without limitation
79f464c52Smaya * the rights to use, copy, modify, merge, publish, distribute, sublicense,
89f464c52Smaya * and/or sell copies of the Software, and to permit persons to whom the
99f464c52Smaya * Software is furnished to do so, subject to the following conditions:
109f464c52Smaya *
119f464c52Smaya * The above copyright notice and this permission notice shall be included
129f464c52Smaya * in all copies or substantial portions of the Software.
139f464c52Smaya *
149f464c52Smaya * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
159f464c52Smaya * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
169f464c52Smaya * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
179f464c52Smaya * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
189f464c52Smaya * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
199f464c52Smaya * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
209f464c52Smaya * DEALINGS IN THE SOFTWARE.
219f464c52Smaya */
229f464c52Smaya
239f464c52Smaya#include <stdio.h>
249f464c52Smaya#include <errno.h>
259f464c52Smaya#include "pipe/p_defines.h"
269f464c52Smaya#include "pipe/p_state.h"
279f464c52Smaya#include "pipe/p_context.h"
289f464c52Smaya#include "pipe/p_screen.h"
299f464c52Smaya#include "util/u_inlines.h"
307ec681f3Smrg#include "util/format/u_format.h"
319f464c52Smaya#include "util/u_upload_mgr.h"
329f464c52Smaya#include "util/ralloc.h"
339f464c52Smaya#include "iris_context.h"
349f464c52Smaya#include "iris_resource.h"
359f464c52Smaya#include "iris_screen.h"
369f464c52Smaya#include "intel/compiler/brw_compiler.h"
379f464c52Smaya
389f464c52Smayastatic bool
399f464c52Smayairis_is_color_fast_clear_compatible(struct iris_context *ice,
409f464c52Smaya                                    enum isl_format format,
419f464c52Smaya                                    const union isl_color_value color)
429f464c52Smaya{
439f464c52Smaya   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
447ec681f3Smrg   const struct intel_device_info *devinfo = &batch->screen->devinfo;
459f464c52Smaya
469f464c52Smaya   if (isl_format_has_int_channel(format)) {
477ec681f3Smrg      perf_debug(&ice->dbg, "Integer fast clear not enabled for %s\n",
489f464c52Smaya                 isl_format_get_name(format));
499f464c52Smaya      return false;
509f464c52Smaya   }
519f464c52Smaya
529f464c52Smaya   for (int i = 0; i < 4; i++) {
539f464c52Smaya      if (!isl_format_has_color_component(format, i)) {
549f464c52Smaya         continue;
559f464c52Smaya      }
569f464c52Smaya
577ec681f3Smrg      if (devinfo->ver < 9 &&
589f464c52Smaya          color.f32[i] != 0.0f && color.f32[i] != 1.0f) {
599f464c52Smaya         return false;
609f464c52Smaya      }
619f464c52Smaya   }
629f464c52Smaya
639f464c52Smaya   return true;
649f464c52Smaya}
659f464c52Smaya
669f464c52Smayastatic bool
679f464c52Smayacan_fast_clear_color(struct iris_context *ice,
689f464c52Smaya                     struct pipe_resource *p_res,
699f464c52Smaya                     unsigned level,
709f464c52Smaya                     const struct pipe_box *box,
717ec681f3Smrg                     bool render_condition_enabled,
729f464c52Smaya                     enum isl_format render_format,
739f464c52Smaya                     union isl_color_value color)
749f464c52Smaya{
759f464c52Smaya   struct iris_resource *res = (void *) p_res;
769f464c52Smaya
777ec681f3Smrg   if (INTEL_DEBUG(DEBUG_NO_FAST_CLEAR))
789f464c52Smaya      return false;
799f464c52Smaya
807ec681f3Smrg   if (!isl_aux_usage_has_fast_clears(res->aux.usage))
819f464c52Smaya      return false;
829f464c52Smaya
839f464c52Smaya   /* Check for partial clear */
849f464c52Smaya   if (box->x > 0 || box->y > 0 ||
857ec681f3Smrg       box->width < minify(p_res->width0, level) ||
867ec681f3Smrg       box->height < minify(p_res->height0, level)) {
877ec681f3Smrg      return false;
887ec681f3Smrg   }
897ec681f3Smrg
907ec681f3Smrg   /* Avoid conditional fast clears to maintain correct tracking of the aux
917ec681f3Smrg    * state (see iris_resource_finish_write for more info). Note that partial
927ec681f3Smrg    * fast clears (if they existed) would not pose a problem with conditional
937ec681f3Smrg    * rendering.
947ec681f3Smrg    */
957ec681f3Smrg   if (render_condition_enabled &&
967ec681f3Smrg       ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {
977ec681f3Smrg      return false;
987ec681f3Smrg   }
997ec681f3Smrg
1007ec681f3Smrg   /* Disable sRGB fast-clears for non-0/1 color values. For texturing and
1017ec681f3Smrg    * draw calls, HW expects the clear color to be in two different color
1027ec681f3Smrg    * spaces after sRGB fast-clears - sRGB in the former and linear in the
1037ec681f3Smrg    * latter. By limiting the allowable values to 0/1, both color space
1047ec681f3Smrg    * requirements are satisfied.
1057ec681f3Smrg    */
1067ec681f3Smrg   if (isl_format_is_srgb(render_format) &&
1077ec681f3Smrg       !isl_color_value_is_zero_one(color, render_format)) {
1089f464c52Smaya      return false;
1099f464c52Smaya   }
1109f464c52Smaya
1119f464c52Smaya   /* We store clear colors as floats or uints as needed.  If there are
1129f464c52Smaya    * texture views in play, the formats will not properly be respected
1139f464c52Smaya    * during resolves because the resolve operations only know about the
1149f464c52Smaya    * resource and not the renderbuffer.
1159f464c52Smaya    */
1167ec681f3Smrg   if (!iris_render_formats_color_compatible(render_format, res->surf.format,
1177ec681f3Smrg                                             color, false)) {
1189f464c52Smaya      return false;
1199f464c52Smaya   }
1209f464c52Smaya
1217ec681f3Smrg   if (!iris_is_color_fast_clear_compatible(ice, res->surf.format, color))
1227ec681f3Smrg      return false;
1239f464c52Smaya
1247ec681f3Smrg   /* The RENDER_SURFACE_STATE page for TGL says:
1257ec681f3Smrg    *
1267ec681f3Smrg    *   For an 8 bpp surface with NUM_MULTISAMPLES = 1, Surface Width not
1277ec681f3Smrg    *   multiple of 64 pixels and more than 1 mip level in the view, Fast Clear
1287ec681f3Smrg    *   is not supported when AUX_CCS_E is set in this field.
1297ec681f3Smrg    *
1307ec681f3Smrg    * The granularity of a fast-clear is one CCS element. For an 8 bpp primary
1317ec681f3Smrg    * surface, this maps to 32px x 4rows. Due to the surface layout parameters,
1327ec681f3Smrg    * if LOD0's width isn't a multiple of 64px, LOD1 and LOD2+ will share CCS
1337ec681f3Smrg    * elements. Assuming LOD2 exists, don't fast-clear any level above LOD0
1347ec681f3Smrg    * to avoid stomping on other LODs.
1357ec681f3Smrg    */
1367ec681f3Smrg   if (level > 0 && util_format_get_blocksizebits(p_res->format) == 8 &&
1377ec681f3Smrg       res->aux.usage == ISL_AUX_USAGE_GFX12_CCS_E && p_res->width0 % 64) {
1389f464c52Smaya      return false;
1397ec681f3Smrg   }
1409f464c52Smaya
1419f464c52Smaya   return true;
1429f464c52Smaya}
1439f464c52Smaya
1449f464c52Smayastatic union isl_color_value
1457ec681f3Smrgconvert_clear_color(enum pipe_format format,
1467ec681f3Smrg                    const union pipe_color_union *color)
1479f464c52Smaya{
1487ec681f3Smrg   /* pipe_color_union and isl_color_value are interchangeable */
1497ec681f3Smrg   union isl_color_value override_color = *(union isl_color_value *)color;
1509f464c52Smaya
1519f464c52Smaya   const struct util_format_description *desc =
1529f464c52Smaya      util_format_description(format);
1539f464c52Smaya   unsigned colormask = util_format_colormask(desc);
1549f464c52Smaya
1559f464c52Smaya   if (util_format_is_intensity(format) ||
1567ec681f3Smrg       util_format_is_luminance(format)) {
1579f464c52Smaya      override_color.u32[1] = override_color.u32[0];
1589f464c52Smaya      override_color.u32[2] = override_color.u32[0];
1599f464c52Smaya      if (util_format_is_intensity(format))
1609f464c52Smaya         override_color.u32[3] = override_color.u32[0];
1619f464c52Smaya   } else {
1629f464c52Smaya      for (int chan = 0; chan < 3; chan++) {
1639f464c52Smaya         if (!(colormask & (1 << chan)))
1649f464c52Smaya            override_color.u32[chan] = 0;
1659f464c52Smaya      }
1669f464c52Smaya   }
1679f464c52Smaya
1689f464c52Smaya   if (util_format_is_unorm(format)) {
1699f464c52Smaya      for (int i = 0; i < 4; i++)
1707ec681f3Smrg         override_color.f32[i] = SATURATE(override_color.f32[i]);
1719f464c52Smaya   } else if (util_format_is_snorm(format)) {
1729f464c52Smaya      for (int i = 0; i < 4; i++)
1739f464c52Smaya         override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f);
1749f464c52Smaya   } else if (util_format_is_pure_uint(format)) {
1759f464c52Smaya      for (int i = 0; i < 4; i++) {
1769f464c52Smaya         unsigned bits = util_format_get_component_bits(
1779f464c52Smaya            format, UTIL_FORMAT_COLORSPACE_RGB, i);
1789f464c52Smaya         if (bits < 32) {
1799f464c52Smaya            uint32_t max = (1u << bits) - 1;
1809f464c52Smaya            override_color.u32[i] = MIN2(override_color.u32[i], max);
1819f464c52Smaya         }
1829f464c52Smaya      }
1839f464c52Smaya   } else if (util_format_is_pure_sint(format)) {
1849f464c52Smaya      for (int i = 0; i < 4; i++) {
1859f464c52Smaya         unsigned bits = util_format_get_component_bits(
1869f464c52Smaya            format, UTIL_FORMAT_COLORSPACE_RGB, i);
1877ec681f3Smrg         if (bits > 0 && bits < 32) {
1887ec681f3Smrg            int32_t max = u_intN_max(bits);
1897ec681f3Smrg            int32_t min = u_intN_min(bits);
1909f464c52Smaya            override_color.i32[i] = CLAMP(override_color.i32[i], min, max);
1919f464c52Smaya         }
1929f464c52Smaya      }
1939f464c52Smaya   } else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||
1949f464c52Smaya              format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
1959f464c52Smaya      /* these packed float formats only store unsigned values */
1969f464c52Smaya      for (int i = 0; i < 4; i++)
1979f464c52Smaya         override_color.f32[i] = MAX2(override_color.f32[i], 0.0f);
1989f464c52Smaya   }
1999f464c52Smaya
2009f464c52Smaya   if (!(colormask & 1 << 3)) {
2019f464c52Smaya      if (util_format_is_pure_integer(format))
2029f464c52Smaya         override_color.u32[3] = 1;
2039f464c52Smaya      else
2049f464c52Smaya         override_color.f32[3] = 1.0f;
2059f464c52Smaya   }
2069f464c52Smaya
2079f464c52Smaya   return override_color;
2089f464c52Smaya}
2099f464c52Smaya
2109f464c52Smayastatic void
2119f464c52Smayafast_clear_color(struct iris_context *ice,
2129f464c52Smaya                 struct iris_resource *res,
2139f464c52Smaya                 unsigned level,
2149f464c52Smaya                 const struct pipe_box *box,
2159f464c52Smaya                 enum isl_format format,
2167ec681f3Smrg                 union isl_color_value color)
2179f464c52Smaya{
2189f464c52Smaya   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
2199f464c52Smaya   struct pipe_resource *p_res = (void *) res;
2209f464c52Smaya
2217ec681f3Smrg   bool color_changed = res->aux.clear_color_unknown ||
2227ec681f3Smrg      memcmp(&res->aux.clear_color, &color, sizeof(color)) != 0;
2239f464c52Smaya
2249f464c52Smaya   if (color_changed) {
2257ec681f3Smrg      /* If we are clearing to a new clear value, we need to resolve fast
2267ec681f3Smrg       * clears from other levels/layers first, since we can't have different
2277ec681f3Smrg       * levels/layers with different fast clear colors.
2289f464c52Smaya       */
2297ec681f3Smrg      for (unsigned res_lvl = 0; res_lvl < res->surf.levels; res_lvl++) {
2307ec681f3Smrg         const unsigned level_layers =
2317ec681f3Smrg            iris_get_num_logical_layers(res, res_lvl);
2327ec681f3Smrg         for (unsigned layer = 0; layer < level_layers; layer++) {
2337ec681f3Smrg            if (res_lvl == level &&
2347ec681f3Smrg                layer >= box->z &&
2357ec681f3Smrg                layer < box->z + box->depth) {
2367ec681f3Smrg               /* We're going to clear this layer anyway.  Leave it alone. */
2377ec681f3Smrg               continue;
2387ec681f3Smrg            }
2397ec681f3Smrg
2407ec681f3Smrg            enum isl_aux_state aux_state =
2417ec681f3Smrg               iris_resource_get_aux_state(res, res_lvl, layer);
2427ec681f3Smrg
2437ec681f3Smrg            if (aux_state != ISL_AUX_STATE_CLEAR &&
2447ec681f3Smrg                aux_state != ISL_AUX_STATE_PARTIAL_CLEAR &&
2457ec681f3Smrg                aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
2467ec681f3Smrg               /* This slice doesn't have any fast-cleared bits. */
2477ec681f3Smrg               continue;
2487ec681f3Smrg            }
2497ec681f3Smrg
2507ec681f3Smrg            /* If we got here, then the level may have fast-clear bits that use
2517ec681f3Smrg             * the old clear value.  We need to do a color resolve to get rid
2527ec681f3Smrg             * of their use of the clear color before we can change it.
2537ec681f3Smrg             * Fortunately, few applications ever change their clear color at
2547ec681f3Smrg             * different levels/layers, so this shouldn't happen often.
2557ec681f3Smrg             */
2567ec681f3Smrg            iris_resource_prepare_access(ice, res,
2577ec681f3Smrg                                         res_lvl, 1, layer, 1,
2587ec681f3Smrg                                         res->aux.usage,
2597ec681f3Smrg                                         false);
2607ec681f3Smrg            if (res->aux.clear_color_unknown) {
2617ec681f3Smrg               perf_debug(&ice->dbg,
2627ec681f3Smrg                          "Resolving resource (%p) level %d, layer %d: color changing from "
2637ec681f3Smrg                          "(unknown) to (%0.2f, %0.2f, %0.2f, %0.2f)\n",
2647ec681f3Smrg                          res, res_lvl, layer,
2657ec681f3Smrg                          color.f32[0], color.f32[1], color.f32[2], color.f32[3]);
2667ec681f3Smrg            } else {
2677ec681f3Smrg               perf_debug(&ice->dbg,
2687ec681f3Smrg                          "Resolving resource (%p) level %d, layer %d: color changing from "
2697ec681f3Smrg                          "(%0.2f, %0.2f, %0.2f, %0.2f) to "
2707ec681f3Smrg                          "(%0.2f, %0.2f, %0.2f, %0.2f)\n",
2717ec681f3Smrg                          res, res_lvl, layer,
2727ec681f3Smrg                          res->aux.clear_color.f32[0],
2737ec681f3Smrg                          res->aux.clear_color.f32[1],
2747ec681f3Smrg                          res->aux.clear_color.f32[2],
2757ec681f3Smrg                          res->aux.clear_color.f32[3],
2767ec681f3Smrg                          color.f32[0], color.f32[1], color.f32[2], color.f32[3]);
2777ec681f3Smrg            }
2787ec681f3Smrg         }
2797ec681f3Smrg      }
2809f464c52Smaya   }
2819f464c52Smaya
2829f464c52Smaya   iris_resource_set_clear_color(ice, res, color);
2839f464c52Smaya
2849f464c52Smaya   /* If the buffer is already in ISL_AUX_STATE_CLEAR, and the color hasn't
2859f464c52Smaya    * changed, the clear is redundant and can be skipped.
2869f464c52Smaya    */
2877ec681f3Smrg   const enum isl_aux_state aux_state =
2887ec681f3Smrg      iris_resource_get_aux_state(res, level, box->z);
2897ec681f3Smrg   if (!color_changed && box->depth == 1 && aux_state == ISL_AUX_STATE_CLEAR)
2909f464c52Smaya      return;
2919f464c52Smaya
2927ec681f3Smrg   /* Ivybridge PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":
2939f464c52Smaya    *
2949f464c52Smaya    *    "Any transition from any value in {Clear, Render, Resolve} to a
2959f464c52Smaya    *    different value in {Clear, Render, Resolve} requires end of pipe
2969f464c52Smaya    *    synchronization."
2979f464c52Smaya    *
2989f464c52Smaya    * In other words, fast clear ops are not properly synchronized with
2999f464c52Smaya    * other drawing.  We need to use a PIPE_CONTROL to ensure that the
3009f464c52Smaya    * contents of the previous draw hit the render target before we resolve
3019f464c52Smaya    * and again afterwards to ensure that the resolve is complete before we
3029f464c52Smaya    * do any more regular drawing.
3039f464c52Smaya    */
3047ec681f3Smrg   iris_emit_end_of_pipe_sync(batch,
3057ec681f3Smrg                              "fast clear: pre-flush",
3067ec681f3Smrg                              PIPE_CONTROL_RENDER_TARGET_FLUSH |
3077ec681f3Smrg                              PIPE_CONTROL_TILE_CACHE_FLUSH);
3087ec681f3Smrg
3097ec681f3Smrg   iris_batch_sync_region_start(batch);
3109f464c52Smaya
3119f464c52Smaya   /* If we reach this point, we need to fast clear to change the state to
3129f464c52Smaya    * ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both).
3139f464c52Smaya    */
3147ec681f3Smrg   enum blorp_batch_flags blorp_flags = 0;
3159f464c52Smaya   blorp_flags |= color_changed ? 0 : BLORP_BATCH_NO_UPDATE_CLEAR_COLOR;
3169f464c52Smaya
3179f464c52Smaya   struct blorp_batch blorp_batch;
3189f464c52Smaya   blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
3199f464c52Smaya
3209f464c52Smaya   struct blorp_surf surf;
3217ec681f3Smrg   iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,
3227ec681f3Smrg                                p_res, res->aux.usage, level, true);
3237ec681f3Smrg
3247ec681f3Smrg   blorp_fast_clear(&blorp_batch, &surf, res->surf.format,
3257ec681f3Smrg                    ISL_SWIZZLE_IDENTITY,
3269f464c52Smaya                    level, box->z, box->depth,
3279f464c52Smaya                    box->x, box->y, box->x + box->width,
3289f464c52Smaya                    box->y + box->height);
3299f464c52Smaya   blorp_batch_finish(&blorp_batch);
3307ec681f3Smrg   iris_emit_end_of_pipe_sync(batch,
3317ec681f3Smrg                              "fast clear: post flush",
3327ec681f3Smrg                              PIPE_CONTROL_RENDER_TARGET_FLUSH);
3337ec681f3Smrg   iris_batch_sync_region_end(batch);
3349f464c52Smaya
3359f464c52Smaya   iris_resource_set_aux_state(ice, res, level, box->z,
3369f464c52Smaya                               box->depth, ISL_AUX_STATE_CLEAR);
3377ec681f3Smrg   ice->state.dirty |= IRIS_DIRTY_RENDER_BUFFER;
3387ec681f3Smrg   ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;
3399f464c52Smaya   return;
3409f464c52Smaya}
3419f464c52Smaya
3429f464c52Smayastatic void
3439f464c52Smayaclear_color(struct iris_context *ice,
3449f464c52Smaya            struct pipe_resource *p_res,
3459f464c52Smaya            unsigned level,
3469f464c52Smaya            const struct pipe_box *box,
3479f464c52Smaya            bool render_condition_enabled,
3489f464c52Smaya            enum isl_format format,
3499f464c52Smaya            struct isl_swizzle swizzle,
3509f464c52Smaya            union isl_color_value color)
3519f464c52Smaya{
3529f464c52Smaya   struct iris_resource *res = (void *) p_res;
3539f464c52Smaya
3549f464c52Smaya   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
3557ec681f3Smrg   const struct intel_device_info *devinfo = &batch->screen->devinfo;
3569f464c52Smaya   enum blorp_batch_flags blorp_flags = 0;
3579f464c52Smaya
3589f464c52Smaya   if (render_condition_enabled) {
3599f464c52Smaya      if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)
3609f464c52Smaya         return;
3619f464c52Smaya
3629f464c52Smaya      if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)
3639f464c52Smaya         blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
3649f464c52Smaya   }
3659f464c52Smaya
3669f464c52Smaya   if (p_res->target == PIPE_BUFFER)
3677ec681f3Smrg      util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);
3689f464c52Smaya
3699f464c52Smaya   iris_batch_maybe_flush(batch, 1500);
3709f464c52Smaya
3719f464c52Smaya   bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box,
3727ec681f3Smrg                                              render_condition_enabled,
3737ec681f3Smrg                                              format, color);
3749f464c52Smaya   if (can_fast_clear) {
3757ec681f3Smrg      fast_clear_color(ice, res, level, box, format, color);
3769f464c52Smaya      return;
3779f464c52Smaya   }
3789f464c52Smaya
3799f464c52Smaya   enum isl_aux_usage aux_usage =
3807ec681f3Smrg      iris_resource_render_aux_usage(ice, res, level, format, false);
3819f464c52Smaya
3827ec681f3Smrg   iris_resource_prepare_render(ice, res, level, box->z, box->depth,
3837ec681f3Smrg                                aux_usage);
3847ec681f3Smrg   iris_emit_buffer_barrier_for(batch, res->bo, IRIS_DOMAIN_RENDER_WRITE);
3859f464c52Smaya
3869f464c52Smaya   struct blorp_surf surf;
3877ec681f3Smrg   iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,
3887ec681f3Smrg                                p_res, aux_usage, level, true);
3897ec681f3Smrg
3907ec681f3Smrg   iris_batch_sync_region_start(batch);
3919f464c52Smaya
3929f464c52Smaya   struct blorp_batch blorp_batch;
3939f464c52Smaya   blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
3949f464c52Smaya
3959f464c52Smaya   if (!isl_format_supports_rendering(devinfo, format) &&
3969f464c52Smaya       isl_format_is_rgbx(format))
3979f464c52Smaya      format = isl_format_rgbx_to_rgba(format);
3989f464c52Smaya
3999f464c52Smaya   blorp_clear(&blorp_batch, &surf, format, swizzle,
4009f464c52Smaya               level, box->z, box->depth, box->x, box->y,
4019f464c52Smaya               box->x + box->width, box->y + box->height,
4027ec681f3Smrg               color, 0 /* color_write_disable */);
4039f464c52Smaya
4049f464c52Smaya   blorp_batch_finish(&blorp_batch);
4057ec681f3Smrg   iris_batch_sync_region_end(batch);
4067ec681f3Smrg
4077ec681f3Smrg   iris_flush_and_dirty_for_history(ice, batch, res,
4087ec681f3Smrg                                    PIPE_CONTROL_RENDER_TARGET_FLUSH,
4097ec681f3Smrg                                    "cache history: post color clear");
4109f464c52Smaya
4119f464c52Smaya   iris_resource_finish_render(ice, res, level,
4129f464c52Smaya                               box->z, box->depth, aux_usage);
4139f464c52Smaya}
4149f464c52Smaya
4159f464c52Smayastatic bool
4169f464c52Smayacan_fast_clear_depth(struct iris_context *ice,
4179f464c52Smaya                     struct iris_resource *res,
4189f464c52Smaya                     unsigned level,
4199f464c52Smaya                     const struct pipe_box *box,
4207ec681f3Smrg                     bool render_condition_enabled,
4219f464c52Smaya                     float depth)
4229f464c52Smaya{
4239f464c52Smaya   struct pipe_resource *p_res = (void *) res;
4247ec681f3Smrg   struct pipe_context *ctx = (void *) ice;
4257ec681f3Smrg   struct iris_screen *screen = (void *) ctx->screen;
4267ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
4277ec681f3Smrg
4287ec681f3Smrg   if (INTEL_DEBUG(DEBUG_NO_FAST_CLEAR))
4297ec681f3Smrg      return false;
4309f464c52Smaya
4319f464c52Smaya   /* Check for partial clears */
4329f464c52Smaya   if (box->x > 0 || box->y > 0 ||
4339f464c52Smaya       box->width < u_minify(p_res->width0, level) ||
4349f464c52Smaya       box->height < u_minify(p_res->height0, level)) {
4359f464c52Smaya      return false;
4369f464c52Smaya   }
4379f464c52Smaya
4387ec681f3Smrg   /* Avoid conditional fast clears to maintain correct tracking of the aux
4397ec681f3Smrg    * state (see iris_resource_finish_write for more info). Note that partial
4407ec681f3Smrg    * fast clears would not pose a problem with conditional rendering.
4417ec681f3Smrg    */
4427ec681f3Smrg   if (render_condition_enabled &&
4437ec681f3Smrg       ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {
4449f464c52Smaya      return false;
4457ec681f3Smrg   }
4467ec681f3Smrg
4477ec681f3Smrg   if (!iris_resource_level_has_hiz(res, level))
4487ec681f3Smrg      return false;
4497ec681f3Smrg
4507ec681f3Smrg   if (!blorp_can_hiz_clear_depth(devinfo, &res->surf, res->aux.usage,
4517ec681f3Smrg                                  level, box->z, box->x, box->y,
4527ec681f3Smrg                                  box->x + box->width,
4537ec681f3Smrg                                  box->y + box->height)) {
4547ec681f3Smrg      return false;
4557ec681f3Smrg   }
4569f464c52Smaya
4579f464c52Smaya   return true;
4589f464c52Smaya}
4599f464c52Smaya
4609f464c52Smayastatic void
4619f464c52Smayafast_clear_depth(struct iris_context *ice,
4629f464c52Smaya                 struct iris_resource *res,
4639f464c52Smaya                 unsigned level,
4649f464c52Smaya                 const struct pipe_box *box,
4659f464c52Smaya                 float depth)
4669f464c52Smaya{
4679f464c52Smaya   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
4689f464c52Smaya
4699f464c52Smaya   bool update_clear_depth = false;
4709f464c52Smaya
4719f464c52Smaya   /* If we're clearing to a new clear value, then we need to resolve any clear
4729f464c52Smaya    * flags out of the HiZ buffer into the real depth buffer.
4739f464c52Smaya    */
4747ec681f3Smrg   if (res->aux.clear_color_unknown || res->aux.clear_color.f32[0] != depth) {
4759f464c52Smaya      for (unsigned res_level = 0; res_level < res->surf.levels; res_level++) {
4769f464c52Smaya         const unsigned level_layers =
4779f464c52Smaya            iris_get_num_logical_layers(res, res_level);
4789f464c52Smaya         for (unsigned layer = 0; layer < level_layers; layer++) {
4799f464c52Smaya            if (res_level == level &&
4809f464c52Smaya                layer >= box->z &&
4819f464c52Smaya                layer < box->z + box->depth) {
4829f464c52Smaya               /* We're going to clear this layer anyway.  Leave it alone. */
4839f464c52Smaya               continue;
4849f464c52Smaya            }
4859f464c52Smaya
4869f464c52Smaya            enum isl_aux_state aux_state =
4879f464c52Smaya               iris_resource_get_aux_state(res, res_level, layer);
4889f464c52Smaya
4899f464c52Smaya            if (aux_state != ISL_AUX_STATE_CLEAR &&
4909f464c52Smaya                aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {
4919f464c52Smaya               /* This slice doesn't have any fast-cleared bits. */
4929f464c52Smaya               continue;
4939f464c52Smaya            }
4949f464c52Smaya
4959f464c52Smaya            /* If we got here, then the level may have fast-clear bits that
4969f464c52Smaya             * use the old clear value.  We need to do a depth resolve to get
4979f464c52Smaya             * rid of their use of the clear value before we can change it.
4989f464c52Smaya             * Fortunately, few applications ever change their depth clear
4999f464c52Smaya             * value so this shouldn't happen often.
5009f464c52Smaya             */
5019f464c52Smaya            iris_hiz_exec(ice, batch, res, res_level, layer, 1,
5029f464c52Smaya                          ISL_AUX_OP_FULL_RESOLVE, false);
5039f464c52Smaya            iris_resource_set_aux_state(ice, res, res_level, layer, 1,
5049f464c52Smaya                                        ISL_AUX_STATE_RESOLVED);
5059f464c52Smaya         }
5069f464c52Smaya      }
5079f464c52Smaya      const union isl_color_value clear_value = { .f32 = {depth, } };
5089f464c52Smaya      iris_resource_set_clear_color(ice, res, clear_value);
5099f464c52Smaya      update_clear_depth = true;
5109f464c52Smaya   }
5119f464c52Smaya
5127ec681f3Smrg   if (res->aux.usage == ISL_AUX_USAGE_HIZ_CCS_WT) {
5137ec681f3Smrg      /* From Bspec 47010 (Depth Buffer Clear):
5147ec681f3Smrg       *
5157ec681f3Smrg       *    Since the fast clear cycles to CCS are not cached in TileCache,
5167ec681f3Smrg       *    any previous depth buffer writes to overlapping pixels must be
5177ec681f3Smrg       *    flushed out of TileCache before a succeeding Depth Buffer Clear.
5187ec681f3Smrg       *    This restriction only applies to Depth Buffer with write-thru
5197ec681f3Smrg       *    enabled, since fast clears to CCS only occur for write-thru mode.
5207ec681f3Smrg       *
5217ec681f3Smrg       * There may have been a write to this depth buffer. Flush it from the
5227ec681f3Smrg       * tile cache just in case.
5237ec681f3Smrg       */
5247ec681f3Smrg      iris_emit_pipe_control_flush(batch, "hiz_ccs_wt: before fast clear",
5257ec681f3Smrg                                   PIPE_CONTROL_DEPTH_CACHE_FLUSH |
5267ec681f3Smrg                                   PIPE_CONTROL_TILE_CACHE_FLUSH);
5277ec681f3Smrg   }
5287ec681f3Smrg
5299f464c52Smaya   for (unsigned l = 0; l < box->depth; l++) {
5309f464c52Smaya      enum isl_aux_state aux_state =
5319f464c52Smaya         iris_resource_get_aux_state(res, level, box->z + l);
5327ec681f3Smrg      if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) {
5337ec681f3Smrg         if (aux_state == ISL_AUX_STATE_CLEAR) {
5347ec681f3Smrg            perf_debug(&ice->dbg, "Performing HiZ clear just to update the "
5357ec681f3Smrg                                  "depth clear value\n");
5367ec681f3Smrg         }
5379f464c52Smaya         iris_hiz_exec(ice, batch, res, level,
5389f464c52Smaya                       box->z + l, 1, ISL_AUX_OP_FAST_CLEAR,
5399f464c52Smaya                       update_clear_depth);
5409f464c52Smaya      }
5419f464c52Smaya   }
5429f464c52Smaya
5439f464c52Smaya   iris_resource_set_aux_state(ice, res, level, box->z, box->depth,
5449f464c52Smaya                               ISL_AUX_STATE_CLEAR);
5459f464c52Smaya   ice->state.dirty |= IRIS_DIRTY_DEPTH_BUFFER;
5467ec681f3Smrg   ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;
5479f464c52Smaya}
5489f464c52Smaya
5499f464c52Smayastatic void
5509f464c52Smayaclear_depth_stencil(struct iris_context *ice,
5519f464c52Smaya                    struct pipe_resource *p_res,
5529f464c52Smaya                    unsigned level,
5539f464c52Smaya                    const struct pipe_box *box,
5549f464c52Smaya                    bool render_condition_enabled,
5559f464c52Smaya                    bool clear_depth,
5569f464c52Smaya                    bool clear_stencil,
5579f464c52Smaya                    float depth,
5589f464c52Smaya                    uint8_t stencil)
5599f464c52Smaya{
5609f464c52Smaya   struct iris_resource *res = (void *) p_res;
5619f464c52Smaya
5629f464c52Smaya   struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];
5639f464c52Smaya   enum blorp_batch_flags blorp_flags = 0;
5649f464c52Smaya
5659f464c52Smaya   if (render_condition_enabled) {
5669f464c52Smaya      if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)
5679f464c52Smaya         return;
5689f464c52Smaya
5699f464c52Smaya      if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)
5709f464c52Smaya         blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;
5719f464c52Smaya   }
5729f464c52Smaya
5739f464c52Smaya   iris_batch_maybe_flush(batch, 1500);
5749f464c52Smaya
5759f464c52Smaya   struct iris_resource *z_res;
5769f464c52Smaya   struct iris_resource *stencil_res;
5779f464c52Smaya   struct blorp_surf z_surf;
5789f464c52Smaya   struct blorp_surf stencil_surf;
5799f464c52Smaya
5809f464c52Smaya   iris_get_depth_stencil_resources(p_res, &z_res, &stencil_res);
5819f464c52Smaya   if (z_res && clear_depth &&
5827ec681f3Smrg       can_fast_clear_depth(ice, z_res, level, box, render_condition_enabled,
5837ec681f3Smrg                            depth)) {
5849f464c52Smaya      fast_clear_depth(ice, z_res, level, box, depth);
5857ec681f3Smrg      iris_flush_and_dirty_for_history(ice, batch, res, 0,
5867ec681f3Smrg                                       "cache history: post fast Z clear");
5879f464c52Smaya      clear_depth = false;
5889f464c52Smaya      z_res = false;
5899f464c52Smaya   }
5909f464c52Smaya
5919f464c52Smaya   /* At this point, we might have fast cleared the depth buffer. So if there's
5929f464c52Smaya    * no stencil clear pending, return early.
5939f464c52Smaya    */
5947ec681f3Smrg   if (!(clear_depth || (clear_stencil && stencil_res))) {
5959f464c52Smaya      return;
5969f464c52Smaya   }
5979f464c52Smaya
5987ec681f3Smrg   if (clear_depth && z_res) {
5997ec681f3Smrg      const enum isl_aux_usage aux_usage =
6007ec681f3Smrg         iris_resource_render_aux_usage(ice, z_res, level, z_res->surf.format,
6017ec681f3Smrg                                        false);
6027ec681f3Smrg      iris_resource_prepare_render(ice, z_res, level, box->z, box->depth,
6037ec681f3Smrg                                   aux_usage);
6047ec681f3Smrg      iris_emit_buffer_barrier_for(batch, z_res->bo, IRIS_DOMAIN_DEPTH_WRITE);
6057ec681f3Smrg      iris_blorp_surf_for_resource(&batch->screen->isl_dev, &z_surf,
6067ec681f3Smrg                                   &z_res->base.b, aux_usage, level, true);
6077ec681f3Smrg   }
6087ec681f3Smrg
6097ec681f3Smrg   uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0;
6107ec681f3Smrg   if (stencil_mask) {
6117ec681f3Smrg      iris_resource_prepare_access(ice, stencil_res, level, 1, box->z,
6127ec681f3Smrg                                   box->depth, stencil_res->aux.usage, false);
6137ec681f3Smrg      iris_emit_buffer_barrier_for(batch, stencil_res->bo,
6147ec681f3Smrg                                   IRIS_DOMAIN_DEPTH_WRITE);
6157ec681f3Smrg      iris_blorp_surf_for_resource(&batch->screen->isl_dev,
6167ec681f3Smrg                                   &stencil_surf, &stencil_res->base.b,
6177ec681f3Smrg                                   stencil_res->aux.usage, level, true);
6189f464c52Smaya   }
6199f464c52Smaya
6207ec681f3Smrg   iris_batch_sync_region_start(batch);
6217ec681f3Smrg
6229f464c52Smaya   struct blorp_batch blorp_batch;
6239f464c52Smaya   blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);
6249f464c52Smaya
6259f464c52Smaya   blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf,
6269f464c52Smaya                             level, box->z, box->depth,
6279f464c52Smaya                             box->x, box->y,
6289f464c52Smaya                             box->x + box->width,
6299f464c52Smaya                             box->y + box->height,
6309f464c52Smaya                             clear_depth && z_res, depth,
6317ec681f3Smrg                             stencil_mask, stencil);
6329f464c52Smaya
6339f464c52Smaya   blorp_batch_finish(&blorp_batch);
6347ec681f3Smrg   iris_batch_sync_region_end(batch);
6357ec681f3Smrg
6367ec681f3Smrg   iris_flush_and_dirty_for_history(ice, batch, res, 0,
6377ec681f3Smrg                                    "cache history: post slow ZS clear");
6387ec681f3Smrg
6397ec681f3Smrg   if (clear_depth && z_res) {
6407ec681f3Smrg      iris_resource_finish_render(ice, z_res, level, box->z, box->depth,
6417ec681f3Smrg                                  z_surf.aux_usage);
6427ec681f3Smrg   }
6439f464c52Smaya
6447ec681f3Smrg   if (stencil_mask) {
6457ec681f3Smrg      iris_resource_finish_write(ice, stencil_res, level, box->z, box->depth,
6467ec681f3Smrg                                 stencil_res->aux.usage);
6479f464c52Smaya   }
6489f464c52Smaya}
6499f464c52Smaya
6509f464c52Smaya/**
6519f464c52Smaya * The pipe->clear() driver hook.
6529f464c52Smaya *
6539f464c52Smaya * This clears buffers attached to the current draw framebuffer.
6549f464c52Smaya */
6559f464c52Smayastatic void
6569f464c52Smayairis_clear(struct pipe_context *ctx,
6579f464c52Smaya           unsigned buffers,
6587ec681f3Smrg           const struct pipe_scissor_state *scissor_state,
6599f464c52Smaya           const union pipe_color_union *p_color,
6609f464c52Smaya           double depth,
6619f464c52Smaya           unsigned stencil)
6629f464c52Smaya{
6639f464c52Smaya   struct iris_context *ice = (void *) ctx;
6649f464c52Smaya   struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;
6659f464c52Smaya
6669f464c52Smaya   assert(buffers != 0);
6679f464c52Smaya
6687ec681f3Smrg   struct pipe_box box = {
6697ec681f3Smrg      .width = cso_fb->width,
6707ec681f3Smrg      .height = cso_fb->height,
6717ec681f3Smrg   };
6727ec681f3Smrg
6737ec681f3Smrg   if (scissor_state) {
6747ec681f3Smrg      box.x = scissor_state->minx;
6757ec681f3Smrg      box.y = scissor_state->miny;
6767ec681f3Smrg      box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx);
6777ec681f3Smrg      box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny);
6787ec681f3Smrg   }
6797ec681f3Smrg
6809f464c52Smaya   if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
6819f464c52Smaya      struct pipe_surface *psurf = cso_fb->zsbuf;
6829f464c52Smaya
6837ec681f3Smrg      box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;
6847ec681f3Smrg      box.z = psurf->u.tex.first_layer,
6859f464c52Smaya      clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true,
6869f464c52Smaya                          buffers & PIPE_CLEAR_DEPTH,
6879f464c52Smaya                          buffers & PIPE_CLEAR_STENCIL,
6889f464c52Smaya                          depth, stencil);
6899f464c52Smaya   }
6909f464c52Smaya
6919f464c52Smaya   if (buffers & PIPE_CLEAR_COLOR) {
6929f464c52Smaya      for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {
6939f464c52Smaya         if (buffers & (PIPE_CLEAR_COLOR0 << i)) {
6949f464c52Smaya            struct pipe_surface *psurf = cso_fb->cbufs[i];
6959f464c52Smaya            struct iris_surface *isurf = (void *) psurf;
6967ec681f3Smrg            box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,
6977ec681f3Smrg            box.z = psurf->u.tex.first_layer,
6989f464c52Smaya
6999f464c52Smaya            clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
7009f464c52Smaya                        true, isurf->view.format, isurf->view.swizzle,
7017ec681f3Smrg                        convert_clear_color(psurf->format, p_color));
7029f464c52Smaya         }
7039f464c52Smaya      }
7049f464c52Smaya   }
7059f464c52Smaya}
7069f464c52Smaya
7079f464c52Smaya/**
7089f464c52Smaya * The pipe->clear_texture() driver hook.
7099f464c52Smaya *
7109f464c52Smaya * This clears the given texture resource.
7119f464c52Smaya */
7129f464c52Smayastatic void
7139f464c52Smayairis_clear_texture(struct pipe_context *ctx,
7149f464c52Smaya                   struct pipe_resource *p_res,
7159f464c52Smaya                   unsigned level,
7169f464c52Smaya                   const struct pipe_box *box,
7179f464c52Smaya                   const void *data)
7189f464c52Smaya{
7199f464c52Smaya   struct iris_context *ice = (void *) ctx;
7209f464c52Smaya   struct iris_screen *screen = (void *) ctx->screen;
7217ec681f3Smrg   const struct intel_device_info *devinfo = &screen->devinfo;
7229f464c52Smaya
7239f464c52Smaya   if (util_format_is_depth_or_stencil(p_res->format)) {
7247ec681f3Smrg      const struct util_format_unpack_description *unpack =
7257ec681f3Smrg         util_format_unpack_description(p_res->format);
7269f464c52Smaya
7279f464c52Smaya      float depth = 0.0;
7289f464c52Smaya      uint8_t stencil = 0;
7299f464c52Smaya
7307ec681f3Smrg      if (unpack->unpack_z_float)
7317ec681f3Smrg         util_format_unpack_z_float(p_res->format, &depth, data, 1);
7329f464c52Smaya
7337ec681f3Smrg      if (unpack->unpack_s_8uint)
7347ec681f3Smrg         util_format_unpack_s_8uint(p_res->format, &stencil, data, 1);
7359f464c52Smaya
7369f464c52Smaya      clear_depth_stencil(ice, p_res, level, box, true, true, true,
7379f464c52Smaya                          depth, stencil);
7389f464c52Smaya   } else {
7399f464c52Smaya      union isl_color_value color;
7409f464c52Smaya      struct iris_resource *res = (void *) p_res;
7419f464c52Smaya      enum isl_format format = res->surf.format;
7429f464c52Smaya
7439f464c52Smaya      if (!isl_format_supports_rendering(devinfo, format)) {
7449f464c52Smaya         const struct isl_format_layout *fmtl = isl_format_get_layout(format);
7459f464c52Smaya         // XXX: actually just get_copy_format_for_bpb from BLORP
7469f464c52Smaya         // XXX: don't cut and paste this
7479f464c52Smaya         switch (fmtl->bpb) {
7489f464c52Smaya         case 8:   format = ISL_FORMAT_R8_UINT;           break;
7499f464c52Smaya         case 16:  format = ISL_FORMAT_R8G8_UINT;         break;
7509f464c52Smaya         case 24:  format = ISL_FORMAT_R8G8B8_UINT;       break;
7519f464c52Smaya         case 32:  format = ISL_FORMAT_R8G8B8A8_UINT;     break;
7529f464c52Smaya         case 48:  format = ISL_FORMAT_R16G16B16_UINT;    break;
7539f464c52Smaya         case 64:  format = ISL_FORMAT_R16G16B16A16_UINT; break;
7549f464c52Smaya         case 96:  format = ISL_FORMAT_R32G32B32_UINT;    break;
7559f464c52Smaya         case 128: format = ISL_FORMAT_R32G32B32A32_UINT; break;
7569f464c52Smaya         default:
7579f464c52Smaya            unreachable("Unknown format bpb");
7589f464c52Smaya         }
7599f464c52Smaya
7609f464c52Smaya         /* No aux surfaces for non-renderable surfaces */
7619f464c52Smaya         assert(res->aux.usage == ISL_AUX_USAGE_NONE);
7629f464c52Smaya      }
7639f464c52Smaya
7649f464c52Smaya      isl_color_value_unpack(&color, format, data);
7659f464c52Smaya
7669f464c52Smaya      clear_color(ice, p_res, level, box, true, format,
7679f464c52Smaya                  ISL_SWIZZLE_IDENTITY, color);
7689f464c52Smaya   }
7699f464c52Smaya}
7709f464c52Smaya
7719f464c52Smaya/**
7729f464c52Smaya * The pipe->clear_render_target() driver hook.
7739f464c52Smaya *
7749f464c52Smaya * This clears the given render target surface.
7759f464c52Smaya */
7769f464c52Smayastatic void
7779f464c52Smayairis_clear_render_target(struct pipe_context *ctx,
7789f464c52Smaya                         struct pipe_surface *psurf,
7799f464c52Smaya                         const union pipe_color_union *p_color,
7809f464c52Smaya                         unsigned dst_x, unsigned dst_y,
7819f464c52Smaya                         unsigned width, unsigned height,
7829f464c52Smaya                         bool render_condition_enabled)
7839f464c52Smaya{
7849f464c52Smaya   struct iris_context *ice = (void *) ctx;
7859f464c52Smaya   struct iris_surface *isurf = (void *) psurf;
7869f464c52Smaya   struct pipe_box box = {
7879f464c52Smaya      .x = dst_x,
7889f464c52Smaya      .y = dst_y,
7899f464c52Smaya      .z = psurf->u.tex.first_layer,
7909f464c52Smaya      .width = width,
7919f464c52Smaya      .height = height,
7929f464c52Smaya      .depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
7939f464c52Smaya   };
7949f464c52Smaya
7959f464c52Smaya   clear_color(ice, psurf->texture, psurf->u.tex.level, &box,
7969f464c52Smaya               render_condition_enabled,
7977ec681f3Smrg               isurf->view.format, isurf->view.swizzle,
7987ec681f3Smrg               convert_clear_color(psurf->format, p_color));
7999f464c52Smaya}
8009f464c52Smaya
8019f464c52Smaya/**
8029f464c52Smaya * The pipe->clear_depth_stencil() driver hook.
8039f464c52Smaya *
8049f464c52Smaya * This clears the given depth/stencil surface.
8059f464c52Smaya */
8069f464c52Smayastatic void
8079f464c52Smayairis_clear_depth_stencil(struct pipe_context *ctx,
8089f464c52Smaya                         struct pipe_surface *psurf,
8099f464c52Smaya                         unsigned flags,
8109f464c52Smaya                         double depth,
8119f464c52Smaya                         unsigned stencil,
8129f464c52Smaya                         unsigned dst_x, unsigned dst_y,
8139f464c52Smaya                         unsigned width, unsigned height,
8149f464c52Smaya                         bool render_condition_enabled)
8159f464c52Smaya{
8169f464c52Smaya   struct iris_context *ice = (void *) ctx;
8179f464c52Smaya   struct pipe_box box = {
8189f464c52Smaya      .x = dst_x,
8199f464c52Smaya      .y = dst_y,
8209f464c52Smaya      .z = psurf->u.tex.first_layer,
8219f464c52Smaya      .width = width,
8229f464c52Smaya      .height = height,
8239f464c52Smaya      .depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1
8249f464c52Smaya   };
8259f464c52Smaya
8269f464c52Smaya   assert(util_format_is_depth_or_stencil(psurf->texture->format));
8279f464c52Smaya
8289f464c52Smaya   clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box,
8299f464c52Smaya                       render_condition_enabled,
8309f464c52Smaya                       flags & PIPE_CLEAR_DEPTH, flags & PIPE_CLEAR_STENCIL,
8319f464c52Smaya                       depth, stencil);
8329f464c52Smaya}
8339f464c52Smaya
8349f464c52Smayavoid
8359f464c52Smayairis_init_clear_functions(struct pipe_context *ctx)
8369f464c52Smaya{
8379f464c52Smaya   ctx->clear = iris_clear;
8389f464c52Smaya   ctx->clear_texture = iris_clear_texture;
8399f464c52Smaya   ctx->clear_render_target = iris_clear_render_target;
8409f464c52Smaya   ctx->clear_depth_stencil = iris_clear_depth_stencil;
8419f464c52Smaya}
842