Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_clear.c
4565 views
/*1* Copyright © 2017 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included11* in all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER19* DEALINGS IN THE SOFTWARE.20*/2122#include <stdio.h>23#include <errno.h>24#include "pipe/p_defines.h"25#include "pipe/p_state.h"26#include "pipe/p_context.h"27#include "pipe/p_screen.h"28#include "util/u_inlines.h"29#include "util/format/u_format.h"30#include "util/u_upload_mgr.h"31#include "util/ralloc.h"32#include "iris_context.h"33#include "iris_resource.h"34#include "iris_screen.h"35#include "intel/compiler/brw_compiler.h"3637static bool38iris_is_color_fast_clear_compatible(struct iris_context *ice,39enum isl_format format,40const union isl_color_value color)41{42struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];43const struct intel_device_info *devinfo = &batch->screen->devinfo;4445if (isl_format_has_int_channel(format)) {46perf_debug(&ice->dbg, "Integer fast clear not enabled for %s\n",47isl_format_get_name(format));48return false;49}5051for (int i = 0; i < 4; i++) {52if (!isl_format_has_color_component(format, i)) {53continue;54}5556if (devinfo->ver < 9 &&57color.f32[i] != 0.0f && color.f32[i] != 1.0f) {58return false;59}60}6162return true;63}6465static bool66can_fast_clear_color(struct iris_context *ice,67struct pipe_resource *p_res,68unsigned level,69const struct pipe_box *box,70bool render_condition_enabled,71enum isl_format render_format,72union isl_color_value color)73{74struct iris_resource *res = (void *) p_res;7576if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)77return false;7879if (!isl_aux_usage_has_fast_clears(res->aux.usage))80return false;8182/* Check for partial clear */83if (box->x > 0 || box->y > 0 ||84box->width < minify(p_res->width0, level) ||85box->height < minify(p_res->height0, level)) {86return false;87}8889/* Avoid conditional fast clears to maintain correct tracking of the aux90* state (see iris_resource_finish_write for more info). Note that partial91* fast clears (if they existed) would not pose a problem with conditional92* rendering.93*/94if (render_condition_enabled &&95ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {96return false;97}9899/* Disable sRGB fast-clears for non-0/1 color values. For texturing and100* draw calls, HW expects the clear color to be in two different color101* spaces after sRGB fast-clears - sRGB in the former and linear in the102* latter. By limiting the allowable values to 0/1, both color space103* requirements are satisfied.104*/105if (isl_format_is_srgb(render_format) &&106!isl_color_value_is_zero_one(color, render_format)) {107return false;108}109110/* We store clear colors as floats or uints as needed. If there are111* texture views in play, the formats will not properly be respected112* during resolves because the resolve operations only know about the113* resource and not the renderbuffer.114*/115if (!iris_render_formats_color_compatible(render_format, res->surf.format,116color)) {117return false;118}119120if (!iris_is_color_fast_clear_compatible(ice, res->surf.format, color))121return false;122123/* The RENDER_SURFACE_STATE page for TGL says:124*125* For an 8 bpp surface with NUM_MULTISAMPLES = 1, Surface Width not126* multiple of 64 pixels and more than 1 mip level in the view, Fast Clear127* is not supported when AUX_CCS_E is set in this field.128*129* The granularity of a fast-clear is one CCS element. For an 8 bpp primary130* surface, this maps to 32px x 4rows. Due to the surface layout parameters,131* if LOD0's width isn't a multiple of 64px, LOD1 and LOD2+ will share CCS132* elements. Assuming LOD2 exists, don't fast-clear any level above LOD0133* to avoid stomping on other LODs.134*/135if (level > 0 && util_format_get_blocksizebits(p_res->format) == 8 &&136res->aux.usage == ISL_AUX_USAGE_GFX12_CCS_E && p_res->width0 % 64) {137return false;138}139140return true;141}142143static union isl_color_value144convert_clear_color(enum pipe_format format,145const union pipe_color_union *color)146{147/* pipe_color_union and isl_color_value are interchangeable */148union isl_color_value override_color = *(union isl_color_value *)color;149150const struct util_format_description *desc =151util_format_description(format);152unsigned colormask = util_format_colormask(desc);153154if (util_format_is_intensity(format) ||155util_format_is_luminance(format)) {156override_color.u32[1] = override_color.u32[0];157override_color.u32[2] = override_color.u32[0];158if (util_format_is_intensity(format))159override_color.u32[3] = override_color.u32[0];160} else {161for (int chan = 0; chan < 3; chan++) {162if (!(colormask & (1 << chan)))163override_color.u32[chan] = 0;164}165}166167if (util_format_is_unorm(format)) {168for (int i = 0; i < 4; i++)169override_color.f32[i] = SATURATE(override_color.f32[i]);170} else if (util_format_is_snorm(format)) {171for (int i = 0; i < 4; i++)172override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f);173} else if (util_format_is_pure_uint(format)) {174for (int i = 0; i < 4; i++) {175unsigned bits = util_format_get_component_bits(176format, UTIL_FORMAT_COLORSPACE_RGB, i);177if (bits < 32) {178uint32_t max = (1u << bits) - 1;179override_color.u32[i] = MIN2(override_color.u32[i], max);180}181}182} else if (util_format_is_pure_sint(format)) {183for (int i = 0; i < 4; i++) {184unsigned bits = util_format_get_component_bits(185format, UTIL_FORMAT_COLORSPACE_RGB, i);186if (bits > 0 && bits < 32) {187int32_t max = (1 << (bits - 1)) - 1;188int32_t min = -(1 << (bits - 1));189override_color.i32[i] = CLAMP(override_color.i32[i], min, max);190}191}192} else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||193format == PIPE_FORMAT_R9G9B9E5_FLOAT) {194/* these packed float formats only store unsigned values */195for (int i = 0; i < 4; i++)196override_color.f32[i] = MAX2(override_color.f32[i], 0.0f);197}198199if (!(colormask & 1 << 3)) {200if (util_format_is_pure_integer(format))201override_color.u32[3] = 1;202else203override_color.f32[3] = 1.0f;204}205206return override_color;207}208209static void210fast_clear_color(struct iris_context *ice,211struct iris_resource *res,212unsigned level,213const struct pipe_box *box,214enum isl_format format,215union isl_color_value color)216{217struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];218struct pipe_resource *p_res = (void *) res;219220bool color_changed = !!memcmp(&res->aux.clear_color, &color,221sizeof(color));222223if (color_changed) {224/* If we are clearing to a new clear value, we need to resolve fast225* clears from other levels/layers first, since we can't have different226* levels/layers with different fast clear colors.227*/228for (unsigned res_lvl = 0; res_lvl < res->surf.levels; res_lvl++) {229const unsigned level_layers =230iris_get_num_logical_layers(res, res_lvl);231for (unsigned layer = 0; layer < level_layers; layer++) {232if (res_lvl == level &&233layer >= box->z &&234layer < box->z + box->depth) {235/* We're going to clear this layer anyway. Leave it alone. */236continue;237}238239enum isl_aux_state aux_state =240iris_resource_get_aux_state(res, res_lvl, layer);241242if (aux_state != ISL_AUX_STATE_CLEAR &&243aux_state != ISL_AUX_STATE_PARTIAL_CLEAR &&244aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {245/* This slice doesn't have any fast-cleared bits. */246continue;247}248249/* If we got here, then the level may have fast-clear bits that use250* the old clear value. We need to do a color resolve to get rid251* of their use of the clear color before we can change it.252* Fortunately, few applications ever change their clear color at253* different levels/layers, so this shouldn't happen often.254*/255iris_resource_prepare_access(ice, res,256res_lvl, 1, layer, 1,257res->aux.usage,258false);259perf_debug(&ice->dbg,260"Resolving resource (%p) level %d, layer %d: color changing from "261"(%0.2f, %0.2f, %0.2f, %0.2f) to "262"(%0.2f, %0.2f, %0.2f, %0.2f)\n",263res, res_lvl, layer,264res->aux.clear_color.f32[0],265res->aux.clear_color.f32[1],266res->aux.clear_color.f32[2],267res->aux.clear_color.f32[3],268color.f32[0], color.f32[1], color.f32[2], color.f32[3]);269}270}271}272273iris_resource_set_clear_color(ice, res, color);274275/* If the buffer is already in ISL_AUX_STATE_CLEAR, and the color hasn't276* changed, the clear is redundant and can be skipped.277*/278const enum isl_aux_state aux_state =279iris_resource_get_aux_state(res, level, box->z);280if (!color_changed && box->depth == 1 && aux_state == ISL_AUX_STATE_CLEAR)281return;282283/* Ivybridge PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":284*285* "Any transition from any value in {Clear, Render, Resolve} to a286* different value in {Clear, Render, Resolve} requires end of pipe287* synchronization."288*289* In other words, fast clear ops are not properly synchronized with290* other drawing. We need to use a PIPE_CONTROL to ensure that the291* contents of the previous draw hit the render target before we resolve292* and again afterwards to ensure that the resolve is complete before we293* do any more regular drawing.294*/295iris_emit_end_of_pipe_sync(batch,296"fast clear: pre-flush",297PIPE_CONTROL_RENDER_TARGET_FLUSH |298PIPE_CONTROL_TILE_CACHE_FLUSH);299300iris_batch_sync_region_start(batch);301302/* If we reach this point, we need to fast clear to change the state to303* ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both).304*/305enum blorp_batch_flags blorp_flags = 0;306blorp_flags |= color_changed ? 0 : BLORP_BATCH_NO_UPDATE_CLEAR_COLOR;307308struct blorp_batch blorp_batch;309blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);310311struct blorp_surf surf;312iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,313p_res, res->aux.usage, level, true);314315blorp_fast_clear(&blorp_batch, &surf, format, ISL_SWIZZLE_IDENTITY,316level, box->z, box->depth,317box->x, box->y, box->x + box->width,318box->y + box->height);319blorp_batch_finish(&blorp_batch);320iris_emit_end_of_pipe_sync(batch,321"fast clear: post flush",322PIPE_CONTROL_RENDER_TARGET_FLUSH);323iris_batch_sync_region_end(batch);324325iris_resource_set_aux_state(ice, res, level, box->z,326box->depth, ISL_AUX_STATE_CLEAR);327ice->state.dirty |= IRIS_DIRTY_RENDER_BUFFER;328ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;329return;330}331332static void333clear_color(struct iris_context *ice,334struct pipe_resource *p_res,335unsigned level,336const struct pipe_box *box,337bool render_condition_enabled,338enum isl_format format,339struct isl_swizzle swizzle,340union isl_color_value color)341{342struct iris_resource *res = (void *) p_res;343344struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];345const struct intel_device_info *devinfo = &batch->screen->devinfo;346enum blorp_batch_flags blorp_flags = 0;347348if (render_condition_enabled) {349if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)350return;351352if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)353blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;354}355356if (p_res->target == PIPE_BUFFER)357util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);358359iris_batch_maybe_flush(batch, 1500);360361bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box,362render_condition_enabled,363format, color);364if (can_fast_clear) {365fast_clear_color(ice, res, level, box, format, color);366return;367}368369bool color_write_disable[4] = { false, false, false, false };370enum isl_aux_usage aux_usage =371iris_resource_render_aux_usage(ice, res, level, format, false);372373iris_resource_prepare_render(ice, res, level, box->z, box->depth,374aux_usage);375iris_emit_buffer_barrier_for(batch, res->bo, IRIS_DOMAIN_RENDER_WRITE);376377struct blorp_surf surf;378iris_blorp_surf_for_resource(&batch->screen->isl_dev, &surf,379p_res, aux_usage, level, true);380381iris_batch_sync_region_start(batch);382383struct blorp_batch blorp_batch;384blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);385386if (!isl_format_supports_rendering(devinfo, format) &&387isl_format_is_rgbx(format))388format = isl_format_rgbx_to_rgba(format);389390blorp_clear(&blorp_batch, &surf, format, swizzle,391level, box->z, box->depth, box->x, box->y,392box->x + box->width, box->y + box->height,393color, color_write_disable);394395blorp_batch_finish(&blorp_batch);396iris_batch_sync_region_end(batch);397398iris_flush_and_dirty_for_history(ice, batch, res,399PIPE_CONTROL_RENDER_TARGET_FLUSH,400"cache history: post color clear");401402iris_resource_finish_render(ice, res, level,403box->z, box->depth, aux_usage);404}405406static bool407can_fast_clear_depth(struct iris_context *ice,408struct iris_resource *res,409unsigned level,410const struct pipe_box *box,411bool render_condition_enabled,412float depth)413{414struct pipe_resource *p_res = (void *) res;415struct pipe_context *ctx = (void *) ice;416struct iris_screen *screen = (void *) ctx->screen;417const struct intel_device_info *devinfo = &screen->devinfo;418419if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)420return false;421422/* Check for partial clears */423if (box->x > 0 || box->y > 0 ||424box->width < u_minify(p_res->width0, level) ||425box->height < u_minify(p_res->height0, level)) {426return false;427}428429/* Avoid conditional fast clears to maintain correct tracking of the aux430* state (see iris_resource_finish_write for more info). Note that partial431* fast clears would not pose a problem with conditional rendering.432*/433if (render_condition_enabled &&434ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT) {435return false;436}437438if (!iris_resource_level_has_hiz(res, level))439return false;440441if (!blorp_can_hiz_clear_depth(devinfo, &res->surf, res->aux.usage,442level, box->z, box->x, box->y,443box->x + box->width,444box->y + box->height)) {445return false;446}447448return true;449}450451static void452fast_clear_depth(struct iris_context *ice,453struct iris_resource *res,454unsigned level,455const struct pipe_box *box,456float depth)457{458struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];459460bool update_clear_depth = false;461462/* If we're clearing to a new clear value, then we need to resolve any clear463* flags out of the HiZ buffer into the real depth buffer.464*/465if (res->aux.clear_color.f32[0] != depth) {466for (unsigned res_level = 0; res_level < res->surf.levels; res_level++) {467const unsigned level_layers =468iris_get_num_logical_layers(res, res_level);469for (unsigned layer = 0; layer < level_layers; layer++) {470if (res_level == level &&471layer >= box->z &&472layer < box->z + box->depth) {473/* We're going to clear this layer anyway. Leave it alone. */474continue;475}476477enum isl_aux_state aux_state =478iris_resource_get_aux_state(res, res_level, layer);479480if (aux_state != ISL_AUX_STATE_CLEAR &&481aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {482/* This slice doesn't have any fast-cleared bits. */483continue;484}485486/* If we got here, then the level may have fast-clear bits that487* use the old clear value. We need to do a depth resolve to get488* rid of their use of the clear value before we can change it.489* Fortunately, few applications ever change their depth clear490* value so this shouldn't happen often.491*/492iris_hiz_exec(ice, batch, res, res_level, layer, 1,493ISL_AUX_OP_FULL_RESOLVE, false);494iris_resource_set_aux_state(ice, res, res_level, layer, 1,495ISL_AUX_STATE_RESOLVED);496iris_emit_pipe_control_flush(batch, "hiz op: post depth resolve",497PIPE_CONTROL_TILE_CACHE_FLUSH);498}499}500const union isl_color_value clear_value = { .f32 = {depth, } };501iris_resource_set_clear_color(ice, res, clear_value);502update_clear_depth = true;503}504505for (unsigned l = 0; l < box->depth; l++) {506enum isl_aux_state aux_state =507iris_resource_get_aux_state(res, level, box->z + l);508if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) {509if (aux_state == ISL_AUX_STATE_CLEAR) {510perf_debug(&ice->dbg, "Performing HiZ clear just to update the "511"depth clear value\n");512}513iris_hiz_exec(ice, batch, res, level,514box->z + l, 1, ISL_AUX_OP_FAST_CLEAR,515update_clear_depth);516}517}518519iris_resource_set_aux_state(ice, res, level, box->z, box->depth,520ISL_AUX_STATE_CLEAR);521ice->state.dirty |= IRIS_DIRTY_DEPTH_BUFFER;522ice->state.stage_dirty |= IRIS_ALL_STAGE_DIRTY_BINDINGS;523}524525static void526clear_depth_stencil(struct iris_context *ice,527struct pipe_resource *p_res,528unsigned level,529const struct pipe_box *box,530bool render_condition_enabled,531bool clear_depth,532bool clear_stencil,533float depth,534uint8_t stencil)535{536struct iris_resource *res = (void *) p_res;537538struct iris_batch *batch = &ice->batches[IRIS_BATCH_RENDER];539enum blorp_batch_flags blorp_flags = 0;540541if (render_condition_enabled) {542if (ice->state.predicate == IRIS_PREDICATE_STATE_DONT_RENDER)543return;544545if (ice->state.predicate == IRIS_PREDICATE_STATE_USE_BIT)546blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;547}548549iris_batch_maybe_flush(batch, 1500);550551struct iris_resource *z_res;552struct iris_resource *stencil_res;553struct blorp_surf z_surf;554struct blorp_surf stencil_surf;555556iris_get_depth_stencil_resources(p_res, &z_res, &stencil_res);557if (z_res && clear_depth &&558can_fast_clear_depth(ice, z_res, level, box, render_condition_enabled,559depth)) {560fast_clear_depth(ice, z_res, level, box, depth);561iris_flush_and_dirty_for_history(ice, batch, res, 0,562"cache history: post fast Z clear");563clear_depth = false;564z_res = false;565}566567/* At this point, we might have fast cleared the depth buffer. So if there's568* no stencil clear pending, return early.569*/570if (!(clear_depth || (clear_stencil && stencil_res))) {571return;572}573574if (clear_depth && z_res) {575const enum isl_aux_usage aux_usage =576iris_resource_render_aux_usage(ice, z_res, level, z_res->surf.format,577false);578iris_resource_prepare_render(ice, z_res, level, box->z, box->depth,579aux_usage);580iris_emit_buffer_barrier_for(batch, z_res->bo, IRIS_DOMAIN_DEPTH_WRITE);581iris_blorp_surf_for_resource(&batch->screen->isl_dev, &z_surf,582&z_res->base.b, aux_usage, level, true);583}584585uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0;586if (stencil_mask) {587iris_resource_prepare_access(ice, stencil_res, level, 1, box->z,588box->depth, stencil_res->aux.usage, false);589iris_emit_buffer_barrier_for(batch, stencil_res->bo,590IRIS_DOMAIN_DEPTH_WRITE);591iris_blorp_surf_for_resource(&batch->screen->isl_dev,592&stencil_surf, &stencil_res->base.b,593stencil_res->aux.usage, level, true);594}595596iris_batch_sync_region_start(batch);597598struct blorp_batch blorp_batch;599blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);600601blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf,602level, box->z, box->depth,603box->x, box->y,604box->x + box->width,605box->y + box->height,606clear_depth && z_res, depth,607stencil_mask, stencil);608609blorp_batch_finish(&blorp_batch);610iris_batch_sync_region_end(batch);611612iris_flush_and_dirty_for_history(ice, batch, res,613PIPE_CONTROL_TILE_CACHE_FLUSH,614"cache history: post slow ZS clear");615616if (clear_depth && z_res) {617iris_resource_finish_render(ice, z_res, level, box->z, box->depth,618z_surf.aux_usage);619}620621if (stencil_mask) {622iris_resource_finish_write(ice, stencil_res, level, box->z, box->depth,623stencil_res->aux.usage);624}625}626627/**628* The pipe->clear() driver hook.629*630* This clears buffers attached to the current draw framebuffer.631*/632static void633iris_clear(struct pipe_context *ctx,634unsigned buffers,635const struct pipe_scissor_state *scissor_state,636const union pipe_color_union *p_color,637double depth,638unsigned stencil)639{640struct iris_context *ice = (void *) ctx;641struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;642643assert(buffers != 0);644645struct pipe_box box = {646.width = cso_fb->width,647.height = cso_fb->height,648};649650if (scissor_state) {651box.x = scissor_state->minx;652box.y = scissor_state->miny;653box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx);654box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny);655}656657if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {658struct pipe_surface *psurf = cso_fb->zsbuf;659660box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;661box.z = psurf->u.tex.first_layer,662clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true,663buffers & PIPE_CLEAR_DEPTH,664buffers & PIPE_CLEAR_STENCIL,665depth, stencil);666}667668if (buffers & PIPE_CLEAR_COLOR) {669for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {670if (buffers & (PIPE_CLEAR_COLOR0 << i)) {671struct pipe_surface *psurf = cso_fb->cbufs[i];672struct iris_surface *isurf = (void *) psurf;673box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,674box.z = psurf->u.tex.first_layer,675676clear_color(ice, psurf->texture, psurf->u.tex.level, &box,677true, isurf->view.format, isurf->view.swizzle,678convert_clear_color(psurf->format, p_color));679}680}681}682}683684/**685* The pipe->clear_texture() driver hook.686*687* This clears the given texture resource.688*/689static void690iris_clear_texture(struct pipe_context *ctx,691struct pipe_resource *p_res,692unsigned level,693const struct pipe_box *box,694const void *data)695{696struct iris_context *ice = (void *) ctx;697struct iris_screen *screen = (void *) ctx->screen;698struct iris_resource *res = (void *) p_res;699const struct intel_device_info *devinfo = &screen->devinfo;700701if (iris_resource_unfinished_aux_import(res))702iris_resource_finish_aux_import(ctx->screen, res);703704if (util_format_is_depth_or_stencil(p_res->format)) {705const struct util_format_unpack_description *unpack =706util_format_unpack_description(p_res->format);707708float depth = 0.0;709uint8_t stencil = 0;710711if (unpack->unpack_z_float)712util_format_unpack_z_float(p_res->format, &depth, data, 1);713714if (unpack->unpack_s_8uint)715util_format_unpack_s_8uint(p_res->format, &stencil, data, 1);716717clear_depth_stencil(ice, p_res, level, box, true, true, true,718depth, stencil);719} else {720union isl_color_value color;721struct iris_resource *res = (void *) p_res;722enum isl_format format = res->surf.format;723724if (!isl_format_supports_rendering(devinfo, format)) {725const struct isl_format_layout *fmtl = isl_format_get_layout(format);726// XXX: actually just get_copy_format_for_bpb from BLORP727// XXX: don't cut and paste this728switch (fmtl->bpb) {729case 8: format = ISL_FORMAT_R8_UINT; break;730case 16: format = ISL_FORMAT_R8G8_UINT; break;731case 24: format = ISL_FORMAT_R8G8B8_UINT; break;732case 32: format = ISL_FORMAT_R8G8B8A8_UINT; break;733case 48: format = ISL_FORMAT_R16G16B16_UINT; break;734case 64: format = ISL_FORMAT_R16G16B16A16_UINT; break;735case 96: format = ISL_FORMAT_R32G32B32_UINT; break;736case 128: format = ISL_FORMAT_R32G32B32A32_UINT; break;737default:738unreachable("Unknown format bpb");739}740741/* No aux surfaces for non-renderable surfaces */742assert(res->aux.usage == ISL_AUX_USAGE_NONE);743}744745isl_color_value_unpack(&color, format, data);746747clear_color(ice, p_res, level, box, true, format,748ISL_SWIZZLE_IDENTITY, color);749}750}751752/**753* The pipe->clear_render_target() driver hook.754*755* This clears the given render target surface.756*/757static void758iris_clear_render_target(struct pipe_context *ctx,759struct pipe_surface *psurf,760const union pipe_color_union *p_color,761unsigned dst_x, unsigned dst_y,762unsigned width, unsigned height,763bool render_condition_enabled)764{765struct iris_context *ice = (void *) ctx;766struct iris_surface *isurf = (void *) psurf;767struct pipe_box box = {768.x = dst_x,769.y = dst_y,770.z = psurf->u.tex.first_layer,771.width = width,772.height = height,773.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1774};775776clear_color(ice, psurf->texture, psurf->u.tex.level, &box,777render_condition_enabled,778isurf->view.format, isurf->view.swizzle,779convert_clear_color(psurf->format, p_color));780}781782/**783* The pipe->clear_depth_stencil() driver hook.784*785* This clears the given depth/stencil surface.786*/787static void788iris_clear_depth_stencil(struct pipe_context *ctx,789struct pipe_surface *psurf,790unsigned flags,791double depth,792unsigned stencil,793unsigned dst_x, unsigned dst_y,794unsigned width, unsigned height,795bool render_condition_enabled)796{797struct iris_context *ice = (void *) ctx;798struct pipe_box box = {799.x = dst_x,800.y = dst_y,801.z = psurf->u.tex.first_layer,802.width = width,803.height = height,804.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1805};806807assert(util_format_is_depth_or_stencil(psurf->texture->format));808809clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box,810render_condition_enabled,811flags & PIPE_CLEAR_DEPTH, flags & PIPE_CLEAR_STENCIL,812depth, stencil);813}814815void816iris_init_clear_functions(struct pipe_context *ctx)817{818ctx->clear = iris_clear;819ctx->clear_texture = iris_clear_texture;820ctx->clear_render_target = iris_clear_render_target;821ctx->clear_depth_stencil = iris_clear_depth_stencil;822}823824825