[PATCH] gfxstream: Add common interfaces in the VirtGpuDevice to query DrmInfo and...
authorAaron Ruby <aruby@qnx.com>
Thu, 6 Feb 2025 21:46:25 +0000 (16:46 -0500)
committerTimo Aaltonen <tjaalton@debian.org>
Thu, 3 Apr 2025 10:47:45 +0000 (13:47 +0300)
- Advertise the availability of these extensions, fully implemented as
guestOnly features

Reviewed-By: Gurchetan Singh <gurchetansingh@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33363>

Gbp-Pq: Name gfxstream-add-common-interfaces.diff

src/gfxstream/guest/platform/include/VirtGpu.h
src/gfxstream/guest/platform/linux/LinuxVirtGpu.h
src/gfxstream/guest/platform/linux/LinuxVirtGpuDevice.cpp
src/gfxstream/guest/vulkan_enc/ResourceTracker.cpp

index 8f7ee182fc4bf1e9de5623b93d4c58bdf31da0cf..8fee452538fc6541743e43f4d74bbfb496dc8961 100644 (file)
@@ -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;
 };
index a92a67a962551317f23d371023c80cfaea84f188..18ccb47012a9408f4566faf3b51fc298743104b5 100644 (file)
@@ -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;
index d085a3a91fffb50e14dddfb12a925ac868b1fb17..d5509388fda85ce77ac3b5485dd9368eccea10a3 100644 (file)
@@ -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;
+}
index bd443ed0900667a1110a5569e5b5d9f9d874abc3..f7efb1dc0ad64237ebffd5307b5091973f4814c6 100644 (file)
@@ -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__);
+            }
+        }
     }
 }