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

[d3d11] Clean up some texture map mode checks

This commit is contained in:
Philip Rebohle 2024-11-02 09:55:47 +01:00 committed by Philip Rebohle
parent 43e636cf42
commit 1d2d05dde0
3 changed files with 29 additions and 15 deletions

View File

@ -3950,8 +3950,8 @@ namespace dxvk {
// It is possible for any of the given images to be a staging image with // It is possible for any of the given images to be a staging image with
// no actual image, so we need to account for all possibilities here. // no actual image, so we need to account for all possibilities here.
bool dstIsImage = pDstTexture->GetMapMode() != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING; bool dstIsImage = pDstTexture->HasImage();
bool srcIsImage = pSrcTexture->GetMapMode() != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING; bool srcIsImage = pSrcTexture->HasImage();
if (dstIsImage && srcIsImage) { if (dstIsImage && srcIsImage) {
EmitCs([ EmitCs([
@ -5196,7 +5196,7 @@ namespace dxvk {
VkOffset3D DstOffset, VkOffset3D DstOffset,
VkExtent3D DstExtent, VkExtent3D DstExtent,
DxvkBufferSlice StagingBuffer) { DxvkBufferSlice StagingBuffer) {
bool dstIsImage = pDstTexture->GetMapMode() != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING; bool dstIsImage = pDstTexture->HasImage();
uint32_t dstSubresource = D3D11CalcSubresource(pDstSubresource->mipLevel, uint32_t dstSubresource = D3D11CalcSubresource(pDstSubresource->mipLevel,
pDstSubresource->arrayLayer, pDstTexture->Desc()->MipLevels); pDstSubresource->arrayLayer, pDstTexture->Desc()->MipLevels);

View File

@ -132,8 +132,6 @@ namespace dxvk {
// Image migt be null if this is a staging resource // Image migt be null if this is a staging resource
Rc<DxvkImage> image = pTexture->GetImage(); Rc<DxvkImage> image = pTexture->GetImage();
auto mapMode = pTexture->GetMapMode();
auto desc = pTexture->Desc(); auto desc = pTexture->Desc();
VkFormat packedFormat = m_parent->LookupPackedFormat(desc->Format, pTexture->GetFormatMode()).Format; VkFormat packedFormat = m_parent->LookupPackedFormat(desc->Format, pTexture->GetFormatMode()).Format;
@ -143,7 +141,7 @@ namespace dxvk {
// Compute data size for all subresources and allocate staging buffer memory // Compute data size for all subresources and allocate staging buffer memory
DxvkBufferSlice stagingSlice; DxvkBufferSlice stagingSlice;
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) { if (pTexture->HasImage()) {
VkDeviceSize dataSize = 0u; VkDeviceSize dataSize = 0u;
for (uint32_t mip = 0; mip < image->info().mipLevels; mip++) { for (uint32_t mip = 0; mip < image->info().mipLevels; mip++) {
@ -163,7 +161,7 @@ namespace dxvk {
uint32_t index = D3D11CalcSubresource(mip, layer, desc->MipLevels); uint32_t index = D3D11CalcSubresource(mip, layer, desc->MipLevels);
VkExtent3D mipLevelExtent = pTexture->MipLevelExtent(mip); VkExtent3D mipLevelExtent = pTexture->MipLevelExtent(mip);
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) { if (pTexture->HasImage()) {
VkDeviceSize mipSizePerLayer = util::computeImageDataSize( VkDeviceSize mipSizePerLayer = util::computeImageDataSize(
packedFormat, image->mipLevelExtent(mip), formatInfo->aspectMask); packedFormat, image->mipLevelExtent(mip), formatInfo->aspectMask);
@ -176,7 +174,7 @@ namespace dxvk {
dataOffset += align(mipSizePerLayer, CACHE_LINE_SIZE); dataOffset += align(mipSizePerLayer, CACHE_LINE_SIZE);
} }
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) { if (pTexture->HasPersistentBuffers()) {
util::packImageData(pTexture->GetMapPtr(index, 0), util::packImageData(pTexture->GetMapPtr(index, 0),
pInitialData[index].pSysMem, pInitialData[index].SysMemPitch, pInitialData[index].SysMemSlicePitch, pInitialData[index].pSysMem, pInitialData[index].SysMemPitch, pInitialData[index].SysMemSlicePitch,
0, 0, pTexture->GetVkImageType(), mipLevelExtent, 1, formatInfo, formatInfo->aspectMask); 0, 0, pTexture->GetVkImageType(), mipLevelExtent, 1, formatInfo, formatInfo->aspectMask);
@ -185,7 +183,7 @@ namespace dxvk {
} }
// Upload all subresources of the image in one go // Upload all subresources of the image in one go
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) { if (pTexture->HasImage()) {
EmitCs([ EmitCs([
cImage = std::move(image), cImage = std::move(image),
cStagingSlice = std::move(stagingSlice), cStagingSlice = std::move(stagingSlice),
@ -198,7 +196,7 @@ namespace dxvk {
}); });
} }
} else { } else {
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) { if (pTexture->HasImage()) {
m_transferCommands += 1; m_transferCommands += 1;
// While the Microsoft docs state that resource contents are // While the Microsoft docs state that resource contents are
@ -213,7 +211,7 @@ namespace dxvk {
}); });
} }
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) { if (pTexture->HasPersistentBuffers()) {
for (uint32_t i = 0; i < pTexture->CountSubresources(); i++) { for (uint32_t i = 0; i < pTexture->CountSubresources(); i++) {
auto layout = pTexture->GetSubresourceLayout(formatInfo->aspectMask, i); auto layout = pTexture->GetSubresourceLayout(formatInfo->aspectMask, i);
std::memset(pTexture->GetMapPtr(i, layout.Offset), 0, layout.Size); std::memset(pTexture->GetMapPtr(i, layout.Offset), 0, layout.Size);
@ -355,10 +353,7 @@ namespace dxvk {
// Ensure that initialization commands are submitted and waited on before // Ensure that initialization commands are submitted and waited on before
// returning control to the application in order to avoid race conditions // returning control to the application in order to avoid race conditions
// in case the texture is used immediately on a secondary device. // in case the texture is used immediately on a secondary device.
auto mapMode = pResource->GetMapMode(); if (pResource->HasImage()) {
if (mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_NONE
|| mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER) {
ExecuteFlush(); ExecuteFlush();
m_device->waitForResource(*pResource->GetImage(), DxvkAccess::Write); m_device->waitForResource(*pResource->GetImage(), DxvkAccess::Write);

View File

@ -172,6 +172,25 @@ namespace dxvk {
return m_mapMode; return m_mapMode;
} }
/**
* \brief Checks whether this texture has an image
*
* Staging textures will not use an image, only mapped buffers.
* \returns \c true for non-staging textures.
*/
bool HasImage() const {
return m_mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_STAGING;
}
/**
* \brief Checks whether this texture has persistent buffers
* \returns \c true for buffer-mapped textures or staging textures.
*/
bool HasPersistentBuffers() const {
return m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER
|| m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_STAGING;
}
/** /**
* \brief Map type of a given subresource * \brief Map type of a given subresource
* *