loader: handle picking zink for nouveau for certain GPUs.

This adds NOUVEAU_USE_ZINK env var, but also has commented out
code to pick it for turing+ if mesa is built with nvk and zink.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27628>
This commit is contained in:
Dave Airlie 2024-02-20 13:11:28 +10:00
parent caf99133ec
commit 6a688e65a0
3 changed files with 45 additions and 5 deletions

View file

@ -319,6 +319,11 @@ with_any_intel = [
].contains(true)
with_any_nouveau = with_gallium_nouveau or with_nouveau_vk
# needed in the loader
if with_nouveau_vk
pre_args += '-DHAVE_NVK'
endif
if with_swrast_vk and not with_gallium_softpipe
error('swrast vulkan requires gallium swrast')
endif

View file

@ -54,6 +54,8 @@
#include "util/u_debug.h"
#include "git_sha1.h"
#include "drm-uapi/nouveau_drm.h"
#define MAX_DRM_DEVICES 64
#ifdef USE_DRICONF
@ -123,7 +125,7 @@ loader_get_kernel_driver_name(int fd)
}
bool
iris_predicate(int fd)
iris_predicate(int fd, const char *driver)
{
char *kernel_driver = loader_get_kernel_driver_name(fd);
bool ret = kernel_driver && (strcmp(kernel_driver, "i915") == 0 ||
@ -133,6 +135,37 @@ iris_predicate(int fd)
return ret;
}
/* choose zink or nouveau GL */
bool
nouveau_zink_predicate(int fd, const char *driver)
{
#if !defined(HAVE_NVK) || !defined(HAVE_ZINK)
if (!strcmp(driver, "zink"))
return false;
return true;
#else
bool prefer_zink = false;
/* enable this once zink is up to speed.
* struct drm_nouveau_getparam r = { .param = NOUVEAU_GETPARAM_CHIPSET_ID };
* int ret = drmCommandWriteRead(fd, DRM_NOUVEAU_GETPARAM, &r, sizeof(r));
* if (ret == 0 && (r.value & ~0xf) >= 0x160)
* prefer_zink = true;
*/
prefer_zink = debug_get_bool_option("NOUVEAU_USE_ZINK", prefer_zink);
if (prefer_zink && !strcmp(driver, "zink"))
return true;
if (!prefer_zink && !strcmp(driver, "nouveau"))
return true;
return false;
#endif
}
/**
* Goes through all the platform devices whose driver is on the given list and
* try to open their render node. It returns the fd of the first device that
@ -643,7 +676,7 @@ loader_get_pci_driver(int fd)
if (vendor_id != driver_map[i].vendor_id)
continue;
if (driver_map[i].predicate && !driver_map[i].predicate(fd))
if (driver_map[i].predicate && !driver_map[i].predicate(fd, driver_map[i].driver))
continue;
if (driver_map[i].num_chips_ids == -1) {

View file

@ -44,14 +44,15 @@ static const int vmwgfx_chip_ids[] = {
#undef CHIPSET
};
bool iris_predicate(int fd);
bool iris_predicate(int fd, const char *driver);
bool nouveau_zink_predicate(int fd, const char *driver);
static const struct {
int vendor_id;
const char *driver;
const int *chip_ids;
int num_chips_ids;
bool (*predicate)(int fd);
bool (*predicate)(int fd, const char *driver);
} driver_map[] = {
{ 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) },
{ 0x8086, "crocus", crocus_chip_ids, ARRAY_SIZE(crocus_chip_ids) },
@ -59,7 +60,8 @@ static const struct {
{ 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) },
{ 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) },
{ 0x1002, "radeonsi", NULL, -1 },
{ 0x10de, "nouveau", NULL, -1, },
{ 0x10de, "nouveau", NULL, -1, nouveau_zink_predicate },
{ 0x10de, "zink", NULL, -1, nouveau_zink_predicate },
{ 0x1af4, "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) },
{ 0x15ad, "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) },
};