Skip to content

Commit 6c93334

Browse files
committed
Implement toCpp virtual swapchain code
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.
1 parent 839cdfe commit 6c93334

9 files changed

+884
-83
lines changed

framework/decode/vulkan_cpp_consumer_base.cpp

+60-38
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,25 @@ bool VulkanCppConsumerBase::WriteSwapchainFiles()
358358
int32_t result = util::platform::FileOpen(&header_file, header_filename.c_str(), "w");
359359
if (result == 0)
360360
{
361+
fputs(sCommonHeaderOutputHeaders, header_file);
361362
fputs(sSwapchainHeaderCode, header_file);
362363

364+
if (enable_virtual_swapchain_)
365+
{
366+
fputs("\n\n// Enable the virtual swapchain code\n", header_file);
367+
fputs("#define USE_VIRTUAL_SWAPCHAIN 1\n", header_file);
368+
}
369+
else
370+
{
371+
fputs("\n\n// Disable the virtual swapchain code\n", header_file);
372+
fputs("#define USE_VIRTUAL_SWAPCHAIN 0\n", header_file);
373+
}
374+
363375
util::platform::FileClose(header_file);
364376

365377
result = util::platform::FileOpen(&source_file, source_filename.c_str(), "w");
366378
if (result == 0)
367379
{
368-
FILE* global_file = GetGlobalFile();
369-
fputs(sCommonHeaderOutputHeaders, source_file);
370380
fputs(sSwapchainSourceCode, source_file);
371381

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

684694
pfn_loader_.AddMethodName("vkGetSwapchainImagesKHR");
685695

696+
uint32_t captured_swapchain_count = 0;
697+
if (pSwapchainImageCount->GetPointer() != nullptr)
698+
{
699+
captured_swapchain_count = *pSwapchainImageCount->GetPointer();
700+
}
701+
686702
fprintf(file,
687-
"\tVK_CALL_CHECK(loaded_vkGetSwapchainImagesKHR(%s, %s, &%s, %s), %s);\n",
703+
"\tVK_CALL_CHECK(toCppGetSwapchainImagesKHR(%s, %s, %u, &%s, %s), %s);\n",
688704
GetHandle(device).c_str(),
689705
handle_id_map_[swapchain].c_str(),
706+
captured_swapchain_count,
690707
ptr_map_[pSwapchainImageCount].c_str(),
691708
swapchain_images_var_name.c_str(),
692709
util::ToString<VkResult>(returnValue).c_str());
@@ -1792,30 +1809,18 @@ void VulkanCppConsumerBase::Generate_vkAcquireNextImageKHR(VkResult
17921809
AddKnownVariables("uint32_t", image_index_var_name);
17931810

17941811
pfn_loader_.AddMethodName("vkAcquireNextImageKHR");
1795-
if (returnValue == VK_SUCCESS)
1796-
{
1797-
fprintf(file,
1798-
"\twhile (loaded_vkAcquireNextImageKHR(%s, %s, %" PRIu64
1799-
"UL, %s, %s, &%s) != VK_SUCCESS) { usleep(5000); };\n",
1800-
GetHandle(device).c_str(),
1801-
GetHandle(swapchain).c_str(),
1802-
timeout,
1803-
GetHandle(semaphore).c_str(),
1804-
GetHandle(fence).c_str(),
1805-
image_index_var_name.c_str());
1806-
}
1807-
else
1808-
{
1809-
fprintf(file,
1810-
"\tVK_CALL_CHECK(loaded_vkAcquireNextImageKHR(%s, %s, %" PRIu64 "UL, %s, %s, &%s), %s);\n",
1811-
GetHandle(device).c_str(),
1812-
GetHandle(swapchain).c_str(),
1813-
timeout,
1814-
GetHandle(semaphore).c_str(),
1815-
GetHandle(fence).c_str(),
1816-
image_index_var_name.c_str(),
1817-
util::ToString<VkResult>(returnValue).c_str());
1818-
}
1812+
fprintf(file,
1813+
"\tVK_CALL_CHECK(toCppAcquireNextImageKHR(static_cast<VkResult>(0x%08x), %s, %s, %" PRIu64
1814+
"UL, %s, %s, %u, &%s), %s);\n",
1815+
returnValue,
1816+
GetHandle(device).c_str(),
1817+
GetHandle(swapchain).c_str(),
1818+
timeout,
1819+
GetHandle(semaphore).c_str(),
1820+
GetHandle(fence).c_str(),
1821+
(*pImageIndex->GetPointer()),
1822+
image_index_var_name.c_str(),
1823+
util::ToString<VkResult>(returnValue).c_str());
18191824
}
18201825

18211826
void VulkanCppConsumerBase::Generate_vkAcquireNextImage2KHR(
@@ -3283,6 +3288,25 @@ void VulkanCppConsumerBase::ProcessSetOpaqueAddressCommand(format::HandleId devi
32833288
}
32843289
}
32853290

3291+
void VulkanCppConsumerBase::Generate_vkGetDeviceQueue(format::HandleId device,
3292+
uint32_t queueFamilyIndex,
3293+
uint32_t queueIndex,
3294+
HandlePointerDecoder<VkQueue>* pQueue)
3295+
{
3296+
FILE* file = GetFrameFile();
3297+
fprintf(file, "\t{\n");
3298+
std::string pqueue_name = "pQueue_" + std::to_string(this->GetNextId(VK_OBJECT_TYPE_QUEUE));
3299+
AddKnownVariables("VkQueue", pqueue_name, pQueue->GetPointer());
3300+
this->AddHandles(pqueue_name, pQueue->GetPointer());
3301+
fprintf(file,
3302+
"\t\ttoCppGetDeviceQueue(%s, %u, %u, &%s);\n",
3303+
this->GetHandle(device).c_str(),
3304+
queueFamilyIndex,
3305+
queueIndex,
3306+
pqueue_name.c_str());
3307+
fprintf(file, "\t}\n");
3308+
}
3309+
32863310
void VulkanCppConsumerBase::Generate_vkGetAndroidHardwareBufferPropertiesANDROID(
32873311
VkResult returnValue,
32883312
format::HandleId device,
@@ -3528,20 +3552,18 @@ void VulkanCppConsumerBase::Generate_vkQueuePresentKHR(VkResult
35283552
{
35293553
FILE* file = GetFrameFile();
35303554
fprintf(file, "\t{\n");
3531-
// queue
3532-
// pPresentInfo
3533-
std::stringstream stream_ppresent_info;
3534-
std::string ppresent_info_struct = GenerateStruct_VkPresentInfoKHR(stream_ppresent_info,
3535-
pPresentInfo->GetPointer(),
3536-
pPresentInfo->GetMetaStructPointer(),
3537-
imported_semaphores_,
3538-
*this);
3539-
fprintf(file, "%s", stream_ppresent_info.str().c_str());
3555+
std::stringstream stream_present_info;
3556+
std::string present_info_struct = GenerateStruct_VkPresentInfoKHR(stream_present_info,
3557+
pPresentInfo->GetPointer(),
3558+
pPresentInfo->GetMetaStructPointer(),
3559+
imported_semaphores_,
3560+
*this);
3561+
fprintf(file, "%s", stream_present_info.str().c_str());
35403562
pfn_loader_.AddMethodName("vkQueuePresentKHR");
35413563
fprintf(file,
3542-
"\t\tVK_CALL_CHECK(loaded_vkQueuePresentKHR(%s, &%s), %s);\n",
3564+
"\t\tVK_CALL_CHECK(toCppQueuePresentKHR(%s, &%s), %s);\n",
35433565
this->GetHandle(queue).c_str(),
3544-
ppresent_info_struct.c_str(),
3566+
present_info_struct.c_str(),
35453567
util::ToString<VkResult>(returnValue).c_str());
35463568
fprintf(file, "\t}\n");
35473569
}

framework/decode/vulkan_cpp_consumer_base.h

+7
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class VulkanCppConsumerBase : public VulkanConsumer
133133
void SetWindowSize(uint32_t appWindowWidth, uint32_t appWindowHeight);
134134
void SetMaxCommandLimit(uint32_t max) { max_command_limit_ = max; }
135135

136+
void DisableVirtualSwapchain() { enable_virtual_swapchain_ = false; }
137+
136138
uint32_t GetNextId();
137139
uint32_t GetNextId(VkObjectType object_type);
138140

@@ -416,6 +418,10 @@ class VulkanCppConsumerBase : public VulkanConsumer
416418
format::HandleId device,
417419
uint64_t buffer,
418420
StructPointerDecoder<Decoded_VkAndroidHardwareBufferPropertiesANDROID>* pProperties);
421+
void Generate_vkGetDeviceQueue(format::HandleId device,
422+
uint32_t queueFamilyIndex,
423+
uint32_t queueIndex,
424+
HandlePointerDecoder<VkQueue>* pQueue);
419425
void Generate_vkGetMemoryAndroidHardwareBufferANDROID(
420426
VkResult returnValue,
421427
format::HandleId device,
@@ -680,6 +686,7 @@ class VulkanCppConsumerBase : public VulkanConsumer
680686
size_t size;
681687
};
682688

689+
bool enable_virtual_swapchain_{ true };
683690
uint32_t frame_number_;
684691
uint32_t frame_split_number_;
685692
uint32_t frame_api_call_number_;

0 commit comments

Comments
 (0)