1b8e80941Smrg/* 2b8e80941Smrg * Copyright 2017 Intel Corporation 3b8e80941Smrg * 4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5b8e80941Smrg * copy of this software and associated documentation files (the "Software"), 6b8e80941Smrg * to deal in the Software without restriction, including without limitation 7b8e80941Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 8b8e80941Smrg * license, and/or sell copies of the Software, and to permit persons to whom 9b8e80941Smrg * the Software is furnished to do so, subject to the following conditions: 10b8e80941Smrg * 11b8e80941Smrg * The above copyright notice and this permission notice (including the next 12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the 13b8e80941Smrg * Software. 14b8e80941Smrg * 15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18b8e80941Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19b8e80941Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20b8e80941Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21b8e80941Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 22b8e80941Smrg */ 23b8e80941Smrg#ifndef IRIS_RESOURCE_H 24b8e80941Smrg#define IRIS_RESOURCE_H 25b8e80941Smrg 26b8e80941Smrg#include "pipe/p_state.h" 27b8e80941Smrg#include "util/u_inlines.h" 28b8e80941Smrg#include "util/u_range.h" 29b8e80941Smrg#include "intel/isl/isl.h" 30b8e80941Smrg 31b8e80941Smrgstruct iris_batch; 32b8e80941Smrgstruct iris_context; 33b8e80941Smrg 34b8e80941Smrg#define IRIS_MAX_MIPLEVELS 15 35b8e80941Smrg 36b8e80941Smrgstruct iris_format_info { 37b8e80941Smrg enum isl_format fmt; 38b8e80941Smrg struct isl_swizzle swizzle; 39b8e80941Smrg}; 40b8e80941Smrg 41b8e80941Smrg#define IRIS_RESOURCE_FLAG_SHADER_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) 42b8e80941Smrg#define IRIS_RESOURCE_FLAG_SURFACE_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 1) 43b8e80941Smrg#define IRIS_RESOURCE_FLAG_DYNAMIC_MEMZONE (PIPE_RESOURCE_FLAG_DRV_PRIV << 2) 44b8e80941Smrg 45b8e80941Smrgenum gen9_astc5x5_wa_tex_type { 46b8e80941Smrg GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5 = 1 << 0, 47b8e80941Smrg GEN9_ASTC5X5_WA_TEX_TYPE_AUX = 1 << 1, 48b8e80941Smrg}; 49b8e80941Smrg 50b8e80941Smrg/** 51b8e80941Smrg * Resources represent a GPU buffer object or image (mipmap tree). 52b8e80941Smrg * 53b8e80941Smrg * They contain the storage (BO) and layout information (ISL surface). 54b8e80941Smrg */ 55b8e80941Smrgstruct iris_resource { 56b8e80941Smrg struct pipe_resource base; 57b8e80941Smrg enum pipe_format internal_format; 58b8e80941Smrg 59b8e80941Smrg /** 60b8e80941Smrg * The ISL surface layout information for this resource. 61b8e80941Smrg * 62b8e80941Smrg * This is not filled out for PIPE_BUFFER resources, but is guaranteed 63b8e80941Smrg * to be zeroed. Note that this also guarantees that res->surf.tiling 64b8e80941Smrg * will be ISL_TILING_LINEAR, so it's safe to check that. 65b8e80941Smrg */ 66b8e80941Smrg struct isl_surf surf; 67b8e80941Smrg 68b8e80941Smrg /** Backing storage for the resource */ 69b8e80941Smrg struct iris_bo *bo; 70b8e80941Smrg 71b8e80941Smrg /** 72b8e80941Smrg * A bitfield of PIPE_BIND_* indicating how this resource was bound 73b8e80941Smrg * in the past. Only meaningful for PIPE_BUFFER; used for flushing. 74b8e80941Smrg */ 75b8e80941Smrg unsigned bind_history; 76b8e80941Smrg 77b8e80941Smrg /** 78b8e80941Smrg * For PIPE_BUFFER resources, a range which may contain valid data. 79b8e80941Smrg * 80b8e80941Smrg * This is a conservative estimate of what part of the buffer contains 81b8e80941Smrg * valid data that we have to preserve. The rest of the buffer is 82b8e80941Smrg * considered invalid, and we can promote writes to that region to 83b8e80941Smrg * be unsynchronized writes, avoiding blit copies. 84b8e80941Smrg */ 85b8e80941Smrg struct util_range valid_buffer_range; 86b8e80941Smrg 87b8e80941Smrg /** 88b8e80941Smrg * Auxiliary buffer information (CCS, MCS, or HiZ). 89b8e80941Smrg */ 90b8e80941Smrg struct { 91b8e80941Smrg /** The surface layout for the auxiliary buffer. */ 92b8e80941Smrg struct isl_surf surf; 93b8e80941Smrg 94b8e80941Smrg /** The buffer object containing the auxiliary data. */ 95b8e80941Smrg struct iris_bo *bo; 96b8e80941Smrg 97b8e80941Smrg /** Offset into 'bo' where the auxiliary surface starts. */ 98b8e80941Smrg uint32_t offset; 99b8e80941Smrg 100b8e80941Smrg /** 101b8e80941Smrg * Fast clear color for this surface. For depth surfaces, the clear 102b8e80941Smrg * value is stored as a float32 in the red component. 103b8e80941Smrg */ 104b8e80941Smrg union isl_color_value clear_color; 105b8e80941Smrg 106b8e80941Smrg /** Buffer object containing the indirect clear color. */ 107b8e80941Smrg struct iris_bo *clear_color_bo; 108b8e80941Smrg 109b8e80941Smrg /** Offset into bo where the clear color can be found. */ 110b8e80941Smrg uint64_t clear_color_offset; 111b8e80941Smrg 112b8e80941Smrg /** 113b8e80941Smrg * \brief The type of auxiliary compression used by this resource. 114b8e80941Smrg * 115b8e80941Smrg * This describes the type of auxiliary compression that is intended to 116b8e80941Smrg * be used by this resource. An aux usage of ISL_AUX_USAGE_NONE means 117b8e80941Smrg * that auxiliary compression is permanently disabled. An aux usage 118b8e80941Smrg * other than ISL_AUX_USAGE_NONE does not imply that auxiliary 119b8e80941Smrg * compression will always be enabled for this surface. 120b8e80941Smrg */ 121b8e80941Smrg enum isl_aux_usage usage; 122b8e80941Smrg 123b8e80941Smrg /** 124b8e80941Smrg * A bitfield of ISL_AUX_* modes that might this resource might use. 125b8e80941Smrg * 126b8e80941Smrg * For example, a surface might use both CCS_E and CCS_D at times. 127b8e80941Smrg */ 128b8e80941Smrg unsigned possible_usages; 129b8e80941Smrg 130b8e80941Smrg /** 131b8e80941Smrg * Same as possible_usages, but only with modes supported for sampling. 132b8e80941Smrg */ 133b8e80941Smrg unsigned sampler_usages; 134b8e80941Smrg 135b8e80941Smrg /** 136b8e80941Smrg * \brief Maps miptree slices to their current aux state. 137b8e80941Smrg * 138b8e80941Smrg * This two-dimensional array is indexed as [level][layer] and stores an 139b8e80941Smrg * aux state for each slice. 140b8e80941Smrg */ 141b8e80941Smrg enum isl_aux_state **state; 142b8e80941Smrg 143b8e80941Smrg /** 144b8e80941Smrg * If (1 << level) is set, HiZ is enabled for that miplevel. 145b8e80941Smrg */ 146b8e80941Smrg uint16_t has_hiz; 147b8e80941Smrg } aux; 148b8e80941Smrg 149b8e80941Smrg /** 150b8e80941Smrg * For external surfaces, this is DRM format modifier that was used to 151b8e80941Smrg * create or import the surface. For internal surfaces, this will always 152b8e80941Smrg * be DRM_FORMAT_MOD_INVALID. 153b8e80941Smrg */ 154b8e80941Smrg const struct isl_drm_modifier_info *mod_info; 155b8e80941Smrg}; 156b8e80941Smrg 157b8e80941Smrg/** 158b8e80941Smrg * A simple <resource, offset> tuple for storing a reference to a 159b8e80941Smrg * piece of state stored in a GPU buffer object. 160b8e80941Smrg */ 161b8e80941Smrgstruct iris_state_ref { 162b8e80941Smrg struct pipe_resource *res; 163b8e80941Smrg uint32_t offset; 164b8e80941Smrg}; 165b8e80941Smrg 166b8e80941Smrg/** 167b8e80941Smrg * Gallium CSO for sampler views (texture views). 168b8e80941Smrg * 169b8e80941Smrg * In addition to the normal pipe_resource, this adds an ISL view 170b8e80941Smrg * which may reinterpret the format or restrict levels/layers. 171b8e80941Smrg * 172b8e80941Smrg * These can also be linear texture buffers. 173b8e80941Smrg */ 174b8e80941Smrgstruct iris_sampler_view { 175b8e80941Smrg struct pipe_sampler_view base; 176b8e80941Smrg struct isl_view view; 177b8e80941Smrg 178b8e80941Smrg union isl_color_value clear_color; 179b8e80941Smrg 180b8e80941Smrg /* A short-cut (not a reference) to the actual resource being viewed. 181b8e80941Smrg * Multi-planar (or depth+stencil) images may have multiple resources 182b8e80941Smrg * chained together; this skips having to traverse base->texture->*. 183b8e80941Smrg */ 184b8e80941Smrg struct iris_resource *res; 185b8e80941Smrg 186b8e80941Smrg /** The resource (BO) holding our SURFACE_STATE. */ 187b8e80941Smrg struct iris_state_ref surface_state; 188b8e80941Smrg}; 189b8e80941Smrg 190b8e80941Smrg/** 191b8e80941Smrg * Image view representation. 192b8e80941Smrg */ 193b8e80941Smrgstruct iris_image_view { 194b8e80941Smrg struct pipe_image_view base; 195b8e80941Smrg 196b8e80941Smrg /** The resource (BO) holding our SURFACE_STATE. */ 197b8e80941Smrg struct iris_state_ref surface_state; 198b8e80941Smrg}; 199b8e80941Smrg 200b8e80941Smrg/** 201b8e80941Smrg * Gallium CSO for surfaces (framebuffer attachments). 202b8e80941Smrg * 203b8e80941Smrg * A view of a surface that can be bound to a color render target or 204b8e80941Smrg * depth/stencil attachment. 205b8e80941Smrg */ 206b8e80941Smrgstruct iris_surface { 207b8e80941Smrg struct pipe_surface base; 208b8e80941Smrg struct isl_view view; 209b8e80941Smrg union isl_color_value clear_color; 210b8e80941Smrg 211b8e80941Smrg /** The resource (BO) holding our SURFACE_STATE. */ 212b8e80941Smrg struct iris_state_ref surface_state; 213b8e80941Smrg}; 214b8e80941Smrg 215b8e80941Smrg/** 216b8e80941Smrg * Transfer object - information about a buffer mapping. 217b8e80941Smrg */ 218b8e80941Smrgstruct iris_transfer { 219b8e80941Smrg struct pipe_transfer base; 220b8e80941Smrg struct pipe_debug_callback *dbg; 221b8e80941Smrg void *buffer; 222b8e80941Smrg void *ptr; 223b8e80941Smrg 224b8e80941Smrg /** A linear staging resource for GPU-based copy_region transfers. */ 225b8e80941Smrg struct pipe_resource *staging; 226b8e80941Smrg struct blorp_context *blorp; 227b8e80941Smrg struct iris_batch *batch; 228b8e80941Smrg 229b8e80941Smrg void (*unmap)(struct iris_transfer *); 230b8e80941Smrg}; 231b8e80941Smrg 232b8e80941Smrg/** 233b8e80941Smrg * Unwrap a pipe_resource to get the underlying iris_bo (for convenience). 234b8e80941Smrg */ 235b8e80941Smrgstatic inline struct iris_bo * 236b8e80941Smrgiris_resource_bo(struct pipe_resource *p_res) 237b8e80941Smrg{ 238b8e80941Smrg struct iris_resource *res = (void *) p_res; 239b8e80941Smrg return res->bo; 240b8e80941Smrg} 241b8e80941Smrg 242b8e80941Smrgstruct iris_format_info iris_format_for_usage(const struct gen_device_info *, 243b8e80941Smrg enum pipe_format pf, 244b8e80941Smrg isl_surf_usage_flags_t usage); 245b8e80941Smrg 246b8e80941Smrgstruct pipe_resource *iris_resource_get_separate_stencil(struct pipe_resource *); 247b8e80941Smrg 248b8e80941Smrgvoid iris_get_depth_stencil_resources(struct pipe_resource *res, 249b8e80941Smrg struct iris_resource **out_z, 250b8e80941Smrg struct iris_resource **out_s); 251b8e80941Smrgbool iris_resource_set_clear_color(struct iris_context *ice, 252b8e80941Smrg struct iris_resource *res, 253b8e80941Smrg union isl_color_value color); 254b8e80941Smrgunion isl_color_value 255b8e80941Smrgiris_resource_get_clear_color(const struct iris_resource *res, 256b8e80941Smrg struct iris_bo **clear_color_bo, 257b8e80941Smrg uint64_t *clear_color_offset); 258b8e80941Smrg 259b8e80941Smrgvoid iris_init_screen_resource_functions(struct pipe_screen *pscreen); 260b8e80941Smrg 261b8e80941Smrgvoid iris_dirty_for_history(struct iris_context *ice, 262b8e80941Smrg struct iris_resource *res); 263b8e80941Smrguint32_t iris_flush_bits_for_history(struct iris_resource *res); 264b8e80941Smrg 265b8e80941Smrgvoid iris_flush_and_dirty_for_history(struct iris_context *ice, 266b8e80941Smrg struct iris_batch *batch, 267b8e80941Smrg struct iris_resource *res); 268b8e80941Smrg 269b8e80941Smrgunsigned iris_get_num_logical_layers(const struct iris_resource *res, 270b8e80941Smrg unsigned level); 271b8e80941Smrg 272b8e80941Smrgvoid iris_resource_disable_aux(struct iris_resource *res); 273b8e80941Smrg 274b8e80941Smrg#define INTEL_REMAINING_LAYERS UINT32_MAX 275b8e80941Smrg#define INTEL_REMAINING_LEVELS UINT32_MAX 276b8e80941Smrg 277b8e80941Smrgvoid 278b8e80941Smrgiris_hiz_exec(struct iris_context *ice, 279b8e80941Smrg struct iris_batch *batch, 280b8e80941Smrg struct iris_resource *res, 281b8e80941Smrg unsigned int level, unsigned int start_layer, 282b8e80941Smrg unsigned int num_layers, enum isl_aux_op op, 283b8e80941Smrg bool update_clear_depth); 284b8e80941Smrg 285b8e80941Smrg/** 286b8e80941Smrg * Prepare a miptree for access 287b8e80941Smrg * 288b8e80941Smrg * This function should be called prior to any access to miptree in order to 289b8e80941Smrg * perform any needed resolves. 290b8e80941Smrg * 291b8e80941Smrg * \param[in] start_level The first mip level to be accessed 292b8e80941Smrg * 293b8e80941Smrg * \param[in] num_levels The number of miplevels to be accessed or 294b8e80941Smrg * INTEL_REMAINING_LEVELS to indicate every level 295b8e80941Smrg * above start_level will be accessed 296b8e80941Smrg * 297b8e80941Smrg * \param[in] start_layer The first array slice or 3D layer to be accessed 298b8e80941Smrg * 299b8e80941Smrg * \param[in] num_layers The number of array slices or 3D layers be 300b8e80941Smrg * accessed or INTEL_REMAINING_LAYERS to indicate 301b8e80941Smrg * every layer above start_layer will be accessed 302b8e80941Smrg * 303b8e80941Smrg * \param[in] aux_supported Whether or not the access will support the 304b8e80941Smrg * miptree's auxiliary compression format; this 305b8e80941Smrg * must be false for uncompressed miptrees 306b8e80941Smrg * 307b8e80941Smrg * \param[in] fast_clear_supported Whether or not the access will support 308b8e80941Smrg * fast clears in the miptree's auxiliary 309b8e80941Smrg * compression format 310b8e80941Smrg */ 311b8e80941Smrgvoid 312b8e80941Smrgiris_resource_prepare_access(struct iris_context *ice, 313b8e80941Smrg struct iris_batch *batch, 314b8e80941Smrg struct iris_resource *res, 315b8e80941Smrg uint32_t start_level, uint32_t num_levels, 316b8e80941Smrg uint32_t start_layer, uint32_t num_layers, 317b8e80941Smrg enum isl_aux_usage aux_usage, 318b8e80941Smrg bool fast_clear_supported); 319b8e80941Smrg 320b8e80941Smrg/** 321b8e80941Smrg * Complete a write operation 322b8e80941Smrg * 323b8e80941Smrg * This function should be called after any operation writes to a miptree. 324b8e80941Smrg * This will update the miptree's compression state so that future resolves 325b8e80941Smrg * happen correctly. Technically, this function can be called before the 326b8e80941Smrg * write occurs but the caller must ensure that they don't interlace 327b8e80941Smrg * iris_resource_prepare_access and iris_resource_finish_write calls to 328b8e80941Smrg * overlapping layer/level ranges. 329b8e80941Smrg * 330b8e80941Smrg * \param[in] level The mip level that was written 331b8e80941Smrg * 332b8e80941Smrg * \param[in] start_layer The first array slice or 3D layer written 333b8e80941Smrg * 334b8e80941Smrg * \param[in] num_layers The number of array slices or 3D layers 335b8e80941Smrg * written or INTEL_REMAINING_LAYERS to indicate 336b8e80941Smrg * every layer above start_layer was written 337b8e80941Smrg * 338b8e80941Smrg * \param[in] written_with_aux Whether or not the write was done with 339b8e80941Smrg * auxiliary compression enabled 340b8e80941Smrg */ 341b8e80941Smrgvoid 342b8e80941Smrgiris_resource_finish_write(struct iris_context *ice, 343b8e80941Smrg struct iris_resource *res, uint32_t level, 344b8e80941Smrg uint32_t start_layer, uint32_t num_layers, 345b8e80941Smrg enum isl_aux_usage aux_usage); 346b8e80941Smrg 347b8e80941Smrg/** Get the auxiliary compression state of a miptree slice */ 348b8e80941Smrgenum isl_aux_state 349b8e80941Smrgiris_resource_get_aux_state(const struct iris_resource *res, 350b8e80941Smrg uint32_t level, uint32_t layer); 351b8e80941Smrg 352b8e80941Smrg/** 353b8e80941Smrg * Set the auxiliary compression state of a miptree slice range 354b8e80941Smrg * 355b8e80941Smrg * This function directly sets the auxiliary compression state of a slice 356b8e80941Smrg * range of a miptree. It only modifies data structures and does not do any 357b8e80941Smrg * resolves. This should only be called by code which directly performs 358b8e80941Smrg * compression operations such as fast clears and resolves. Most code should 359b8e80941Smrg * use iris_resource_prepare_access or iris_resource_finish_write. 360b8e80941Smrg */ 361b8e80941Smrgvoid 362b8e80941Smrgiris_resource_set_aux_state(struct iris_context *ice, 363b8e80941Smrg struct iris_resource *res, uint32_t level, 364b8e80941Smrg uint32_t start_layer, uint32_t num_layers, 365b8e80941Smrg enum isl_aux_state aux_state); 366b8e80941Smrg 367b8e80941Smrg/** 368b8e80941Smrg * Prepare a miptree for raw access 369b8e80941Smrg * 370b8e80941Smrg * This helper prepares the miptree for access that knows nothing about any 371b8e80941Smrg * sort of compression whatsoever. This is useful when mapping the surface or 372b8e80941Smrg * using it with the blitter. 373b8e80941Smrg */ 374b8e80941Smrgstatic inline void 375b8e80941Smrgiris_resource_access_raw(struct iris_context *ice, 376b8e80941Smrg struct iris_batch *batch, 377b8e80941Smrg struct iris_resource *res, 378b8e80941Smrg uint32_t level, uint32_t layer, 379b8e80941Smrg uint32_t num_layers, 380b8e80941Smrg bool write) 381b8e80941Smrg{ 382b8e80941Smrg iris_resource_prepare_access(ice, batch, res, level, 1, layer, num_layers, 383b8e80941Smrg ISL_AUX_USAGE_NONE, false); 384b8e80941Smrg if (write) { 385b8e80941Smrg iris_resource_finish_write(ice, res, level, layer, num_layers, 386b8e80941Smrg ISL_AUX_USAGE_NONE); 387b8e80941Smrg } 388b8e80941Smrg} 389b8e80941Smrg 390b8e80941Smrgenum isl_aux_usage iris_resource_texture_aux_usage(struct iris_context *ice, 391b8e80941Smrg const struct iris_resource *res, 392b8e80941Smrg enum isl_format view_fmt, 393b8e80941Smrg enum gen9_astc5x5_wa_tex_type); 394b8e80941Smrgvoid iris_resource_prepare_texture(struct iris_context *ice, 395b8e80941Smrg struct iris_batch *batch, 396b8e80941Smrg struct iris_resource *res, 397b8e80941Smrg enum isl_format view_format, 398b8e80941Smrg uint32_t start_level, uint32_t num_levels, 399b8e80941Smrg uint32_t start_layer, uint32_t num_layers, 400b8e80941Smrg enum gen9_astc5x5_wa_tex_type); 401b8e80941Smrgvoid iris_resource_prepare_image(struct iris_context *ice, 402b8e80941Smrg struct iris_batch *batch, 403b8e80941Smrg struct iris_resource *res); 404b8e80941Smrg 405b8e80941Smrgvoid iris_resource_check_level_layer(const struct iris_resource *res, 406b8e80941Smrg uint32_t level, uint32_t layer); 407b8e80941Smrg 408b8e80941Smrgbool iris_resource_level_has_hiz(const struct iris_resource *res, 409b8e80941Smrg uint32_t level); 410b8e80941Smrg 411b8e80941Smrgenum isl_aux_usage iris_resource_render_aux_usage(struct iris_context *ice, 412b8e80941Smrg struct iris_resource *res, 413b8e80941Smrg enum isl_format render_fmt, 414b8e80941Smrg bool blend_enabled, 415b8e80941Smrg bool draw_aux_disabled); 416b8e80941Smrgvoid iris_resource_prepare_render(struct iris_context *ice, 417b8e80941Smrg struct iris_batch *batch, 418b8e80941Smrg struct iris_resource *res, uint32_t level, 419b8e80941Smrg uint32_t start_layer, uint32_t layer_count, 420b8e80941Smrg enum isl_aux_usage aux_usage); 421b8e80941Smrgvoid iris_resource_finish_render(struct iris_context *ice, 422b8e80941Smrg struct iris_resource *res, uint32_t level, 423b8e80941Smrg uint32_t start_layer, uint32_t layer_count, 424b8e80941Smrg enum isl_aux_usage aux_usage); 425b8e80941Smrgvoid iris_resource_prepare_depth(struct iris_context *ice, 426b8e80941Smrg struct iris_batch *batch, 427b8e80941Smrg struct iris_resource *res, uint32_t level, 428b8e80941Smrg uint32_t start_layer, uint32_t layer_count); 429b8e80941Smrgvoid iris_resource_finish_depth(struct iris_context *ice, 430b8e80941Smrg struct iris_resource *res, uint32_t level, 431b8e80941Smrg uint32_t start_layer, uint32_t layer_count, 432b8e80941Smrg bool depth_written); 433b8e80941Smrg#endif 434