Skip to content

Commit

Permalink
decode: Workaround non-CPU readable AHB image
Browse files Browse the repository at this point in the history
Importing external memory with external format is not supported at
replay time. The capture stored data in RGBA8_UNORM.
The content of the Android Hardware Buffer is restored with a Vulkan
image which imports the AHB memory, then it's filled reusing
functionalities of the resource initializer.
Finally, both image views and samplers are patched to remove any
reference to Android hardware buffers and external memory formats.
  • Loading branch information
antonio-lunarg committed Feb 24, 2025
1 parent e41eb0c commit 57cdaa5
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 195 deletions.
337 changes: 176 additions & 161 deletions framework/decode/vulkan_replay_consumer_base.cpp

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions framework/decode/vulkan_replay_consumer_base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2023 LunarG, Inc.
** Copyright (c) 2018-2025 LunarG, Inc.
** Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -192,16 +192,16 @@ class VulkanReplayConsumerBase : public VulkanConsumer
format::HandleId commandBuffer,
StructPointerDecoder<Decoded_VkPushDescriptorSetWithTemplateInfo>* pPushDescriptorSetWithTemplateInfo) override;

void Process_vkCreateRayTracingPipelinesKHR(
const ApiCallInfo& call_info,
VkResult returnValue,
format::HandleId device,
format::HandleId deferredOperation,
format::HandleId pipelineCache,
uint32_t createInfoCount,
StructPointerDecoder<Decoded_VkRayTracingPipelineCreateInfoKHR>* pCreateInfos,
StructPointerDecoder<Decoded_VkAllocationCallbacks>* pAllocator,
HandlePointerDecoder<VkPipeline>* pPipelines) override;
void Process_vkCreateRayTracingPipelinesKHR(
const ApiCallInfo& call_info,
VkResult returnValue,
format::HandleId device,
format::HandleId deferredOperation,
format::HandleId pipelineCache,
uint32_t createInfoCount,
StructPointerDecoder<Decoded_VkRayTracingPipelineCreateInfoKHR>* pCreateInfos,
StructPointerDecoder<Decoded_VkAllocationCallbacks>* pAllocator,
HandlePointerDecoder<VkPipeline>* pPipelines) override;

void ProcessBuildVulkanAccelerationStructuresMetaCommand(
format::HandleId device,
Expand Down Expand Up @@ -1405,6 +1405,13 @@ class VulkanReplayConsumerBase : public VulkanConsumer
VulkanShaderModuleInfo* shader_module_info,
const StructPointerDecoder<Decoded_VkAllocationCallbacks>* pAllocator);

VkResult OverrideCreateSampler(PFN_vkCreateSampler func,
VkResult result,
const VulkanDeviceInfo* device_info,
const StructPointerDecoder<Decoded_VkSamplerCreateInfo>* pCreateInfo,
const StructPointerDecoder<Decoded_VkAllocationCallbacks>* pAllocator,
HandlePointerDecoder<VkSampler>* pSampler);

