Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_blorp.c
4565 views
/*1* Copyright © 2018 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/**23* @file iris_blorp.c24*25* ============================= GENXML CODE =============================26* [This file is compiled once per generation.]27* =======================================================================28*29* GenX specific code for working with BLORP (blitting, resolves, clears30* on the 3D engine). This provides the driver-specific hooks needed to31* implement the BLORP API.32*33* See iris_blit.c, iris_clear.c, and so on.34*/3536#include <assert.h>3738#include "iris_batch.h"39#include "iris_resource.h"40#include "iris_context.h"4142#include "util/u_upload_mgr.h"43#include "intel/common/intel_l3_config.h"4445#include "blorp/blorp_genX_exec.h"4647static uint32_t *48stream_state(struct iris_batch *batch,49struct u_upload_mgr *uploader,50unsigned size,51unsigned alignment,52uint32_t *out_offset,53struct iris_bo **out_bo)54{55struct pipe_resource *res = NULL;56void *ptr = NULL;5758u_upload_alloc(uploader, 0, size, alignment, out_offset, &res, &ptr);5960struct iris_bo *bo = iris_resource_bo(res);61iris_use_pinned_bo(batch, bo, false, IRIS_DOMAIN_NONE);6263iris_record_state_size(batch->state_sizes,64bo->gtt_offset + *out_offset, size);6566/* If the caller has asked for a BO, we leave them the responsibility of67* adding bo->gtt_offset (say, by handing an address to genxml). If not,68* we assume they want the offset from a base address.69*/70if (out_bo)71*out_bo = bo;72else73*out_offset += iris_bo_offset_from_base_address(bo);7475pipe_resource_reference(&res, NULL);7677return ptr;78}7980static void *81blorp_emit_dwords(struct blorp_batch *blorp_batch, unsigned n)82{83struct iris_batch *batch = blorp_batch->driver_batch;84return iris_get_command_space(batch, n * sizeof(uint32_t));85}8687static uint64_t88combine_and_pin_address(struct blorp_batch *blorp_batch,89struct blorp_address addr)90{91struct iris_batch *batch = blorp_batch->driver_batch;92struct iris_bo *bo = addr.buffer;9394iris_use_pinned_bo(batch, bo, addr.reloc_flags & RELOC_WRITE,95IRIS_DOMAIN_NONE);9697/* Assume this is a general address, not relative to a base. */98return bo->gtt_offset + addr.offset;99}100101static uint64_t102blorp_emit_reloc(struct blorp_batch *blorp_batch, UNUSED void *location,103struct blorp_address addr, uint32_t delta)104{105return combine_and_pin_address(blorp_batch, addr) + delta;106}107108static void109blorp_surface_reloc(struct blorp_batch *blorp_batch, uint32_t ss_offset,110struct blorp_address addr, uint32_t delta)111{112/* Let blorp_get_surface_address do the pinning. */113}114115static uint64_t116blorp_get_surface_address(struct blorp_batch *blorp_batch,117struct blorp_address addr)118{119return combine_and_pin_address(blorp_batch, addr);120}121122UNUSED static struct blorp_address123blorp_get_surface_base_address(UNUSED struct blorp_batch *blorp_batch)124{125return (struct blorp_address) { .offset = IRIS_MEMZONE_BINDER_START };126}127128static void *129blorp_alloc_dynamic_state(struct blorp_batch *blorp_batch,130uint32_t size,131uint32_t alignment,132uint32_t *offset)133{134struct iris_context *ice = blorp_batch->blorp->driver_ctx;135struct iris_batch *batch = blorp_batch->driver_batch;136137return stream_state(batch, ice->state.dynamic_uploader,138size, alignment, offset, NULL);139}140141static void142blorp_alloc_binding_table(struct blorp_batch *blorp_batch,143unsigned num_entries,144unsigned state_size,145unsigned state_alignment,146uint32_t *bt_offset,147uint32_t *surface_offsets,148void **surface_maps)149{150struct iris_context *ice = blorp_batch->blorp->driver_ctx;151struct iris_binder *binder = &ice->state.binder;152struct iris_batch *batch = blorp_batch->driver_batch;153154*bt_offset = iris_binder_reserve(ice, num_entries * sizeof(uint32_t));155uint32_t *bt_map = binder->map + *bt_offset;156157for (unsigned i = 0; i < num_entries; i++) {158surface_maps[i] = stream_state(batch, ice->state.surface_uploader,159state_size, state_alignment,160&surface_offsets[i], NULL);161bt_map[i] = surface_offsets[i] - (uint32_t) binder->bo->gtt_offset;162}163164iris_use_pinned_bo(batch, binder->bo, false, IRIS_DOMAIN_NONE);165166batch->screen->vtbl.update_surface_base_address(batch, binder);167}168169static void *170blorp_alloc_vertex_buffer(struct blorp_batch *blorp_batch,171uint32_t size,172struct blorp_address *addr)173{174struct iris_context *ice = blorp_batch->blorp->driver_ctx;175struct iris_batch *batch = blorp_batch->driver_batch;176struct iris_bo *bo;177uint32_t offset;178179void *map = stream_state(batch, ice->ctx.const_uploader, size, 64,180&offset, &bo);181182*addr = (struct blorp_address) {183.buffer = bo,184.offset = offset,185.mocs = iris_mocs(bo, &batch->screen->isl_dev,186ISL_SURF_USAGE_VERTEX_BUFFER_BIT),187};188189return map;190}191192/**193* See iris_upload_render_state's IRIS_DIRTY_VERTEX_BUFFERS handling for194* a comment about why these VF invalidations are needed.195*/196static void197blorp_vf_invalidate_for_vb_48b_transitions(struct blorp_batch *blorp_batch,198const struct blorp_address *addrs,199UNUSED uint32_t *sizes,200unsigned num_vbs)201{202#if GFX_VER < 11203struct iris_context *ice = blorp_batch->blorp->driver_ctx;204struct iris_batch *batch = blorp_batch->driver_batch;205bool need_invalidate = false;206207for (unsigned i = 0; i < num_vbs; i++) {208struct iris_bo *bo = addrs[i].buffer;209uint16_t high_bits = bo->gtt_offset >> 32u;210211if (high_bits != ice->state.last_vbo_high_bits[i]) {212need_invalidate = true;213ice->state.last_vbo_high_bits[i] = high_bits;214}215}216217if (need_invalidate) {218iris_emit_pipe_control_flush(batch,219"workaround: VF cache 32-bit key [blorp]",220PIPE_CONTROL_VF_CACHE_INVALIDATE |221PIPE_CONTROL_CS_STALL);222}223#endif224}225226static struct blorp_address227blorp_get_workaround_address(struct blorp_batch *blorp_batch)228{229struct iris_batch *batch = blorp_batch->driver_batch;230231return (struct blorp_address) {232.buffer = batch->screen->workaround_address.bo,233.offset = batch->screen->workaround_address.offset,234};235}236237static void238blorp_flush_range(UNUSED struct blorp_batch *blorp_batch,239UNUSED void *start,240UNUSED size_t size)241{242/* All allocated states come from the batch which we will flush before we243* submit it. There's nothing for us to do here.244*/245}246247static const struct intel_l3_config *248blorp_get_l3_config(struct blorp_batch *blorp_batch)249{250struct iris_batch *batch = blorp_batch->driver_batch;251return batch->screen->l3_config_3d;252}253254static void255iris_blorp_exec(struct blorp_batch *blorp_batch,256const struct blorp_params *params)257{258struct iris_context *ice = blorp_batch->blorp->driver_ctx;259struct iris_batch *batch = blorp_batch->driver_batch;260261#if GFX_VER >= 11262/* The PIPE_CONTROL command description says:263*264* "Whenever a Binding Table Index (BTI) used by a Render Target Message265* points to a different RENDER_SURFACE_STATE, SW must issue a Render266* Target Cache Flush by enabling this bit. When render target flush267* is set due to new association of BTI, PS Scoreboard Stall bit must268* be set in this packet."269*/270iris_emit_pipe_control_flush(batch,271"workaround: RT BTI change [blorp]",272PIPE_CONTROL_RENDER_TARGET_FLUSH |273PIPE_CONTROL_STALL_AT_SCOREBOARD);274#endif275276#if GFX_VERx10 == 120277if (!(blorp_batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL)) {278/* Wa_14010455700279*280* ISL will change some CHICKEN registers depending on the depth surface281* format, along with emitting the depth and stencil packets. In that282* case, we want to do a depth flush and stall, so the pipeline is not283* using these settings while we change the registers.284*/285iris_emit_end_of_pipe_sync(batch,286"Workaround: Stop pipeline for 14010455700",287PIPE_CONTROL_DEPTH_STALL |288PIPE_CONTROL_DEPTH_CACHE_FLUSH);289}290#endif291292/* Flush the render cache in cases where the same surface is used with293* different aux modes, which can lead to GPU hangs. Invalidation of294* sampler caches and flushing of any caches which had previously written295* the source surfaces should already have been handled by the caller.296*/297if (params->dst.enabled) {298iris_cache_flush_for_render(batch, params->dst.addr.buffer,299params->dst.aux_usage);300}301302iris_require_command_space(batch, 1400);303304#if GFX_VER == 8305genX(update_pma_fix)(ice, batch, false);306#endif307308const unsigned scale = params->fast_clear_op ? UINT_MAX : 1;309if (ice->state.current_hash_scale != scale) {310genX(emit_hashing_mode)(ice, batch, params->x1 - params->x0,311params->y1 - params->y0, scale);312}313314#if GFX_VER >= 12315genX(invalidate_aux_map_state)(batch);316#endif317318iris_handle_always_flush_cache(batch);319320blorp_exec(blorp_batch, params);321322iris_handle_always_flush_cache(batch);323324/* We've smashed all state compared to what the normal 3D pipeline325* rendering tracks for GL.326*/327328uint64_t skip_bits = (IRIS_DIRTY_POLYGON_STIPPLE |329IRIS_DIRTY_SO_BUFFERS |330IRIS_DIRTY_SO_DECL_LIST |331IRIS_DIRTY_LINE_STIPPLE |332IRIS_ALL_DIRTY_FOR_COMPUTE |333IRIS_DIRTY_SCISSOR_RECT |334IRIS_DIRTY_VF |335IRIS_DIRTY_SF_CL_VIEWPORT);336uint64_t skip_stage_bits = (IRIS_ALL_STAGE_DIRTY_FOR_COMPUTE |337IRIS_STAGE_DIRTY_UNCOMPILED_VS |338IRIS_STAGE_DIRTY_UNCOMPILED_TCS |339IRIS_STAGE_DIRTY_UNCOMPILED_TES |340IRIS_STAGE_DIRTY_UNCOMPILED_GS |341IRIS_STAGE_DIRTY_UNCOMPILED_FS |342IRIS_STAGE_DIRTY_SAMPLER_STATES_VS |343IRIS_STAGE_DIRTY_SAMPLER_STATES_TCS |344IRIS_STAGE_DIRTY_SAMPLER_STATES_TES |345IRIS_STAGE_DIRTY_SAMPLER_STATES_GS);346347if (!ice->shaders.uncompiled[MESA_SHADER_TESS_EVAL]) {348/* BLORP disabled tessellation, that's fine for the next draw */349skip_stage_bits |= IRIS_STAGE_DIRTY_TCS |350IRIS_STAGE_DIRTY_TES |351IRIS_STAGE_DIRTY_CONSTANTS_TCS |352IRIS_STAGE_DIRTY_CONSTANTS_TES |353IRIS_STAGE_DIRTY_BINDINGS_TCS |354IRIS_STAGE_DIRTY_BINDINGS_TES;355}356357if (!ice->shaders.uncompiled[MESA_SHADER_GEOMETRY]) {358/* BLORP disabled geometry shaders, that's fine for the next draw */359skip_stage_bits |= IRIS_STAGE_DIRTY_GS |360IRIS_STAGE_DIRTY_CONSTANTS_GS |361IRIS_STAGE_DIRTY_BINDINGS_GS;362}363364/* we can skip flagging IRIS_DIRTY_DEPTH_BUFFER, if365* BLORP_BATCH_NO_EMIT_DEPTH_STENCIL is set.366*/367if (blorp_batch->flags & BLORP_BATCH_NO_EMIT_DEPTH_STENCIL)368skip_bits |= IRIS_DIRTY_DEPTH_BUFFER;369370if (!params->wm_prog_data)371skip_bits |= IRIS_DIRTY_BLEND_STATE | IRIS_DIRTY_PS_BLEND;372373ice->state.dirty |= ~skip_bits;374ice->state.stage_dirty |= ~skip_stage_bits;375376for (int i = 0; i < ARRAY_SIZE(ice->shaders.urb.size); i++)377ice->shaders.urb.size[i] = 0;378379if (params->src.enabled)380iris_bo_bump_seqno(params->src.addr.buffer, batch->next_seqno,381IRIS_DOMAIN_OTHER_READ);382if (params->dst.enabled)383iris_bo_bump_seqno(params->dst.addr.buffer, batch->next_seqno,384IRIS_DOMAIN_RENDER_WRITE);385if (params->depth.enabled)386iris_bo_bump_seqno(params->depth.addr.buffer, batch->next_seqno,387IRIS_DOMAIN_DEPTH_WRITE);388if (params->stencil.enabled)389iris_bo_bump_seqno(params->stencil.addr.buffer, batch->next_seqno,390IRIS_DOMAIN_DEPTH_WRITE);391}392393static void394blorp_measure_start(struct blorp_batch *blorp_batch,395const struct blorp_params *params)396{397struct iris_context *ice = blorp_batch->blorp->driver_ctx;398struct iris_batch *batch = blorp_batch->driver_batch;399400if (batch->measure == NULL)401return;402403iris_measure_snapshot(ice, batch, params->snapshot_type, NULL, NULL, NULL);404}405406void407genX(init_blorp)(struct iris_context *ice)408{409struct iris_screen *screen = (struct iris_screen *)ice->ctx.screen;410411blorp_init(&ice->blorp, ice, &screen->isl_dev);412ice->blorp.compiler = screen->compiler;413ice->blorp.lookup_shader = iris_blorp_lookup_shader;414ice->blorp.upload_shader = iris_blorp_upload_shader;415ice->blorp.exec = iris_blorp_exec;416}417418419