Path: blob/21.2-virgl/src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
4574 views
/*1* Copyright (C) 2017 Rob Clark <[email protected]>2* Copyright © 2018 Google, Inc.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*23* Authors:24* Rob Clark <[email protected]>25*/2627#include "util/format_srgb.h"28#include "util/half_float.h"29#include "util/u_dump.h"3031#include "freedreno_blitter.h"32#include "freedreno_fence.h"33#include "freedreno_resource.h"34#include "freedreno_tracepoints.h"3536#include "fd6_blitter.h"37#include "fd6_emit.h"38#include "fd6_format.h"39#include "fd6_resource.h"4041static inline enum a6xx_2d_ifmt42fd6_ifmt(enum a6xx_format fmt)43{44switch (fmt) {45case FMT6_A8_UNORM:46case FMT6_8_UNORM:47case FMT6_8_SNORM:48case FMT6_8_8_UNORM:49case FMT6_8_8_SNORM:50case FMT6_8_8_8_8_UNORM:51case FMT6_8_8_8_X8_UNORM:52case FMT6_8_8_8_8_SNORM:53case FMT6_4_4_4_4_UNORM:54case FMT6_5_5_5_1_UNORM:55case FMT6_5_6_5_UNORM:56return R2D_UNORM8;5758case FMT6_32_UINT:59case FMT6_32_SINT:60case FMT6_32_32_UINT:61case FMT6_32_32_SINT:62case FMT6_32_32_32_32_UINT:63case FMT6_32_32_32_32_SINT:64return R2D_INT32;6566case FMT6_16_UINT:67case FMT6_16_SINT:68case FMT6_16_16_UINT:69case FMT6_16_16_SINT:70case FMT6_16_16_16_16_UINT:71case FMT6_16_16_16_16_SINT:72case FMT6_10_10_10_2_UINT:73return R2D_INT16;7475case FMT6_8_UINT:76case FMT6_8_SINT:77case FMT6_8_8_UINT:78case FMT6_8_8_SINT:79case FMT6_8_8_8_8_UINT:80case FMT6_8_8_8_8_SINT:81case FMT6_Z24_UNORM_S8_UINT:82case FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8:83return R2D_INT8;8485case FMT6_16_UNORM:86case FMT6_16_SNORM:87case FMT6_16_16_UNORM:88case FMT6_16_16_SNORM:89case FMT6_16_16_16_16_UNORM:90case FMT6_16_16_16_16_SNORM:91case FMT6_32_FLOAT:92case FMT6_32_32_FLOAT:93case FMT6_32_32_32_32_FLOAT:94return R2D_FLOAT32;9596case FMT6_16_FLOAT:97case FMT6_16_16_FLOAT:98case FMT6_16_16_16_16_FLOAT:99case FMT6_11_11_10_FLOAT:100case FMT6_10_10_10_2_UNORM_DEST:101return R2D_FLOAT16;102103default:104unreachable("bad format");105return 0;106}107}108109/* Make sure none of the requested dimensions extend beyond the size of the110* resource. Not entirely sure why this happens, but sometimes it does, and111* w/ 2d blt doesn't have wrap modes like a sampler, so force those cases112* back to u_blitter113*/114static bool115ok_dims(const struct pipe_resource *r, const struct pipe_box *b, int lvl)116{117int last_layer =118r->target == PIPE_TEXTURE_3D ? u_minify(r->depth0, lvl) : r->array_size;119120return (b->x >= 0) && (b->x + b->width <= u_minify(r->width0, lvl)) &&121(b->y >= 0) && (b->y + b->height <= u_minify(r->height0, lvl)) &&122(b->z >= 0) && (b->z + b->depth <= last_layer);123}124125static bool126ok_format(enum pipe_format pfmt)127{128enum a6xx_format fmt = fd6_pipe2color(pfmt);129130if (util_format_is_compressed(pfmt))131return true;132133switch (pfmt) {134case PIPE_FORMAT_Z24_UNORM_S8_UINT:135case PIPE_FORMAT_Z24X8_UNORM:136case PIPE_FORMAT_Z16_UNORM:137case PIPE_FORMAT_Z32_UNORM:138case PIPE_FORMAT_Z32_FLOAT:139case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:140case PIPE_FORMAT_S8_UINT:141return true;142default:143break;144}145146if (fmt == FMT6_NONE)147return false;148149return true;150}151152#define DEBUG_BLIT 0153#define DEBUG_BLIT_FALLBACK 0154155#define fail_if(cond) \156do { \157if (cond) { \158if (DEBUG_BLIT_FALLBACK) { \159fprintf(stderr, "falling back: %s for blit:\n", #cond); \160dump_blit_info(info); \161} \162return false; \163} \164} while (0)165166static bool167is_ubwc(struct pipe_resource *prsc, unsigned level)168{169return fd_resource_ubwc_enabled(fd_resource(prsc), level);170}171172static void173dump_blit_info(const struct pipe_blit_info *info)174{175util_dump_blit_info(stderr, info);176fprintf(stderr, "\ndst resource: ");177util_dump_resource(stderr, info->dst.resource);178if (is_ubwc(info->dst.resource, info->dst.level))179fprintf(stderr, " (ubwc)");180fprintf(stderr, "\nsrc resource: ");181util_dump_resource(stderr, info->src.resource);182if (is_ubwc(info->src.resource, info->src.level))183fprintf(stderr, " (ubwc)");184fprintf(stderr, "\n");185}186187static bool188can_do_blit(const struct pipe_blit_info *info)189{190/* I think we can do scaling, but not in z dimension since that would191* require blending..192*/193fail_if(info->dst.box.depth != info->src.box.depth);194195/* Fail if unsupported format: */196fail_if(!ok_format(info->src.format));197fail_if(!ok_format(info->dst.format));198199debug_assert(!util_format_is_compressed(info->src.format));200debug_assert(!util_format_is_compressed(info->dst.format));201202fail_if(!ok_dims(info->src.resource, &info->src.box, info->src.level));203204fail_if(!ok_dims(info->dst.resource, &info->dst.box, info->dst.level));205206debug_assert(info->dst.box.width >= 0);207debug_assert(info->dst.box.height >= 0);208debug_assert(info->dst.box.depth >= 0);209210fail_if(info->dst.resource->nr_samples > 1);211212fail_if(info->window_rectangle_include);213214const struct util_format_description *src_desc =215util_format_description(info->src.format);216const struct util_format_description *dst_desc =217util_format_description(info->dst.format);218const int common_channels =219MIN2(src_desc->nr_channels, dst_desc->nr_channels);220221if (info->mask & PIPE_MASK_RGBA) {222for (int i = 0; i < common_channels; i++) {223fail_if(memcmp(&src_desc->channel[i], &dst_desc->channel[i],224sizeof(src_desc->channel[0])));225}226}227228fail_if(info->alpha_blend);229230return true;231}232233static void234emit_setup(struct fd_batch *batch)235{236struct fd_ringbuffer *ring = batch->draw;237struct fd_screen *screen = batch->ctx->screen;238239fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);240fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);241fd6_event_write(batch, ring, PC_CCU_INVALIDATE_COLOR, false);242fd6_event_write(batch, ring, PC_CCU_INVALIDATE_DEPTH, false);243244/* normal BLIT_OP_SCALE operation needs bypass RB_CCU_CNTL */245OUT_WFI5(ring);246OUT_PKT4(ring, REG_A6XX_RB_CCU_CNTL, 1);247OUT_RING(ring, A6XX_RB_CCU_CNTL_COLOR_OFFSET(screen->ccu_offset_bypass));248}249250static void251emit_blit_setup(struct fd_ringbuffer *ring, enum pipe_format pfmt,252bool scissor_enable, union pipe_color_union *color)253{254enum a6xx_format fmt = fd6_pipe2color(pfmt);255bool is_srgb = util_format_is_srgb(pfmt);256enum a6xx_2d_ifmt ifmt = fd6_ifmt(fmt);257258if (is_srgb) {259assert(ifmt == R2D_UNORM8);260ifmt = R2D_UNORM8_SRGB;261}262263uint32_t blit_cntl = A6XX_RB_2D_BLIT_CNTL_MASK(0xf) |264A6XX_RB_2D_BLIT_CNTL_COLOR_FORMAT(fmt) |265A6XX_RB_2D_BLIT_CNTL_IFMT(ifmt) |266COND(color, A6XX_RB_2D_BLIT_CNTL_SOLID_COLOR) |267COND(scissor_enable, A6XX_RB_2D_BLIT_CNTL_SCISSOR);268269OUT_PKT4(ring, REG_A6XX_RB_2D_BLIT_CNTL, 1);270OUT_RING(ring, blit_cntl);271272OUT_PKT4(ring, REG_A6XX_GRAS_2D_BLIT_CNTL, 1);273OUT_RING(ring, blit_cntl);274275if (fmt == FMT6_10_10_10_2_UNORM_DEST)276fmt = FMT6_16_16_16_16_FLOAT;277278/* This register is probably badly named... it seems that it's279* controlling the internal/accumulator format or something like280* that. It's certainly not tied to only the src format.281*/282OUT_PKT4(ring, REG_A6XX_SP_2D_DST_FORMAT, 1);283OUT_RING(284ring,285A6XX_SP_2D_DST_FORMAT_COLOR_FORMAT(fmt) |286COND(util_format_is_pure_sint(pfmt), A6XX_SP_2D_DST_FORMAT_SINT) |287COND(util_format_is_pure_uint(pfmt), A6XX_SP_2D_DST_FORMAT_UINT) |288COND(is_srgb, A6XX_SP_2D_DST_FORMAT_SRGB) |289A6XX_SP_2D_DST_FORMAT_MASK(0xf));290291OUT_PKT4(ring, REG_A6XX_RB_2D_UNKNOWN_8C01, 1);292OUT_RING(ring, 0);293}294295/* buffers need to be handled specially since x/width can exceed the bounds296* supported by hw.. if necessary decompose into (potentially) two 2D blits297*/298static void299emit_blit_buffer(struct fd_context *ctx, struct fd_ringbuffer *ring,300const struct pipe_blit_info *info)301{302const struct pipe_box *sbox = &info->src.box;303const struct pipe_box *dbox = &info->dst.box;304struct fd_resource *src, *dst;305unsigned sshift, dshift;306307if (DEBUG_BLIT) {308fprintf(stderr, "buffer blit: ");309dump_blit_info(info);310}311312src = fd_resource(info->src.resource);313dst = fd_resource(info->dst.resource);314315debug_assert(src->layout.cpp == 1);316debug_assert(dst->layout.cpp == 1);317debug_assert(info->src.resource->format == info->dst.resource->format);318debug_assert((sbox->y == 0) && (sbox->height == 1));319debug_assert((dbox->y == 0) && (dbox->height == 1));320debug_assert((sbox->z == 0) && (sbox->depth == 1));321debug_assert((dbox->z == 0) && (dbox->depth == 1));322debug_assert(sbox->width == dbox->width);323debug_assert(info->src.level == 0);324debug_assert(info->dst.level == 0);325326/*327* Buffers can have dimensions bigger than max width, remap into328* multiple 1d blits to fit within max dimension329*330* Note that blob uses .ARRAY_PITCH=128 for blitting buffers, which331* seems to prevent overfetch related faults. Not quite sure what332* the deal is there.333*334* Low 6 bits of SRC/DST addresses need to be zero (ie. address335* aligned to 64) so we need to shift src/dst x1/x2 to make up the336* difference. On top of already splitting up the blit so width337* isn't > 16k.338*339* We perhaps could do a bit better, if src and dst are aligned but340* in the worst case this means we have to split the copy up into341* 16k (0x4000) minus 64 (0x40).342*/343344sshift = sbox->x & 0x3f;345dshift = dbox->x & 0x3f;346347emit_blit_setup(ring, PIPE_FORMAT_R8_UNORM, false, NULL);348349for (unsigned off = 0; off < sbox->width; off += (0x4000 - 0x40)) {350unsigned soff, doff, w, p;351352soff = (sbox->x + off) & ~0x3f;353doff = (dbox->x + off) & ~0x3f;354355w = MIN2(sbox->width - off, (0x4000 - 0x40));356p = align(w, 64);357358debug_assert((soff + w) <= fd_bo_size(src->bo));359debug_assert((doff + w) <= fd_bo_size(dst->bo));360361/*362* Emit source:363*/364OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);365OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(FMT6_8_UNORM) |366A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_LINEAR) |367A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(WZYX) | 0x500000);368OUT_RING(ring,369A6XX_SP_PS_2D_SRC_SIZE_WIDTH(sshift + w) |370A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(1)); /* SP_PS_2D_SRC_SIZE */371OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */372OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(p));373374OUT_RING(ring, 0x00000000);375OUT_RING(ring, 0x00000000);376OUT_RING(ring, 0x00000000);377OUT_RING(ring, 0x00000000);378OUT_RING(ring, 0x00000000);379380/*381* Emit destination:382*/383OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);384OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_8_UNORM) |385A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |386A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));387OUT_RELOC(ring, dst->bo, doff, 0, 0); /* RB_2D_DST_LO/HI */388OUT_RING(ring, A6XX_RB_2D_DST_PITCH(p));389OUT_RING(ring, 0x00000000);390OUT_RING(ring, 0x00000000);391OUT_RING(ring, 0x00000000);392OUT_RING(ring, 0x00000000);393OUT_RING(ring, 0x00000000);394395/*396* Blit command:397*/398OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);399OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(sshift));400OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(sshift + w - 1));401OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));402OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(0));403404OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);405OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dshift) | A6XX_GRAS_2D_DST_TL_Y(0));406OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dshift + w - 1) |407A6XX_GRAS_2D_DST_BR_Y(0));408409OUT_PKT7(ring, CP_EVENT_WRITE, 1);410OUT_RING(ring, 0x3f);411OUT_WFI5(ring);412413OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);414OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);415416OUT_PKT7(ring, CP_BLIT, 1);417OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));418419OUT_WFI5(ring);420421OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);422OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */423}424}425426static void427fd6_clear_ubwc(struct fd_batch *batch, struct fd_resource *rsc) assert_dt428{429struct fd_ringbuffer *ring = fd_batch_get_prologue(batch);430union pipe_color_union color = {};431432emit_blit_setup(ring, PIPE_FORMAT_R8_UNORM, false, &color);433434OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 13);435OUT_RING(ring, 0x00000000);436OUT_RING(ring, 0x00000000);437OUT_RING(ring, 0x00000000);438OUT_RING(ring, 0x00000000);439OUT_RING(ring, 0x00000000);440OUT_RING(ring, 0x00000000);441OUT_RING(ring, 0x00000000);442OUT_RING(ring, 0x00000000);443OUT_RING(ring, 0x00000000);444OUT_RING(ring, 0x00000000);445OUT_RING(ring, 0x00000000);446OUT_RING(ring, 0x00000000);447OUT_RING(ring, 0x00000000);448449OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);450OUT_RING(ring, 0x00000000);451OUT_RING(ring, 0x00000000);452OUT_RING(ring, 0x00000000);453OUT_RING(ring, 0x00000000);454455OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);456OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(0));457OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(0));458OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));459OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(0));460461unsigned size = rsc->layout.slices[0].offset;462unsigned offset = 0;463464/* We could be more clever here and realize that we could use a465* larger width if the size is aligned to something more than a466* single page.. or even use a format larger than r8 in those467* cases. But for normal sized textures and even up to 16k x 16k468* at <= 4byte/pixel, we'll only go thru the loop once469*/470const unsigned w = 0x1000;471472/* ubwc size should always be page aligned: */473assert((size % w) == 0);474475while (size > 0) {476const unsigned h = MIN2(0x4000, size / w);477/* width is already aligned to a suitable pitch: */478const unsigned p = w;479480/*481* Emit destination:482*/483OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);484OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(FMT6_8_UNORM) |485A6XX_RB_2D_DST_INFO_TILE_MODE(TILE6_LINEAR) |486A6XX_RB_2D_DST_INFO_COLOR_SWAP(WZYX));487OUT_RELOC(ring, rsc->bo, offset, 0, 0); /* RB_2D_DST_LO/HI */488OUT_RING(ring, A6XX_RB_2D_DST_PITCH(p));489OUT_RING(ring, 0x00000000);490OUT_RING(ring, 0x00000000);491OUT_RING(ring, 0x00000000);492OUT_RING(ring, 0x00000000);493OUT_RING(ring, 0x00000000);494495/*496* Blit command:497*/498499OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);500OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));501OUT_RING(ring,502A6XX_GRAS_2D_DST_BR_X(w - 1) | A6XX_GRAS_2D_DST_BR_Y(h - 1));503504OUT_PKT7(ring, CP_EVENT_WRITE, 1);505OUT_RING(ring, 0x3f);506OUT_WFI5(ring);507508OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);509OUT_RING(ring, batch->ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);510511OUT_PKT7(ring, CP_BLIT, 1);512OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));513514OUT_WFI5(ring);515516OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);517OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */518519offset += w * h;520size -= w * h;521}522523fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);524fd6_event_write(batch, ring, PC_CCU_FLUSH_DEPTH_TS, true);525fd6_event_write(batch, ring, CACHE_FLUSH_TS, true);526fd6_cache_inv(batch, ring);527}528529static void530emit_blit_dst(struct fd_ringbuffer *ring, struct pipe_resource *prsc,531enum pipe_format pfmt, unsigned level, unsigned layer)532{533struct fd_resource *dst = fd_resource(prsc);534enum a6xx_format fmt = fd6_pipe2color(pfmt);535enum a6xx_tile_mode tile = fd_resource_tile_mode(prsc, level);536enum a3xx_color_swap swap = fd6_resource_swap(dst, pfmt);537uint32_t pitch = fd_resource_pitch(dst, level);538bool ubwc_enabled = fd_resource_ubwc_enabled(dst, level);539unsigned off = fd_resource_offset(dst, level, layer);540541if (fmt == FMT6_Z24_UNORM_S8_UINT)542fmt = FMT6_Z24_UNORM_S8_UINT_AS_R8G8B8A8;543544OUT_PKT4(ring, REG_A6XX_RB_2D_DST_INFO, 9);545OUT_RING(ring, A6XX_RB_2D_DST_INFO_COLOR_FORMAT(fmt) |546A6XX_RB_2D_DST_INFO_TILE_MODE(tile) |547A6XX_RB_2D_DST_INFO_COLOR_SWAP(swap) |548COND(util_format_is_srgb(pfmt), A6XX_RB_2D_DST_INFO_SRGB) |549COND(ubwc_enabled, A6XX_RB_2D_DST_INFO_FLAGS));550OUT_RELOC(ring, dst->bo, off, 0, 0); /* RB_2D_DST_LO/HI */551OUT_RING(ring, A6XX_RB_2D_DST_PITCH(pitch));552OUT_RING(ring, 0x00000000);553OUT_RING(ring, 0x00000000);554OUT_RING(ring, 0x00000000);555OUT_RING(ring, 0x00000000);556OUT_RING(ring, 0x00000000);557558if (ubwc_enabled) {559OUT_PKT4(ring, REG_A6XX_RB_2D_DST_FLAGS, 6);560fd6_emit_flag_reference(ring, dst, level, layer);561OUT_RING(ring, 0x00000000);562OUT_RING(ring, 0x00000000);563OUT_RING(ring, 0x00000000);564}565}566567static void568emit_blit_src(struct fd_ringbuffer *ring, const struct pipe_blit_info *info,569unsigned layer, unsigned nr_samples)570{571struct fd_resource *src = fd_resource(info->src.resource);572enum a6xx_format sfmt = fd6_pipe2color(info->src.format);573enum a6xx_tile_mode stile =574fd_resource_tile_mode(info->src.resource, info->src.level);575enum a3xx_color_swap sswap = fd6_resource_swap(src, info->src.format);576uint32_t pitch = fd_resource_pitch(src, info->src.level);577bool subwc_enabled = fd_resource_ubwc_enabled(src, info->src.level);578unsigned soff = fd_resource_offset(src, info->src.level, layer);579uint32_t width = u_minify(src->b.b.width0, info->src.level) * nr_samples;580uint32_t height = u_minify(src->b.b.height0, info->src.level);581uint32_t filter = 0;582583if (info->filter == PIPE_TEX_FILTER_LINEAR)584filter = A6XX_SP_PS_2D_SRC_INFO_FILTER;585586enum a3xx_msaa_samples samples = fd_msaa_samples(src->b.b.nr_samples);587588if (sfmt == FMT6_10_10_10_2_UNORM_DEST)589sfmt = FMT6_10_10_10_2_UNORM;590591OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);592OUT_RING(ring, A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt) |593A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(stile) |594A6XX_SP_PS_2D_SRC_INFO_COLOR_SWAP(sswap) |595A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples) |596COND(samples > MSAA_ONE && (info->mask & PIPE_MASK_RGBA),597A6XX_SP_PS_2D_SRC_INFO_SAMPLES_AVERAGE) |598COND(subwc_enabled, A6XX_SP_PS_2D_SRC_INFO_FLAGS) |599COND(util_format_is_srgb(info->src.format),600A6XX_SP_PS_2D_SRC_INFO_SRGB) |6010x500000 | filter);602OUT_RING(ring,603A6XX_SP_PS_2D_SRC_SIZE_WIDTH(width) |604A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(height)); /* SP_PS_2D_SRC_SIZE */605OUT_RELOC(ring, src->bo, soff, 0, 0); /* SP_PS_2D_SRC_LO/HI */606OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(pitch));607608OUT_RING(ring, 0x00000000);609OUT_RING(ring, 0x00000000);610OUT_RING(ring, 0x00000000);611OUT_RING(ring, 0x00000000);612OUT_RING(ring, 0x00000000);613614if (subwc_enabled) {615OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_FLAGS, 6);616fd6_emit_flag_reference(ring, src, info->src.level, layer);617OUT_RING(ring, 0x00000000);618OUT_RING(ring, 0x00000000);619OUT_RING(ring, 0x00000000);620}621}622623static void624emit_blit_texture(struct fd_context *ctx, struct fd_ringbuffer *ring,625const struct pipe_blit_info *info)626{627const struct pipe_box *sbox = &info->src.box;628const struct pipe_box *dbox = &info->dst.box;629struct fd_resource *dst;630int sx1, sy1, sx2, sy2;631int dx1, dy1, dx2, dy2;632633if (DEBUG_BLIT) {634fprintf(stderr, "texture blit: ");635dump_blit_info(info);636}637638dst = fd_resource(info->dst.resource);639640uint32_t nr_samples = fd_resource_nr_samples(&dst->b.b);641642sx1 = sbox->x * nr_samples;643sy1 = sbox->y;644sx2 = (sbox->x + sbox->width) * nr_samples - 1;645sy2 = sbox->y + sbox->height - 1;646647OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);648OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(sx1));649OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(sx2));650OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(sy1));651OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(sy2));652653dx1 = dbox->x * nr_samples;654dy1 = dbox->y;655dx2 = (dbox->x + dbox->width) * nr_samples - 1;656dy2 = dbox->y + dbox->height - 1;657658OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);659OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(dx1) | A6XX_GRAS_2D_DST_TL_Y(dy1));660OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(dx2) | A6XX_GRAS_2D_DST_BR_Y(dy2));661662if (info->scissor_enable) {663OUT_PKT4(ring, REG_A6XX_GRAS_2D_RESOLVE_CNTL_1, 2);664OUT_RING(ring, A6XX_GRAS_2D_RESOLVE_CNTL_1_X(info->scissor.minx) |665A6XX_GRAS_2D_RESOLVE_CNTL_1_Y(info->scissor.miny));666OUT_RING(ring, A6XX_GRAS_2D_RESOLVE_CNTL_1_X(info->scissor.maxx - 1) |667A6XX_GRAS_2D_RESOLVE_CNTL_1_Y(info->scissor.maxy - 1));668}669670emit_blit_setup(ring, info->dst.format, info->scissor_enable, NULL);671672for (unsigned i = 0; i < info->dst.box.depth; i++) {673674emit_blit_src(ring, info, sbox->z + i, nr_samples);675emit_blit_dst(ring, info->dst.resource, info->dst.format, info->dst.level,676dbox->z + i);677678/*679* Blit command:680*/681OUT_PKT7(ring, CP_EVENT_WRITE, 1);682OUT_RING(ring, 0x3f);683OUT_WFI5(ring);684685OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);686OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);687688OUT_PKT7(ring, CP_BLIT, 1);689OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));690691OUT_WFI5(ring);692693OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);694OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */695}696}697698static void699emit_clear_color(struct fd_ringbuffer *ring, enum pipe_format pfmt,700union pipe_color_union *color)701{702switch (pfmt) {703case PIPE_FORMAT_Z24X8_UNORM:704case PIPE_FORMAT_Z24_UNORM_S8_UINT:705case PIPE_FORMAT_X24S8_UINT: {706uint32_t depth_unorm24 = color->f[0] * ((1u << 24) - 1);707uint8_t stencil = color->ui[1];708color->ui[0] = depth_unorm24 & 0xff;709color->ui[1] = (depth_unorm24 >> 8) & 0xff;710color->ui[2] = (depth_unorm24 >> 16) & 0xff;711color->ui[3] = stencil;712break;713}714default:715break;716}717718OUT_PKT4(ring, REG_A6XX_RB_2D_SRC_SOLID_C0, 4);719switch (fd6_ifmt(fd6_pipe2color(pfmt))) {720case R2D_UNORM8:721case R2D_UNORM8_SRGB:722/* The r2d ifmt is badly named, it also covers the signed case: */723if (util_format_is_snorm(pfmt)) {724OUT_RING(ring, float_to_byte_tex(color->f[0]));725OUT_RING(ring, float_to_byte_tex(color->f[1]));726OUT_RING(ring, float_to_byte_tex(color->f[2]));727OUT_RING(ring, float_to_byte_tex(color->f[3]));728} else {729OUT_RING(ring, float_to_ubyte(color->f[0]));730OUT_RING(ring, float_to_ubyte(color->f[1]));731OUT_RING(ring, float_to_ubyte(color->f[2]));732OUT_RING(ring, float_to_ubyte(color->f[3]));733}734break;735case R2D_FLOAT16:736OUT_RING(ring, _mesa_float_to_half(color->f[0]));737OUT_RING(ring, _mesa_float_to_half(color->f[1]));738OUT_RING(ring, _mesa_float_to_half(color->f[2]));739OUT_RING(ring, _mesa_float_to_half(color->f[3]));740break;741case R2D_FLOAT32:742case R2D_INT32:743case R2D_INT16:744case R2D_INT8:745default:746OUT_RING(ring, color->ui[0]);747OUT_RING(ring, color->ui[1]);748OUT_RING(ring, color->ui[2]);749OUT_RING(ring, color->ui[3]);750break;751}752}753754/**755* Handle conversion of clear color756*/757static union pipe_color_union758convert_color(enum pipe_format format, union pipe_color_union *pcolor)759{760union pipe_color_union color = *pcolor;761762/* For solid-fill blits, the hw isn't going to convert from763* linear to srgb for us:764*/765if (util_format_is_srgb(format)) {766for (int i = 0; i < 3; i++)767color.f[i] = util_format_linear_to_srgb_float(color.f[i]);768}769770if (util_format_is_snorm(format)) {771for (int i = 0; i < 3; i++)772color.f[i] = CLAMP(color.f[i], -1.0f, 1.0f);773}774775/* Note that float_to_ubyte() already clamps, for the unorm case */776777return color;778}779780void781fd6_clear_surface(struct fd_context *ctx, struct fd_ringbuffer *ring,782struct pipe_surface *psurf, uint32_t width, uint32_t height,783union pipe_color_union *color)784{785if (DEBUG_BLIT) {786fprintf(stderr, "surface clear:\ndst resource: ");787util_dump_resource(stderr, psurf->texture);788fprintf(stderr, "\n");789}790791uint32_t nr_samples = fd_resource_nr_samples(psurf->texture);792OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);793OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));794OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(width * nr_samples - 1) |795A6XX_GRAS_2D_DST_BR_Y(height - 1));796797union pipe_color_union clear_color = convert_color(psurf->format, color);798799emit_clear_color(ring, psurf->format, &clear_color);800emit_blit_setup(ring, psurf->format, false, &clear_color);801802for (unsigned i = psurf->u.tex.first_layer; i <= psurf->u.tex.last_layer;803i++) {804emit_blit_dst(ring, psurf->texture, psurf->format, psurf->u.tex.level, i);805806/*807* Blit command:808*/809OUT_PKT7(ring, CP_EVENT_WRITE, 1);810OUT_RING(ring, 0x3f);811OUT_WFI5(ring);812813OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);814OUT_RING(ring, ctx->screen->info->a6xx.magic.RB_UNKNOWN_8E04_blit);815816OUT_PKT7(ring, CP_BLIT, 1);817OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));818819OUT_WFI5(ring);820821OUT_PKT4(ring, REG_A6XX_RB_UNKNOWN_8E04, 1);822OUT_RING(ring, 0); /* RB_UNKNOWN_8E04 */823}824}825826void827fd6_resolve_tile(struct fd_batch *batch, struct fd_ringbuffer *ring,828uint32_t base, struct pipe_surface *psurf)829{830const struct fd_gmem_stateobj *gmem = batch->gmem_state;831uint64_t gmem_base = batch->ctx->screen->gmem_base + base;832uint32_t gmem_pitch = gmem->bin_w * batch->framebuffer.samples *833util_format_get_blocksize(psurf->format);834835OUT_PKT4(ring, REG_A6XX_GRAS_2D_DST_TL, 2);836OUT_RING(ring, A6XX_GRAS_2D_DST_TL_X(0) | A6XX_GRAS_2D_DST_TL_Y(0));837OUT_RING(ring, A6XX_GRAS_2D_DST_BR_X(psurf->width - 1) |838A6XX_GRAS_2D_DST_BR_Y(psurf->height - 1));839840OUT_PKT4(ring, REG_A6XX_GRAS_2D_SRC_TL_X, 4);841OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_X(0));842OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_X(psurf->width - 1));843OUT_RING(ring, A6XX_GRAS_2D_SRC_TL_Y(0));844OUT_RING(ring, A6XX_GRAS_2D_SRC_BR_Y(psurf->height - 1));845846/* Enable scissor bit, which will take into account the window scissor847* which is set per-tile848*/849emit_blit_setup(ring, psurf->format, true, NULL);850851/* We shouldn't be using GMEM in the layered rendering case: */852assert(psurf->u.tex.first_layer == psurf->u.tex.last_layer);853854emit_blit_dst(ring, psurf->texture, psurf->format, psurf->u.tex.level,855psurf->u.tex.first_layer);856857enum a6xx_format sfmt = fd6_pipe2color(psurf->format);858enum a3xx_msaa_samples samples = fd_msaa_samples(batch->framebuffer.samples);859860OUT_PKT4(ring, REG_A6XX_SP_PS_2D_SRC_INFO, 10);861OUT_RING(ring,862A6XX_SP_PS_2D_SRC_INFO_COLOR_FORMAT(sfmt) |863A6XX_SP_PS_2D_SRC_INFO_TILE_MODE(TILE6_2) |864A6XX_SP_PS_2D_SRC_INFO_SAMPLES(samples) |865COND(samples > MSAA_ONE, A6XX_SP_PS_2D_SRC_INFO_SAMPLES_AVERAGE) |866COND(util_format_is_srgb(psurf->format), A6XX_SP_PS_2D_SRC_INFO_SRGB) |867A6XX_SP_PS_2D_SRC_INFO_UNK20 | A6XX_SP_PS_2D_SRC_INFO_UNK22);868OUT_RING(ring, A6XX_SP_PS_2D_SRC_SIZE_WIDTH(psurf->width) |869A6XX_SP_PS_2D_SRC_SIZE_HEIGHT(psurf->height));870OUT_RING(ring, gmem_base); /* SP_PS_2D_SRC_LO */871OUT_RING(ring, gmem_base >> 32); /* SP_PS_2D_SRC_HI */872OUT_RING(ring, A6XX_SP_PS_2D_SRC_PITCH_PITCH(gmem_pitch));873OUT_RING(ring, 0x00000000);874OUT_RING(ring, 0x00000000);875OUT_RING(ring, 0x00000000);876OUT_RING(ring, 0x00000000);877OUT_RING(ring, 0x00000000);878879/* sync GMEM writes with CACHE. */880fd6_cache_inv(batch, ring);881882/* Wait for CACHE_INVALIDATE to land */883fd_wfi(batch, ring);884885OUT_PKT7(ring, CP_BLIT, 1);886OUT_RING(ring, CP_BLIT_0_OP(BLIT_OP_SCALE));887888OUT_WFI5(ring);889890/* CP_BLIT writes to the CCU, unlike CP_EVENT_WRITE::BLIT which writes to891* sysmem, and we generally assume that GMEM renderpasses leave their892* results in sysmem, so we need to flush manually here.893*/894fd6_event_write(batch, ring, PC_CCU_FLUSH_COLOR_TS, true);895}896897static bool898handle_rgba_blit(struct fd_context *ctx,899const struct pipe_blit_info *info) assert_dt900{901struct fd_batch *batch;902903debug_assert(!(info->mask & PIPE_MASK_ZS));904905if (!can_do_blit(info))906return false;907908struct fd_resource *src = fd_resource(info->src.resource);909struct fd_resource *dst = fd_resource(info->dst.resource);910911fd6_validate_format(ctx, src, info->src.format);912fd6_validate_format(ctx, dst, info->dst.format);913914batch = fd_bc_alloc_batch(ctx, true);915916fd_screen_lock(ctx->screen);917918fd_batch_resource_read(batch, src);919fd_batch_resource_write(batch, dst);920921fd_screen_unlock(ctx->screen);922923ASSERTED bool ret = fd_batch_lock_submit(batch);924assert(ret);925926/* Marking the batch as needing flush must come after the batch927* dependency tracking (resource_read()/resource_write()), as that928* can trigger a flush929*/930fd_batch_needs_flush(batch);931932fd_batch_update_queries(batch);933934emit_setup(batch);935936DBG_BLIT(info, batch);937938trace_start_blit(&batch->trace, info->src.resource->target,939info->dst.resource->target);940941if ((info->src.resource->target == PIPE_BUFFER) &&942(info->dst.resource->target == PIPE_BUFFER)) {943assert(src->layout.tile_mode == TILE6_LINEAR);944assert(dst->layout.tile_mode == TILE6_LINEAR);945emit_blit_buffer(ctx, batch->draw, info);946} else {947/* I don't *think* we need to handle blits between buffer <-> !buffer */948debug_assert(info->src.resource->target != PIPE_BUFFER);949debug_assert(info->dst.resource->target != PIPE_BUFFER);950emit_blit_texture(ctx, batch->draw, info);951}952953trace_end_blit(&batch->trace);954955fd6_event_write(batch, batch->draw, PC_CCU_FLUSH_COLOR_TS, true);956fd6_event_write(batch, batch->draw, PC_CCU_FLUSH_DEPTH_TS, true);957fd6_event_write(batch, batch->draw, CACHE_FLUSH_TS, true);958fd6_cache_inv(batch, batch->draw);959960fd_batch_unlock_submit(batch);961962fd_batch_flush(batch);963fd_batch_reference(&batch, NULL);964965/* Acc query state will have been dirtied by our fd_batch_update_queries, so966* the ctx->batch may need to turn its queries back on.967*/968ctx->update_active_queries = true;969970return true;971}972973/**974* Re-written z/s blits can still fail for various reasons (for example MSAA).975* But we want to do the fallback blit with the re-written pipe_blit_info,976* in particular as u_blitter cannot blit stencil. So handle the fallback977* ourself and never "fail".978*/979static bool980do_rewritten_blit(struct fd_context *ctx,981const struct pipe_blit_info *info) assert_dt982{983bool success = handle_rgba_blit(ctx, info);984if (!success)985success = fd_blitter_blit(ctx, info);986debug_assert(success); /* fallback should never fail! */987return success;988}989990/**991* Handle depth/stencil blits either via u_blitter and/or re-writing the992* blit into an equivilant format that we can handle993*/994static bool995handle_zs_blit(struct fd_context *ctx,996const struct pipe_blit_info *info) assert_dt997{998struct pipe_blit_info blit = *info;9991000if (DEBUG_BLIT) {1001fprintf(stderr, "---- handle_zs_blit: ");1002dump_blit_info(info);1003}10041005if (info->src.format != info->dst.format)1006return false;10071008struct fd_resource *src = fd_resource(info->src.resource);1009struct fd_resource *dst = fd_resource(info->dst.resource);10101011switch (info->dst.format) {1012case PIPE_FORMAT_S8_UINT:1013debug_assert(info->mask == PIPE_MASK_S);1014blit.mask = PIPE_MASK_R;1015blit.src.format = PIPE_FORMAT_R8_UINT;1016blit.dst.format = PIPE_FORMAT_R8_UINT;1017return do_rewritten_blit(ctx, &blit);10181019case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:1020if (info->mask & PIPE_MASK_Z) {1021blit.mask = PIPE_MASK_R;1022blit.src.format = PIPE_FORMAT_R32_FLOAT;1023blit.dst.format = PIPE_FORMAT_R32_FLOAT;1024do_rewritten_blit(ctx, &blit);1025}10261027if (info->mask & PIPE_MASK_S) {1028blit.mask = PIPE_MASK_R;1029blit.src.format = PIPE_FORMAT_R8_UINT;1030blit.dst.format = PIPE_FORMAT_R8_UINT;1031blit.src.resource = &src->stencil->b.b;1032blit.dst.resource = &dst->stencil->b.b;1033do_rewritten_blit(ctx, &blit);1034}10351036return true;10371038case PIPE_FORMAT_Z16_UNORM:1039blit.mask = PIPE_MASK_R;1040blit.src.format = PIPE_FORMAT_R16_UNORM;1041blit.dst.format = PIPE_FORMAT_R16_UNORM;1042return do_rewritten_blit(ctx, &blit);10431044case PIPE_FORMAT_Z32_UNORM:1045case PIPE_FORMAT_Z32_FLOAT:1046debug_assert(info->mask == PIPE_MASK_Z);1047blit.mask = PIPE_MASK_R;1048blit.src.format = PIPE_FORMAT_R32_UINT;1049blit.dst.format = PIPE_FORMAT_R32_UINT;1050return do_rewritten_blit(ctx, &blit);10511052case PIPE_FORMAT_Z24X8_UNORM:1053case PIPE_FORMAT_Z24_UNORM_S8_UINT:1054blit.mask = 0;1055if (info->mask & PIPE_MASK_Z)1056blit.mask |= PIPE_MASK_R | PIPE_MASK_G | PIPE_MASK_B;1057if (info->mask & PIPE_MASK_S)1058blit.mask |= PIPE_MASK_A;1059blit.src.format = PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8;1060blit.dst.format = PIPE_FORMAT_Z24_UNORM_S8_UINT_AS_R8G8B8A8;1061/* non-UBWC Z24_UNORM_S8_UINT_AS_R8G8B8A8 is broken on a630, fall back to1062* 8888_unorm.1063*/1064if (!ctx->screen->info->a6xx.has_z24uint_s8uint) {1065if (!src->layout.ubwc)1066blit.src.format = PIPE_FORMAT_RGBA8888_UNORM;1067if (!dst->layout.ubwc)1068blit.dst.format = PIPE_FORMAT_RGBA8888_UNORM;1069}1070return fd_blitter_blit(ctx, &blit);10711072default:1073return false;1074}1075}10761077static bool1078handle_compressed_blit(struct fd_context *ctx,1079const struct pipe_blit_info *info) assert_dt1080{1081struct pipe_blit_info blit = *info;10821083if (DEBUG_BLIT) {1084fprintf(stderr, "---- handle_compressed_blit: ");1085dump_blit_info(info);1086}10871088if (info->src.format != info->dst.format)1089return fd_blitter_blit(ctx, info);10901091if (util_format_get_blocksize(info->src.format) == 8) {1092blit.src.format = blit.dst.format = PIPE_FORMAT_R16G16B16A16_UINT;1093} else {1094debug_assert(util_format_get_blocksize(info->src.format) == 16);1095blit.src.format = blit.dst.format = PIPE_FORMAT_R32G32B32A32_UINT;1096}10971098int bw = util_format_get_blockwidth(info->src.format);1099int bh = util_format_get_blockheight(info->src.format);11001101/* NOTE: x/y *must* be aligned to block boundary (ie. in1102* glCompressedTexSubImage2D()) but width/height may not1103* be:1104*/11051106debug_assert((blit.src.box.x % bw) == 0);1107debug_assert((blit.src.box.y % bh) == 0);11081109blit.src.box.x /= bw;1110blit.src.box.y /= bh;1111blit.src.box.width = DIV_ROUND_UP(blit.src.box.width, bw);1112blit.src.box.height = DIV_ROUND_UP(blit.src.box.height, bh);11131114debug_assert((blit.dst.box.x % bw) == 0);1115debug_assert((blit.dst.box.y % bh) == 0);11161117blit.dst.box.x /= bw;1118blit.dst.box.y /= bh;1119blit.dst.box.width = DIV_ROUND_UP(blit.dst.box.width, bw);1120blit.dst.box.height = DIV_ROUND_UP(blit.dst.box.height, bh);11211122return do_rewritten_blit(ctx, &blit);1123}11241125static enum pipe_format1126snorm_copy_format(enum pipe_format format)1127{1128switch (format) {1129case PIPE_FORMAT_R8_SNORM: return PIPE_FORMAT_R8_UNORM;1130case PIPE_FORMAT_R16_SNORM: return PIPE_FORMAT_R16_UNORM;1131case PIPE_FORMAT_A16_SNORM: return PIPE_FORMAT_A16_UNORM;1132case PIPE_FORMAT_L16_SNORM: return PIPE_FORMAT_L16_UNORM;1133case PIPE_FORMAT_I16_SNORM: return PIPE_FORMAT_I16_UNORM;1134case PIPE_FORMAT_R8G8_SNORM: return PIPE_FORMAT_R8G8_UNORM;1135case PIPE_FORMAT_R8G8B8_SNORM: return PIPE_FORMAT_R8G8B8_UNORM;1136case PIPE_FORMAT_R32_SNORM: return PIPE_FORMAT_R32_UNORM;1137case PIPE_FORMAT_R16G16_SNORM: return PIPE_FORMAT_R16G16_UNORM;1138case PIPE_FORMAT_L16A16_SNORM: return PIPE_FORMAT_L16A16_UNORM;1139case PIPE_FORMAT_R8G8B8A8_SNORM: return PIPE_FORMAT_R8G8B8A8_UNORM;1140case PIPE_FORMAT_R10G10B10A2_SNORM: return PIPE_FORMAT_R10G10B10A2_UNORM;1141case PIPE_FORMAT_B10G10R10A2_SNORM: return PIPE_FORMAT_B10G10R10A2_UNORM;1142case PIPE_FORMAT_R16G16B16_SNORM: return PIPE_FORMAT_R16G16B16_UNORM;1143case PIPE_FORMAT_R16G16B16A16_SNORM: return PIPE_FORMAT_R16G16B16A16_UNORM;1144case PIPE_FORMAT_R16G16B16X16_SNORM: return PIPE_FORMAT_R16G16B16X16_UNORM;1145case PIPE_FORMAT_R32G32_SNORM: return PIPE_FORMAT_R32G32_UNORM;1146case PIPE_FORMAT_R32G32B32_SNORM: return PIPE_FORMAT_R32G32B32_UNORM;1147case PIPE_FORMAT_R32G32B32A32_SNORM: return PIPE_FORMAT_R32G32B32A32_UNORM;1148default:1149unreachable("unhandled snorm format");1150return format;1151}1152}11531154/**1155* For SNORM formats, copy them as the equivalent UNORM format. If we treat1156* them as snorm then the 0x80 (-1.0 snorm8) value will get clamped to 0x811157* (also -1.0), when we're supposed to be memcpying the bits. See1158* https://gitlab.khronos.org/Tracker/vk-gl-cts/-/issues/2917 for discussion.1159*/1160static bool1161handle_snorm_copy_blit(struct fd_context *ctx,1162const struct pipe_blit_info *info)1163assert_dt1164{1165struct pipe_blit_info blit = *info;11661167blit.src.format = blit.dst.format = snorm_copy_format(info->src.format);11681169return do_rewritten_blit(ctx, &blit);1170}11711172static bool1173fd6_blit(struct fd_context *ctx, const struct pipe_blit_info *info) assert_dt1174{1175if (info->mask & PIPE_MASK_ZS)1176return handle_zs_blit(ctx, info);11771178if (util_format_is_compressed(info->src.format) ||1179util_format_is_compressed(info->dst.format))1180return handle_compressed_blit(ctx, info);11811182if ((info->src.format == info->dst.format) &&1183util_format_is_snorm(info->src.format))1184return handle_snorm_copy_blit(ctx, info);11851186return handle_rgba_blit(ctx, info);1187}11881189void1190fd6_blitter_init(struct pipe_context *pctx) disable_thread_safety_analysis1191{1192struct fd_context *ctx = fd_context(pctx);11931194ctx->clear_ubwc = fd6_clear_ubwc;1195ctx->validate_format = fd6_validate_format;11961197if (FD_DBG(NOBLIT))1198return;11991200ctx->blit = fd6_blit;1201}12021203unsigned1204fd6_tile_mode(const struct pipe_resource *tmpl)1205{1206/* if the mipmap level 0 is still too small to be tiled, then don't1207* bother pretending:1208*/1209if (fd_resource_level_linear(tmpl, 0))1210return TILE6_LINEAR;12111212/* basically just has to be a format we can blit, so uploads/downloads1213* via linear staging buffer works:1214*/1215if (ok_format(tmpl->format))1216return TILE6_3;12171218return TILE6_LINEAR;1219}122012211222