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

[d3d11] Clean up image staging buffer creation

This commit is contained in:
Philip Rebohle 2024-11-02 00:53:19 +01:00 committed by Philip Rebohle
parent 9e316b8c71
commit bd6b7aedc1
2 changed files with 26 additions and 27 deletions

View File

@ -188,23 +188,25 @@ namespace dxvk {
} }
// If necessary, create the mapped linear buffer // If necessary, create the mapped linear buffer
uint32_t subresourceCount = m_desc.ArraySize * m_desc.MipLevels;
if (m_mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) { if (m_mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) {
for (uint32_t i = 0; i < m_desc.ArraySize; i++) { m_mapInfo.resize(subresourceCount);
for (uint32_t j = 0; j < m_desc.MipLevels; j++) {
if (m_mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_DIRECT)
m_buffers.push_back(CreateMappedBuffer(j));
VkImageSubresource subresource = { }; for (uint32_t i = 0; i < subresourceCount; i++) {
subresource.aspectMask = formatProperties->aspectMask; m_mapInfo[i].layout = DetermineSubresourceLayout(&imageInfo,
subresource.arrayLayer = i; GetSubresourceFromIndex(formatProperties->aspectMask, i));
subresource.mipLevel = j;
auto& mapInfo = m_mapInfo.emplace_back();
mapInfo.layout = DetermineSubresourceLayout(&imageInfo, subresource);
}
} }
} }
if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER
|| m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) {
m_buffers.resize(subresourceCount);
for (uint32_t i = 0; i < subresourceCount; i++)
CreateMappedBuffer(i);
}
// Skip image creation if possible // Skip image creation if possible
if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_STAGING) if (m_mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_STAGING)
return; return;
@ -735,16 +737,12 @@ namespace dxvk {
} }
D3D11CommonTexture::MappedBuffer D3D11CommonTexture::CreateMappedBuffer(UINT MipLevel) const { void D3D11CommonTexture::CreateMappedBuffer(UINT Subresource) {
const DxvkFormatInfo* formatInfo = lookupFormatInfo( const DxvkFormatInfo* formatInfo = lookupFormatInfo(
m_device->LookupPackedFormat(m_desc.Format, GetFormatMode()).Format); m_device->LookupPackedFormat(m_desc.Format, GetFormatMode()).Format);
VkImageSubresource subresource = { };
subresource.aspectMask = formatInfo->aspectMask;
subresource.mipLevel = MipLevel;
DxvkBufferCreateInfo info; DxvkBufferCreateInfo info;
info.size = DetermineSubresourceLayout(nullptr, subresource).Size; info.size = GetSubresourceLayout(formatInfo->aspectMask, Subresource).Size;
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
| VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
| VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
@ -775,11 +773,10 @@ namespace dxvk {
if (m_desc.Usage == D3D11_USAGE_STAGING || useCached) if (m_desc.Usage == D3D11_USAGE_STAGING || useCached)
memType |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT; memType |= VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
MappedBuffer result; auto& entry = m_buffers[Subresource];
result.buffer = m_device->GetDXVKDevice()->createBuffer(info, memType); entry.buffer = m_device->GetDXVKDevice()->createBuffer(info, memType);
result.slice = result.buffer->storage(); entry.slice = entry.buffer->storage();
return result;
} }

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "../util/util_small_vector.h"
#include "../dxvk/dxvk_cs.h" #include "../dxvk/dxvk_cs.h"
#include "../dxvk/dxvk_device.h" #include "../dxvk/dxvk_device.h"
@ -546,13 +548,13 @@ namespace dxvk {
VkFormat m_packedFormat; VkFormat m_packedFormat;
Rc<DxvkImage> m_image; Rc<DxvkImage> m_image;
std::vector<MappedBuffer> m_buffers; small_vector<MappedBuffer, 6> m_buffers;
std::vector<MappedInfo> m_mapInfo; small_vector<MappedInfo, 6> m_mapInfo;
void* m_mapPtr = nullptr; void* m_mapPtr = nullptr;
MappedBuffer CreateMappedBuffer( void CreateMappedBuffer(
UINT MipLevel) const; UINT Subresource);
BOOL CheckImageSupport( BOOL CheckImageSupport(
const DxvkImageCreateInfo* pImageInfo, const DxvkImageCreateInfo* pImageInfo,