1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 10:24:12 +01:00

[d3d11] Simplify ClearView implementation

Removes some code duplication for the no-clear-rect case.
This commit is contained in:
Philip Rebohle 2020-04-22 22:32:53 +02:00
parent b3c19ba5e8
commit 9a76645228
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -964,6 +964,9 @@ namespace dxvk {
UINT NumRects) { UINT NumRects) {
D3D10DeviceLock lock = LockContext(); D3D10DeviceLock lock = LockContext();
if (NumRects && !pRect)
return;
// ID3D11View has no methods to query the exact type of // ID3D11View has no methods to query the exact type of
// the view, so we'll have to check each possible class // the view, so we'll have to check each possible class
auto dsv = dynamic_cast<D3D11DepthStencilView*>(pView); auto dsv = dynamic_cast<D3D11DepthStencilView*>(pView);
@ -1014,14 +1017,21 @@ namespace dxvk {
VkImageAspectFlags clearAspect = formatInfo->aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT); VkImageAspectFlags clearAspect = formatInfo->aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT);
// Clear all the rectangles that are specified // Clear all the rectangles that are specified
for (uint32_t i = 0; i < NumRects; i++) { for (uint32_t i = 0; i < NumRects || i < 1; i++) {
if (pRect) {
if (pRect[i].left >= pRect[i].right if (pRect[i].left >= pRect[i].right
|| pRect[i].top >= pRect[i].bottom) || pRect[i].top >= pRect[i].bottom)
continue; continue;
}
if (bufView != nullptr) { if (bufView != nullptr) {
VkDeviceSize offset = pRect[i].left; VkDeviceSize offset = 0;
VkDeviceSize length = pRect[i].right - pRect[i].left; VkDeviceSize length = bufView->info().rangeLength / formatInfo->elementSize;
if (pRect) {
offset = pRect[i].left;
length = pRect[i].right - pRect[i].left;
}
EmitCs([ EmitCs([
cBufferView = bufView, cBufferView = bufView,
@ -1038,10 +1048,15 @@ namespace dxvk {
} }
if (imgView != nullptr) { if (imgView != nullptr) {
VkOffset3D offset = { pRect[i].left, pRect[i].top, 0 }; VkOffset3D offset = { 0, 0, 0 };
VkExtent3D extent = { VkExtent3D extent = imgView->mipLevelExtent(0);
if (pRect) {
offset = { pRect[i].left, pRect[i].top, 0 };
extent = {
uint32_t(pRect[i].right - pRect[i].left), uint32_t(pRect[i].right - pRect[i].left),
uint32_t(pRect[i].bottom - pRect[i].top), 1 }; uint32_t(pRect[i].bottom - pRect[i].top), 1 };
}
EmitCs([ EmitCs([
cImageView = imgView, cImageView = imgView,
@ -1049,47 +1064,14 @@ namespace dxvk {
cAreaExtent = extent, cAreaExtent = extent,
cClearAspect = clearAspect, cClearAspect = clearAspect,
cClearValue = clearValue cClearValue = clearValue
] (DxvkContext* ctx) {
ctx->clearImageView(
cImageView,
cAreaOffset,
cAreaExtent,
cClearAspect,
cClearValue);
});
}
}
// The rect array is optional, so if it is not
// specified, we'll have to clear the entire view
if (pRect == nullptr) {
if (bufView != nullptr) {
EmitCs([
cBufferView = bufView,
cClearValue = clearValue,
cElementSize = formatInfo->elementSize
] (DxvkContext* ctx) {
ctx->clearBufferView(cBufferView,
cBufferView->info().rangeOffset / cElementSize,
cBufferView->info().rangeLength / cElementSize,
cClearValue.color);
});
}
if (imgView != nullptr) {
EmitCs([
cImageView = imgView,
cClearAspect = clearAspect,
cClearValue = clearValue
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
const VkImageUsageFlags rtUsage = const VkImageUsageFlags rtUsage =
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
VkOffset3D offset = { 0, 0, 0 }; bool isFullSize = cImageView->mipLevelExtent(0) == cAreaExtent;
VkExtent3D extent = cImageView->mipLevelExtent(0);
if (cImageView->info().usage & rtUsage) { if ((cImageView->info().usage & rtUsage) && isFullSize) {
ctx->clearRenderTarget( ctx->clearRenderTarget(
cImageView, cImageView,
cClearAspect, cClearAspect,
@ -1097,7 +1079,8 @@ namespace dxvk {
} else { } else {
ctx->clearImageView( ctx->clearImageView(
cImageView, cImageView,
offset, extent, cAreaOffset,
cAreaExtent,
cClearAspect, cClearAspect,
cClearValue); cClearValue);
} }