Skip clears if attachments are invalid

This commit is contained in:
Billy Laws 2022-09-29 20:53:41 +01:00
parent 01a5e95ce1
commit af1b4ca4f8

View File

@ -135,48 +135,52 @@ namespace skyline::gpu::interconnect::maxwell3d {
std::shared_ptr<TextureView> depthStencilView{}; std::shared_ptr<TextureView> depthStencilView{};
if (clearSurface.rEnable || clearSurface.gEnable || clearSurface.bEnable || clearSurface.aEnable) { if (clearSurface.rEnable || clearSurface.gEnable || clearSurface.bEnable || clearSurface.aEnable) {
colorView = activeState.GetColorRenderTargetForClear(ctx, clearSurface.mrtSelect); if (auto view{activeState.GetColorRenderTargetForClear(ctx, clearSurface.mrtSelect)}) {
ctx.executor.AttachTexture(&*colorView); ctx.executor.AttachTexture(&*view);
if (!(clearSurface.rEnable && clearSurface.gEnable && clearSurface.bEnable && clearSurface.aEnable)) if (!(clearSurface.rEnable && clearSurface.gEnable && clearSurface.bEnable && clearSurface.aEnable))
Logger::Warn("Partial clears are unimplemented! Performing full clear instead"); Logger::Warn("Partial clears are unimplemented! Performing full clear instead");
if (!(colorView->range.aspectMask & vk::ImageAspectFlagBits::eColor)) { if (!(view->range.aspectMask & vk::ImageAspectFlagBits::eColor)) {
Logger::Warn("Colour RT used in clear lacks colour aspect"); // TODO: Drop this check after texman rework Logger::Warn("Colour RT used in clear lacks colour aspect"); // TODO: Drop this check after texman rework
return; return;
} }
if (needsAttachmentClearCmd(colorView)) { if (needsAttachmentClearCmd(view)) {
clearAttachments.push_back({ .aspectMask = colorView->range.aspectMask, .clearValue = {clearEngineRegisters.colorClearValue} }); clearAttachments.push_back({.aspectMask = view->range.aspectMask, .clearValue = {clearEngineRegisters.colorClearValue}});
colorView = view;
} else { } else {
ctx.executor.AddClearColorSubpass(&*colorView, clearEngineRegisters.colorClearValue); ctx.executor.AddClearColorSubpass(&*view, clearEngineRegisters.colorClearValue);
colorView = {}; // Will avoid adding as colour RT }
} }
} }
if (clearSurface.stencilEnable || clearSurface.zEnable) { if (clearSurface.stencilEnable || clearSurface.zEnable) {
depthStencilView = activeState.GetDepthRenderTargetForClear(ctx); if (auto view{activeState.GetDepthRenderTargetForClear(ctx)}) {
ctx.executor.AttachTexture(&*depthStencilView); ctx.executor.AttachTexture(&*view);
bool viewHasDepth{depthStencilView->range.aspectMask & vk::ImageAspectFlagBits::eDepth}, viewHasStencil{depthStencilView->range.aspectMask & vk::ImageAspectFlagBits::eStencil}; bool viewHasDepth{view->range.aspectMask & vk::ImageAspectFlagBits::eDepth}, viewHasStencil{view->range.aspectMask & vk::ImageAspectFlagBits::eStencil};
vk::ClearDepthStencilValue clearValue{ vk::ClearDepthStencilValue clearValue{
.depth = clearEngineRegisters.depthClearValue, .depth = clearEngineRegisters.depthClearValue,
.stencil = clearEngineRegisters.stencilClearValue .stencil = clearEngineRegisters.stencilClearValue
}; };
if (!viewHasDepth && !viewHasStencil) { if (!viewHasDepth && !viewHasStencil) {
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(depthStencilView) || (!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) || (!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
clearAttachments.push_back({ .aspectMask = depthStencilView->range.aspectMask, .clearValue = clearValue }); clearAttachments.push_back({.aspectMask = view->range.aspectMask, .clearValue = clearValue});
depthStencilView = view;
} else { } else {
ctx.executor.AddClearDepthStencilSubpass(&*depthStencilView, clearValue); ctx.executor.AddClearDepthStencilSubpass(&*view, clearValue);
depthStencilView = {}; // Will avoid adding as depth-stencil RT
} }
} }
}
if (clearAttachments.empty())
return;
// Always use surfaceClip for render area since it's more likely to match the renderArea of draws and avoid an RP break // Always use surfaceClip for render area since it's more likely to match the renderArea of draws and avoid an RP break
const auto &surfaceClip{clearEngineRegisters.surfaceClip}; const auto &surfaceClip{clearEngineRegisters.surfaceClip};