1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2017 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci#ifndef CROCUS_RESOURCE_H 24bf215546Sopenharmony_ci#define CROCUS_RESOURCE_H 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci#include "pipe/p_state.h" 27bf215546Sopenharmony_ci#include "util/u_inlines.h" 28bf215546Sopenharmony_ci#include "util/u_range.h" 29bf215546Sopenharmony_ci#include "util/u_threaded_context.h" 30bf215546Sopenharmony_ci#include "intel/isl/isl.h" 31bf215546Sopenharmony_ci#include "intel/dev/intel_device_info.h" 32bf215546Sopenharmony_ci#include "crocus_bufmgr.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistruct crocus_batch; 35bf215546Sopenharmony_cistruct crocus_context; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#define CROCUS_MAX_MIPLEVELS 15 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistruct crocus_format_info { 40bf215546Sopenharmony_ci enum isl_format fmt; 41bf215546Sopenharmony_ci enum pipe_swizzle swizzles[4]; 42bf215546Sopenharmony_ci}; 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_cistatic inline enum isl_channel_select 45bf215546Sopenharmony_cipipe_to_isl_swizzle(const enum pipe_swizzle pswz, bool green_to_blue) 46bf215546Sopenharmony_ci{ 47bf215546Sopenharmony_ci unsigned swz = (pswz + 4) & 7; 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci return (green_to_blue && swz == ISL_CHANNEL_SELECT_GREEN) ? ISL_CHANNEL_SELECT_BLUE : swz; 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cistatic inline struct isl_swizzle 53bf215546Sopenharmony_cipipe_to_isl_swizzles(const enum pipe_swizzle pswz[4]) 54bf215546Sopenharmony_ci{ 55bf215546Sopenharmony_ci struct isl_swizzle swz; 56bf215546Sopenharmony_ci swz.r = pipe_to_isl_swizzle(pswz[0], false); 57bf215546Sopenharmony_ci swz.g = pipe_to_isl_swizzle(pswz[1], false); 58bf215546Sopenharmony_ci swz.b = pipe_to_isl_swizzle(pswz[2], false); 59bf215546Sopenharmony_ci swz.a = pipe_to_isl_swizzle(pswz[3], false); 60bf215546Sopenharmony_ci return swz; 61bf215546Sopenharmony_ci} 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_cistatic inline void 64bf215546Sopenharmony_cicrocus_combine_swizzle(enum pipe_swizzle outswz[4], 65bf215546Sopenharmony_ci const enum pipe_swizzle fswz[4], 66bf215546Sopenharmony_ci const enum pipe_swizzle vswz[4]) 67bf215546Sopenharmony_ci{ 68bf215546Sopenharmony_ci for (unsigned i = 0; i < 4; i++) { 69bf215546Sopenharmony_ci switch (vswz[i]) { 70bf215546Sopenharmony_ci case PIPE_SWIZZLE_X: outswz[i] = fswz[0]; break; 71bf215546Sopenharmony_ci case PIPE_SWIZZLE_Y: outswz[i] = fswz[1]; break; 72bf215546Sopenharmony_ci case PIPE_SWIZZLE_Z: outswz[i] = fswz[2]; break; 73bf215546Sopenharmony_ci case PIPE_SWIZZLE_W: outswz[i] = fswz[3]; break; 74bf215546Sopenharmony_ci case PIPE_SWIZZLE_1: outswz[i] = PIPE_SWIZZLE_1; break; 75bf215546Sopenharmony_ci case PIPE_SWIZZLE_0: outswz[i] = PIPE_SWIZZLE_0; break; 76bf215546Sopenharmony_ci default: unreachable("invalid swizzle"); 77bf215546Sopenharmony_ci } 78bf215546Sopenharmony_ci } 79bf215546Sopenharmony_ci} 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci/** 82bf215546Sopenharmony_ci * Resources represent a GPU buffer object or image (mipmap tree). 83bf215546Sopenharmony_ci * 84bf215546Sopenharmony_ci * They contain the storage (BO) and layout information (ISL surface). 85bf215546Sopenharmony_ci */ 86bf215546Sopenharmony_cistruct crocus_resource { 87bf215546Sopenharmony_ci struct threaded_resource base; 88bf215546Sopenharmony_ci enum pipe_format internal_format; 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_ci /** 91bf215546Sopenharmony_ci * The ISL surface layout information for this resource. 92bf215546Sopenharmony_ci * 93bf215546Sopenharmony_ci * This is not filled out for PIPE_BUFFER resources, but is guaranteed 94bf215546Sopenharmony_ci * to be zeroed. Note that this also guarantees that res->surf.tiling 95bf215546Sopenharmony_ci * will be ISL_TILING_LINEAR, so it's safe to check that. 96bf215546Sopenharmony_ci */ 97bf215546Sopenharmony_ci struct isl_surf surf; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci /** Backing storage for the resource */ 100bf215546Sopenharmony_ci struct crocus_bo *bo; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci /** offset at which data starts in the BO */ 103bf215546Sopenharmony_ci uint64_t offset; 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci /** 106bf215546Sopenharmony_ci * A bitfield of PIPE_BIND_* indicating how this resource was bound 107bf215546Sopenharmony_ci * in the past. Only meaningful for PIPE_BUFFER; used for flushing. 108bf215546Sopenharmony_ci */ 109bf215546Sopenharmony_ci unsigned bind_history; 110bf215546Sopenharmony_ci 111bf215546Sopenharmony_ci /** 112bf215546Sopenharmony_ci * A bitfield of MESA_SHADER_* stages indicating where this resource 113bf215546Sopenharmony_ci * was bound. 114bf215546Sopenharmony_ci */ 115bf215546Sopenharmony_ci unsigned bind_stages; 116bf215546Sopenharmony_ci 117bf215546Sopenharmony_ci /** 118bf215546Sopenharmony_ci * For PIPE_BUFFER resources, a range which may contain valid data. 119bf215546Sopenharmony_ci * 120bf215546Sopenharmony_ci * This is a conservative estimate of what part of the buffer contains 121bf215546Sopenharmony_ci * valid data that we have to preserve. The rest of the buffer is 122bf215546Sopenharmony_ci * considered invalid, and we can promote writes to that region to 123bf215546Sopenharmony_ci * be unsynchronized writes, avoiding blit copies. 124bf215546Sopenharmony_ci */ 125bf215546Sopenharmony_ci struct util_range valid_buffer_range; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci /** 128bf215546Sopenharmony_ci * Auxiliary buffer information (CCS, MCS, or HiZ). 129bf215546Sopenharmony_ci */ 130bf215546Sopenharmony_ci struct { 131bf215546Sopenharmony_ci /** The surface layout for the auxiliary buffer. */ 132bf215546Sopenharmony_ci struct isl_surf surf; 133bf215546Sopenharmony_ci 134bf215546Sopenharmony_ci /** The buffer object containing the auxiliary data. */ 135bf215546Sopenharmony_ci struct crocus_bo *bo; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci /** Offset into 'bo' where the auxiliary surface starts. */ 138bf215546Sopenharmony_ci uint32_t offset; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci /** 141bf215546Sopenharmony_ci * Fast clear color for this surface. For depth surfaces, the clear 142bf215546Sopenharmony_ci * value is stored as a float32 in the red component. 143bf215546Sopenharmony_ci */ 144bf215546Sopenharmony_ci union isl_color_value clear_color; 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci /** 147bf215546Sopenharmony_ci * \brief The type of auxiliary compression used by this resource. 148bf215546Sopenharmony_ci * 149bf215546Sopenharmony_ci * This describes the type of auxiliary compression that is intended to 150bf215546Sopenharmony_ci * be used by this resource. An aux usage of ISL_AUX_USAGE_NONE means 151bf215546Sopenharmony_ci * that auxiliary compression is permanently disabled. An aux usage 152bf215546Sopenharmony_ci * other than ISL_AUX_USAGE_NONE does not imply that auxiliary 153bf215546Sopenharmony_ci * compression will always be enabled for this surface. 154bf215546Sopenharmony_ci */ 155bf215546Sopenharmony_ci enum isl_aux_usage usage; 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ci /** 158bf215546Sopenharmony_ci * \brief Maps miptree slices to their current aux state. 159bf215546Sopenharmony_ci * 160bf215546Sopenharmony_ci * This two-dimensional array is indexed as [level][layer] and stores an 161bf215546Sopenharmony_ci * aux state for each slice. 162bf215546Sopenharmony_ci */ 163bf215546Sopenharmony_ci enum isl_aux_state **state; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci /** 166bf215546Sopenharmony_ci * If (1 << level) is set, HiZ is enabled for that miplevel. 167bf215546Sopenharmony_ci */ 168bf215546Sopenharmony_ci uint16_t has_hiz; 169bf215546Sopenharmony_ci } aux; 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci /** 172bf215546Sopenharmony_ci * \brief Shadow miptree for sampling when the main isn't supported by HW. 173bf215546Sopenharmony_ci * 174bf215546Sopenharmony_ci * To workaround various sampler bugs and limitations, we blit the main 175bf215546Sopenharmony_ci * texture into a new texture that can be sampled. 176bf215546Sopenharmony_ci * 177bf215546Sopenharmony_ci * This miptree may be used for: 178bf215546Sopenharmony_ci * - Stencil texturing (pre-BDW) as required by GL_ARB_stencil_texturing. 179bf215546Sopenharmony_ci */ 180bf215546Sopenharmony_ci struct crocus_resource *shadow; 181bf215546Sopenharmony_ci bool shadow_needs_update; 182bf215546Sopenharmony_ci 183bf215546Sopenharmony_ci /** 184bf215546Sopenharmony_ci * For external surfaces, this is format that was used to create or import 185bf215546Sopenharmony_ci * the surface. For internal surfaces, this will always be 186bf215546Sopenharmony_ci * PIPE_FORMAT_NONE. 187bf215546Sopenharmony_ci */ 188bf215546Sopenharmony_ci enum pipe_format external_format; 189bf215546Sopenharmony_ci 190bf215546Sopenharmony_ci /** 191bf215546Sopenharmony_ci * For external surfaces, this is DRM format modifier that was used to 192bf215546Sopenharmony_ci * create or import the surface. For internal surfaces, this will always 193bf215546Sopenharmony_ci * be DRM_FORMAT_MOD_INVALID. 194bf215546Sopenharmony_ci */ 195bf215546Sopenharmony_ci const struct isl_drm_modifier_info *mod_info; 196bf215546Sopenharmony_ci 197bf215546Sopenharmony_ci /** 198bf215546Sopenharmony_ci * The screen the resource was originally created with, stored for refcounting. 199bf215546Sopenharmony_ci */ 200bf215546Sopenharmony_ci struct pipe_screen *orig_screen; 201bf215546Sopenharmony_ci}; 202bf215546Sopenharmony_ci 203bf215546Sopenharmony_ci/** 204bf215546Sopenharmony_ci * A simple <resource, offset> tuple for storing a reference to a 205bf215546Sopenharmony_ci * piece of state stored in a GPU buffer object. 206bf215546Sopenharmony_ci */ 207bf215546Sopenharmony_cistruct crocus_state_ref { 208bf215546Sopenharmony_ci struct pipe_resource *res; 209bf215546Sopenharmony_ci uint32_t offset; 210bf215546Sopenharmony_ci}; 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_ci/** 213bf215546Sopenharmony_ci * Gallium CSO for sampler views (texture views). 214bf215546Sopenharmony_ci * 215bf215546Sopenharmony_ci * In addition to the normal pipe_resource, this adds an ISL view 216bf215546Sopenharmony_ci * which may reinterpret the format or restrict levels/layers. 217bf215546Sopenharmony_ci * 218bf215546Sopenharmony_ci * These can also be linear texture buffers. 219bf215546Sopenharmony_ci */ 220bf215546Sopenharmony_cistruct crocus_sampler_view { 221bf215546Sopenharmony_ci struct pipe_sampler_view base; 222bf215546Sopenharmony_ci struct isl_view view; 223bf215546Sopenharmony_ci struct isl_view gather_view; 224bf215546Sopenharmony_ci 225bf215546Sopenharmony_ci enum pipe_swizzle swizzle[4]; 226bf215546Sopenharmony_ci union isl_color_value clear_color; 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci /* A short-cut (not a reference) to the actual resource being viewed. 229bf215546Sopenharmony_ci * Multi-planar (or depth+stencil) images may have multiple resources 230bf215546Sopenharmony_ci * chained together; this skips having to traverse base->texture->*. 231bf215546Sopenharmony_ci */ 232bf215546Sopenharmony_ci struct crocus_resource *res; 233bf215546Sopenharmony_ci}; 234bf215546Sopenharmony_ci 235bf215546Sopenharmony_ci/** 236bf215546Sopenharmony_ci * Image view representation. 237bf215546Sopenharmony_ci */ 238bf215546Sopenharmony_cistruct crocus_image_view { 239bf215546Sopenharmony_ci struct pipe_image_view base; 240bf215546Sopenharmony_ci struct isl_view view; 241bf215546Sopenharmony_ci}; 242bf215546Sopenharmony_ci 243bf215546Sopenharmony_ci/** 244bf215546Sopenharmony_ci * Gallium CSO for surfaces (framebuffer attachments). 245bf215546Sopenharmony_ci * 246bf215546Sopenharmony_ci * A view of a surface that can be bound to a color render target or 247bf215546Sopenharmony_ci * depth/stencil attachment. 248bf215546Sopenharmony_ci */ 249bf215546Sopenharmony_cistruct crocus_surface { 250bf215546Sopenharmony_ci struct pipe_surface base; 251bf215546Sopenharmony_ci struct isl_view view; 252bf215546Sopenharmony_ci struct isl_view read_view; 253bf215546Sopenharmony_ci struct isl_surf surf; 254bf215546Sopenharmony_ci union isl_color_value clear_color; 255bf215546Sopenharmony_ci 256bf215546Sopenharmony_ci struct pipe_resource *align_res; 257bf215546Sopenharmony_ci}; 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci/** 260bf215546Sopenharmony_ci * Transfer object - information about a buffer mapping. 261bf215546Sopenharmony_ci */ 262bf215546Sopenharmony_cistruct crocus_transfer { 263bf215546Sopenharmony_ci struct threaded_transfer base; 264bf215546Sopenharmony_ci struct util_debug_callback *dbg; 265bf215546Sopenharmony_ci void *buffer; 266bf215546Sopenharmony_ci void *ptr; 267bf215546Sopenharmony_ci 268bf215546Sopenharmony_ci /** A linear staging resource for GPU-based copy_region transfers. */ 269bf215546Sopenharmony_ci struct pipe_resource *staging; 270bf215546Sopenharmony_ci struct blorp_context *blorp; 271bf215546Sopenharmony_ci struct crocus_batch *batch; 272bf215546Sopenharmony_ci 273bf215546Sopenharmony_ci bool dest_had_defined_contents; 274bf215546Sopenharmony_ci bool has_swizzling; 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci void (*unmap)(struct crocus_transfer *); 277bf215546Sopenharmony_ci}; 278bf215546Sopenharmony_ci 279bf215546Sopenharmony_ci/** 280bf215546Sopenharmony_ci * Memory Object 281bf215546Sopenharmony_ci */ 282bf215546Sopenharmony_cistruct crocus_memory_object { 283bf215546Sopenharmony_ci struct pipe_memory_object b; 284bf215546Sopenharmony_ci struct crocus_bo *bo; 285bf215546Sopenharmony_ci uint64_t format; 286bf215546Sopenharmony_ci unsigned stride; 287bf215546Sopenharmony_ci}; 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_ci/** 290bf215546Sopenharmony_ci * Unwrap a pipe_resource to get the underlying crocus_bo (for convenience). 291bf215546Sopenharmony_ci */ 292bf215546Sopenharmony_cistatic inline struct crocus_bo * 293bf215546Sopenharmony_cicrocus_resource_bo(struct pipe_resource *p_res) 294bf215546Sopenharmony_ci{ 295bf215546Sopenharmony_ci struct crocus_resource *res = (void *) p_res; 296bf215546Sopenharmony_ci return res->bo; 297bf215546Sopenharmony_ci} 298bf215546Sopenharmony_ci 299bf215546Sopenharmony_cistatic inline uint32_t 300bf215546Sopenharmony_cicrocus_mocs(const struct crocus_bo *bo, 301bf215546Sopenharmony_ci const struct isl_device *dev) 302bf215546Sopenharmony_ci{ 303bf215546Sopenharmony_ci return isl_mocs(dev, 0, bo && crocus_bo_is_external(bo)); 304bf215546Sopenharmony_ci} 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_cistruct crocus_format_info crocus_format_for_usage(const struct intel_device_info *, 307bf215546Sopenharmony_ci enum pipe_format pf, 308bf215546Sopenharmony_ci isl_surf_usage_flags_t usage); 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_cistatic inline struct pipe_resource * 311bf215546Sopenharmony_ci_crocus_resource_get_separate_stencil(struct pipe_resource *p_res) 312bf215546Sopenharmony_ci{ 313bf215546Sopenharmony_ci /* For packed depth-stencil, we treat depth as the primary resource 314bf215546Sopenharmony_ci * and store S8 as the "second plane" resource. 315bf215546Sopenharmony_ci */ 316bf215546Sopenharmony_ci if (p_res->next && p_res->next->format == PIPE_FORMAT_S8_UINT) 317bf215546Sopenharmony_ci return p_res->next; 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci return NULL; 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_ci} 322bf215546Sopenharmony_cistatic inline void 323bf215546Sopenharmony_cicrocus_get_depth_stencil_resources(const struct intel_device_info *devinfo, 324bf215546Sopenharmony_ci struct pipe_resource *res, 325bf215546Sopenharmony_ci struct crocus_resource **out_z, 326bf215546Sopenharmony_ci struct crocus_resource **out_s) 327bf215546Sopenharmony_ci{ 328bf215546Sopenharmony_ci /* gen4/5 only supports packed ds */ 329bf215546Sopenharmony_ci if (devinfo->ver < 6) { 330bf215546Sopenharmony_ci *out_z = (void *)res; 331bf215546Sopenharmony_ci *out_s = (void *)res; 332bf215546Sopenharmony_ci return; 333bf215546Sopenharmony_ci } 334bf215546Sopenharmony_ci 335bf215546Sopenharmony_ci if (res && res->format != PIPE_FORMAT_S8_UINT) { 336bf215546Sopenharmony_ci *out_z = (void *) res; 337bf215546Sopenharmony_ci *out_s = (void *) _crocus_resource_get_separate_stencil(res); 338bf215546Sopenharmony_ci } else { 339bf215546Sopenharmony_ci *out_z = NULL; 340bf215546Sopenharmony_ci *out_s = (void *) res; 341bf215546Sopenharmony_ci } 342bf215546Sopenharmony_ci} 343bf215546Sopenharmony_ci 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_cibool crocus_resource_set_clear_color(struct crocus_context *ice, 346bf215546Sopenharmony_ci struct crocus_resource *res, 347bf215546Sopenharmony_ci union isl_color_value color); 348bf215546Sopenharmony_ciunion isl_color_value 349bf215546Sopenharmony_cicrocus_resource_get_clear_color(const struct crocus_resource *res); 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_civoid 352bf215546Sopenharmony_cicrocus_replace_buffer_storage(struct pipe_context *ctx, 353bf215546Sopenharmony_ci struct pipe_resource *p_dst, 354bf215546Sopenharmony_ci struct pipe_resource *p_src, 355bf215546Sopenharmony_ci unsigned num_rebinds, 356bf215546Sopenharmony_ci uint32_t rebind_mask, 357bf215546Sopenharmony_ci uint32_t delete_buffer_id); 358bf215546Sopenharmony_ci 359bf215546Sopenharmony_civoid crocus_init_screen_resource_functions(struct pipe_screen *pscreen); 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_civoid crocus_dirty_for_history(struct crocus_context *ice, 362bf215546Sopenharmony_ci struct crocus_resource *res); 363bf215546Sopenharmony_ciuint32_t crocus_flush_bits_for_history(struct crocus_resource *res); 364bf215546Sopenharmony_ci 365bf215546Sopenharmony_civoid crocus_flush_and_dirty_for_history(struct crocus_context *ice, 366bf215546Sopenharmony_ci struct crocus_batch *batch, 367bf215546Sopenharmony_ci struct crocus_resource *res, 368bf215546Sopenharmony_ci uint32_t extra_flags, 369bf215546Sopenharmony_ci const char *reason); 370bf215546Sopenharmony_ci 371bf215546Sopenharmony_ciunsigned crocus_get_num_logical_layers(const struct crocus_resource *res, 372bf215546Sopenharmony_ci unsigned level); 373bf215546Sopenharmony_ci 374bf215546Sopenharmony_civoid crocus_resource_disable_aux(struct crocus_resource *res); 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci#define INTEL_REMAINING_LAYERS UINT32_MAX 377bf215546Sopenharmony_ci#define INTEL_REMAINING_LEVELS UINT32_MAX 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_civoid 380bf215546Sopenharmony_cicrocus_hiz_exec(struct crocus_context *ice, 381bf215546Sopenharmony_ci struct crocus_batch *batch, 382bf215546Sopenharmony_ci struct crocus_resource *res, 383bf215546Sopenharmony_ci unsigned int level, unsigned int start_layer, 384bf215546Sopenharmony_ci unsigned int num_layers, enum isl_aux_op op, 385bf215546Sopenharmony_ci bool update_clear_depth); 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_ci/** 388bf215546Sopenharmony_ci * Prepare a miptree for access 389bf215546Sopenharmony_ci * 390bf215546Sopenharmony_ci * This function should be called prior to any access to miptree in order to 391bf215546Sopenharmony_ci * perform any needed resolves. 392bf215546Sopenharmony_ci * 393bf215546Sopenharmony_ci * \param[in] start_level The first mip level to be accessed 394bf215546Sopenharmony_ci * 395bf215546Sopenharmony_ci * \param[in] num_levels The number of miplevels to be accessed or 396bf215546Sopenharmony_ci * INTEL_REMAINING_LEVELS to indicate every level 397bf215546Sopenharmony_ci * above start_level will be accessed 398bf215546Sopenharmony_ci * 399bf215546Sopenharmony_ci * \param[in] start_layer The first array slice or 3D layer to be accessed 400bf215546Sopenharmony_ci * 401bf215546Sopenharmony_ci * \param[in] num_layers The number of array slices or 3D layers be 402bf215546Sopenharmony_ci * accessed or INTEL_REMAINING_LAYERS to indicate 403bf215546Sopenharmony_ci * every layer above start_layer will be accessed 404bf215546Sopenharmony_ci * 405bf215546Sopenharmony_ci * \param[in] aux_supported Whether or not the access will support the 406bf215546Sopenharmony_ci * miptree's auxiliary compression format; this 407bf215546Sopenharmony_ci * must be false for uncompressed miptrees 408bf215546Sopenharmony_ci * 409bf215546Sopenharmony_ci * \param[in] fast_clear_supported Whether or not the access will support 410bf215546Sopenharmony_ci * fast clears in the miptree's auxiliary 411bf215546Sopenharmony_ci * compression format 412bf215546Sopenharmony_ci */ 413bf215546Sopenharmony_civoid 414bf215546Sopenharmony_cicrocus_resource_prepare_access(struct crocus_context *ice, 415bf215546Sopenharmony_ci struct crocus_resource *res, 416bf215546Sopenharmony_ci uint32_t start_level, uint32_t num_levels, 417bf215546Sopenharmony_ci uint32_t start_layer, uint32_t num_layers, 418bf215546Sopenharmony_ci enum isl_aux_usage aux_usage, 419bf215546Sopenharmony_ci bool fast_clear_supported); 420bf215546Sopenharmony_ci 421bf215546Sopenharmony_ci/** 422bf215546Sopenharmony_ci * Complete a write operation 423bf215546Sopenharmony_ci * 424bf215546Sopenharmony_ci * This function should be called after any operation writes to a miptree. 425bf215546Sopenharmony_ci * This will update the miptree's compression state so that future resolves 426bf215546Sopenharmony_ci * happen correctly. Technically, this function can be called before the 427bf215546Sopenharmony_ci * write occurs but the caller must ensure that they don't interlace 428bf215546Sopenharmony_ci * crocus_resource_prepare_access and crocus_resource_finish_write calls to 429bf215546Sopenharmony_ci * overlapping layer/level ranges. 430bf215546Sopenharmony_ci * 431bf215546Sopenharmony_ci * \param[in] level The mip level that was written 432bf215546Sopenharmony_ci * 433bf215546Sopenharmony_ci * \param[in] start_layer The first array slice or 3D layer written 434bf215546Sopenharmony_ci * 435bf215546Sopenharmony_ci * \param[in] num_layers The number of array slices or 3D layers 436bf215546Sopenharmony_ci * written or INTEL_REMAINING_LAYERS to indicate 437bf215546Sopenharmony_ci * every layer above start_layer was written 438bf215546Sopenharmony_ci * 439bf215546Sopenharmony_ci * \param[in] written_with_aux Whether or not the write was done with 440bf215546Sopenharmony_ci * auxiliary compression enabled 441bf215546Sopenharmony_ci */ 442bf215546Sopenharmony_civoid 443bf215546Sopenharmony_cicrocus_resource_finish_write(struct crocus_context *ice, 444bf215546Sopenharmony_ci struct crocus_resource *res, uint32_t level, 445bf215546Sopenharmony_ci uint32_t start_layer, uint32_t num_layers, 446bf215546Sopenharmony_ci enum isl_aux_usage aux_usage); 447bf215546Sopenharmony_ci 448bf215546Sopenharmony_ci/** Get the auxiliary compression state of a miptree slice */ 449bf215546Sopenharmony_cienum isl_aux_state 450bf215546Sopenharmony_cicrocus_resource_get_aux_state(const struct crocus_resource *res, 451bf215546Sopenharmony_ci uint32_t level, uint32_t layer); 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci/** 454bf215546Sopenharmony_ci * Set the auxiliary compression state of a miptree slice range 455bf215546Sopenharmony_ci * 456bf215546Sopenharmony_ci * This function directly sets the auxiliary compression state of a slice 457bf215546Sopenharmony_ci * range of a miptree. It only modifies data structures and does not do any 458bf215546Sopenharmony_ci * resolves. This should only be called by code which directly performs 459bf215546Sopenharmony_ci * compression operations such as fast clears and resolves. Most code should 460bf215546Sopenharmony_ci * use crocus_resource_prepare_access or crocus_resource_finish_write. 461bf215546Sopenharmony_ci */ 462bf215546Sopenharmony_civoid 463bf215546Sopenharmony_cicrocus_resource_set_aux_state(struct crocus_context *ice, 464bf215546Sopenharmony_ci struct crocus_resource *res, uint32_t level, 465bf215546Sopenharmony_ci uint32_t start_layer, uint32_t num_layers, 466bf215546Sopenharmony_ci enum isl_aux_state aux_state); 467bf215546Sopenharmony_ci 468bf215546Sopenharmony_ci/** 469bf215546Sopenharmony_ci * Prepare a miptree for raw access 470bf215546Sopenharmony_ci * 471bf215546Sopenharmony_ci * This helper prepares the miptree for access that knows nothing about any 472bf215546Sopenharmony_ci * sort of compression whatsoever. This is useful when mapping the surface or 473bf215546Sopenharmony_ci * using it with the blitter. 474bf215546Sopenharmony_ci */ 475bf215546Sopenharmony_cistatic inline void 476bf215546Sopenharmony_cicrocus_resource_access_raw(struct crocus_context *ice, 477bf215546Sopenharmony_ci struct crocus_resource *res, 478bf215546Sopenharmony_ci uint32_t level, uint32_t layer, 479bf215546Sopenharmony_ci uint32_t num_layers, 480bf215546Sopenharmony_ci bool write) 481bf215546Sopenharmony_ci{ 482bf215546Sopenharmony_ci crocus_resource_prepare_access(ice, res, level, 1, layer, num_layers, 483bf215546Sopenharmony_ci ISL_AUX_USAGE_NONE, false); 484bf215546Sopenharmony_ci if (write) { 485bf215546Sopenharmony_ci crocus_resource_finish_write(ice, res, level, layer, num_layers, 486bf215546Sopenharmony_ci ISL_AUX_USAGE_NONE); 487bf215546Sopenharmony_ci } 488bf215546Sopenharmony_ci} 489bf215546Sopenharmony_ci 490bf215546Sopenharmony_civoid 491bf215546Sopenharmony_cicrocus_resource_get_image_offset(struct crocus_resource *res, 492bf215546Sopenharmony_ci uint32_t level, uint32_t z, 493bf215546Sopenharmony_ci uint32_t *x, uint32_t *y); 494bf215546Sopenharmony_cistatic inline enum isl_aux_usage 495bf215546Sopenharmony_cicrocus_resource_texture_aux_usage(const struct crocus_resource *res) 496bf215546Sopenharmony_ci{ 497bf215546Sopenharmony_ci return res->aux.usage == ISL_AUX_USAGE_MCS ? ISL_AUX_USAGE_MCS : ISL_AUX_USAGE_NONE; 498bf215546Sopenharmony_ci} 499bf215546Sopenharmony_ci 500bf215546Sopenharmony_civoid crocus_resource_prepare_texture(struct crocus_context *ice, 501bf215546Sopenharmony_ci struct crocus_resource *res, 502bf215546Sopenharmony_ci enum isl_format view_format, 503bf215546Sopenharmony_ci uint32_t start_level, uint32_t num_levels, 504bf215546Sopenharmony_ci uint32_t start_layer, uint32_t num_layers); 505bf215546Sopenharmony_ci 506bf215546Sopenharmony_cistatic inline bool 507bf215546Sopenharmony_cicrocus_resource_unfinished_aux_import(struct crocus_resource *res) 508bf215546Sopenharmony_ci{ 509bf215546Sopenharmony_ci return res->base.b.next != NULL && res->mod_info && 510bf215546Sopenharmony_ci res->mod_info->aux_usage != ISL_AUX_USAGE_NONE; 511bf215546Sopenharmony_ci} 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_civoid crocus_resource_finish_aux_import(struct pipe_screen *pscreen, 514bf215546Sopenharmony_ci struct crocus_resource *res); 515bf215546Sopenharmony_ci 516bf215546Sopenharmony_cibool crocus_has_invalid_primary(const struct crocus_resource *res, 517bf215546Sopenharmony_ci unsigned start_level, unsigned num_levels, 518bf215546Sopenharmony_ci unsigned start_layer, unsigned num_layers); 519bf215546Sopenharmony_ci 520bf215546Sopenharmony_civoid crocus_resource_check_level_layer(const struct crocus_resource *res, 521bf215546Sopenharmony_ci uint32_t level, uint32_t layer); 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_cibool crocus_resource_level_has_hiz(const struct crocus_resource *res, 524bf215546Sopenharmony_ci uint32_t level); 525bf215546Sopenharmony_cibool crocus_has_color_unresolved(const struct crocus_resource *res, 526bf215546Sopenharmony_ci unsigned start_level, unsigned num_levels, 527bf215546Sopenharmony_ci unsigned start_layer, unsigned num_layers); 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_cienum isl_aux_usage crocus_resource_render_aux_usage(struct crocus_context *ice, 530bf215546Sopenharmony_ci struct crocus_resource *res, 531bf215546Sopenharmony_ci uint32_t level, 532bf215546Sopenharmony_ci enum isl_format render_fmt, 533bf215546Sopenharmony_ci bool draw_aux_disabled); 534bf215546Sopenharmony_civoid crocus_resource_prepare_render(struct crocus_context *ice, 535bf215546Sopenharmony_ci struct crocus_resource *res, uint32_t level, 536bf215546Sopenharmony_ci uint32_t start_layer, uint32_t layer_count, 537bf215546Sopenharmony_ci enum isl_aux_usage aux_usage); 538bf215546Sopenharmony_civoid crocus_resource_finish_render(struct crocus_context *ice, 539bf215546Sopenharmony_ci struct crocus_resource *res, uint32_t level, 540bf215546Sopenharmony_ci uint32_t start_layer, uint32_t layer_count, 541bf215546Sopenharmony_ci enum isl_aux_usage aux_usage); 542bf215546Sopenharmony_ci#endif 543