Path: blob/21.2-virgl/src/gallium/drivers/v3d/v3dx_rcl.c
4570 views
/*1* Copyright © 2017 Broadcom2*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 (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "util/format/u_format.h"24#include "v3d_context.h"25#include "broadcom/common/v3d_tiling.h"26#include "broadcom/common/v3d_macros.h"27#include "broadcom/cle/v3dx_pack.h"2829#define PIPE_CLEAR_COLOR_BUFFERS (PIPE_CLEAR_COLOR0 | \30PIPE_CLEAR_COLOR1 | \31PIPE_CLEAR_COLOR2 | \32PIPE_CLEAR_COLOR3) \3334#define PIPE_FIRST_COLOR_BUFFER_BIT (ffs(PIPE_CLEAR_COLOR0) - 1)3536/* The HW queues up the load until the tile coordinates show up, but can only37* track one at a time. If we need to do more than one load, then we need to38* flush out the previous load by emitting the tile coordinates and doing a39* dummy store.40*/41static void42flush_last_load(struct v3d_cl *cl)43{44if (V3D_VERSION >= 40)45return;4647cl_emit(cl, TILE_COORDINATES_IMPLICIT, coords);48cl_emit(cl, STORE_TILE_BUFFER_GENERAL, store) {49store.buffer_to_store = NONE;50}51}5253static void54load_general(struct v3d_cl *cl, struct pipe_surface *psurf, int buffer,55int layer, uint32_t pipe_bit, uint32_t *loads_pending)56{57struct v3d_surface *surf = v3d_surface(psurf);58bool separate_stencil = surf->separate_stencil && buffer == STENCIL;59if (separate_stencil) {60psurf = surf->separate_stencil;61surf = v3d_surface(psurf);62}6364struct v3d_resource *rsc = v3d_resource(psurf->texture);6566uint32_t layer_offset =67v3d_layer_offset(&rsc->base, psurf->u.tex.level,68psurf->u.tex.first_layer + layer);69cl_emit(cl, LOAD_TILE_BUFFER_GENERAL, load) {70load.buffer_to_load = buffer;71load.address = cl_address(rsc->bo, layer_offset);7273#if V3D_VERSION >= 4074load.memory_format = surf->tiling;75if (separate_stencil)76load.input_image_format = V3D_OUTPUT_IMAGE_FORMAT_S8;77else78load.input_image_format = surf->format;79load.r_b_swap = surf->swap_rb;80load.force_alpha_1 = util_format_has_alpha1(psurf->format);81if (surf->tiling == V3D_TILING_UIF_NO_XOR ||82surf->tiling == V3D_TILING_UIF_XOR) {83load.height_in_ub_or_stride =84surf->padded_height_of_output_image_in_uif_blocks;85} else if (surf->tiling == V3D_TILING_RASTER) {86struct v3d_resource_slice *slice =87&rsc->slices[psurf->u.tex.level];88load.height_in_ub_or_stride = slice->stride;89}9091if (psurf->texture->nr_samples > 1)92load.decimate_mode = V3D_DECIMATE_MODE_ALL_SAMPLES;93else94load.decimate_mode = V3D_DECIMATE_MODE_SAMPLE_0;9596#else /* V3D_VERSION < 40 */97/* Can't do raw ZSTENCIL loads -- need to load/store them to98* separate buffers for Z and stencil.99*/100assert(buffer != ZSTENCIL);101load.raw_mode = true;102load.padded_height_of_output_image_in_uif_blocks =103surf->padded_height_of_output_image_in_uif_blocks;104#endif /* V3D_VERSION < 40 */105}106107*loads_pending &= ~pipe_bit;108if (*loads_pending)109flush_last_load(cl);110}111112static void113store_general(struct v3d_job *job,114struct v3d_cl *cl, struct pipe_surface *psurf,115int layer, int buffer, int pipe_bit,116uint32_t *stores_pending, bool general_color_clear,117bool resolve_4x)118{119struct v3d_surface *surf = v3d_surface(psurf);120bool separate_stencil = surf->separate_stencil && buffer == STENCIL;121if (separate_stencil) {122psurf = surf->separate_stencil;123surf = v3d_surface(psurf);124}125126*stores_pending &= ~pipe_bit;127bool last_store = !(*stores_pending);128129struct v3d_resource *rsc = v3d_resource(psurf->texture);130131rsc->writes++;132133uint32_t layer_offset =134v3d_layer_offset(&rsc->base, psurf->u.tex.level,135psurf->u.tex.first_layer + layer);136cl_emit(cl, STORE_TILE_BUFFER_GENERAL, store) {137store.buffer_to_store = buffer;138store.address = cl_address(rsc->bo, layer_offset);139140#if V3D_VERSION >= 40141store.clear_buffer_being_stored = false;142143if (separate_stencil)144store.output_image_format = V3D_OUTPUT_IMAGE_FORMAT_S8;145else146store.output_image_format = surf->format;147148store.r_b_swap = surf->swap_rb;149store.memory_format = surf->tiling;150151if (surf->tiling == V3D_TILING_UIF_NO_XOR ||152surf->tiling == V3D_TILING_UIF_XOR) {153store.height_in_ub_or_stride =154surf->padded_height_of_output_image_in_uif_blocks;155} else if (surf->tiling == V3D_TILING_RASTER) {156struct v3d_resource_slice *slice =157&rsc->slices[psurf->u.tex.level];158store.height_in_ub_or_stride = slice->stride;159}160161assert(!resolve_4x || job->bbuf);162if (psurf->texture->nr_samples > 1)163store.decimate_mode = V3D_DECIMATE_MODE_ALL_SAMPLES;164else if (resolve_4x && job->bbuf->texture->nr_samples > 1)165store.decimate_mode = V3D_DECIMATE_MODE_4X;166else167store.decimate_mode = V3D_DECIMATE_MODE_SAMPLE_0;168169#else /* V3D_VERSION < 40 */170/* Can't do raw ZSTENCIL stores -- need to load/store them to171* separate buffers for Z and stencil.172*/173assert(buffer != ZSTENCIL);174store.raw_mode = true;175if (!last_store) {176store.disable_color_buffers_clear_on_write = true;177store.disable_z_buffer_clear_on_write = true;178store.disable_stencil_buffer_clear_on_write = true;179} else {180store.disable_color_buffers_clear_on_write =181!(((pipe_bit & PIPE_CLEAR_COLOR_BUFFERS) &&182general_color_clear &&183(job->clear & pipe_bit)));184store.disable_z_buffer_clear_on_write =185!(job->clear & PIPE_CLEAR_DEPTH);186store.disable_stencil_buffer_clear_on_write =187!(job->clear & PIPE_CLEAR_STENCIL);188}189store.padded_height_of_output_image_in_uif_blocks =190surf->padded_height_of_output_image_in_uif_blocks;191#endif /* V3D_VERSION < 40 */192}193194/* There must be a TILE_COORDINATES_IMPLICIT between each store. */195if (V3D_VERSION < 40 && !last_store) {196cl_emit(cl, TILE_COORDINATES_IMPLICIT, coords);197}198}199200static int201zs_buffer_from_pipe_bits(int pipe_clear_bits)202{203switch (pipe_clear_bits & PIPE_CLEAR_DEPTHSTENCIL) {204case PIPE_CLEAR_DEPTHSTENCIL:205return ZSTENCIL;206case PIPE_CLEAR_DEPTH:207return Z;208case PIPE_CLEAR_STENCIL:209return STENCIL;210default:211return NONE;212}213}214215static void216v3d_rcl_emit_loads(struct v3d_job *job, struct v3d_cl *cl, int layer)217{218/* When blitting, no color or zs buffer is loaded; instead the blit219* source buffer is loaded for the aspects that we are going to blit.220*/221assert(!job->bbuf || job->load == 0);222assert(!job->bbuf || job->nr_cbufs <= 1);223assert(!job->bbuf || V3D_VERSION >= 40);224225uint32_t loads_pending = job->bbuf ? job->store : job->load;226227for (int i = 0; i < job->nr_cbufs; i++) {228uint32_t bit = PIPE_CLEAR_COLOR0 << i;229if (!(loads_pending & bit))230continue;231232struct pipe_surface *psurf = job->bbuf ? job->bbuf : job->cbufs[i];233assert(!job->bbuf || i == 0);234235if (!psurf || (V3D_VERSION < 40 &&236psurf->texture->nr_samples <= 1)) {237continue;238}239240load_general(cl, psurf, RENDER_TARGET_0 + i, layer,241bit, &loads_pending);242}243244if ((loads_pending & PIPE_CLEAR_DEPTHSTENCIL) &&245(V3D_VERSION >= 40 ||246(job->zsbuf && job->zsbuf->texture->nr_samples > 1))) {247struct pipe_surface *src = job->bbuf ? job->bbuf : job->zsbuf;248struct v3d_resource *rsc = v3d_resource(src->texture);249250if (rsc->separate_stencil &&251(loads_pending & PIPE_CLEAR_STENCIL)) {252load_general(cl, src,253STENCIL, layer,254PIPE_CLEAR_STENCIL,255&loads_pending);256}257258if (loads_pending & PIPE_CLEAR_DEPTHSTENCIL) {259load_general(cl, src,260zs_buffer_from_pipe_bits(loads_pending),261layer,262loads_pending & PIPE_CLEAR_DEPTHSTENCIL,263&loads_pending);264}265}266267#if V3D_VERSION < 40268/* The initial reload will be queued until we get the269* tile coordinates.270*/271if (loads_pending) {272cl_emit(cl, RELOAD_TILE_COLOR_BUFFER, load) {273load.disable_color_buffer_load =274(~loads_pending &275PIPE_CLEAR_COLOR_BUFFERS) >>276PIPE_FIRST_COLOR_BUFFER_BIT;277load.enable_z_load =278loads_pending & PIPE_CLEAR_DEPTH;279load.enable_stencil_load =280loads_pending & PIPE_CLEAR_STENCIL;281}282}283#else /* V3D_VERSION >= 40 */284assert(!loads_pending);285cl_emit(cl, END_OF_LOADS, end);286#endif287}288289static void290v3d_rcl_emit_stores(struct v3d_job *job, struct v3d_cl *cl, int layer)291{292#if V3D_VERSION < 40293UNUSED bool needs_color_clear = job->clear & PIPE_CLEAR_COLOR_BUFFERS;294UNUSED bool needs_z_clear = job->clear & PIPE_CLEAR_DEPTH;295UNUSED bool needs_s_clear = job->clear & PIPE_CLEAR_STENCIL;296297/* For clearing color in a TLB general on V3D 3.3:298*299* - NONE buffer store clears all TLB color buffers.300* - color buffer store clears just the TLB color buffer being stored.301* - Z/S buffers store may not clear the TLB color buffer.302*303* And on V3D 4.1, we only have one flag for "clear the buffer being304* stored" in the general packet, and a separate packet to clear all305* color TLB buffers.306*307* As a result, we only bother flagging TLB color clears in a general308* packet when we don't have to emit a separate packet to clear all309* TLB color buffers.310*/311bool general_color_clear = (needs_color_clear &&312(job->clear & PIPE_CLEAR_COLOR_BUFFERS) ==313(job->store & PIPE_CLEAR_COLOR_BUFFERS));314#else315bool general_color_clear = false;316#endif317318uint32_t stores_pending = job->store;319320/* For V3D 4.1, use general stores for all TLB stores.321*322* For V3D 3.3, we only use general stores to do raw stores for any323* MSAA surfaces. These output UIF tiled images where each 4x MSAA324* pixel is a 2x2 quad, and the format will be that of the325* internal_type/internal_bpp, rather than the format from GL's326* perspective. Non-MSAA surfaces will use327* STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED.328*/329assert(!job->bbuf || job->nr_cbufs <= 1);330for (int i = 0; i < job->nr_cbufs; i++) {331uint32_t bit = PIPE_CLEAR_COLOR0 << i;332if (!(job->store & bit))333continue;334335struct pipe_surface *psurf = job->cbufs[i];336if (!psurf ||337(V3D_VERSION < 40 && psurf->texture->nr_samples <= 1)) {338continue;339}340341store_general(job, cl, psurf, layer, RENDER_TARGET_0 + i, bit,342&stores_pending, general_color_clear, job->bbuf);343}344345if (job->store & PIPE_CLEAR_DEPTHSTENCIL && job->zsbuf &&346!(V3D_VERSION < 40 && job->zsbuf->texture->nr_samples <= 1)) {347struct v3d_resource *rsc = v3d_resource(job->zsbuf->texture);348if (rsc->separate_stencil) {349if (job->store & PIPE_CLEAR_DEPTH) {350store_general(job, cl, job->zsbuf, layer,351Z, PIPE_CLEAR_DEPTH,352&stores_pending,353general_color_clear,354false);355}356357if (job->store & PIPE_CLEAR_STENCIL) {358store_general(job, cl, job->zsbuf, layer,359STENCIL, PIPE_CLEAR_STENCIL,360&stores_pending,361general_color_clear,362false);363}364} else {365store_general(job, cl, job->zsbuf, layer,366zs_buffer_from_pipe_bits(job->store),367job->store & PIPE_CLEAR_DEPTHSTENCIL,368&stores_pending, general_color_clear,369false);370}371}372373#if V3D_VERSION < 40374if (stores_pending) {375cl_emit(cl, STORE_MULTI_SAMPLE_RESOLVED_TILE_COLOR_BUFFER_EXTENDED, store) {376377store.disable_color_buffer_write =378(~stores_pending >>379PIPE_FIRST_COLOR_BUFFER_BIT) & 0xf;380store.enable_z_write = stores_pending & PIPE_CLEAR_DEPTH;381store.enable_stencil_write = stores_pending & PIPE_CLEAR_STENCIL;382383/* Note that when set this will clear all of the color384* buffers.385*/386store.disable_color_buffers_clear_on_write =387!needs_color_clear;388store.disable_z_buffer_clear_on_write =389!needs_z_clear;390store.disable_stencil_buffer_clear_on_write =391!needs_s_clear;392};393} else if (needs_color_clear && !general_color_clear) {394/* If we didn't do our color clears in the general packet,395* then emit a packet to clear all the TLB color buffers now.396*/397cl_emit(cl, STORE_TILE_BUFFER_GENERAL, store) {398store.buffer_to_store = NONE;399}400}401#else /* V3D_VERSION >= 40 */402/* If we're emitting an RCL with GL_ARB_framebuffer_no_attachments,403* we still need to emit some sort of store.404*/405if (!job->store) {406cl_emit(cl, STORE_TILE_BUFFER_GENERAL, store) {407store.buffer_to_store = NONE;408}409}410411assert(!stores_pending);412413/* GFXH-1461/GFXH-1689: The per-buffer store command's clear414* buffer bit is broken for depth/stencil. In addition, the415* clear packet's Z/S bit is broken, but the RTs bit ends up416* clearing Z/S.417*/418if (job->clear) {419cl_emit(cl, CLEAR_TILE_BUFFERS, clear) {420clear.clear_z_stencil_buffer = true;421clear.clear_all_render_targets = true;422}423}424#endif /* V3D_VERSION >= 40 */425}426427static void428v3d_rcl_emit_generic_per_tile_list(struct v3d_job *job, int layer)429{430/* Emit the generic list in our indirect state -- the rcl will just431* have pointers into it.432*/433struct v3d_cl *cl = &job->indirect;434v3d_cl_ensure_space(cl, 200, 1);435struct v3d_cl_reloc tile_list_start = cl_get_address(cl);436437if (V3D_VERSION >= 40) {438/* V3D 4.x only requires a single tile coordinates, and439* END_OF_LOADS switches us between loading and rendering.440*/441cl_emit(cl, TILE_COORDINATES_IMPLICIT, coords);442}443444v3d_rcl_emit_loads(job, cl, layer);445446if (V3D_VERSION < 40) {447/* Tile Coordinates triggers the last reload and sets where448* the stores go. There must be one per store packet.449*/450cl_emit(cl, TILE_COORDINATES_IMPLICIT, coords);451}452453/* The binner starts out writing tiles assuming that the initial mode454* is triangles, so make sure that's the case.455*/456cl_emit(cl, PRIM_LIST_FORMAT, fmt) {457fmt.primitive_type = LIST_TRIANGLES;458}459460#if V3D_VERSION >= 41461/* PTB assumes that value to be 0, but hw will not set it. */462cl_emit(cl, SET_INSTANCEID, set) {463set.instance_id = 0;464}465#endif466467cl_emit(cl, BRANCH_TO_IMPLICIT_TILE_LIST, branch);468469v3d_rcl_emit_stores(job, cl, layer);470471#if V3D_VERSION >= 40472cl_emit(cl, END_OF_TILE_MARKER, end);473#endif474475cl_emit(cl, RETURN_FROM_SUB_LIST, ret);476477cl_emit(&job->rcl, START_ADDRESS_OF_GENERIC_TILE_LIST, branch) {478branch.start = tile_list_start;479branch.end = cl_get_address(cl);480}481}482483#if V3D_VERSION >= 40484static void485v3d_setup_render_target(struct v3d_job *job, int cbuf,486uint32_t *rt_bpp, uint32_t *rt_type, uint32_t *rt_clamp)487{488if (!job->cbufs[cbuf])489return;490491struct v3d_surface *surf = v3d_surface(job->cbufs[cbuf]);492*rt_bpp = surf->internal_bpp;493if (job->bbuf) {494struct v3d_surface *bsurf = v3d_surface(job->bbuf);495*rt_bpp = MAX2(*rt_bpp, bsurf->internal_bpp);496}497*rt_type = surf->internal_type;498*rt_clamp = V3D_RENDER_TARGET_CLAMP_NONE;499}500501#else /* V3D_VERSION < 40 */502503static void504v3d_emit_z_stencil_config(struct v3d_job *job, struct v3d_surface *surf,505struct v3d_resource *rsc, bool is_separate_stencil)506{507cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_Z_STENCIL, zs) {508zs.address = cl_address(rsc->bo, surf->offset);509510if (!is_separate_stencil) {511zs.internal_type = surf->internal_type;512zs.output_image_format = surf->format;513} else {514zs.z_stencil_id = 1; /* Separate stencil */515}516517zs.padded_height_of_output_image_in_uif_blocks =518surf->padded_height_of_output_image_in_uif_blocks;519520assert(surf->tiling != V3D_TILING_RASTER);521zs.memory_format = surf->tiling;522}523524if (job->store & (is_separate_stencil ?525PIPE_CLEAR_STENCIL :526PIPE_CLEAR_DEPTHSTENCIL)) {527rsc->writes++;528}529}530#endif /* V3D_VERSION < 40 */531532#define div_round_up(a, b) (((a) + (b) - 1) / b)533534static bool535supertile_in_job_scissors(struct v3d_job *job,536uint32_t x, uint32_t y, uint32_t w, uint32_t h)537{538if (job->scissor.disabled || job->scissor.count == 0)539return true;540541const uint32_t min_x = x * w;542const uint32_t min_y = y * h;543const uint32_t max_x = min_x + w - 1;544const uint32_t max_y = min_y + h - 1;545546for (uint32_t i = 0; i < job->scissor.count; i++) {547const uint32_t min_s_x = job->scissor.rects[i].min_x;548const uint32_t min_s_y = job->scissor.rects[i].min_y;549const uint32_t max_s_x = job->scissor.rects[i].max_x;550const uint32_t max_s_y = job->scissor.rects[i].max_y;551552if (max_x < min_s_x || min_x > max_s_x ||553max_y < min_s_y || min_y > max_s_y) {554continue;555}556557return true;558}559560return false;561}562563static void564emit_render_layer(struct v3d_job *job, uint32_t layer)565{566uint32_t supertile_w = 1, supertile_h = 1;567568/* If doing multicore binning, we would need to initialize each569* core's tile list here.570*/571uint32_t tile_alloc_offset =572layer * job->draw_tiles_x * job->draw_tiles_y * 64;573cl_emit(&job->rcl, MULTICORE_RENDERING_TILE_LIST_SET_BASE, list) {574list.address = cl_address(job->tile_alloc, tile_alloc_offset);575}576577cl_emit(&job->rcl, MULTICORE_RENDERING_SUPERTILE_CFG, config) {578uint32_t frame_w_in_supertiles, frame_h_in_supertiles;579const uint32_t max_supertiles = 256;580581/* Size up our supertiles until we get under the limit. */582for (;;) {583frame_w_in_supertiles = div_round_up(job->draw_tiles_x,584supertile_w);585frame_h_in_supertiles = div_round_up(job->draw_tiles_y,586supertile_h);587if (frame_w_in_supertiles *588frame_h_in_supertiles < max_supertiles) {589break;590}591592if (supertile_w < supertile_h)593supertile_w++;594else595supertile_h++;596}597598config.number_of_bin_tile_lists = 1;599config.total_frame_width_in_tiles = job->draw_tiles_x;600config.total_frame_height_in_tiles = job->draw_tiles_y;601602config.supertile_width_in_tiles = supertile_w;603config.supertile_height_in_tiles = supertile_h;604605config.total_frame_width_in_supertiles = frame_w_in_supertiles;606config.total_frame_height_in_supertiles = frame_h_in_supertiles;607}608609/* Start by clearing the tile buffer. */610cl_emit(&job->rcl, TILE_COORDINATES, coords) {611coords.tile_column_number = 0;612coords.tile_row_number = 0;613}614615/* Emit an initial clear of the tile buffers. This is necessary616* for any buffers that should be cleared (since clearing617* normally happens at the *end* of the generic tile list), but618* it's also nice to clear everything so the first tile doesn't619* inherit any contents from some previous frame.620*621* Also, implement the GFXH-1742 workaround. There's a race in622* the HW between the RCL updating the TLB's internal type/size623* and thespawning of the QPU instances using the TLB's current624* internal type/size. To make sure the QPUs get the right625* state, we need 1 dummy store in between internal type/size626* changes on V3D 3.x, and 2 dummy stores on 4.x.627*/628#if V3D_VERSION < 40629cl_emit(&job->rcl, STORE_TILE_BUFFER_GENERAL, store) {630store.buffer_to_store = NONE;631}632#else633for (int i = 0; i < 2; i++) {634if (i > 0)635cl_emit(&job->rcl, TILE_COORDINATES, coords);636cl_emit(&job->rcl, END_OF_LOADS, end);637cl_emit(&job->rcl, STORE_TILE_BUFFER_GENERAL, store) {638store.buffer_to_store = NONE;639}640if (i == 0) {641cl_emit(&job->rcl, CLEAR_TILE_BUFFERS, clear) {642clear.clear_z_stencil_buffer = true;643clear.clear_all_render_targets = true;644}645}646cl_emit(&job->rcl, END_OF_TILE_MARKER, end);647}648#endif649650cl_emit(&job->rcl, FLUSH_VCD_CACHE, flush);651652v3d_rcl_emit_generic_per_tile_list(job, layer);653654/* XXX perf: We should expose GL_MESA_tile_raster_order to655* improve X11 performance, but we should use Morton order656* otherwise to improve cache locality.657*/658uint32_t supertile_w_in_pixels = job->tile_width * supertile_w;659uint32_t supertile_h_in_pixels = job->tile_height * supertile_h;660uint32_t min_x_supertile = job->draw_min_x / supertile_w_in_pixels;661uint32_t min_y_supertile = job->draw_min_y / supertile_h_in_pixels;662663uint32_t max_x_supertile = 0;664uint32_t max_y_supertile = 0;665if (job->draw_max_x != 0 && job->draw_max_y != 0) {666max_x_supertile = (job->draw_max_x - 1) / supertile_w_in_pixels;667max_y_supertile = (job->draw_max_y - 1) / supertile_h_in_pixels;668}669670for (int y = min_y_supertile; y <= max_y_supertile; y++) {671for (int x = min_x_supertile; x <= max_x_supertile; x++) {672if (supertile_in_job_scissors(job, x, y,673supertile_w_in_pixels,674supertile_h_in_pixels)) {675cl_emit(&job->rcl, SUPERTILE_COORDINATES, coords) {676coords.column_number_in_supertiles = x;677coords.row_number_in_supertiles = y;678}679}680}681}682}683684void685v3dX(emit_rcl)(struct v3d_job *job)686{687/* The RCL list should be empty. */688assert(!job->rcl.bo);689690v3d_cl_ensure_space_with_branch(&job->rcl, 200 +691MAX2(job->num_layers, 1) * 256 *692cl_packet_length(SUPERTILE_COORDINATES));693job->submit.rcl_start = job->rcl.bo->offset;694v3d_job_add_bo(job, job->rcl.bo);695696/* Common config must be the first TILE_RENDERING_MODE_CFG697* and Z_STENCIL_CLEAR_VALUES must be last. The ones in between are698* optional updates to the previous HW state.699*/700cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_COMMON, config) {701#if V3D_VERSION < 40702config.enable_z_store = job->store & PIPE_CLEAR_DEPTH;703config.enable_stencil_store = job->store & PIPE_CLEAR_STENCIL;704#else /* V3D_VERSION >= 40 */705if (job->zsbuf) {706struct v3d_surface *surf = v3d_surface(job->zsbuf);707config.internal_depth_type = surf->internal_type;708}709#endif /* V3D_VERSION >= 40 */710711/* XXX: Early D/S clear */712713switch (job->first_ez_state) {714case V3D_EZ_UNDECIDED:715case V3D_EZ_LT_LE:716config.early_z_disable = false;717config.early_z_test_and_update_direction =718EARLY_Z_DIRECTION_LT_LE;719break;720case V3D_EZ_GT_GE:721config.early_z_disable = false;722config.early_z_test_and_update_direction =723EARLY_Z_DIRECTION_GT_GE;724break;725case V3D_EZ_DISABLED:726config.early_z_disable = true;727}728729config.image_width_pixels = job->draw_width;730config.image_height_pixels = job->draw_height;731732config.number_of_render_targets = MAX2(job->nr_cbufs, 1);733734config.multisample_mode_4x = job->msaa;735736config.maximum_bpp_of_all_render_targets = job->internal_bpp;737}738739for (int i = 0; i < job->nr_cbufs; i++) {740struct pipe_surface *psurf = job->cbufs[i];741if (!psurf)742continue;743struct v3d_surface *surf = v3d_surface(psurf);744struct v3d_resource *rsc = v3d_resource(psurf->texture);745746UNUSED uint32_t config_pad = 0;747uint32_t clear_pad = 0;748749/* XXX: Set the pad for raster. */750if (surf->tiling == V3D_TILING_UIF_NO_XOR ||751surf->tiling == V3D_TILING_UIF_XOR) {752int uif_block_height = v3d_utile_height(rsc->cpp) * 2;753uint32_t implicit_padded_height = (align(job->draw_height, uif_block_height) /754uif_block_height);755if (surf->padded_height_of_output_image_in_uif_blocks -756implicit_padded_height < 15) {757config_pad = (surf->padded_height_of_output_image_in_uif_blocks -758implicit_padded_height);759} else {760config_pad = 15;761clear_pad = surf->padded_height_of_output_image_in_uif_blocks;762}763}764765#if V3D_VERSION < 40766cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_COLOR, rt) {767rt.address = cl_address(rsc->bo, surf->offset);768rt.internal_type = surf->internal_type;769rt.output_image_format = surf->format;770rt.memory_format = surf->tiling;771rt.internal_bpp = surf->internal_bpp;772rt.render_target_number = i;773rt.pad = config_pad;774775if (job->store & PIPE_CLEAR_COLOR0 << i)776rsc->writes++;777}778#endif /* V3D_VERSION < 40 */779780cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_CLEAR_COLORS_PART1,781clear) {782clear.clear_color_low_32_bits = job->clear_color[i][0];783clear.clear_color_next_24_bits = job->clear_color[i][1] & 0xffffff;784clear.render_target_number = i;785};786787if (surf->internal_bpp >= V3D_INTERNAL_BPP_64) {788cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_CLEAR_COLORS_PART2,789clear) {790clear.clear_color_mid_low_32_bits =791((job->clear_color[i][1] >> 24) |792(job->clear_color[i][2] << 8));793clear.clear_color_mid_high_24_bits =794((job->clear_color[i][2] >> 24) |795((job->clear_color[i][3] & 0xffff) << 8));796clear.render_target_number = i;797};798}799800if (surf->internal_bpp >= V3D_INTERNAL_BPP_128 || clear_pad) {801cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_CLEAR_COLORS_PART3,802clear) {803clear.uif_padded_height_in_uif_blocks = clear_pad;804clear.clear_color_high_16_bits = job->clear_color[i][3] >> 16;805clear.render_target_number = i;806};807}808}809810#if V3D_VERSION >= 40811cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_COLOR, rt) {812v3d_setup_render_target(job, 0,813&rt.render_target_0_internal_bpp,814&rt.render_target_0_internal_type,815&rt.render_target_0_clamp);816v3d_setup_render_target(job, 1,817&rt.render_target_1_internal_bpp,818&rt.render_target_1_internal_type,819&rt.render_target_1_clamp);820v3d_setup_render_target(job, 2,821&rt.render_target_2_internal_bpp,822&rt.render_target_2_internal_type,823&rt.render_target_2_clamp);824v3d_setup_render_target(job, 3,825&rt.render_target_3_internal_bpp,826&rt.render_target_3_internal_type,827&rt.render_target_3_clamp);828}829#endif830831#if V3D_VERSION < 40832/* TODO: Don't bother emitting if we don't load/clear Z/S. */833if (job->zsbuf) {834struct pipe_surface *psurf = job->zsbuf;835struct v3d_surface *surf = v3d_surface(psurf);836struct v3d_resource *rsc = v3d_resource(psurf->texture);837838v3d_emit_z_stencil_config(job, surf, rsc, false);839840/* Emit the separate stencil packet if we have a resource for841* it. The HW will only load/store this buffer if the842* Z/Stencil config doesn't have stencil in its format.843*/844if (surf->separate_stencil) {845v3d_emit_z_stencil_config(job,846v3d_surface(surf->separate_stencil),847rsc->separate_stencil, true);848}849}850#endif /* V3D_VERSION < 40 */851852/* Ends rendering mode config. */853cl_emit(&job->rcl, TILE_RENDERING_MODE_CFG_ZS_CLEAR_VALUES,854clear) {855clear.z_clear_value = job->clear_z;856clear.stencil_clear_value = job->clear_s;857};858859/* Always set initial block size before the first branch, which needs860* to match the value from binning mode config.861*/862cl_emit(&job->rcl, TILE_LIST_INITIAL_BLOCK_SIZE, init) {863init.use_auto_chained_tile_lists = true;864init.size_of_first_block_in_chained_tile_lists =865TILE_ALLOCATION_BLOCK_SIZE_64B;866}867868/* ARB_framebuffer_no_attachments allows rendering to happen even when869* the framebuffer has no attachments, the idea being that fragment870* shaders can still do image load/store, ssbo, etc without having to871* write to actual attachments, so always run at least one iteration872* of the loop.873*/874assert(job->num_layers > 0 || (job->load == 0 && job->store == 0));875for (int layer = 0; layer < MAX2(1, job->num_layers); layer++)876emit_render_layer(job, layer);877878cl_emit(&job->rcl, END_OF_RENDERING, end);879}880881882