Path: blob/21.2-virgl/src/gallium/drivers/crocus/crocus_clear.c
4570 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/u_surface.h"30#include "util/format/u_format.h"31#include "util/u_upload_mgr.h"32#include "util/ralloc.h"33#include "crocus_context.h"34#include "crocus_resource.h"35#include "crocus_screen.h"36#include "intel/compiler/brw_compiler.h"37#include "util/format_srgb.h"3839static bool40crocus_is_color_fast_clear_compatible(struct crocus_context *ice,41enum isl_format format,42const union isl_color_value color)43{44if (isl_format_has_int_channel(format)) {45perf_debug(&ice->dbg, "Integer fast clear not enabled for %s",46isl_format_get_name(format));47return false;48}4950for (int i = 0; i < 4; i++) {51if (!isl_format_has_color_component(format, i)) {52continue;53}5455if (color.f32[i] != 0.0f && color.f32[i] != 1.0f) {56return false;57}58}5960return true;61}6263static bool64can_fast_clear_color(struct crocus_context *ice,65struct pipe_resource *p_res,66unsigned level,67const struct pipe_box *box,68bool render_condition_enabled,69enum isl_format format,70enum isl_format render_format,71union isl_color_value color)72{73struct crocus_resource *res = (void *) p_res;7475if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)76return false;7778if (!isl_aux_usage_has_fast_clears(res->aux.usage))79return false;8081/* Check for partial clear */82if (box->x > 0 || box->y > 0 ||83box->width < minify(p_res->width0, level) ||84box->height < minify(p_res->height0, level)) {85return false;86}8788/* Avoid conditional fast clears to maintain correct tracking of the aux89* state (see iris_resource_finish_write for more info). Note that partial90* fast clears (if they existed) would not pose a problem with conditional91* rendering.92*/93if (render_condition_enabled &&94ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT) {95return false;96}9798/* We store clear colors as floats or uints as needed. If there are99* texture views in play, the formats will not properly be respected100* during resolves because the resolve operations only know about the101* resource and not the renderbuffer.102*/103if (isl_format_srgb_to_linear(render_format) !=104isl_format_srgb_to_linear(format)) {105return false;106}107108/* XXX: if (irb->mt->supports_fast_clear)109* see intel_miptree_create_for_dri_image()110*/111112if (!crocus_is_color_fast_clear_compatible(ice, format, color))113return false;114115return true;116}117118static union isl_color_value119convert_fast_clear_color(struct crocus_context *ice,120struct crocus_resource *res,121enum isl_format render_format,122const union isl_color_value color)123{124union isl_color_value override_color = color;125struct pipe_resource *p_res = (void *) res;126127const enum pipe_format format = p_res->format;128const struct util_format_description *desc =129util_format_description(format);130unsigned colormask = util_format_colormask(desc);131132if (util_format_is_intensity(format) ||133util_format_is_luminance(format) ||134util_format_is_luminance_alpha(format)) {135override_color.u32[1] = override_color.u32[0];136override_color.u32[2] = override_color.u32[0];137if (util_format_is_intensity(format))138override_color.u32[3] = override_color.u32[0];139} else {140for (int chan = 0; chan < 3; chan++) {141if (!(colormask & (1 << chan)))142override_color.u32[chan] = 0;143}144}145146if (util_format_is_unorm(format)) {147for (int i = 0; i < 4; i++)148override_color.f32[i] = CLAMP(override_color.f32[i], 0.0f, 1.0f);149} else if (util_format_is_snorm(format)) {150for (int i = 0; i < 4; i++)151override_color.f32[i] = CLAMP(override_color.f32[i], -1.0f, 1.0f);152} else if (util_format_is_pure_uint(format)) {153for (int i = 0; i < 4; i++) {154unsigned bits = util_format_get_component_bits(155format, UTIL_FORMAT_COLORSPACE_RGB, i);156if (bits < 32) {157uint32_t max = (1u << bits) - 1;158override_color.u32[i] = MIN2(override_color.u32[i], max);159}160}161} else if (util_format_is_pure_sint(format)) {162for (int i = 0; i < 4; i++) {163unsigned bits = util_format_get_component_bits(164format, UTIL_FORMAT_COLORSPACE_RGB, i);165if (bits < 32) {166int32_t max = (1 << (bits - 1)) - 1;167int32_t min = -(1 << (bits - 1));168override_color.i32[i] = CLAMP(override_color.i32[i], min, max);169}170}171} else if (format == PIPE_FORMAT_R11G11B10_FLOAT ||172format == PIPE_FORMAT_R9G9B9E5_FLOAT) {173/* these packed float formats only store unsigned values */174for (int i = 0; i < 4; i++)175override_color.f32[i] = MAX2(override_color.f32[i], 0.0f);176}177178if (!(colormask & 1 << 3)) {179if (util_format_is_pure_integer(format))180override_color.u32[3] = 1;181else182override_color.f32[3] = 1.0f;183}184185/* Handle linear to SRGB conversion */186if (isl_format_is_srgb(render_format)) {187for (int i = 0; i < 3; i++) {188override_color.f32[i] =189util_format_linear_to_srgb_float(override_color.f32[i]);190}191}192193return override_color;194}195196static void197fast_clear_color(struct crocus_context *ice,198struct crocus_resource *res,199unsigned level,200const struct pipe_box *box,201enum isl_format format,202union isl_color_value color,203enum blorp_batch_flags blorp_flags)204{205struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];206struct crocus_screen *screen = batch->screen;207struct pipe_resource *p_res = (void *) res;208209color = convert_fast_clear_color(ice, res, format, color);210211bool color_changed = !!memcmp(&res->aux.clear_color, &color,212sizeof(color));213214if (color_changed) {215/* If we are clearing to a new clear value, we need to resolve fast216* clears from other levels/layers first, since we can't have different217* levels/layers with different fast clear colors.218*/219for (unsigned res_lvl = 0; res_lvl < res->surf.levels; res_lvl++) {220const unsigned level_layers =221crocus_get_num_logical_layers(res, res_lvl);222for (unsigned layer = 0; layer < level_layers; layer++) {223if (res_lvl == level &&224layer >= box->z &&225layer < box->z + box->depth) {226/* We're going to clear this layer anyway. Leave it alone. */227continue;228}229230enum isl_aux_state aux_state =231crocus_resource_get_aux_state(res, res_lvl, layer);232233if (aux_state != ISL_AUX_STATE_CLEAR &&234aux_state != ISL_AUX_STATE_PARTIAL_CLEAR &&235aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {236/* This slice doesn't have any fast-cleared bits. */237continue;238}239240/* If we got here, then the level may have fast-clear bits that use241* the old clear value. We need to do a color resolve to get rid242* of their use of the clear color before we can change it.243* Fortunately, few applications ever change their clear color at244* different levels/layers, so this shouldn't happen often.245*/246crocus_resource_prepare_access(ice, res,247res_lvl, 1, layer, 1,248res->aux.usage,249false);250perf_debug(&ice->dbg,251"Resolving resource (%p) level %d, layer %d: color changing from "252"(%0.2f, %0.2f, %0.2f, %0.2f) to "253"(%0.2f, %0.2f, %0.2f, %0.2f)\n",254res, res_lvl, layer,255res->aux.clear_color.f32[0],256res->aux.clear_color.f32[1],257res->aux.clear_color.f32[2],258res->aux.clear_color.f32[3],259color.f32[0], color.f32[1], color.f32[2], color.f32[3]);260}261}262}263264crocus_resource_set_clear_color(ice, res, color);265266/* If the buffer is already in ISL_AUX_STATE_CLEAR, and the color hasn't267* changed, the clear is redundant and can be skipped.268*/269const enum isl_aux_state aux_state =270crocus_resource_get_aux_state(res, level, box->z);271if (!color_changed && box->depth == 1 && aux_state == ISL_AUX_STATE_CLEAR)272return;273274/* Ivybrigde PRM Vol 2, Part 1, "11.7 MCS Buffer for Render Target(s)":275*276* "Any transition from any value in {Clear, Render, Resolve} to a277* different value in {Clear, Render, Resolve} requires end of pipe278* synchronization."279*280* In other words, fast clear ops are not properly synchronized with281* other drawing. We need to use a PIPE_CONTROL to ensure that the282* contents of the previous draw hit the render target before we resolve283* and again afterwards to ensure that the resolve is complete before we284* do any more regular drawing.285*/286crocus_emit_end_of_pipe_sync(batch,287"fast clear: pre-flush",288PIPE_CONTROL_RENDER_TARGET_FLUSH);289290/* If we reach this point, we need to fast clear to change the state to291* ISL_AUX_STATE_CLEAR, or to update the fast clear color (or both).292*/293blorp_flags |= color_changed ? 0 : BLORP_BATCH_NO_UPDATE_CLEAR_COLOR;294295struct blorp_batch blorp_batch;296blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);297298struct blorp_surf surf;299crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev, &surf,300p_res, res->aux.usage, level, true);301302/* In newer gens (> 9), the hardware will do a linear -> sRGB conversion of303* the clear color during the fast clear, if the surface format is of sRGB304* type. We use the linear version of the surface format here to prevent305* that from happening, since we already do our own linear -> sRGB306* conversion in convert_fast_clear_color().307*/308blorp_fast_clear(&blorp_batch, &surf, isl_format_srgb_to_linear(format),309ISL_SWIZZLE_IDENTITY,310level, box->z, box->depth,311box->x, box->y, box->x + box->width,312box->y + box->height);313blorp_batch_finish(&blorp_batch);314crocus_emit_end_of_pipe_sync(batch,315"fast clear: post flush",316PIPE_CONTROL_RENDER_TARGET_FLUSH);317318crocus_resource_set_aux_state(ice, res, level, box->z,319box->depth, ISL_AUX_STATE_CLEAR);320ice->state.stage_dirty |= CROCUS_ALL_STAGE_DIRTY_BINDINGS;321return;322}323324static void325clear_color(struct crocus_context *ice,326struct pipe_resource *p_res,327unsigned level,328const struct pipe_box *box,329bool render_condition_enabled,330enum isl_format format,331struct isl_swizzle swizzle,332union isl_color_value color)333{334struct crocus_resource *res = (void *) p_res;335struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];336struct crocus_screen *screen = batch->screen;337const struct intel_device_info *devinfo = &batch->screen->devinfo;338enum blorp_batch_flags blorp_flags = 0;339340if (render_condition_enabled) {341if (!crocus_check_conditional_render(ice))342return;343344if (ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT)345blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;346}347348if (p_res->target == PIPE_BUFFER)349util_range_add(&res->base.b, &res->valid_buffer_range, box->x, box->x + box->width);350351crocus_batch_maybe_flush(batch, 1500);352353bool can_fast_clear = can_fast_clear_color(ice, p_res, level, box,354render_condition_enabled,355res->surf.format, format, color);356if (can_fast_clear) {357fast_clear_color(ice, res, level, box, format, color,358blorp_flags);359return;360}361362bool color_write_disable[4] = { false, false, false, false };363enum isl_aux_usage aux_usage =364crocus_resource_render_aux_usage(ice, res, level, format, false);365366crocus_resource_prepare_render(ice, res, level,367box->z, box->depth, aux_usage);368369struct blorp_surf surf;370crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev, &surf,371p_res, aux_usage, level, true);372373struct blorp_batch blorp_batch;374blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);375376if (!isl_format_supports_rendering(devinfo, format) &&377isl_format_is_rgbx(format))378format = isl_format_rgbx_to_rgba(format);379380blorp_clear(&blorp_batch, &surf, format, swizzle,381level, box->z, box->depth, box->x, box->y,382box->x + box->width, box->y + box->height,383color, color_write_disable);384385blorp_batch_finish(&blorp_batch);386crocus_flush_and_dirty_for_history(ice, batch, res,387PIPE_CONTROL_RENDER_TARGET_FLUSH,388"cache history: post color clear");389390crocus_resource_finish_render(ice, res, level,391box->z, box->depth, aux_usage);392}393394static bool395can_fast_clear_depth(struct crocus_context *ice,396struct crocus_resource *res,397unsigned level,398const struct pipe_box *box,399bool render_condition_enabled,400float depth)401{402struct pipe_resource *p_res = (void *) res;403struct pipe_context *ctx = (void *) ice;404struct crocus_screen *screen = (void *) ctx->screen;405const struct intel_device_info *devinfo = &screen->devinfo;406407if (devinfo->ver < 6)408return false;409410if (INTEL_DEBUG & DEBUG_NO_FAST_CLEAR)411return false;412413/* Check for partial clears */414if (box->x > 0 || box->y > 0 ||415box->width < u_minify(p_res->width0, level) ||416box->height < u_minify(p_res->height0, level)) {417return false;418}419420/* Avoid conditional fast clears to maintain correct tracking of the aux421* state (see iris_resource_finish_write for more info). Note that partial422* fast clears would not pose a problem with conditional rendering.423*/424if (render_condition_enabled &&425ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT) {426return false;427}428429if (!crocus_resource_level_has_hiz(res, level))430return false;431432if (res->base.b.format == PIPE_FORMAT_Z16_UNORM) {433/* From the Sandy Bridge PRM, volume 2 part 1, page 314:434*435* "[DevSNB+]: Several cases exist where Depth Buffer Clear cannot be436* enabled (the legacy method of clearing must be performed):437*438* - DevSNB{W/A}]: When depth buffer format is D16_UNORM and the439* width of the map (LOD0) is not multiple of 16, fast clear440* optimization must be disabled.441*/442if (devinfo->ver == 6 &&443(minify(res->surf.phys_level0_sa.width,444level) % 16) != 0)445return false;446}447return true;448}449450static void451fast_clear_depth(struct crocus_context *ice,452struct crocus_resource *res,453unsigned level,454const struct pipe_box *box,455float depth)456{457struct pipe_resource *p_res = (void *) res;458struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];459460/* Quantize the clear value to what can be stored in the actual depth461* buffer. This makes the following check more accurate because it now462* checks if the actual depth bits will match. It also prevents us from463* getting a too-accurate depth value during depth testing or when sampling464* with HiZ enabled.465*/466const unsigned nbits = p_res->format == PIPE_FORMAT_Z16_UNORM ? 16 : 24;467const uint32_t depth_max = (1 << nbits) - 1;468depth = p_res->format == PIPE_FORMAT_Z32_FLOAT ? depth :469(unsigned)(depth * depth_max) / (float)depth_max;470471bool update_clear_depth = false;472473/* If we're clearing to a new clear value, then we need to resolve any clear474* flags out of the HiZ buffer into the real depth buffer.475*/476if (res->aux.clear_color.f32[0] != depth) {477for (unsigned res_level = 0; res_level < res->surf.levels; res_level++) {478if (!crocus_resource_level_has_hiz(res, res_level))479continue;480481const unsigned level_layers =482crocus_get_num_logical_layers(res, res_level);483for (unsigned layer = 0; layer < level_layers; layer++) {484if (res_level == level &&485layer >= box->z &&486layer < box->z + box->depth) {487/* We're going to clear this layer anyway. Leave it alone. */488continue;489}490491enum isl_aux_state aux_state =492crocus_resource_get_aux_state(res, res_level, layer);493494if (aux_state != ISL_AUX_STATE_CLEAR &&495aux_state != ISL_AUX_STATE_COMPRESSED_CLEAR) {496/* This slice doesn't have any fast-cleared bits. */497continue;498}499500/* If we got here, then the level may have fast-clear bits that501* use the old clear value. We need to do a depth resolve to get502* rid of their use of the clear value before we can change it.503* Fortunately, few applications ever change their depth clear504* value so this shouldn't happen often.505*/506crocus_hiz_exec(ice, batch, res, res_level, layer, 1,507ISL_AUX_OP_FULL_RESOLVE, false);508crocus_resource_set_aux_state(ice, res, res_level, layer, 1,509ISL_AUX_STATE_RESOLVED);510}511}512const union isl_color_value clear_value = { .f32 = {depth, } };513crocus_resource_set_clear_color(ice, res, clear_value);514update_clear_depth = true;515}516517for (unsigned l = 0; l < box->depth; l++) {518enum isl_aux_state aux_state =519crocus_resource_level_has_hiz(res, level) ?520crocus_resource_get_aux_state(res, level, box->z + l) :521ISL_AUX_STATE_AUX_INVALID;522if (update_clear_depth || aux_state != ISL_AUX_STATE_CLEAR) {523if (aux_state == ISL_AUX_STATE_CLEAR) {524perf_debug(&ice->dbg, "Performing HiZ clear just to update the "525"depth clear value\n");526}527crocus_hiz_exec(ice, batch, res, level,528box->z + l, 1, ISL_AUX_OP_FAST_CLEAR,529update_clear_depth);530}531}532533crocus_resource_set_aux_state(ice, res, level, box->z, box->depth,534ISL_AUX_STATE_CLEAR);535ice->state.dirty |= CROCUS_DIRTY_DEPTH_BUFFER;536}537538static void539clear_depth_stencil(struct crocus_context *ice,540struct pipe_resource *p_res,541unsigned level,542const struct pipe_box *box,543bool render_condition_enabled,544bool clear_depth,545bool clear_stencil,546float depth,547uint8_t stencil)548{549struct crocus_resource *res = (void *) p_res;550struct crocus_batch *batch = &ice->batches[CROCUS_BATCH_RENDER];551struct crocus_screen *screen = batch->screen;552enum blorp_batch_flags blorp_flags = 0;553554if (render_condition_enabled) {555if (!crocus_check_conditional_render(ice))556return;557558if (ice->state.predicate == CROCUS_PREDICATE_STATE_USE_BIT)559blorp_flags |= BLORP_BATCH_PREDICATE_ENABLE;560}561562crocus_batch_maybe_flush(batch, 1500);563564struct crocus_resource *z_res;565struct crocus_resource *stencil_res;566struct blorp_surf z_surf;567struct blorp_surf stencil_surf;568569crocus_get_depth_stencil_resources(&batch->screen->devinfo, p_res, &z_res, &stencil_res);570if (z_res && clear_depth &&571can_fast_clear_depth(ice, z_res, level, box, render_condition_enabled,572depth)) {573fast_clear_depth(ice, z_res, level, box, depth);574crocus_flush_and_dirty_for_history(ice, batch, res, 0,575"cache history: post fast Z clear");576clear_depth = false;577z_res = NULL;578}579580/* At this point, we might have fast cleared the depth buffer. So if there's581* no stencil clear pending, return early.582*/583if (!(clear_depth || (clear_stencil && stencil_res))) {584return;585}586587if (clear_depth && z_res) {588const enum isl_aux_usage aux_usage =589crocus_resource_render_aux_usage(ice, z_res, level, z_res->surf.format,590false);591crocus_resource_prepare_render(ice, z_res, level, box->z, box->depth,592aux_usage);593crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev,594&z_surf, &z_res->base.b, aux_usage,595level, true);596}597598struct blorp_batch blorp_batch;599blorp_batch_init(&ice->blorp, &blorp_batch, batch, blorp_flags);600601uint8_t stencil_mask = clear_stencil && stencil_res ? 0xff : 0;602if (stencil_mask) {603crocus_resource_prepare_access(ice, stencil_res, level, 1, box->z,604box->depth, stencil_res->aux.usage, false);605crocus_blorp_surf_for_resource(&screen->vtbl, &batch->screen->isl_dev,606&stencil_surf, &stencil_res->base.b,607stencil_res->aux.usage, level, true);608}609610blorp_clear_depth_stencil(&blorp_batch, &z_surf, &stencil_surf,611level, box->z, box->depth,612box->x, box->y,613box->x + box->width,614box->y + box->height,615clear_depth && z_res, depth,616stencil_mask, stencil);617618blorp_batch_finish(&blorp_batch);619crocus_flush_and_dirty_for_history(ice, batch, res, 0,620"cache history: post slow ZS clear");621622if (clear_depth && z_res) {623crocus_resource_finish_render(ice, z_res, level,624box->z, box->depth, z_surf.aux_usage);625}626627if (stencil_mask) {628crocus_resource_finish_write(ice, stencil_res, level, box->z, box->depth,629stencil_res->aux.usage);630}631}632633/**634* The pipe->clear() driver hook.635*636* This clears buffers attached to the current draw framebuffer.637*/638static void639crocus_clear(struct pipe_context *ctx,640unsigned buffers,641const struct pipe_scissor_state *scissor_state,642const union pipe_color_union *p_color,643double depth,644unsigned stencil)645{646struct crocus_context *ice = (void *) ctx;647struct pipe_framebuffer_state *cso_fb = &ice->state.framebuffer;648struct crocus_screen *screen = (void *) ctx->screen;649const struct intel_device_info *devinfo = &screen->devinfo;650assert(buffers != 0);651652struct pipe_box box = {653.width = cso_fb->width,654.height = cso_fb->height,655};656657if (scissor_state) {658box.x = scissor_state->minx;659box.y = scissor_state->miny;660box.width = MIN2(box.width, scissor_state->maxx - scissor_state->minx);661box.height = MIN2(box.height, scissor_state->maxy - scissor_state->miny);662}663664if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {665if (devinfo->ver < 6) {666crocus_blitter_begin(ice, CROCUS_SAVE_FRAGMENT_STATE, true);667util_blitter_clear(ice->blitter, cso_fb->width, cso_fb->height,668util_framebuffer_get_num_layers(cso_fb),669buffers & PIPE_CLEAR_DEPTHSTENCIL, p_color, depth, stencil, false);670} else {671struct pipe_surface *psurf = cso_fb->zsbuf;672box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1;673box.z = psurf->u.tex.first_layer;674675clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box, true,676buffers & PIPE_CLEAR_DEPTH,677buffers & PIPE_CLEAR_STENCIL,678depth, stencil);679}680buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;681}682683if (buffers & PIPE_CLEAR_COLOR) {684/* pipe_color_union and isl_color_value are interchangeable */685union isl_color_value *color = (void *) p_color;686687for (unsigned i = 0; i < cso_fb->nr_cbufs; i++) {688if (buffers & (PIPE_CLEAR_COLOR0 << i)) {689struct pipe_surface *psurf = cso_fb->cbufs[i];690struct crocus_surface *isurf = (void *) psurf;691box.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1,692box.z = psurf->u.tex.first_layer,693694clear_color(ice, psurf->texture, psurf->u.tex.level, &box,695true, isurf->view.format, isurf->view.swizzle,696*color);697}698}699}700}701702/**703* The pipe->clear_texture() driver hook.704*705* This clears the given texture resource.706*/707static void708crocus_clear_texture(struct pipe_context *ctx,709struct pipe_resource *p_res,710unsigned level,711const struct pipe_box *box,712const void *data)713{714struct crocus_context *ice = (void *) ctx;715struct crocus_screen *screen = (void *) ctx->screen;716const struct intel_device_info *devinfo = &screen->devinfo;717struct crocus_resource *res = (void *) p_res;718719if (devinfo->ver < 6) {720util_clear_texture(ctx, p_res,721level, box, data);722return;723}724725if (crocus_resource_unfinished_aux_import(res))726crocus_resource_finish_aux_import(ctx->screen, res);727728if (util_format_is_depth_or_stencil(p_res->format)) {729const struct util_format_unpack_description *fmt_unpack =730util_format_unpack_description(p_res->format);731732float depth = 0.0;733uint8_t stencil = 0;734735if (fmt_unpack->unpack_z_float)736fmt_unpack->unpack_z_float(&depth, 0, data, 0, 1, 1);737738if (fmt_unpack->unpack_s_8uint)739fmt_unpack->unpack_s_8uint(&stencil, 0, data, 0, 1, 1);740741clear_depth_stencil(ice, p_res, level, box, true, true, true,742depth, stencil);743} else {744union isl_color_value color;745struct crocus_resource *res = (void *) p_res;746enum isl_format format = res->surf.format;747748if (!isl_format_supports_rendering(devinfo, format)) {749const struct isl_format_layout *fmtl = isl_format_get_layout(format);750// XXX: actually just get_copy_format_for_bpb from BLORP751// XXX: don't cut and paste this752switch (fmtl->bpb) {753case 8: format = ISL_FORMAT_R8_UINT; break;754case 16: format = ISL_FORMAT_R8G8_UINT; break;755case 24: format = ISL_FORMAT_R8G8B8_UINT; break;756case 32: format = ISL_FORMAT_R8G8B8A8_UINT; break;757case 48: format = ISL_FORMAT_R16G16B16_UINT; break;758case 64: format = ISL_FORMAT_R16G16B16A16_UINT; break;759case 96: format = ISL_FORMAT_R32G32B32_UINT; break;760case 128: format = ISL_FORMAT_R32G32B32A32_UINT; break;761default:762unreachable("Unknown format bpb");763}764765/* No aux surfaces for non-renderable surfaces */766assert(res->aux.usage == ISL_AUX_USAGE_NONE);767}768769isl_color_value_unpack(&color, format, data);770771clear_color(ice, p_res, level, box, true, format,772ISL_SWIZZLE_IDENTITY, color);773}774}775776/**777* The pipe->clear_render_target() driver hook.778*779* This clears the given render target surface.780*/781static void782crocus_clear_render_target(struct pipe_context *ctx,783struct pipe_surface *psurf,784const union pipe_color_union *p_color,785unsigned dst_x, unsigned dst_y,786unsigned width, unsigned height,787bool render_condition_enabled)788{789struct crocus_context *ice = (void *) ctx;790struct crocus_surface *isurf = (void *) psurf;791struct pipe_box box = {792.x = dst_x,793.y = dst_y,794.z = psurf->u.tex.first_layer,795.width = width,796.height = height,797.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1798};799800/* pipe_color_union and isl_color_value are interchangeable */801union isl_color_value *color = (void *) p_color;802803clear_color(ice, psurf->texture, psurf->u.tex.level, &box,804render_condition_enabled,805isurf->view.format, isurf->view.swizzle, *color);806}807808/**809* The pipe->clear_depth_stencil() driver hook.810*811* This clears the given depth/stencil surface.812*/813static void814crocus_clear_depth_stencil(struct pipe_context *ctx,815struct pipe_surface *psurf,816unsigned flags,817double depth,818unsigned stencil,819unsigned dst_x, unsigned dst_y,820unsigned width, unsigned height,821bool render_condition_enabled)822{823return;824#if 0825struct crocus_context *ice = (void *) ctx;826struct pipe_box box = {827.x = dst_x,828.y = dst_y,829.z = psurf->u.tex.first_layer,830.width = width,831.height = height,832.depth = psurf->u.tex.last_layer - psurf->u.tex.first_layer + 1833};834uint32_t blit_flags = 0;835836assert(util_format_is_depth_or_stencil(psurf->texture->format));837838crocus_blitter_begin(ice, CROCUS_SAVE_FRAGMENT_STATE);839util_blitter_clear(ice->blitter, width, height,8401, flags, NULL, depth, stencil, render_condition_enabled);841#if 0842clear_depth_stencil(ice, psurf->texture, psurf->u.tex.level, &box,843render_condition_enabled,844flags & PIPE_CLEAR_DEPTH, flags & PIPE_CLEAR_STENCIL,845depth, stencil);846#endif847#endif848}849850void851crocus_init_clear_functions(struct pipe_context *ctx)852{853ctx->clear = crocus_clear;854ctx->clear_texture = crocus_clear_texture;855ctx->clear_render_target = crocus_clear_render_target;856ctx->clear_depth_stencil = crocus_clear_depth_stencil;857}858859860