2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
47 #include "addrlib/gfx9/chip/gfx9_enum.h"
48 #include "util/build_id.h"
49 #include "util/debug.h"
50 #include "util/mesa-sha1.h"
53 radv_get_build_id(void *ptr
, struct mesa_sha1
*ctx
)
57 #ifdef HAVE_DL_ITERATE_PHDR
58 const struct build_id_note
*note
= NULL
;
59 if ((note
= build_id_find_nhdr_for_addr(ptr
))) {
60 _mesa_sha1_update(ctx
, build_id_data(note
), build_id_length(note
));
63 if (disk_cache_get_function_timestamp(ptr
, ×tamp
)) {
64 _mesa_sha1_update(ctx
, ×tamp
, sizeof(timestamp
));
71 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
74 unsigned char sha1
[20];
75 unsigned ptr_size
= sizeof(void*);
77 memset(uuid
, 0, VK_UUID_SIZE
);
78 _mesa_sha1_init(&ctx
);
80 if (!radv_get_build_id(radv_device_get_cache_uuid
, &ctx
) ||
81 !radv_get_build_id(LLVMInitializeAMDGPUTargetInfo
, &ctx
))
84 _mesa_sha1_update(&ctx
, &family
, sizeof(family
));
85 _mesa_sha1_update(&ctx
, &ptr_size
, sizeof(ptr_size
));
86 _mesa_sha1_final(&ctx
, sha1
);
88 memcpy(uuid
, sha1
, VK_UUID_SIZE
);
93 radv_get_driver_uuid(void *uuid
)
95 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
99 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
101 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
105 radv_get_device_name(enum radeon_family family
, char *name
, size_t name_len
)
107 const char *chip_string
;
108 char llvm_string
[32] = {};
111 case CHIP_TAHITI
: chip_string
= "AMD RADV TAHITI"; break;
112 case CHIP_PITCAIRN
: chip_string
= "AMD RADV PITCAIRN"; break;
113 case CHIP_VERDE
: chip_string
= "AMD RADV CAPE VERDE"; break;
114 case CHIP_OLAND
: chip_string
= "AMD RADV OLAND"; break;
115 case CHIP_HAINAN
: chip_string
= "AMD RADV HAINAN"; break;
116 case CHIP_BONAIRE
: chip_string
= "AMD RADV BONAIRE"; break;
117 case CHIP_KAVERI
: chip_string
= "AMD RADV KAVERI"; break;
118 case CHIP_KABINI
: chip_string
= "AMD RADV KABINI"; break;
119 case CHIP_HAWAII
: chip_string
= "AMD RADV HAWAII"; break;
120 case CHIP_MULLINS
: chip_string
= "AMD RADV MULLINS"; break;
121 case CHIP_TONGA
: chip_string
= "AMD RADV TONGA"; break;
122 case CHIP_ICELAND
: chip_string
= "AMD RADV ICELAND"; break;
123 case CHIP_CARRIZO
: chip_string
= "AMD RADV CARRIZO"; break;
124 case CHIP_FIJI
: chip_string
= "AMD RADV FIJI"; break;
125 case CHIP_POLARIS10
: chip_string
= "AMD RADV POLARIS10"; break;
126 case CHIP_POLARIS11
: chip_string
= "AMD RADV POLARIS11"; break;
127 case CHIP_POLARIS12
: chip_string
= "AMD RADV POLARIS12"; break;
128 case CHIP_STONEY
: chip_string
= "AMD RADV STONEY"; break;
129 case CHIP_VEGAM
: chip_string
= "AMD RADV VEGA M"; break;
130 case CHIP_VEGA10
: chip_string
= "AMD RADV VEGA10"; break;
131 case CHIP_VEGA12
: chip_string
= "AMD RADV VEGA12"; break;
132 case CHIP_RAVEN
: chip_string
= "AMD RADV RAVEN"; break;
133 default: chip_string
= "AMD RADV unknown"; break;
136 snprintf(llvm_string
, sizeof(llvm_string
),
137 " (LLVM %i.%i.%i)", (HAVE_LLVM
>> 8) & 0xff,
138 HAVE_LLVM
& 0xff, MESA_LLVM_VERSION_PATCH
);
139 snprintf(name
, name_len
, "%s%s", chip_string
, llvm_string
);
143 radv_physical_device_init_mem_types(struct radv_physical_device
*device
)
145 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
146 uint64_t visible_vram_size
= MIN2(device
->rad_info
.vram_size
,
147 device
->rad_info
.vram_vis_size
);
149 int vram_index
= -1, visible_vram_index
= -1, gart_index
= -1;
150 device
->memory_properties
.memoryHeapCount
= 0;
151 if (device
->rad_info
.vram_size
- visible_vram_size
> 0) {
152 vram_index
= device
->memory_properties
.memoryHeapCount
++;
153 device
->memory_properties
.memoryHeaps
[vram_index
] = (VkMemoryHeap
) {
154 .size
= device
->rad_info
.vram_size
- visible_vram_size
,
155 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
158 if (visible_vram_size
) {
159 visible_vram_index
= device
->memory_properties
.memoryHeapCount
++;
160 device
->memory_properties
.memoryHeaps
[visible_vram_index
] = (VkMemoryHeap
) {
161 .size
= visible_vram_size
,
162 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
165 if (device
->rad_info
.gart_size
> 0) {
166 gart_index
= device
->memory_properties
.memoryHeapCount
++;
167 device
->memory_properties
.memoryHeaps
[gart_index
] = (VkMemoryHeap
) {
168 .size
= device
->rad_info
.gart_size
,
169 .flags
= device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
173 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
174 unsigned type_count
= 0;
175 if (vram_index
>= 0) {
176 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM
;
177 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
178 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
179 .heapIndex
= vram_index
,
182 if (gart_index
>= 0) {
183 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_WRITE_COMBINE
;
184 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
185 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
186 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
187 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
188 .heapIndex
= gart_index
,
191 if (visible_vram_index
>= 0) {
192 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_VRAM_CPU_ACCESS
;
193 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
194 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
195 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
196 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
197 .heapIndex
= visible_vram_index
,
200 if (gart_index
>= 0) {
201 device
->mem_type_indices
[type_count
] = RADV_MEM_TYPE_GTT_CACHED
;
202 device
->memory_properties
.memoryTypes
[type_count
++] = (VkMemoryType
) {
203 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
204 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
205 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
|
206 (device
->rad_info
.has_dedicated_vram
? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
),
207 .heapIndex
= gart_index
,
210 device
->memory_properties
.memoryTypeCount
= type_count
;
214 radv_handle_env_var_force_family(struct radv_physical_device
*device
)
216 const char *family
= getenv("RADV_FORCE_FAMILY");
222 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
223 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
224 /* Override family and chip_class. */
225 device
->rad_info
.family
= i
;
227 if (i
>= CHIP_VEGA10
)
228 device
->rad_info
.chip_class
= GFX9
;
229 else if (i
>= CHIP_TONGA
)
230 device
->rad_info
.chip_class
= VI
;
231 else if (i
>= CHIP_BONAIRE
)
232 device
->rad_info
.chip_class
= CIK
;
234 device
->rad_info
.chip_class
= SI
;
240 fprintf(stderr
, "radv: Unknown family: %s\n", family
);
245 radv_physical_device_init(struct radv_physical_device
*device
,
246 struct radv_instance
*instance
,
247 drmDevicePtr drm_device
)
249 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
251 drmVersionPtr version
;
255 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
257 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
258 radv_logi("Could not open device '%s'", path
);
260 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
263 version
= drmGetVersion(fd
);
267 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
268 radv_logi("Could not get the kernel driver version for device '%s'", path
);
270 return vk_errorf(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
,
271 "failed to get version %s: %m", path
);
274 if (strcmp(version
->name
, "amdgpu")) {
275 drmFreeVersion(version
);
280 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
281 radv_logi("Device '%s' is not using the amdgpu kernel driver.", path
);
283 return VK_ERROR_INCOMPATIBLE_DRIVER
;
285 drmFreeVersion(version
);
287 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
288 radv_logi("Found compatible device '%s'.", path
);
290 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
291 device
->instance
= instance
;
292 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
293 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
295 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
296 instance
->perftest_flags
);
298 result
= vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
302 if (instance
->enabled_extensions
.KHR_display
) {
303 master_fd
= open(drm_device
->nodes
[DRM_NODE_PRIMARY
], O_RDWR
| O_CLOEXEC
);
304 if (master_fd
>= 0) {
305 uint32_t accel_working
= 0;
306 struct drm_amdgpu_info request
= {
307 .return_pointer
= (uintptr_t)&accel_working
,
308 .return_size
= sizeof(accel_working
),
309 .query
= AMDGPU_INFO_ACCEL_WORKING
312 if (drmCommandWrite(master_fd
, DRM_AMDGPU_INFO
, &request
, sizeof (struct drm_amdgpu_info
)) < 0 || !accel_working
) {
319 device
->master_fd
= master_fd
;
320 device
->local_fd
= fd
;
321 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
323 radv_handle_env_var_force_family(device
);
325 radv_get_device_name(device
->rad_info
.family
, device
->name
, sizeof(device
->name
));
327 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
328 device
->ws
->destroy(device
->ws
);
329 result
= vk_errorf(instance
, VK_ERROR_INITIALIZATION_FAILED
,
330 "cannot generate UUID");
334 /* These flags affect shader compilation. */
335 uint64_t shader_env_flags
=
336 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
337 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
339 /* The gpu id is already embedded in the uuid so we just pass "radv"
340 * when creating the cache.
342 char buf
[VK_UUID_SIZE
* 2 + 1];
343 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
* 2);
344 device
->disk_cache
= disk_cache_create(device
->name
, buf
, shader_env_flags
);
346 if (device
->rad_info
.chip_class
< VI
||
347 device
->rad_info
.chip_class
> GFX9
)
348 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
350 radv_get_driver_uuid(&device
->device_uuid
);
351 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
353 if (device
->rad_info
.family
== CHIP_STONEY
||
354 device
->rad_info
.chip_class
>= GFX9
) {
355 device
->has_rbplus
= true;
356 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
||
357 device
->rad_info
.family
== CHIP_VEGA12
||
358 device
->rad_info
.family
== CHIP_RAVEN
;
361 /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
364 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
366 device
->cpdma_prefetch_writes_memory
= device
->rad_info
.chip_class
<= VI
;
368 /* Vega10/Raven need a special workaround for a hardware bug. */
369 device
->has_scissor_bug
= device
->rad_info
.family
== CHIP_VEGA10
||
370 device
->rad_info
.family
== CHIP_RAVEN
;
372 /* Out-of-order primitive rasterization. */
373 device
->has_out_of_order_rast
= device
->rad_info
.chip_class
>= VI
&&
374 device
->rad_info
.max_se
>= 2;
375 device
->out_of_order_rast_allowed
= device
->has_out_of_order_rast
&&
376 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_OUT_OF_ORDER
);
378 device
->dcc_msaa_allowed
=
379 (device
->instance
->perftest_flags
& RADV_PERFTEST_DCC_MSAA
);
381 radv_physical_device_init_mem_types(device
);
382 radv_fill_device_extension_table(device
, &device
->supported_extensions
);
384 result
= radv_init_wsi(device
);
385 if (result
!= VK_SUCCESS
) {
386 device
->ws
->destroy(device
->ws
);
387 vk_error(instance
, result
);
391 if ((device
->instance
->debug_flags
& RADV_DEBUG_INFO
))
392 ac_print_gpu_info(&device
->rad_info
);
404 radv_physical_device_finish(struct radv_physical_device
*device
)
406 radv_finish_wsi(device
);
407 device
->ws
->destroy(device
->ws
);
408 disk_cache_destroy(device
->disk_cache
);
409 close(device
->local_fd
);
410 if (device
->master_fd
!= -1)
411 close(device
->master_fd
);
415 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
416 VkSystemAllocationScope allocationScope
)
422 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
423 size_t align
, VkSystemAllocationScope allocationScope
)
425 return realloc(pOriginal
, size
);
429 default_free_func(void *pUserData
, void *pMemory
)
434 static const VkAllocationCallbacks default_alloc
= {
436 .pfnAllocation
= default_alloc_func
,
437 .pfnReallocation
= default_realloc_func
,
438 .pfnFree
= default_free_func
,
441 static const struct debug_control radv_debug_options
[] = {
442 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
443 {"nodcc", RADV_DEBUG_NO_DCC
},
444 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
445 {"nocache", RADV_DEBUG_NO_CACHE
},
446 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
447 {"nohiz", RADV_DEBUG_NO_HIZ
},
448 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
449 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
450 {"allbos", RADV_DEBUG_ALL_BOS
},
451 {"noibs", RADV_DEBUG_NO_IBS
},
452 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
453 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
454 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
455 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
456 {"nosisched", RADV_DEBUG_NO_SISCHED
},
457 {"preoptir", RADV_DEBUG_PREOPTIR
},
458 {"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS
},
459 {"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER
},
460 {"info", RADV_DEBUG_INFO
},
461 {"errors", RADV_DEBUG_ERRORS
},
462 {"startup", RADV_DEBUG_STARTUP
},
463 {"checkir", RADV_DEBUG_CHECKIR
},
464 {"nothreadllvm", RADV_DEBUG_NOTHREADLLVM
},
469 radv_get_debug_option_name(int id
)
471 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
472 return radv_debug_options
[id
].string
;
475 static const struct debug_control radv_perftest_options
[] = {
476 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
477 {"sisched", RADV_PERFTEST_SISCHED
},
478 {"localbos", RADV_PERFTEST_LOCAL_BOS
},
479 {"binning", RADV_PERFTEST_BINNING
},
480 {"dccmsaa", RADV_PERFTEST_DCC_MSAA
},
485 radv_get_perftest_option_name(int id
)
487 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
488 return radv_perftest_options
[id
].string
;
492 radv_handle_per_app_options(struct radv_instance
*instance
,
493 const VkApplicationInfo
*info
)
495 const char *name
= info
? info
->pApplicationName
: NULL
;
500 if (!strcmp(name
, "Talos - Linux - 32bit") ||
501 !strcmp(name
, "Talos - Linux - 64bit")) {
502 if (!(instance
->debug_flags
& RADV_DEBUG_NO_SISCHED
)) {
503 /* Force enable LLVM sisched for Talos because it looks
504 * safe and it gives few more FPS.
506 instance
->perftest_flags
|= RADV_PERFTEST_SISCHED
;
508 } else if (!strcmp(name
, "DOOM_VFR")) {
509 /* Work around a Doom VFR game bug */
510 instance
->debug_flags
|= RADV_DEBUG_NO_DYNAMIC_BOUNDS
;
514 static int radv_get_instance_extension_index(const char *name
)
516 for (unsigned i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; ++i
) {
517 if (strcmp(name
, radv_instance_extensions
[i
].extensionName
) == 0)
524 VkResult
radv_CreateInstance(
525 const VkInstanceCreateInfo
* pCreateInfo
,
526 const VkAllocationCallbacks
* pAllocator
,
527 VkInstance
* pInstance
)
529 struct radv_instance
*instance
;
532 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
534 uint32_t client_version
;
535 if (pCreateInfo
->pApplicationInfo
&&
536 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
537 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
539 radv_EnumerateInstanceVersion(&client_version
);
542 instance
= vk_zalloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
543 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
545 return vk_error(NULL
, VK_ERROR_OUT_OF_HOST_MEMORY
);
547 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
550 instance
->alloc
= *pAllocator
;
552 instance
->alloc
= default_alloc
;
554 instance
->apiVersion
= client_version
;
555 instance
->physicalDeviceCount
= -1;
557 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
560 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
561 radv_perftest_options
);
564 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
565 radv_logi("Created an instance");
567 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
568 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
569 int index
= radv_get_instance_extension_index(ext_name
);
571 if (index
< 0 || !radv_supported_instance_extensions
.extensions
[index
]) {
572 vk_free2(&default_alloc
, pAllocator
, instance
);
573 return vk_error(instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
576 instance
->enabled_extensions
.extensions
[index
] = true;
579 result
= vk_debug_report_instance_init(&instance
->debug_report_callbacks
);
580 if (result
!= VK_SUCCESS
) {
581 vk_free2(&default_alloc
, pAllocator
, instance
);
582 return vk_error(instance
, result
);
587 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
589 radv_handle_per_app_options(instance
, pCreateInfo
->pApplicationInfo
);
591 *pInstance
= radv_instance_to_handle(instance
);
596 void radv_DestroyInstance(
597 VkInstance _instance
,
598 const VkAllocationCallbacks
* pAllocator
)
600 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
605 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
606 radv_physical_device_finish(instance
->physicalDevices
+ i
);
609 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
613 vk_debug_report_instance_destroy(&instance
->debug_report_callbacks
);
615 vk_free(&instance
->alloc
, instance
);
619 radv_enumerate_devices(struct radv_instance
*instance
)
621 /* TODO: Check for more devices ? */
622 drmDevicePtr devices
[8];
623 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
626 instance
->physicalDeviceCount
= 0;
628 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
630 if (instance
->debug_flags
& RADV_DEBUG_STARTUP
)
631 radv_logi("Found %d drm nodes", max_devices
);
634 return vk_error(instance
, VK_ERROR_INCOMPATIBLE_DRIVER
);
636 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
637 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
638 devices
[i
]->bustype
== DRM_BUS_PCI
&&
639 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
641 result
= radv_physical_device_init(instance
->physicalDevices
+
642 instance
->physicalDeviceCount
,
645 if (result
== VK_SUCCESS
)
646 ++instance
->physicalDeviceCount
;
647 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
651 drmFreeDevices(devices
, max_devices
);
656 VkResult
radv_EnumeratePhysicalDevices(
657 VkInstance _instance
,
658 uint32_t* pPhysicalDeviceCount
,
659 VkPhysicalDevice
* pPhysicalDevices
)
661 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
664 if (instance
->physicalDeviceCount
< 0) {
665 result
= radv_enumerate_devices(instance
);
666 if (result
!= VK_SUCCESS
&&
667 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
671 if (!pPhysicalDevices
) {
672 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
674 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
675 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
676 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
679 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
683 VkResult
radv_EnumeratePhysicalDeviceGroups(
684 VkInstance _instance
,
685 uint32_t* pPhysicalDeviceGroupCount
,
686 VkPhysicalDeviceGroupProperties
* pPhysicalDeviceGroupProperties
)
688 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
691 if (instance
->physicalDeviceCount
< 0) {
692 result
= radv_enumerate_devices(instance
);
693 if (result
!= VK_SUCCESS
&&
694 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
698 if (!pPhysicalDeviceGroupProperties
) {
699 *pPhysicalDeviceGroupCount
= instance
->physicalDeviceCount
;
701 *pPhysicalDeviceGroupCount
= MIN2(*pPhysicalDeviceGroupCount
, instance
->physicalDeviceCount
);
702 for (unsigned i
= 0; i
< *pPhysicalDeviceGroupCount
; ++i
) {
703 pPhysicalDeviceGroupProperties
[i
].physicalDeviceCount
= 1;
704 pPhysicalDeviceGroupProperties
[i
].physicalDevices
[0] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
705 pPhysicalDeviceGroupProperties
[i
].subsetAllocation
= false;
708 return *pPhysicalDeviceGroupCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
712 void radv_GetPhysicalDeviceFeatures(
713 VkPhysicalDevice physicalDevice
,
714 VkPhysicalDeviceFeatures
* pFeatures
)
716 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
717 memset(pFeatures
, 0, sizeof(*pFeatures
));
719 *pFeatures
= (VkPhysicalDeviceFeatures
) {
720 .robustBufferAccess
= true,
721 .fullDrawIndexUint32
= true,
722 .imageCubeArray
= true,
723 .independentBlend
= true,
724 .geometryShader
= true,
725 .tessellationShader
= true,
726 .sampleRateShading
= true,
727 .dualSrcBlend
= true,
729 .multiDrawIndirect
= true,
730 .drawIndirectFirstInstance
= true,
732 .depthBiasClamp
= true,
733 .fillModeNonSolid
= true,
738 .multiViewport
= true,
739 .samplerAnisotropy
= true,
740 .textureCompressionETC2
= pdevice
->rad_info
.chip_class
>= GFX9
||
741 pdevice
->rad_info
.family
== CHIP_STONEY
,
742 .textureCompressionASTC_LDR
= false,
743 .textureCompressionBC
= true,
744 .occlusionQueryPrecise
= true,
745 .pipelineStatisticsQuery
= true,
746 .vertexPipelineStoresAndAtomics
= true,
747 .fragmentStoresAndAtomics
= true,
748 .shaderTessellationAndGeometryPointSize
= true,
749 .shaderImageGatherExtended
= true,
750 .shaderStorageImageExtendedFormats
= true,
751 .shaderStorageImageMultisample
= false,
752 .shaderUniformBufferArrayDynamicIndexing
= true,
753 .shaderSampledImageArrayDynamicIndexing
= true,
754 .shaderStorageBufferArrayDynamicIndexing
= true,
755 .shaderStorageImageArrayDynamicIndexing
= true,
756 .shaderStorageImageReadWithoutFormat
= true,
757 .shaderStorageImageWriteWithoutFormat
= true,
758 .shaderClipDistance
= true,
759 .shaderCullDistance
= true,
760 .shaderFloat64
= true,
762 .shaderInt16
= pdevice
->rad_info
.chip_class
>= GFX9
&& HAVE_LLVM
>= 0x700,
763 .sparseBinding
= true,
764 .variableMultisampleRate
= true,
765 .inheritedQueries
= true,
769 void radv_GetPhysicalDeviceFeatures2(
770 VkPhysicalDevice physicalDevice
,
771 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
773 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
774 vk_foreach_struct(ext
, pFeatures
->pNext
) {
775 switch (ext
->sType
) {
776 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
777 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
778 features
->variablePointersStorageBuffer
= true;
779 features
->variablePointers
= false;
782 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR
: {
783 VkPhysicalDeviceMultiviewFeaturesKHR
*features
= (VkPhysicalDeviceMultiviewFeaturesKHR
*)ext
;
784 features
->multiview
= true;
785 features
->multiviewGeometryShader
= true;
786 features
->multiviewTessellationShader
= true;
789 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES
: {
790 VkPhysicalDeviceShaderDrawParameterFeatures
*features
=
791 (VkPhysicalDeviceShaderDrawParameterFeatures
*)ext
;
792 features
->shaderDrawParameters
= true;
795 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES
: {
796 VkPhysicalDeviceProtectedMemoryFeatures
*features
=
797 (VkPhysicalDeviceProtectedMemoryFeatures
*)ext
;
798 features
->protectedMemory
= false;
801 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES
: {
802 VkPhysicalDevice16BitStorageFeatures
*features
=
803 (VkPhysicalDevice16BitStorageFeatures
*)ext
;
804 bool enabled
= HAVE_LLVM
>= 0x0700 && pdevice
->rad_info
.chip_class
>= VI
;
805 features
->storageBuffer16BitAccess
= enabled
;
806 features
->uniformAndStorageBuffer16BitAccess
= enabled
;
807 features
->storagePushConstant16
= enabled
;
808 features
->storageInputOutput16
= enabled
;
811 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES
: {
812 VkPhysicalDeviceSamplerYcbcrConversionFeatures
*features
=
813 (VkPhysicalDeviceSamplerYcbcrConversionFeatures
*)ext
;
814 features
->samplerYcbcrConversion
= false;
817 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT
: {
818 VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*features
=
819 (VkPhysicalDeviceDescriptorIndexingFeaturesEXT
*)ext
;
820 features
->shaderInputAttachmentArrayDynamicIndexing
= true;
821 features
->shaderUniformTexelBufferArrayDynamicIndexing
= true;
822 features
->shaderStorageTexelBufferArrayDynamicIndexing
= true;
823 features
->shaderUniformBufferArrayNonUniformIndexing
= false;
824 features
->shaderSampledImageArrayNonUniformIndexing
= false;
825 features
->shaderStorageBufferArrayNonUniformIndexing
= false;
826 features
->shaderStorageImageArrayNonUniformIndexing
= false;
827 features
->shaderInputAttachmentArrayNonUniformIndexing
= false;
828 features
->shaderUniformTexelBufferArrayNonUniformIndexing
= false;
829 features
->shaderStorageTexelBufferArrayNonUniformIndexing
= false;
830 features
->descriptorBindingUniformBufferUpdateAfterBind
= true;
831 features
->descriptorBindingSampledImageUpdateAfterBind
= true;
832 features
->descriptorBindingStorageImageUpdateAfterBind
= true;
833 features
->descriptorBindingStorageBufferUpdateAfterBind
= true;
834 features
->descriptorBindingUniformTexelBufferUpdateAfterBind
= true;
835 features
->descriptorBindingStorageTexelBufferUpdateAfterBind
= true;
836 features
->descriptorBindingUpdateUnusedWhilePending
= true;
837 features
->descriptorBindingPartiallyBound
= true;
838 features
->descriptorBindingVariableDescriptorCount
= true;
839 features
->runtimeDescriptorArray
= true;
842 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT
: {
843 VkPhysicalDeviceConditionalRenderingFeaturesEXT
*features
=
844 (VkPhysicalDeviceConditionalRenderingFeaturesEXT
*)ext
;
845 features
->conditionalRendering
= true;
846 features
->inheritedConditionalRendering
= false;
849 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT
: {
850 VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*features
=
851 (VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT
*)ext
;
852 features
->vertexAttributeInstanceRateDivisor
= VK_TRUE
;
853 features
->vertexAttributeInstanceRateZeroDivisor
= VK_TRUE
;
860 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
863 void radv_GetPhysicalDeviceProperties(
864 VkPhysicalDevice physicalDevice
,
865 VkPhysicalDeviceProperties
* pProperties
)
867 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
868 VkSampleCountFlags sample_counts
= 0xf;
870 /* make sure that the entire descriptor set is addressable with a signed
871 * 32-bit int. So the sum of all limits scaled by descriptor size has to
872 * be at most 2 GiB. the combined image & samples object count as one of
873 * both. This limit is for the pipeline layout, not for the set layout, but
874 * there is no set limit, so we just set a pipeline limit. I don't think
875 * any app is going to hit this soon. */
876 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
877 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
878 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
879 32 /* sampler, largest when combined with image */ +
880 64 /* sampled image */ +
881 64 /* storage image */);
883 VkPhysicalDeviceLimits limits
= {
884 .maxImageDimension1D
= (1 << 14),
885 .maxImageDimension2D
= (1 << 14),
886 .maxImageDimension3D
= (1 << 11),
887 .maxImageDimensionCube
= (1 << 14),
888 .maxImageArrayLayers
= (1 << 11),
889 .maxTexelBufferElements
= 128 * 1024 * 1024,
890 .maxUniformBufferRange
= UINT32_MAX
,
891 .maxStorageBufferRange
= UINT32_MAX
,
892 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
893 .maxMemoryAllocationCount
= UINT32_MAX
,
894 .maxSamplerAllocationCount
= 64 * 1024,
895 .bufferImageGranularity
= 64, /* A cache line */
896 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
897 .maxBoundDescriptorSets
= MAX_SETS
,
898 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
899 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
900 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
901 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
902 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
903 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
904 .maxPerStageResources
= max_descriptor_set_size
,
905 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
906 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
907 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
,
908 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
909 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
,
910 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
911 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
912 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
913 .maxVertexInputAttributes
= 32,
914 .maxVertexInputBindings
= 32,
915 .maxVertexInputAttributeOffset
= 2047,
916 .maxVertexInputBindingStride
= 2048,
917 .maxVertexOutputComponents
= 128,
918 .maxTessellationGenerationLevel
= 64,
919 .maxTessellationPatchSize
= 32,
920 .maxTessellationControlPerVertexInputComponents
= 128,
921 .maxTessellationControlPerVertexOutputComponents
= 128,
922 .maxTessellationControlPerPatchOutputComponents
= 120,
923 .maxTessellationControlTotalOutputComponents
= 4096,
924 .maxTessellationEvaluationInputComponents
= 128,
925 .maxTessellationEvaluationOutputComponents
= 128,
926 .maxGeometryShaderInvocations
= 127,
927 .maxGeometryInputComponents
= 64,
928 .maxGeometryOutputComponents
= 128,
929 .maxGeometryOutputVertices
= 256,
930 .maxGeometryTotalOutputComponents
= 1024,
931 .maxFragmentInputComponents
= 128,
932 .maxFragmentOutputAttachments
= 8,
933 .maxFragmentDualSrcAttachments
= 1,
934 .maxFragmentCombinedOutputResources
= 8,
935 .maxComputeSharedMemorySize
= 32768,
936 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
937 .maxComputeWorkGroupInvocations
= 2048,
938 .maxComputeWorkGroupSize
= {
943 .subPixelPrecisionBits
= 4 /* FIXME */,
944 .subTexelPrecisionBits
= 4 /* FIXME */,
945 .mipmapPrecisionBits
= 4 /* FIXME */,
946 .maxDrawIndexedIndexValue
= UINT32_MAX
,
947 .maxDrawIndirectCount
= UINT32_MAX
,
948 .maxSamplerLodBias
= 16,
949 .maxSamplerAnisotropy
= 16,
950 .maxViewports
= MAX_VIEWPORTS
,
951 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
952 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
953 .viewportSubPixelBits
= 8,
954 .minMemoryMapAlignment
= 4096, /* A page */
955 .minTexelBufferOffsetAlignment
= 1,
956 .minUniformBufferOffsetAlignment
= 4,
957 .minStorageBufferOffsetAlignment
= 4,
958 .minTexelOffset
= -32,
959 .maxTexelOffset
= 31,
960 .minTexelGatherOffset
= -32,
961 .maxTexelGatherOffset
= 31,
962 .minInterpolationOffset
= -2,
963 .maxInterpolationOffset
= 2,
964 .subPixelInterpolationOffsetBits
= 8,
965 .maxFramebufferWidth
= (1 << 14),
966 .maxFramebufferHeight
= (1 << 14),
967 .maxFramebufferLayers
= (1 << 10),
968 .framebufferColorSampleCounts
= sample_counts
,
969 .framebufferDepthSampleCounts
= sample_counts
,
970 .framebufferStencilSampleCounts
= sample_counts
,
971 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
972 .maxColorAttachments
= MAX_RTS
,
973 .sampledImageColorSampleCounts
= sample_counts
,
974 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
975 .sampledImageDepthSampleCounts
= sample_counts
,
976 .sampledImageStencilSampleCounts
= sample_counts
,
977 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
978 .maxSampleMaskWords
= 1,
979 .timestampComputeAndGraphics
= true,
980 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
981 .maxClipDistances
= 8,
982 .maxCullDistances
= 8,
983 .maxCombinedClipAndCullDistances
= 8,
984 .discreteQueuePriorities
= 1,
985 .pointSizeRange
= { 0.125, 255.875 },
986 .lineWidthRange
= { 0.0, 7.9921875 },
987 .pointSizeGranularity
= (1.0 / 8.0),
988 .lineWidthGranularity
= (1.0 / 128.0),
989 .strictLines
= false, /* FINISHME */
990 .standardSampleLocations
= true,
991 .optimalBufferCopyOffsetAlignment
= 128,
992 .optimalBufferCopyRowPitchAlignment
= 128,
993 .nonCoherentAtomSize
= 64,
996 *pProperties
= (VkPhysicalDeviceProperties
) {
997 .apiVersion
= radv_physical_device_api_version(pdevice
),
998 .driverVersion
= vk_get_driver_version(),
999 .vendorID
= ATI_VENDOR_ID
,
1000 .deviceID
= pdevice
->rad_info
.pci_id
,
1001 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
1003 .sparseProperties
= {0},
1006 strcpy(pProperties
->deviceName
, pdevice
->name
);
1007 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
1010 void radv_GetPhysicalDeviceProperties2(
1011 VkPhysicalDevice physicalDevice
,
1012 VkPhysicalDeviceProperties2KHR
*pProperties
)
1014 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1015 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
1017 vk_foreach_struct(ext
, pProperties
->pNext
) {
1018 switch (ext
->sType
) {
1019 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
1020 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
1021 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
1022 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
1025 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
1026 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
1027 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
1028 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
1029 properties
->deviceLUIDValid
= false;
1032 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR
: {
1033 VkPhysicalDeviceMultiviewPropertiesKHR
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHR
*)ext
;
1034 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
1035 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
1038 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
1039 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
1040 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
1041 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
1044 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT
: {
1045 VkPhysicalDeviceDiscardRectanglePropertiesEXT
*properties
=
1046 (VkPhysicalDeviceDiscardRectanglePropertiesEXT
*)ext
;
1047 properties
->maxDiscardRectangles
= MAX_DISCARD_RECTANGLES
;
1050 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT
: {
1051 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*properties
=
1052 (VkPhysicalDeviceExternalMemoryHostPropertiesEXT
*) ext
;
1053 properties
->minImportedHostPointerAlignment
= 4096;
1056 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES
: {
1057 VkPhysicalDeviceSubgroupProperties
*properties
=
1058 (VkPhysicalDeviceSubgroupProperties
*)ext
;
1059 properties
->subgroupSize
= 64;
1060 properties
->supportedStages
= VK_SHADER_STAGE_ALL
;
1061 properties
->supportedOperations
=
1062 VK_SUBGROUP_FEATURE_ARITHMETIC_BIT
|
1063 VK_SUBGROUP_FEATURE_BASIC_BIT
|
1064 VK_SUBGROUP_FEATURE_BALLOT_BIT
|
1065 VK_SUBGROUP_FEATURE_QUAD_BIT
|
1066 VK_SUBGROUP_FEATURE_VOTE_BIT
;
1067 if (pdevice
->rad_info
.chip_class
>= VI
) {
1068 properties
->supportedOperations
|=
1069 VK_SUBGROUP_FEATURE_SHUFFLE_BIT
|
1070 VK_SUBGROUP_FEATURE_SHUFFLE_RELATIVE_BIT
;
1072 properties
->quadOperationsInAllStages
= true;
1075 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES
: {
1076 VkPhysicalDeviceMaintenance3Properties
*properties
=
1077 (VkPhysicalDeviceMaintenance3Properties
*)ext
;
1078 /* Make sure everything is addressable by a signed 32-bit int, and
1079 * our largest descriptors are 96 bytes. */
1080 properties
->maxPerSetDescriptors
= (1ull << 31) / 96;
1081 /* Our buffer size fields allow only this much */
1082 properties
->maxMemoryAllocationSize
= 0xFFFFFFFFull
;
1085 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT
: {
1086 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*properties
=
1087 (VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT
*)ext
;
1088 /* GFX6-8 only support single channel min/max filter. */
1089 properties
->filterMinmaxImageComponentMapping
= pdevice
->rad_info
.chip_class
>= GFX9
;
1090 properties
->filterMinmaxSingleComponentFormats
= true;
1093 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_AMD
: {
1094 VkPhysicalDeviceShaderCorePropertiesAMD
*properties
=
1095 (VkPhysicalDeviceShaderCorePropertiesAMD
*)ext
;
1097 /* Shader engines. */
1098 properties
->shaderEngineCount
=
1099 pdevice
->rad_info
.max_se
;
1100 properties
->shaderArraysPerEngineCount
=
1101 pdevice
->rad_info
.max_sh_per_se
;
1102 properties
->computeUnitsPerShaderArray
=
1103 pdevice
->rad_info
.num_good_compute_units
/
1104 (pdevice
->rad_info
.max_se
*
1105 pdevice
->rad_info
.max_sh_per_se
);
1106 properties
->simdPerComputeUnit
= 4;
1107 properties
->wavefrontsPerSimd
=
1108 pdevice
->rad_info
.family
== CHIP_TONGA
||
1109 pdevice
->rad_info
.family
== CHIP_ICELAND
||
1110 pdevice
->rad_info
.family
== CHIP_POLARIS10
||
1111 pdevice
->rad_info
.family
== CHIP_POLARIS11
||
1112 pdevice
->rad_info
.family
== CHIP_POLARIS12
||
1113 pdevice
->rad_info
.family
== CHIP_VEGAM
? 8 : 10;
1114 properties
->wavefrontSize
= 64;
1117 properties
->sgprsPerSimd
=
1118 radv_get_num_physical_sgprs(pdevice
);
1119 properties
->minSgprAllocation
=
1120 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1121 properties
->maxSgprAllocation
=
1122 pdevice
->rad_info
.family
== CHIP_TONGA
||
1123 pdevice
->rad_info
.family
== CHIP_ICELAND
? 96 : 104;
1124 properties
->sgprAllocationGranularity
=
1125 pdevice
->rad_info
.chip_class
>= VI
? 16 : 8;
1128 properties
->vgprsPerSimd
= RADV_NUM_PHYSICAL_VGPRS
;
1129 properties
->minVgprAllocation
= 4;
1130 properties
->maxVgprAllocation
= 256;
1131 properties
->vgprAllocationGranularity
= 4;
1134 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT
: {
1135 VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*properties
=
1136 (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT
*)ext
;
1137 properties
->maxVertexAttribDivisor
= UINT32_MAX
;
1140 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT
: {
1141 VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*properties
=
1142 (VkPhysicalDeviceDescriptorIndexingPropertiesEXT
*)ext
;
1143 properties
->maxUpdateAfterBindDescriptorsInAllPools
= UINT32_MAX
/ 64;
1144 properties
->shaderUniformBufferArrayNonUniformIndexingNative
= false;
1145 properties
->shaderSampledImageArrayNonUniformIndexingNative
= false;
1146 properties
->shaderStorageBufferArrayNonUniformIndexingNative
= false;
1147 properties
->shaderStorageImageArrayNonUniformIndexingNative
= false;
1148 properties
->shaderInputAttachmentArrayNonUniformIndexingNative
= false;
1149 properties
->robustBufferAccessUpdateAfterBind
= false;
1150 properties
->quadDivergentImplicitLod
= false;
1152 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
1153 (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
1154 32 /* storage buffer, 32 due to potential space wasted on alignment */ +
1155 32 /* sampler, largest when combined with image */ +
1156 64 /* sampled image */ +
1157 64 /* storage image */);
1158 properties
->maxPerStageDescriptorUpdateAfterBindSamplers
= max_descriptor_set_size
;
1159 properties
->maxPerStageDescriptorUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1160 properties
->maxPerStageDescriptorUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1161 properties
->maxPerStageDescriptorUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1162 properties
->maxPerStageDescriptorUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1163 properties
->maxPerStageDescriptorUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1164 properties
->maxPerStageUpdateAfterBindResources
= max_descriptor_set_size
;
1165 properties
->maxDescriptorSetUpdateAfterBindSamplers
= max_descriptor_set_size
;
1166 properties
->maxDescriptorSetUpdateAfterBindUniformBuffers
= max_descriptor_set_size
;
1167 properties
->maxDescriptorSetUpdateAfterBindUniformBuffersDynamic
= MAX_DYNAMIC_UNIFORM_BUFFERS
;
1168 properties
->maxDescriptorSetUpdateAfterBindStorageBuffers
= max_descriptor_set_size
;
1169 properties
->maxDescriptorSetUpdateAfterBindStorageBuffersDynamic
= MAX_DYNAMIC_STORAGE_BUFFERS
;
1170 properties
->maxDescriptorSetUpdateAfterBindSampledImages
= max_descriptor_set_size
;
1171 properties
->maxDescriptorSetUpdateAfterBindStorageImages
= max_descriptor_set_size
;
1172 properties
->maxDescriptorSetUpdateAfterBindInputAttachments
= max_descriptor_set_size
;
1175 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES
: {
1176 VkPhysicalDeviceProtectedMemoryProperties
*properties
=
1177 (VkPhysicalDeviceProtectedMemoryProperties
*)ext
;
1178 properties
->protectedNoFault
= false;
1181 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONSERVATIVE_RASTERIZATION_PROPERTIES_EXT
: {
1182 VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*properties
=
1183 (VkPhysicalDeviceConservativeRasterizationPropertiesEXT
*)ext
;
1184 properties
->primitiveOverestimationSize
= 0;
1185 properties
->maxExtraPrimitiveOverestimationSize
= 0;
1186 properties
->extraPrimitiveOverestimationSizeGranularity
= 0;
1187 properties
->primitiveUnderestimation
= VK_FALSE
;
1188 properties
->conservativePointAndLineRasterization
= VK_FALSE
;
1189 properties
->degenerateTrianglesRasterized
= VK_FALSE
;
1190 properties
->degenerateLinesRasterized
= VK_FALSE
;
1191 properties
->fullyCoveredFragmentShaderInputVariable
= VK_FALSE
;
1192 properties
->conservativeRasterizationPostDepthCoverage
= VK_FALSE
;
1201 static void radv_get_physical_device_queue_family_properties(
1202 struct radv_physical_device
* pdevice
,
1204 VkQueueFamilyProperties
** pQueueFamilyProperties
)
1206 int num_queue_families
= 1;
1208 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1209 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
1210 num_queue_families
++;
1212 if (pQueueFamilyProperties
== NULL
) {
1213 *pCount
= num_queue_families
;
1222 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1223 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
1224 VK_QUEUE_COMPUTE_BIT
|
1225 VK_QUEUE_TRANSFER_BIT
|
1226 VK_QUEUE_SPARSE_BINDING_BIT
,
1228 .timestampValidBits
= 64,
1229 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1234 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
1235 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
1236 if (*pCount
> idx
) {
1237 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
1238 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
1239 VK_QUEUE_TRANSFER_BIT
|
1240 VK_QUEUE_SPARSE_BINDING_BIT
,
1241 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
1242 .timestampValidBits
= 64,
1243 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
1251 void radv_GetPhysicalDeviceQueueFamilyProperties(
1252 VkPhysicalDevice physicalDevice
,
1254 VkQueueFamilyProperties
* pQueueFamilyProperties
)
1256 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1257 if (!pQueueFamilyProperties
) {
1258 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1261 VkQueueFamilyProperties
*properties
[] = {
1262 pQueueFamilyProperties
+ 0,
1263 pQueueFamilyProperties
+ 1,
1264 pQueueFamilyProperties
+ 2,
1266 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1267 assert(*pCount
<= 3);
1270 void radv_GetPhysicalDeviceQueueFamilyProperties2(
1271 VkPhysicalDevice physicalDevice
,
1273 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
1275 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1276 if (!pQueueFamilyProperties
) {
1277 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
1280 VkQueueFamilyProperties
*properties
[] = {
1281 &pQueueFamilyProperties
[0].queueFamilyProperties
,
1282 &pQueueFamilyProperties
[1].queueFamilyProperties
,
1283 &pQueueFamilyProperties
[2].queueFamilyProperties
,
1285 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
1286 assert(*pCount
<= 3);
1289 void radv_GetPhysicalDeviceMemoryProperties(
1290 VkPhysicalDevice physicalDevice
,
1291 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1293 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1295 *pMemoryProperties
= physical_device
->memory_properties
;
1298 void radv_GetPhysicalDeviceMemoryProperties2(
1299 VkPhysicalDevice physicalDevice
,
1300 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1302 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1303 &pMemoryProperties
->memoryProperties
);
1306 VkResult
radv_GetMemoryHostPointerPropertiesEXT(
1308 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
1309 const void *pHostPointer
,
1310 VkMemoryHostPointerPropertiesEXT
*pMemoryHostPointerProperties
)
1312 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1316 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
: {
1317 const struct radv_physical_device
*physical_device
= device
->physical_device
;
1318 uint32_t memoryTypeBits
= 0;
1319 for (int i
= 0; i
< physical_device
->memory_properties
.memoryTypeCount
; i
++) {
1320 if (physical_device
->mem_type_indices
[i
] == RADV_MEM_TYPE_GTT_CACHED
) {
1321 memoryTypeBits
= (1 << i
);
1325 pMemoryHostPointerProperties
->memoryTypeBits
= memoryTypeBits
;
1329 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
1333 static enum radeon_ctx_priority
1334 radv_get_queue_global_priority(const VkDeviceQueueGlobalPriorityCreateInfoEXT
*pObj
)
1336 /* Default to MEDIUM when a specific global priority isn't requested */
1338 return RADEON_CTX_PRIORITY_MEDIUM
;
1340 switch(pObj
->globalPriority
) {
1341 case VK_QUEUE_GLOBAL_PRIORITY_REALTIME_EXT
:
1342 return RADEON_CTX_PRIORITY_REALTIME
;
1343 case VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT
:
1344 return RADEON_CTX_PRIORITY_HIGH
;
1345 case VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT
:
1346 return RADEON_CTX_PRIORITY_MEDIUM
;
1347 case VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT
:
1348 return RADEON_CTX_PRIORITY_LOW
;
1350 unreachable("Illegal global priority value");
1351 return RADEON_CTX_PRIORITY_INVALID
;
1356 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1357 uint32_t queue_family_index
, int idx
,
1358 VkDeviceQueueCreateFlags flags
,
1359 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
)
1361 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1362 queue
->device
= device
;
1363 queue
->queue_family_index
= queue_family_index
;
1364 queue
->queue_idx
= idx
;
1365 queue
->priority
= radv_get_queue_global_priority(global_priority
);
1366 queue
->flags
= flags
;
1368 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
, queue
->priority
);
1370 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1376 radv_queue_finish(struct radv_queue
*queue
)
1379 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1381 if (queue
->initial_full_flush_preamble_cs
)
1382 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1383 if (queue
->initial_preamble_cs
)
1384 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1385 if (queue
->continue_preamble_cs
)
1386 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1387 if (queue
->descriptor_bo
)
1388 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1389 if (queue
->scratch_bo
)
1390 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1391 if (queue
->esgs_ring_bo
)
1392 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1393 if (queue
->gsvs_ring_bo
)
1394 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1395 if (queue
->tess_rings_bo
)
1396 queue
->device
->ws
->buffer_destroy(queue
->tess_rings_bo
);
1397 if (queue
->compute_scratch_bo
)
1398 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1402 radv_bo_list_init(struct radv_bo_list
*bo_list
)
1404 pthread_mutex_init(&bo_list
->mutex
, NULL
);
1405 bo_list
->list
.count
= bo_list
->capacity
= 0;
1406 bo_list
->list
.bos
= NULL
;
1410 radv_bo_list_finish(struct radv_bo_list
*bo_list
)
1412 free(bo_list
->list
.bos
);
1413 pthread_mutex_destroy(&bo_list
->mutex
);
1416 static VkResult
radv_bo_list_add(struct radv_device
*device
,
1417 struct radeon_winsys_bo
*bo
)
1419 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1421 if (unlikely(!device
->use_global_bo_list
))
1424 pthread_mutex_lock(&bo_list
->mutex
);
1425 if (bo_list
->list
.count
== bo_list
->capacity
) {
1426 unsigned capacity
= MAX2(4, bo_list
->capacity
* 2);
1427 void *data
= realloc(bo_list
->list
.bos
, capacity
* sizeof(struct radeon_winsys_bo
*));
1430 pthread_mutex_unlock(&bo_list
->mutex
);
1431 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1434 bo_list
->list
.bos
= (struct radeon_winsys_bo
**)data
;
1435 bo_list
->capacity
= capacity
;
1438 bo_list
->list
.bos
[bo_list
->list
.count
++] = bo
;
1439 pthread_mutex_unlock(&bo_list
->mutex
);
1443 static void radv_bo_list_remove(struct radv_device
*device
,
1444 struct radeon_winsys_bo
*bo
)
1446 struct radv_bo_list
*bo_list
= &device
->bo_list
;
1448 if (unlikely(!device
->use_global_bo_list
))
1451 pthread_mutex_lock(&bo_list
->mutex
);
1452 for(unsigned i
= 0; i
< bo_list
->list
.count
; ++i
) {
1453 if (bo_list
->list
.bos
[i
] == bo
) {
1454 bo_list
->list
.bos
[i
] = bo_list
->list
.bos
[bo_list
->list
.count
- 1];
1455 --bo_list
->list
.count
;
1459 pthread_mutex_unlock(&bo_list
->mutex
);
1463 radv_device_init_gs_info(struct radv_device
*device
)
1465 device
->gs_table_depth
= ac_get_gs_table_depth(device
->physical_device
->rad_info
.chip_class
,
1466 device
->physical_device
->rad_info
.family
);
1469 static int radv_get_device_extension_index(const char *name
)
1471 for (unsigned i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; ++i
) {
1472 if (strcmp(name
, radv_device_extensions
[i
].extensionName
) == 0)
1479 radv_get_int_debug_option(const char *name
, int default_value
)
1486 result
= default_value
;
1490 result
= strtol(str
, &endptr
, 0);
1491 if (str
== endptr
) {
1492 /* No digits founs. */
1493 result
= default_value
;
1500 VkResult
radv_CreateDevice(
1501 VkPhysicalDevice physicalDevice
,
1502 const VkDeviceCreateInfo
* pCreateInfo
,
1503 const VkAllocationCallbacks
* pAllocator
,
1506 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1508 struct radv_device
*device
;
1510 bool keep_shader_info
= false;
1512 /* Check enabled features */
1513 if (pCreateInfo
->pEnabledFeatures
) {
1514 VkPhysicalDeviceFeatures supported_features
;
1515 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1516 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1517 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1518 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1519 for (uint32_t i
= 0; i
< num_features
; i
++) {
1520 if (enabled_feature
[i
] && !supported_feature
[i
])
1521 return vk_error(physical_device
->instance
, VK_ERROR_FEATURE_NOT_PRESENT
);
1525 device
= vk_zalloc2(&physical_device
->instance
->alloc
, pAllocator
,
1527 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1529 return vk_error(physical_device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
1531 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1532 device
->instance
= physical_device
->instance
;
1533 device
->physical_device
= physical_device
;
1535 device
->ws
= physical_device
->ws
;
1537 device
->alloc
= *pAllocator
;
1539 device
->alloc
= physical_device
->instance
->alloc
;
1541 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1542 const char *ext_name
= pCreateInfo
->ppEnabledExtensionNames
[i
];
1543 int index
= radv_get_device_extension_index(ext_name
);
1544 if (index
< 0 || !physical_device
->supported_extensions
.extensions
[index
]) {
1545 vk_free(&device
->alloc
, device
);
1546 return vk_error(physical_device
->instance
, VK_ERROR_EXTENSION_NOT_PRESENT
);
1549 device
->enabled_extensions
.extensions
[index
] = true;
1552 keep_shader_info
= device
->enabled_extensions
.AMD_shader_info
;
1554 /* With update after bind we can't attach bo's to the command buffer
1555 * from the descriptor set anymore, so we have to use a global BO list.
1557 device
->use_global_bo_list
=
1558 device
->enabled_extensions
.EXT_descriptor_indexing
;
1560 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1561 list_inithead(&device
->shader_slabs
);
1563 radv_bo_list_init(&device
->bo_list
);
1565 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1566 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1567 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1568 const VkDeviceQueueGlobalPriorityCreateInfoEXT
*global_priority
=
1569 vk_find_struct_const(queue_create
->pNext
, DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT
);
1571 assert(!global_priority
|| device
->physical_device
->rad_info
.has_ctx_priority
);
1573 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1574 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1575 if (!device
->queues
[qfi
]) {
1576 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1580 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1582 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1584 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1585 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
],
1586 qfi
, q
, queue_create
->flags
,
1588 if (result
!= VK_SUCCESS
)
1593 device
->pbb_allowed
= device
->physical_device
->rad_info
.chip_class
>= GFX9
&&
1594 ((device
->instance
->perftest_flags
& RADV_PERFTEST_BINNING
) ||
1595 device
->physical_device
->rad_info
.family
== CHIP_RAVEN
);
1597 /* Disabled and not implemented for now. */
1598 device
->dfsm_allowed
= device
->pbb_allowed
&&
1599 device
->physical_device
->rad_info
.family
== CHIP_RAVEN
;
1602 device
->always_use_syncobj
= device
->physical_device
->rad_info
.has_syncobj_wait_for_submit
;
1605 /* The maximum number of scratch waves. Scratch space isn't divided
1606 * evenly between CUs. The number is only a function of the number of CUs.
1607 * We can decrease the constant to decrease the scratch buffer size.
1609 * sctx->scratch_waves must be >= the maximum possible size of
1610 * 1 threadgroup, so that the hw doesn't hang from being unable
1613 * The recommended value is 4 per CU at most. Higher numbers don't
1614 * bring much benefit, but they still occupy chip resources (think
1615 * async compute). I've seen ~2% performance difference between 4 and 32.
1617 uint32_t max_threads_per_block
= 2048;
1618 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1619 max_threads_per_block
/ 64);
1621 device
->dispatch_initiator
= S_00B800_COMPUTE_SHADER_EN(1);
1623 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1624 /* If the KMD allows it (there is a KMD hw register for it),
1625 * allow launching waves out-of-order.
1627 device
->dispatch_initiator
|= S_00B800_ORDER_MODE(1);
1630 radv_device_init_gs_info(device
);
1632 device
->tess_offchip_block_dw_size
=
1633 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1634 device
->has_distributed_tess
=
1635 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1636 device
->physical_device
->rad_info
.max_se
>= 2;
1638 if (getenv("RADV_TRACE_FILE")) {
1639 const char *filename
= getenv("RADV_TRACE_FILE");
1641 keep_shader_info
= true;
1643 if (!radv_init_trace(device
))
1646 fprintf(stderr
, "*****************************************************************************\n");
1647 fprintf(stderr
, "* WARNING: RADV_TRACE_FILE is costly and should only be used for debugging! *\n");
1648 fprintf(stderr
, "*****************************************************************************\n");
1650 fprintf(stderr
, "Trace file will be dumped to %s\n", filename
);
1651 radv_dump_enabled_options(device
, stderr
);
1654 device
->keep_shader_info
= keep_shader_info
;
1656 result
= radv_device_init_meta(device
);
1657 if (result
!= VK_SUCCESS
)
1660 radv_device_init_msaa(device
);
1662 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1663 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1665 case RADV_QUEUE_GENERAL
:
1666 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1667 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1668 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1670 case RADV_QUEUE_COMPUTE
:
1671 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1672 radeon_emit(device
->empty_cs
[family
], 0);
1675 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1678 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1679 cik_create_gfx_config(device
);
1681 VkPipelineCacheCreateInfo ci
;
1682 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1685 ci
.pInitialData
= NULL
;
1686 ci
.initialDataSize
= 0;
1688 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1690 if (result
!= VK_SUCCESS
)
1693 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1695 device
->force_aniso
=
1696 MIN2(16, radv_get_int_debug_option("RADV_TEX_ANISO", -1));
1697 if (device
->force_aniso
>= 0) {
1698 fprintf(stderr
, "radv: Forcing anisotropy filter to %ix\n",
1699 1 << util_logbase2(device
->force_aniso
));
1702 *pDevice
= radv_device_to_handle(device
);
1706 radv_device_finish_meta(device
);
1708 radv_bo_list_finish(&device
->bo_list
);
1710 if (device
->trace_bo
)
1711 device
->ws
->buffer_destroy(device
->trace_bo
);
1713 if (device
->gfx_init
)
1714 device
->ws
->buffer_destroy(device
->gfx_init
);
1716 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1717 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1718 radv_queue_finish(&device
->queues
[i
][q
]);
1719 if (device
->queue_count
[i
])
1720 vk_free(&device
->alloc
, device
->queues
[i
]);
1723 vk_free(&device
->alloc
, device
);
1727 void radv_DestroyDevice(
1729 const VkAllocationCallbacks
* pAllocator
)
1731 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1736 if (device
->trace_bo
)
1737 device
->ws
->buffer_destroy(device
->trace_bo
);
1739 if (device
->gfx_init
)
1740 device
->ws
->buffer_destroy(device
->gfx_init
);
1742 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1743 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1744 radv_queue_finish(&device
->queues
[i
][q
]);
1745 if (device
->queue_count
[i
])
1746 vk_free(&device
->alloc
, device
->queues
[i
]);
1747 if (device
->empty_cs
[i
])
1748 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1750 radv_device_finish_meta(device
);
1752 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1753 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1755 radv_destroy_shader_slabs(device
);
1757 radv_bo_list_finish(&device
->bo_list
);
1758 vk_free(&device
->alloc
, device
);
1761 VkResult
radv_EnumerateInstanceLayerProperties(
1762 uint32_t* pPropertyCount
,
1763 VkLayerProperties
* pProperties
)
1765 if (pProperties
== NULL
) {
1766 *pPropertyCount
= 0;
1770 /* None supported at this time */
1771 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1774 VkResult
radv_EnumerateDeviceLayerProperties(
1775 VkPhysicalDevice physicalDevice
,
1776 uint32_t* pPropertyCount
,
1777 VkLayerProperties
* pProperties
)
1779 if (pProperties
== NULL
) {
1780 *pPropertyCount
= 0;
1784 /* None supported at this time */
1785 return vk_error(NULL
, VK_ERROR_LAYER_NOT_PRESENT
);
1788 void radv_GetDeviceQueue2(
1790 const VkDeviceQueueInfo2
* pQueueInfo
,
1793 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1794 struct radv_queue
*queue
;
1796 queue
= &device
->queues
[pQueueInfo
->queueFamilyIndex
][pQueueInfo
->queueIndex
];
1797 if (pQueueInfo
->flags
!= queue
->flags
) {
1798 /* From the Vulkan 1.1.70 spec:
1800 * "The queue returned by vkGetDeviceQueue2 must have the same
1801 * flags value from this structure as that used at device
1802 * creation time in a VkDeviceQueueCreateInfo instance. If no
1803 * matching flags were specified at device creation time then
1804 * pQueue will return VK_NULL_HANDLE."
1806 *pQueue
= VK_NULL_HANDLE
;
1810 *pQueue
= radv_queue_to_handle(queue
);
1813 void radv_GetDeviceQueue(
1815 uint32_t queueFamilyIndex
,
1816 uint32_t queueIndex
,
1819 const VkDeviceQueueInfo2 info
= (VkDeviceQueueInfo2
) {
1820 .sType
= VK_STRUCTURE_TYPE_DEVICE_QUEUE_INFO_2
,
1821 .queueFamilyIndex
= queueFamilyIndex
,
1822 .queueIndex
= queueIndex
1825 radv_GetDeviceQueue2(_device
, &info
, pQueue
);
1829 fill_geom_tess_rings(struct radv_queue
*queue
,
1831 bool add_sample_positions
,
1832 uint32_t esgs_ring_size
,
1833 struct radeon_winsys_bo
*esgs_ring_bo
,
1834 uint32_t gsvs_ring_size
,
1835 struct radeon_winsys_bo
*gsvs_ring_bo
,
1836 uint32_t tess_factor_ring_size
,
1837 uint32_t tess_offchip_ring_offset
,
1838 uint32_t tess_offchip_ring_size
,
1839 struct radeon_winsys_bo
*tess_rings_bo
)
1841 uint64_t esgs_va
= 0, gsvs_va
= 0;
1842 uint64_t tess_va
= 0, tess_offchip_va
= 0;
1843 uint32_t *desc
= &map
[4];
1846 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1848 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1849 if (tess_rings_bo
) {
1850 tess_va
= radv_buffer_get_va(tess_rings_bo
);
1851 tess_offchip_va
= tess_va
+ tess_offchip_ring_offset
;
1854 /* stride 0, num records - size, add tid, swizzle, elsize4,
1857 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1858 S_008F04_STRIDE(0) |
1859 S_008F04_SWIZZLE_ENABLE(true);
1860 desc
[2] = esgs_ring_size
;
1861 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1862 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1863 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1864 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1865 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1866 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1867 S_008F0C_ELEMENT_SIZE(1) |
1868 S_008F0C_INDEX_STRIDE(3) |
1869 S_008F0C_ADD_TID_ENABLE(true);
1872 /* GS entry for ES->GS ring */
1873 /* stride 0, num records - size, elsize0,
1876 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1877 S_008F04_STRIDE(0) |
1878 S_008F04_SWIZZLE_ENABLE(false);
1879 desc
[2] = esgs_ring_size
;
1880 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1881 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1882 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1883 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1884 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1885 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1886 S_008F0C_ELEMENT_SIZE(0) |
1887 S_008F0C_INDEX_STRIDE(0) |
1888 S_008F0C_ADD_TID_ENABLE(false);
1891 /* VS entry for GS->VS ring */
1892 /* stride 0, num records - size, elsize0,
1895 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1896 S_008F04_STRIDE(0) |
1897 S_008F04_SWIZZLE_ENABLE(false);
1898 desc
[2] = gsvs_ring_size
;
1899 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1900 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1901 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1902 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1903 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1904 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1905 S_008F0C_ELEMENT_SIZE(0) |
1906 S_008F0C_INDEX_STRIDE(0) |
1907 S_008F0C_ADD_TID_ENABLE(false);
1910 /* stride gsvs_itemsize, num records 64
1911 elsize 4, index stride 16 */
1912 /* shader will patch stride and desc[2] */
1914 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1915 S_008F04_STRIDE(0) |
1916 S_008F04_SWIZZLE_ENABLE(true);
1918 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1919 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1920 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1921 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1922 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1923 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1924 S_008F0C_ELEMENT_SIZE(1) |
1925 S_008F0C_INDEX_STRIDE(1) |
1926 S_008F0C_ADD_TID_ENABLE(true);
1930 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_va
>> 32) |
1931 S_008F04_STRIDE(0) |
1932 S_008F04_SWIZZLE_ENABLE(false);
1933 desc
[2] = tess_factor_ring_size
;
1934 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1935 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1936 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1937 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1938 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1939 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1940 S_008F0C_ELEMENT_SIZE(0) |
1941 S_008F0C_INDEX_STRIDE(0) |
1942 S_008F0C_ADD_TID_ENABLE(false);
1945 desc
[0] = tess_offchip_va
;
1946 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1947 S_008F04_STRIDE(0) |
1948 S_008F04_SWIZZLE_ENABLE(false);
1949 desc
[2] = tess_offchip_ring_size
;
1950 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1951 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1952 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1953 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1954 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1955 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1956 S_008F0C_ELEMENT_SIZE(0) |
1957 S_008F0C_INDEX_STRIDE(0) |
1958 S_008F0C_ADD_TID_ENABLE(false);
1961 /* add sample positions after all rings */
1962 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1964 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1966 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1968 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1970 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1974 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1976 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1977 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1978 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1979 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1980 unsigned max_offchip_buffers
;
1981 unsigned offchip_granularity
;
1982 unsigned hs_offchip_param
;
1986 * This must be one less than the maximum number due to a hw limitation.
1987 * Various hardware bugs in SI, CIK, and GFX9 need this.
1990 * Vega10 should limit max_offchip_buffers to 508 (4 * 127).
1991 * Gfx7 should limit max_offchip_buffers to 508
1992 * Gfx6 should limit max_offchip_buffers to 126 (2 * 63)
1994 * Follow AMDVLK here.
1996 if (device
->physical_device
->rad_info
.family
== CHIP_VEGA10
||
1997 device
->physical_device
->rad_info
.chip_class
== CIK
||
1998 device
->physical_device
->rad_info
.chip_class
== SI
)
1999 --max_offchip_buffers_per_se
;
2001 max_offchip_buffers
= max_offchip_buffers_per_se
*
2002 device
->physical_device
->rad_info
.max_se
;
2004 switch (device
->tess_offchip_block_dw_size
) {
2009 offchip_granularity
= V_03093C_X_8K_DWORDS
;
2012 offchip_granularity
= V_03093C_X_4K_DWORDS
;
2016 switch (device
->physical_device
->rad_info
.chip_class
) {
2018 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
2024 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
2028 *max_offchip_buffers_p
= max_offchip_buffers
;
2029 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2030 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
2031 --max_offchip_buffers
;
2033 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
2034 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
2037 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
2039 return hs_offchip_param
;
2043 radv_emit_gs_ring_sizes(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2044 struct radeon_winsys_bo
*esgs_ring_bo
,
2045 uint32_t esgs_ring_size
,
2046 struct radeon_winsys_bo
*gsvs_ring_bo
,
2047 uint32_t gsvs_ring_size
)
2049 if (!esgs_ring_bo
&& !gsvs_ring_bo
)
2053 radv_cs_add_buffer(queue
->device
->ws
, cs
, esgs_ring_bo
);
2056 radv_cs_add_buffer(queue
->device
->ws
, cs
, gsvs_ring_bo
);
2058 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2059 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
2060 radeon_emit(cs
, esgs_ring_size
>> 8);
2061 radeon_emit(cs
, gsvs_ring_size
>> 8);
2063 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
2064 radeon_emit(cs
, esgs_ring_size
>> 8);
2065 radeon_emit(cs
, gsvs_ring_size
>> 8);
2070 radv_emit_tess_factor_ring(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2071 unsigned hs_offchip_param
, unsigned tf_ring_size
,
2072 struct radeon_winsys_bo
*tess_rings_bo
)
2079 tf_va
= radv_buffer_get_va(tess_rings_bo
);
2081 radv_cs_add_buffer(queue
->device
->ws
, cs
, tess_rings_bo
);
2083 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2084 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
2085 S_030938_SIZE(tf_ring_size
/ 4));
2086 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
2088 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2089 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
2090 S_030944_BASE_HI(tf_va
>> 40));
2092 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
,
2095 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
2096 S_008988_SIZE(tf_ring_size
/ 4));
2097 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
2099 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
2105 radv_emit_compute_scratch(struct radv_queue
*queue
, struct radeon_cmdbuf
*cs
,
2106 struct radeon_winsys_bo
*compute_scratch_bo
)
2108 uint64_t scratch_va
;
2110 if (!compute_scratch_bo
)
2113 scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
2115 radv_cs_add_buffer(queue
->device
->ws
, cs
, compute_scratch_bo
);
2117 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
2118 radeon_emit(cs
, scratch_va
);
2119 radeon_emit(cs
, S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2120 S_008F04_SWIZZLE_ENABLE(1));
2124 radv_emit_global_shader_pointers(struct radv_queue
*queue
,
2125 struct radeon_cmdbuf
*cs
,
2126 struct radeon_winsys_bo
*descriptor_bo
)
2133 va
= radv_buffer_get_va(descriptor_bo
);
2135 radv_cs_add_buffer(queue
->device
->ws
, cs
, descriptor_bo
);
2137 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2138 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2139 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2140 R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS
,
2141 R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS
};
2143 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2144 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2148 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
2149 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
2150 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
2151 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
2152 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
2153 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
2155 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
2156 radv_emit_shader_pointer(queue
->device
, cs
, regs
[i
],
2163 radv_init_graphics_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2165 struct radv_device
*device
= queue
->device
;
2167 if (device
->gfx_init
) {
2168 uint64_t va
= radv_buffer_get_va(device
->gfx_init
);
2170 radeon_emit(cs
, PKT3(PKT3_INDIRECT_BUFFER_CIK
, 2, 0));
2171 radeon_emit(cs
, va
);
2172 radeon_emit(cs
, va
>> 32);
2173 radeon_emit(cs
, device
->gfx_init_size_dw
& 0xffff);
2175 radv_cs_add_buffer(device
->ws
, cs
, device
->gfx_init
);
2177 struct radv_physical_device
*physical_device
= device
->physical_device
;
2178 si_emit_graphics(physical_device
, cs
);
2183 radv_init_compute_state(struct radeon_cmdbuf
*cs
, struct radv_queue
*queue
)
2185 struct radv_physical_device
*physical_device
= queue
->device
->physical_device
;
2186 si_emit_compute(physical_device
, cs
);
2190 radv_get_preamble_cs(struct radv_queue
*queue
,
2191 uint32_t scratch_size
,
2192 uint32_t compute_scratch_size
,
2193 uint32_t esgs_ring_size
,
2194 uint32_t gsvs_ring_size
,
2195 bool needs_tess_rings
,
2196 bool needs_sample_positions
,
2197 struct radeon_cmdbuf
**initial_full_flush_preamble_cs
,
2198 struct radeon_cmdbuf
**initial_preamble_cs
,
2199 struct radeon_cmdbuf
**continue_preamble_cs
)
2201 struct radeon_winsys_bo
*scratch_bo
= NULL
;
2202 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
2203 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
2204 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
2205 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
2206 struct radeon_winsys_bo
*tess_rings_bo
= NULL
;
2207 struct radeon_cmdbuf
*dest_cs
[3] = {0};
2208 bool add_tess_rings
= false, add_sample_positions
= false;
2209 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
2210 unsigned max_offchip_buffers
;
2211 unsigned hs_offchip_param
= 0;
2212 unsigned tess_offchip_ring_offset
;
2213 uint32_t ring_bo_flags
= RADEON_FLAG_NO_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
;
2214 if (!queue
->has_tess_rings
) {
2215 if (needs_tess_rings
)
2216 add_tess_rings
= true;
2218 if (!queue
->has_sample_positions
) {
2219 if (needs_sample_positions
)
2220 add_sample_positions
= true;
2222 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
2223 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
2224 &max_offchip_buffers
);
2225 tess_offchip_ring_offset
= align(tess_factor_ring_size
, 64 * 1024);
2226 tess_offchip_ring_size
= max_offchip_buffers
*
2227 queue
->device
->tess_offchip_block_dw_size
* 4;
2229 if (scratch_size
<= queue
->scratch_size
&&
2230 compute_scratch_size
<= queue
->compute_scratch_size
&&
2231 esgs_ring_size
<= queue
->esgs_ring_size
&&
2232 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
2233 !add_tess_rings
&& !add_sample_positions
&&
2234 queue
->initial_preamble_cs
) {
2235 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2236 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2237 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2238 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2239 *continue_preamble_cs
= NULL
;
2243 if (scratch_size
> queue
->scratch_size
) {
2244 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2252 scratch_bo
= queue
->scratch_bo
;
2254 if (compute_scratch_size
> queue
->compute_scratch_size
) {
2255 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2256 compute_scratch_size
,
2260 if (!compute_scratch_bo
)
2264 compute_scratch_bo
= queue
->compute_scratch_bo
;
2266 if (esgs_ring_size
> queue
->esgs_ring_size
) {
2267 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2275 esgs_ring_bo
= queue
->esgs_ring_bo
;
2276 esgs_ring_size
= queue
->esgs_ring_size
;
2279 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
2280 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2288 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
2289 gsvs_ring_size
= queue
->gsvs_ring_size
;
2292 if (add_tess_rings
) {
2293 tess_rings_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2294 tess_offchip_ring_offset
+ tess_offchip_ring_size
,
2301 tess_rings_bo
= queue
->tess_rings_bo
;
2304 if (scratch_bo
!= queue
->scratch_bo
||
2305 esgs_ring_bo
!= queue
->esgs_ring_bo
||
2306 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
2307 tess_rings_bo
!= queue
->tess_rings_bo
||
2308 add_sample_positions
) {
2310 if (gsvs_ring_bo
|| esgs_ring_bo
||
2311 tess_rings_bo
|| add_sample_positions
) {
2312 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
2313 if (add_sample_positions
)
2314 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
2316 else if (scratch_bo
)
2317 size
= 8; /* 2 dword */
2319 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
2323 RADEON_FLAG_CPU_ACCESS
|
2324 RADEON_FLAG_NO_INTERPROCESS_SHARING
|
2325 RADEON_FLAG_READ_ONLY
);
2329 descriptor_bo
= queue
->descriptor_bo
;
2331 for(int i
= 0; i
< 3; ++i
) {
2332 struct radeon_cmdbuf
*cs
= NULL
;
2333 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
2334 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
2341 radv_cs_add_buffer(queue
->device
->ws
, cs
, scratch_bo
);
2343 /* Emit initial configuration. */
2344 switch (queue
->queue_family_index
) {
2345 case RADV_QUEUE_GENERAL
:
2346 radv_init_graphics_state(cs
, queue
);
2348 case RADV_QUEUE_COMPUTE
:
2349 radv_init_compute_state(cs
, queue
);
2351 case RADV_QUEUE_TRANSFER
:
2355 if (descriptor_bo
!= queue
->descriptor_bo
) {
2356 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
2359 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
2360 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
2361 S_008F04_SWIZZLE_ENABLE(1);
2362 map
[0] = scratch_va
;
2366 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
||
2367 add_sample_positions
)
2368 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
2369 esgs_ring_size
, esgs_ring_bo
,
2370 gsvs_ring_size
, gsvs_ring_bo
,
2371 tess_factor_ring_size
,
2372 tess_offchip_ring_offset
,
2373 tess_offchip_ring_size
,
2376 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
2379 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_rings_bo
) {
2380 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2381 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2382 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2383 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
2386 radv_emit_gs_ring_sizes(queue
, cs
, esgs_ring_bo
, esgs_ring_size
,
2387 gsvs_ring_bo
, gsvs_ring_size
);
2388 radv_emit_tess_factor_ring(queue
, cs
, hs_offchip_param
,
2389 tess_factor_ring_size
, tess_rings_bo
);
2390 radv_emit_global_shader_pointers(queue
, cs
, descriptor_bo
);
2391 radv_emit_compute_scratch(queue
, cs
, compute_scratch_bo
);
2394 si_cs_emit_cache_flush(cs
,
2395 queue
->device
->physical_device
->rad_info
.chip_class
,
2397 queue
->queue_family_index
== RING_COMPUTE
&&
2398 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2399 (queue
->queue_family_index
== RADV_QUEUE_COMPUTE
? RADV_CMD_FLAG_CS_PARTIAL_FLUSH
: (RADV_CMD_FLAG_CS_PARTIAL_FLUSH
| RADV_CMD_FLAG_PS_PARTIAL_FLUSH
)) |
2400 RADV_CMD_FLAG_INV_ICACHE
|
2401 RADV_CMD_FLAG_INV_SMEM_L1
|
2402 RADV_CMD_FLAG_INV_VMEM_L1
|
2403 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2404 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2405 } else if (i
== 1) {
2406 si_cs_emit_cache_flush(cs
,
2407 queue
->device
->physical_device
->rad_info
.chip_class
,
2409 queue
->queue_family_index
== RING_COMPUTE
&&
2410 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
2411 RADV_CMD_FLAG_INV_ICACHE
|
2412 RADV_CMD_FLAG_INV_SMEM_L1
|
2413 RADV_CMD_FLAG_INV_VMEM_L1
|
2414 RADV_CMD_FLAG_INV_GLOBAL_L2
|
2415 RADV_CMD_FLAG_START_PIPELINE_STATS
, 0);
2418 if (!queue
->device
->ws
->cs_finalize(cs
))
2422 if (queue
->initial_full_flush_preamble_cs
)
2423 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
2425 if (queue
->initial_preamble_cs
)
2426 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
2428 if (queue
->continue_preamble_cs
)
2429 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
2431 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
2432 queue
->initial_preamble_cs
= dest_cs
[1];
2433 queue
->continue_preamble_cs
= dest_cs
[2];
2435 if (scratch_bo
!= queue
->scratch_bo
) {
2436 if (queue
->scratch_bo
)
2437 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
2438 queue
->scratch_bo
= scratch_bo
;
2439 queue
->scratch_size
= scratch_size
;
2442 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
2443 if (queue
->compute_scratch_bo
)
2444 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
2445 queue
->compute_scratch_bo
= compute_scratch_bo
;
2446 queue
->compute_scratch_size
= compute_scratch_size
;
2449 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
2450 if (queue
->esgs_ring_bo
)
2451 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
2452 queue
->esgs_ring_bo
= esgs_ring_bo
;
2453 queue
->esgs_ring_size
= esgs_ring_size
;
2456 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
2457 if (queue
->gsvs_ring_bo
)
2458 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
2459 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
2460 queue
->gsvs_ring_size
= gsvs_ring_size
;
2463 if (tess_rings_bo
!= queue
->tess_rings_bo
) {
2464 queue
->tess_rings_bo
= tess_rings_bo
;
2465 queue
->has_tess_rings
= true;
2468 if (descriptor_bo
!= queue
->descriptor_bo
) {
2469 if (queue
->descriptor_bo
)
2470 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
2472 queue
->descriptor_bo
= descriptor_bo
;
2475 if (add_sample_positions
)
2476 queue
->has_sample_positions
= true;
2478 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
2479 *initial_preamble_cs
= queue
->initial_preamble_cs
;
2480 *continue_preamble_cs
= queue
->continue_preamble_cs
;
2481 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
2482 *continue_preamble_cs
= NULL
;
2485 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
2487 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
2488 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
2489 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
2490 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
2491 queue
->device
->ws
->buffer_destroy(scratch_bo
);
2492 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
2493 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
2494 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
2495 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
2496 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
2497 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
2498 if (tess_rings_bo
&& tess_rings_bo
!= queue
->tess_rings_bo
)
2499 queue
->device
->ws
->buffer_destroy(tess_rings_bo
);
2500 return vk_error(queue
->device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2503 static VkResult
radv_alloc_sem_counts(struct radv_instance
*instance
,
2504 struct radv_winsys_sem_counts
*counts
,
2506 const VkSemaphore
*sems
,
2510 int syncobj_idx
= 0, sem_idx
= 0;
2512 if (num_sems
== 0 && _fence
== VK_NULL_HANDLE
)
2515 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2516 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2518 if (sem
->temp_syncobj
|| sem
->syncobj
)
2519 counts
->syncobj_count
++;
2521 counts
->sem_count
++;
2524 if (_fence
!= VK_NULL_HANDLE
) {
2525 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2526 if (fence
->temp_syncobj
|| fence
->syncobj
)
2527 counts
->syncobj_count
++;
2530 if (counts
->syncobj_count
) {
2531 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2532 if (!counts
->syncobj
)
2533 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2536 if (counts
->sem_count
) {
2537 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2539 free(counts
->syncobj
);
2540 return vk_error(instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2544 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2545 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2547 if (sem
->temp_syncobj
) {
2548 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2550 else if (sem
->syncobj
)
2551 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2554 counts
->sem
[sem_idx
++] = sem
->sem
;
2558 if (_fence
!= VK_NULL_HANDLE
) {
2559 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2560 if (fence
->temp_syncobj
)
2561 counts
->syncobj
[syncobj_idx
++] = fence
->temp_syncobj
;
2562 else if (fence
->syncobj
)
2563 counts
->syncobj
[syncobj_idx
++] = fence
->syncobj
;
2570 radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2572 free(sem_info
->wait
.syncobj
);
2573 free(sem_info
->wait
.sem
);
2574 free(sem_info
->signal
.syncobj
);
2575 free(sem_info
->signal
.sem
);
2579 static void radv_free_temp_syncobjs(struct radv_device
*device
,
2581 const VkSemaphore
*sems
)
2583 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2584 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2586 if (sem
->temp_syncobj
) {
2587 device
->ws
->destroy_syncobj(device
->ws
, sem
->temp_syncobj
);
2588 sem
->temp_syncobj
= 0;
2594 radv_alloc_sem_info(struct radv_instance
*instance
,
2595 struct radv_winsys_sem_info
*sem_info
,
2597 const VkSemaphore
*wait_sems
,
2598 int num_signal_sems
,
2599 const VkSemaphore
*signal_sems
,
2603 memset(sem_info
, 0, sizeof(*sem_info
));
2605 ret
= radv_alloc_sem_counts(instance
, &sem_info
->wait
, num_wait_sems
, wait_sems
, VK_NULL_HANDLE
, true);
2608 ret
= radv_alloc_sem_counts(instance
, &sem_info
->signal
, num_signal_sems
, signal_sems
, fence
, false);
2610 radv_free_sem_info(sem_info
);
2612 /* caller can override these */
2613 sem_info
->cs_emit_wait
= true;
2614 sem_info
->cs_emit_signal
= true;
2618 /* Signals fence as soon as all the work currently put on queue is done. */
2619 static VkResult
radv_signal_fence(struct radv_queue
*queue
,
2620 struct radv_fence
*fence
)
2624 struct radv_winsys_sem_info sem_info
;
2626 result
= radv_alloc_sem_info(queue
->device
->instance
, &sem_info
, 0, NULL
, 0, NULL
,
2627 radv_fence_to_handle(fence
));
2628 if (result
!= VK_SUCCESS
)
2631 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2632 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2633 1, NULL
, NULL
, &sem_info
, NULL
,
2634 false, fence
->fence
);
2635 radv_free_sem_info(&sem_info
);
2638 return vk_error(queue
->device
->instance
, VK_ERROR_DEVICE_LOST
);
2643 VkResult
radv_QueueSubmit(
2645 uint32_t submitCount
,
2646 const VkSubmitInfo
* pSubmits
,
2649 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2650 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2651 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2652 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2654 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2655 uint32_t scratch_size
= 0;
2656 uint32_t compute_scratch_size
= 0;
2657 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2658 struct radeon_cmdbuf
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2660 bool fence_emitted
= false;
2661 bool tess_rings_needed
= false;
2662 bool sample_positions_needed
= false;
2664 /* Do this first so failing to allocate scratch buffers can't result in
2665 * partially executed submissions. */
2666 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2667 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2668 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2669 pSubmits
[i
].pCommandBuffers
[j
]);
2671 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2672 compute_scratch_size
= MAX2(compute_scratch_size
,
2673 cmd_buffer
->compute_scratch_size_needed
);
2674 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2675 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2676 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2677 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2681 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2682 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2683 sample_positions_needed
, &initial_flush_preamble_cs
,
2684 &initial_preamble_cs
, &continue_preamble_cs
);
2685 if (result
!= VK_SUCCESS
)
2688 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2689 struct radeon_cmdbuf
**cs_array
;
2690 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2691 bool can_patch
= true;
2693 struct radv_winsys_sem_info sem_info
;
2695 result
= radv_alloc_sem_info(queue
->device
->instance
,
2697 pSubmits
[i
].waitSemaphoreCount
,
2698 pSubmits
[i
].pWaitSemaphores
,
2699 pSubmits
[i
].signalSemaphoreCount
,
2700 pSubmits
[i
].pSignalSemaphores
,
2702 if (result
!= VK_SUCCESS
)
2705 if (!pSubmits
[i
].commandBufferCount
) {
2706 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2707 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2708 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2713 radv_loge("failed to submit CS %d\n", i
);
2716 fence_emitted
= true;
2718 radv_free_sem_info(&sem_info
);
2722 cs_array
= malloc(sizeof(struct radeon_cmdbuf
*) *
2723 (pSubmits
[i
].commandBufferCount
));
2725 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2726 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2727 pSubmits
[i
].pCommandBuffers
[j
]);
2728 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2730 cs_array
[j
] = cmd_buffer
->cs
;
2731 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2734 cmd_buffer
->status
= RADV_CMD_BUFFER_STATUS_PENDING
;
2737 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2738 struct radeon_cmdbuf
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2739 const struct radv_winsys_bo_list
*bo_list
= NULL
;
2741 advance
= MIN2(max_cs_submission
,
2742 pSubmits
[i
].commandBufferCount
- j
);
2744 if (queue
->device
->trace_bo
)
2745 *queue
->device
->trace_id_ptr
= 0;
2747 sem_info
.cs_emit_wait
= j
== 0;
2748 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2750 if (unlikely(queue
->device
->use_global_bo_list
)) {
2751 pthread_mutex_lock(&queue
->device
->bo_list
.mutex
);
2752 bo_list
= &queue
->device
->bo_list
.list
;
2755 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2756 advance
, initial_preamble
, continue_preamble_cs
,
2758 can_patch
, base_fence
);
2760 if (unlikely(queue
->device
->use_global_bo_list
))
2761 pthread_mutex_unlock(&queue
->device
->bo_list
.mutex
);
2764 radv_loge("failed to submit CS %d\n", i
);
2767 fence_emitted
= true;
2768 if (queue
->device
->trace_bo
) {
2769 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2773 radv_free_temp_syncobjs(queue
->device
,
2774 pSubmits
[i
].waitSemaphoreCount
,
2775 pSubmits
[i
].pWaitSemaphores
);
2776 radv_free_sem_info(&sem_info
);
2781 if (!fence_emitted
) {
2782 result
= radv_signal_fence(queue
, fence
);
2783 if (result
!= VK_SUCCESS
)
2786 fence
->submitted
= true;
2792 VkResult
radv_QueueWaitIdle(
2795 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2797 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2798 radv_queue_family_to_ring(queue
->queue_family_index
),
2803 VkResult
radv_DeviceWaitIdle(
2806 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2808 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2809 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2810 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2816 VkResult
radv_EnumerateInstanceExtensionProperties(
2817 const char* pLayerName
,
2818 uint32_t* pPropertyCount
,
2819 VkExtensionProperties
* pProperties
)
2821 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2823 for (int i
= 0; i
< RADV_INSTANCE_EXTENSION_COUNT
; i
++) {
2824 if (radv_supported_instance_extensions
.extensions
[i
]) {
2825 vk_outarray_append(&out
, prop
) {
2826 *prop
= radv_instance_extensions
[i
];
2831 return vk_outarray_status(&out
);
2834 VkResult
radv_EnumerateDeviceExtensionProperties(
2835 VkPhysicalDevice physicalDevice
,
2836 const char* pLayerName
,
2837 uint32_t* pPropertyCount
,
2838 VkExtensionProperties
* pProperties
)
2840 RADV_FROM_HANDLE(radv_physical_device
, device
, physicalDevice
);
2841 VK_OUTARRAY_MAKE(out
, pProperties
, pPropertyCount
);
2843 for (int i
= 0; i
< RADV_DEVICE_EXTENSION_COUNT
; i
++) {
2844 if (device
->supported_extensions
.extensions
[i
]) {
2845 vk_outarray_append(&out
, prop
) {
2846 *prop
= radv_device_extensions
[i
];
2851 return vk_outarray_status(&out
);
2854 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2855 VkInstance _instance
,
2858 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
2860 return radv_lookup_entrypoint_checked(pName
,
2861 instance
? instance
->apiVersion
: 0,
2862 instance
? &instance
->enabled_extensions
: NULL
,
2866 /* The loader wants us to expose a second GetInstanceProcAddr function
2867 * to work around certain LD_PRELOAD issues seen in apps.
2870 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2871 VkInstance instance
,
2875 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2876 VkInstance instance
,
2879 return radv_GetInstanceProcAddr(instance
, pName
);
2882 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2886 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2888 return radv_lookup_entrypoint_checked(pName
,
2889 device
->instance
->apiVersion
,
2890 &device
->instance
->enabled_extensions
,
2891 &device
->enabled_extensions
);
2894 bool radv_get_memory_fd(struct radv_device
*device
,
2895 struct radv_device_memory
*memory
,
2898 struct radeon_bo_metadata metadata
;
2900 if (memory
->image
) {
2901 radv_init_metadata(device
, memory
->image
, &metadata
);
2902 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2905 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2909 static VkResult
radv_alloc_memory(struct radv_device
*device
,
2910 const VkMemoryAllocateInfo
* pAllocateInfo
,
2911 const VkAllocationCallbacks
* pAllocator
,
2912 VkDeviceMemory
* pMem
)
2914 struct radv_device_memory
*mem
;
2916 enum radeon_bo_domain domain
;
2918 enum radv_mem_type mem_type_index
= device
->physical_device
->mem_type_indices
[pAllocateInfo
->memoryTypeIndex
];
2920 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2922 if (pAllocateInfo
->allocationSize
== 0) {
2923 /* Apparently, this is allowed */
2924 *pMem
= VK_NULL_HANDLE
;
2928 const VkImportMemoryFdInfoKHR
*import_info
=
2929 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2930 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2931 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2932 const VkExportMemoryAllocateInfoKHR
*export_info
=
2933 vk_find_struct_const(pAllocateInfo
->pNext
, EXPORT_MEMORY_ALLOCATE_INFO_KHR
);
2934 const VkImportMemoryHostPointerInfoEXT
*host_ptr_info
=
2935 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_HOST_POINTER_INFO_EXT
);
2937 const struct wsi_memory_allocate_info
*wsi_info
=
2938 vk_find_struct_const(pAllocateInfo
->pNext
, WSI_MEMORY_ALLOCATE_INFO_MESA
);
2940 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2941 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2943 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
2945 if (wsi_info
&& wsi_info
->implicit_sync
)
2946 flags
|= RADEON_FLAG_IMPLICIT_SYNC
;
2948 if (dedicate_info
) {
2949 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2950 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2956 mem
->user_ptr
= NULL
;
2959 assert(import_info
->handleType
==
2960 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
2961 import_info
->handleType
==
2962 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
2963 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2966 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2969 close(import_info
->fd
);
2971 } else if (host_ptr_info
) {
2972 assert(host_ptr_info
->handleType
== VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT
);
2973 assert(mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
);
2974 mem
->bo
= device
->ws
->buffer_from_ptr(device
->ws
, host_ptr_info
->pHostPointer
,
2975 pAllocateInfo
->allocationSize
);
2977 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2980 mem
->user_ptr
= host_ptr_info
->pHostPointer
;
2983 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2984 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2985 mem_type_index
== RADV_MEM_TYPE_GTT_CACHED
)
2986 domain
= RADEON_DOMAIN_GTT
;
2988 domain
= RADEON_DOMAIN_VRAM
;
2990 if (mem_type_index
== RADV_MEM_TYPE_VRAM
)
2991 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2993 flags
|= RADEON_FLAG_CPU_ACCESS
;
2995 if (mem_type_index
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2996 flags
|= RADEON_FLAG_GTT_WC
;
2998 if (!dedicate_info
&& !import_info
&& (!export_info
|| !export_info
->handleTypes
))
2999 flags
|= RADEON_FLAG_NO_INTERPROCESS_SHARING
;
3001 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
3005 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3008 mem
->type_index
= mem_type_index
;
3011 result
= radv_bo_list_add(device
, mem
->bo
);
3012 if (result
!= VK_SUCCESS
)
3015 *pMem
= radv_device_memory_to_handle(mem
);
3020 device
->ws
->buffer_destroy(mem
->bo
);
3022 vk_free2(&device
->alloc
, pAllocator
, mem
);
3027 VkResult
radv_AllocateMemory(
3029 const VkMemoryAllocateInfo
* pAllocateInfo
,
3030 const VkAllocationCallbacks
* pAllocator
,
3031 VkDeviceMemory
* pMem
)
3033 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3034 return radv_alloc_memory(device
, pAllocateInfo
, pAllocator
, pMem
);
3037 void radv_FreeMemory(
3039 VkDeviceMemory _mem
,
3040 const VkAllocationCallbacks
* pAllocator
)
3042 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3043 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
3048 radv_bo_list_remove(device
, mem
->bo
);
3049 device
->ws
->buffer_destroy(mem
->bo
);
3052 vk_free2(&device
->alloc
, pAllocator
, mem
);
3055 VkResult
radv_MapMemory(
3057 VkDeviceMemory _memory
,
3058 VkDeviceSize offset
,
3060 VkMemoryMapFlags flags
,
3063 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3064 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3072 *ppData
= mem
->user_ptr
;
3074 *ppData
= device
->ws
->buffer_map(mem
->bo
);
3081 return vk_error(device
->instance
, VK_ERROR_MEMORY_MAP_FAILED
);
3084 void radv_UnmapMemory(
3086 VkDeviceMemory _memory
)
3088 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3089 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
3094 if (mem
->user_ptr
== NULL
)
3095 device
->ws
->buffer_unmap(mem
->bo
);
3098 VkResult
radv_FlushMappedMemoryRanges(
3100 uint32_t memoryRangeCount
,
3101 const VkMappedMemoryRange
* pMemoryRanges
)
3106 VkResult
radv_InvalidateMappedMemoryRanges(
3108 uint32_t memoryRangeCount
,
3109 const VkMappedMemoryRange
* pMemoryRanges
)
3114 void radv_GetBufferMemoryRequirements(
3117 VkMemoryRequirements
* pMemoryRequirements
)
3119 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3120 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3122 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3124 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3125 pMemoryRequirements
->alignment
= 4096;
3127 pMemoryRequirements
->alignment
= 16;
3129 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
3132 void radv_GetBufferMemoryRequirements2(
3134 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
3135 VkMemoryRequirements2KHR
* pMemoryRequirements
)
3137 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
3138 &pMemoryRequirements
->memoryRequirements
);
3139 RADV_FROM_HANDLE(radv_buffer
, buffer
, pInfo
->buffer
);
3140 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3141 switch (ext
->sType
) {
3142 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
3143 VkMemoryDedicatedRequirementsKHR
*req
=
3144 (VkMemoryDedicatedRequirementsKHR
*) ext
;
3145 req
->requiresDedicatedAllocation
= buffer
->shareable
;
3146 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3155 void radv_GetImageMemoryRequirements(
3158 VkMemoryRequirements
* pMemoryRequirements
)
3160 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3161 RADV_FROM_HANDLE(radv_image
, image
, _image
);
3163 pMemoryRequirements
->memoryTypeBits
= (1u << device
->physical_device
->memory_properties
.memoryTypeCount
) - 1;
3165 pMemoryRequirements
->size
= image
->size
;
3166 pMemoryRequirements
->alignment
= image
->alignment
;
3169 void radv_GetImageMemoryRequirements2(
3171 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
3172 VkMemoryRequirements2KHR
* pMemoryRequirements
)
3174 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
3175 &pMemoryRequirements
->memoryRequirements
);
3177 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
3179 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
3180 switch (ext
->sType
) {
3181 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
3182 VkMemoryDedicatedRequirementsKHR
*req
=
3183 (VkMemoryDedicatedRequirementsKHR
*) ext
;
3184 req
->requiresDedicatedAllocation
= image
->shareable
;
3185 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
3194 void radv_GetImageSparseMemoryRequirements(
3197 uint32_t* pSparseMemoryRequirementCount
,
3198 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
3203 void radv_GetImageSparseMemoryRequirements2(
3205 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
3206 uint32_t* pSparseMemoryRequirementCount
,
3207 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
3212 void radv_GetDeviceMemoryCommitment(
3214 VkDeviceMemory memory
,
3215 VkDeviceSize
* pCommittedMemoryInBytes
)
3217 *pCommittedMemoryInBytes
= 0;
3220 VkResult
radv_BindBufferMemory2(VkDevice device
,
3221 uint32_t bindInfoCount
,
3222 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
3224 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3225 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3226 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
3229 buffer
->bo
= mem
->bo
;
3230 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
3238 VkResult
radv_BindBufferMemory(
3241 VkDeviceMemory memory
,
3242 VkDeviceSize memoryOffset
)
3244 const VkBindBufferMemoryInfoKHR info
= {
3245 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3248 .memoryOffset
= memoryOffset
3251 return radv_BindBufferMemory2(device
, 1, &info
);
3254 VkResult
radv_BindImageMemory2(VkDevice device
,
3255 uint32_t bindInfoCount
,
3256 const VkBindImageMemoryInfoKHR
*pBindInfos
)
3258 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3259 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
3260 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
3263 image
->bo
= mem
->bo
;
3264 image
->offset
= pBindInfos
[i
].memoryOffset
;
3274 VkResult
radv_BindImageMemory(
3277 VkDeviceMemory memory
,
3278 VkDeviceSize memoryOffset
)
3280 const VkBindImageMemoryInfoKHR info
= {
3281 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
3284 .memoryOffset
= memoryOffset
3287 return radv_BindImageMemory2(device
, 1, &info
);
3292 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
3293 const VkSparseBufferMemoryBindInfo
*bind
)
3295 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
3297 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3298 struct radv_device_memory
*mem
= NULL
;
3300 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3301 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3303 device
->ws
->buffer_virtual_bind(buffer
->bo
,
3304 bind
->pBinds
[i
].resourceOffset
,
3305 bind
->pBinds
[i
].size
,
3306 mem
? mem
->bo
: NULL
,
3307 bind
->pBinds
[i
].memoryOffset
);
3312 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
3313 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
3315 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
3317 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
3318 struct radv_device_memory
*mem
= NULL
;
3320 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
3321 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
3323 device
->ws
->buffer_virtual_bind(image
->bo
,
3324 bind
->pBinds
[i
].resourceOffset
,
3325 bind
->pBinds
[i
].size
,
3326 mem
? mem
->bo
: NULL
,
3327 bind
->pBinds
[i
].memoryOffset
);
3331 VkResult
radv_QueueBindSparse(
3333 uint32_t bindInfoCount
,
3334 const VkBindSparseInfo
* pBindInfo
,
3337 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3338 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
3339 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
3340 bool fence_emitted
= false;
3344 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
3345 struct radv_winsys_sem_info sem_info
;
3346 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
3347 radv_sparse_buffer_bind_memory(queue
->device
,
3348 pBindInfo
[i
].pBufferBinds
+ j
);
3351 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
3352 radv_sparse_image_opaque_bind_memory(queue
->device
,
3353 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
3357 result
= radv_alloc_sem_info(queue
->device
->instance
,
3359 pBindInfo
[i
].waitSemaphoreCount
,
3360 pBindInfo
[i
].pWaitSemaphores
,
3361 pBindInfo
[i
].signalSemaphoreCount
,
3362 pBindInfo
[i
].pSignalSemaphores
,
3364 if (result
!= VK_SUCCESS
)
3367 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
3368 ret
= queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
3369 &queue
->device
->empty_cs
[queue
->queue_family_index
],
3374 radv_loge("failed to submit CS %d\n", i
);
3378 fence_emitted
= true;
3380 fence
->submitted
= true;
3383 radv_free_sem_info(&sem_info
);
3388 if (!fence_emitted
) {
3389 result
= radv_signal_fence(queue
, fence
);
3390 if (result
!= VK_SUCCESS
)
3393 fence
->submitted
= true;
3399 VkResult
radv_CreateFence(
3401 const VkFenceCreateInfo
* pCreateInfo
,
3402 const VkAllocationCallbacks
* pAllocator
,
3405 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3406 const VkExportFenceCreateInfoKHR
*export
=
3407 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_FENCE_CREATE_INFO_KHR
);
3408 VkExternalFenceHandleTypeFlagsKHR handleTypes
=
3409 export
? export
->handleTypes
: 0;
3411 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
3413 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3416 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3418 fence
->fence_wsi
= NULL
;
3419 fence
->submitted
= false;
3420 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
3421 fence
->temp_syncobj
= 0;
3422 if (device
->always_use_syncobj
|| handleTypes
) {
3423 int ret
= device
->ws
->create_syncobj(device
->ws
, &fence
->syncobj
);
3425 vk_free2(&device
->alloc
, pAllocator
, fence
);
3426 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3428 if (pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
) {
3429 device
->ws
->signal_syncobj(device
->ws
, fence
->syncobj
);
3431 fence
->fence
= NULL
;
3433 fence
->fence
= device
->ws
->create_fence();
3434 if (!fence
->fence
) {
3435 vk_free2(&device
->alloc
, pAllocator
, fence
);
3436 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3441 *pFence
= radv_fence_to_handle(fence
);
3446 void radv_DestroyFence(
3449 const VkAllocationCallbacks
* pAllocator
)
3451 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3452 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3457 if (fence
->temp_syncobj
)
3458 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3460 device
->ws
->destroy_syncobj(device
->ws
, fence
->syncobj
);
3462 device
->ws
->destroy_fence(fence
->fence
);
3463 if (fence
->fence_wsi
)
3464 fence
->fence_wsi
->destroy(fence
->fence_wsi
);
3465 vk_free2(&device
->alloc
, pAllocator
, fence
);
3469 static uint64_t radv_get_current_time()
3472 clock_gettime(CLOCK_MONOTONIC
, &tv
);
3473 return tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
3476 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
3478 uint64_t current_time
= radv_get_current_time();
3480 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
3482 return current_time
+ timeout
;
3486 static bool radv_all_fences_plain_and_submitted(uint32_t fenceCount
, const VkFence
*pFences
)
3488 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3489 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3490 if (fence
->fence
== NULL
|| fence
->syncobj
||
3491 fence
->temp_syncobj
||
3492 (!fence
->signalled
&& !fence
->submitted
))
3498 static bool radv_all_fences_syncobj(uint32_t fenceCount
, const VkFence
*pFences
)
3500 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3501 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3502 if (fence
->syncobj
== 0 && fence
->temp_syncobj
== 0)
3508 VkResult
radv_WaitForFences(
3510 uint32_t fenceCount
,
3511 const VkFence
* pFences
,
3515 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3516 timeout
= radv_get_absolute_timeout(timeout
);
3518 if (device
->always_use_syncobj
&&
3519 radv_all_fences_syncobj(fenceCount
, pFences
))
3521 uint32_t *handles
= malloc(sizeof(uint32_t) * fenceCount
);
3523 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3525 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3526 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3527 handles
[i
] = fence
->temp_syncobj
? fence
->temp_syncobj
: fence
->syncobj
;
3530 bool success
= device
->ws
->wait_syncobj(device
->ws
, handles
, fenceCount
, waitAll
, timeout
);
3533 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3536 if (!waitAll
&& fenceCount
> 1) {
3537 /* Not doing this by default for waitAll, due to needing to allocate twice. */
3538 if (device
->physical_device
->rad_info
.drm_minor
>= 10 && radv_all_fences_plain_and_submitted(fenceCount
, pFences
)) {
3539 uint32_t wait_count
= 0;
3540 struct radeon_winsys_fence
**fences
= malloc(sizeof(struct radeon_winsys_fence
*) * fenceCount
);
3542 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3544 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3545 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3547 if (fence
->signalled
) {
3552 fences
[wait_count
++] = fence
->fence
;
3555 bool success
= device
->ws
->fences_wait(device
->ws
, fences
, wait_count
,
3556 waitAll
, timeout
- radv_get_current_time());
3559 return success
? VK_SUCCESS
: VK_TIMEOUT
;
3562 while(radv_get_current_time() <= timeout
) {
3563 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3564 if (radv_GetFenceStatus(_device
, pFences
[i
]) == VK_SUCCESS
)
3571 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
3572 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3573 bool expired
= false;
3575 if (fence
->temp_syncobj
) {
3576 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, timeout
))
3581 if (fence
->syncobj
) {
3582 if (!device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, timeout
))
3587 if (fence
->signalled
)
3591 if (!fence
->submitted
) {
3592 while(radv_get_current_time() <= timeout
&&
3596 if (!fence
->submitted
)
3599 /* Recheck as it may have been set by
3600 * submitting operations. */
3602 if (fence
->signalled
)
3606 expired
= device
->ws
->fence_wait(device
->ws
,
3613 if (fence
->fence_wsi
) {
3614 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, timeout
);
3615 if (result
!= VK_SUCCESS
)
3619 fence
->signalled
= true;
3625 VkResult
radv_ResetFences(VkDevice _device
,
3626 uint32_t fenceCount
,
3627 const VkFence
*pFences
)
3629 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3631 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
3632 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
3633 fence
->submitted
= fence
->signalled
= false;
3635 /* Per spec, we first restore the permanent payload, and then reset, so
3636 * having a temp syncobj should not skip resetting the permanent syncobj. */
3637 if (fence
->temp_syncobj
) {
3638 device
->ws
->destroy_syncobj(device
->ws
, fence
->temp_syncobj
);
3639 fence
->temp_syncobj
= 0;
3642 if (fence
->syncobj
) {
3643 device
->ws
->reset_syncobj(device
->ws
, fence
->syncobj
);
3650 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
3652 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3653 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
3655 if (fence
->temp_syncobj
) {
3656 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->temp_syncobj
, 1, true, 0);
3657 return success
? VK_SUCCESS
: VK_NOT_READY
;
3660 if (fence
->syncobj
) {
3661 bool success
= device
->ws
->wait_syncobj(device
->ws
, &fence
->syncobj
, 1, true, 0);
3662 return success
? VK_SUCCESS
: VK_NOT_READY
;
3665 if (fence
->signalled
)
3667 if (!fence
->submitted
)
3668 return VK_NOT_READY
;
3670 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
3671 return VK_NOT_READY
;
3673 if (fence
->fence_wsi
) {
3674 VkResult result
= fence
->fence_wsi
->wait(fence
->fence_wsi
, 0);
3676 if (result
!= VK_SUCCESS
) {
3677 if (result
== VK_TIMEOUT
)
3678 return VK_NOT_READY
;
3686 // Queue semaphore functions
3688 VkResult
radv_CreateSemaphore(
3690 const VkSemaphoreCreateInfo
* pCreateInfo
,
3691 const VkAllocationCallbacks
* pAllocator
,
3692 VkSemaphore
* pSemaphore
)
3694 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3695 const VkExportSemaphoreCreateInfoKHR
*export
=
3696 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
3697 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
3698 export
? export
->handleTypes
: 0;
3700 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
3702 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3704 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3706 sem
->temp_syncobj
= 0;
3707 /* create a syncobject if we are going to export this semaphore */
3708 if (device
->always_use_syncobj
|| handleTypes
) {
3709 assert (device
->physical_device
->rad_info
.has_syncobj
);
3710 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
3712 vk_free2(&device
->alloc
, pAllocator
, sem
);
3713 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3717 sem
->sem
= device
->ws
->create_sem(device
->ws
);
3719 vk_free2(&device
->alloc
, pAllocator
, sem
);
3720 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3725 *pSemaphore
= radv_semaphore_to_handle(sem
);
3729 void radv_DestroySemaphore(
3731 VkSemaphore _semaphore
,
3732 const VkAllocationCallbacks
* pAllocator
)
3734 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3735 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
3740 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
3742 device
->ws
->destroy_sem(sem
->sem
);
3743 vk_free2(&device
->alloc
, pAllocator
, sem
);
3746 VkResult
radv_CreateEvent(
3748 const VkEventCreateInfo
* pCreateInfo
,
3749 const VkAllocationCallbacks
* pAllocator
,
3752 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3753 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
3755 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3758 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3760 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
3762 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
| RADEON_FLAG_NO_INTERPROCESS_SHARING
);
3764 vk_free2(&device
->alloc
, pAllocator
, event
);
3765 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3768 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
3770 *pEvent
= radv_event_to_handle(event
);
3775 void radv_DestroyEvent(
3778 const VkAllocationCallbacks
* pAllocator
)
3780 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3781 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3785 device
->ws
->buffer_destroy(event
->bo
);
3786 vk_free2(&device
->alloc
, pAllocator
, event
);
3789 VkResult
radv_GetEventStatus(
3793 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3795 if (*event
->map
== 1)
3796 return VK_EVENT_SET
;
3797 return VK_EVENT_RESET
;
3800 VkResult
radv_SetEvent(
3804 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3810 VkResult
radv_ResetEvent(
3814 RADV_FROM_HANDLE(radv_event
, event
, _event
);
3820 VkResult
radv_CreateBuffer(
3822 const VkBufferCreateInfo
* pCreateInfo
,
3823 const VkAllocationCallbacks
* pAllocator
,
3826 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3827 struct radv_buffer
*buffer
;
3829 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
3831 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
3832 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3834 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
3836 buffer
->size
= pCreateInfo
->size
;
3837 buffer
->usage
= pCreateInfo
->usage
;
3840 buffer
->flags
= pCreateInfo
->flags
;
3842 buffer
->shareable
= vk_find_struct_const(pCreateInfo
->pNext
,
3843 EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR
) != NULL
;
3845 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
3846 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
3847 align64(buffer
->size
, 4096),
3848 4096, 0, RADEON_FLAG_VIRTUAL
);
3850 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3851 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
3855 *pBuffer
= radv_buffer_to_handle(buffer
);
3860 void radv_DestroyBuffer(
3863 const VkAllocationCallbacks
* pAllocator
)
3865 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3866 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3871 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3872 device
->ws
->buffer_destroy(buffer
->bo
);
3874 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3877 static inline unsigned
3878 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3881 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3883 return image
->surface
.u
.legacy
.tiling_index
[level
];
3886 static uint32_t radv_surface_max_layer_count(struct radv_image_view
*iview
)
3888 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: (iview
->base_layer
+ iview
->layer_count
);
3892 radv_init_dcc_control_reg(struct radv_device
*device
,
3893 struct radv_image_view
*iview
)
3895 unsigned max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_256B
;
3896 unsigned min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_32B
;
3897 unsigned max_compressed_block_size
;
3898 unsigned independent_64b_blocks
;
3900 if (!radv_image_has_dcc(iview
->image
))
3903 if (iview
->image
->info
.samples
> 1) {
3904 if (iview
->image
->surface
.bpe
== 1)
3905 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3906 else if (iview
->image
->surface
.bpe
== 2)
3907 max_uncompressed_block_size
= V_028C78_MAX_BLOCK_SIZE_128B
;
3910 if (!device
->physical_device
->rad_info
.has_dedicated_vram
) {
3911 /* amdvlk: [min-compressed-block-size] should be set to 32 for
3912 * dGPU and 64 for APU because all of our APUs to date use
3913 * DIMMs which have a request granularity size of 64B while all
3914 * other chips have a 32B request size.
3916 min_compressed_block_size
= V_028C78_MIN_BLOCK_SIZE_64B
;
3919 if (iview
->image
->usage
& (VK_IMAGE_USAGE_SAMPLED_BIT
|
3920 VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
3921 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
)) {
3922 /* If this DCC image is potentially going to be used in texture
3923 * fetches, we need some special settings.
3925 independent_64b_blocks
= 1;
3926 max_compressed_block_size
= V_028C78_MAX_BLOCK_SIZE_64B
;
3928 /* MAX_UNCOMPRESSED_BLOCK_SIZE must be >=
3929 * MAX_COMPRESSED_BLOCK_SIZE. Set MAX_COMPRESSED_BLOCK_SIZE as
3930 * big as possible for better compression state.
3932 independent_64b_blocks
= 0;
3933 max_compressed_block_size
= max_uncompressed_block_size
;
3936 return S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3937 S_028C78_MAX_COMPRESSED_BLOCK_SIZE(max_compressed_block_size
) |
3938 S_028C78_MIN_COMPRESSED_BLOCK_SIZE(min_compressed_block_size
) |
3939 S_028C78_INDEPENDENT_64B_BLOCKS(independent_64b_blocks
);
3943 radv_initialise_color_surface(struct radv_device
*device
,
3944 struct radv_color_buffer_info
*cb
,
3945 struct radv_image_view
*iview
)
3947 const struct vk_format_description
*desc
;
3948 unsigned ntype
, format
, swap
, endian
;
3949 unsigned blend_clamp
= 0, blend_bypass
= 0;
3951 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3953 desc
= vk_format_description(iview
->vk_format
);
3955 memset(cb
, 0, sizeof(*cb
));
3957 /* Intensity is implemented as Red, so treat it that way. */
3958 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3960 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3962 cb
->cb_color_base
= va
>> 8;
3964 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3965 struct gfx9_surf_meta_flags meta
;
3966 if (iview
->image
->dcc_offset
)
3967 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3969 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3971 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3972 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3973 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3974 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3976 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3977 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3979 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3980 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3982 cb
->cb_color_base
+= level_info
->offset
>> 8;
3983 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3984 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3986 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3987 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3988 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3990 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3991 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3992 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3994 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3996 if (radv_image_has_fmask(iview
->image
)) {
3997 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3998 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3999 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
4000 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
4002 /* This must be set for fast clear to work without FMASK. */
4003 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
4004 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
4005 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
4006 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
4010 /* CMASK variables */
4011 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4012 va
+= iview
->image
->cmask
.offset
;
4013 cb
->cb_color_cmask
= va
>> 8;
4015 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4016 va
+= iview
->image
->dcc_offset
;
4017 cb
->cb_dcc_base
= va
>> 8;
4018 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
4020 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4021 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
4022 S_028C6C_SLICE_MAX(max_slice
);
4024 if (iview
->image
->info
.samples
> 1) {
4025 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
4027 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
4028 S_028C74_NUM_FRAGMENTS(log_samples
);
4031 if (radv_image_has_fmask(iview
->image
)) {
4032 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
4033 cb
->cb_color_fmask
= va
>> 8;
4034 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
4036 cb
->cb_color_fmask
= cb
->cb_color_base
;
4039 ntype
= radv_translate_color_numformat(iview
->vk_format
,
4041 vk_format_get_first_non_void_channel(iview
->vk_format
));
4042 format
= radv_translate_colorformat(iview
->vk_format
);
4043 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
4044 radv_finishme("Illegal color\n");
4045 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
4046 endian
= radv_colorformat_endian_swap(format
);
4048 /* blend clamp should be set for all NORM/SRGB types */
4049 if (ntype
== V_028C70_NUMBER_UNORM
||
4050 ntype
== V_028C70_NUMBER_SNORM
||
4051 ntype
== V_028C70_NUMBER_SRGB
)
4054 /* set blend bypass according to docs if SINT/UINT or
4055 8/24 COLOR variants */
4056 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
4057 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
4058 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
4063 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
4064 (format
== V_028C70_COLOR_8
||
4065 format
== V_028C70_COLOR_8_8
||
4066 format
== V_028C70_COLOR_8_8_8_8
))
4067 ->color_is_int8
= true;
4069 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
4070 S_028C70_COMP_SWAP(swap
) |
4071 S_028C70_BLEND_CLAMP(blend_clamp
) |
4072 S_028C70_BLEND_BYPASS(blend_bypass
) |
4073 S_028C70_SIMPLE_FLOAT(1) |
4074 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
4075 ntype
!= V_028C70_NUMBER_SNORM
&&
4076 ntype
!= V_028C70_NUMBER_SRGB
&&
4077 format
!= V_028C70_COLOR_8_24
&&
4078 format
!= V_028C70_COLOR_24_8
) |
4079 S_028C70_NUMBER_TYPE(ntype
) |
4080 S_028C70_ENDIAN(endian
);
4081 if (radv_image_has_fmask(iview
->image
)) {
4082 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
4083 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
4084 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
4085 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
4089 if (radv_image_has_cmask(iview
->image
) &&
4090 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
4091 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
4093 if (radv_dcc_enabled(iview
->image
, iview
->base_mip
))
4094 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
4096 cb
->cb_dcc_control
= radv_init_dcc_control_reg(device
, iview
);
4098 /* This must be set for fast clear to work without FMASK. */
4099 if (!radv_image_has_fmask(iview
->image
) &&
4100 device
->physical_device
->rad_info
.chip_class
== SI
) {
4101 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
4102 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
4105 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4106 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
4107 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
4109 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
4110 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
4111 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
4112 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
4113 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
4114 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
4119 radv_calc_decompress_on_z_planes(struct radv_device
*device
,
4120 struct radv_image_view
*iview
)
4122 unsigned max_zplanes
= 0;
4124 assert(radv_image_is_tc_compat_htile(iview
->image
));
4126 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4127 /* Default value for 32-bit depth surfaces. */
4130 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
4131 iview
->image
->info
.samples
> 1)
4134 max_zplanes
= max_zplanes
+ 1;
4136 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
) {
4137 /* Do not enable Z plane compression for 16-bit depth
4138 * surfaces because isn't supported on GFX8. Only
4139 * 32-bit depth surfaces are supported by the hardware.
4140 * This allows to maintain shader compatibility and to
4141 * reduce the number of depth decompressions.
4145 if (iview
->image
->info
.samples
<= 1)
4147 else if (iview
->image
->info
.samples
<= 4)
4158 radv_initialise_ds_surface(struct radv_device
*device
,
4159 struct radv_ds_buffer_info
*ds
,
4160 struct radv_image_view
*iview
)
4162 unsigned level
= iview
->base_mip
;
4163 unsigned format
, stencil_format
;
4164 uint64_t va
, s_offs
, z_offs
;
4165 bool stencil_only
= false;
4166 memset(ds
, 0, sizeof(*ds
));
4167 switch (iview
->image
->vk_format
) {
4168 case VK_FORMAT_D24_UNORM_S8_UINT
:
4169 case VK_FORMAT_X8_D24_UNORM_PACK32
:
4170 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
4171 ds
->offset_scale
= 2.0f
;
4173 case VK_FORMAT_D16_UNORM
:
4174 case VK_FORMAT_D16_UNORM_S8_UINT
:
4175 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
4176 ds
->offset_scale
= 4.0f
;
4178 case VK_FORMAT_D32_SFLOAT
:
4179 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
4180 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
4181 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
4182 ds
->offset_scale
= 1.0f
;
4184 case VK_FORMAT_S8_UINT
:
4185 stencil_only
= true;
4191 format
= radv_translate_dbformat(iview
->image
->vk_format
);
4192 stencil_format
= iview
->image
->surface
.has_stencil
?
4193 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
4195 uint32_t max_slice
= radv_surface_max_layer_count(iview
) - 1;
4196 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
4197 S_028008_SLICE_MAX(max_slice
);
4199 ds
->db_htile_data_base
= 0;
4200 ds
->db_htile_surface
= 0;
4202 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
4203 s_offs
= z_offs
= va
;
4205 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
4206 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
4207 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
4209 ds
->db_z_info
= S_028038_FORMAT(format
) |
4210 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
4211 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
4212 S_028038_MAXMIP(iview
->image
->info
.levels
- 1) |
4213 S_028038_ZRANGE_PRECISION(1);
4214 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
4215 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
4217 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
4218 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
4219 ds
->db_depth_view
|= S_028008_MIPID(level
);
4221 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
4222 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
4224 if (radv_htile_enabled(iview
->image
, level
)) {
4225 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
4227 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4228 unsigned max_zplanes
=
4229 radv_calc_decompress_on_z_planes(device
, iview
);
4231 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
) |
4232 S_028038_ITERATE_FLUSH(1);
4233 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
4236 if (!iview
->image
->surface
.has_stencil
)
4237 /* Use all of the htile_buffer for depth if there's no stencil. */
4238 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
4239 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4240 iview
->image
->htile_offset
;
4241 ds
->db_htile_data_base
= va
>> 8;
4242 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
4243 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
4244 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
4247 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
4250 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
4252 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
4253 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
4255 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!radv_image_is_tc_compat_htile(iview
->image
));
4256 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
4257 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
4259 if (iview
->image
->info
.samples
> 1)
4260 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
4262 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
4263 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
4264 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
4265 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
4266 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
4267 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
4268 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
4269 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
4272 tile_mode
= stencil_tile_mode
;
4274 ds
->db_depth_info
|=
4275 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
4276 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
4277 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
4278 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
4279 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
4280 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
4281 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
4282 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
4284 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
4285 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4286 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
4287 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
4289 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
4292 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
4293 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
4294 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
4296 if (radv_htile_enabled(iview
->image
, level
)) {
4297 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
4299 if (!iview
->image
->surface
.has_stencil
&&
4300 !radv_image_is_tc_compat_htile(iview
->image
))
4301 /* Use all of the htile_buffer for depth if there's no stencil. */
4302 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
4304 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
4305 iview
->image
->htile_offset
;
4306 ds
->db_htile_data_base
= va
>> 8;
4307 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
4309 if (radv_image_is_tc_compat_htile(iview
->image
)) {
4310 unsigned max_zplanes
=
4311 radv_calc_decompress_on_z_planes(device
, iview
);
4313 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
4314 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(max_zplanes
);
4319 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
4320 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
4323 VkResult
radv_CreateFramebuffer(
4325 const VkFramebufferCreateInfo
* pCreateInfo
,
4326 const VkAllocationCallbacks
* pAllocator
,
4327 VkFramebuffer
* pFramebuffer
)
4329 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4330 struct radv_framebuffer
*framebuffer
;
4332 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
4334 size_t size
= sizeof(*framebuffer
) +
4335 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
4336 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
4337 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4338 if (framebuffer
== NULL
)
4339 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4341 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
4342 framebuffer
->width
= pCreateInfo
->width
;
4343 framebuffer
->height
= pCreateInfo
->height
;
4344 framebuffer
->layers
= pCreateInfo
->layers
;
4345 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
4346 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
4347 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
4348 framebuffer
->attachments
[i
].attachment
= iview
;
4349 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
4350 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
4351 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
4352 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
4354 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
4355 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
4356 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_max_layer_count(iview
));
4359 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
4363 void radv_DestroyFramebuffer(
4366 const VkAllocationCallbacks
* pAllocator
)
4368 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4369 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
4373 vk_free2(&device
->alloc
, pAllocator
, fb
);
4376 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
4378 switch (address_mode
) {
4379 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
4380 return V_008F30_SQ_TEX_WRAP
;
4381 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
4382 return V_008F30_SQ_TEX_MIRROR
;
4383 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
4384 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
4385 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
4386 return V_008F30_SQ_TEX_CLAMP_BORDER
;
4387 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
4388 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
4390 unreachable("illegal tex wrap mode");
4396 radv_tex_compare(VkCompareOp op
)
4399 case VK_COMPARE_OP_NEVER
:
4400 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
4401 case VK_COMPARE_OP_LESS
:
4402 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
4403 case VK_COMPARE_OP_EQUAL
:
4404 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
4405 case VK_COMPARE_OP_LESS_OR_EQUAL
:
4406 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
4407 case VK_COMPARE_OP_GREATER
:
4408 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
4409 case VK_COMPARE_OP_NOT_EQUAL
:
4410 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
4411 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
4412 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
4413 case VK_COMPARE_OP_ALWAYS
:
4414 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
4416 unreachable("illegal compare mode");
4422 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
4425 case VK_FILTER_NEAREST
:
4426 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
4427 V_008F38_SQ_TEX_XY_FILTER_POINT
);
4428 case VK_FILTER_LINEAR
:
4429 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
4430 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
4431 case VK_FILTER_CUBIC_IMG
:
4433 fprintf(stderr
, "illegal texture filter");
4439 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
4442 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
4443 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
4444 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
4445 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
4447 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
4452 radv_tex_bordercolor(VkBorderColor bcolor
)
4455 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
4456 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
4457 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
4458 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
4459 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
4460 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
4461 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
4462 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
4463 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
4471 radv_tex_aniso_filter(unsigned filter
)
4485 radv_tex_filter_mode(VkSamplerReductionModeEXT mode
)
4488 case VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT
:
4489 return SQ_IMG_FILTER_MODE_BLEND
;
4490 case VK_SAMPLER_REDUCTION_MODE_MIN_EXT
:
4491 return SQ_IMG_FILTER_MODE_MIN
;
4492 case VK_SAMPLER_REDUCTION_MODE_MAX_EXT
:
4493 return SQ_IMG_FILTER_MODE_MAX
;
4501 radv_get_max_anisotropy(struct radv_device
*device
,
4502 const VkSamplerCreateInfo
*pCreateInfo
)
4504 if (device
->force_aniso
>= 0)
4505 return device
->force_aniso
;
4507 if (pCreateInfo
->anisotropyEnable
&&
4508 pCreateInfo
->maxAnisotropy
> 1.0f
)
4509 return (uint32_t)pCreateInfo
->maxAnisotropy
;
4515 radv_init_sampler(struct radv_device
*device
,
4516 struct radv_sampler
*sampler
,
4517 const VkSamplerCreateInfo
*pCreateInfo
)
4519 uint32_t max_aniso
= radv_get_max_anisotropy(device
, pCreateInfo
);
4520 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
4521 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
4522 unsigned filter_mode
= SQ_IMG_FILTER_MODE_BLEND
;
4524 const struct VkSamplerReductionModeCreateInfoEXT
*sampler_reduction
=
4525 vk_find_struct_const(pCreateInfo
->pNext
,
4526 SAMPLER_REDUCTION_MODE_CREATE_INFO_EXT
);
4527 if (sampler_reduction
)
4528 filter_mode
= radv_tex_filter_mode(sampler_reduction
->reductionMode
);
4530 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
4531 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
4532 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
4533 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
4534 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
4535 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
4536 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
4537 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
4538 S_008F30_DISABLE_CUBE_WRAP(0) |
4539 S_008F30_COMPAT_MODE(is_vi
) |
4540 S_008F30_FILTER_MODE(filter_mode
));
4541 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
4542 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
4543 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
4544 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
4545 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
4546 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
4547 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
4548 S_008F38_MIP_POINT_PRECLAMP(0) |
4549 S_008F38_DISABLE_LSB_CEIL(device
->physical_device
->rad_info
.chip_class
<= VI
) |
4550 S_008F38_FILTER_PREC_FIX(1) |
4551 S_008F38_ANISO_OVERRIDE(is_vi
));
4552 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
4553 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
4556 VkResult
radv_CreateSampler(
4558 const VkSamplerCreateInfo
* pCreateInfo
,
4559 const VkAllocationCallbacks
* pAllocator
,
4560 VkSampler
* pSampler
)
4562 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4563 struct radv_sampler
*sampler
;
4565 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
4567 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
4568 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
4570 return vk_error(device
->instance
, VK_ERROR_OUT_OF_HOST_MEMORY
);
4572 radv_init_sampler(device
, sampler
, pCreateInfo
);
4573 *pSampler
= radv_sampler_to_handle(sampler
);
4578 void radv_DestroySampler(
4581 const VkAllocationCallbacks
* pAllocator
)
4583 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4584 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
4588 vk_free2(&device
->alloc
, pAllocator
, sampler
);
4591 /* vk_icd.h does not declare this function, so we declare it here to
4592 * suppress Wmissing-prototypes.
4594 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4595 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
4597 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
4598 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
4600 /* For the full details on loader interface versioning, see
4601 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
4602 * What follows is a condensed summary, to help you navigate the large and
4603 * confusing official doc.
4605 * - Loader interface v0 is incompatible with later versions. We don't
4608 * - In loader interface v1:
4609 * - The first ICD entrypoint called by the loader is
4610 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
4612 * - The ICD must statically expose no other Vulkan symbol unless it is
4613 * linked with -Bsymbolic.
4614 * - Each dispatchable Vulkan handle created by the ICD must be
4615 * a pointer to a struct whose first member is VK_LOADER_DATA. The
4616 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
4617 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
4618 * vkDestroySurfaceKHR(). The ICD must be capable of working with
4619 * such loader-managed surfaces.
4621 * - Loader interface v2 differs from v1 in:
4622 * - The first ICD entrypoint called by the loader is
4623 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
4624 * statically expose this entrypoint.
4626 * - Loader interface v3 differs from v2 in:
4627 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
4628 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
4629 * because the loader no longer does so.
4631 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
4635 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
4636 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
4639 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4640 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
4642 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
4644 /* At the moment, we support only the below handle types. */
4645 assert(pGetFdInfo
->handleType
==
4646 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4647 pGetFdInfo
->handleType
==
4648 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
);
4650 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
4652 return vk_error(device
->instance
, VK_ERROR_OUT_OF_DEVICE_MEMORY
);
4656 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
4657 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
4659 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
4661 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4663 switch (handleType
) {
4664 case VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT
:
4665 pMemoryFdProperties
->memoryTypeBits
= (1 << RADV_MEM_TYPE_COUNT
) - 1;
4669 /* The valid usage section for this function says:
4671 * "handleType must not be one of the handle types defined as
4674 * So opaque handle types fall into the default "unsupported" case.
4676 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4680 static VkResult
radv_import_opaque_fd(struct radv_device
*device
,
4684 uint32_t syncobj_handle
= 0;
4685 int ret
= device
->ws
->import_syncobj(device
->ws
, fd
, &syncobj_handle
);
4687 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4690 device
->ws
->destroy_syncobj(device
->ws
, *syncobj
);
4692 *syncobj
= syncobj_handle
;
4698 static VkResult
radv_import_sync_fd(struct radv_device
*device
,
4702 /* If we create a syncobj we do it locally so that if we have an error, we don't
4703 * leave a syncobj in an undetermined state in the fence. */
4704 uint32_t syncobj_handle
= *syncobj
;
4705 if (!syncobj_handle
) {
4706 int ret
= device
->ws
->create_syncobj(device
->ws
, &syncobj_handle
);
4708 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4713 device
->ws
->signal_syncobj(device
->ws
, syncobj_handle
);
4715 int ret
= device
->ws
->import_syncobj_from_sync_file(device
->ws
, syncobj_handle
, fd
);
4717 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4720 *syncobj
= syncobj_handle
;
4727 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
4728 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
4730 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4731 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
4732 uint32_t *syncobj_dst
= NULL
;
4734 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
4735 syncobj_dst
= &sem
->temp_syncobj
;
4737 syncobj_dst
= &sem
->syncobj
;
4740 switch(pImportSemaphoreFdInfo
->handleType
) {
4741 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4742 return radv_import_opaque_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4743 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4744 return radv_import_sync_fd(device
, pImportSemaphoreFdInfo
->fd
, syncobj_dst
);
4746 unreachable("Unhandled semaphore handle type");
4750 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
4751 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
4754 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4755 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
4757 uint32_t syncobj_handle
;
4759 if (sem
->temp_syncobj
)
4760 syncobj_handle
= sem
->temp_syncobj
;
4762 syncobj_handle
= sem
->syncobj
;
4764 switch(pGetFdInfo
->handleType
) {
4765 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4766 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4768 case VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4769 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4771 if (sem
->temp_syncobj
) {
4772 close (sem
->temp_syncobj
);
4773 sem
->temp_syncobj
= 0;
4775 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4780 unreachable("Unhandled semaphore handle type");
4784 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4788 void radv_GetPhysicalDeviceExternalSemaphoreProperties(
4789 VkPhysicalDevice physicalDevice
,
4790 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
4791 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
4793 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4795 /* Require has_syncobj_wait_for_submit for the syncobj signal ioctl introduced at virtually the same time */
4796 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4797 (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4798 pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4799 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4800 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4801 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4802 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4803 } else if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
4804 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4805 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
4806 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
4807 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4809 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
4810 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
4811 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;
4815 VkResult
radv_ImportFenceFdKHR(VkDevice _device
,
4816 const VkImportFenceFdInfoKHR
*pImportFenceFdInfo
)
4818 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4819 RADV_FROM_HANDLE(radv_fence
, fence
, pImportFenceFdInfo
->fence
);
4820 uint32_t *syncobj_dst
= NULL
;
4823 if (pImportFenceFdInfo
->flags
& VK_FENCE_IMPORT_TEMPORARY_BIT_KHR
) {
4824 syncobj_dst
= &fence
->temp_syncobj
;
4826 syncobj_dst
= &fence
->syncobj
;
4829 switch(pImportFenceFdInfo
->handleType
) {
4830 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4831 return radv_import_opaque_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4832 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4833 return radv_import_sync_fd(device
, pImportFenceFdInfo
->fd
, syncobj_dst
);
4835 unreachable("Unhandled fence handle type");
4839 VkResult
radv_GetFenceFdKHR(VkDevice _device
,
4840 const VkFenceGetFdInfoKHR
*pGetFdInfo
,
4843 RADV_FROM_HANDLE(radv_device
, device
, _device
);
4844 RADV_FROM_HANDLE(radv_fence
, fence
, pGetFdInfo
->fence
);
4846 uint32_t syncobj_handle
;
4848 if (fence
->temp_syncobj
)
4849 syncobj_handle
= fence
->temp_syncobj
;
4851 syncobj_handle
= fence
->syncobj
;
4853 switch(pGetFdInfo
->handleType
) {
4854 case VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
:
4855 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
4857 case VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
:
4858 ret
= device
->ws
->export_syncobj_to_sync_file(device
->ws
, syncobj_handle
, pFd
);
4860 if (fence
->temp_syncobj
) {
4861 close (fence
->temp_syncobj
);
4862 fence
->temp_syncobj
= 0;
4864 device
->ws
->reset_syncobj(device
->ws
, syncobj_handle
);
4869 unreachable("Unhandled fence handle type");
4873 return vk_error(device
->instance
, VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
4877 void radv_GetPhysicalDeviceExternalFenceProperties(
4878 VkPhysicalDevice physicalDevice
,
4879 const VkPhysicalDeviceExternalFenceInfoKHR
* pExternalFenceInfo
,
4880 VkExternalFencePropertiesKHR
* pExternalFenceProperties
)
4882 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
4884 if (pdevice
->rad_info
.has_syncobj_wait_for_submit
&&
4885 (pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
||
4886 pExternalFenceInfo
->handleType
== VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
)) {
4887 pExternalFenceProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4888 pExternalFenceProperties
->compatibleHandleTypes
= VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
| VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT_KHR
;
4889 pExternalFenceProperties
->externalFenceFeatures
= VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT_KHR
|
4890 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
4892 pExternalFenceProperties
->exportFromImportedHandleTypes
= 0;
4893 pExternalFenceProperties
->compatibleHandleTypes
= 0;
4894 pExternalFenceProperties
->externalFenceFeatures
= 0;
4899 radv_CreateDebugReportCallbackEXT(VkInstance _instance
,
4900 const VkDebugReportCallbackCreateInfoEXT
* pCreateInfo
,
4901 const VkAllocationCallbacks
* pAllocator
,
4902 VkDebugReportCallbackEXT
* pCallback
)
4904 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4905 return vk_create_debug_report_callback(&instance
->debug_report_callbacks
,
4906 pCreateInfo
, pAllocator
, &instance
->alloc
,
4911 radv_DestroyDebugReportCallbackEXT(VkInstance _instance
,
4912 VkDebugReportCallbackEXT _callback
,
4913 const VkAllocationCallbacks
* pAllocator
)
4915 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4916 vk_destroy_debug_report_callback(&instance
->debug_report_callbacks
,
4917 _callback
, pAllocator
, &instance
->alloc
);
4921 radv_DebugReportMessageEXT(VkInstance _instance
,
4922 VkDebugReportFlagsEXT flags
,
4923 VkDebugReportObjectTypeEXT objectType
,
4926 int32_t messageCode
,
4927 const char* pLayerPrefix
,
4928 const char* pMessage
)
4930 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
4931 vk_debug_report(&instance
->debug_report_callbacks
, flags
, objectType
,
4932 object
, location
, messageCode
, pLayerPrefix
, pMessage
);
4936 radv_GetDeviceGroupPeerMemoryFeatures(
4939 uint32_t localDeviceIndex
,
4940 uint32_t remoteDeviceIndex
,
4941 VkPeerMemoryFeatureFlags
* pPeerMemoryFeatures
)
4943 assert(localDeviceIndex
== remoteDeviceIndex
);
4945 *pPeerMemoryFeatures
= VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT
|
4946 VK_PEER_MEMORY_FEATURE_COPY_DST_BIT
|
4947 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT
|
4948 VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT
;