Skip to content

Commit

Permalink
vulkan: Fix multipass RTT in OIT mode
Browse files Browse the repository at this point in the history
Use correct temp attachment depending on pass count. Keep attachment
index to bind the correct one before final subpass.
Use correct initial layout for OP+PT attachment 1 (was eUndefined) when
creating the RTT render pass.
Fixes Alone in the Dark cutscenes.
Issue #1609

Recreate RTT attachments if switching CopyToVRAM on/off.
  • Loading branch information
flyinghead committed Aug 24, 2024
1 parent 244bb72 commit 7a27a43
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 9 additions & 3 deletions core/rend/vulkan/oit/oit_drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ void OITDrawer::UploadMainBuffer(const OITDescriptorSets::VertexShaderUniforms&
vk::Framebuffer OITTextureDrawer::getFramebuffer(int renderPass, int renderPassCount)
{
if (renderPass < renderPassCount - 1)
return *tempFramebuffers[(renderPassCount - 1 - renderPass) % 2];
else
{
framebufferIndex = (renderPassCount - renderPass) % 2;
return *tempFramebuffers[framebufferIndex];
}
else {
framebufferIndex = 0;
return *framebuffer;
}
}

bool OITDrawer::Draw(const Texture *fogTexture, const Texture *paletteTexture)
Expand Down Expand Up @@ -467,10 +472,11 @@ void OITDrawer::MakeBuffers(int width, int height, vk::ImageUsageFlags colorUsag
{
oitBuffers->Init(width, height);

if (width <= maxWidth && height <= maxHeight)
if (width <= maxWidth && height <= maxHeight && colorUsage == currentBufferUsage)
return;
maxWidth = std::max(maxWidth, width);
maxHeight = std::max(maxHeight, height);
currentBufferUsage = colorUsage;

for (auto& framebuffer : tempFramebuffers) {
if (framebuffer)
Expand Down
6 changes: 3 additions & 3 deletions core/rend/vulkan/oit/oit_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class OITDrawer : public BaseDrawer

void MakeBuffers(int width, int height, vk::ImageUsageFlags colorUsage = {});
virtual vk::Framebuffer getFramebuffer(int renderPass, int renderPassCount) = 0;
virtual int getFramebufferIndex() { return 0; }
int getFramebufferIndex() { return framebufferIndex; }

vk::Rect2D viewport;
std::array<std::unique_ptr<FramebufferAttachment>, 2> colorAttachments;
Expand All @@ -92,6 +92,7 @@ class OITDrawer : public BaseDrawer
std::vector<bool> clearNeeded;
int maxWidth = 0;
int maxHeight = 0;
int framebufferIndex = 0;

private:
void DrawPoly(const vk::CommandBuffer& cmdBuffer, u32 listType, bool autosort, Pass pass,
Expand Down Expand Up @@ -128,6 +129,7 @@ class OITDrawer : public BaseDrawer
OITDescriptorSets descriptorSets;
vk::Buffer curMainBuffer;
bool dithering = false;
vk::ImageUsageFlags currentBufferUsage {};
};

class OITScreenDrawer : public OITDrawer
Expand Down Expand Up @@ -186,7 +188,6 @@ class OITScreenDrawer : public OITDrawer

protected:
vk::Framebuffer getFramebuffer(int renderPass, int renderPassCount) override;
int getFramebufferIndex() override { return framebufferIndex; }

private:
void MakeFramebuffers(const vk::Extent2D& viewport);
Expand All @@ -195,7 +196,6 @@ class OITScreenDrawer : public OITDrawer
bool frameRendered = false;
float aspectRatio = 0.f;
bool frameStarted = false;
int framebufferIndex = 0;
};

class OITTextureDrawer : public OITDrawer
Expand Down
2 changes: 1 addition & 1 deletion core/rend/vulkan/oit/oit_renderpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ vk::UniqueRenderPass RenderPasses::MakeRenderPass(bool initial, bool last, bool
initial ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad,
last ? vk::AttachmentStoreOp::eDontCare : vk::AttachmentStoreOp::eStore,
vk::AttachmentLoadOp::eDontCare, vk::AttachmentStoreOp::eDontCare,
initial ? vk::ImageLayout::eUndefined : attach0.initialLayout, attach0.finalLayout),
initial ? vk::ImageLayout::eUndefined : attach0.finalLayout, attach0.finalLayout), // initial layout is eUndefined for rtt, so use final layout instead
// OP+PT depth attachment
vk::AttachmentDescription(vk::AttachmentDescriptionFlags(), GetContext()->GetDepthFormat(), vk::SampleCountFlagBits::e1,
initial ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eLoad,
Expand Down

0 comments on commit 7a27a43

Please sign in to comment.