std::function<handle_create_result_t<VkPipeline>()>
AsyncCreateGraphicsPipelines(PFN_vkCreateGraphicsPipelines func,
VkResult returnValue,
Expand Down
37 changes: 25 additions & 12 deletions framework/decode/vulkan_resource_initializer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright (c) 2019-2020 LunarG, Inc.
** Copyright (c) 2019-2025 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -40,11 +40,11 @@ VulkanResourceInitializer::VulkanResourceInitializer(const VulkanDeviceInfo*
bool have_shader_stencil_write,
VulkanResourceAllocator* resource_allocator,
const encode::VulkanDeviceTable* device_table) :
device_(device_info->handle),
staging_memory_(VK_NULL_HANDLE), staging_memory_data_(0), staging_buffer_(VK_NULL_HANDLE), staging_buffer_data_(0),
draw_sampler_(VK_NULL_HANDLE), draw_pool_(VK_NULL_HANDLE), draw_set_layout_(VK_NULL_HANDLE),
draw_set_(VK_NULL_HANDLE), max_copy_size_(max_copy_size), have_shader_stencil_write_(have_shader_stencil_write),
resource_allocator_(resource_allocator), device_table_(device_table), device_info_(device_info)
device_(device_info->handle), staging_memory_(VK_NULL_HANDLE), staging_memory_data_(0),
staging_buffer_(VK_NULL_HANDLE), staging_buffer_data_(0), draw_sampler_(VK_NULL_HANDLE), draw_pool_(VK_NULL_HANDLE),
draw_set_layout_(VK_NULL_HANDLE), draw_set_(VK_NULL_HANDLE), max_copy_size_(max_copy_size),
have_shader_stencil_write_(have_shader_stencil_write), resource_allocator_(resource_allocator),
device_table_(device_table), device_info_(device_info)
{
assert((device_info != nullptr) && (device_info->handle != VK_NULL_HANDLE) &&
(memory_properties.memoryTypeCount > 0) && (memory_properties.memoryHeapCount > 0) &&
Expand Down Expand Up @@ -169,7 +169,8 @@ VkResult VulkanResourceInitializer::InitializeImage(VkDeviceSize dat
VkImageLayout final_layout,
uint32_t layer_count,
uint32_t level_count,
const VkBufferImageCopy* level_copies)
const VkBufferImageCopy* level_copies,
VkSamplerYcbcrConversion conversion)
{
VkDeviceMemory staging_memory = VK_NULL_HANDLE;
VkBuffer staging_buffer = VK_NULL_HANDLE;
Expand Down Expand Up @@ -212,7 +213,8 @@ VkResult VulkanResourceInitializer::InitializeImage(VkDeviceSize dat
final_layout,
layer_count,
level_count,
level_copies);
level_copies,
conversion);
}
else
{
Expand Down Expand Up @@ -1258,7 +1260,8 @@ VkResult VulkanResourceInitializer::PixelShaderImageCopy(uint32_t
VkImageLayout final_layout,
uint32_t layer_count,
uint32_t level_count,
const VkBufferImageCopy* level_copies)
const VkBufferImageCopy* level_copies,
VkSamplerYcbcrConversion conversion)
{
VkQueue queue = VK_NULL_HANDLE;
VkCommandBuffer command_buffer = VK_NULL_HANDLE;
Expand Down Expand Up @@ -1292,7 +1295,9 @@ VkResult VulkanResourceInitializer::PixelShaderImageCopy(uint32_t

if (result == VK_SUCCESS)
{
VkImageCreateInfo image_info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };

VkImageCreateInfo image_info = { VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO };

image_info.pNext = nullptr;
image_info.flags = 0;
image_info.imageType = type;
Expand Down Expand Up @@ -1345,8 +1350,11 @@ VkResult VulkanResourceInitializer::PixelShaderImageCopy(uint32_t
scissor_rect.extent.width = level_copy.imageExtent.width;
scissor_rect.extent.height = level_copy.imageExtent.height;

VkImageViewCreateInfo view_info = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
view_info.pNext = nullptr;
VkSamplerYcbcrConversionInfo conversion_info = {
VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO, nullptr, conversion
};
VkImageViewCreateInfo view_info = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };

view_info.flags = 0;
view_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
view_info.format = format;
Expand Down Expand Up @@ -1374,6 +1382,11 @@ VkResult VulkanResourceInitializer::PixelShaderImageCopy(uint32_t
{
UpdateDrawDescriptorSet(set, staging_view, sampler);

if (conversion != VK_NULL_HANDLE)
{
view_info.pNext = &conversion_info;
view_info.format = VK_FORMAT_UNDEFINED;
}
view_info.image = destination;
result = CreateFramebufferResources(&view_info,
level_copy.imageExtent.width,
Expand Down
8 changes: 5 additions & 3 deletions framework/decode/vulkan_resource_initializer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright (c) 2019-2020 LunarG, Inc.
** Copyright (c) 2019-2025 LunarG, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -73,7 +73,8 @@ class VulkanResourceInitializer
VkImageLayout final_layout,
uint32_t layer_count,
uint32_t level_count,
const VkBufferImageCopy* level_copies);
const VkBufferImageCopy* level_copies,
VkSamplerYcbcrConversion conversion = VK_NULL_HANDLE);

VkResult TransitionImage(uint32_t queue_family_index,
VkImage image,
Expand Down Expand Up @@ -174,7 +175,8 @@ class VulkanResourceInitializer
VkImageLayout final_layout,
uint32_t layer_count,
uint32_t level_count,
const VkBufferImageCopy* level_copies);
const VkBufferImageCopy* level_copies,
VkSamplerYcbcrConversion conversion = VK_NULL_HANDLE);

private:
struct CommandExecObjects
Expand Down
14 changes: 7 additions & 7 deletions framework/generated/generated_vulkan_replay_consumer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
** Copyright (c) 2018-2023 Valve Corporation
** Copyright (c) 2018-2023 LunarG, Inc.
** Copyright (c) 2018-2025 LunarG, Inc.
** Copyright (c) 2023 Advanced Micro Devices, Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
Expand Down Expand Up @@ -1089,17 +1089,17 @@ void VulkanReplayConsumer::Process_vkCreateSampler(
StructPointerDecoder<Decoded_VkAllocationCallbacks>* pAllocator,
HandlePointerDecoder<VkSampler>* pSampler)
{
VkDevice in_device = MapHandle<VulkanDeviceInfo>(device, &CommonObjectInfoTable::GetVkDeviceInfo);
const VkSamplerCreateInfo* in_pCreateInfo = pCreateInfo->GetPointer();
auto in_device = GetObjectInfoTable().GetVkDeviceInfo(device);

MapStructHandles(pCreateInfo->GetMetaStructPointer(), GetObjectInfoTable());
const VkAllocationCallbacks* in_pAllocator = GetAllocationCallbacks(pAllocator);
if (!pSampler->IsNull()) { pSampler->SetHandleLength(1); }
VkSampler* out_pSampler = pSampler->GetHandlePointer();
VulkanSamplerInfo handle_info;
pSampler->SetConsumerData(0, &handle_info);

VkResult replay_result = GetDeviceTable(in_device)->CreateSampler(in_device, in_pCreateInfo, in_pAllocator, out_pSampler);
VkResult replay_result = OverrideCreateSampler(GetDeviceTable(in_device->handle)->CreateSampler, returnValue, in_device, pCreateInfo, pAllocator, pSampler);
CheckResult("vkCreateSampler", returnValue, replay_result, call_info);

AddHandle<VulkanSamplerInfo>(device, pSampler->GetPointer(), out_pSampler, &CommonObjectInfoTable::AddVkSamplerInfo);
AddHandle<VulkanSamplerInfo>(device, pSampler->GetPointer(), pSampler->GetHandlePointer(), std::move(handle_info), &CommonObjectInfoTable::AddVkSamplerInfo);
}

void VulkanReplayConsumer::Process_vkDestroySampler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
"vkCmdCopyAccelerationStructureKHR" : "OverrideCmdCopyAccelerationStructureKHR",
"vkCmdWriteAccelerationStructuresPropertiesKHR" : "OverrideCmdWriteAccelerationStructuresPropertiesKHR",
"vkCmdBindPipeline" : "OverrideCmdBindPipeline",
"vkCmdPushConstants" : "OverrideCmdPushConstants"
"vkCmdPushConstants" : "OverrideCmdPushConstants",
"vkCreateSampler": "OverrideCreateSampler"
}
}

0 comments on commit 57cdaa5

Please sign in to comment.