Skip to content

Commit

Permalink
Rebase and refactor fix for staging buffer memory types (#1173)
Browse files Browse the repository at this point in the history
* Fix memory type selection for staging buffers

This commit fixes an issue with erroneous memory type selection when
binding buffer memory without memory translation, e.g. in cases of
binding replay staging buffers. Currently, the code retrieves the
capture device's memory types, even though we want to bind the
memory directly from the replay device.

This issue led to various replay issues with mapping memory later on
in the replay, and was particularly disruptive when attempting to
replay a trimmed capture on a machine with a GPU of a different vendor
than the capture system.

* elevate choice of memory properties, remove conditional

---------

Co-authored-by: jacobv-nvidia <[email protected]>
Co-authored-by: jacobv-nvidia <[email protected]>
  • Loading branch information
3 people authored Jun 29, 2023
1 parent 3039473 commit 32496a2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
36 changes: 19 additions & 17 deletions framework/decode/vulkan_rebind_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,13 @@ void VulkanRebindAllocator::GetDeviceMemoryCommitment(VkDeviceMemory memory,
GFXRECON_UNREFERENCED_PARAMETER(allocator_data);
}

VkResult VulkanRebindAllocator::BindBufferMemory(VkBuffer buffer,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_buffer_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties)
VkResult VulkanRebindAllocator::BindBufferMemory(VkBuffer buffer,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_buffer_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties,
const VkPhysicalDeviceMemoryProperties& device_memory_properties)
{
GFXRECON_UNREFERENCED_PARAMETER(memory);

Expand All @@ -407,10 +408,10 @@ VkResult VulkanRebindAllocator::BindBufferMemory(VkBuffer buffer,

VmaAllocationCreateInfo create_info;
create_info.flags = 0;
create_info.usage = GetBufferMemoryUsage(
resource_alloc_info->usage,
capture_memory_properties_.memoryTypes[memory_alloc_info->original_index].propertyFlags,
requirements);
create_info.usage =
GetBufferMemoryUsage(resource_alloc_info->usage,
device_memory_properties.memoryTypes[memory_alloc_info->original_index].propertyFlags,
requirements);
create_info.requiredFlags = 0;
create_info.preferredFlags = 0;
create_info.memoryTypeBits = 0;
Expand Down Expand Up @@ -550,12 +551,13 @@ VkResult VulkanRebindAllocator::BindBufferMemory2(uint32_t
return result;
}

VkResult VulkanRebindAllocator::BindImageMemory(VkImage image,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_image_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties)
VkResult VulkanRebindAllocator::BindImageMemory(VkImage image,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_image_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties,
const VkPhysicalDeviceMemoryProperties& device_memory_properties)
{
GFXRECON_UNREFERENCED_PARAMETER(memory);

Expand All @@ -576,7 +578,7 @@ VkResult VulkanRebindAllocator::BindImageMemory(VkImage image,
create_info.usage =
GetImageMemoryUsage(resource_alloc_info->usage,
resource_alloc_info->tiling,
capture_memory_properties_.memoryTypes[memory_alloc_info->original_index].propertyFlags,
device_memory_properties.memoryTypes[memory_alloc_info->original_index].propertyFlags,
requirements);
create_info.requiredFlags = 0;
create_info.preferredFlags = 0;
Expand Down
56 changes: 50 additions & 6 deletions framework/decode/vulkan_rebind_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,16 @@ class VulkanRebindAllocator : public VulkanResourceAllocator
VkDeviceSize memory_offset,
ResourceData allocator_buffer_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties) override;
VkMemoryPropertyFlags* bind_memory_properties) override
{
return BindBufferMemory(buffer,
memory,
memory_offset,
allocator_buffer_data,
allocator_memory_data,
bind_memory_properties,
capture_memory_properties_);
}

virtual VkResult BindBufferMemory2(uint32_t bind_info_count,
const VkBindBufferMemoryInfo* bind_infos,
Expand All @@ -114,7 +123,16 @@ class VulkanRebindAllocator : public VulkanResourceAllocator
VkDeviceSize memory_offset,
ResourceData allocator_image_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties) override;
VkMemoryPropertyFlags* bind_memory_properties) override
{
return BindImageMemory(image,
memory,
memory_offset,
allocator_image_data,
allocator_memory_data,
bind_memory_properties,
capture_memory_properties_);
}

virtual VkResult BindImageMemory2(uint32_t bind_info_count,
const VkBindImageMemoryInfo* bind_infos,
Expand Down Expand Up @@ -217,8 +235,13 @@ class VulkanRebindAllocator : public VulkanResourceAllocator
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties) override
{
return BindBufferMemory(
buffer, memory, memory_offset, allocator_buffer_data, allocator_memory_data, bind_memory_properties);
return BindBufferMemory(buffer,
memory,
memory_offset,
allocator_buffer_data,
allocator_memory_data,
bind_memory_properties,
replay_memory_properties_);
}

virtual VkResult BindImageMemoryDirect(VkImage image,
Expand All @@ -228,8 +251,13 @@ class VulkanRebindAllocator : public VulkanResourceAllocator
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties) override
{
return BindImageMemory(
image, memory, memory_offset, allocator_image_data, allocator_memory_data, bind_memory_properties);
return BindImageMemory(image,
memory,
memory_offset,
allocator_image_data,
allocator_memory_data,
bind_memory_properties,
replay_memory_properties_);
}

virtual VkResult MapResourceMemoryDirect(VkDeviceSize size,
Expand Down Expand Up @@ -342,6 +370,22 @@ class VulkanRebindAllocator : public VulkanResourceAllocator

void ReportBindIncompatibility(const ResourceData* allocator_resource_datas, uint32_t resource_count);

VkResult BindBufferMemory(VkBuffer buffer,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_buffer_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties,
const VkPhysicalDeviceMemoryProperties& device_memory_properties);

VkResult BindImageMemory(VkImage image,
VkDeviceMemory memory,
VkDeviceSize memory_offset,
ResourceData allocator_image_data,
MemoryData allocator_memory_data,
VkMemoryPropertyFlags* bind_memory_properties,
const VkPhysicalDeviceMemoryProperties& device_memory_properties);

private:
VkDevice device_;
VmaAllocator allocator_;
Expand Down

0 comments on commit 32496a2

Please sign in to comment.