From b20ceec727261a438eb0b34b9104be8768f02bd6 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 17 Jul 2019 11:34:21 +0200 Subject: [PATCH] [d3d11] Handle integer formats in ClearRenderTargetView correctly We're supposed to apply the same color conversion as in ClearView. --- src/d3d11/d3d11_context.cpp | 57 +++++++++++++++++++------------------ src/d3d11/d3d11_context.h | 4 +++ 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 15116b5fa..412bc5002 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -711,17 +711,12 @@ namespace dxvk { if (!rtv) return; - const Rc view = rtv->GetImageView(); - - VkClearValue clearValue; - clearValue.color.float32[0] = ColorRGBA[0]; - clearValue.color.float32[1] = ColorRGBA[1]; - clearValue.color.float32[2] = ColorRGBA[2]; - clearValue.color.float32[3] = ColorRGBA[3]; + auto view = rtv->GetImageView(); + auto color = ConvertColorValue(ColorRGBA, view->formatInfo()); EmitCs([ - cClearValue = clearValue, - cImageView = view + cClearValue = color, + cImageView = std::move(view) ] (DxvkContext* ctx) { ctx->clearRenderTarget( cImageView, @@ -971,25 +966,8 @@ namespace dxvk { // Convert the clear color format. ClearView takes // the clear value for integer formats as a set of // integral floats, so we'll have to convert. - VkClearValue clearValue; - VkImageAspectFlags clearAspect; - - if (imgView == nullptr || imgView->info().aspect & VK_IMAGE_ASPECT_COLOR_BIT) { - clearAspect = VK_IMAGE_ASPECT_COLOR_BIT; - - for (uint32_t i = 0; i < 4; i++) { - if (formatInfo->flags.test(DxvkFormatFlag::SampledUInt)) - clearValue.color.uint32[i] = uint32_t(Color[i]); - else if (formatInfo->flags.test(DxvkFormatFlag::SampledSInt)) - clearValue.color.int32[i] = int32_t(Color[i]); - else - clearValue.color.float32[i] = Color[i]; - } - } else { - clearAspect = VK_IMAGE_ASPECT_DEPTH_BIT; - clearValue.depthStencil.depth = Color[0]; - clearValue.depthStencil.stencil = 0; - } + VkClearValue clearValue = ConvertColorValue(Color, formatInfo); + VkImageAspectFlags clearAspect = formatInfo->aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT); // Clear all the rectangles that are specified for (uint32_t i = 0; i < NumRects; i++) { @@ -3780,6 +3758,29 @@ namespace dxvk { } + VkClearValue D3D11DeviceContext::ConvertColorValue( + const FLOAT Color[4], + const DxvkFormatInfo* pFormatInfo) { + VkClearValue result; + + if (pFormatInfo->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) { + for (uint32_t i = 0; i < 4; i++) { + if (pFormatInfo->flags.test(DxvkFormatFlag::SampledUInt)) + result.color.uint32[i] = uint32_t(std::max(0.0f, Color[i])); + else if (pFormatInfo->flags.test(DxvkFormatFlag::SampledSInt)) + result.color.int32[i] = int32_t(Color[i]); + else + result.color.float32[i] = Color[i]; + } + } else { + result.depthStencil.depth = Color[0]; + result.depthStencil.stencil = 0; + } + + return result; + } + + DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) { constexpr size_t UpdateBufferSize = 16 * 1024 * 1024; diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 6f9a3a8ee..305239341 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -813,6 +813,10 @@ namespace dxvk { ID3D11RenderTargetView* const* ppRenderTargetViews, ID3D11DepthStencilView* pDepthStencilView); + VkClearValue ConvertColorValue( + const FLOAT Color[4], + const DxvkFormatInfo* pFormatInfo); + DxvkDataSlice AllocUpdateBufferSlice(size_t Size); DxvkCsChunkRef AllocCsChunk();