1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-04-01 09:25:24 +02:00

[dxvk] Use clearRenderTarget for discards as well

This commit is contained in:
Philip Rebohle 2025-03-21 03:03:33 +01:00
parent 496091815e
commit 31529b8bab
4 changed files with 24 additions and 64 deletions

View File

@ -203,11 +203,11 @@ namespace dxvk {
} }
} }
// Since we don't handle SRVs here, we can assume that the if (rtv || dsv) {
// view covers all aspects of the underlying resource. EmitCs([cView = view] (DxvkContext* ctx) {
EmitCs([cView = view] (DxvkContext* ctx) { ctx->clearRenderTarget(cView, 0, VkClearValue(), cView->info().aspects);
ctx->discardImageView(cView, cView->formatInfo()->aspectMask); });
}); }
} }
@ -430,10 +430,9 @@ namespace dxvk {
cClearValue = color, cClearValue = color,
cImageView = std::move(view) cImageView = std::move(view)
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->clearRenderTarget( ctx->clearRenderTarget(cImageView,
cImageView,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT,
cClearValue); cClearValue, 0u);
}); });
} }
@ -667,10 +666,8 @@ namespace dxvk {
cAspectMask = aspectMask, cAspectMask = aspectMask,
cImageView = dsv->GetImageView() cImageView = dsv->GetImageView()
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->clearRenderTarget( ctx->clearRenderTarget(cImageView,
cImageView, cAspectMask, cClearValue, 0u);
cAspectMask,
cClearValue);
}); });
} }
@ -795,17 +792,10 @@ namespace dxvk {
bool isFullSize = cImageView->mipLevelExtent(0) == cAreaExtent; bool isFullSize = cImageView->mipLevelExtent(0) == cAreaExtent;
if ((cImageView->info().usage & rtUsage) && isFullSize) { if ((cImageView->info().usage & rtUsage) && isFullSize) {
ctx->clearRenderTarget( ctx->clearRenderTarget(cImageView, cClearAspect, cClearValue, 0u);
cImageView,
cClearAspect,
cClearValue);
} else { } else {
ctx->clearImageView( ctx->clearImageView(cImageView, cAreaOffset, cAreaExtent,
cImageView, cClearAspect, cClearValue);
cAreaOffset,
cAreaExtent,
cClearAspect,
cClearValue);
} }
}); });
} }

View File

@ -1552,7 +1552,7 @@ namespace dxvk {
Rc<DxvkImageView> view = cImage->createView(viewKey); Rc<DxvkImageView> view = cImage->createView(viewKey);
if (cOffset == VkOffset3D() && cExtent == cImage->mipLevelExtent(viewKey.mipIndex)) { if (cOffset == VkOffset3D() && cExtent == cImage->mipLevelExtent(viewKey.mipIndex)) {
ctx->clearRenderTarget(view, cSubresource.aspectMask, cClearValue); ctx->clearRenderTarget(view, cSubresource.aspectMask, cClearValue, 0u);
} else { } else {
ctx->clearImageView(view, cOffset, cExtent, ctx->clearImageView(view, cOffset, cExtent,
cSubresource.aspectMask, cClearValue); cSubresource.aspectMask, cClearValue);
@ -1913,10 +1913,8 @@ namespace dxvk {
cAspectMask = aspectMask, cAspectMask = aspectMask,
cImageView = imageView cImageView = imageView
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->clearRenderTarget( ctx->clearRenderTarget(cImageView,
cImageView, cAspectMask, cClearValue, 0u);
cAspectMask,
cClearValue);
}); });
} }
else { else {

View File

@ -378,7 +378,8 @@ namespace dxvk {
void DxvkContext::clearRenderTarget( void DxvkContext::clearRenderTarget(
const Rc<DxvkImageView>& imageView, const Rc<DxvkImageView>& imageView,
VkImageAspectFlags clearAspects, VkImageAspectFlags clearAspects,
VkClearValue clearValue) { VkClearValue clearValue,
VkImageAspectFlags discardAspects) {
// Make sure the color components are ordered correctly // Make sure the color components are ordered correctly
if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT) { if (clearAspects & VK_IMAGE_ASPECT_COLOR_BIT) {
clearValue.color = util::swizzleClearColor(clearValue.color, clearValue.color = util::swizzleClearColor(clearValue.color,
@ -413,6 +414,9 @@ namespace dxvk {
// next draw if there is no reason to interrupt the render pass. This is // next draw if there is no reason to interrupt the render pass. This is
// useful to adjust store ops for tilers, and ensures that pending resolves // useful to adjust store ops for tilers, and ensures that pending resolves
// are handled correctly. // are handled correctly.
if (discardAspects)
this->deferDiscard(imageView, discardAspects);
if (clearAspects) if (clearAspects)
this->deferClear(imageView, clearAspects, clearValue); this->deferClear(imageView, clearAspects, clearValue);
@ -866,27 +870,6 @@ namespace dxvk {
} }
void DxvkContext::discardImageView(
const Rc<DxvkImageView>& imageView,
VkImageAspectFlags discardAspects) {
VkImageUsageFlags viewUsage = imageView->info().usage;
if (!(viewUsage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)))
return;
// Perform store op optimization on bound render targets
if (m_flags.test(DxvkContextFlag::GpRenderPassBound)) {
VkImageSubresourceRange subresource = imageView->imageSubresources();
subresource.aspectMask &= discardAspects;
discardRenderTarget(*imageView->image(), subresource);
}
// Perform load op optimization on subsequent render passes
deferDiscard(imageView, discardAspects);
}
void DxvkContext::discardImage( void DxvkContext::discardImage(
const Rc<DxvkImage>& image) { const Rc<DxvkImage>& image) {
VkImageUsageFlags imageUsage = image->info().usage; VkImageUsageFlags imageUsage = image->info().usage;

View File

@ -500,12 +500,14 @@ namespace dxvk {
* \param [in] imageView Render target view to clear * \param [in] imageView Render target view to clear
* \param [in] clearAspects Image aspects to clear * \param [in] clearAspects Image aspects to clear
* \param [in] clearValue The clear value * \param [in] clearValue The clear value
* \param [in] discardAspects Image aspects to discard
*/ */
void clearRenderTarget( void clearRenderTarget(
const Rc<DxvkImageView>& imageView, const Rc<DxvkImageView>& imageView,
VkImageAspectFlags clearAspects, VkImageAspectFlags clearAspects,
VkClearValue clearValue); VkClearValue clearValue,
VkImageAspectFlags discardAspects);
/** /**
* \brief Clears an image view * \brief Clears an image view
* *
@ -705,19 +707,6 @@ namespace dxvk {
const uint32_t* pages, const uint32_t* pages,
const Rc<DxvkBuffer>& srcBuffer, const Rc<DxvkBuffer>& srcBuffer,
VkDeviceSize srcOffset); VkDeviceSize srcOffset);
/**
* \brief Discards contents of an image view
*
* Discards the current contents of the image
* and performs a fast layout transition. This
* may improve performance in some cases.
* \param [in] imageView View to discard
* \param [in] discardAspects Image aspects to discard
*/
void discardImageView(
const Rc<DxvkImageView>& imageView,
VkImageAspectFlags discardAspects);
/** /**
* \brief Discards contents of an image * \brief Discards contents of an image