gfxstream: Modify deviceName, driverVersion, driverName, driverInfo ...
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

... to report that Vulkan is running through a gfxstream driver to the
host driver. This matches what Venus does.

TODOs added for driverID, need spec'd driverID for gfxstream in Mesa.

Example:

Device Properties and Extensions:
=================================
GPU0:
VkPhysicalDeviceProperties:
---------------------------
        apiVersion        = 1.3.0 (4206592)
        driverVersion     = 525.147.5.0 (2204418368)
        vendorID          = 0x10de
        deviceID          = 0x1fb9
        deviceType        = PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
        deviceName        = Virtio-GPU GFXStream (Quadro T1000)
        pipelineCacheUUID = 5e84b6ed-4e70-35e3-a855-d75f23b64fd5

VkPhysicalDeviceDriverProperties:
---------------------------------
        driverID        = DRIVER_ID_NVIDIA_PROPRIETARY
        driverName      = gfxstream
        driverInfo      = Mesa 25.1.0
        conformanceVersion:
                major    = 1
                minor    = 3
                subminor = 3
                patch    = 1

Reviewed-by: Gurchetan Singh <gurchetansingh@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36290>
This commit is contained in:
Aaron Ruby 2025-07-22 15:10:27 -04:00 committed by Marge Bot
parent 22c624d75b
commit 525513fd23
4 changed files with 81 additions and 55 deletions

View file

