1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-18 20:52:10 +01:00

[d3d11] Handle integer formats in ClearRenderTargetView correctly

We're supposed to apply the same color conversion as in ClearView.
This commit is contained in:
Philip Rebohle 2019-07-17 11:34:21 +02:00
parent c6ea115ca3
commit b20ceec727
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 33 additions and 28 deletions

View File

@ -711,17 +711,12 @@ namespace dxvk {
if (!rtv) if (!rtv)
return; return;
const Rc<DxvkImageView> view = rtv->GetImageView(); auto view = rtv->GetImageView();
auto color = ConvertColorValue(ColorRGBA, view->formatInfo());
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];
EmitCs([ EmitCs([
cClearValue = clearValue, cClearValue = color,
cImageView = view cImageView = std::move(view)
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->clearRenderTarget( ctx->clearRenderTarget(
cImageView, cImageView,
@ -971,25 +966,8 @@ namespace dxvk {
// Convert the clear color format. ClearView takes // Convert the clear color format. ClearView takes
// the clear value for integer formats as a set of // the clear value for integer formats as a set of
// integral floats, so we'll have to convert. // integral floats, so we'll have to convert.
VkClearValue clearValue; VkClearValue clearValue = ConvertColorValue(Color, formatInfo);
VkImageAspectFlags clearAspect; VkImageAspectFlags clearAspect = formatInfo->aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT);
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;
}
// 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++) {
@ -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) { DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
constexpr size_t UpdateBufferSize = 16 * 1024 * 1024; constexpr size_t UpdateBufferSize = 16 * 1024 * 1024;

View File

@ -813,6 +813,10 @@ namespace dxvk {
ID3D11RenderTargetView* const* ppRenderTargetViews, ID3D11RenderTargetView* const* ppRenderTargetViews,
ID3D11DepthStencilView* pDepthStencilView); ID3D11DepthStencilView* pDepthStencilView);
VkClearValue ConvertColorValue(
const FLOAT Color[4],
const DxvkFormatInfo* pFormatInfo);
DxvkDataSlice AllocUpdateBufferSlice(size_t Size); DxvkDataSlice AllocUpdateBufferSlice(size_t Size);
DxvkCsChunkRef AllocCsChunk(); DxvkCsChunkRef AllocCsChunk();