2019-12-16 04:28:01 +01:00
|
|
|
#include "d3d9_common_texture.h"
|
|
|
|
|
|
|
|
#include "d3d9_util.h"
|
|
|
|
#include "d3d9_device.h"
|
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
#include "../util/util_shared_res.h"
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
D3D9CommonTexture::D3D9CommonTexture(
|
|
|
|
D3D9DeviceEx* pDevice,
|
|
|
|
const D3D9_COMMON_TEXTURE_DESC* pDesc,
|
2022-02-23 22:19:28 +01:00
|
|
|
D3DRESOURCETYPE ResourceType,
|
|
|
|
HANDLE* pSharedHandle)
|
2020-01-17 11:54:41 +01:00
|
|
|
: m_device(pDevice), m_desc(*pDesc), m_type(ResourceType) {
|
2019-12-16 04:28:01 +01:00
|
|
|
if (m_desc.Format == D3D9Format::Unknown)
|
|
|
|
m_desc.Format = (m_desc.Usage & D3DUSAGE_DEPTHSTENCIL)
|
|
|
|
? D3D9Format::D32
|
|
|
|
: D3D9Format::X8R8G8B8;
|
|
|
|
|
2021-03-19 02:05:44 +01:00
|
|
|
for (uint32_t i = 0; i < m_dirtyBoxes.size(); i++) {
|
|
|
|
AddDirtyBox(nullptr, i);
|
2020-09-07 13:09:30 +02:00
|
|
|
}
|
|
|
|
|
2021-03-19 04:28:47 +01:00
|
|
|
if (m_desc.Pool != D3DPOOL_DEFAULT) {
|
|
|
|
const uint32_t subresources = CountSubresources();
|
|
|
|
for (uint32_t i = 0; i < subresources; i++) {
|
|
|
|
SetNeedsUpload(i, true);
|
|
|
|
}
|
2022-02-23 22:19:28 +01:00
|
|
|
if (pSharedHandle) {
|
|
|
|
throw DxvkError("D3D9: Incompatible pool type for texture sharing.");
|
|
|
|
}
|
2021-03-19 04:28:47 +01:00
|
|
|
}
|
|
|
|
|
2020-01-17 11:54:41 +01:00
|
|
|
m_mapping = pDevice->LookupFormat(m_desc.Format);
|
|
|
|
|
2022-01-27 17:27:25 +01:00
|
|
|
m_mapMode = DetermineMapMode();
|
|
|
|
m_shadow = DetermineShadowState();
|
|
|
|
m_supportsFetch4 = DetermineFetch4Compatibility();
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
const bool createImage = m_desc.Pool != D3DPOOL_SYSTEMMEM && m_desc.Pool != D3DPOOL_SCRATCH && m_desc.Format != D3D9Format::NULL_FORMAT;
|
|
|
|
if (createImage) {
|
2020-02-14 00:31:25 +01:00
|
|
|
bool plainSurface = m_type == D3DRTYPE_SURFACE &&
|
|
|
|
!(m_desc.Usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL));
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
try {
|
2022-02-23 22:19:28 +01:00
|
|
|
m_image = CreatePrimaryImage(ResourceType, plainSurface, pSharedHandle);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
catch (const DxvkError& e) {
|
2020-02-14 00:31:25 +01:00
|
|
|
// D3DUSAGE_AUTOGENMIPMAP and offscreen plain is mutually exclusive
|
|
|
|
// so we can combine their retry this way.
|
|
|
|
if (m_desc.Usage & D3DUSAGE_AUTOGENMIPMAP || plainSurface) {
|
2019-12-16 04:28:01 +01:00
|
|
|
m_desc.Usage &= ~D3DUSAGE_AUTOGENMIPMAP;
|
|
|
|
m_desc.MipLevels = 1;
|
2022-02-23 22:19:28 +01:00
|
|
|
m_image = CreatePrimaryImage(ResourceType, false, pSharedHandle);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
if (pSharedHandle && *pSharedHandle == nullptr) {
|
|
|
|
*pSharedHandle = m_image->sharedHandle();
|
|
|
|
ExportImageInfo();
|
|
|
|
}
|
|
|
|
|
2020-01-16 03:42:02 +01:00
|
|
|
CreateSampleView(0);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
if (!IsManaged()) {
|
|
|
|
m_size = m_image->memSize();
|
|
|
|
if (!m_device->ChangeReportedMemory(-m_size))
|
|
|
|
throw DxvkError("D3D9: Reporting out of memory from tracking.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
if (m_mapMode == D3D9_COMMON_TEXTURE_MAP_MODE_UNMAPPABLE)
|
|
|
|
AllocData();
|
|
|
|
else if (m_mapMode != D3D9_COMMON_TEXTURE_MAP_MODE_NONE && m_desc.Pool != D3DPOOL_DEFAULT)
|
2019-12-16 04:28:01 +01:00
|
|
|
CreateBuffers();
|
2020-05-26 14:11:24 +02:00
|
|
|
|
|
|
|
m_exposedMipLevels = m_desc.MipLevels;
|
|
|
|
|
|
|
|
if (m_desc.Usage & D3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
m_exposedMipLevels = 1;
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
D3D9CommonTexture::~D3D9CommonTexture() {
|
|
|
|
if (m_size != 0)
|
|
|
|
m_device->ChangeReportedMemory(m_size);
|
2022-02-14 00:08:01 +01:00
|
|
|
|
|
|
|
m_device->RemoveMappedTexture(this);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkImageSubresource D3D9CommonTexture::GetSubresourceFromIndex(
|
|
|
|
VkImageAspectFlags Aspect,
|
|
|
|
UINT Subresource) const {
|
|
|
|
VkImageSubresource result;
|
|
|
|
result.aspectMask = Aspect;
|
|
|
|
result.mipLevel = Subresource % m_desc.MipLevels;
|
|
|
|
result.arrayLayer = Subresource / m_desc.MipLevels;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT D3D9CommonTexture::NormalizeTextureProperties(
|
|
|
|
D3D9DeviceEx* pDevice,
|
2020-01-17 11:54:41 +01:00
|
|
|
D3D9_COMMON_TEXTURE_DESC* pDesc) {
|
2019-12-16 04:28:01 +01:00
|
|
|
auto* options = pDevice->GetOptions();
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// Mapping Validation
|
2020-01-17 11:54:41 +01:00
|
|
|
auto mapping = pDevice->LookupFormat(pDesc->Format);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
// Handle DisableA8RT hack for The Sims 2
|
|
|
|
if (pDesc->Format == D3D9Format::A8 &&
|
|
|
|
(pDesc->Usage & D3DUSAGE_RENDERTARGET) &&
|
|
|
|
options->disableA8RT)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
// If the mapping is invalid then lets return invalid
|
|
|
|
// Some edge cases:
|
|
|
|
// NULL format does not map to anything, but should succeed
|
|
|
|
// SCRATCH textures can still be made if the device does not support
|
|
|
|
// the format at all.
|
|
|
|
|
2020-01-17 11:54:41 +01:00
|
|
|
if (!mapping.IsValid() && pDesc->Format != D3D9Format::NULL_FORMAT) {
|
2019-12-16 04:28:01 +01:00
|
|
|
auto info = pDevice->UnsupportedFormatInfo(pDesc->Format);
|
|
|
|
|
2021-08-23 17:08:35 +02:00
|
|
|
if (pDesc->Pool != D3DPOOL_SCRATCH || info->elementSize == 0)
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////
|
|
|
|
// Desc Validation
|
|
|
|
|
|
|
|
if (pDesc->Width == 0 || pDesc->Height == 0 || pDesc->Depth == 0)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
2022-07-13 13:44:08 +02:00
|
|
|
if (FAILED(DecodeMultiSampleType(pDevice->GetDXVKDevice(), pDesc->MultiSample, pDesc->MultisampleQuality, nullptr)))
|
2019-12-16 04:28:01 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
// Using MANAGED pool with DYNAMIC usage is illegal
|
|
|
|
if (IsPoolManaged(pDesc->Pool) && (pDesc->Usage & D3DUSAGE_DYNAMIC))
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
// D3DUSAGE_WRITEONLY doesn't apply to textures.
|
|
|
|
if (pDesc->Usage & D3DUSAGE_WRITEONLY)
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
// RENDERTARGET and DEPTHSTENCIL must be default pool
|
|
|
|
constexpr DWORD incompatibleUsages = D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL;
|
|
|
|
if (pDesc->Pool != D3DPOOL_DEFAULT && (pDesc->Usage & incompatibleUsages))
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
// Use the maximum possible mip level count if the supplied
|
|
|
|
// mip level count is either unspecified (0) or invalid
|
2020-05-26 13:46:55 +02:00
|
|
|
const uint32_t maxMipLevelCount = pDesc->MultiSample <= D3DMULTISAMPLE_NONMASKABLE
|
2019-12-16 04:28:01 +01:00
|
|
|
? util::computeMipLevelCount({ pDesc->Width, pDesc->Height, pDesc->Depth })
|
|
|
|
: 1u;
|
2020-05-26 13:46:55 +02:00
|
|
|
|
|
|
|
if (pDesc->Usage & D3DUSAGE_AUTOGENMIPMAP)
|
|
|
|
pDesc->MipLevels = 0;
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
if (pDesc->MipLevels == 0 || pDesc->MipLevels > maxMipLevelCount)
|
|
|
|
pDesc->MipLevels = maxMipLevelCount;
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
void* D3D9CommonTexture::GetData(UINT Subresource) {
|
|
|
|
if (unlikely(m_mappedSlices[Subresource].mapPtr != nullptr || m_mapMode != D3D9_COMMON_TEXTURE_MAP_MODE_UNMAPPABLE))
|
|
|
|
return m_mappedSlices[Subresource].mapPtr;
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
D3D9Memory& memory = m_data[Subresource];
|
|
|
|
memory.Map();
|
|
|
|
return memory.Ptr();
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
void D3D9CommonTexture::CreateBufferSubresource(UINT Subresource) {
|
2019-12-16 04:28:01 +01:00
|
|
|
DxvkBufferCreateInfo info;
|
|
|
|
info.size = GetMipSize(Subresource);
|
|
|
|
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
|
|
|
info.stages = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
|
|
|
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
|
2020-02-10 19:26:54 +01:00
|
|
|
if (m_mapping.ConversionFormatInfo.FormatType != D3D9ConversionFormat_None) {
|
2020-03-02 04:54:38 +01:00
|
|
|
info.usage |= VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
|
2019-12-16 04:28:01 +01:00
|
|
|
info.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkMemoryPropertyFlags memType = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
2021-07-08 22:41:06 +02:00
|
|
|
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
|
|
|
| VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
m_buffers[Subresource] = m_device->GetDXVKDevice()->createBuffer(info, memType);
|
|
|
|
m_mappedSlices[Subresource] = m_buffers[Subresource]->getSliceHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkDeviceSize D3D9CommonTexture::GetMipSize(UINT Subresource) const {
|
|
|
|
const UINT MipLevel = Subresource % m_desc.MipLevels;
|
|
|
|
|
2021-08-23 17:08:35 +02:00
|
|
|
const DxvkFormatInfo* formatInfo = m_mapping.FormatColor != VK_FORMAT_UNDEFINED
|
2022-07-15 17:23:54 +02:00
|
|
|
? lookupFormatInfo(m_mapping.FormatColor)
|
2019-12-16 04:28:01 +01:00
|
|
|
: m_device->UnsupportedFormatInfo(m_desc.Format);
|
|
|
|
|
|
|
|
const VkExtent3D mipExtent = util::computeMipLevelExtent(
|
2020-08-07 10:52:25 +02:00
|
|
|
GetExtent(), MipLevel);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
const VkExtent3D blockCount = util::computeBlockCount(
|
2021-08-23 17:08:35 +02:00
|
|
|
mipExtent, formatInfo->blockSize);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2020-08-07 10:52:25 +02:00
|
|
|
const uint32_t planeCount = m_mapping.ConversionFormatInfo.PlaneCount;
|
2020-08-07 10:37:55 +02:00
|
|
|
|
2020-08-16 16:13:30 +02:00
|
|
|
return std::min(planeCount, 2u)
|
2021-08-23 17:08:35 +02:00
|
|
|
* align(formatInfo->elementSize * blockCount.width, 4)
|
2019-12-16 04:28:01 +01:00
|
|
|
* blockCount.height
|
|
|
|
* blockCount.depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
Rc<DxvkImage> D3D9CommonTexture::CreatePrimaryImage(D3DRESOURCETYPE ResourceType, bool TryOffscreenRT, HANDLE* pSharedHandle) const {
|
2019-12-16 04:28:01 +01:00
|
|
|
DxvkImageCreateInfo imageInfo;
|
|
|
|
imageInfo.type = GetImageTypeFromResourceType(ResourceType);
|
2020-02-24 07:38:26 +01:00
|
|
|
imageInfo.format = m_mapping.ConversionFormatInfo.FormatColor != VK_FORMAT_UNDEFINED
|
|
|
|
? m_mapping.ConversionFormatInfo.FormatColor
|
2020-02-10 19:26:54 +01:00
|
|
|
: m_mapping.FormatColor;
|
2019-12-16 04:28:01 +01:00
|
|
|
imageInfo.flags = 0;
|
|
|
|
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
imageInfo.extent.width = m_desc.Width;
|
|
|
|
imageInfo.extent.height = m_desc.Height;
|
|
|
|
imageInfo.extent.depth = m_desc.Depth;
|
|
|
|
imageInfo.numLayers = m_desc.ArraySize;
|
|
|
|
imageInfo.mipLevels = m_desc.MipLevels;
|
|
|
|
imageInfo.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
|
|
imageInfo.stages = VK_PIPELINE_STAGE_TRANSFER_BIT
|
|
|
|
| m_device->GetEnabledShaderStages();
|
|
|
|
imageInfo.access = VK_ACCESS_TRANSFER_READ_BIT
|
|
|
|
| VK_ACCESS_TRANSFER_WRITE_BIT
|
|
|
|
| VK_ACCESS_SHADER_READ_BIT;
|
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
imageInfo.layout = VK_IMAGE_LAYOUT_GENERAL;
|
2021-02-14 03:42:40 +01:00
|
|
|
imageInfo.shared = m_desc.IsBackBuffer;
|
2022-03-12 21:25:31 +01:00
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
if (pSharedHandle) {
|
|
|
|
imageInfo.sharing.type = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT;
|
2022-03-12 21:25:31 +01:00
|
|
|
imageInfo.sharing.mode = (*pSharedHandle == INVALID_HANDLE_VALUE || *pSharedHandle == nullptr)
|
|
|
|
? DxvkSharedHandleMode::Export
|
|
|
|
: DxvkSharedHandleMode::Import;
|
|
|
|
imageInfo.sharing.type = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT;
|
|
|
|
imageInfo.sharing.handle = *pSharedHandle;
|
2022-03-13 02:32:56 +01:00
|
|
|
imageInfo.shared = true;
|
2022-02-23 22:19:28 +01:00
|
|
|
// TODO: validate metadata?
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2020-02-10 19:26:54 +01:00
|
|
|
if (m_mapping.ConversionFormatInfo.FormatType != D3D9ConversionFormat_None) {
|
2019-12-16 04:28:01 +01:00
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
|
|
|
|
}
|
|
|
|
|
2022-07-13 13:44:08 +02:00
|
|
|
DecodeMultiSampleType(m_device->GetDXVKDevice(), m_desc.MultiSample, m_desc.MultisampleQuality, &imageInfo.sampleCount);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
// The image must be marked as mutable if it can be reinterpreted
|
|
|
|
// by a view with a different format. Depth-stencil formats cannot
|
|
|
|
// be reinterpreted in Vulkan, so we'll ignore those.
|
2022-07-15 17:23:54 +02:00
|
|
|
auto formatProperties = lookupFormatInfo(m_mapping.FormatColor);
|
2019-12-16 04:28:01 +01:00
|
|
|
|
|
|
|
bool isMutable = m_mapping.FormatSrgb != VK_FORMAT_UNDEFINED;
|
|
|
|
bool isColorFormat = (formatProperties->aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) != 0;
|
|
|
|
|
|
|
|
if (isMutable && isColorFormat) {
|
|
|
|
imageInfo.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
|
|
|
|
|
|
|
imageInfo.viewFormatCount = 2;
|
|
|
|
imageInfo.viewFormats = m_mapping.Formats;
|
|
|
|
}
|
|
|
|
|
2022-08-16 12:39:06 +02:00
|
|
|
const bool hasAttachmentFeedbackLoops =
|
|
|
|
m_device->GetDXVKDevice()->features().extAttachmentFeedbackLoopLayout.attachmentFeedbackLoopLayout;
|
|
|
|
const bool isRT = m_desc.Usage & D3DUSAGE_RENDERTARGET;
|
|
|
|
const bool isDS = m_desc.Usage & D3DUSAGE_DEPTHSTENCIL;
|
|
|
|
const bool isAutoGen = m_desc.Usage & D3DUSAGE_AUTOGENMIPMAP;
|
|
|
|
|
2020-02-14 00:31:25 +01:00
|
|
|
// Are we an RT, need to gen mips or an offscreen plain surface?
|
2022-08-16 12:39:06 +02:00
|
|
|
if (isRT || isAutoGen || TryOffscreenRT) {
|
2019-12-16 04:28:01 +01:00
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
imageInfo.access |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT
|
|
|
|
| VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
|
|
|
}
|
|
|
|
|
2022-08-16 12:39:06 +02:00
|
|
|
if (isDS) {
|
2019-12-16 04:28:01 +01:00
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
imageInfo.stages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
|
|
|
|
| VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
|
|
|
imageInfo.access |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT
|
|
|
|
| VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
|
|
|
}
|
|
|
|
|
2022-08-16 14:32:32 +02:00
|
|
|
if (ResourceType == D3DRTYPE_TEXTURE && (isRT || isDS) && hasAttachmentFeedbackLoops)
|
2022-08-16 10:43:52 +02:00
|
|
|
imageInfo.usage |= VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT;
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
if (ResourceType == D3DRTYPE_CUBETEXTURE)
|
|
|
|
imageInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
|
|
|
|
|
|
|
// Some image formats (i.e. the R32G32B32 ones) are
|
|
|
|
// only supported with linear tiling on most GPUs
|
|
|
|
if (!CheckImageSupport(&imageInfo, VK_IMAGE_TILING_OPTIMAL))
|
|
|
|
imageInfo.tiling = VK_IMAGE_TILING_LINEAR;
|
|
|
|
|
|
|
|
// We must keep LINEAR images in GENERAL layout, but we
|
|
|
|
// can choose a better layout for the image based on how
|
|
|
|
// it is going to be used by the game.
|
2022-02-23 22:19:28 +01:00
|
|
|
if (imageInfo.tiling == VK_IMAGE_TILING_OPTIMAL && imageInfo.sharing.mode == DxvkSharedHandleMode::None)
|
2019-12-16 04:28:01 +01:00
|
|
|
imageInfo.layout = OptimizeLayout(imageInfo.usage);
|
|
|
|
|
|
|
|
// For some formats, we need to enable render target
|
|
|
|
// capabilities if available, but these should
|
|
|
|
// in no way affect the default image layout
|
|
|
|
imageInfo.usage |= EnableMetaCopyUsage(imageInfo.format, imageInfo.tiling);
|
|
|
|
|
|
|
|
// Check if we can actually create the image
|
|
|
|
if (!CheckImageSupport(&imageInfo, imageInfo.tiling)) {
|
|
|
|
throw DxvkError(str::format(
|
|
|
|
"D3D9: Cannot create texture:",
|
|
|
|
"\n Type: ", std::hex, ResourceType,
|
|
|
|
"\n Format: ", m_desc.Format,
|
|
|
|
"\n Extent: ", m_desc.Width,
|
|
|
|
"x", m_desc.Height,
|
|
|
|
"x", m_desc.Depth,
|
|
|
|
"\n Samples: ", m_desc.MultiSample,
|
|
|
|
"\n Layers: ", m_desc.ArraySize,
|
|
|
|
"\n Levels: ", m_desc.MipLevels,
|
|
|
|
"\n Usage: ", std::hex, m_desc.Usage,
|
|
|
|
"\n Pool: ", std::hex, m_desc.Pool));
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_device->GetDXVKDevice()->createImage(imageInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Rc<DxvkImage> D3D9CommonTexture::CreateResolveImage() const {
|
|
|
|
DxvkImageCreateInfo imageInfo = m_image->info();
|
|
|
|
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
|
|
|
|
|
|
|
return m_device->GetDXVKDevice()->createImage(imageInfo, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL D3D9CommonTexture::DetermineShadowState() const {
|
2022-01-27 17:27:25 +01:00
|
|
|
constexpr std::array<D3D9Format, 3> blacklist = {
|
2019-12-16 04:28:01 +01:00
|
|
|
D3D9Format::INTZ, D3D9Format::DF16, D3D9Format::DF24
|
|
|
|
};
|
|
|
|
|
|
|
|
return IsDepthFormat(m_desc.Format)
|
|
|
|
&& std::find(blacklist.begin(), blacklist.end(), m_desc.Format) == blacklist.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-27 17:27:25 +01:00
|
|
|
BOOL D3D9CommonTexture::DetermineFetch4Compatibility() const {
|
|
|
|
constexpr std::array<D3D9Format, 8> singleChannelFormats = {
|
|
|
|
D3D9Format::INTZ, D3D9Format::DF16, D3D9Format::DF24,
|
|
|
|
D3D9Format::R16F, D3D9Format::R32F, D3D9Format::A8,
|
|
|
|
D3D9Format::L8, D3D9Format::L16
|
|
|
|
};
|
|
|
|
|
|
|
|
return std::find(singleChannelFormats.begin(), singleChannelFormats.end(), m_desc.Format) != singleChannelFormats.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
BOOL D3D9CommonTexture::CheckImageSupport(
|
|
|
|
const DxvkImageCreateInfo* pImageInfo,
|
|
|
|
VkImageTiling Tiling) const {
|
|
|
|
const Rc<DxvkAdapter> adapter = m_device->GetDXVKDevice()->adapter();
|
|
|
|
|
|
|
|
VkImageFormatProperties formatProps = { };
|
|
|
|
|
|
|
|
VkResult status = adapter->imageFormatProperties(
|
|
|
|
pImageInfo->format, pImageInfo->type, Tiling,
|
|
|
|
pImageInfo->usage, pImageInfo->flags, formatProps);
|
|
|
|
|
|
|
|
if (status != VK_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (pImageInfo->extent.width <= formatProps.maxExtent.width)
|
|
|
|
&& (pImageInfo->extent.height <= formatProps.maxExtent.height)
|
|
|
|
&& (pImageInfo->extent.depth <= formatProps.maxExtent.depth)
|
|
|
|
&& (pImageInfo->numLayers <= formatProps.maxArrayLayers)
|
|
|
|
&& (pImageInfo->mipLevels <= formatProps.maxMipLevels)
|
|
|
|
&& (pImageInfo->sampleCount & formatProps.sampleCounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkImageUsageFlags D3D9CommonTexture::EnableMetaCopyUsage(
|
|
|
|
VkFormat Format,
|
|
|
|
VkImageTiling Tiling) const {
|
|
|
|
VkFormatFeatureFlags requestedFeatures = 0;
|
|
|
|
|
|
|
|
if (Format == VK_FORMAT_D16_UNORM || Format == VK_FORMAT_D32_SFLOAT)
|
|
|
|
requestedFeatures |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
|
|
|
|
if (Format == VK_FORMAT_R16_UNORM || Format == VK_FORMAT_R32_SFLOAT)
|
|
|
|
requestedFeatures |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT;
|
|
|
|
|
|
|
|
if (requestedFeatures == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Enable usage flags for all supported and requested features
|
|
|
|
VkFormatProperties properties = m_device->GetDXVKDevice()->adapter()->formatProperties(Format);
|
|
|
|
|
|
|
|
requestedFeatures &= Tiling == VK_IMAGE_TILING_OPTIMAL
|
|
|
|
? properties.optimalTilingFeatures
|
|
|
|
: properties.linearTilingFeatures;
|
|
|
|
|
|
|
|
VkImageUsageFlags requestedUsage = 0;
|
|
|
|
|
|
|
|
if (requestedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
requestedUsage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
|
|
|
|
|
|
|
if (requestedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
|
|
|
|
requestedUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
|
|
|
|
return requestedUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkImageType D3D9CommonTexture::GetImageTypeFromResourceType(D3DRESOURCETYPE Type) {
|
|
|
|
switch (Type) {
|
2021-08-06 18:17:29 +02:00
|
|
|
case D3DRTYPE_SURFACE:
|
2019-12-16 04:28:01 +01:00
|
|
|
case D3DRTYPE_TEXTURE: return VK_IMAGE_TYPE_2D;
|
|
|
|
case D3DRTYPE_VOLUMETEXTURE: return VK_IMAGE_TYPE_3D;
|
|
|
|
case D3DRTYPE_CUBETEXTURE: return VK_IMAGE_TYPE_2D;
|
|
|
|
default: throw DxvkError("D3D9CommonTexture: Unhandled resource type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkImageViewType D3D9CommonTexture::GetImageViewTypeFromResourceType(
|
|
|
|
D3DRESOURCETYPE Dimension,
|
|
|
|
UINT Layer) {
|
|
|
|
switch (Dimension) {
|
2021-08-06 18:17:29 +02:00
|
|
|
case D3DRTYPE_SURFACE:
|
2019-12-16 04:28:01 +01:00
|
|
|
case D3DRTYPE_TEXTURE: return VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
case D3DRTYPE_VOLUMETEXTURE: return VK_IMAGE_VIEW_TYPE_3D;
|
|
|
|
case D3DRTYPE_CUBETEXTURE: return Layer == AllLayers
|
|
|
|
? VK_IMAGE_VIEW_TYPE_CUBE
|
|
|
|
: VK_IMAGE_VIEW_TYPE_2D;
|
|
|
|
default: throw DxvkError("D3D9CommonTexture: Unhandled resource type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-26 05:24:15 +01:00
|
|
|
VkImageLayout D3D9CommonTexture::OptimizeLayout(VkImageUsageFlags Usage) const {
|
2019-12-16 04:28:01 +01:00
|
|
|
const VkImageUsageFlags usageFlags = Usage;
|
|
|
|
|
|
|
|
// Filter out unnecessary flags. Transfer operations
|
|
|
|
// are handled by the backend in a transparent manner.
|
|
|
|
Usage &= ~(VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
|
|
|
|
|
2021-02-26 05:24:15 +01:00
|
|
|
// Ignore sampled bit in case the image was created with
|
|
|
|
// an image flag that only allows attachment usage
|
|
|
|
if (m_desc.IsAttachmentOnly)
|
|
|
|
Usage &= ~VK_IMAGE_USAGE_SAMPLED_BIT;
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
// If the image is used only as an attachment, we never
|
|
|
|
// have to transform the image back to a different layout
|
|
|
|
if (Usage == VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
|
|
|
return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
if (Usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
|
|
|
|
|
|
|
Usage &= ~(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
|
|
|
|
| VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
|
|
|
|
|
|
|
|
// If the image is used for reading but not as a storage
|
|
|
|
// image, we can optimize the image for texture access
|
|
|
|
if (Usage == VK_IMAGE_USAGE_SAMPLED_BIT) {
|
|
|
|
return usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
|
|
|
|
? VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL
|
|
|
|
: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we have to stick with the default layout
|
|
|
|
return VK_IMAGE_LAYOUT_GENERAL;
|
|
|
|
}
|
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
D3D9_COMMON_TEXTURE_MAP_MODE D3D9CommonTexture::DetermineMapMode() const {
|
|
|
|
if (m_desc.Format == D3D9Format::NULL_FORMAT)
|
|
|
|
return D3D9_COMMON_TEXTURE_MAP_MODE_NONE;
|
|
|
|
|
|
|
|
#ifdef D3D9_ALLOW_UNMAPPING
|
2022-02-14 00:08:01 +01:00
|
|
|
if (m_device->GetOptions()->textureMemory != 0 && m_desc.Pool != D3DPOOL_DEFAULT)
|
2022-03-16 02:28:22 +01:00
|
|
|
return D3D9_COMMON_TEXTURE_MAP_MODE_UNMAPPABLE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (m_desc.Pool == D3DPOOL_SYSTEMMEM || m_desc.Pool == D3DPOOL_SCRATCH)
|
|
|
|
return D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM;
|
|
|
|
|
|
|
|
return D3D9_COMMON_TEXTURE_MAP_MODE_BACKED;
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
void D3D9CommonTexture::ExportImageInfo() {
|
|
|
|
/* From MSDN:
|
|
|
|
Textures being shared from D3D9 to D3D11 have the following restrictions.
|
|
|
|
|
|
|
|
- Textures must be 2D
|
|
|
|
- Only 1 mip level is allowed
|
|
|
|
- Texture must have default usage
|
|
|
|
- Texture must be write only
|
|
|
|
- MSAA textures are not allowed
|
|
|
|
- Bind flags must have SHADER_RESOURCE and RENDER_TARGET set
|
|
|
|
- Only R10G10B10A2_UNORM, R16G16B16A16_FLOAT and R8G8B8A8_UNORM formats are allowed
|
|
|
|
*/
|
|
|
|
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_UNKNOWN;
|
|
|
|
|
|
|
|
switch (m_desc.Format) {
|
|
|
|
case D3D9Format::A2B10G10R10: dxgiFormat = DXGI_FORMAT_R10G10B10A2_UNORM; break;
|
|
|
|
case D3D9Format::A16B16G16R16F: dxgiFormat = DXGI_FORMAT_R16G16B16A16_FLOAT; break;
|
2022-03-12 22:24:05 +01:00
|
|
|
case D3D9Format::A8B8G8R8: dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM; break;
|
|
|
|
case D3D9Format::X8B8G8R8: dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM; break; /* No RGBX in DXGI */
|
|
|
|
case D3D9Format::A8R8G8B8: dxgiFormat = DXGI_FORMAT_B8G8R8A8_UNORM; break;
|
2022-02-23 22:19:28 +01:00
|
|
|
case D3D9Format::X8R8G8B8: dxgiFormat = DXGI_FORMAT_B8G8R8X8_UNORM; break;
|
|
|
|
default:
|
2022-03-12 22:24:05 +01:00
|
|
|
Logger::warn(str::format("D3D9: Unsupported format for shared textures: ", m_desc.Format));
|
2022-02-23 22:19:28 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_desc.Depth == 1 && m_desc.MipLevels == 1 && m_desc.MultiSample == D3DMULTISAMPLE_NONE &&
|
|
|
|
m_desc.Usage & D3DUSAGE_RENDERTARGET && dxgiFormat != DXGI_FORMAT_UNKNOWN) {
|
|
|
|
HANDLE ntHandle = openKmtHandle(m_image->sharedHandle());
|
|
|
|
|
|
|
|
DxvkSharedTextureMetadata metadata;
|
|
|
|
|
|
|
|
metadata.Width = m_desc.Width;
|
|
|
|
metadata.Height = m_desc.Height;
|
|
|
|
metadata.MipLevels = m_desc.MipLevels;
|
|
|
|
metadata.ArraySize = m_desc.ArraySize;
|
|
|
|
metadata.Format = dxgiFormat;
|
|
|
|
metadata.SampleDesc.Count = 1;
|
|
|
|
metadata.SampleDesc.Quality = 0;
|
|
|
|
metadata.Usage = D3D11_USAGE_DEFAULT;
|
|
|
|
metadata.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
|
|
|
|
metadata.CPUAccessFlags = 0;
|
|
|
|
metadata.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
|
|
|
metadata.TextureLayout = D3D11_TEXTURE_LAYOUT_UNDEFINED;
|
|
|
|
|
|
|
|
if (ntHandle == INVALID_HANDLE_VALUE || !setSharedMetadata(ntHandle, &metadata, sizeof(metadata)))
|
|
|
|
Logger::warn("D3D9: Failed to write shared resource info for a texture");
|
|
|
|
|
|
|
|
if (ntHandle != INVALID_HANDLE_VALUE)
|
|
|
|
::CloseHandle(ntHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-16 04:28:01 +01:00
|
|
|
Rc<DxvkImageView> D3D9CommonTexture::CreateView(
|
|
|
|
UINT Layer,
|
|
|
|
UINT Lod,
|
2020-01-16 03:42:02 +01:00
|
|
|
VkImageUsageFlags UsageFlags,
|
2021-11-12 00:51:59 +01:00
|
|
|
bool Srgb) {
|
2019-12-16 04:28:01 +01:00
|
|
|
DxvkImageViewCreateInfo viewInfo;
|
2020-02-24 07:38:26 +01:00
|
|
|
viewInfo.format = m_mapping.ConversionFormatInfo.FormatColor != VK_FORMAT_UNDEFINED
|
|
|
|
? PickSRGB(m_mapping.ConversionFormatInfo.FormatColor, m_mapping.ConversionFormatInfo.FormatSrgb, Srgb)
|
|
|
|
: PickSRGB(m_mapping.FormatColor, m_mapping.FormatSrgb, Srgb);
|
2022-07-15 17:23:54 +02:00
|
|
|
viewInfo.aspect = lookupFormatInfo(viewInfo.format)->aspectMask;
|
2020-01-16 03:42:02 +01:00
|
|
|
viewInfo.swizzle = m_mapping.Swizzle;
|
2019-12-16 04:28:01 +01:00
|
|
|
viewInfo.usage = UsageFlags;
|
|
|
|
viewInfo.type = GetImageViewTypeFromResourceType(m_type, Layer);
|
|
|
|
viewInfo.minLevel = Lod;
|
2021-11-12 00:51:59 +01:00
|
|
|
viewInfo.numLevels = m_desc.MipLevels - Lod;
|
2019-12-16 04:28:01 +01:00
|
|
|
viewInfo.minLayer = Layer == AllLayers ? 0 : Layer;
|
|
|
|
viewInfo.numLayers = Layer == AllLayers ? m_desc.ArraySize : 1;
|
|
|
|
|
|
|
|
// Remove the stencil aspect if we are trying to create a regular image
|
|
|
|
// view of a depth stencil format
|
|
|
|
if (UsageFlags != VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
viewInfo.aspect &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
|
|
|
|
|
|
if (UsageFlags == VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT ||
|
|
|
|
UsageFlags == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
viewInfo.numLevels = 1;
|
|
|
|
|
|
|
|
// Remove swizzle on depth views.
|
|
|
|
if (UsageFlags == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
|
|
|
viewInfo.swizzle = { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
|
|
|
|
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY };
|
|
|
|
|
|
|
|
// Create the underlying image view object
|
|
|
|
return m_device->GetDXVKDevice()->createImageView(GetImage(), viewInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-06 21:10:22 +02:00
|
|
|
void D3D9CommonTexture::PreLoadAll() {
|
2020-06-06 22:59:25 +02:00
|
|
|
if (!IsManaged())
|
|
|
|
return;
|
2020-06-06 21:10:22 +02:00
|
|
|
|
2020-06-06 22:59:25 +02:00
|
|
|
auto lock = m_device->LockDevice();
|
|
|
|
m_device->UploadManagedTexture(this);
|
|
|
|
m_device->MarkTextureUploaded(this);
|
2020-06-06 21:10:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void D3D9CommonTexture::PreLoadSubresource(UINT Subresource) {
|
|
|
|
if (IsManaged()) {
|
|
|
|
auto lock = m_device->LockDevice();
|
|
|
|
|
2021-03-19 02:05:44 +01:00
|
|
|
if (NeedsUpload(Subresource)) {
|
2020-06-06 21:10:22 +02:00
|
|
|
m_device->FlushImage(this, Subresource);
|
|
|
|
SetNeedsUpload(Subresource, false);
|
2020-06-06 22:59:25 +02:00
|
|
|
|
|
|
|
if (!NeedsAnyUpload())
|
|
|
|
m_device->MarkTextureUploaded(this);
|
2020-06-06 21:10:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-16 03:42:02 +01:00
|
|
|
void D3D9CommonTexture::CreateSampleView(UINT Lod) {
|
|
|
|
// This will be a no-op for SYSTEMMEM types given we
|
|
|
|
// don't expose the cap to allow texturing with them.
|
|
|
|
if (unlikely(m_mapMode == D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM))
|
|
|
|
return;
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2020-01-16 03:42:02 +01:00
|
|
|
m_sampleView.Color = CreateView(AllLayers, Lod, VK_IMAGE_USAGE_SAMPLED_BIT, false);
|
2020-01-17 17:41:58 +01:00
|
|
|
|
|
|
|
if (IsSrgbCompatible())
|
|
|
|
m_sampleView.Srgb = CreateView(AllLayers, Lod, VK_IMAGE_USAGE_SAMPLED_BIT, true);
|
2019-12-16 04:28:01 +01:00
|
|
|
}
|
|
|
|
|
2022-03-16 02:28:22 +01:00
|
|
|
void D3D9CommonTexture::AllocData() {
|
|
|
|
// D3D9Initializer will handle clearing the data
|
|
|
|
const uint32_t count = CountSubresources();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
m_data[i] = m_device->GetAllocator()->Alloc(GetMipSize(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Rc<DxvkBuffer>& D3D9CommonTexture::GetBuffer(UINT Subresource, bool Initialize) {
|
|
|
|
if (unlikely(m_buffers[Subresource] == nullptr)) {
|
|
|
|
CreateBufferSubresource(Subresource);
|
|
|
|
|
|
|
|
if (Initialize) {
|
|
|
|
if (m_data[Subresource]) {
|
|
|
|
m_data[Subresource].Map();
|
|
|
|
memcpy(m_mappedSlices[Subresource].mapPtr, m_data[Subresource].Ptr(), GetMipSize(Subresource));
|
|
|
|
} else {
|
|
|
|
memset(m_mappedSlices[Subresource].mapPtr, 0, GetMipSize(Subresource));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_data[Subresource] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_buffers[Subresource];
|
|
|
|
}
|
2019-12-16 04:28:01 +01:00
|
|
|
|
2022-02-23 22:19:28 +01:00
|
|
|
}
|