Use semaphore to sync same chain steps too (sync slow texture compression)

This commit is contained in:
mittorn 2024-11-12 10:48:47 +03:00
parent 55e791419e
commit 186e435255

View file

@ -262,18 +262,22 @@ struct ComputeApplication {
}
void runCommandBuffer(int chidx, int frameNum) {
$Sc submitInfo = SubmitInfo(chain[chidx].decomposeCommandBuffer);
waitFence(chidx);
//waitFence(chidx);
vkResetFences(dev.device, 1, &chain[chidx].decomposeFence);
//vkResetFences(dev.device, 1, &chain[chidx].compressFence);
VK_CHECK_RESULT(vkQueueSubmit(dev.defaultQueue, 1, &submitInfo, chain[chidx].decomposeFence));
CallWith($Sc(SubmitInfo(chain[chidx].decomposeCommandBuffer,$(waitSemaphoreCount),
$(pWaitSemaphores) = &compressSemaphore,
$(pWaitDstStageMask) &= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT),
$M(VkTimelineSemaphoreSubmitInfoKHR{VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR}, $(waitSemaphoreValueCount),
$(pWaitSemaphoreValues) &= (uint64_t)frameNum)),
vkQueueSubmit(dev.defaultQueue, 1, &ref, chain[chidx].decomposeFence));
//VK_CHECK_RESULT(vkWaitForFences(dev.device, 1, &chain[chidx].decomposeFence, VK_TRUE, 100000000000));
//$M(VkTimelineSemaphoreSubmitInfoKHR{VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR}, $(signalSemaphoreValueCount), $(pSignalSemaphoreValues) &= (uint64_t)frameNum);
CallWith($Sc(
SubmitInfo(chain[chidx].compressCommandBuffer, $(signalSemaphoreCount),
$(pSignalSemaphores) = &compressSemaphore),
$M(VkTimelineSemaphoreSubmitInfoKHR{VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR}, $(signalSemaphoreValueCount),
$(pSignalSemaphoreValues) &= (uint64_t)frameNum)
$(pSignalSemaphoreValues) &= (uint64_t)frameNum + CHAIN_SIZE)
)
,vkQueueSubmit(dev.defaultQueue, 1, &ref, NULL));// 1, &ref, chain[chidx].compressFence));
chain[chidx].running = true;
@ -290,7 +294,9 @@ struct ComputeApplication {
{
int chidx = frameNum & 3;
//VK_CHECK_RESULT(vkWaitForFences(dev.device, 1, &chain[chidx].compressFence, VK_TRUE, 100000000000));
CallWith($M(VkSemaphoreWaitInfoKHR{VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO_KHR}, $(pSemaphores) = &compressSemaphore, $(semaphoreCount), $(pValues) &= (uint64_t)frameNum ),
CallWith($M(VkSemaphoreWaitInfoKHR{VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO_KHR}, $(semaphoreCount),
$(pSemaphores) = &compressSemaphore,
$(pValues) &= (uint64_t)frameNum + CHAIN_SIZE ),
pvkWaitSemaphoresKHR(dev.device,&ref, 100000000000));
#if 1
@ -409,7 +415,12 @@ struct ComputeApplication {
dev.FlushCommandBuffer(b, dev.defaultQueue);
enc.Setup(drm_fd, WIDTH/2, HEIGHT/2, filename, fd, &mod, &size, &offset, &pitch1, &pitch2, modifiers, count, p010);
CallWith($Sc(VkSemaphoreCreateInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO}, $M(VkSemaphoreTypeCreateInfoKHR{VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO_KHR},$(semaphoreType) = VK_SEMAPHORE_TYPE_TIMELINE_KHR)), vkCreateSemaphore(dev.device, &ref, NULL, &compressSemaphore));
CallWith($Sc(
VkSemaphoreCreateInfo{VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO},
$M(VkSemaphoreTypeCreateInfoKHR{VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO_KHR},
$(semaphoreType) = VK_SEMAPHORE_TYPE_TIMELINE_KHR,
$(initialValue) = CHAIN_SIZE)
), vkCreateSemaphore(dev.device, &ref, NULL, &compressSemaphore));
for(int i = 0; i < CHAIN_SIZE; i++)
{
dev.CreateAndMap(chain[i].uboBuf, sizeof(UBO));
@ -442,9 +453,9 @@ struct ComputeApplication {
int chidx = frameNum & 3;
// Finally, run the recorded command buffer.
runCommandBuffer(chidx, frameNum);
#ifndef SKIP_FENCE_SYNC
//#ifndef SKIP_FENCE_SYNC
waitFence(chidx);
#endif
//#endif
//recorder_frame4(r, chidx);
if(frameNum == 1)