mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-22 07:54:15 +01:00
[d3d11] Overhaul DiscardResource and DiscardView implementations
For host-visible resources, these behave like MAP_DISCARD. Euro Truck Simulator 2 and friends relies on this (see #1250).
This commit is contained in:
parent
1211bb5e5f
commit
a7c21a617c
@ -78,10 +78,14 @@ namespace dxvk {
|
|||||||
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
||||||
pResource->GetType(&resType);
|
pResource->GetType(&resType);
|
||||||
|
|
||||||
if (resType == D3D11_RESOURCE_DIMENSION_BUFFER)
|
if (resType == D3D11_RESOURCE_DIMENSION_BUFFER) {
|
||||||
DiscardBuffer(static_cast<D3D11Buffer*>(pResource));
|
DiscardBuffer(pResource);
|
||||||
else if (resType != D3D11_RESOURCE_DIMENSION_UNKNOWN)
|
} else {
|
||||||
DiscardTexture(GetCommonTexture(pResource));
|
auto texture = GetCommonTexture(pResource);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < texture->CountSubresources(); i++)
|
||||||
|
DiscardTexture(pResource, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -114,12 +118,19 @@ namespace dxvk {
|
|||||||
if (view == nullptr)
|
if (view == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EmitCs([cView = std::move(view)]
|
// Get information about underlying resource
|
||||||
(DxvkContext* ctx) {
|
Com<ID3D11Resource> resource;
|
||||||
ctx->discardImage(
|
pResourceView->GetResource(&resource);
|
||||||
cView->image(),
|
|
||||||
cView->subresources());
|
uint32_t mipCount = GetCommonTexture(resource.ptr())->Desc()->MipLevels;
|
||||||
});
|
|
||||||
|
// Discard mip levels one by one
|
||||||
|
VkImageSubresourceRange sr = view->subresources();
|
||||||
|
|
||||||
|
for (uint32_t layer = 0; layer < sr.layerCount; layer++) {
|
||||||
|
for (uint32_t mip = 0; mip < sr.levelCount; mip++)
|
||||||
|
DiscardTexture(resource.ptr(), D3D11CalcSubresource(mip, layer, mipCount));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3562,22 +3573,29 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::DiscardBuffer(
|
void D3D11DeviceContext::DiscardBuffer(
|
||||||
D3D11Buffer* pBuffer) {
|
ID3D11Resource* pResource) {
|
||||||
EmitCs([cBuffer = pBuffer->GetBuffer()] (DxvkContext* ctx) {
|
auto buffer = static_cast<D3D11Buffer*>(pResource);
|
||||||
ctx->discardBuffer(cBuffer);
|
|
||||||
});
|
if (buffer->GetMapMode() != D3D11_COMMON_BUFFER_MAP_MODE_NONE) {
|
||||||
|
D3D11_MAPPED_SUBRESOURCE sr;
|
||||||
|
|
||||||
|
Map(pResource, 0, D3D11_MAP_WRITE_DISCARD, 0, &sr);
|
||||||
|
Unmap(pResource, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void D3D11DeviceContext::DiscardTexture(
|
void D3D11DeviceContext::DiscardTexture(
|
||||||
D3D11CommonTexture* pTexture) {
|
ID3D11Resource* pResource,
|
||||||
EmitCs([cImage = pTexture->GetImage()] (DxvkContext* ctx) {
|
UINT Subresource) {
|
||||||
VkImageSubresourceRange subresources = {
|
auto texture = GetCommonTexture(pResource);
|
||||||
cImage->formatInfo()->aspectMask,
|
|
||||||
0, cImage->info().mipLevels,
|
if (texture->GetMapMode() != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) {
|
||||||
0, cImage->info().numLayers };
|
D3D11_MAPPED_SUBRESOURCE sr;
|
||||||
ctx->discardImage(cImage, subresources);
|
|
||||||
});
|
Map(pResource, Subresource, D3D11_MAP_WRITE_DISCARD, 0, &sr);
|
||||||
|
Unmap(pResource, Subresource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -783,10 +783,11 @@ namespace dxvk {
|
|||||||
UINT Counter);
|
UINT Counter);
|
||||||
|
|
||||||
void DiscardBuffer(
|
void DiscardBuffer(
|
||||||
D3D11Buffer* pBuffer);
|
ID3D11Resource* pResource);
|
||||||
|
|
||||||
void DiscardTexture(
|
void DiscardTexture(
|
||||||
D3D11CommonTexture* pTexture);
|
ID3D11Resource* pResource,
|
||||||
|
UINT Subresource);
|
||||||
|
|
||||||
void SetDrawBuffers(
|
void SetDrawBuffers(
|
||||||
ID3D11Buffer* pBufferForArgs,
|
ID3D11Buffer* pBufferForArgs,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user