mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-05-10 19:21:42 +00:00
feat(bindless): Implement transition command buffer
This commit is contained in:
parent
63249dde7a
commit
cb4992a5dc
3 changed files with 70 additions and 7 deletions
|
|
@ -75,7 +75,7 @@ Context::Context(
|
|||
{ width, height },
|
||||
flowScale,
|
||||
performanceMode,
|
||||
false /* TODO: HDR */
|
||||
false
|
||||
};
|
||||
|
||||
this->m_priv = std::make_unique<priv::Context>(priv::Context {
|
||||
|
|
@ -158,7 +158,11 @@ void Context::dispatch(uint32_t total) {
|
|||
// Dispatch main passes
|
||||
uint64_t prevInternal{};
|
||||
for (uint32_t i = 0; i < total; i++) {
|
||||
const auto& transCmdbuf{ctx.pipeline.getCmdbufs().at(0)}; // FIXME: replace with actual buf
|
||||
const auto& transCmdbuf{ctx.pipeline.buildTransCmdbuf(
|
||||
vk.dld, *vk.device,
|
||||
mapped->iteration,
|
||||
i, total
|
||||
)};
|
||||
|
||||
// Transition command buffer to next timestamp
|
||||
if (i == 0) {
|
||||
|
|
@ -179,7 +183,7 @@ void Context::dispatch(uint32_t total) {
|
|||
.pWaitSemaphores = i == 0 ? &*internal.first : &*sync.first,
|
||||
.pWaitDstStageMask = &waitStage,
|
||||
.commandBufferCount = 1,
|
||||
.pCommandBuffers = &*transCmdbuf,
|
||||
.pCommandBuffers = &transCmdbuf,
|
||||
.signalSemaphoreCount = 1,
|
||||
.pSignalSemaphores = &*internal.first
|
||||
}},
|
||||
|
|
|
|||
|
|
@ -805,3 +805,45 @@ Pipeline::Pipeline(
|
|||
LOG_DEBUG(" Recorded command buffers for pipeline execution")
|
||||
LOG_DEBUG("Finished building pipeline")
|
||||
}
|
||||
|
||||
vk::CommandBuffer Pipeline::buildTransCmdbuf(
|
||||
const vk::detail::DispatchLoaderDynamic& dld,
|
||||
const vk::Device& device,
|
||||
uint32_t iteration,
|
||||
uint32_t index,
|
||||
uint32_t total
|
||||
) {
|
||||
const bool persist{total > 8};
|
||||
const uint64_t key{persist ? ((static_cast<uint64_t>(index) << 32) | total) : index};
|
||||
|
||||
if (persist && this->m_transCmdbufs.contains(key))
|
||||
return *this->m_transCmdbufs.at(key);
|
||||
|
||||
auto& cmdbuf{this->m_transCmdbufs[key]};
|
||||
cmdbuf = vkhelper::createCommandBuffer(
|
||||
dld,
|
||||
device,
|
||||
*this->m_pool
|
||||
);
|
||||
|
||||
cmdbuf->begin({
|
||||
.flags = persist ? vk::CommandBufferUsageFlagBits::eSimultaneousUse :
|
||||
vk::CommandBufferUsageFlagBits::eOneTimeSubmit
|
||||
}, dld);
|
||||
|
||||
const UniformBuffer buf{
|
||||
.timestamp = static_cast<float>(index + 1) / static_cast<float>(total + 1),
|
||||
.iteration = iteration
|
||||
};
|
||||
cmdbuf->updateBuffer(
|
||||
*this->m_descriptorSet.buffer.first,
|
||||
0,
|
||||
4,
|
||||
static_cast<const void*>(&buf.timestamp),
|
||||
dld
|
||||
);
|
||||
|
||||
cmdbuf->end(dld);
|
||||
|
||||
return *cmdbuf;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
namespace lsfgvk::pipeline {
|
||||
|
||||
// TODO: Improve API design
|
||||
|
||||
/// Handle to an external image
|
||||
struct ExternalImage {
|
||||
/// Image Extent
|
||||
|
|
@ -60,7 +58,7 @@ namespace lsfgvk::pipeline {
|
|||
/// Create a new pipeline
|
||||
///
|
||||
/// @param dld Vulkan dispatch loader
|
||||
/// @param dev Vulkan device
|
||||
/// @param device Vulkan device
|
||||
/// @param physdev Vulkan physical device
|
||||
/// @param queue Vulkan compute queue
|
||||
/// @param queueFamilyIndex Compute queue family index
|
||||
|
|
@ -74,7 +72,7 @@ namespace lsfgvk::pipeline {
|
|||
///
|
||||
explicit Pipeline(
|
||||
const vk::detail::DispatchLoaderDynamic& dld,
|
||||
const vk::Device& dev,
|
||||
const vk::Device& device,
|
||||
const vk::PhysicalDevice& physdev,
|
||||
const vk::Queue& queue,
|
||||
uint32_t queueFamilyIndex,
|
||||
|
|
@ -118,6 +116,24 @@ namespace lsfgvk::pipeline {
|
|||
return this->m_cmdbufs;
|
||||
}
|
||||
|
||||
///
|
||||
/// Build a transition command buffer
|
||||
///
|
||||
/// @param dld Vulkan dispatch loader
|
||||
/// @param device Vulkan device
|
||||
/// @param iteration Current iteration
|
||||
/// @param index Index of the iteration
|
||||
/// @param total Total iterations
|
||||
/// @return Command buffer handle
|
||||
///
|
||||
vk::CommandBuffer buildTransCmdbuf(
|
||||
const vk::detail::DispatchLoaderDynamic& dld,
|
||||
const vk::Device& device,
|
||||
uint32_t iteration,
|
||||
uint32_t index,
|
||||
uint32_t total
|
||||
);
|
||||
|
||||
private:
|
||||
/// Vulkan descriptor set & pipeline layout
|
||||
struct Layout {
|
||||
|
|
@ -203,6 +219,7 @@ namespace lsfgvk::pipeline {
|
|||
|
||||
vk::UniqueCommandPool m_pool;
|
||||
std::vector<vk::UniqueCommandBuffer> m_cmdbufs;
|
||||
std::unordered_map<uint64_t, vk::UniqueCommandBuffer> m_transCmdbufs;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue