Skip to content

Commit

Permalink
code refine
Browse files Browse the repository at this point in the history
  • Loading branch information
K1ngst0m authored and Kingstom committed Nov 21, 2023
1 parent af4fdf8 commit 8c5517e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
22 changes: 3 additions & 19 deletions engine/api/vulkan/swapChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ Result SwapChain::acquireNextImage(Semaphore* pSemaphore, Fence* pFence)
{
APH_ASSERT(pSemaphore);
VkResult res = VK_SUCCESS;
res =
m_pDevice->getDeviceTable()->vkAcquireNextImageKHR(m_pDevice->getHandle(), getHandle(), UINT64_MAX, pSemaphore->getHandle(),
pFence ? pFence->getHandle() : VK_NULL_HANDLE, &m_imageIdx);
res = m_pDevice->getDeviceTable()->vkAcquireNextImageKHR(
m_pDevice->getHandle(), getHandle(), UINT64_MAX, pSemaphore->getHandle(),
pFence ? pFence->getHandle() : VK_NULL_HANDLE, &m_imageIdx);

if(res == VK_ERROR_OUT_OF_DATE_KHR)
{
Expand Down Expand Up @@ -230,22 +230,6 @@ void SwapChain::reCreate()
};

auto pImage = m_imagePools.allocate(m_pDevice, imageCreateInfo, handle);

{
// auto queue = m_pDevice->getQueue(QueueType::Graphics);
// auto* pPool = m_pDevice->acquireCommandPool({.queue = queue, .transient = true});
// vk::CommandBuffer* cmd = nullptr;
// APH_CHECK_RESULT(pPool->allocate(1, &cmd));
// _VR(cmd->begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT));
// cmd->transitionImageLayout(pImage, ResourceState::RESOURCE_STATE_PRESENT);
// _VR(cmd->end());
// vk::QueueSubmitInfo submitInfo{.commandBuffers = {cmd}};
// APH_CHECK_RESULT(queue->submit({submitInfo}));
// APH_CHECK_RESULT(queue->waitIdle());
// pPool->free(1, &cmd);
// APH_CHECK_RESULT(m_pDevice->releaseCommandPool(pPool));
}

m_images.push_back(pImage);
}
}
Expand Down
21 changes: 5 additions & 16 deletions engine/renderGraph/renderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void RenderGraph::build(vk::SwapChain* pSwapChain)
m_buildData.bufferBarriers.clear();
m_buildData.imageBarriers.clear();
m_buildData.frameSubmitInfos.clear();
for(auto *pass: m_declareData.passes)
for(auto* pass : m_declareData.passes)
{
m_buildData.passDependencyGraph[pass].clear();
}
Expand Down Expand Up @@ -466,20 +466,9 @@ void RenderGraph::execute(vk::Fence* pFence)

// submit && present
{
vk::Fence* frameFence = {};

if(!pFence)
{
frameFence = m_buildData.frameFence;
}
else
{
frameFence = pFence;
}
vk::Fence* frameFence = pFence ? pFence : m_buildData.frameFence;
frameFence->reset();

vk::Semaphore* presentSem = m_buildData.presentSem;

APH_CHECK_RESULT(queue->submit(m_buildData.frameSubmitInfos, frameFence));

if(m_buildData.pSwapchain)
Expand Down Expand Up @@ -522,7 +511,7 @@ void RenderGraph::execute(vk::Fence* pFence)
pCopyCmd->insertBarrier({
{
.pImage = pOutImage,
.currentState = ResourceState::CopySource,
.currentState = ResourceState::Undefined,
.newState = ResourceState::RenderTarget,
},
{
Expand All @@ -532,9 +521,9 @@ void RenderGraph::execute(vk::Fence* pFence)
},
});
},
{m_buildData.renderSem}, {presentSem});
{m_buildData.renderSem}, {m_buildData.presentSem});

APH_CHECK_RESULT(m_buildData.pSwapchain->presentImage(queue, {presentSem}));
APH_CHECK_RESULT(m_buildData.pSwapchain->presentImage(queue, {m_buildData.presentSem}));
}

if(!pFence)
Expand Down
12 changes: 1 addition & 11 deletions engine/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,8 @@ void Renderer::recordGraph(std::function<void(RenderGraph*)>&& func)
for(auto& pGraph : m_frameGraph)
{
auto taskGroup = m_taskManager.createTaskGroup("frame graph recording");
taskGroup->addTask([&pGraph, func]() {
taskGroup->addTask([this, &pGraph, func]() {
func(pGraph.get());
});
m_taskManager.submit(taskGroup);
}
m_taskManager.wait();

for(auto& pGraph : m_frameGraph)
{
auto taskGroup = m_taskManager.createTaskGroup("frame graph building");
taskGroup->addTask([&pGraph, this]() {
pGraph->build(m_pSwapChain);
});
m_taskManager.submit(taskGroup);
Expand All @@ -231,7 +222,6 @@ void Renderer::render()
{
m_frameIdx = (m_frameIdx + 1) % m_config.maxFrames;
m_frameFence[m_frameIdx]->wait();
// m_frameGraph[m_frameIdx]->build(m_pSwapChain);
m_frameGraph[m_frameIdx]->execute(m_frameFence[m_frameIdx]);
}
} // namespace aph::vk

0 comments on commit 8c5517e

Please sign in to comment.