1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2013 Advanced Micro Devices, Inc. 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 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * 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 NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci * Authors: Marek Olšák <maraeo@gmail.com> 24bf215546Sopenharmony_ci * 25bf215546Sopenharmony_ci */ 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci/** 28bf215546Sopenharmony_ci * This file contains common screen and context structures and functions 29bf215546Sopenharmony_ci * for r600g and radeonsi. 30bf215546Sopenharmony_ci */ 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#ifndef R600_PIPE_COMMON_H 33bf215546Sopenharmony_ci#define R600_PIPE_COMMON_H 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci#include <stdio.h> 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci#include "winsys/radeon_winsys.h" 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include "util/disk_cache.h" 40bf215546Sopenharmony_ci#include "util/u_blitter.h" 41bf215546Sopenharmony_ci#include "util/list.h" 42bf215546Sopenharmony_ci#include "util/u_range.h" 43bf215546Sopenharmony_ci#include "util/slab.h" 44bf215546Sopenharmony_ci#include "util/u_suballoc.h" 45bf215546Sopenharmony_ci#include "util/u_transfer.h" 46bf215546Sopenharmony_ci#include "util/u_threaded_context.h" 47bf215546Sopenharmony_ci 48bf215546Sopenharmony_ci#include "compiler/nir/nir.h" 49bf215546Sopenharmony_ci 50bf215546Sopenharmony_cistruct u_log_context; 51bf215546Sopenharmony_ci#define ATI_VENDOR_ID 0x1002 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci#define R600_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0) 54bf215546Sopenharmony_ci#define R600_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1) 55bf215546Sopenharmony_ci#define R600_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2) 56bf215546Sopenharmony_ci#define R600_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4) 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci#define R600_CONTEXT_STREAMOUT_FLUSH (1u << 0) 59bf215546Sopenharmony_ci/* Pipeline & streamout query controls. */ 60bf215546Sopenharmony_ci#define R600_CONTEXT_START_PIPELINE_STATS (1u << 1) 61bf215546Sopenharmony_ci#define R600_CONTEXT_STOP_PIPELINE_STATS (1u << 2) 62bf215546Sopenharmony_ci#define R600_CONTEXT_FLUSH_FOR_RENDER_COND (1u << 3) 63bf215546Sopenharmony_ci#define R600_CONTEXT_PRIVATE_FLAG (1u << 4) 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci/* special primitive types */ 66bf215546Sopenharmony_ci#define R600_PRIM_RECTANGLE_LIST PIPE_PRIM_MAX 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci#define R600_NOT_QUERY 0xffffffff 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci/* Debug flags. */ 71bf215546Sopenharmony_ci#define DBG_VS (1 << PIPE_SHADER_VERTEX) 72bf215546Sopenharmony_ci#define DBG_PS (1 << PIPE_SHADER_FRAGMENT) 73bf215546Sopenharmony_ci#define DBG_GS (1 << PIPE_SHADER_GEOMETRY) 74bf215546Sopenharmony_ci#define DBG_TCS (1 << PIPE_SHADER_TESS_CTRL) 75bf215546Sopenharmony_ci#define DBG_TES (1 << PIPE_SHADER_TESS_EVAL) 76bf215546Sopenharmony_ci#define DBG_CS (1 << PIPE_SHADER_COMPUTE) 77bf215546Sopenharmony_ci#define DBG_ALL_SHADERS (DBG_FS - 1) 78bf215546Sopenharmony_ci#define DBG_FS (1 << 6) /* fetch shader */ 79bf215546Sopenharmony_ci#define DBG_TEX (1 << 7) 80bf215546Sopenharmony_ci#define DBG_NIR (1 << 8) 81bf215546Sopenharmony_ci#define DBG_COMPUTE (1 << 9) 82bf215546Sopenharmony_ci/* gap */ 83bf215546Sopenharmony_ci#define DBG_VM (1 << 11) 84bf215546Sopenharmony_ci#define DBG_PREOPT_IR (1 << 15) 85bf215546Sopenharmony_ci#define DBG_CHECK_IR (1 << 16) 86bf215546Sopenharmony_ci/* gaps */ 87bf215546Sopenharmony_ci#define DBG_TEST_DMA (1 << 20) 88bf215546Sopenharmony_ci/* Bits 21-31 are reserved for the r600g driver. */ 89bf215546Sopenharmony_ci/* features */ 90bf215546Sopenharmony_ci#define DBG_NO_ASYNC_DMA (1ull << 32) 91bf215546Sopenharmony_ci#define DBG_NO_HYPERZ (1ull << 33) 92bf215546Sopenharmony_ci#define DBG_NO_DISCARD_RANGE (1ull << 34) 93bf215546Sopenharmony_ci#define DBG_NO_2D_TILING (1ull << 35) 94bf215546Sopenharmony_ci#define DBG_NO_TILING (1ull << 36) 95bf215546Sopenharmony_ci#define DBG_SWITCH_ON_EOP (1ull << 37) 96bf215546Sopenharmony_ci#define DBG_FORCE_DMA (1ull << 38) 97bf215546Sopenharmony_ci#define DBG_INFO (1ull << 40) 98bf215546Sopenharmony_ci#define DBG_NO_WC (1ull << 41) 99bf215546Sopenharmony_ci#define DBG_CHECK_VM (1ull << 42) 100bf215546Sopenharmony_ci/* gap */ 101bf215546Sopenharmony_ci#define DBG_TEST_VMFAULT_CP (1ull << 51) 102bf215546Sopenharmony_ci#define DBG_TEST_VMFAULT_SDMA (1ull << 52) 103bf215546Sopenharmony_ci#define DBG_TEST_VMFAULT_SHADER (1ull << 53) 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci#define R600_MAP_BUFFER_ALIGNMENT 64 106bf215546Sopenharmony_ci#define R600_MAX_VIEWPORTS 16 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_ci#define SI_MAX_VARIABLE_THREADS_PER_BLOCK 1024 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_cienum r600_coherency { 111bf215546Sopenharmony_ci R600_COHERENCY_NONE, /* no cache flushes needed */ 112bf215546Sopenharmony_ci R600_COHERENCY_SHADER, 113bf215546Sopenharmony_ci R600_COHERENCY_CB_META, 114bf215546Sopenharmony_ci}; 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci#if UTIL_ARCH_BIG_ENDIAN 117bf215546Sopenharmony_ci#define R600_BIG_ENDIAN 1 118bf215546Sopenharmony_ci#else 119bf215546Sopenharmony_ci#define R600_BIG_ENDIAN 0 120bf215546Sopenharmony_ci#endif 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_cistruct r600_common_context; 123bf215546Sopenharmony_cistruct r600_perfcounters; 124bf215546Sopenharmony_cistruct tgsi_shader_info; 125bf215546Sopenharmony_cistruct r600_qbo_state; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci/* Only 32-bit buffer allocations are supported, gallium doesn't support more 128bf215546Sopenharmony_ci * at the moment. 129bf215546Sopenharmony_ci */ 130bf215546Sopenharmony_cistruct r600_resource { 131bf215546Sopenharmony_ci struct threaded_resource b; 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci /* Winsys objects. */ 134bf215546Sopenharmony_ci struct pb_buffer *buf; 135bf215546Sopenharmony_ci uint64_t gpu_address; 136bf215546Sopenharmony_ci /* Memory usage if the buffer placement is optimal. */ 137bf215546Sopenharmony_ci uint64_t vram_usage; 138bf215546Sopenharmony_ci uint64_t gart_usage; 139bf215546Sopenharmony_ci 140bf215546Sopenharmony_ci /* Resource properties. */ 141bf215546Sopenharmony_ci uint64_t bo_size; 142bf215546Sopenharmony_ci unsigned bo_alignment; 143bf215546Sopenharmony_ci enum radeon_bo_domain domains; 144bf215546Sopenharmony_ci enum radeon_bo_flag flags; 145bf215546Sopenharmony_ci unsigned bind_history; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci /* The buffer range which is initialized (with a write transfer, 148bf215546Sopenharmony_ci * streamout, DMA, or as a random access target). The rest of 149bf215546Sopenharmony_ci * the buffer is considered invalid and can be mapped unsynchronized. 150bf215546Sopenharmony_ci * 151bf215546Sopenharmony_ci * This allows unsychronized mapping of a buffer range which hasn't 152bf215546Sopenharmony_ci * been used yet. It's for applications which forget to use 153bf215546Sopenharmony_ci * the unsynchronized map flag and expect the driver to figure it out. 154bf215546Sopenharmony_ci */ 155bf215546Sopenharmony_ci struct util_range valid_buffer_range; 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ci /* Whether the resource has been exported via resource_get_handle. */ 158bf215546Sopenharmony_ci unsigned external_usage; /* PIPE_HANDLE_USAGE_* */ 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci /* Whether this resource is referenced by bindless handles. */ 161bf215546Sopenharmony_ci bool texture_handle_allocated; 162bf215546Sopenharmony_ci bool image_handle_allocated; 163bf215546Sopenharmony_ci bool compute_global_bo; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci /* 166bf215546Sopenharmony_ci * EG/Cayman only - for RAT operations hw need an immediate buffer 167bf215546Sopenharmony_ci * to store results in. 168bf215546Sopenharmony_ci */ 169bf215546Sopenharmony_ci struct r600_resource *immed_buffer; 170bf215546Sopenharmony_ci}; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_cistruct r600_transfer { 173bf215546Sopenharmony_ci struct threaded_transfer b; 174bf215546Sopenharmony_ci struct r600_resource *staging; 175bf215546Sopenharmony_ci}; 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_cistruct r600_fmask_info { 178bf215546Sopenharmony_ci uint64_t offset; 179bf215546Sopenharmony_ci uint64_t size; 180bf215546Sopenharmony_ci unsigned alignment; 181bf215546Sopenharmony_ci unsigned pitch_in_pixels; 182bf215546Sopenharmony_ci unsigned bank_height; 183bf215546Sopenharmony_ci unsigned slice_tile_max; 184bf215546Sopenharmony_ci unsigned tile_mode_index; 185bf215546Sopenharmony_ci unsigned tile_swizzle; 186bf215546Sopenharmony_ci}; 187bf215546Sopenharmony_ci 188bf215546Sopenharmony_cistruct r600_cmask_info { 189bf215546Sopenharmony_ci uint64_t offset; 190bf215546Sopenharmony_ci uint64_t size; 191bf215546Sopenharmony_ci unsigned alignment; 192bf215546Sopenharmony_ci unsigned slice_tile_max; 193bf215546Sopenharmony_ci uint64_t base_address_reg; 194bf215546Sopenharmony_ci}; 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_cistruct r600_texture { 197bf215546Sopenharmony_ci struct r600_resource resource; 198bf215546Sopenharmony_ci 199bf215546Sopenharmony_ci uint64_t size; 200bf215546Sopenharmony_ci unsigned num_level0_transfers; 201bf215546Sopenharmony_ci enum pipe_format db_render_format; 202bf215546Sopenharmony_ci bool is_depth; 203bf215546Sopenharmony_ci bool db_compatible; 204bf215546Sopenharmony_ci bool can_sample_z; 205bf215546Sopenharmony_ci bool can_sample_s; 206bf215546Sopenharmony_ci unsigned dirty_level_mask; /* each bit says if that mipmap is compressed */ 207bf215546Sopenharmony_ci unsigned stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */ 208bf215546Sopenharmony_ci struct r600_texture *flushed_depth_texture; 209bf215546Sopenharmony_ci struct radeon_surf surface; 210bf215546Sopenharmony_ci 211bf215546Sopenharmony_ci /* Colorbuffer compression and fast clear. */ 212bf215546Sopenharmony_ci struct r600_fmask_info fmask; 213bf215546Sopenharmony_ci struct r600_cmask_info cmask; 214bf215546Sopenharmony_ci struct r600_resource *cmask_buffer; 215bf215546Sopenharmony_ci unsigned cb_color_info; /* fast clear enable bit */ 216bf215546Sopenharmony_ci unsigned color_clear_value[2]; 217bf215546Sopenharmony_ci unsigned last_msaa_resolve_target_micro_mode; 218bf215546Sopenharmony_ci 219bf215546Sopenharmony_ci /* Depth buffer compression and fast clear. */ 220bf215546Sopenharmony_ci uint64_t htile_offset; 221bf215546Sopenharmony_ci bool depth_cleared; /* if it was cleared at least once */ 222bf215546Sopenharmony_ci float depth_clear_value; 223bf215546Sopenharmony_ci bool stencil_cleared; /* if it was cleared at least once */ 224bf215546Sopenharmony_ci uint8_t stencil_clear_value; 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci bool non_disp_tiling; /* R600-Cayman only */ 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci /* Counter that should be non-zero if the texture is bound to a 229bf215546Sopenharmony_ci * framebuffer. Implemented in radeonsi only. 230bf215546Sopenharmony_ci */ 231bf215546Sopenharmony_ci uint32_t framebuffers_bound; 232bf215546Sopenharmony_ci}; 233bf215546Sopenharmony_ci 234bf215546Sopenharmony_cistruct r600_surface { 235bf215546Sopenharmony_ci struct pipe_surface base; 236bf215546Sopenharmony_ci 237bf215546Sopenharmony_ci /* These can vary with block-compressed textures. */ 238bf215546Sopenharmony_ci unsigned width0; 239bf215546Sopenharmony_ci unsigned height0; 240bf215546Sopenharmony_ci 241bf215546Sopenharmony_ci bool color_initialized; 242bf215546Sopenharmony_ci bool depth_initialized; 243bf215546Sopenharmony_ci 244bf215546Sopenharmony_ci /* Misc. color flags. */ 245bf215546Sopenharmony_ci bool alphatest_bypass; 246bf215546Sopenharmony_ci bool export_16bpc; 247bf215546Sopenharmony_ci bool color_is_int8; 248bf215546Sopenharmony_ci bool color_is_int10; 249bf215546Sopenharmony_ci 250bf215546Sopenharmony_ci /* Color registers. */ 251bf215546Sopenharmony_ci unsigned cb_color_info; 252bf215546Sopenharmony_ci unsigned cb_color_base; 253bf215546Sopenharmony_ci unsigned cb_color_view; 254bf215546Sopenharmony_ci unsigned cb_color_size; /* R600 only */ 255bf215546Sopenharmony_ci unsigned cb_color_dim; /* EG only */ 256bf215546Sopenharmony_ci unsigned cb_color_pitch; /* EG and later */ 257bf215546Sopenharmony_ci unsigned cb_color_slice; /* EG and later */ 258bf215546Sopenharmony_ci unsigned cb_color_attrib; /* EG and later */ 259bf215546Sopenharmony_ci unsigned cb_color_fmask; /* CB_COLORn_FMASK (EG and later) or CB_COLORn_FRAG (r600) */ 260bf215546Sopenharmony_ci unsigned cb_color_fmask_slice; /* EG and later */ 261bf215546Sopenharmony_ci unsigned cb_color_cmask; /* CB_COLORn_TILE (r600 only) */ 262bf215546Sopenharmony_ci unsigned cb_color_mask; /* R600 only */ 263bf215546Sopenharmony_ci struct r600_resource *cb_buffer_fmask; /* Used for FMASK relocations. R600 only */ 264bf215546Sopenharmony_ci struct r600_resource *cb_buffer_cmask; /* Used for CMASK relocations. R600 only */ 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci /* DB registers. */ 267bf215546Sopenharmony_ci uint64_t db_depth_base; /* DB_Z_READ/WRITE_BASE (EG and later) or DB_DEPTH_BASE (r600) */ 268bf215546Sopenharmony_ci uint64_t db_stencil_base; /* EG and later */ 269bf215546Sopenharmony_ci uint64_t db_htile_data_base; 270bf215546Sopenharmony_ci unsigned db_depth_info; /* R600 only, then SI and later */ 271bf215546Sopenharmony_ci unsigned db_z_info; /* EG and later */ 272bf215546Sopenharmony_ci unsigned db_depth_view; 273bf215546Sopenharmony_ci unsigned db_depth_size; 274bf215546Sopenharmony_ci unsigned db_depth_slice; /* EG and later */ 275bf215546Sopenharmony_ci unsigned db_stencil_info; /* EG and later */ 276bf215546Sopenharmony_ci unsigned db_prefetch_limit; /* R600 only */ 277bf215546Sopenharmony_ci unsigned db_htile_surface; 278bf215546Sopenharmony_ci unsigned db_preload_control; /* EG and later */ 279bf215546Sopenharmony_ci}; 280bf215546Sopenharmony_ci 281bf215546Sopenharmony_cistruct r600_mmio_counter { 282bf215546Sopenharmony_ci unsigned busy; 283bf215546Sopenharmony_ci unsigned idle; 284bf215546Sopenharmony_ci}; 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ciunion r600_mmio_counters { 287bf215546Sopenharmony_ci struct r600_mmio_counters_named { 288bf215546Sopenharmony_ci /* For global GPU load including SDMA. */ 289bf215546Sopenharmony_ci struct r600_mmio_counter gpu; 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci /* GRBM_STATUS */ 292bf215546Sopenharmony_ci struct r600_mmio_counter spi; 293bf215546Sopenharmony_ci struct r600_mmio_counter gui; 294bf215546Sopenharmony_ci struct r600_mmio_counter ta; 295bf215546Sopenharmony_ci struct r600_mmio_counter gds; 296bf215546Sopenharmony_ci struct r600_mmio_counter vgt; 297bf215546Sopenharmony_ci struct r600_mmio_counter ia; 298bf215546Sopenharmony_ci struct r600_mmio_counter sx; 299bf215546Sopenharmony_ci struct r600_mmio_counter wd; 300bf215546Sopenharmony_ci struct r600_mmio_counter bci; 301bf215546Sopenharmony_ci struct r600_mmio_counter sc; 302bf215546Sopenharmony_ci struct r600_mmio_counter pa; 303bf215546Sopenharmony_ci struct r600_mmio_counter db; 304bf215546Sopenharmony_ci struct r600_mmio_counter cp; 305bf215546Sopenharmony_ci struct r600_mmio_counter cb; 306bf215546Sopenharmony_ci 307bf215546Sopenharmony_ci /* SRBM_STATUS2 */ 308bf215546Sopenharmony_ci struct r600_mmio_counter sdma; 309bf215546Sopenharmony_ci 310bf215546Sopenharmony_ci /* CP_STAT */ 311bf215546Sopenharmony_ci struct r600_mmio_counter pfp; 312bf215546Sopenharmony_ci struct r600_mmio_counter meq; 313bf215546Sopenharmony_ci struct r600_mmio_counter me; 314bf215546Sopenharmony_ci struct r600_mmio_counter surf_sync; 315bf215546Sopenharmony_ci struct r600_mmio_counter cp_dma; 316bf215546Sopenharmony_ci struct r600_mmio_counter scratch_ram; 317bf215546Sopenharmony_ci } named; 318bf215546Sopenharmony_ci unsigned array[sizeof(struct r600_mmio_counters_named) / sizeof(unsigned)]; 319bf215546Sopenharmony_ci}; 320bf215546Sopenharmony_ci 321bf215546Sopenharmony_cistruct r600_memory_object { 322bf215546Sopenharmony_ci struct pipe_memory_object b; 323bf215546Sopenharmony_ci struct pb_buffer *buf; 324bf215546Sopenharmony_ci uint32_t stride; 325bf215546Sopenharmony_ci uint32_t offset; 326bf215546Sopenharmony_ci}; 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_cistruct r600_common_screen { 329bf215546Sopenharmony_ci struct pipe_screen b; 330bf215546Sopenharmony_ci struct radeon_winsys *ws; 331bf215546Sopenharmony_ci enum radeon_family family; 332bf215546Sopenharmony_ci enum amd_gfx_level gfx_level; 333bf215546Sopenharmony_ci struct radeon_info info; 334bf215546Sopenharmony_ci uint64_t debug_flags; 335bf215546Sopenharmony_ci bool has_cp_dma; 336bf215546Sopenharmony_ci bool has_streamout; 337bf215546Sopenharmony_ci 338bf215546Sopenharmony_ci struct disk_cache *disk_shader_cache; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci struct slab_parent_pool pool_transfers; 341bf215546Sopenharmony_ci 342bf215546Sopenharmony_ci /* Texture filter settings. */ 343bf215546Sopenharmony_ci int force_aniso; /* -1 = disabled */ 344bf215546Sopenharmony_ci 345bf215546Sopenharmony_ci /* Auxiliary context. Mainly used to initialize resources. 346bf215546Sopenharmony_ci * It must be locked prior to using and flushed before unlocking. */ 347bf215546Sopenharmony_ci struct pipe_context *aux_context; 348bf215546Sopenharmony_ci mtx_t aux_context_lock; 349bf215546Sopenharmony_ci 350bf215546Sopenharmony_ci /* This must be in the screen, because UE4 uses one context for 351bf215546Sopenharmony_ci * compilation and another one for rendering. 352bf215546Sopenharmony_ci */ 353bf215546Sopenharmony_ci unsigned num_compilations; 354bf215546Sopenharmony_ci /* Along with ST_DEBUG=precompile, this should show if applications 355bf215546Sopenharmony_ci * are loading shaders on demand. This is a monotonic counter. 356bf215546Sopenharmony_ci */ 357bf215546Sopenharmony_ci unsigned num_shaders_created; 358bf215546Sopenharmony_ci unsigned num_shader_cache_hits; 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci /* GPU load thread. */ 361bf215546Sopenharmony_ci mtx_t gpu_load_mutex; 362bf215546Sopenharmony_ci thrd_t gpu_load_thread; 363bf215546Sopenharmony_ci bool gpu_load_thread_created; 364bf215546Sopenharmony_ci union r600_mmio_counters mmio_counters; 365bf215546Sopenharmony_ci volatile unsigned gpu_load_stop_thread; /* bool */ 366bf215546Sopenharmony_ci 367bf215546Sopenharmony_ci char renderer_string[100]; 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci /* Performance counters. */ 370bf215546Sopenharmony_ci struct r600_perfcounters *perfcounters; 371bf215546Sopenharmony_ci 372bf215546Sopenharmony_ci /* If pipe_screen wants to recompute and re-emit the framebuffer, 373bf215546Sopenharmony_ci * sampler, and image states of all contexts, it should atomically 374bf215546Sopenharmony_ci * increment this. 375bf215546Sopenharmony_ci * 376bf215546Sopenharmony_ci * Each context will compare this with its own last known value of 377bf215546Sopenharmony_ci * the counter before drawing and re-emit the states accordingly. 378bf215546Sopenharmony_ci */ 379bf215546Sopenharmony_ci unsigned dirty_tex_counter; 380bf215546Sopenharmony_ci 381bf215546Sopenharmony_ci /* Atomically increment this counter when an existing texture's 382bf215546Sopenharmony_ci * metadata is enabled or disabled in a way that requires changing 383bf215546Sopenharmony_ci * contexts' compressed texture binding masks. 384bf215546Sopenharmony_ci */ 385bf215546Sopenharmony_ci unsigned compressed_colortex_counter; 386bf215546Sopenharmony_ci 387bf215546Sopenharmony_ci struct { 388bf215546Sopenharmony_ci /* Context flags to set so that all writes from earlier jobs 389bf215546Sopenharmony_ci * in the CP are seen by L2 clients. 390bf215546Sopenharmony_ci */ 391bf215546Sopenharmony_ci unsigned cp_to_L2; 392bf215546Sopenharmony_ci 393bf215546Sopenharmony_ci /* Context flags to set so that all writes from earlier jobs 394bf215546Sopenharmony_ci * that end in L2 are seen by CP. 395bf215546Sopenharmony_ci */ 396bf215546Sopenharmony_ci unsigned L2_to_cp; 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_ci /* Context flags to set so that all writes from earlier 399bf215546Sopenharmony_ci * compute jobs are seen by L2 clients. 400bf215546Sopenharmony_ci */ 401bf215546Sopenharmony_ci unsigned compute_to_L2; 402bf215546Sopenharmony_ci } barrier_flags; 403bf215546Sopenharmony_ci 404bf215546Sopenharmony_ci struct nir_shader_compiler_options nir_options; 405bf215546Sopenharmony_ci struct nir_shader_compiler_options nir_options_fs; 406bf215546Sopenharmony_ci}; 407bf215546Sopenharmony_ci 408bf215546Sopenharmony_ci/* This encapsulates a state or an operation which can emitted into the GPU 409bf215546Sopenharmony_ci * command stream. */ 410bf215546Sopenharmony_cistruct r600_atom { 411bf215546Sopenharmony_ci void (*emit)(struct r600_common_context *ctx, struct r600_atom *state); 412bf215546Sopenharmony_ci unsigned num_dw; 413bf215546Sopenharmony_ci unsigned short id; 414bf215546Sopenharmony_ci}; 415bf215546Sopenharmony_ci 416bf215546Sopenharmony_cistruct r600_so_target { 417bf215546Sopenharmony_ci struct pipe_stream_output_target b; 418bf215546Sopenharmony_ci 419bf215546Sopenharmony_ci /* The buffer where BUFFER_FILLED_SIZE is stored. */ 420bf215546Sopenharmony_ci struct r600_resource *buf_filled_size; 421bf215546Sopenharmony_ci unsigned buf_filled_size_offset; 422bf215546Sopenharmony_ci bool buf_filled_size_valid; 423bf215546Sopenharmony_ci 424bf215546Sopenharmony_ci unsigned stride_in_dw; 425bf215546Sopenharmony_ci}; 426bf215546Sopenharmony_ci 427bf215546Sopenharmony_cistruct r600_streamout { 428bf215546Sopenharmony_ci struct r600_atom begin_atom; 429bf215546Sopenharmony_ci bool begin_emitted; 430bf215546Sopenharmony_ci unsigned num_dw_for_end; 431bf215546Sopenharmony_ci 432bf215546Sopenharmony_ci unsigned enabled_mask; 433bf215546Sopenharmony_ci unsigned num_targets; 434bf215546Sopenharmony_ci struct r600_so_target *targets[PIPE_MAX_SO_BUFFERS]; 435bf215546Sopenharmony_ci 436bf215546Sopenharmony_ci unsigned append_bitmask; 437bf215546Sopenharmony_ci bool suspended; 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_ci /* External state which comes from the vertex shader, 440bf215546Sopenharmony_ci * it must be set explicitly when binding a shader. */ 441bf215546Sopenharmony_ci uint16_t *stride_in_dw; 442bf215546Sopenharmony_ci unsigned enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */ 443bf215546Sopenharmony_ci 444bf215546Sopenharmony_ci /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */ 445bf215546Sopenharmony_ci unsigned hw_enabled_mask; 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci /* The state of VGT_STRMOUT_(CONFIG|EN). */ 448bf215546Sopenharmony_ci struct r600_atom enable_atom; 449bf215546Sopenharmony_ci bool streamout_enabled; 450bf215546Sopenharmony_ci bool prims_gen_query_enabled; 451bf215546Sopenharmony_ci int num_prims_gen_queries; 452bf215546Sopenharmony_ci}; 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_cistruct r600_signed_scissor { 455bf215546Sopenharmony_ci int minx; 456bf215546Sopenharmony_ci int miny; 457bf215546Sopenharmony_ci int maxx; 458bf215546Sopenharmony_ci int maxy; 459bf215546Sopenharmony_ci}; 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_cistruct r600_scissors { 462bf215546Sopenharmony_ci struct r600_atom atom; 463bf215546Sopenharmony_ci unsigned dirty_mask; 464bf215546Sopenharmony_ci struct pipe_scissor_state states[R600_MAX_VIEWPORTS]; 465bf215546Sopenharmony_ci}; 466bf215546Sopenharmony_ci 467bf215546Sopenharmony_cistruct r600_viewports { 468bf215546Sopenharmony_ci struct r600_atom atom; 469bf215546Sopenharmony_ci unsigned dirty_mask; 470bf215546Sopenharmony_ci unsigned depth_range_dirty_mask; 471bf215546Sopenharmony_ci struct pipe_viewport_state states[R600_MAX_VIEWPORTS]; 472bf215546Sopenharmony_ci struct r600_signed_scissor as_scissor[R600_MAX_VIEWPORTS]; 473bf215546Sopenharmony_ci}; 474bf215546Sopenharmony_ci 475bf215546Sopenharmony_cistruct r600_ring { 476bf215546Sopenharmony_ci struct radeon_cmdbuf cs; 477bf215546Sopenharmony_ci void (*flush)(void *ctx, unsigned flags, 478bf215546Sopenharmony_ci struct pipe_fence_handle **fence); 479bf215546Sopenharmony_ci}; 480bf215546Sopenharmony_ci 481bf215546Sopenharmony_ci/* Saved CS data for debugging features. */ 482bf215546Sopenharmony_cistruct radeon_saved_cs { 483bf215546Sopenharmony_ci uint32_t *ib; 484bf215546Sopenharmony_ci unsigned num_dw; 485bf215546Sopenharmony_ci 486bf215546Sopenharmony_ci struct radeon_bo_list_item *bo_list; 487bf215546Sopenharmony_ci unsigned bo_count; 488bf215546Sopenharmony_ci}; 489bf215546Sopenharmony_ci 490bf215546Sopenharmony_cistruct r600_common_context { 491bf215546Sopenharmony_ci struct pipe_context b; /* base class */ 492bf215546Sopenharmony_ci 493bf215546Sopenharmony_ci struct r600_common_screen *screen; 494bf215546Sopenharmony_ci struct radeon_winsys *ws; 495bf215546Sopenharmony_ci struct radeon_winsys_ctx *ctx; 496bf215546Sopenharmony_ci enum radeon_family family; 497bf215546Sopenharmony_ci enum amd_gfx_level gfx_level; 498bf215546Sopenharmony_ci struct r600_ring gfx; 499bf215546Sopenharmony_ci struct r600_ring dma; 500bf215546Sopenharmony_ci struct pipe_fence_handle *last_gfx_fence; 501bf215546Sopenharmony_ci struct pipe_fence_handle *last_sdma_fence; 502bf215546Sopenharmony_ci struct r600_resource *eop_bug_scratch; 503bf215546Sopenharmony_ci unsigned num_gfx_cs_flushes; 504bf215546Sopenharmony_ci unsigned initial_gfx_cs_size; 505bf215546Sopenharmony_ci unsigned last_dirty_tex_counter; 506bf215546Sopenharmony_ci unsigned last_compressed_colortex_counter; 507bf215546Sopenharmony_ci unsigned last_num_draw_calls; 508bf215546Sopenharmony_ci 509bf215546Sopenharmony_ci struct threaded_context *tc; 510bf215546Sopenharmony_ci struct u_suballocator allocator_zeroed_memory; 511bf215546Sopenharmony_ci struct slab_child_pool pool_transfers; 512bf215546Sopenharmony_ci struct slab_child_pool pool_transfers_unsync; /* for threaded_context */ 513bf215546Sopenharmony_ci 514bf215546Sopenharmony_ci /* Current unaccounted memory usage. */ 515bf215546Sopenharmony_ci uint64_t vram; 516bf215546Sopenharmony_ci uint64_t gtt; 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_ci /* States. */ 519bf215546Sopenharmony_ci struct r600_streamout streamout; 520bf215546Sopenharmony_ci struct r600_scissors scissors; 521bf215546Sopenharmony_ci struct r600_viewports viewports; 522bf215546Sopenharmony_ci bool scissor_enabled; 523bf215546Sopenharmony_ci bool clip_halfz; 524bf215546Sopenharmony_ci bool vs_writes_viewport_index; 525bf215546Sopenharmony_ci bool vs_disables_clipping_viewport; 526bf215546Sopenharmony_ci 527bf215546Sopenharmony_ci /* Additional context states. */ 528bf215546Sopenharmony_ci unsigned flags; /* flush flags */ 529bf215546Sopenharmony_ci 530bf215546Sopenharmony_ci /* Queries. */ 531bf215546Sopenharmony_ci /* Maintain the list of active queries for pausing between IBs. */ 532bf215546Sopenharmony_ci int num_occlusion_queries; 533bf215546Sopenharmony_ci int num_perfect_occlusion_queries; 534bf215546Sopenharmony_ci struct list_head active_queries; 535bf215546Sopenharmony_ci unsigned num_cs_dw_queries_suspend; 536bf215546Sopenharmony_ci /* Misc stats. */ 537bf215546Sopenharmony_ci unsigned num_draw_calls; 538bf215546Sopenharmony_ci unsigned num_decompress_calls; 539bf215546Sopenharmony_ci unsigned num_mrt_draw_calls; 540bf215546Sopenharmony_ci unsigned num_prim_restart_calls; 541bf215546Sopenharmony_ci unsigned num_spill_draw_calls; 542bf215546Sopenharmony_ci unsigned num_compute_calls; 543bf215546Sopenharmony_ci unsigned num_spill_compute_calls; 544bf215546Sopenharmony_ci unsigned num_dma_calls; 545bf215546Sopenharmony_ci unsigned num_cp_dma_calls; 546bf215546Sopenharmony_ci unsigned num_vs_flushes; 547bf215546Sopenharmony_ci unsigned num_ps_flushes; 548bf215546Sopenharmony_ci unsigned num_cs_flushes; 549bf215546Sopenharmony_ci unsigned num_cb_cache_flushes; 550bf215546Sopenharmony_ci unsigned num_db_cache_flushes; 551bf215546Sopenharmony_ci unsigned num_resident_handles; 552bf215546Sopenharmony_ci uint64_t num_alloc_tex_transfer_bytes; 553bf215546Sopenharmony_ci 554bf215546Sopenharmony_ci /* Render condition. */ 555bf215546Sopenharmony_ci struct r600_atom render_cond_atom; 556bf215546Sopenharmony_ci struct pipe_query *render_cond; 557bf215546Sopenharmony_ci unsigned render_cond_mode; 558bf215546Sopenharmony_ci bool render_cond_invert; 559bf215546Sopenharmony_ci bool render_cond_force_off; /* for u_blitter */ 560bf215546Sopenharmony_ci 561bf215546Sopenharmony_ci /* MSAA sample locations. 562bf215546Sopenharmony_ci * The first index is the sample index. 563bf215546Sopenharmony_ci * The second index is the coordinate: X, Y. */ 564bf215546Sopenharmony_ci float sample_locations_1x[1][2]; 565bf215546Sopenharmony_ci float sample_locations_2x[2][2]; 566bf215546Sopenharmony_ci float sample_locations_4x[4][2]; 567bf215546Sopenharmony_ci float sample_locations_8x[8][2]; 568bf215546Sopenharmony_ci float sample_locations_16x[16][2]; 569bf215546Sopenharmony_ci 570bf215546Sopenharmony_ci struct util_debug_callback debug; 571bf215546Sopenharmony_ci struct pipe_device_reset_callback device_reset_callback; 572bf215546Sopenharmony_ci struct u_log_context *log; 573bf215546Sopenharmony_ci 574bf215546Sopenharmony_ci void *query_result_shader; 575bf215546Sopenharmony_ci 576bf215546Sopenharmony_ci /* Copy one resource to another using async DMA. */ 577bf215546Sopenharmony_ci void (*dma_copy)(struct pipe_context *ctx, 578bf215546Sopenharmony_ci struct pipe_resource *dst, 579bf215546Sopenharmony_ci unsigned dst_level, 580bf215546Sopenharmony_ci unsigned dst_x, unsigned dst_y, unsigned dst_z, 581bf215546Sopenharmony_ci struct pipe_resource *src, 582bf215546Sopenharmony_ci unsigned src_level, 583bf215546Sopenharmony_ci const struct pipe_box *src_box); 584bf215546Sopenharmony_ci 585bf215546Sopenharmony_ci void (*dma_clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst, 586bf215546Sopenharmony_ci uint64_t offset, uint64_t size, unsigned value); 587bf215546Sopenharmony_ci 588bf215546Sopenharmony_ci void (*clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst, 589bf215546Sopenharmony_ci uint64_t offset, uint64_t size, unsigned value, 590bf215546Sopenharmony_ci enum r600_coherency coher); 591bf215546Sopenharmony_ci 592bf215546Sopenharmony_ci void (*blit_decompress_depth)(struct pipe_context *ctx, 593bf215546Sopenharmony_ci struct r600_texture *texture, 594bf215546Sopenharmony_ci struct r600_texture *staging, 595bf215546Sopenharmony_ci unsigned first_level, unsigned last_level, 596bf215546Sopenharmony_ci unsigned first_layer, unsigned last_layer, 597bf215546Sopenharmony_ci unsigned first_sample, unsigned last_sample); 598bf215546Sopenharmony_ci 599bf215546Sopenharmony_ci /* Reallocate the buffer and update all resource bindings where 600bf215546Sopenharmony_ci * the buffer is bound, including all resource descriptors. */ 601bf215546Sopenharmony_ci void (*invalidate_buffer)(struct pipe_context *ctx, struct pipe_resource *buf); 602bf215546Sopenharmony_ci 603bf215546Sopenharmony_ci /* Update all resource bindings where the buffer is bound, including 604bf215546Sopenharmony_ci * all resource descriptors. This is invalidate_buffer without 605bf215546Sopenharmony_ci * the invalidation. */ 606bf215546Sopenharmony_ci void (*rebind_buffer)(struct pipe_context *ctx, struct pipe_resource *buf, 607bf215546Sopenharmony_ci uint64_t old_gpu_address); 608bf215546Sopenharmony_ci 609bf215546Sopenharmony_ci void (*save_qbo_state)(struct pipe_context *ctx, struct r600_qbo_state *st); 610bf215546Sopenharmony_ci 611bf215546Sopenharmony_ci /* This ensures there is enough space in the command stream. */ 612bf215546Sopenharmony_ci void (*need_gfx_cs_space)(struct pipe_context *ctx, unsigned num_dw, 613bf215546Sopenharmony_ci bool include_draw_vbo); 614bf215546Sopenharmony_ci 615bf215546Sopenharmony_ci void (*set_atom_dirty)(struct r600_common_context *ctx, 616bf215546Sopenharmony_ci struct r600_atom *atom, bool dirty); 617bf215546Sopenharmony_ci 618bf215546Sopenharmony_ci void (*check_vm_faults)(struct r600_common_context *ctx, 619bf215546Sopenharmony_ci struct radeon_saved_cs *saved, 620bf215546Sopenharmony_ci enum amd_ip_type ring); 621bf215546Sopenharmony_ci}; 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci/* r600_buffer_common.c */ 624bf215546Sopenharmony_cibool r600_rings_is_buffer_referenced(struct r600_common_context *ctx, 625bf215546Sopenharmony_ci struct pb_buffer *buf, 626bf215546Sopenharmony_ci unsigned usage); 627bf215546Sopenharmony_civoid *r600_buffer_map_sync_with_rings(struct r600_common_context *ctx, 628bf215546Sopenharmony_ci struct r600_resource *resource, 629bf215546Sopenharmony_ci unsigned usage); 630bf215546Sopenharmony_civoid r600_buffer_subdata(struct pipe_context *ctx, 631bf215546Sopenharmony_ci struct pipe_resource *buffer, 632bf215546Sopenharmony_ci unsigned usage, unsigned offset, 633bf215546Sopenharmony_ci unsigned size, const void *data); 634bf215546Sopenharmony_civoid r600_init_resource_fields(struct r600_common_screen *rscreen, 635bf215546Sopenharmony_ci struct r600_resource *res, 636bf215546Sopenharmony_ci uint64_t size, unsigned alignment); 637bf215546Sopenharmony_cibool r600_alloc_resource(struct r600_common_screen *rscreen, 638bf215546Sopenharmony_ci struct r600_resource *res); 639bf215546Sopenharmony_civoid r600_buffer_destroy(struct pipe_screen *screen, struct pipe_resource *buf); 640bf215546Sopenharmony_civoid r600_buffer_flush_region(struct pipe_context *ctx, 641bf215546Sopenharmony_ci struct pipe_transfer *transfer, 642bf215546Sopenharmony_ci const struct pipe_box *rel_box); 643bf215546Sopenharmony_cistruct pipe_resource *r600_buffer_create(struct pipe_screen *screen, 644bf215546Sopenharmony_ci const struct pipe_resource *templ, 645bf215546Sopenharmony_ci unsigned alignment); 646bf215546Sopenharmony_cistruct pipe_resource * r600_aligned_buffer_create(struct pipe_screen *screen, 647bf215546Sopenharmony_ci unsigned flags, 648bf215546Sopenharmony_ci unsigned usage, 649bf215546Sopenharmony_ci unsigned size, 650bf215546Sopenharmony_ci unsigned alignment); 651bf215546Sopenharmony_cistruct pipe_resource * 652bf215546Sopenharmony_cir600_buffer_from_user_memory(struct pipe_screen *screen, 653bf215546Sopenharmony_ci const struct pipe_resource *templ, 654bf215546Sopenharmony_ci void *user_memory); 655bf215546Sopenharmony_civoid 656bf215546Sopenharmony_cir600_invalidate_resource(struct pipe_context *ctx, 657bf215546Sopenharmony_ci struct pipe_resource *resource); 658bf215546Sopenharmony_civoid r600_replace_buffer_storage(struct pipe_context *ctx, 659bf215546Sopenharmony_ci struct pipe_resource *dst, 660bf215546Sopenharmony_ci struct pipe_resource *src); 661bf215546Sopenharmony_civoid *r600_buffer_transfer_map(struct pipe_context *ctx, 662bf215546Sopenharmony_ci struct pipe_resource *resource, 663bf215546Sopenharmony_ci unsigned level, 664bf215546Sopenharmony_ci unsigned usage, 665bf215546Sopenharmony_ci const struct pipe_box *box, 666bf215546Sopenharmony_ci struct pipe_transfer **ptransfer); 667bf215546Sopenharmony_civoid r600_buffer_transfer_unmap(struct pipe_context *ctx, 668bf215546Sopenharmony_ci struct pipe_transfer *transfer); 669bf215546Sopenharmony_ci 670bf215546Sopenharmony_ci/* r600_common_pipe.c */ 671bf215546Sopenharmony_civoid r600_gfx_write_event_eop(struct r600_common_context *ctx, 672bf215546Sopenharmony_ci unsigned event, unsigned event_flags, 673bf215546Sopenharmony_ci unsigned data_sel, 674bf215546Sopenharmony_ci struct r600_resource *buf, uint64_t va, 675bf215546Sopenharmony_ci uint32_t new_fence, unsigned query_type); 676bf215546Sopenharmony_ciunsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen); 677bf215546Sopenharmony_civoid r600_gfx_wait_fence(struct r600_common_context *ctx, 678bf215546Sopenharmony_ci struct r600_resource *buf, 679bf215546Sopenharmony_ci uint64_t va, uint32_t ref, uint32_t mask); 680bf215546Sopenharmony_civoid r600_draw_rectangle(struct blitter_context *blitter, 681bf215546Sopenharmony_ci void *vertex_elements_cso, 682bf215546Sopenharmony_ci blitter_get_vs_func get_vs, 683bf215546Sopenharmony_ci int x1, int y1, int x2, int y2, 684bf215546Sopenharmony_ci float depth, unsigned num_instances, 685bf215546Sopenharmony_ci enum blitter_attrib_type type, 686bf215546Sopenharmony_ci const union blitter_attrib *attrib); 687bf215546Sopenharmony_cibool r600_common_screen_init(struct r600_common_screen *rscreen, 688bf215546Sopenharmony_ci struct radeon_winsys *ws); 689bf215546Sopenharmony_civoid r600_destroy_common_screen(struct r600_common_screen *rscreen); 690bf215546Sopenharmony_civoid r600_preflush_suspend_features(struct r600_common_context *ctx); 691bf215546Sopenharmony_civoid r600_postflush_resume_features(struct r600_common_context *ctx); 692bf215546Sopenharmony_cibool r600_common_context_init(struct r600_common_context *rctx, 693bf215546Sopenharmony_ci struct r600_common_screen *rscreen, 694bf215546Sopenharmony_ci unsigned context_flags); 695bf215546Sopenharmony_civoid r600_common_context_cleanup(struct r600_common_context *rctx); 696bf215546Sopenharmony_cibool r600_can_dump_shader(struct r600_common_screen *rscreen, 697bf215546Sopenharmony_ci unsigned processor); 698bf215546Sopenharmony_cibool r600_extra_shader_checks(struct r600_common_screen *rscreen, 699bf215546Sopenharmony_ci unsigned processor); 700bf215546Sopenharmony_civoid r600_screen_clear_buffer(struct r600_common_screen *rscreen, struct pipe_resource *dst, 701bf215546Sopenharmony_ci uint64_t offset, uint64_t size, unsigned value); 702bf215546Sopenharmony_cistruct pipe_resource *r600_resource_create_common(struct pipe_screen *screen, 703bf215546Sopenharmony_ci const struct pipe_resource *templ); 704bf215546Sopenharmony_ciconst char *r600_get_llvm_processor_name(enum radeon_family family); 705bf215546Sopenharmony_civoid r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw, 706bf215546Sopenharmony_ci struct r600_resource *dst, struct r600_resource *src); 707bf215546Sopenharmony_civoid radeon_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, 708bf215546Sopenharmony_ci struct radeon_saved_cs *saved, bool get_buffer_list); 709bf215546Sopenharmony_civoid radeon_clear_saved_cs(struct radeon_saved_cs *saved); 710bf215546Sopenharmony_cibool r600_check_device_reset(struct r600_common_context *rctx); 711bf215546Sopenharmony_ci 712bf215546Sopenharmony_ci/* r600_gpu_load.c */ 713bf215546Sopenharmony_civoid r600_gpu_load_kill_thread(struct r600_common_screen *rscreen); 714bf215546Sopenharmony_ciuint64_t r600_begin_counter(struct r600_common_screen *rscreen, unsigned type); 715bf215546Sopenharmony_ciunsigned r600_end_counter(struct r600_common_screen *rscreen, unsigned type, 716bf215546Sopenharmony_ci uint64_t begin); 717bf215546Sopenharmony_ci 718bf215546Sopenharmony_ci/* r600_perfcounters.c */ 719bf215546Sopenharmony_civoid r600_perfcounters_destroy(struct r600_common_screen *rscreen); 720bf215546Sopenharmony_ci 721bf215546Sopenharmony_ci/* r600_query.c */ 722bf215546Sopenharmony_civoid r600_init_screen_query_functions(struct r600_common_screen *rscreen); 723bf215546Sopenharmony_civoid r600_query_init(struct r600_common_context *rctx); 724bf215546Sopenharmony_civoid r600_suspend_queries(struct r600_common_context *ctx); 725bf215546Sopenharmony_civoid r600_resume_queries(struct r600_common_context *ctx); 726bf215546Sopenharmony_civoid r600_query_fix_enabled_rb_mask(struct r600_common_screen *rscreen); 727bf215546Sopenharmony_ci 728bf215546Sopenharmony_ci/* r600_streamout.c */ 729bf215546Sopenharmony_civoid r600_streamout_buffers_dirty(struct r600_common_context *rctx); 730bf215546Sopenharmony_civoid r600_set_streamout_targets(struct pipe_context *ctx, 731bf215546Sopenharmony_ci unsigned num_targets, 732bf215546Sopenharmony_ci struct pipe_stream_output_target **targets, 733bf215546Sopenharmony_ci const unsigned *offset); 734bf215546Sopenharmony_civoid r600_emit_streamout_end(struct r600_common_context *rctx); 735bf215546Sopenharmony_civoid r600_update_prims_generated_query_state(struct r600_common_context *rctx, 736bf215546Sopenharmony_ci unsigned type, int diff); 737bf215546Sopenharmony_civoid r600_streamout_init(struct r600_common_context *rctx); 738bf215546Sopenharmony_ci 739bf215546Sopenharmony_ci/* r600_test_dma.c */ 740bf215546Sopenharmony_civoid r600_test_dma(struct r600_common_screen *rscreen); 741bf215546Sopenharmony_ci 742bf215546Sopenharmony_ci/* r600_texture.c */ 743bf215546Sopenharmony_cibool r600_prepare_for_dma_blit(struct r600_common_context *rctx, 744bf215546Sopenharmony_ci struct r600_texture *rdst, 745bf215546Sopenharmony_ci unsigned dst_level, unsigned dstx, 746bf215546Sopenharmony_ci unsigned dsty, unsigned dstz, 747bf215546Sopenharmony_ci struct r600_texture *rsrc, 748bf215546Sopenharmony_ci unsigned src_level, 749bf215546Sopenharmony_ci const struct pipe_box *src_box); 750bf215546Sopenharmony_civoid r600_texture_destroy(struct pipe_screen *screen, struct pipe_resource *ptex); 751bf215546Sopenharmony_civoid r600_texture_get_fmask_info(struct r600_common_screen *rscreen, 752bf215546Sopenharmony_ci struct r600_texture *rtex, 753bf215546Sopenharmony_ci unsigned nr_samples, 754bf215546Sopenharmony_ci struct r600_fmask_info *out); 755bf215546Sopenharmony_civoid r600_texture_get_cmask_info(struct r600_common_screen *rscreen, 756bf215546Sopenharmony_ci struct r600_texture *rtex, 757bf215546Sopenharmony_ci struct r600_cmask_info *out); 758bf215546Sopenharmony_cibool r600_init_flushed_depth_texture(struct pipe_context *ctx, 759bf215546Sopenharmony_ci struct pipe_resource *texture, 760bf215546Sopenharmony_ci struct r600_texture **staging); 761bf215546Sopenharmony_civoid r600_print_texture_info(struct r600_common_screen *rscreen, 762bf215546Sopenharmony_ci struct r600_texture *rtex, struct u_log_context *log); 763bf215546Sopenharmony_cistruct pipe_resource *r600_texture_create(struct pipe_screen *screen, 764bf215546Sopenharmony_ci const struct pipe_resource *templ); 765bf215546Sopenharmony_cistruct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe, 766bf215546Sopenharmony_ci struct pipe_resource *texture, 767bf215546Sopenharmony_ci const struct pipe_surface *templ, 768bf215546Sopenharmony_ci unsigned width0, unsigned height0, 769bf215546Sopenharmony_ci unsigned width, unsigned height); 770bf215546Sopenharmony_ciunsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap); 771bf215546Sopenharmony_civoid evergreen_do_fast_color_clear(struct r600_common_context *rctx, 772bf215546Sopenharmony_ci struct pipe_framebuffer_state *fb, 773bf215546Sopenharmony_ci struct r600_atom *fb_state, 774bf215546Sopenharmony_ci unsigned *buffers, ubyte *dirty_cbufs, 775bf215546Sopenharmony_ci const union pipe_color_union *color); 776bf215546Sopenharmony_civoid r600_init_screen_texture_functions(struct r600_common_screen *rscreen); 777bf215546Sopenharmony_civoid r600_init_context_texture_functions(struct r600_common_context *rctx); 778bf215546Sopenharmony_civoid eg_resource_alloc_immed(struct r600_common_screen *rscreen, 779bf215546Sopenharmony_ci struct r600_resource *res, 780bf215546Sopenharmony_ci unsigned immed_size); 781bf215546Sopenharmony_civoid *r600_texture_transfer_map(struct pipe_context *ctx, 782bf215546Sopenharmony_ci struct pipe_resource *texture, 783bf215546Sopenharmony_ci unsigned level, 784bf215546Sopenharmony_ci unsigned usage, 785bf215546Sopenharmony_ci const struct pipe_box *box, 786bf215546Sopenharmony_ci struct pipe_transfer **ptransfer); 787bf215546Sopenharmony_civoid r600_texture_transfer_unmap(struct pipe_context *ctx, 788bf215546Sopenharmony_ci struct pipe_transfer* transfer); 789bf215546Sopenharmony_ci 790bf215546Sopenharmony_ci/* r600_viewport.c */ 791bf215546Sopenharmony_civoid evergreen_apply_scissor_bug_workaround(struct r600_common_context *rctx, 792bf215546Sopenharmony_ci struct pipe_scissor_state *scissor); 793bf215546Sopenharmony_civoid r600_viewport_set_rast_deps(struct r600_common_context *rctx, 794bf215546Sopenharmony_ci bool scissor_enable, bool clip_halfz); 795bf215546Sopenharmony_civoid r600_update_vs_writes_viewport_index(struct r600_common_context *rctx, 796bf215546Sopenharmony_ci struct tgsi_shader_info *info); 797bf215546Sopenharmony_civoid r600_init_viewport_functions(struct r600_common_context *rctx); 798bf215546Sopenharmony_ci 799bf215546Sopenharmony_ci/* cayman_msaa.c */ 800bf215546Sopenharmony_ciextern const uint32_t eg_sample_locs_2x[4]; 801bf215546Sopenharmony_ciextern const unsigned eg_max_dist_2x; 802bf215546Sopenharmony_ciextern const uint32_t eg_sample_locs_4x[4]; 803bf215546Sopenharmony_ciextern const unsigned eg_max_dist_4x; 804bf215546Sopenharmony_civoid cayman_get_sample_position(struct pipe_context *ctx, unsigned sample_count, 805bf215546Sopenharmony_ci unsigned sample_index, float *out_value); 806bf215546Sopenharmony_civoid cayman_init_msaa(struct pipe_context *ctx); 807bf215546Sopenharmony_civoid cayman_emit_msaa_state(struct radeon_cmdbuf *cs, int nr_samples, 808bf215546Sopenharmony_ci int ps_iter_samples, int overrast_samples); 809bf215546Sopenharmony_ci 810bf215546Sopenharmony_ci 811bf215546Sopenharmony_ci/* Inline helpers. */ 812bf215546Sopenharmony_ci 813bf215546Sopenharmony_cistatic inline struct r600_resource *r600_resource(struct pipe_resource *r) 814bf215546Sopenharmony_ci{ 815bf215546Sopenharmony_ci return (struct r600_resource*)r; 816bf215546Sopenharmony_ci} 817bf215546Sopenharmony_ci 818bf215546Sopenharmony_cistatic inline void 819bf215546Sopenharmony_cir600_resource_reference(struct r600_resource **ptr, struct r600_resource *res) 820bf215546Sopenharmony_ci{ 821bf215546Sopenharmony_ci pipe_resource_reference((struct pipe_resource **)ptr, 822bf215546Sopenharmony_ci (struct pipe_resource *)res); 823bf215546Sopenharmony_ci} 824bf215546Sopenharmony_ci 825bf215546Sopenharmony_cistatic inline void 826bf215546Sopenharmony_cir600_texture_reference(struct r600_texture **ptr, struct r600_texture *res) 827bf215546Sopenharmony_ci{ 828bf215546Sopenharmony_ci pipe_resource_reference((struct pipe_resource **)ptr, &res->resource.b.b); 829bf215546Sopenharmony_ci} 830bf215546Sopenharmony_ci 831bf215546Sopenharmony_cistatic inline void 832bf215546Sopenharmony_cir600_context_add_resource_size(struct pipe_context *ctx, struct pipe_resource *r) 833bf215546Sopenharmony_ci{ 834bf215546Sopenharmony_ci struct r600_common_context *rctx = (struct r600_common_context *)ctx; 835bf215546Sopenharmony_ci struct r600_resource *res = (struct r600_resource *)r; 836bf215546Sopenharmony_ci 837bf215546Sopenharmony_ci if (res) { 838bf215546Sopenharmony_ci /* Add memory usage for need_gfx_cs_space */ 839bf215546Sopenharmony_ci rctx->vram += res->vram_usage; 840bf215546Sopenharmony_ci rctx->gtt += res->gart_usage; 841bf215546Sopenharmony_ci } 842bf215546Sopenharmony_ci} 843bf215546Sopenharmony_ci 844bf215546Sopenharmony_cistatic inline bool r600_get_strmout_en(struct r600_common_context *rctx) 845bf215546Sopenharmony_ci{ 846bf215546Sopenharmony_ci return rctx->streamout.streamout_enabled || 847bf215546Sopenharmony_ci rctx->streamout.prims_gen_query_enabled; 848bf215546Sopenharmony_ci} 849bf215546Sopenharmony_ci 850bf215546Sopenharmony_ci#define SQ_TEX_XY_FILTER_POINT 0x00 851bf215546Sopenharmony_ci#define SQ_TEX_XY_FILTER_BILINEAR 0x01 852bf215546Sopenharmony_ci#define SQ_TEX_XY_FILTER_ANISO_POINT 0x02 853bf215546Sopenharmony_ci#define SQ_TEX_XY_FILTER_ANISO_BILINEAR 0x03 854bf215546Sopenharmony_ci 855bf215546Sopenharmony_cistatic inline unsigned eg_tex_filter(unsigned filter, unsigned max_aniso) 856bf215546Sopenharmony_ci{ 857bf215546Sopenharmony_ci if (filter == PIPE_TEX_FILTER_LINEAR) 858bf215546Sopenharmony_ci return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_BILINEAR 859bf215546Sopenharmony_ci : SQ_TEX_XY_FILTER_BILINEAR; 860bf215546Sopenharmony_ci else 861bf215546Sopenharmony_ci return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_POINT 862bf215546Sopenharmony_ci : SQ_TEX_XY_FILTER_POINT; 863bf215546Sopenharmony_ci} 864bf215546Sopenharmony_ci 865bf215546Sopenharmony_cistatic inline unsigned r600_tex_aniso_filter(unsigned filter) 866bf215546Sopenharmony_ci{ 867bf215546Sopenharmony_ci if (filter < 2) 868bf215546Sopenharmony_ci return 0; 869bf215546Sopenharmony_ci if (filter < 4) 870bf215546Sopenharmony_ci return 1; 871bf215546Sopenharmony_ci if (filter < 8) 872bf215546Sopenharmony_ci return 2; 873bf215546Sopenharmony_ci if (filter < 16) 874bf215546Sopenharmony_ci return 3; 875bf215546Sopenharmony_ci return 4; 876bf215546Sopenharmony_ci} 877bf215546Sopenharmony_ci 878bf215546Sopenharmony_cistatic inline unsigned r600_wavefront_size(enum radeon_family family) 879bf215546Sopenharmony_ci{ 880bf215546Sopenharmony_ci switch (family) { 881bf215546Sopenharmony_ci case CHIP_RV610: 882bf215546Sopenharmony_ci case CHIP_RS780: 883bf215546Sopenharmony_ci case CHIP_RV620: 884bf215546Sopenharmony_ci case CHIP_RS880: 885bf215546Sopenharmony_ci return 16; 886bf215546Sopenharmony_ci case CHIP_RV630: 887bf215546Sopenharmony_ci case CHIP_RV635: 888bf215546Sopenharmony_ci case CHIP_RV730: 889bf215546Sopenharmony_ci case CHIP_RV710: 890bf215546Sopenharmony_ci case CHIP_PALM: 891bf215546Sopenharmony_ci case CHIP_CEDAR: 892bf215546Sopenharmony_ci return 32; 893bf215546Sopenharmony_ci default: 894bf215546Sopenharmony_ci return 64; 895bf215546Sopenharmony_ci } 896bf215546Sopenharmony_ci} 897bf215546Sopenharmony_ci 898bf215546Sopenharmony_cistatic inline unsigned 899bf215546Sopenharmony_cir600_get_sampler_view_priority(struct r600_resource *res) 900bf215546Sopenharmony_ci{ 901bf215546Sopenharmony_ci if (res->b.b.target == PIPE_BUFFER) 902bf215546Sopenharmony_ci return RADEON_PRIO_SAMPLER_BUFFER; 903bf215546Sopenharmony_ci 904bf215546Sopenharmony_ci if (res->b.b.nr_samples > 1) 905bf215546Sopenharmony_ci return RADEON_PRIO_SAMPLER_TEXTURE_MSAA; 906bf215546Sopenharmony_ci 907bf215546Sopenharmony_ci return RADEON_PRIO_SAMPLER_TEXTURE; 908bf215546Sopenharmony_ci} 909bf215546Sopenharmony_ci 910bf215546Sopenharmony_cistatic inline bool 911bf215546Sopenharmony_cir600_can_sample_zs(struct r600_texture *tex, bool stencil_sampler) 912bf215546Sopenharmony_ci{ 913bf215546Sopenharmony_ci return (stencil_sampler && tex->can_sample_s) || 914bf215546Sopenharmony_ci (!stencil_sampler && tex->can_sample_z); 915bf215546Sopenharmony_ci} 916bf215546Sopenharmony_ci 917bf215546Sopenharmony_cistatic inline bool 918bf215546Sopenharmony_cir600_htile_enabled(struct r600_texture *tex, unsigned level) 919bf215546Sopenharmony_ci{ 920bf215546Sopenharmony_ci return tex->htile_offset && level == 0; 921bf215546Sopenharmony_ci} 922bf215546Sopenharmony_ci 923bf215546Sopenharmony_ci#define COMPUTE_DBG(rscreen, fmt, args...) \ 924bf215546Sopenharmony_ci do { \ 925bf215546Sopenharmony_ci if ((rscreen->b.debug_flags & DBG_COMPUTE)) fprintf(stderr, fmt, ##args); \ 926bf215546Sopenharmony_ci } while (0); 927bf215546Sopenharmony_ci 928bf215546Sopenharmony_ci#define R600_ERR(fmt, args...) \ 929bf215546Sopenharmony_ci fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args) 930bf215546Sopenharmony_ci 931bf215546Sopenharmony_ci/* For MSAA sample positions. */ 932bf215546Sopenharmony_ci#define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \ 933bf215546Sopenharmony_ci (((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) | \ 934bf215546Sopenharmony_ci (((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \ 935bf215546Sopenharmony_ci (((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \ 936bf215546Sopenharmony_ci (((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28)) 937bf215546Sopenharmony_ci 938bf215546Sopenharmony_cistatic inline int S_FIXED(float value, unsigned frac_bits) 939bf215546Sopenharmony_ci{ 940bf215546Sopenharmony_ci return value * (1 << frac_bits); 941bf215546Sopenharmony_ci} 942bf215546Sopenharmony_ci 943bf215546Sopenharmony_ci#endif 944