Skip to content

Commit

Permalink
Implement toCpp virtual swapchain code
Browse files Browse the repository at this point in the history
Implement the virtual swapchain path in the toCpp code.  This is
done by writing a swapchain_common header and source file which
handles the swapchain code.  By default, the virtual swapchain
code is enabled but can be disabled.  In generated code, this can
be done simply by modifying the define of "USE_VIRTUAL_SWAPCHAIN"
from 1 to 0.

It can also be disabled when generating the source by using the
"--captured-swapchain" option.
  • Loading branch information
MarkY-LunarG committed Dec 28, 2023
1 parent 839cdfe commit 166630b
Show file tree
Hide file tree
Showing 12 changed files with 884 additions and 216 deletions.
98 changes: 60 additions & 38 deletions framework/decode/vulkan_cpp_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,25 @@ bool VulkanCppConsumerBase::WriteSwapchainFiles()
int32_t result = util::platform::FileOpen(&header_file, header_filename.c_str(), "w");
if (result == 0)
{
fputs(sCommonHeaderOutputHeaders, header_file);
fputs(sSwapchainHeaderCode, header_file);

if (enable_virtual_swapchain_)
{
fputs("\n\n// Enable the virtual swapchain code\n", header_file);
fputs("#define USE_VIRTUAL_SWAPCHAIN 1\n", header_file);
}
else
{
fputs("\n\n// Disable the virtual swapchain code\n", header_file);
fputs("#define USE_VIRTUAL_SWAPCHAIN 0\n", header_file);
}

util::platform::FileClose(header_file);

result = util::platform::FileOpen(&source_file, source_filename.c_str(), "w");
if (result == 0)
{
FILE* global_file = GetGlobalFile();
fputs(sCommonHeaderOutputHeaders, source_file);
fputs(sSwapchainSourceCode, source_file);

util::platform::FileClose(source_file);
Expand Down Expand Up @@ -683,10 +693,17 @@ void VulkanCppConsumerBase::Generate_vkGetSwapchainImagesKHR(VkResult

pfn_loader_.AddMethodName("vkGetSwapchainImagesKHR");

uint32_t captured_swapchain_count = 0;
if (pSwapchainImageCount->GetPointer() != nullptr)
{
captured_swapchain_count = *pSwapchainImageCount->GetPointer();
}

fprintf(file,
"\tVK_CALL_CHECK(loaded_vkGetSwapchainImagesKHR(%s, %s, &%s, %s), %s);\n",
"\tVK_CALL_CHECK(toCppGetSwapchainImagesKHR(%s, %s, %u, &%s, %s), %s);\n",
GetHandle(device).c_str(),
handle_id_map_[swapchain].c_str(),
captured_swapchain_count,
ptr_map_[pSwapchainImageCount].c_str(),
swapchain_images_var_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
Expand Down Expand Up @@ -1792,30 +1809,18 @@ void VulkanCppConsumerBase::Generate_vkAcquireNextImageKHR(VkResult
AddKnownVariables("uint32_t", image_index_var_name);

pfn_loader_.AddMethodName("vkAcquireNextImageKHR");
if (returnValue == VK_SUCCESS)
{
fprintf(file,
"\twhile (loaded_vkAcquireNextImageKHR(%s, %s, %" PRIu64
"UL, %s, %s, &%s) != VK_SUCCESS) { usleep(5000); };\n",
GetHandle(device).c_str(),
GetHandle(swapchain).c_str(),
timeout,
GetHandle(semaphore).c_str(),
GetHandle(fence).c_str(),
image_index_var_name.c_str());
}
else
{
fprintf(file,
"\tVK_CALL_CHECK(loaded_vkAcquireNextImageKHR(%s, %s, %" PRIu64 "UL, %s, %s, &%s), %s);\n",
GetHandle(device).c_str(),
GetHandle(swapchain).c_str(),
timeout,
GetHandle(semaphore).c_str(),
GetHandle(fence).c_str(),
image_index_var_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
}
fprintf(file,
"\tVK_CALL_CHECK(toCppAcquireNextImageKHR(static_cast<VkResult>(0x%08x), %s, %s, %" PRIu64
"UL, %s, %s, %u, &%s), %s);\n",
returnValue,
GetHandle(device).c_str(),
GetHandle(swapchain).c_str(),
timeout,
GetHandle(semaphore).c_str(),
GetHandle(fence).c_str(),
(*pImageIndex->GetPointer()),
image_index_var_name.c_str(),
util::ToString<VkResult>(returnValue).c_str());
}

void VulkanCppConsumerBase::Generate_vkAcquireNextImage2KHR(
Expand Down Expand Up @@ -3283,6 +3288,25 @@ void VulkanCppConsumerBase::ProcessSetOpaqueAddressCommand(format::HandleId devi
}
}

void VulkanCppConsumerBase::Generate_vkGetDeviceQueue(format::HandleId device,
uint32_t queueFamilyIndex,
uint32_t queueIndex,
HandlePointerDecoder<VkQueue>* pQueue)
{
FILE* file = GetFrameFile();
fprintf(file, "\t{\n");
std::string pqueue_name = "pQueue_" + std::to_string(this->GetNextId(VK_OBJECT_TYPE_QUEUE));
AddKnownVariables("VkQueue", pqueue_name, pQueue->GetPointer());
this->AddHandles(pqueue_name, pQueue->GetPointer());
fprintf(file,
"\t\ttoCppGetDeviceQueue(%s, %u, %u, &%s);\n",
this->GetHandle(device).c_str(),
queueFamilyIndex,
queueIndex,
pqueue_name.c_str());
fprintf(file, "\t}\n");
}

void VulkanCppConsumerBase::Generate_vkGetAndroidHardwareBufferPropertiesANDROID(
VkResult returnValue,
format::HandleId device,
Expand Down Expand Up @@ -3528,20 +3552,18 @@ void VulkanCppConsumerBase::Generate_vkQueuePresentKHR(VkResult
{
FILE* file = GetFrameFile();
fprintf(file, "\t{\n");
// queue
// pPresentInfo
std::stringstream stream_ppresent_info;
std::string ppresent_info_struct = GenerateStruct_VkPresentInfoKHR(stream_ppresent_info,
pPresentInfo->GetPointer(),
pPresentInfo->GetMetaStructPointer(),
imported_semaphores_,
*this);
fprintf(file, "%s", stream_ppresent_info.str().c_str());
std::stringstream stream_present_info;
std::string present_info_struct = GenerateStruct_VkPresentInfoKHR(stream_present_info,
pPresentInfo->GetPointer(),
pPresentInfo->GetMetaStructPointer(),
imported_semaphores_,
*this);
fprintf(file, "%s", stream_present_info.str().c_str());
pfn_loader_.AddMethodName("vkQueuePresentKHR");
fprintf(file,
"\t\tVK_CALL_CHECK(loaded_vkQueuePresentKHR(%s, &%s), %s);\n",
"\t\tVK_CALL_CHECK(toCppQueuePresentKHR(%s, &%s), %s);\n",
this->GetHandle(queue).c_str(),
ppresent_info_struct.c_str(),
present_info_struct.c_str(),
util::ToString<VkResult>(returnValue).c_str());
fprintf(file, "\t}\n");
}
Expand Down
7 changes: 7 additions & 0 deletions framework/decode/vulkan_cpp_consumer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class VulkanCppConsumerBase : public VulkanConsumer
void SetWindowSize(uint32_t appWindowWidth, uint32_t appWindowHeight);
void SetMaxCommandLimit(uint32_t max) { max_command_limit_ = max; }

void DisableVirtualSwapchain() { enable_virtual_swapchain_ = false; }

uint32_t GetNextId();
uint32_t GetNextId(VkObjectType object_type);

Expand Down Expand Up @@ -416,6 +418,10 @@ class VulkanCppConsumerBase : public VulkanConsumer
format::HandleId device,
uint64_t buffer,
StructPointerDecoder<Decoded_VkAndroidHardwareBufferPropertiesANDROID>* pProperties);
void Generate_vkGetDeviceQueue(format::HandleId device,
uint32_t queueFamilyIndex,
uint32_t queueIndex,
HandlePointerDecoder<VkQueue>* pQueue);
void Generate_vkGetMemoryAndroidHardwareBufferANDROID(
VkResult returnValue,
format::HandleId device,
Expand Down Expand Up @@ -680,6 +686,7 @@ class VulkanCppConsumerBase : public VulkanConsumer
size_t size;
};

bool enable_virtual_swapchain_{ true };
uint32_t frame_number_;
uint32_t frame_split_number_;
uint32_t frame_api_call_number_;
Expand Down
Loading

0 comments on commit 166630b

Please sign in to comment.