From 485b2b501cf964be35c24c12e427d9e96c141e02 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sat, 7 Feb 2026 23:06:40 -0800 Subject: [PATCH] venus: implement all descriptor heap commands There're potential optimizations available for below: - vkWriteSamplerDescriptorsEXT - vkWriteResourceDescriptorsEXT - vkGetPhysicalDeviceDescriptorSizeEXT - vkRegisterCustomBorderColorEXT ...and we can revisit if there's perf hit from above for real apps. Part-of: --- src/virtio/vulkan/meson.build | 1 + src/virtio/vulkan/vn_command_buffer.c | 21 +++++++ src/virtio/vulkan/vn_descriptor_heap.c | 83 ++++++++++++++++++++++++++ src/virtio/vulkan/vn_physical_device.c | 13 ++++ 4 files changed, 118 insertions(+) create mode 100644 src/virtio/vulkan/vn_descriptor_heap.c diff --git a/src/virtio/vulkan/meson.build b/src/virtio/vulkan/meson.build index 00b787a172c..e9e9dca83bb 100644 --- a/src/virtio/vulkan/meson.build +++ b/src/virtio/vulkan/meson.build @@ -59,6 +59,7 @@ libvn_files = files( 'vn_command_buffer.c', 'vn_common.c', 'vn_cs.c', + 'vn_descriptor_heap.c', 'vn_descriptor_set.c', 'vn_device.c', 'vn_device_memory.c', diff --git a/src/virtio/vulkan/vn_command_buffer.c b/src/virtio/vulkan/vn_command_buffer.c index 433079daa53..fa8c8a8b484 100644 --- a/src/virtio/vulkan/vn_command_buffer.c +++ b/src/virtio/vulkan/vn_command_buffer.c @@ -2813,3 +2813,24 @@ vn_CmdDrawMeshTasksIndirectCountEXT(VkCommandBuffer commandBuffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); } + +VKAPI_ATTR void VKAPI_CALL +vn_CmdBindResourceHeapEXT(VkCommandBuffer commandBuffer, + const VkBindHeapInfoEXT *pBindInfo) +{ + VN_CMD_ENQUEUE(vkCmdBindResourceHeapEXT, commandBuffer, pBindInfo); +} + +VKAPI_ATTR void VKAPI_CALL +vn_CmdBindSamplerHeapEXT(VkCommandBuffer commandBuffer, + const VkBindHeapInfoEXT *pBindInfo) +{ + VN_CMD_ENQUEUE(vkCmdBindSamplerHeapEXT, commandBuffer, pBindInfo); +} + +VKAPI_ATTR void VKAPI_CALL +vn_CmdPushDataEXT(VkCommandBuffer commandBuffer, + const VkPushDataInfoEXT *pPushDataInfo) +{ + VN_CMD_ENQUEUE(vkCmdPushDataEXT, commandBuffer, pPushDataInfo); +} diff --git a/src/virtio/vulkan/vn_descriptor_heap.c b/src/virtio/vulkan/vn_descriptor_heap.c new file mode 100644 index 00000000000..a765e3d447d --- /dev/null +++ b/src/virtio/vulkan/vn_descriptor_heap.c @@ -0,0 +1,83 @@ +/* + * Copyright 2026 Google LLC + * SPDX-License-Identifier: MIT + */ + +#include "venus-protocol/vn_protocol_driver_descriptor_heap.h" + +#include "vn_device.h" + +/* descriptor heap commands */ + +VKAPI_ATTR VkResult VKAPI_CALL +vn_WriteSamplerDescriptorsEXT(VkDevice device, + uint32_t samplerCount, + const VkSamplerCreateInfo *pSamplers, + const VkHostAddressRangeEXT *pDescriptors) +{ + struct vn_device *dev = vn_device_from_handle(device); + + /* TODO move out from primary ring? */ + for (uint32_t i = 0; i < samplerCount; i++) { + VkResult result = vn_call_vkWriteSamplerDescriptorMESA( + dev->primary_ring, device, &pSamplers[i], pDescriptors[i].size, + pDescriptors[i].address); + if (result != VK_SUCCESS) + return vn_error(dev->instance, result); + } + + return VK_SUCCESS; +} + +VKAPI_ATTR VkResult VKAPI_CALL +vn_WriteResourceDescriptorsEXT(VkDevice device, + uint32_t resourceCount, + const VkResourceDescriptorInfoEXT *pResources, + const VkHostAddressRangeEXT *pDescriptors) +{ + struct vn_device *dev = vn_device_from_handle(device); + + /* TODO move out from primary ring? */ + for (uint32_t i = 0; i < resourceCount; i++) { + VkResult result = vn_call_vkWriteResourceDescriptorMESA( + dev->primary_ring, device, &pResources[i], pDescriptors[i].size, + pDescriptors[i].address); + if (result != VK_SUCCESS) + return vn_error(dev->instance, result); + } + + return VK_SUCCESS; +} + +VKAPI_ATTR VkResult VKAPI_CALL +vn_GetImageOpaqueCaptureDataEXT(VkDevice device, + uint32_t imageCount, + const VkImage *pImages, + VkHostAddressRangeEXT *pDatas) +{ + struct vn_device *dev = vn_device_from_handle(device); + return vn_call_vkGetImageOpaqueCaptureDataEXT(dev->primary_ring, device, + imageCount, pImages, pDatas); +} + +VKAPI_ATTR VkResult VKAPI_CALL +vn_RegisterCustomBorderColorEXT( + VkDevice device, + const VkSamplerCustomBorderColorCreateInfoEXT *pBorderColor, + VkBool32 requestIndex, + uint32_t *pIndex) +{ + struct vn_device *dev = vn_device_from_handle(device); + + /* TODO manage indexes to make it async */ + return vn_call_vkRegisterCustomBorderColorEXT( + dev->primary_ring, device, pBorderColor, requestIndex, pIndex); +} + +VKAPI_ATTR void VKAPI_CALL +vn_UnregisterCustomBorderColorEXT(VkDevice device, uint32_t index) +{ + struct vn_device *dev = vn_device_from_handle(device); + vn_async_vkUnregisterCustomBorderColorEXT(dev->primary_ring, device, + index); +} diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index e939a05ce00..30b58c43da7 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -3059,3 +3059,16 @@ vn_GetPhysicalDeviceMultisamplePropertiesEXT( vn_call_vkGetPhysicalDeviceMultisamplePropertiesEXT( ring, physicalDevice, samples, pMultisampleProperties); } + +VKAPI_ATTR VkDeviceSize VKAPI_CALL +vn_GetPhysicalDeviceDescriptorSizeEXT(VkPhysicalDevice physicalDevice, + VkDescriptorType descriptorType) +{ + struct vn_physical_device *physical_dev = + vn_physical_device_from_handle(physicalDevice); + struct vn_ring *ring = physical_dev->instance->ring.ring; + + /* TODO per-device cache */ + return vn_call_vkGetPhysicalDeviceDescriptorSizeEXT(ring, physicalDevice, + descriptorType); +}