From a6ade961b24fd041d5ccc0cb9e1a45248f0d4b88 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 28 Nov 2025 00:22:23 -0800 Subject: [PATCH] venus: implement VK_EXT_map_memory_placed Part-of: --- docs/features.txt | 2 +- src/virtio/vulkan/vn_device.c | 5 +++++ src/virtio/vulkan/vn_device_memory.c | 10 +++++++++- src/virtio/vulkan/vn_physical_device.c | 12 ++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index 6964b9e3d86..70181c89079 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -716,7 +716,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_swapchain_colorspace DONE (anv, hk, lvp, nvk, radv, tu, v3dv, vn) VK_EXT_depth_clamp_zero_one DONE (anv, nvk, panvk, pvr, radv, tu, v3dv/vc7+, vn) VK_INTEL_shader_integer_functions2 DONE (anv, hasvk, radv) - VK_EXT_map_memory_placed DONE (anv, hk, nvk, pvr, radv, tu) + VK_EXT_map_memory_placed DONE (anv, hk, nvk, pvr, radv, tu, vn) VK_MESA_image_alignment_control DONE (anv, nvk, radv) VK_EXT_legacy_dithering DONE (anv, tu, vn) VK_QCOM_fragment_density_map_offset DONE (tu) diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c index 103f246b489..743d4f429d6 100644 --- a/src/virtio/vulkan/vn_device.c +++ b/src/virtio/vulkan/vn_device.c @@ -328,6 +328,11 @@ vn_device_fix_create_info(const struct vn_device *dev, block_exts[block_count++] = VK_KHR_MAP_MEMORY_2_EXTENSION_NAME; } + if (app_exts->EXT_map_memory_placed) { + /* see vn_physical_device_get_native_extensions */ + block_exts[block_count++] = VK_EXT_MAP_MEMORY_PLACED_EXTENSION_NAME; + } + if (app_exts->EXT_device_memory_report) { /* see vn_physical_device_get_native_extensions */ block_exts[block_count++] = VK_EXT_DEVICE_MEMORY_REPORT_EXTENSION_NAME; diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c index f82ff599ab9..dbf28f5b574 100644 --- a/src/virtio/vulkan/vn_device_memory.c +++ b/src/virtio/vulkan/vn_device_memory.c @@ -436,6 +436,7 @@ vn_MapMemory2(VkDevice device, const VkDeviceSize size = pMemoryMapInfo->size; const struct vk_device_memory *mem_vk = &mem->base.vk; const bool need_bo = !mem->base_bo; + void *placed_addr = NULL; void *ptr = NULL; VkResult result; @@ -457,7 +458,14 @@ vn_MapMemory2(VkDevice device, return vn_error(dev->instance, result); } - ptr = vn_renderer_bo_map(dev->renderer, mem->base_bo, NULL); + if (pMemoryMapInfo->flags & VK_MEMORY_MAP_PLACED_BIT_EXT) { + const VkMemoryMapPlacedInfoEXT *placed_info = vk_find_struct_const( + pMemoryMapInfo->pNext, MEMORY_MAP_PLACED_INFO_EXT); + assert(placed_info != NULL); + placed_addr = placed_info->pPlacedAddress; + } + + ptr = vn_renderer_bo_map(dev->renderer, mem->base_bo, placed_addr); if (!ptr) { /* vn_renderer_bo_map implies a roundtrip on success, but not here. */ if (need_bo) { diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index a4abf19a419..908386efa09 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -14,6 +14,7 @@ #include "git_sha1.h" #include "util/mesa-sha1.h" +#include "util/os_misc.h" #include "venus-protocol/vn_protocol_driver_device.h" #include "vk_android.h" #include "vk_common_entrypoints.h" @@ -411,6 +412,11 @@ vn_physical_device_init_features(struct vn_physical_device *physical_dev) */ feats->deviceMemoryReport = true; + /* VK_EXT_map_memory_placed */ + feats->memoryMapPlaced = true; + feats->memoryMapRangePlaced = false; + feats->memoryUnmapReserve = true; + #ifdef VN_USE_WSI_PLATFORM feats->presentId = true; feats->presentId2 = true; @@ -838,6 +844,11 @@ vn_physical_device_init_properties(struct vn_physical_device *physical_dev) /* initialize native properties */ + /* VK_EXT_map_memory_placed */ + uint64_t os_page_size = 4096; + os_get_page_size(&os_page_size); + props->minPlacedMemoryMapAlignment = os_page_size; + /* VK_EXT_physical_device_drm */ VN_SET_VK_PROPS(props, &renderer_info->drm.props); @@ -1180,6 +1191,7 @@ vn_physical_device_get_native_extensions( exts->KHR_deferred_host_operations = physical_dev->ray_tracing && renderer_exts->KHR_acceleration_structure; exts->KHR_map_memory2 = true; + exts->EXT_map_memory_placed = true; exts->EXT_physical_device_drm = true; /* use common implementation */ exts->EXT_tooling_info = true;