From: Aaron Ruby Date: Thu, 6 Feb 2025 21:46:25 +0000 (-0500) Subject: [PATCH] gfxstream: Add common interfaces in the VirtGpuDevice to query DrmInfo and... X-Git-Tag: archive/raspbian/25.0.7-2+rpi1^2^2^2^2^2^2~3 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=d2a3bc64fbeeadafbb8a54a150bea907bf800479;p=mesa.git [PATCH] gfxstream: Add common interfaces in the VirtGpuDevice to query DrmInfo and PciBusInfo - Advertise the availability of these extensions, fully implemented as guestOnly features Reviewed-By: Gurchetan Singh Part-of: Gbp-Pq: Name gfxstream-add-common-interfaces.diff --- diff --git a/src/gfxstream/guest/platform/include/VirtGpu.h b/src/gfxstream/guest/platform/include/VirtGpu.h index 8f7ee182f..8fee45253 100644 --- a/src/gfxstream/guest/platform/include/VirtGpu.h +++ b/src/gfxstream/guest/platform/include/VirtGpu.h @@ -130,6 +130,23 @@ struct VirtGpuCaps { struct composerCapset composerCapset; }; +struct VirtGpuDrmInfo { + bool hasPrimary; + bool hasRender; + int64_t primaryMajor; + int64_t primaryMinor; + int64_t renderMajor; + int64_t renderMinor; +}; + +// Note: Fields match equivalent structure for Magma +struct VirtGpuPciBusInfo { + uint16_t domain; + uint8_t bus; + uint8_t device; + uint8_t function; +}; + #define INVALID_DESCRIPTOR -1 class VirtGpuResourceMapping; @@ -196,6 +213,9 @@ class VirtGpuDevice { virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuResource* blob) = 0; + virtual bool getDrmInfo(VirtGpuDrmInfo* drmInfo) { return false; } + virtual bool getPciBusInfo(VirtGpuPciBusInfo* pciBusInfo) { return false; } + private: enum VirtGpuCapset mCapset; }; diff --git a/src/gfxstream/guest/platform/linux/LinuxVirtGpu.h b/src/gfxstream/guest/platform/linux/LinuxVirtGpu.h index a92a67a96..18ccb4701 100644 --- a/src/gfxstream/guest/platform/linux/LinuxVirtGpu.h +++ b/src/gfxstream/guest/platform/linux/LinuxVirtGpu.h @@ -67,6 +67,9 @@ class LinuxVirtGpuDevice : public VirtGpuDevice { virtual VirtGpuResourcePtr importBlob(const struct VirtGpuExternalHandle& handle); virtual int execBuffer(struct VirtGpuExecBuffer& execbuffer, const VirtGpuResource* blob); + virtual bool getDrmInfo(VirtGpuDrmInfo* drmInfo) override; + virtual bool getPciBusInfo(VirtGpuPciBusInfo* pciBusInfo) override; + private: int64_t mDeviceHandle; struct VirtGpuCaps mCaps; diff --git a/src/gfxstream/guest/platform/linux/LinuxVirtGpuDevice.cpp b/src/gfxstream/guest/platform/linux/LinuxVirtGpuDevice.cpp index d085a3a91..d5509388f 100644 --- a/src/gfxstream/guest/platform/linux/LinuxVirtGpuDevice.cpp +++ b/src/gfxstream/guest/platform/linux/LinuxVirtGpuDevice.cpp @@ -356,3 +356,26 @@ int LinuxVirtGpuDevice::execBuffer(struct VirtGpuExecBuffer& execbuffer, VirtGpuDevice* osCreateVirtGpuDevice(enum VirtGpuCapset capset, int32_t descriptor) { return new LinuxVirtGpuDevice(capset, descriptor); } + +bool LinuxVirtGpuDevice::getDrmInfo(VirtGpuDrmInfo* drmInfo) { + drmInfo->hasPrimary = mHasPrimary; + drmInfo->hasRender = true; + drmInfo->primaryMajor = mPrimaryMajor; + drmInfo->primaryMinor = mPrimaryMinor; + drmInfo->renderMajor = mRenderMajor; + drmInfo->renderMinor = mRenderMinor; + return true; +} + +bool LinuxVirtGpuDevice::getPciBusInfo(VirtGpuPciBusInfo* pciBusInfo) { + if (mBusType != DRM_BUS_PCI) { + return false; + } + + pciBusInfo->domain = mPciBusInfo.domain; + pciBusInfo->bus = mPciBusInfo.bus; + pciBusInfo->device = mPciBusInfo.dev; + pciBusInfo->function = mPciBusInfo.func; + + return true; +} diff --git a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp index bd443ed09..f7efb1dc0 100644 --- a/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp +++ b/src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp @@ -2101,6 +2101,42 @@ void ResourceTracker::on_vkGetPhysicalDeviceProperties2(void* context, VkPhysicalDeviceProperties2* pProperties) { if (pProperties) { on_vkGetPhysicalDeviceProperties(context, physicalDevice, &pProperties->properties); + + VkPhysicalDeviceDrmPropertiesEXT* drmProps = + vk_find_struct(pProperties, PHYSICAL_DEVICE_DRM_PROPERTIES_EXT); + if (drmProps) { + VirtGpuDrmInfo drmInfo; + if (VirtGpuDevice::getInstance()->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 (pciBusInfoProps) { + VirtGpuPciBusInfo pciBusInfo; + if (VirtGpuDevice::getInstance()->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__); + } + } } }