lsfg-vk-v3.1p: optimizing delta

This commit is contained in:
PancakeTAS 2025-07-12 19:41:30 +02:00
parent ec4be495ea
commit 2fde1bbf10
No known key found for this signature in database
3 changed files with 15 additions and 17 deletions

View file

@ -30,20 +30,19 @@ namespace LSFG::Shaders {
/// @param inImg2 Second Input image
/// @param optImg1 Optional image for non-first passes.
/// @param optImg2 Second optional image for non-first passes.
/// @param optImg3 Third optional image for non-first passes.
///
/// @throws LSFG::vulkan_error if resource creation fails.
///
Delta(Vulkan& vk, std::array<std::array<Core::Image, 2>, 3> inImgs1,
Core::Image inImg2,
std::optional<Core::Image> optImg1,
std::optional<Core::Image> optImg2,
std::optional<Core::Image> optImg3);
std::optional<Core::Image> optImg2);
///
/// Dispatch the shaderchain.
///
void Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64_t pass_idx);
void Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64_t pass_idx,
bool last);
/// Get the first output image
[[nodiscard]] const auto& getOutImage1() const { return this->outImg1; }
@ -70,7 +69,7 @@ namespace LSFG::Shaders {
std::array<std::array<Core::Image, 2>, 3> inImgs1;
Core::Image inImg2;
std::optional<Core::Image> optImg1, optImg2, optImg3;
std::optional<Core::Image> optImg1, optImg2;
std::array<Core::Image, 3> tempImgs1;
std::array<Core::Image, 2> tempImgs2;
Core::Image outImg1, outImg2;

View file

@ -48,8 +48,7 @@ Context::Context(Vulkan& vk,
this->alpha.at(6 - i).getOutImages(),
this->beta.getOutImages().at(6 - i),
(i == 4) ? std::nullopt : std::make_optional(this->gamma.at(i - 1).getOutImage()),
(i == 4) ? std::nullopt : std::make_optional(this->delta.at(i - 5).getOutImage1()),
(i == 4) ? std::nullopt : std::make_optional(this->delta.at(i - 5).getOutImage2()));
(i == 4) ? std::nullopt : std::make_optional(this->delta.at(i - 5).getOutImage1()));
}
this->generate = Shaders::Generate(vk,
this->inImg_0, this->inImg_1,
@ -105,7 +104,7 @@ void Context::present(Vulkan& vk,
for (size_t i = 0; i < 7; i++) {
this->gamma.at(i).Dispatch(buf2, this->frameIdx, pass);
if (i >= 4)
this->delta.at(i - 4).Dispatch(buf2, this->frameIdx, pass);
this->delta.at(i - 4).Dispatch(buf2, this->frameIdx, pass, i == 6);
}
this->generate.Dispatch(buf2, this->frameIdx, pass);

View file

@ -16,11 +16,9 @@ using namespace LSFG::Shaders;
Delta::Delta(Vulkan& vk, std::array<std::array<Core::Image, 2>, 3> inImgs1,
Core::Image inImg2,
std::optional<Core::Image> optImg1,
std::optional<Core::Image> optImg2,
std::optional<Core::Image> optImg3)
std::optional<Core::Image> optImg2)
: inImgs1(std::move(inImgs1)), inImg2(std::move(inImg2)),
optImg1(std::move(optImg1)), optImg2(std::move(optImg2)),
optImg3(std::move(optImg3)) {
optImg1(std::move(optImg1)), optImg2(std::move(optImg2)) {
// create resources
this->shaderModules = {{
vk.shaders.getShader(vk.device, "delta[0]",
@ -115,7 +113,7 @@ Delta::Delta(Vulkan& vk, std::array<std::array<Core::Image, 2>, 3> inImgs1,
.add(VK_DESCRIPTOR_TYPE_SAMPLER, this->samplers.at(2))
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, this->inImgs1.at((i + 2) % 3))
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, this->inImgs1.at(i % 3))
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, this->optImg1)
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)
.add(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, this->tempImgs1)
.build();
}
@ -195,13 +193,14 @@ Delta::Delta(Vulkan& vk, std::array<std::array<Core::Image, 2>, 3> inImgs1,
.add(VK_DESCRIPTOR_TYPE_SAMPLER, this->samplers.at(0))
.add(VK_DESCRIPTOR_TYPE_SAMPLER, this->samplers.at(2))
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, this->tempImgs1.at(0))
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, this->optImg3)
.add(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)
.add(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, this->outImg2)
.build();
}
}
void Delta::Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64_t pass_idx) {
void Delta::Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64_t pass_idx,
bool last) {
auto& pass = this->passes.at(pass_idx);
// first shader
@ -275,6 +274,9 @@ void Delta::Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64
pass.sixthDescriptorSet.at(frameCount % 3).bind(buf, this->pipelines.at(5));
buf.dispatch(threadsX, threadsY, 1);
if (!last)
return;
// seventh shader
Utils::BarrierBuilder(buf)
.addW2R(this->tempImgs2)
@ -299,7 +301,6 @@ void Delta::Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64
// ninth shader
Utils::BarrierBuilder(buf)
.addW2R(this->tempImgs2)
.addW2R(this->optImg3)
.addR2W(this->tempImgs1.at(0))
.addR2W(this->tempImgs1.at(1))
.build();
@ -312,7 +313,6 @@ void Delta::Dispatch(const Core::CommandBuffer& buf, uint64_t frameCount, uint64
Utils::BarrierBuilder(buf)
.addW2R(this->tempImgs1.at(0))
.addW2R(this->tempImgs1.at(1))
.addW2R(this->optImg3)
.addR2W(this->outImg2)
.build();