amd, radv: create null device without winsys

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37525>
This commit is contained in:
Daniel Schürmann
2025-09-22 21:09:22 +02:00
committed by Marge Bot
parent 04ebbc3c41
commit 7d6de8b17e
4 changed files with 241 additions and 44 deletions
+117
View File
@@ -0,0 +1,117 @@
/*
* Copyright © 2020 Valve Corporation
*
* SPDX-License-Identifier: MIT
*/
#include "ac_null_device.h"
#include "ac_gpu_info.h"
#include "util/u_string.h"
bool
ac_null_device_create(struct radeon_info *gpu_info, const char *family)
{
unsigned i;
gpu_info->gfx_level = CLASS_UNKNOWN;
gpu_info->family = CHIP_UNKNOWN;
for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
if (!strcasecmp(family, ac_get_family_name(i))) {
/* Override family and gfx_level. */
gpu_info->family = i;
gpu_info->name = ac_get_family_name(i);
if (gpu_info->family >= CHIP_GFX1200)
gpu_info->gfx_level = GFX12;
else if (gpu_info->family >= CHIP_NAVI31)
gpu_info->gfx_level = GFX11;
else if (i >= CHIP_NAVI21)
gpu_info->gfx_level = GFX10_3;
else if (i >= CHIP_NAVI10)
gpu_info->gfx_level = GFX10;
else if (i >= CHIP_VEGA10)
gpu_info->gfx_level = GFX9;
else if (i >= CHIP_TONGA)
gpu_info->gfx_level = GFX8;
else if (i >= CHIP_BONAIRE)
gpu_info->gfx_level = GFX7;
else
gpu_info->gfx_level = GFX6;
}
}
if (gpu_info->family == CHIP_UNKNOWN)
return false;
gpu_info->pci_id = pci_ids[gpu_info->family].pci_id;
gpu_info->max_se = pci_ids[gpu_info->family].has_dedicated_vram ? 4 : 1;
gpu_info->num_se = gpu_info->max_se;
if (gpu_info->gfx_level >= GFX10_3)
gpu_info->max_waves_per_simd = 16;
else if (gpu_info->gfx_level >= GFX10)
gpu_info->max_waves_per_simd = 20;
else if (gpu_info->family >= CHIP_POLARIS10 && gpu_info->family <= CHIP_VEGAM)
gpu_info->max_waves_per_simd = 8;
else
gpu_info->max_waves_per_simd = 10;
if (gpu_info->gfx_level >= GFX10)
gpu_info->num_physical_sgprs_per_simd = 128 * gpu_info->max_waves_per_simd;
else if (gpu_info->gfx_level >= GFX8)
gpu_info->num_physical_sgprs_per_simd = 800;
else
gpu_info->num_physical_sgprs_per_simd = 512;
gpu_info->has_timeline_syncobj = true;
gpu_info->has_vm_always_valid = true;
gpu_info->has_3d_cube_border_color_mipmap = true;
gpu_info->has_image_opcodes = true;
gpu_info->has_attr_ring = gpu_info->gfx_level >= GFX11;
gpu_info->has_attr_ring_wait_bug = gpu_info->gfx_level == GFX11 || gpu_info->gfx_level == GFX11_5;
gpu_info->has_ngg_fully_culled_bug = gpu_info->gfx_level == GFX10;
gpu_info->has_ngg_passthru_no_msg = gpu_info->family >= CHIP_NAVI23;
if (gpu_info->family == CHIP_NAVI31 || gpu_info->family == CHIP_NAVI32 || gpu_info->gfx_level >= GFX12)
gpu_info->num_physical_wave64_vgprs_per_simd = 768;
else if (gpu_info->gfx_level >= GFX10)
gpu_info->num_physical_wave64_vgprs_per_simd = 512;
else
gpu_info->num_physical_wave64_vgprs_per_simd = 256;
gpu_info->num_simd_per_compute_unit = gpu_info->gfx_level >= GFX10 ? 2 : 4;
gpu_info->lds_size_per_workgroup = gpu_info->gfx_level >= GFX7 ? 64 * 1024 : 32 * 1024;
gpu_info->max_render_backends = pci_ids[gpu_info->family].num_render_backends;
gpu_info->has_dedicated_vram = pci_ids[gpu_info->family].has_dedicated_vram;
gpu_info->has_packed_math_16bit = gpu_info->gfx_level >= GFX9;
gpu_info->has_image_load_dcc_bug = gpu_info->family == CHIP_NAVI23 || gpu_info->family == CHIP_VANGOGH;
gpu_info->has_distributed_tess =
gpu_info->gfx_level >= GFX10 || (gpu_info->gfx_level >= GFX8 && gpu_info->max_se >= 2);
gpu_info->has_accelerated_dot_product =
gpu_info->family == CHIP_VEGA20 ||
(gpu_info->family >= CHIP_MI100 && gpu_info->family != CHIP_NAVI10 && gpu_info->family != CHIP_GFX1013);
gpu_info->has_image_bvh_intersect_ray = gpu_info->gfx_level >= GFX10_3 || gpu_info->family == CHIP_GFX1013;
gpu_info->address32_hi = gpu_info->gfx_level >= GFX9 ? 0xffff8000u : 0x0;
gpu_info->has_rbplus = gpu_info->family == CHIP_STONEY || gpu_info->gfx_level >= GFX9;
gpu_info->rbplus_allowed =
gpu_info->has_rbplus &&
(gpu_info->family == CHIP_STONEY || gpu_info->family == CHIP_VEGA12 || gpu_info->family == CHIP_RAVEN ||
gpu_info->family == CHIP_RAVEN2 || gpu_info->family == CHIP_RENOIR || gpu_info->gfx_level >= GFX10_3);
gpu_info->has_gang_submit = true;
gpu_info->mesh_fast_launch_2 = gpu_info->gfx_level >= GFX11;
gpu_info->hs_offchip_workgroup_dw_size = gpu_info->family == CHIP_HAWAII ? 4096 : 8192;
gpu_info->has_ls_vgpr_init_bug = gpu_info->family == CHIP_VEGA10 || gpu_info->family == CHIP_RAVEN;
gpu_info->has_graphics = true;
gpu_info->ip[AMD_IP_GFX].num_queues = 1;
gpu_info->gart_page_size = 4096;
gpu_info->family_overridden = true;
return true;
}
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright © 2025 Valve Corporation
*
* SPDX-License-Identifier: MIT
*/
#ifndef RADV_NULL_DEVICE_H
#define RADV_NULL_DEVICE_H
#include <stdbool.h>
#include <stdint.h>
#include "amd_family.h"
/* Hardcode some GPU info that are needed for the driver or for some tools. */
static const struct {
uint32_t pci_id;
uint32_t num_render_backends;
bool has_dedicated_vram;
} pci_ids[] = {
/* clang-format off */
[CHIP_TAHITI] = {0x6780, 8, true},
[CHIP_PITCAIRN] = {0x6800, 8, true},
[CHIP_VERDE] = {0x6820, 4, true},
[CHIP_OLAND] = {0x6060, 2, true},
[CHIP_HAINAN] = {0x6660, 2, true},
[CHIP_BONAIRE] = {0x6640, 4, true},
[CHIP_KAVERI] = {0x1304, 2, false},
[CHIP_KABINI] = {0x9830, 2, false},
[CHIP_HAWAII] = {0x67A0, 16, true},
[CHIP_TONGA] = {0x6920, 8, true},
[CHIP_ICELAND] = {0x6900, 2, true},
[CHIP_CARRIZO] = {0x9870, 2, false},
[CHIP_FIJI] = {0x7300, 16, true},
[CHIP_STONEY] = {0x98E4, 2, false},
[CHIP_POLARIS10] = {0x67C0, 8, true},
[CHIP_POLARIS11] = {0x67E0, 4, true},
[CHIP_POLARIS12] = {0x6980, 4, true},
[CHIP_VEGAM] = {0x694C, 4, true},
[CHIP_VEGA10] = {0x6860, 16, true},
[CHIP_VEGA12] = {0x69A0, 8, true},
[CHIP_VEGA20] = {0x66A0, 16, true},
[CHIP_RAVEN] = {0x15DD, 2, false},
[CHIP_RENOIR] = {0x1636, 2, false},
[CHIP_MI100] = {0x738C, 2, true},
[CHIP_NAVI10] = {0x7310, 16, true},
[CHIP_NAVI12] = {0x7360, 8, true},
[CHIP_NAVI14] = {0x7340, 8, true},
[CHIP_NAVI21] = {0x73A0, 16, true},
[CHIP_VANGOGH] = {0x163F, 8, false},
[CHIP_NAVI22] = {0x73C0, 8, true},
[CHIP_NAVI23] = {0x73E0, 8, true},
[CHIP_NAVI31] = {0x744C, 24, true},
[CHIP_GFX1201] = {0x7550, 16, true},
/* clang-format on */
};
bool ac_null_device_create(struct radeon_info *gpu_info, const char *family);
#endif /* RADV_NULL_DEVICE_H */
+2
View File
@@ -76,6 +76,8 @@ amd_common_files = files(
'ac_formats.c',
'ac_formats.h',
'ac_linux_drm.h',
'ac_null_device.c',
'ac_null_device.h',
'ac_shadowed_regs.c',
'ac_shadowed_regs.h',
'ac_spm.c',
+63 -44
View File
@@ -9,6 +9,9 @@
*/
#include <fcntl.h>
#include "util/os_misc.h"
#include "vulkan/vulkan_core.h"
#include "vk_sync_dummy.h"
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
@@ -17,6 +20,7 @@
#include "vk_log.h"
#include "vk_shader_module.h"
#include "common/ac_null_device.h"
#include "util/disk_cache.h"
#include "util/hex.h"
#include "util/u_debug.h"
@@ -37,7 +41,6 @@ typedef void *drmDevicePtr;
#include "util/os_drm.h"
#include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
#endif
#include "winsys/null/radv_null_winsys_public.h"
#include "git_sha1.h"
#if AMD_LLVM_AVAILABLE
@@ -2206,6 +2209,23 @@ radv_is_gpu_supported(const struct radeon_info *info)
return true;
}
static const struct vk_sync_type *const dummy_types[2] = {
&vk_sync_dummy_type,
NULL,
};
static VkResult
radv_create_null_device(struct radv_instance *instance, struct radv_physical_device *pdev)
{
const char *family = os_get_option("RADV_FORCE_FAMILY");
if (!ac_null_device_create(&pdev->info, family))
return vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED, "Unknown family: %s\n", family);
pdev->vk.supported_sync_types = dummy_types;
return VK_SUCCESS;
}
static VkResult
radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm_device,
struct radv_physical_device **pdev_out)
@@ -2280,67 +2300,64 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm
}
#ifdef _WIN32
pdev->ws = radv_null_winsys_create();
if (!pdev->ws)
result = VK_ERROR_OUT_OF_HOST_MEMORY;
result = radv_create_null_device(instance, pdev);
if (result != VK_SUCCESS)
goto fail_base;
#else
if (drm_device) {
bool reserve_vmid = instance->vk.trace_mode & RADV_TRACE_MODE_RGP;
result = radv_amdgpu_winsys_create(fd, instance->debug_flags, instance->perftest_flags, reserve_vmid, is_virtio,
&pdev->ws);
} else {
pdev->ws = radv_null_winsys_create();
if (!pdev->ws)
result = VK_ERROR_OUT_OF_HOST_MEMORY;
}
#endif
if (result != VK_SUCCESS) {
result = vk_errorf(instance, result, "failed to initialize winsys");
goto fail_base;
}
if (result != VK_SUCCESS) {
result = vk_errorf(instance, result, "failed to initialize winsys");
goto fail_base;
}
pdev->vk.supported_sync_types = pdev->ws->get_sync_types(pdev->ws);
pdev->vk.supported_sync_types = pdev->ws->get_sync_types(pdev->ws);
pdev->ws->query_info(pdev->ws, &pdev->info);
#ifndef _WIN32
if (drm_device && instance->vk.enabled_extensions.KHR_display) {
master_fd = open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
if (master_fd >= 0) {
uint32_t accel_working = 0;
struct drm_amdgpu_info request = {.return_pointer = (uintptr_t)&accel_working,
.return_size = sizeof(accel_working),
.query = AMDGPU_INFO_ACCEL_WORKING};
if (instance->vk.enabled_extensions.KHR_display) {
master_fd = open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
if (master_fd >= 0) {
uint32_t accel_working = 0;
struct drm_amdgpu_info request = {.return_pointer = (uintptr_t)&accel_working,
.return_size = sizeof(accel_working),
.query = AMDGPU_INFO_ACCEL_WORKING};
if (drm_ioctl_write(master_fd, DRM_AMDGPU_INFO, &request, sizeof(struct drm_amdgpu_info)) < 0 ||
!accel_working) {
close(master_fd);
master_fd = -1;
if (drm_ioctl_write(master_fd, DRM_AMDGPU_INFO, &request, sizeof(struct drm_amdgpu_info)) < 0 ||
!accel_working) {
close(master_fd);
master_fd = -1;
}
}
}
}
#endif
pdev->master_fd = master_fd;
pdev->local_fd = fd;
pdev->ws->query_info(pdev->ws, &pdev->info);
pdev->info.family_overridden = drm_device == NULL;
/* Allow all devices on a virtual winsys, otherwise do a basic support check. */
if (!radv_is_gpu_supported(&pdev->info)) {
if (instance->debug_flags & RADV_DEBUG_STARTUP)
fprintf(stderr, "radv: info: device '%s' is not supported by RADV.\n", pdev->info.name);
result = VK_ERROR_INCOMPATIBLE_DRIVER;
goto fail_wsi;
}
/* Allow all devices on a virtual winsys, otherwise do a basic support check. */
if (!radv_is_gpu_supported(&pdev->info) && drm_device) {
if (instance->debug_flags & RADV_DEBUG_STARTUP)
fprintf(stderr, "radv: info: device '%s' is not supported by RADV.\n", pdev->info.name);
result = VK_ERROR_INCOMPATIBLE_DRIVER;
goto fail_wsi;
}
if (drm_device) {
pdev->addrlib = ac_addrlib_create(&pdev->info, &pdev->info.max_alignment);
if (!pdev->addrlib) {
result = VK_ERROR_INITIALIZATION_FAILED;
goto fail_wsi;
}
} else {
/* Create NULL device if no DRM device was provided. */
result = radv_create_null_device(instance, pdev);
if (result != VK_SUCCESS)
goto fail_base;
}
#endif
pdev->master_fd = master_fd;
pdev->local_fd = fd;
pdev->use_llvm = instance->debug_flags & RADV_DEBUG_LLVM;
#if !AMD_LLVM_AVAILABLE
@@ -2542,7 +2559,8 @@ fail_perfcounters:
fail_wsi:
if (pdev->addrlib)
ac_addrlib_destroy(pdev->addrlib);
pdev->ws->destroy(pdev->ws);
if (pdev->ws)
pdev->ws->destroy(pdev->ws);
fail_base:
vk_physical_device_finish(&pdev->vk);
fail_alloc:
@@ -2605,7 +2623,8 @@ radv_physical_device_destroy(struct vk_physical_device *vk_device)
ac_destroy_perfcounters(&pdev->ac_perfcounters);
if (pdev->addrlib)
ac_addrlib_destroy(pdev->addrlib);
pdev->ws->destroy(pdev->ws);
if (pdev->ws)
pdev->ws->destroy(pdev->ws);
disk_cache_destroy(pdev->vk.disk_cache);
disk_cache_destroy(pdev->disk_cache_meta);
if (pdev->local_fd != -1)