diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 45f899b2f3..cca69370fb 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -5828,6 +5828,16 @@ class Resource final }; VkMemoryRequirements requirements{}; vk.vkGetBufferMemoryRequirements(device_.info.device, buffer_, &requirements); + // On GPUs where UNIFORM_BUFFER_BIT rounds requirements.size past `bytes` (e.g. above minImportedHostPointerAlignment), + // D3D12 CBVs need 256-byte address and size alignment anyway and the layer encodes CBVs as raw V#s, so drop + // UNIFORM_BUFFER_BIT when the UBO size rounding exceeds the imported host range. + if (requirements.size > bytes) { + vk.vkDestroyBuffer(device_.info.device, buffer_, nullptr); + buffer_ = VK_NULL_HANDLE; + info.usage &= ~VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + if (vk.vkCreateBuffer(device_.info.device, &info, nullptr, &buffer_) != VK_SUCCESS) return decline(E_OUTOFMEMORY); + vk.vkGetBufferMemoryRequirements(device_.info.device, buffer_, &requirements); + } VkMemoryHostPointerPropertiesEXT host{VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT}; if (device_.get_host_pointer_properties(device_.info.device, VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT, base_address, diff --git a/runtime/test/d3d12_existing_heap_test.cpp b/runtime/test/d3d12_existing_heap_test.cpp index 3d65fc7409..2d1ad54b4a 100644 --- a/runtime/test/d3d12_existing_heap_test.cpp +++ b/runtime/test/d3d12_existing_heap_test.cpp @@ -606,9 +606,11 @@ int check_title_placed_all(ID3D12Device* device) { failures += check_title_placed(device, "VirtualAlloc range", pages, size); failures += check_placed_texture_views(device, pages); // Inside a page, as the title places small UAV buffers (64-byte aligned, found in review on an RTX 5090): the - // import starts at the page and the buffer is bound at the offset. + // import starts at the page and the buffer is bound at the offset. Also check a 16-byte slice 64 bytes from the + // end of the committed range, where 256-byte uniform-buffer size rounding would run past the page. failures += check_title_placed(device, "64 bytes into a page", static_cast(pages) + 64, 0x1000 - 64); failures += check_host_prefix_buffers(device); + failures += check_title_placed(device, "16 bytes near the end of the range", static_cast(pages) + size - 64, 16); VirtualFree(pages, 0, MEM_RELEASE); HANDLE section = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(size), nullptr); void* view = section ? MapViewOfFile(section, FILE_MAP_ALL_ACCESS, 0, 0, size) : nullptr;