Skip to content
Snippets Groups Projects
Verified Commit a49c1c0c authored by Tobias Frisch's avatar Tobias Frisch
Browse files

[#39] Added documentation and typedefs for function types

parent 81e274ed
No related branches found
No related tags found
1 merge request!31Resolve "Command Submit Interface"
Pipeline #25058 passed
...@@ -29,6 +29,9 @@ namespace vkcv ...@@ -29,6 +29,9 @@ namespace vkcv
std::vector<vk::Semaphore> waitSemaphores; std::vector<vk::Semaphore> waitSemaphores;
std::vector<vk::Semaphore> signalSemaphores; std::vector<vk::Semaphore> signalSemaphores;
}; };
typedef std::function<void(const vk::CommandBuffer& cmdBuffer)> RecordCommandFunction;
typedef std::function<void(void)> FinishCommandFunction;
class Core final class Core final
{ {
...@@ -179,9 +182,15 @@ namespace vkcv ...@@ -179,9 +182,15 @@ namespace vkcv
vk::Format getSwapchainImageFormat(); vk::Format getSwapchainImageFormat();
void submitCommands( /**
const SubmitInfo &submitInfo, * Submit a command buffer to any queue of selected type. The recording can be customized by a
const std::function<void(vk::CommandBuffer cmdBuffer)> recording, * custom record-command-function. If the command submission has finished, an optional finish-function
const std::function<void()> finishCallback); * will be called.
*
* @param submitInfo Submit information
* @param record Record-command-function
* @param finish Finish-command-function or nullptr
*/
void submitCommands(const SubmitInfo &submitInfo, const RecordCommandFunction& record, const FinishCommandFunction& finish);
}; };
} }
...@@ -173,7 +173,7 @@ namespace vkcv ...@@ -173,7 +173,7 @@ namespace vkcv
SubmitInfo submitInfo; SubmitInfo submitInfo;
submitInfo.queueType = QueueType::Graphics; submitInfo.queueType = QueueType::Graphics;
submitInfo.signalSemaphores = { m_SyncResources.renderFinished }; submitInfo.signalSemaphores = { m_SyncResources.renderFinished };
submitCommands(submitInfo, [renderpass, renderArea, imageView, framebuffer, pipeline](const vk::CommandBuffer cmdBuffer) { submitCommands(submitInfo, [renderpass, renderArea, imageView, framebuffer, pipeline](const vk::CommandBuffer& cmdBuffer) {
const std::array<float, 4> clearColor = { 0.f, 0.f, 0.f, 1.f }; const std::array<float, 4> clearColor = { 0.f, 0.f, 0.f, 1.f };
const vk::ClearValue clearValues(clearColor); const vk::ClearValue clearValues(clearColor);
...@@ -222,12 +222,9 @@ namespace vkcv ...@@ -222,12 +222,9 @@ namespace vkcv
/* boilerplate for #34 */ /* boilerplate for #34 */
std::cout << "Resized to : " << width << " , " << height << std::endl; std::cout << "Resized to : " << width << " , " << height << std::endl;
} }
void Core::submitCommands( void Core::submitCommands(const SubmitInfo &submitInfo, const RecordCommandFunction& record, const FinishCommandFunction& finish)
const SubmitInfo& submitInfo, {
const std::function<void(vk::CommandBuffer cmdBuffer)> recording,
const std::function<void()> finishCallback) {
const vk::Device& device = m_Context.getDevice(); const vk::Device& device = m_Context.getDevice();
const vkcv::Queue queue = getQueueForSubmit(submitInfo.queueType, m_Context.getQueueManager()); const vkcv::Queue queue = getQueueForSubmit(submitInfo.queueType, m_Context.getQueueManager());
...@@ -235,16 +232,18 @@ namespace vkcv ...@@ -235,16 +232,18 @@ namespace vkcv
const vk::CommandBuffer cmdBuffer = allocateCommandBuffer(device, cmdPool); const vk::CommandBuffer cmdBuffer = allocateCommandBuffer(device, cmdPool);
beginCommandBuffer(cmdBuffer, vk::CommandBufferUsageFlagBits::eOneTimeSubmit); beginCommandBuffer(cmdBuffer, vk::CommandBufferUsageFlagBits::eOneTimeSubmit);
recording(cmdBuffer); record(cmdBuffer);
cmdBuffer.end(); cmdBuffer.end();
const vk::Fence waitFence = createFence(device); const vk::Fence waitFence = createFence(device);
submitCommandBufferToQueue(queue.handle, cmdBuffer, waitFence, submitInfo.waitSemaphores, submitInfo.signalSemaphores); submitCommandBufferToQueue(queue.handle, cmdBuffer, waitFence, submitInfo.waitSemaphores, submitInfo.signalSemaphores);
waitForFence(device, waitFence); waitForFence(device, waitFence);
device.destroyFence(waitFence); device.destroyFence(waitFence);
if (finishCallback) {
finishCallback();
}
device.freeCommandBuffers(cmdPool, cmdBuffer); device.freeCommandBuffers(cmdPool, cmdBuffer);
if (finish) {
finish();
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment