Only clear requested aspect for depth/stencil clears

Fixes water in Skyrim (depth was being cleared when only stencil should have been)
This commit is contained in:
Billy Laws 2023-02-20 13:41:35 +00:00
parent 330f402398
commit 34fddfccba

View File

@ -182,18 +182,22 @@ namespace skyline::gpu::interconnect::maxwell3d {
ctx.executor.AttachTexture(&*view); ctx.executor.AttachTexture(&*view);
bool viewHasDepth{view->range.aspectMask & vk::ImageAspectFlagBits::eDepth}, viewHasStencil{view->range.aspectMask & vk::ImageAspectFlagBits::eStencil}; bool viewHasDepth{view->range.aspectMask & vk::ImageAspectFlagBits::eDepth}, viewHasStencil{view->range.aspectMask & vk::ImageAspectFlagBits::eStencil};
vk::ImageAspectFlags clearAspectMask{(clearSurface.zEnable ? vk::ImageAspectFlagBits::eDepth : vk::ImageAspectFlags{}) |
(clearSurface.stencilEnable ? vk::ImageAspectFlagBits::eStencil : vk::ImageAspectFlags{})};
clearAspectMask &= view->range.aspectMask;
vk::ClearDepthStencilValue clearValue{ vk::ClearDepthStencilValue clearValue{
.depth = clearEngineRegisters.depthClearValue, .depth = clearEngineRegisters.depthClearValue,
.stencil = clearEngineRegisters.stencilClearValue .stencil = clearEngineRegisters.stencilClearValue
}; };
if (!viewHasDepth && !viewHasStencil) { if (!clearAspectMask) {
Logger::Warn("Depth stencil RT used in clear lacks depth or stencil aspects"); // TODO: Drop this check after texman rework Logger::Warn("Depth stencil RT used in clear lacks depth or stencil aspects"); // TODO: Drop this check after texman rework
return; return;
} }
if (needsAttachmentClearCmd(view) || (!clearSurface.stencilEnable && viewHasStencil) || (!clearSurface.zEnable && viewHasDepth)) { // Subpass clears write to all aspects of the texture, so we can't use them when only one component is enabled if (needsAttachmentClearCmd(view) || (clearAspectMask != view->range.aspectMask)) { // Subpass clears write to all aspects of the texture, so we can't use them when only one component is enabled
clearAttachments.push_back({.aspectMask = view->range.aspectMask, .clearValue = clearValue}); clearAttachments.push_back({.aspectMask = clearAspectMask, .clearValue = clearValue});
depthStencilView = view; depthStencilView = view;
} else { } else {
ctx.executor.AddClearDepthStencilSubpass(&*view, clearValue); ctx.executor.AddClearDepthStencilSubpass(&*view, clearValue);