@ -74,7 +74,6 @@ ENCODER_CUSTOM_RESOURCE_POSTPROCESS = [
"vkMapMemoryIntoAddressSpaceGOOGLE",
"vkGetPhysicalDeviceFeatures2",
"vkGetPhysicalDeviceFeatures2KHR",
"vkGetPhysicalDeviceProperties",
"vkGetPhysicalDeviceProperties2",
"vkGetPhysicalDeviceProperties2KHR",
"vkCreateDescriptorUpdateTemplate",

View file

@ -144,6 +144,7 @@ NON_AUTOGEN_ENTRYPOINTS = [
# Use vk_common_* entrypoints; usually just dispatches to the "vk*2()" API variant
"vkGetDeviceQueue",
"vkGetPhysicalDeviceProperties",
]
# Handles that need to be translated to/from their corresponding gfxstream object types

View file

@ -11,14 +11,15 @@
#include "Resources.h"
#include "VkEncoder.h"
#include "gfxstream_vk_private.h"
#include "git_sha1.h"
#include "goldfish_address_space.h"
#include "goldfish_vk_private_defs.h"
#include "util/anon_file.h"
#include "util/detect_os.h"
#include "util/log.h"
#include "util/macros.h"
#include "vulkan/vulkan_core.h"
#include "util/detect_os.h"
#include "virtio/virtio-gpu/virgl_hw.h"
#include "vulkan/vulkan_core.h"
#ifdef VK_USE_PLATFORM_ANDROID_KHR
#include "vk_format_info.h"
@ -2118,21 +2119,6 @@ VkResult ResourceTracker::on_vkEnumeratePhysicalDevices(void* context, VkResult,
}
}
void ResourceTracker::on_vkGetPhysicalDeviceProperties(void*, VkPhysicalDevice,
VkPhysicalDeviceProperties* pProperties) {
#ifdef LINUX_GUEST_BUILD
if (pProperties) {
if (VK_PHYSICAL_DEVICE_TYPE_CPU == pProperties->deviceType) {
/* For Linux guest: Even if host driver reports DEVICE_TYPE_CPU,
* override this to VIRTUAL_GPU, otherwise Linux DRM interfaces
* will take unexpected code paths to deal with "software" driver
*/
pProperties->deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
}
}
#endif
}
void ResourceTracker::on_vkGetPhysicalDeviceFeatures2(void*, VkPhysicalDevice,
VkPhysicalDeviceFeatures2* pFeatures) {
if (pFeatures) {
@ -2153,44 +2139,86 @@ void ResourceTracker::on_vkGetPhysicalDeviceFeatures2KHR(void* context,
void ResourceTracker::on_vkGetPhysicalDeviceProperties2(void* context,
VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2* pProperties) {
if (pProperties) {
on_vkGetPhysicalDeviceProperties(context, physicalDevice, &pProperties->properties);
VirtGpuDevice* instance = VirtGpuDevice::getInstance();
VkPhysicalDeviceDrmPropertiesEXT* drmProps =
vk_find_struct(pProperties, PHYSICAL_DEVICE_DRM_PROPERTIES_EXT);
#ifdef LINUX_GUEST_BUILD
if (VK_PHYSICAL_DEVICE_TYPE_CPU == pProperties->properties.deviceType) {
/* For Linux guest: Even if host driver reports DEVICE_TYPE_CPU,
* override this to VIRTUAL_GPU, otherwise Linux DRM interfaces
* will take unexpected code paths to deal with "software" driver
*/
pProperties->properties.deviceType = VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU;
}
#endif
if (instance && drmProps) {
VirtGpuDrmInfo drmInfo;
if (instance->getDrmInfo(&drmInfo)) {
drmProps->hasPrimary = drmInfo.hasPrimary;
drmProps->hasRender = drmInfo.hasRender;
drmProps->primaryMajor = drmInfo.primaryMajor;
drmProps->primaryMinor = drmInfo.primaryMinor;
drmProps->renderMajor = drmInfo.renderMajor;
drmProps->renderMinor = drmInfo.renderMinor;
} else {
mesa_logd(
"%s: encountered VkPhysicalDeviceDrmPropertiesEXT in pProperties::pNext chain, "
"but failed to query DrmInfo from the VirtGpuDevice",
__func__);
}
/* Get driverVersion from Mesa version, not host's driverVersion */
pProperties->properties.driverVersion = vk_get_driver_version();
// TODO: VkPhysicalDeviceVulkan12Properties::driverID and
// VkPhysicalDeviceDriverProperties::driverID for gfxstream in Mesa
VkPhysicalDeviceVulkan12Properties* vulkan12Props =
vk_find_struct(pProperties, PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES);
if (vulkan12Props) {
// TODO: driverId for gfxstream_vk? update conformanceVersion?
snprintf(vulkan12Props->driverName, sizeof(vulkan12Props->driverName), "gfxstream");
snprintf(vulkan12Props->driverInfo, sizeof(vulkan12Props->driverInfo),
"Mesa " PACKAGE_VERSION MESA_GIT_SHA1);
}
VkPhysicalDeviceDriverProperties* driverProps =
vk_find_struct(pProperties, PHYSICAL_DEVICE_DRIVER_PROPERTIES);
if (driverProps) {
// TODO: driverId for gfxstream_vk? update conformanceVersion?
snprintf(driverProps->driverName, sizeof(driverProps->driverName), "gfxstream");
snprintf(driverProps->driverInfo, sizeof(driverProps->driverInfo),
"Mesa " PACKAGE_VERSION MESA_GIT_SHA1);
}
VirtGpuDevice* instance = VirtGpuDevice::getInstance();
if (!instance) {
mesa_loge("%s(): Could not get an instance of the VirtGpuDevice", __func__);
return;
}
char device_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
int device_name_len = snprintf(device_name, sizeof(device_name), "Virtio-GPU GFXStream (%s)",
pProperties->properties.deviceName);
if (device_name_len >= (int)VK_MAX_PHYSICAL_DEVICE_NAME_SIZE) {
memcpy(device_name + VK_MAX_PHYSICAL_DEVICE_NAME_SIZE - 5, "...)", 4);
device_name_len = VK_MAX_PHYSICAL_DEVICE_NAME_SIZE - 1;
}
memcpy(pProperties->properties.deviceName, device_name, device_name_len + 1);
VkPhysicalDeviceDrmPropertiesEXT* drmProps =
vk_find_struct(pProperties, PHYSICAL_DEVICE_DRM_PROPERTIES_EXT);
if (drmProps) {
VirtGpuDrmInfo drmInfo;
if (instance->getDrmInfo(&drmInfo)) {
drmProps->hasPrimary = drmInfo.hasPrimary;
drmProps->hasRender = drmInfo.hasRender;
drmProps->primaryMajor = drmInfo.primaryMajor;
drmProps->primaryMinor = drmInfo.primaryMinor;
drmProps->renderMajor = drmInfo.renderMajor;
drmProps->renderMinor = drmInfo.renderMinor;
} else {
mesa_logd(
"%s: encountered VkPhysicalDeviceDrmPropertiesEXT in pProperties::pNext chain, "
"but failed to query DrmInfo from the VirtGpuDevice",
__func__);
}
}
VkPhysicalDevicePCIBusInfoPropertiesEXT* pciBusInfoProps =
vk_find_struct(pProperties, PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT);
if (instance && pciBusInfoProps) {
VirtGpuPciBusInfo pciBusInfo;
if (instance->getPciBusInfo(&pciBusInfo)) {
pciBusInfoProps->pciDomain = pciBusInfo.domain;
pciBusInfoProps->pciBus = pciBusInfo.bus;
pciBusInfoProps->pciDevice = pciBusInfo.device;
pciBusInfoProps->pciFunction = pciBusInfo.function;
} else {
mesa_logd(
"%s: encountered VkPhysicalDevicePCIBusInfoPropertiesEXT in pProperties::pNext "
"chain, but failed to query PciBusInfo from the VirtGpuDevice",
__func__);
}
VkPhysicalDevicePCIBusInfoPropertiesEXT* pciBusInfoProps =
vk_find_struct(pProperties, PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT);
if (pciBusInfoProps) {
VirtGpuPciBusInfo pciBusInfo;
if (instance->getPciBusInfo(&pciBusInfo)) {
pciBusInfoProps->pciDomain = pciBusInfo.domain;
pciBusInfoProps->pciBus = pciBusInfo.bus;
pciBusInfoProps->pciDevice = pciBusInfo.device;
pciBusInfoProps->pciFunction = pciBusInfo.function;
} else {
mesa_logd(
"%s: encountered VkPhysicalDevicePCIBusInfoPropertiesEXT in pProperties::pNext "
"chain, but failed to query PciBusInfo from the VirtGpuDevice",
__func__);
}
}
}

View file

@ -164,8 +164,6 @@ class ResourceTracker {
VkPhysicalDeviceFeatures2* pFeatures);
void on_vkGetPhysicalDeviceFeatures2KHR(void* context, VkPhysicalDevice physicalDevice,
VkPhysicalDeviceFeatures2* pFeatures);
void on_vkGetPhysicalDeviceProperties(void* context, VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties* pProperties);
void on_vkGetPhysicalDeviceProperties2(void* context, VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties2* pProperties);
void on_vkGetPhysicalDeviceProperties2KHR(void* context, VkPhysicalDevice physicalDevice,