Path: blob/21.2-virgl/src/gallium/drivers/iris/iris_resource.h
4565 views
/*1* Copyright 2017 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, copy, modify, merge, publish, distribute, sub7* license, and/or sell copies of the Software, and to permit persons to whom8* the 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 NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE.21*/22#ifndef IRIS_RESOURCE_H23#define IRIS_RESOURCE_H2425#include "pipe/p_state.h"26#include "util/u_inlines.h"27#include "util/u_range.h"28#include "util/u_threaded_context.h"29#include "intel/isl/isl.h"30#include "iris_bufmgr.h"3132struct iris_batch;33struct iris_context;34struct shader_info;3536#define IRIS_MAX_MIPLEVELS 153738struct iris_format_info {39enum isl_format fmt;40struct isl_swizzle swizzle;41};4243#define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)44#define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)45#define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)46#define IRIS_RESOURCE_FLAG_BINDLESS_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)47#define IRIS_RESOURCE_FLAG_DEVICE_MEM (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)4849/**50* Resources represent a GPU buffer object or image (mipmap tree).51*52* They contain the storage (BO) and layout information (ISL surface).53*/54struct iris_resource {55struct threaded_resource base;56enum pipe_format internal_format;5758/**59* The ISL surface layout information for this resource.60*61* This is not filled out for PIPE_BUFFER resources, but is guaranteed62* to be zeroed. Note that this also guarantees that res->surf.tiling63* will be ISL_TILING_LINEAR, so it's safe to check that.64*/65struct isl_surf surf;6667/** Backing storage for the resource */68struct iris_bo *bo;6970/** offset at which data starts in the BO */71uint64_t offset;7273/**74* A bitfield of PIPE_BIND_* indicating how this resource was bound75* in the past. Only meaningful for PIPE_BUFFER; used for flushing.76*/77unsigned bind_history;7879/**80* A bitfield of MESA_SHADER_* stages indicating where this resource81* was bound.82*/83unsigned bind_stages;8485/**86* For PIPE_BUFFER resources, a range which may contain valid data.87*88* This is a conservative estimate of what part of the buffer contains89* valid data that we have to preserve. The rest of the buffer is90* considered invalid, and we can promote writes to that region to91* be unsynchronized writes, avoiding blit copies.92*/93struct util_range valid_buffer_range;9495/**96* Auxiliary buffer information (CCS, MCS, or HiZ).97*/98struct {99/** The surface layout for the auxiliary buffer. */100struct isl_surf surf;101102/** The buffer object containing the auxiliary data. */103struct iris_bo *bo;104105/** Offset into 'bo' where the auxiliary surface starts. */106uint32_t offset;107108struct {109struct isl_surf surf;110111/** Offset into 'bo' where the auxiliary surface starts. */112uint32_t offset;113} extra_aux;114115/**116* Fast clear color for this surface. For depth surfaces, the clear117* value is stored as a float32 in the red component.118*/119union isl_color_value clear_color;120121/** Buffer object containing the indirect clear color. */122struct iris_bo *clear_color_bo;123124/** Offset into bo where the clear color can be found. */125uint64_t clear_color_offset;126127/**128* \brief The type of auxiliary compression used by this resource.129*130* This describes the type of auxiliary compression that is intended to131* be used by this resource. An aux usage of ISL_AUX_USAGE_NONE means132* that auxiliary compression is permanently disabled. An aux usage133* other than ISL_AUX_USAGE_NONE does not imply that auxiliary134* compression will always be enabled for this surface.135*/136enum isl_aux_usage usage;137138/**139* A bitfield of ISL_AUX_* modes that might this resource might use.140*141* For example, a surface might use both CCS_E and CCS_D at times.142*/143unsigned possible_usages;144145/**146* Same as possible_usages, but only with modes supported for sampling.147*/148unsigned sampler_usages;149150/**151* \brief Maps miptree slices to their current aux state.152*153* This two-dimensional array is indexed as [level][layer] and stores an154* aux state for each slice.155*/156enum isl_aux_state **state;157} aux;158159/**160* For external surfaces, this is format that was used to create or import161* the surface. For internal surfaces, this will always be162* PIPE_FORMAT_NONE.163*/164enum pipe_format external_format;165166/**167* For external surfaces, this is DRM format modifier that was used to168* create or import the surface. For internal surfaces, this will always169* be DRM_FORMAT_MOD_INVALID.170*/171const struct isl_drm_modifier_info *mod_info;172173/**174* The screen the resource was originally created with, stored for refcounting.175*/176struct pipe_screen *orig_screen;177};178179/**180* A simple <resource, offset> tuple for storing a reference to a181* piece of state stored in a GPU buffer object.182*/183struct iris_state_ref {184struct pipe_resource *res;185uint32_t offset;186};187188/**189* The SURFACE_STATE descriptors for a resource.190*/191struct iris_surface_state {192/**193* CPU-side copy of the packed SURFACE_STATE structures, already194* aligned so they can be uploaded as a contiguous pile of bytes.195*196* This can be updated and re-uploaded if (e.g.) addresses need to change.197*/198uint32_t *cpu;199200/**201* How many states are there? (Each aux mode has its own state.)202*/203unsigned num_states;204205/**206* Address of the resource (res->bo->gtt_offset). Note that "Surface207* Base Address" may be offset from this value.208*/209uint64_t bo_address;210211/** A reference to the GPU buffer holding our uploaded SURFACE_STATE */212struct iris_state_ref ref;213};214215/**216* Gallium CSO for sampler views (texture views).217*218* In addition to the normal pipe_resource, this adds an ISL view219* which may reinterpret the format or restrict levels/layers.220*221* These can also be linear texture buffers.222*/223struct iris_sampler_view {224struct pipe_sampler_view base;225struct isl_view view;226227union isl_color_value clear_color;228229/* A short-cut (not a reference) to the actual resource being viewed.230* Multi-planar (or depth+stencil) images may have multiple resources231* chained together; this skips having to traverse base->texture->*.232*/233struct iris_resource *res;234235/** The resource (BO) holding our SURFACE_STATE. */236struct iris_surface_state surface_state;237};238239/**240* Image view representation.241*/242struct iris_image_view {243struct pipe_image_view base;244245/** The resource (BO) holding our SURFACE_STATE. */246struct iris_surface_state surface_state;247};248249/**250* Gallium CSO for surfaces (framebuffer attachments).251*252* A view of a surface that can be bound to a color render target or253* depth/stencil attachment.254*/255struct iris_surface {256struct pipe_surface base;257struct isl_view view;258struct isl_view read_view;259union isl_color_value clear_color;260261/** The resource (BO) holding our SURFACE_STATE. */262struct iris_surface_state surface_state;263/** The resource (BO) holding our SURFACE_STATE for read. */264struct iris_surface_state surface_state_read;265};266267/**268* Transfer object - information about a buffer mapping.269*/270struct iris_transfer {271struct threaded_transfer base;272struct pipe_debug_callback *dbg;273void *buffer;274void *ptr;275276/** A linear staging resource for GPU-based copy_region transfers. */277struct pipe_resource *staging;278struct blorp_context *blorp;279struct iris_batch *batch;280281bool dest_had_defined_contents;282283void (*unmap)(struct iris_transfer *);284};285286/**287* Memory Object288*/289struct iris_memory_object {290struct pipe_memory_object b;291struct iris_bo *bo;292uint64_t format;293unsigned stride;294};295296/**297* Unwrap a pipe_resource to get the underlying iris_bo (for convenience).298*/299static inline struct iris_bo *300iris_resource_bo(struct pipe_resource *p_res)301{302struct iris_resource *res = (void *) p_res;303return res->bo;304}305306static inline uint32_t307iris_mocs(const struct iris_bo *bo,308const struct isl_device *dev,309isl_surf_usage_flags_t usage)310{311return isl_mocs(dev, usage, bo && iris_bo_is_external(bo));312}313314struct iris_format_info iris_format_for_usage(const struct intel_device_info *,315enum pipe_format pf,316isl_surf_usage_flags_t usage);317318struct pipe_resource *iris_resource_get_separate_stencil(struct pipe_resource *);319320void iris_get_depth_stencil_resources(struct pipe_resource *res,321struct iris_resource **out_z,322struct iris_resource **out_s);323bool iris_resource_set_clear_color(struct iris_context *ice,324struct iris_resource *res,325union isl_color_value color);326union isl_color_value327iris_resource_get_clear_color(const struct iris_resource *res,328struct iris_bo **clear_color_bo,329uint64_t *clear_color_offset);330331void iris_replace_buffer_storage(struct pipe_context *ctx,332struct pipe_resource *dst,333struct pipe_resource *src,334unsigned num_rebinds,335uint32_t rebind_mask,336uint32_t delete_buffer_id);337338339void iris_init_screen_resource_functions(struct pipe_screen *pscreen);340341void iris_dirty_for_history(struct iris_context *ice,342struct iris_resource *res);343uint32_t iris_flush_bits_for_history(struct iris_context *ice,344struct iris_resource *res);345346void iris_flush_and_dirty_for_history(struct iris_context *ice,347struct iris_batch *batch,348struct iris_resource *res,349uint32_t extra_flags,350const char *reason);351352unsigned iris_get_num_logical_layers(const struct iris_resource *res,353unsigned level);354355void iris_resource_disable_aux(struct iris_resource *res);356357#define INTEL_REMAINING_LAYERS UINT32_MAX358#define INTEL_REMAINING_LEVELS UINT32_MAX359360void361iris_hiz_exec(struct iris_context *ice,362struct iris_batch *batch,363struct iris_resource *res,364unsigned int level, unsigned int start_layer,365unsigned int num_layers, enum isl_aux_op op,366bool update_clear_depth);367368/**369* Prepare a miptree for access370*371* This function should be called prior to any access to miptree in order to372* perform any needed resolves.373*374* \param[in] start_level The first mip level to be accessed375*376* \param[in] num_levels The number of miplevels to be accessed or377* INTEL_REMAINING_LEVELS to indicate every level378* above start_level will be accessed379*380* \param[in] start_layer The first array slice or 3D layer to be accessed381*382* \param[in] num_layers The number of array slices or 3D layers be383* accessed or INTEL_REMAINING_LAYERS to indicate384* every layer above start_layer will be accessed385*386* \param[in] aux_supported Whether or not the access will support the387* miptree's auxiliary compression format; this388* must be false for uncompressed miptrees389*390* \param[in] fast_clear_supported Whether or not the access will support391* fast clears in the miptree's auxiliary392* compression format393*/394void395iris_resource_prepare_access(struct iris_context *ice,396struct iris_resource *res,397uint32_t start_level, uint32_t num_levels,398uint32_t start_layer, uint32_t num_layers,399enum isl_aux_usage aux_usage,400bool fast_clear_supported);401402/**403* Complete a write operation404*405* This function should be called after any operation writes to a miptree.406* This will update the miptree's compression state so that future resolves407* happen correctly. Technically, this function can be called before the408* write occurs but the caller must ensure that they don't interlace409* iris_resource_prepare_access and iris_resource_finish_write calls to410* overlapping layer/level ranges.411*412* \param[in] level The mip level that was written413*414* \param[in] start_layer The first array slice or 3D layer written415*416* \param[in] num_layers The number of array slices or 3D layers417* written or INTEL_REMAINING_LAYERS to indicate418* every layer above start_layer was written419*420* \param[in] written_with_aux Whether or not the write was done with421* auxiliary compression enabled422*/423void424iris_resource_finish_write(struct iris_context *ice,425struct iris_resource *res, uint32_t level,426uint32_t start_layer, uint32_t num_layers,427enum isl_aux_usage aux_usage);428429/** Get the auxiliary compression state of a miptree slice */430enum isl_aux_state431iris_resource_get_aux_state(const struct iris_resource *res,432uint32_t level, uint32_t layer);433434/**435* Set the auxiliary compression state of a miptree slice range436*437* This function directly sets the auxiliary compression state of a slice438* range of a miptree. It only modifies data structures and does not do any439* resolves. This should only be called by code which directly performs440* compression operations such as fast clears and resolves. Most code should441* use iris_resource_prepare_access or iris_resource_finish_write.442*/443void444iris_resource_set_aux_state(struct iris_context *ice,445struct iris_resource *res, uint32_t level,446uint32_t start_layer, uint32_t num_layers,447enum isl_aux_state aux_state);448449/**450* Prepare a miptree for raw access451*452* This helper prepares the miptree for access that knows nothing about any453* sort of compression whatsoever. This is useful when mapping the surface or454* using it with the blitter.455*/456static inline void457iris_resource_access_raw(struct iris_context *ice,458struct iris_resource *res,459uint32_t level, uint32_t layer,460uint32_t num_layers,461bool write)462{463iris_resource_prepare_access(ice, res, level, 1, layer, num_layers,464ISL_AUX_USAGE_NONE, false);465if (write) {466iris_resource_finish_write(ice, res, level, layer, num_layers,467ISL_AUX_USAGE_NONE);468}469}470471enum isl_aux_usage iris_resource_texture_aux_usage(struct iris_context *ice,472const struct iris_resource *res,473enum isl_format view_fmt);474void iris_resource_prepare_texture(struct iris_context *ice,475struct iris_resource *res,476enum isl_format view_format,477uint32_t start_level, uint32_t num_levels,478uint32_t start_layer, uint32_t num_layers);479480enum isl_aux_usage iris_image_view_aux_usage(struct iris_context *ice,481const struct pipe_image_view *pview,482const struct shader_info *info);483enum isl_format iris_image_view_get_format(struct iris_context *ice,484const struct pipe_image_view *img);485486static inline bool487iris_resource_unfinished_aux_import(struct iris_resource *res)488{489return res->aux.bo == NULL && res->mod_info &&490res->mod_info->aux_usage != ISL_AUX_USAGE_NONE;491}492493void iris_resource_finish_aux_import(struct pipe_screen *pscreen,494struct iris_resource *res);495496bool iris_has_invalid_primary(const struct iris_resource *res,497unsigned start_level, unsigned num_levels,498unsigned start_layer, unsigned num_layers);499500void iris_resource_check_level_layer(const struct iris_resource *res,501uint32_t level, uint32_t layer);502503bool iris_resource_level_has_hiz(const struct iris_resource *res,504uint32_t level);505506bool iris_sample_with_depth_aux(const struct intel_device_info *devinfo,507const struct iris_resource *res);508509bool iris_can_sample_mcs_with_clear(const struct intel_device_info *devinfo,510const struct iris_resource *res);511512bool iris_has_color_unresolved(const struct iris_resource *res,513unsigned start_level, unsigned num_levels,514unsigned start_layer, unsigned num_layers);515516bool iris_render_formats_color_compatible(enum isl_format a,517enum isl_format b,518union isl_color_value color);519enum isl_aux_usage iris_resource_render_aux_usage(struct iris_context *ice,520struct iris_resource *res,521uint32_t level,522enum isl_format render_fmt,523bool draw_aux_disabled);524void iris_resource_prepare_render(struct iris_context *ice,525struct iris_resource *res, uint32_t level,526uint32_t start_layer, uint32_t layer_count,527enum isl_aux_usage aux_usage);528void iris_resource_finish_render(struct iris_context *ice,529struct iris_resource *res, uint32_t level,530uint32_t start_layer, uint32_t layer_count,531enum isl_aux_usage aux_usage);532#endif533534535