mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-05 19:46:15 +01:00
[d3d11] Reimplement R11G11B10 UAV clears without R32 views
This commit is contained in:
parent
ee28f145dc
commit
c87660480d
@ -576,7 +576,7 @@ namespace dxvk {
|
|||||||
Logger::err(str::format("D3D11: ClearUnorderedAccessViewUint: No raw format found for ", uavFormat));
|
Logger::err(str::format("D3D11: ClearUnorderedAccessViewUint: No raw format found for ", uavFormat));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up clear color struct
|
// Set up clear color struct
|
||||||
VkClearValue clearValue;
|
VkClearValue clearValue;
|
||||||
clearValue.color.uint32[0] = Values[0];
|
clearValue.color.uint32[0] = Values[0];
|
||||||
@ -584,13 +584,20 @@ namespace dxvk {
|
|||||||
clearValue.color.uint32[2] = Values[2];
|
clearValue.color.uint32[2] = Values[2];
|
||||||
clearValue.color.uint32[3] = Values[3];
|
clearValue.color.uint32[3] = Values[3];
|
||||||
|
|
||||||
// This is the only packed format that has UAV support
|
// R11G11B10 is a special cases since there's no corresponding integer format
|
||||||
if (uavFormat == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
|
// with the same bit layout, and creating an R32 view may disable compression,
|
||||||
|
// so if we can't preserve the bit pattern for non-zero values, we can create
|
||||||
|
// a temporary buffer instead and perform a copy from that.
|
||||||
|
bool useBuffer = false;
|
||||||
|
|
||||||
|
if (rawFormat == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
|
||||||
|
useBuffer = (Values[0] | Values[1] | Values[2]) != 0;
|
||||||
|
|
||||||
clearValue.color.uint32[0] = ((Values[0] & 0x7FF) << 0)
|
clearValue.color.uint32[0] = ((Values[0] & 0x7FF) << 0)
|
||||||
| ((Values[1] & 0x7FF) << 11)
|
| ((Values[1] & 0x7FF) << 11)
|
||||||
| ((Values[2] & 0x3FF) << 22);
|
| ((Values[2] & 0x3FF) << 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
if (uav->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
// In case of raw and structured buffers as well as typed
|
// In case of raw and structured buffers as well as typed
|
||||||
// buffers that can be used for atomic operations, we can
|
// buffers that can be used for atomic operations, we can
|
||||||
@ -599,9 +606,10 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (bufferView->info().format == VK_FORMAT_R32_UINT
|
if (bufferView->info().format == VK_FORMAT_R32_UINT
|
||||||
|| bufferView->info().format == VK_FORMAT_R32_SINT
|
|| bufferView->info().format == VK_FORMAT_R32_SINT
|
||||||
|| bufferView->info().format == VK_FORMAT_R32_SFLOAT) {
|
|| bufferView->info().format == VK_FORMAT_R32_SFLOAT
|
||||||
|
|| bufferView->info().format == VK_FORMAT_B10G11R11_UFLOAT_PACK32) {
|
||||||
EmitCs([
|
EmitCs([
|
||||||
cClearValue = Values[0],
|
cClearValue = clearValue.color.uint32[0],
|
||||||
cDstSlice = bufferView->slice()
|
cDstSlice = bufferView->slice()
|
||||||
] (DxvkContext* ctx) {
|
] (DxvkContext* ctx) {
|
||||||
ctx->clearBuffer(
|
ctx->clearBuffer(
|
||||||
@ -630,6 +638,36 @@ namespace dxvk {
|
|||||||
cClearValue.color);
|
cClearValue.color);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} else if (useBuffer) {
|
||||||
|
Rc<DxvkImageView> imageView = uav->GetImageView();
|
||||||
|
|
||||||
|
DxvkBufferCreateInfo bufferInfo;
|
||||||
|
bufferInfo.size = imageView->formatInfo()->elementSize
|
||||||
|
* imageView->info().numLayers
|
||||||
|
* util::flattenImageExtent(imageView->mipLevelExtent(0));
|
||||||
|
bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
||||||
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||||
|
bufferInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||||
|
bufferInfo.access = VK_ACCESS_TRANSFER_READ_BIT
|
||||||
|
| VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||||
|
|
||||||
|
Rc<DxvkBuffer> buffer = m_device->createBuffer(bufferInfo,
|
||||||
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
|
||||||
|
EmitCs([
|
||||||
|
cDstView = std::move(imageView),
|
||||||
|
cSrcBuffer = std::move(buffer),
|
||||||
|
cClearValue = clearValue.color.uint32[0]
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
ctx->clearBuffer(cSrcBuffer, 0,
|
||||||
|
cSrcBuffer->info().size, cClearValue);
|
||||||
|
|
||||||
|
ctx->copyBufferToImage(cDstView->image(),
|
||||||
|
vk::pickSubresourceLayers(cDstView->subresources(), 0),
|
||||||
|
VkOffset3D { 0, 0, 0 },
|
||||||
|
cDstView->mipLevelExtent(0),
|
||||||
|
cSrcBuffer, 0, 0, 0);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// Create a view with an integer format if necessary
|
// Create a view with an integer format if necessary
|
||||||
Rc<DxvkImageView> imageView = uav->GetImageView();
|
Rc<DxvkImageView> imageView = uav->GetImageView();
|
||||||
@ -638,8 +676,7 @@ namespace dxvk {
|
|||||||
DxvkImageViewCreateInfo info = imageView->info();
|
DxvkImageViewCreateInfo info = imageView->info();
|
||||||
info.format = rawFormat;
|
info.format = rawFormat;
|
||||||
|
|
||||||
imageView = m_device->createImageView(
|
imageView = m_device->createImageView(imageView->image(), info);
|
||||||
imageView->image(), info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EmitCs([
|
EmitCs([
|
||||||
|
@ -129,7 +129,7 @@ namespace dxvk {
|
|||||||
// DXGI_FORMAT_R11G11B10_FLOAT
|
// DXGI_FORMAT_R11G11B10_FLOAT
|
||||||
{ VK_FORMAT_B10G11R11_UFLOAT_PACK32,
|
{ VK_FORMAT_B10G11R11_UFLOAT_PACK32,
|
||||||
VK_FORMAT_UNDEFINED,
|
VK_FORMAT_UNDEFINED,
|
||||||
VK_FORMAT_R32_UINT,
|
VK_FORMAT_B10G11R11_UFLOAT_PACK32,
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT },
|
VK_IMAGE_ASPECT_COLOR_BIT },
|
||||||
// DXGI_FORMAT_R8G8B8A8_TYPELESS
|
// DXGI_FORMAT_R8G8B8A8_TYPELESS
|
||||||
{ VK_FORMAT_R8G8B8A8_UNORM,
|
{ VK_FORMAT_R8G8B8A8_UNORM,
|
||||||
|
Loading…
Reference in New Issue
Block a user