1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com> 3bf215546Sopenharmony_ci * Copyright 2010 Marek Olšák <maraeo@gmail.com> 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 9bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 10bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "compiler/nir/nir.h" 25bf215546Sopenharmony_ci#include "util/format/u_format.h" 26bf215546Sopenharmony_ci#include "util/format/u_format_s3tc.h" 27bf215546Sopenharmony_ci#include "util/u_screen.h" 28bf215546Sopenharmony_ci#include "util/u_memory.h" 29bf215546Sopenharmony_ci#include "util/os_time.h" 30bf215546Sopenharmony_ci#include "vl/vl_decoder.h" 31bf215546Sopenharmony_ci#include "vl/vl_video_buffer.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#include "r300_context.h" 34bf215546Sopenharmony_ci#include "r300_texture.h" 35bf215546Sopenharmony_ci#include "r300_screen_buffer.h" 36bf215546Sopenharmony_ci#include "r300_state_inlines.h" 37bf215546Sopenharmony_ci#include "r300_public.h" 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci#include "draw/draw_context.h" 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci/* Return the identifier behind whom the brave coders responsible for this 42bf215546Sopenharmony_ci * amalgamation of code, sweat, and duct tape, routinely obscure their names. 43bf215546Sopenharmony_ci * 44bf215546Sopenharmony_ci * ...I should have just put "Corbin Simpson", but I'm not that cool. 45bf215546Sopenharmony_ci * 46bf215546Sopenharmony_ci * (Or egotistical. Yet.) */ 47bf215546Sopenharmony_cistatic const char* r300_get_vendor(struct pipe_screen* pscreen) 48bf215546Sopenharmony_ci{ 49bf215546Sopenharmony_ci return "X.Org R300 Project"; 50bf215546Sopenharmony_ci} 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_cistatic const char* r300_get_device_vendor(struct pipe_screen* pscreen) 53bf215546Sopenharmony_ci{ 54bf215546Sopenharmony_ci return "ATI"; 55bf215546Sopenharmony_ci} 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_cistatic const char* chip_families[] = { 58bf215546Sopenharmony_ci "unknown", 59bf215546Sopenharmony_ci "ATI R300", 60bf215546Sopenharmony_ci "ATI R350", 61bf215546Sopenharmony_ci "ATI RV350", 62bf215546Sopenharmony_ci "ATI RV370", 63bf215546Sopenharmony_ci "ATI RV380", 64bf215546Sopenharmony_ci "ATI RS400", 65bf215546Sopenharmony_ci "ATI RC410", 66bf215546Sopenharmony_ci "ATI RS480", 67bf215546Sopenharmony_ci "ATI R420", 68bf215546Sopenharmony_ci "ATI R423", 69bf215546Sopenharmony_ci "ATI R430", 70bf215546Sopenharmony_ci "ATI R480", 71bf215546Sopenharmony_ci "ATI R481", 72bf215546Sopenharmony_ci "ATI RV410", 73bf215546Sopenharmony_ci "ATI RS600", 74bf215546Sopenharmony_ci "ATI RS690", 75bf215546Sopenharmony_ci "ATI RS740", 76bf215546Sopenharmony_ci "ATI RV515", 77bf215546Sopenharmony_ci "ATI R520", 78bf215546Sopenharmony_ci "ATI RV530", 79bf215546Sopenharmony_ci "ATI R580", 80bf215546Sopenharmony_ci "ATI RV560", 81bf215546Sopenharmony_ci "ATI RV570" 82bf215546Sopenharmony_ci}; 83bf215546Sopenharmony_ci 84bf215546Sopenharmony_cistatic const char* r300_get_family_name(struct r300_screen* r300screen) 85bf215546Sopenharmony_ci{ 86bf215546Sopenharmony_ci return chip_families[r300screen->caps.family]; 87bf215546Sopenharmony_ci} 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_cistatic const char* r300_get_name(struct pipe_screen* pscreen) 90bf215546Sopenharmony_ci{ 91bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 92bf215546Sopenharmony_ci 93bf215546Sopenharmony_ci return r300_get_family_name(r300screen); 94bf215546Sopenharmony_ci} 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_cistatic void r300_disk_cache_create(struct r300_screen* r300screen) 97bf215546Sopenharmony_ci{ 98bf215546Sopenharmony_ci struct mesa_sha1 ctx; 99bf215546Sopenharmony_ci unsigned char sha1[20]; 100bf215546Sopenharmony_ci char cache_id[20 * 2 + 1]; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci _mesa_sha1_init(&ctx); 103bf215546Sopenharmony_ci if (!disk_cache_get_function_identifier(r300_disk_cache_create, 104bf215546Sopenharmony_ci &ctx)) 105bf215546Sopenharmony_ci return; 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci _mesa_sha1_final(&ctx, sha1); 108bf215546Sopenharmony_ci disk_cache_format_hex_id(cache_id, sha1, 20 * 2); 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci r300screen->disk_shader_cache = 111bf215546Sopenharmony_ci disk_cache_create(r300_get_family_name(r300screen), 112bf215546Sopenharmony_ci cache_id, 113bf215546Sopenharmony_ci r300screen->debug); 114bf215546Sopenharmony_ci} 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_cistatic struct disk_cache* r300_get_disk_shader_cache(struct pipe_screen* pscreen) 117bf215546Sopenharmony_ci{ 118bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 119bf215546Sopenharmony_ci return r300screen->disk_shader_cache; 120bf215546Sopenharmony_ci} 121bf215546Sopenharmony_ci 122bf215546Sopenharmony_cistatic int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param) 123bf215546Sopenharmony_ci{ 124bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 125bf215546Sopenharmony_ci boolean is_r500 = r300screen->caps.is_r500; 126bf215546Sopenharmony_ci 127bf215546Sopenharmony_ci switch (param) { 128bf215546Sopenharmony_ci /* Supported features (boolean caps). */ 129bf215546Sopenharmony_ci case PIPE_CAP_NPOT_TEXTURES: 130bf215546Sopenharmony_ci case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES: 131bf215546Sopenharmony_ci case PIPE_CAP_MIXED_COLOR_DEPTH_BITS: 132bf215546Sopenharmony_ci case PIPE_CAP_ANISOTROPIC_FILTER: 133bf215546Sopenharmony_ci case PIPE_CAP_POINT_SPRITE: 134bf215546Sopenharmony_ci case PIPE_CAP_OCCLUSION_QUERY: 135bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_MIRROR_CLAMP: 136bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE: 137bf215546Sopenharmony_ci case PIPE_CAP_BLEND_EQUATION_SEPARATE: 138bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: 139bf215546Sopenharmony_ci case PIPE_CAP_FS_COORD_ORIGIN_UPPER_LEFT: 140bf215546Sopenharmony_ci case PIPE_CAP_FS_COORD_PIXEL_CENTER_HALF_INTEGER: 141bf215546Sopenharmony_ci case PIPE_CAP_CONDITIONAL_RENDER: 142bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_BARRIER: 143bf215546Sopenharmony_ci case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: 144bf215546Sopenharmony_ci case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT: 145bf215546Sopenharmony_ci case PIPE_CAP_CLIP_HALFZ: 146bf215546Sopenharmony_ci case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION: 147bf215546Sopenharmony_ci case PIPE_CAP_LEGACY_MATH_RULES: 148bf215546Sopenharmony_ci return 1; 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_TRANSFER_MODES: 151bf215546Sopenharmony_ci return PIPE_TEXTURE_TRANSFER_BLIT; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT: 154bf215546Sopenharmony_ci return R300_BUFFER_ALIGNMENT; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT: 157bf215546Sopenharmony_ci return 16; 158bf215546Sopenharmony_ci 159bf215546Sopenharmony_ci case PIPE_CAP_GLSL_FEATURE_LEVEL: 160bf215546Sopenharmony_ci case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY: 161bf215546Sopenharmony_ci return 120; 162bf215546Sopenharmony_ci 163bf215546Sopenharmony_ci /* r300 cannot do swizzling of compressed textures. Supported otherwise. */ 164bf215546Sopenharmony_ci case PIPE_CAP_TEXTURE_SWIZZLE: 165bf215546Sopenharmony_ci return r300screen->caps.dxtc_swizzle; 166bf215546Sopenharmony_ci 167bf215546Sopenharmony_ci /* We don't support color clamping on r500, so that we can use color 168bf215546Sopenharmony_ci * interpolators for generic varyings. */ 169bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_COLOR_CLAMPED: 170bf215546Sopenharmony_ci return !is_r500; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci /* Supported on r500 only. */ 173bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_COLOR_UNCLAMPED: 174bf215546Sopenharmony_ci case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: 175bf215546Sopenharmony_ci case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD: 176bf215546Sopenharmony_ci case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES: 177bf215546Sopenharmony_ci return is_r500 ? 1 : 0; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_ci case PIPE_CAP_SHAREABLE_SHADERS: 180bf215546Sopenharmony_ci return 0; 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci case PIPE_CAP_MAX_GS_INVOCATIONS: 183bf215546Sopenharmony_ci return 32; 184bf215546Sopenharmony_ci case PIPE_CAP_MAX_SHADER_BUFFER_SIZE_UINT: 185bf215546Sopenharmony_ci return 1 << 27; 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci /* SWTCL-only features. */ 188bf215546Sopenharmony_ci case PIPE_CAP_PRIMITIVE_RESTART: 189bf215546Sopenharmony_ci case PIPE_CAP_PRIMITIVE_RESTART_FIXED_INDEX: 190bf215546Sopenharmony_ci case PIPE_CAP_USER_VERTEX_BUFFERS: 191bf215546Sopenharmony_ci case PIPE_CAP_VS_WINDOW_SPACE_POSITION: 192bf215546Sopenharmony_ci return !r300screen->caps.has_tcl; 193bf215546Sopenharmony_ci 194bf215546Sopenharmony_ci /* HWTCL-only features / limitations. */ 195bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY: 196bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY: 197bf215546Sopenharmony_ci case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY: 198bf215546Sopenharmony_ci return r300screen->caps.has_tcl; 199bf215546Sopenharmony_ci 200bf215546Sopenharmony_ci /* Texturing. */ 201bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_2D_SIZE: 202bf215546Sopenharmony_ci return is_r500 ? 4096 : 2048; 203bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: 204bf215546Sopenharmony_ci case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: 205bf215546Sopenharmony_ci /* 13 == 4096, 12 == 2048 */ 206bf215546Sopenharmony_ci return is_r500 ? 13 : 12; 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci /* Render targets. */ 209bf215546Sopenharmony_ci case PIPE_CAP_MAX_RENDER_TARGETS: 210bf215546Sopenharmony_ci return 4; 211bf215546Sopenharmony_ci case PIPE_CAP_ENDIANNESS: 212bf215546Sopenharmony_ci return PIPE_ENDIAN_LITTLE; 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci case PIPE_CAP_MAX_VIEWPORTS: 215bf215546Sopenharmony_ci return 1; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci case PIPE_CAP_MAX_VERTEX_ATTRIB_STRIDE: 218bf215546Sopenharmony_ci return 2048; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci case PIPE_CAP_MAX_VARYINGS: 221bf215546Sopenharmony_ci return 10; 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_ci case PIPE_CAP_PREFER_IMM_ARRAYS_AS_CONSTBUF: 224bf215546Sopenharmony_ci return 0; 225bf215546Sopenharmony_ci 226bf215546Sopenharmony_ci case PIPE_CAP_VENDOR_ID: 227bf215546Sopenharmony_ci return 0x1002; 228bf215546Sopenharmony_ci case PIPE_CAP_DEVICE_ID: 229bf215546Sopenharmony_ci return r300screen->info.pci_id; 230bf215546Sopenharmony_ci case PIPE_CAP_ACCELERATED: 231bf215546Sopenharmony_ci return 1; 232bf215546Sopenharmony_ci case PIPE_CAP_VIDEO_MEMORY: 233bf215546Sopenharmony_ci return r300screen->info.vram_size_kb >> 10; 234bf215546Sopenharmony_ci case PIPE_CAP_UMA: 235bf215546Sopenharmony_ci return 0; 236bf215546Sopenharmony_ci case PIPE_CAP_PCI_GROUP: 237bf215546Sopenharmony_ci return r300screen->info.pci_domain; 238bf215546Sopenharmony_ci case PIPE_CAP_PCI_BUS: 239bf215546Sopenharmony_ci return r300screen->info.pci_bus; 240bf215546Sopenharmony_ci case PIPE_CAP_PCI_DEVICE: 241bf215546Sopenharmony_ci return r300screen->info.pci_dev; 242bf215546Sopenharmony_ci case PIPE_CAP_PCI_FUNCTION: 243bf215546Sopenharmony_ci return r300screen->info.pci_func; 244bf215546Sopenharmony_ci default: 245bf215546Sopenharmony_ci return u_pipe_screen_get_param_defaults(pscreen, param); 246bf215546Sopenharmony_ci } 247bf215546Sopenharmony_ci} 248bf215546Sopenharmony_ci 249bf215546Sopenharmony_cistatic int r300_get_shader_param(struct pipe_screen *pscreen, 250bf215546Sopenharmony_ci enum pipe_shader_type shader, 251bf215546Sopenharmony_ci enum pipe_shader_cap param) 252bf215546Sopenharmony_ci{ 253bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 254bf215546Sopenharmony_ci boolean is_r400 = r300screen->caps.is_r400; 255bf215546Sopenharmony_ci boolean is_r500 = r300screen->caps.is_r500; 256bf215546Sopenharmony_ci 257bf215546Sopenharmony_ci switch (param) { 258bf215546Sopenharmony_ci case PIPE_SHADER_CAP_PREFERRED_IR: 259bf215546Sopenharmony_ci return (r300screen->debug & DBG_USE_TGSI) ? PIPE_SHADER_IR_TGSI : PIPE_SHADER_IR_NIR; 260bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUPPORTED_IRS: 261bf215546Sopenharmony_ci return (1 << PIPE_SHADER_IR_NIR) | (1 << PIPE_SHADER_IR_TGSI); 262bf215546Sopenharmony_ci default: 263bf215546Sopenharmony_ci break; 264bf215546Sopenharmony_ci } 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci switch (shader) { 267bf215546Sopenharmony_ci case PIPE_SHADER_FRAGMENT: 268bf215546Sopenharmony_ci switch (param) 269bf215546Sopenharmony_ci { 270bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: 271bf215546Sopenharmony_ci return is_r500 || is_r400 ? 512 : 96; 272bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: 273bf215546Sopenharmony_ci return is_r500 || is_r400 ? 512 : 64; 274bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: 275bf215546Sopenharmony_ci return is_r500 || is_r400 ? 512 : 32; 276bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: 277bf215546Sopenharmony_ci return is_r500 ? 511 : 4; 278bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: 279bf215546Sopenharmony_ci return is_r500 ? 64 : 0; /* Actually unlimited on r500. */ 280bf215546Sopenharmony_ci /* Fragment shader limits. */ 281bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INPUTS: 282bf215546Sopenharmony_ci /* 2 colors + 8 texcoords are always supported 283bf215546Sopenharmony_ci * (minus fog and wpos). 284bf215546Sopenharmony_ci * 285bf215546Sopenharmony_ci * R500 has the ability to turn 3rd and 4th color into 286bf215546Sopenharmony_ci * additional texcoords but there is no two-sided color 287bf215546Sopenharmony_ci * selection then. However the facing bit can be used instead. */ 288bf215546Sopenharmony_ci return 10; 289bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_OUTPUTS: 290bf215546Sopenharmony_ci return 4; 291bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE: 292bf215546Sopenharmony_ci return (is_r500 ? 256 : 32) * sizeof(float[4]); 293bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: 294bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE: 295bf215546Sopenharmony_ci return 1; 296bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEMPS: 297bf215546Sopenharmony_ci return is_r500 ? 128 : is_r400 ? 64 : 32; 298bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: 299bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: 300bf215546Sopenharmony_ci return r300screen->caps.num_tex_units; 301bf215546Sopenharmony_ci case PIPE_SHADER_CAP_CONT_SUPPORTED: 302bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED: 303bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: 304bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: 305bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: 306bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: 307bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUBROUTINES: 308bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INTEGERS: 309bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT64_ATOMICS: 310bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16: 311bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_DERIVATIVES: 312bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_CONST_BUFFERS: 313bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT16: 314bf215546Sopenharmony_ci case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS: 315bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DROUND_SUPPORTED: 316bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED: 317bf215546Sopenharmony_ci case PIPE_SHADER_CAP_LDEXP_SUPPORTED: 318bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS: 319bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_IMAGES: 320bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS: 321bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS: 322bf215546Sopenharmony_ci return 0; 323bf215546Sopenharmony_ci default: 324bf215546Sopenharmony_ci break; 325bf215546Sopenharmony_ci } 326bf215546Sopenharmony_ci break; 327bf215546Sopenharmony_ci case PIPE_SHADER_VERTEX: 328bf215546Sopenharmony_ci switch (param) 329bf215546Sopenharmony_ci { 330bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: 331bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: 332bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUBROUTINES: 333bf215546Sopenharmony_ci return 0; 334bf215546Sopenharmony_ci default:; 335bf215546Sopenharmony_ci } 336bf215546Sopenharmony_ci 337bf215546Sopenharmony_ci if (!r300screen->caps.has_tcl) { 338bf215546Sopenharmony_ci switch (param) { 339bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS: 340bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_IMAGES: 341bf215546Sopenharmony_ci return 0; 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci /* mesa/st requires that this cap is the same across stages, and the FS 344bf215546Sopenharmony_ci * can't do ints. 345bf215546Sopenharmony_ci */ 346bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INTEGERS: 347bf215546Sopenharmony_ci return 0; 348bf215546Sopenharmony_ci 349bf215546Sopenharmony_ci /* Even if gallivm NIR can do this, we call nir_to_tgsi manually and 350bf215546Sopenharmony_ci * TGSI can't. 351bf215546Sopenharmony_ci */ 352bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT16: 353bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16: 354bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_DERIVATIVES: 355bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_CONST_BUFFERS: 356bf215546Sopenharmony_ci return 0; 357bf215546Sopenharmony_ci 358bf215546Sopenharmony_ci /* While draw could normally handle this for the VS, the NIR lowering 359bf215546Sopenharmony_ci * to regs can't handle our non-native-integers, so we have to lower to 360bf215546Sopenharmony_ci * if ladders. 361bf215546Sopenharmony_ci */ 362bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: 363bf215546Sopenharmony_ci return 0; 364bf215546Sopenharmony_ci default: 365bf215546Sopenharmony_ci return draw_get_shader_param(shader, param); 366bf215546Sopenharmony_ci } 367bf215546Sopenharmony_ci } 368bf215546Sopenharmony_ci 369bf215546Sopenharmony_ci switch (param) 370bf215546Sopenharmony_ci { 371bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INSTRUCTIONS: 372bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS: 373bf215546Sopenharmony_ci return is_r500 ? 1024 : 256; 374bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH: 375bf215546Sopenharmony_ci return is_r500 ? 4 : 0; /* For loops; not sure about conditionals. */ 376bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_INPUTS: 377bf215546Sopenharmony_ci return 16; 378bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_OUTPUTS: 379bf215546Sopenharmony_ci return 10; 380bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFER0_SIZE: 381bf215546Sopenharmony_ci return 256 * sizeof(float[4]); 382bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_CONST_BUFFERS: 383bf215546Sopenharmony_ci return 1; 384bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEMPS: 385bf215546Sopenharmony_ci return 32; 386bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR: 387bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_ANY_INOUT_DECL_RANGE: 388bf215546Sopenharmony_ci return 1; 389bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS: 390bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS: 391bf215546Sopenharmony_ci case PIPE_SHADER_CAP_CONT_SUPPORTED: 392bf215546Sopenharmony_ci case PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED: 393bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: 394bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: 395bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: 396bf215546Sopenharmony_ci case PIPE_SHADER_CAP_SUBROUTINES: 397bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INTEGERS: 398bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16: 399bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_CONST_BUFFERS: 400bf215546Sopenharmony_ci case PIPE_SHADER_CAP_FP16_DERIVATIVES: 401bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT16: 402bf215546Sopenharmony_ci case PIPE_SHADER_CAP_GLSL_16BIT_CONSTS: 403bf215546Sopenharmony_ci case PIPE_SHADER_CAP_INT64_ATOMICS: 404bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: 405bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: 406bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DROUND_SUPPORTED: 407bf215546Sopenharmony_ci case PIPE_SHADER_CAP_DFRACEXP_DLDEXP_SUPPORTED: 408bf215546Sopenharmony_ci case PIPE_SHADER_CAP_LDEXP_SUPPORTED: 409bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_BUFFERS: 410bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_SHADER_IMAGES: 411bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTERS: 412bf215546Sopenharmony_ci case PIPE_SHADER_CAP_MAX_HW_ATOMIC_COUNTER_BUFFERS: 413bf215546Sopenharmony_ci return 0; 414bf215546Sopenharmony_ci default: 415bf215546Sopenharmony_ci break; 416bf215546Sopenharmony_ci } 417bf215546Sopenharmony_ci break; 418bf215546Sopenharmony_ci default: 419bf215546Sopenharmony_ci ; /* nothing */ 420bf215546Sopenharmony_ci } 421bf215546Sopenharmony_ci return 0; 422bf215546Sopenharmony_ci} 423bf215546Sopenharmony_ci 424bf215546Sopenharmony_cistatic float r300_get_paramf(struct pipe_screen* pscreen, 425bf215546Sopenharmony_ci enum pipe_capf param) 426bf215546Sopenharmony_ci{ 427bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 428bf215546Sopenharmony_ci 429bf215546Sopenharmony_ci switch (param) { 430bf215546Sopenharmony_ci case PIPE_CAPF_MIN_LINE_WIDTH: 431bf215546Sopenharmony_ci case PIPE_CAPF_MIN_LINE_WIDTH_AA: 432bf215546Sopenharmony_ci case PIPE_CAPF_MIN_POINT_SIZE: 433bf215546Sopenharmony_ci case PIPE_CAPF_MIN_POINT_SIZE_AA: 434bf215546Sopenharmony_ci return 1; 435bf215546Sopenharmony_ci case PIPE_CAPF_POINT_SIZE_GRANULARITY: 436bf215546Sopenharmony_ci case PIPE_CAPF_LINE_WIDTH_GRANULARITY: 437bf215546Sopenharmony_ci return 0.1; 438bf215546Sopenharmony_ci case PIPE_CAPF_MAX_LINE_WIDTH: 439bf215546Sopenharmony_ci case PIPE_CAPF_MAX_LINE_WIDTH_AA: 440bf215546Sopenharmony_ci case PIPE_CAPF_MAX_POINT_SIZE: 441bf215546Sopenharmony_ci case PIPE_CAPF_MAX_POINT_SIZE_AA: 442bf215546Sopenharmony_ci /* The maximum dimensions of the colorbuffer are our practical 443bf215546Sopenharmony_ci * rendering limits. 2048 pixels should be enough for anybody. */ 444bf215546Sopenharmony_ci if (r300screen->caps.is_r500) { 445bf215546Sopenharmony_ci return 4096.0f; 446bf215546Sopenharmony_ci } else if (r300screen->caps.is_r400) { 447bf215546Sopenharmony_ci return 4021.0f; 448bf215546Sopenharmony_ci } else { 449bf215546Sopenharmony_ci return 2560.0f; 450bf215546Sopenharmony_ci } 451bf215546Sopenharmony_ci case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY: 452bf215546Sopenharmony_ci return 16.0f; 453bf215546Sopenharmony_ci case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS: 454bf215546Sopenharmony_ci return 16.0f; 455bf215546Sopenharmony_ci case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE: 456bf215546Sopenharmony_ci case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE: 457bf215546Sopenharmony_ci case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY: 458bf215546Sopenharmony_ci return 0.0f; 459bf215546Sopenharmony_ci default: 460bf215546Sopenharmony_ci debug_printf("r300: Warning: Unknown CAP %d in get_paramf.\n", 461bf215546Sopenharmony_ci param); 462bf215546Sopenharmony_ci return 0.0f; 463bf215546Sopenharmony_ci } 464bf215546Sopenharmony_ci} 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_cistatic int r300_get_video_param(struct pipe_screen *screen, 467bf215546Sopenharmony_ci enum pipe_video_profile profile, 468bf215546Sopenharmony_ci enum pipe_video_entrypoint entrypoint, 469bf215546Sopenharmony_ci enum pipe_video_cap param) 470bf215546Sopenharmony_ci{ 471bf215546Sopenharmony_ci switch (param) { 472bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_SUPPORTED: 473bf215546Sopenharmony_ci return vl_profile_supported(screen, profile, entrypoint); 474bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_NPOT_TEXTURES: 475bf215546Sopenharmony_ci return 0; 476bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_MAX_WIDTH: 477bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_MAX_HEIGHT: 478bf215546Sopenharmony_ci return vl_video_buffer_max_size(screen); 479bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_PREFERED_FORMAT: 480bf215546Sopenharmony_ci return PIPE_FORMAT_NV12; 481bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_PREFERS_INTERLACED: 482bf215546Sopenharmony_ci return false; 483bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED: 484bf215546Sopenharmony_ci return false; 485bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE: 486bf215546Sopenharmony_ci return true; 487bf215546Sopenharmony_ci case PIPE_VIDEO_CAP_MAX_LEVEL: 488bf215546Sopenharmony_ci return vl_level_supported(screen, profile); 489bf215546Sopenharmony_ci default: 490bf215546Sopenharmony_ci return 0; 491bf215546Sopenharmony_ci } 492bf215546Sopenharmony_ci} 493bf215546Sopenharmony_ci 494bf215546Sopenharmony_ci#define COMMON_NIR_OPTIONS \ 495bf215546Sopenharmony_ci .fdot_replicates = true, \ 496bf215546Sopenharmony_ci .fuse_ffma32 = true, \ 497bf215546Sopenharmony_ci .fuse_ffma64 = true, \ 498bf215546Sopenharmony_ci .lower_bitops = true, \ 499bf215546Sopenharmony_ci .lower_extract_byte = true, \ 500bf215546Sopenharmony_ci .lower_extract_word = true, \ 501bf215546Sopenharmony_ci .lower_fdiv = true, \ 502bf215546Sopenharmony_ci .lower_fdph = true, \ 503bf215546Sopenharmony_ci .lower_flrp32 = true, \ 504bf215546Sopenharmony_ci .lower_flrp64 = true, \ 505bf215546Sopenharmony_ci .lower_fmod = true, \ 506bf215546Sopenharmony_ci .lower_fround_even = true, \ 507bf215546Sopenharmony_ci .lower_insert_byte = true, \ 508bf215546Sopenharmony_ci .lower_insert_word = true, \ 509bf215546Sopenharmony_ci .lower_rotate = true, \ 510bf215546Sopenharmony_ci .lower_uniforms_to_ubo = true, \ 511bf215546Sopenharmony_ci .lower_vector_cmp = true, \ 512bf215546Sopenharmony_ci .no_integers = true, \ 513bf215546Sopenharmony_ci .use_interpolated_input_intrinsics = true 514bf215546Sopenharmony_ci 515bf215546Sopenharmony_cistatic const nir_shader_compiler_options r500_vs_compiler_options = { 516bf215546Sopenharmony_ci COMMON_NIR_OPTIONS, 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_ci /* Have HW loops support and 1024 max instr count, but don't unroll *too* 519bf215546Sopenharmony_ci * hard. 520bf215546Sopenharmony_ci */ 521bf215546Sopenharmony_ci .max_unroll_iterations = 32, 522bf215546Sopenharmony_ci}; 523bf215546Sopenharmony_ci 524bf215546Sopenharmony_cistatic const nir_shader_compiler_options r500_fs_compiler_options = { 525bf215546Sopenharmony_ci COMMON_NIR_OPTIONS, 526bf215546Sopenharmony_ci .lower_fpow = true, /* POW is only in the VS */ 527bf215546Sopenharmony_ci 528bf215546Sopenharmony_ci /* Have HW loops support and 512 max instr count, but don't unroll *too* 529bf215546Sopenharmony_ci * hard. 530bf215546Sopenharmony_ci */ 531bf215546Sopenharmony_ci .max_unroll_iterations = 32, 532bf215546Sopenharmony_ci}; 533bf215546Sopenharmony_ci 534bf215546Sopenharmony_cistatic const nir_shader_compiler_options r300_vs_compiler_options = { 535bf215546Sopenharmony_ci COMMON_NIR_OPTIONS, 536bf215546Sopenharmony_ci .lower_fsat = true, /* No fsat in pre-r500 VS */ 537bf215546Sopenharmony_ci .lower_sincos = true, 538bf215546Sopenharmony_ci 539bf215546Sopenharmony_ci /* Note: has HW loops support, but only 256 ALU instructions. */ 540bf215546Sopenharmony_ci .max_unroll_iterations = 32, 541bf215546Sopenharmony_ci}; 542bf215546Sopenharmony_ci 543bf215546Sopenharmony_cistatic const nir_shader_compiler_options r300_fs_compiler_options = { 544bf215546Sopenharmony_ci COMMON_NIR_OPTIONS, 545bf215546Sopenharmony_ci .lower_fpow = true, /* POW is only in the VS */ 546bf215546Sopenharmony_ci .lower_sincos = true, 547bf215546Sopenharmony_ci 548bf215546Sopenharmony_ci /* No HW loops support, so set it equal to ALU instr max */ 549bf215546Sopenharmony_ci .max_unroll_iterations = 64, 550bf215546Sopenharmony_ci}; 551bf215546Sopenharmony_ci 552bf215546Sopenharmony_cistatic const void * 553bf215546Sopenharmony_cir300_get_compiler_options(struct pipe_screen *pscreen, 554bf215546Sopenharmony_ci enum pipe_shader_ir ir, 555bf215546Sopenharmony_ci enum pipe_shader_type shader) 556bf215546Sopenharmony_ci{ 557bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_ci assert(ir == PIPE_SHADER_IR_NIR); 560bf215546Sopenharmony_ci 561bf215546Sopenharmony_ci if (r300screen->caps.is_r500) { 562bf215546Sopenharmony_ci if (shader == PIPE_SHADER_VERTEX) 563bf215546Sopenharmony_ci return &r500_vs_compiler_options; 564bf215546Sopenharmony_ci else 565bf215546Sopenharmony_ci return &r500_fs_compiler_options; 566bf215546Sopenharmony_ci } else { 567bf215546Sopenharmony_ci if (shader == PIPE_SHADER_VERTEX) 568bf215546Sopenharmony_ci return &r300_vs_compiler_options; 569bf215546Sopenharmony_ci else 570bf215546Sopenharmony_ci return &r300_fs_compiler_options; 571bf215546Sopenharmony_ci } 572bf215546Sopenharmony_ci} 573bf215546Sopenharmony_ci 574bf215546Sopenharmony_ci/** 575bf215546Sopenharmony_ci * Whether the format matches: 576bf215546Sopenharmony_ci * PIPE_FORMAT_?10?10?10?2_UNORM 577bf215546Sopenharmony_ci */ 578bf215546Sopenharmony_cistatic inline boolean 579bf215546Sopenharmony_ciutil_format_is_rgba1010102_variant(const struct util_format_description *desc) 580bf215546Sopenharmony_ci{ 581bf215546Sopenharmony_ci static const unsigned size[4] = {10, 10, 10, 2}; 582bf215546Sopenharmony_ci unsigned chan; 583bf215546Sopenharmony_ci 584bf215546Sopenharmony_ci if (desc->block.width != 1 || 585bf215546Sopenharmony_ci desc->block.height != 1 || 586bf215546Sopenharmony_ci desc->block.bits != 32) 587bf215546Sopenharmony_ci return FALSE; 588bf215546Sopenharmony_ci 589bf215546Sopenharmony_ci for (chan = 0; chan < 4; ++chan) { 590bf215546Sopenharmony_ci if(desc->channel[chan].type != UTIL_FORMAT_TYPE_UNSIGNED && 591bf215546Sopenharmony_ci desc->channel[chan].type != UTIL_FORMAT_TYPE_VOID) 592bf215546Sopenharmony_ci return FALSE; 593bf215546Sopenharmony_ci if (desc->channel[chan].size != size[chan]) 594bf215546Sopenharmony_ci return FALSE; 595bf215546Sopenharmony_ci } 596bf215546Sopenharmony_ci 597bf215546Sopenharmony_ci return TRUE; 598bf215546Sopenharmony_ci} 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_cistatic bool r300_is_blending_supported(struct r300_screen *rscreen, 601bf215546Sopenharmony_ci enum pipe_format format) 602bf215546Sopenharmony_ci{ 603bf215546Sopenharmony_ci int c; 604bf215546Sopenharmony_ci const struct util_format_description *desc = 605bf215546Sopenharmony_ci util_format_description(format); 606bf215546Sopenharmony_ci 607bf215546Sopenharmony_ci if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) 608bf215546Sopenharmony_ci return false; 609bf215546Sopenharmony_ci 610bf215546Sopenharmony_ci c = util_format_get_first_non_void_channel(format); 611bf215546Sopenharmony_ci 612bf215546Sopenharmony_ci /* RGBA16F */ 613bf215546Sopenharmony_ci if (rscreen->caps.is_r500 && 614bf215546Sopenharmony_ci desc->nr_channels == 4 && 615bf215546Sopenharmony_ci desc->channel[c].size == 16 && 616bf215546Sopenharmony_ci desc->channel[c].type == UTIL_FORMAT_TYPE_FLOAT) 617bf215546Sopenharmony_ci return true; 618bf215546Sopenharmony_ci 619bf215546Sopenharmony_ci if (desc->channel[c].normalized && 620bf215546Sopenharmony_ci desc->channel[c].type == UTIL_FORMAT_TYPE_UNSIGNED && 621bf215546Sopenharmony_ci desc->channel[c].size >= 4 && 622bf215546Sopenharmony_ci desc->channel[c].size <= 10) { 623bf215546Sopenharmony_ci /* RGB10_A2, RGBA8, RGB5_A1, RGBA4, RGB565 */ 624bf215546Sopenharmony_ci if (desc->nr_channels >= 3) 625bf215546Sopenharmony_ci return true; 626bf215546Sopenharmony_ci 627bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8G8_UNORM) 628bf215546Sopenharmony_ci return true; 629bf215546Sopenharmony_ci 630bf215546Sopenharmony_ci /* R8, I8, L8, A8 */ 631bf215546Sopenharmony_ci if (desc->nr_channels == 1) 632bf215546Sopenharmony_ci return true; 633bf215546Sopenharmony_ci } 634bf215546Sopenharmony_ci 635bf215546Sopenharmony_ci return false; 636bf215546Sopenharmony_ci} 637bf215546Sopenharmony_ci 638bf215546Sopenharmony_cistatic bool r300_is_format_supported(struct pipe_screen* screen, 639bf215546Sopenharmony_ci enum pipe_format format, 640bf215546Sopenharmony_ci enum pipe_texture_target target, 641bf215546Sopenharmony_ci unsigned sample_count, 642bf215546Sopenharmony_ci unsigned storage_sample_count, 643bf215546Sopenharmony_ci unsigned usage) 644bf215546Sopenharmony_ci{ 645bf215546Sopenharmony_ci uint32_t retval = 0; 646bf215546Sopenharmony_ci boolean is_r500 = r300_screen(screen)->caps.is_r500; 647bf215546Sopenharmony_ci boolean is_r400 = r300_screen(screen)->caps.is_r400; 648bf215546Sopenharmony_ci boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM || 649bf215546Sopenharmony_ci format == PIPE_FORMAT_R10G10B10X2_SNORM || 650bf215546Sopenharmony_ci format == PIPE_FORMAT_B10G10R10A2_UNORM || 651bf215546Sopenharmony_ci format == PIPE_FORMAT_B10G10R10X2_UNORM || 652bf215546Sopenharmony_ci format == PIPE_FORMAT_R10SG10SB10SA2U_NORM; 653bf215546Sopenharmony_ci boolean is_ati1n = format == PIPE_FORMAT_RGTC1_UNORM || 654bf215546Sopenharmony_ci format == PIPE_FORMAT_RGTC1_SNORM || 655bf215546Sopenharmony_ci format == PIPE_FORMAT_LATC1_UNORM || 656bf215546Sopenharmony_ci format == PIPE_FORMAT_LATC1_SNORM; 657bf215546Sopenharmony_ci boolean is_ati2n = format == PIPE_FORMAT_RGTC2_UNORM || 658bf215546Sopenharmony_ci format == PIPE_FORMAT_RGTC2_SNORM || 659bf215546Sopenharmony_ci format == PIPE_FORMAT_LATC2_UNORM || 660bf215546Sopenharmony_ci format == PIPE_FORMAT_LATC2_SNORM; 661bf215546Sopenharmony_ci boolean is_half_float = format == PIPE_FORMAT_R16_FLOAT || 662bf215546Sopenharmony_ci format == PIPE_FORMAT_R16G16_FLOAT || 663bf215546Sopenharmony_ci format == PIPE_FORMAT_R16G16B16_FLOAT || 664bf215546Sopenharmony_ci format == PIPE_FORMAT_R16G16B16A16_FLOAT || 665bf215546Sopenharmony_ci format == PIPE_FORMAT_R16G16B16X16_FLOAT; 666bf215546Sopenharmony_ci const struct util_format_description *desc; 667bf215546Sopenharmony_ci 668bf215546Sopenharmony_ci if (MAX2(1, sample_count) != MAX2(1, storage_sample_count)) 669bf215546Sopenharmony_ci return false; 670bf215546Sopenharmony_ci 671bf215546Sopenharmony_ci /* Check multisampling support. */ 672bf215546Sopenharmony_ci switch (sample_count) { 673bf215546Sopenharmony_ci case 0: 674bf215546Sopenharmony_ci case 1: 675bf215546Sopenharmony_ci break; 676bf215546Sopenharmony_ci case 2: 677bf215546Sopenharmony_ci case 4: 678bf215546Sopenharmony_ci case 6: 679bf215546Sopenharmony_ci /* No texturing and scanout. */ 680bf215546Sopenharmony_ci if (usage & (PIPE_BIND_SAMPLER_VIEW | 681bf215546Sopenharmony_ci PIPE_BIND_DISPLAY_TARGET | 682bf215546Sopenharmony_ci PIPE_BIND_SCANOUT)) { 683bf215546Sopenharmony_ci return false; 684bf215546Sopenharmony_ci } 685bf215546Sopenharmony_ci 686bf215546Sopenharmony_ci desc = util_format_description(format); 687bf215546Sopenharmony_ci 688bf215546Sopenharmony_ci if (is_r500) { 689bf215546Sopenharmony_ci /* Only allow depth/stencil, RGBA8, RGBA1010102, RGBA16F. */ 690bf215546Sopenharmony_ci if (!util_format_is_depth_or_stencil(format) && 691bf215546Sopenharmony_ci !util_format_is_rgba8_variant(desc) && 692bf215546Sopenharmony_ci !util_format_is_rgba1010102_variant(desc) && 693bf215546Sopenharmony_ci format != PIPE_FORMAT_R16G16B16A16_FLOAT && 694bf215546Sopenharmony_ci format != PIPE_FORMAT_R16G16B16X16_FLOAT) { 695bf215546Sopenharmony_ci return false; 696bf215546Sopenharmony_ci } 697bf215546Sopenharmony_ci } else { 698bf215546Sopenharmony_ci /* Only allow depth/stencil, RGBA8. */ 699bf215546Sopenharmony_ci if (!util_format_is_depth_or_stencil(format) && 700bf215546Sopenharmony_ci !util_format_is_rgba8_variant(desc)) { 701bf215546Sopenharmony_ci return false; 702bf215546Sopenharmony_ci } 703bf215546Sopenharmony_ci } 704bf215546Sopenharmony_ci break; 705bf215546Sopenharmony_ci default: 706bf215546Sopenharmony_ci return false; 707bf215546Sopenharmony_ci } 708bf215546Sopenharmony_ci 709bf215546Sopenharmony_ci /* Check sampler format support. */ 710bf215546Sopenharmony_ci if ((usage & PIPE_BIND_SAMPLER_VIEW) && 711bf215546Sopenharmony_ci /* these two are broken for an unknown reason */ 712bf215546Sopenharmony_ci format != PIPE_FORMAT_R8G8B8X8_SNORM && 713bf215546Sopenharmony_ci format != PIPE_FORMAT_R16G16B16X16_SNORM && 714bf215546Sopenharmony_ci /* ATI1N is r5xx-only. */ 715bf215546Sopenharmony_ci (is_r500 || !is_ati1n) && 716bf215546Sopenharmony_ci /* ATI2N is supported on r4xx-r5xx. */ 717bf215546Sopenharmony_ci (is_r400 || is_r500 || !is_ati2n) && 718bf215546Sopenharmony_ci r300_is_sampler_format_supported(format)) { 719bf215546Sopenharmony_ci retval |= PIPE_BIND_SAMPLER_VIEW; 720bf215546Sopenharmony_ci } 721bf215546Sopenharmony_ci 722bf215546Sopenharmony_ci /* Check colorbuffer format support. */ 723bf215546Sopenharmony_ci if ((usage & (PIPE_BIND_RENDER_TARGET | 724bf215546Sopenharmony_ci PIPE_BIND_DISPLAY_TARGET | 725bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | 726bf215546Sopenharmony_ci PIPE_BIND_SHARED | 727bf215546Sopenharmony_ci PIPE_BIND_BLENDABLE)) && 728bf215546Sopenharmony_ci /* 2101010 cannot be rendered to on non-r5xx. */ 729bf215546Sopenharmony_ci (!is_color2101010 || is_r500) && 730bf215546Sopenharmony_ci r300_is_colorbuffer_format_supported(format)) { 731bf215546Sopenharmony_ci retval |= usage & 732bf215546Sopenharmony_ci (PIPE_BIND_RENDER_TARGET | 733bf215546Sopenharmony_ci PIPE_BIND_DISPLAY_TARGET | 734bf215546Sopenharmony_ci PIPE_BIND_SCANOUT | 735bf215546Sopenharmony_ci PIPE_BIND_SHARED); 736bf215546Sopenharmony_ci 737bf215546Sopenharmony_ci if (r300_is_blending_supported(r300_screen(screen), format)) { 738bf215546Sopenharmony_ci retval |= usage & PIPE_BIND_BLENDABLE; 739bf215546Sopenharmony_ci } 740bf215546Sopenharmony_ci } 741bf215546Sopenharmony_ci 742bf215546Sopenharmony_ci /* Check depth-stencil format support. */ 743bf215546Sopenharmony_ci if (usage & PIPE_BIND_DEPTH_STENCIL && 744bf215546Sopenharmony_ci r300_is_zs_format_supported(format)) { 745bf215546Sopenharmony_ci retval |= PIPE_BIND_DEPTH_STENCIL; 746bf215546Sopenharmony_ci } 747bf215546Sopenharmony_ci 748bf215546Sopenharmony_ci /* Check vertex buffer format support. */ 749bf215546Sopenharmony_ci if (usage & PIPE_BIND_VERTEX_BUFFER) { 750bf215546Sopenharmony_ci if (r300_screen(screen)->caps.has_tcl) { 751bf215546Sopenharmony_ci /* Half float is supported on >= R400. */ 752bf215546Sopenharmony_ci if ((is_r400 || is_r500 || !is_half_float) && 753bf215546Sopenharmony_ci r300_translate_vertex_data_type(format) != R300_INVALID_FORMAT) { 754bf215546Sopenharmony_ci retval |= PIPE_BIND_VERTEX_BUFFER; 755bf215546Sopenharmony_ci } 756bf215546Sopenharmony_ci } else { 757bf215546Sopenharmony_ci /* SW TCL */ 758bf215546Sopenharmony_ci if (!util_format_is_pure_integer(format)) { 759bf215546Sopenharmony_ci retval |= PIPE_BIND_VERTEX_BUFFER; 760bf215546Sopenharmony_ci } 761bf215546Sopenharmony_ci } 762bf215546Sopenharmony_ci } 763bf215546Sopenharmony_ci 764bf215546Sopenharmony_ci if (usage & PIPE_BIND_INDEX_BUFFER) { 765bf215546Sopenharmony_ci if (format == PIPE_FORMAT_R8_UINT || 766bf215546Sopenharmony_ci format == PIPE_FORMAT_R16_UINT || 767bf215546Sopenharmony_ci format == PIPE_FORMAT_R32_UINT) 768bf215546Sopenharmony_ci retval |= PIPE_BIND_INDEX_BUFFER; 769bf215546Sopenharmony_ci } 770bf215546Sopenharmony_ci 771bf215546Sopenharmony_ci return retval == usage; 772bf215546Sopenharmony_ci} 773bf215546Sopenharmony_ci 774bf215546Sopenharmony_cistatic void r300_destroy_screen(struct pipe_screen* pscreen) 775bf215546Sopenharmony_ci{ 776bf215546Sopenharmony_ci struct r300_screen* r300screen = r300_screen(pscreen); 777bf215546Sopenharmony_ci struct radeon_winsys *rws = radeon_winsys(pscreen); 778bf215546Sopenharmony_ci 779bf215546Sopenharmony_ci if (rws && !rws->unref(rws)) 780bf215546Sopenharmony_ci return; 781bf215546Sopenharmony_ci 782bf215546Sopenharmony_ci mtx_destroy(&r300screen->cmask_mutex); 783bf215546Sopenharmony_ci slab_destroy_parent(&r300screen->pool_transfers); 784bf215546Sopenharmony_ci 785bf215546Sopenharmony_ci disk_cache_destroy(r300screen->disk_shader_cache); 786bf215546Sopenharmony_ci 787bf215546Sopenharmony_ci if (rws) 788bf215546Sopenharmony_ci rws->destroy(rws); 789bf215546Sopenharmony_ci 790bf215546Sopenharmony_ci FREE(r300screen); 791bf215546Sopenharmony_ci} 792bf215546Sopenharmony_ci 793bf215546Sopenharmony_cistatic void r300_fence_reference(struct pipe_screen *screen, 794bf215546Sopenharmony_ci struct pipe_fence_handle **ptr, 795bf215546Sopenharmony_ci struct pipe_fence_handle *fence) 796bf215546Sopenharmony_ci{ 797bf215546Sopenharmony_ci struct radeon_winsys *rws = r300_screen(screen)->rws; 798bf215546Sopenharmony_ci 799bf215546Sopenharmony_ci rws->fence_reference(ptr, fence); 800bf215546Sopenharmony_ci} 801bf215546Sopenharmony_ci 802bf215546Sopenharmony_cistatic bool r300_fence_finish(struct pipe_screen *screen, 803bf215546Sopenharmony_ci struct pipe_context *ctx, 804bf215546Sopenharmony_ci struct pipe_fence_handle *fence, 805bf215546Sopenharmony_ci uint64_t timeout) 806bf215546Sopenharmony_ci{ 807bf215546Sopenharmony_ci struct radeon_winsys *rws = r300_screen(screen)->rws; 808bf215546Sopenharmony_ci 809bf215546Sopenharmony_ci return rws->fence_wait(rws, fence, timeout); 810bf215546Sopenharmony_ci} 811bf215546Sopenharmony_ci 812bf215546Sopenharmony_cistruct pipe_screen* r300_screen_create(struct radeon_winsys *rws, 813bf215546Sopenharmony_ci const struct pipe_screen_config *config) 814bf215546Sopenharmony_ci{ 815bf215546Sopenharmony_ci struct r300_screen *r300screen = CALLOC_STRUCT(r300_screen); 816bf215546Sopenharmony_ci 817bf215546Sopenharmony_ci if (!r300screen) { 818bf215546Sopenharmony_ci FREE(r300screen); 819bf215546Sopenharmony_ci return NULL; 820bf215546Sopenharmony_ci } 821bf215546Sopenharmony_ci 822bf215546Sopenharmony_ci rws->query_info(rws, &r300screen->info, false, false); 823bf215546Sopenharmony_ci 824bf215546Sopenharmony_ci r300_init_debug(r300screen); 825bf215546Sopenharmony_ci r300_parse_chipset(r300screen->info.pci_id, &r300screen->caps); 826bf215546Sopenharmony_ci 827bf215546Sopenharmony_ci if (SCREEN_DBG_ON(r300screen, DBG_NO_ZMASK)) 828bf215546Sopenharmony_ci r300screen->caps.zmask_ram = 0; 829bf215546Sopenharmony_ci if (SCREEN_DBG_ON(r300screen, DBG_NO_HIZ)) 830bf215546Sopenharmony_ci r300screen->caps.hiz_ram = 0; 831bf215546Sopenharmony_ci if (SCREEN_DBG_ON(r300screen, DBG_NO_TCL)) 832bf215546Sopenharmony_ci r300screen->caps.has_tcl = FALSE; 833bf215546Sopenharmony_ci 834bf215546Sopenharmony_ci r300screen->rws = rws; 835bf215546Sopenharmony_ci r300screen->screen.destroy = r300_destroy_screen; 836bf215546Sopenharmony_ci r300screen->screen.get_name = r300_get_name; 837bf215546Sopenharmony_ci r300screen->screen.get_vendor = r300_get_vendor; 838bf215546Sopenharmony_ci r300screen->screen.get_compiler_options = r300_get_compiler_options; 839bf215546Sopenharmony_ci r300screen->screen.get_device_vendor = r300_get_device_vendor; 840bf215546Sopenharmony_ci r300screen->screen.get_disk_shader_cache = r300_get_disk_shader_cache; 841bf215546Sopenharmony_ci r300screen->screen.get_param = r300_get_param; 842bf215546Sopenharmony_ci r300screen->screen.get_shader_param = r300_get_shader_param; 843bf215546Sopenharmony_ci r300screen->screen.get_paramf = r300_get_paramf; 844bf215546Sopenharmony_ci r300screen->screen.get_video_param = r300_get_video_param; 845bf215546Sopenharmony_ci r300screen->screen.is_format_supported = r300_is_format_supported; 846bf215546Sopenharmony_ci r300screen->screen.is_video_format_supported = vl_video_buffer_is_format_supported; 847bf215546Sopenharmony_ci r300screen->screen.context_create = r300_create_context; 848bf215546Sopenharmony_ci r300screen->screen.fence_reference = r300_fence_reference; 849bf215546Sopenharmony_ci r300screen->screen.fence_finish = r300_fence_finish; 850bf215546Sopenharmony_ci 851bf215546Sopenharmony_ci r300_init_screen_resource_functions(r300screen); 852bf215546Sopenharmony_ci 853bf215546Sopenharmony_ci r300_disk_cache_create(r300screen); 854bf215546Sopenharmony_ci 855bf215546Sopenharmony_ci slab_create_parent(&r300screen->pool_transfers, sizeof(struct pipe_transfer), 64); 856bf215546Sopenharmony_ci 857bf215546Sopenharmony_ci (void) mtx_init(&r300screen->cmask_mutex, mtx_plain); 858bf215546Sopenharmony_ci 859bf215546Sopenharmony_ci return &r300screen->screen; 860bf215546Sopenharmony_ci} 861