mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 04:54:15 +01:00
[d3d11] Clean up InitHostVisibleTexture
Also fixes a potential crash if pSysMem of any initial data structs is null.
This commit is contained in:
parent
f5241d187c
commit
64e32d4ee1
@ -229,38 +229,47 @@ namespace dxvk {
|
|||||||
D3D11CommonTexture* pTexture,
|
D3D11CommonTexture* pTexture,
|
||||||
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
const D3D11_SUBRESOURCE_DATA* pInitialData) {
|
||||||
Rc<DxvkImage> image = pTexture->GetImage();
|
Rc<DxvkImage> image = pTexture->GetImage();
|
||||||
|
auto formatInfo = image->formatInfo();
|
||||||
|
|
||||||
|
for (uint32_t layer = 0; layer < pTexture->Desc()->ArraySize; layer++) {
|
||||||
|
for (uint32_t level = 0; level < pTexture->Desc()->MipLevels; level++) {
|
||||||
|
uint32_t subresourceIndex = D3D11CalcSubresource(level, layer, pTexture->Desc()->MipLevels);
|
||||||
|
|
||||||
for (uint32_t layer = 0; layer < image->info().numLayers; layer++) {
|
|
||||||
for (uint32_t level = 0; level < image->info().mipLevels; level++) {
|
|
||||||
VkImageSubresource subresource;
|
VkImageSubresource subresource;
|
||||||
subresource.aspectMask = image->formatInfo()->aspectMask;
|
subresource.aspectMask = formatInfo->aspectMask;
|
||||||
subresource.mipLevel = level;
|
subresource.mipLevel = level;
|
||||||
subresource.arrayLayer = layer;
|
subresource.arrayLayer = layer;
|
||||||
|
|
||||||
VkExtent3D blockCount = util::computeBlockCount(
|
VkExtent3D blockCount = util::computeBlockCount(
|
||||||
image->mipLevelExtent(level),
|
image->mipLevelExtent(level), formatInfo->blockSize);
|
||||||
image->formatInfo()->blockSize);
|
|
||||||
|
|
||||||
VkSubresourceLayout layout = image->querySubresourceLayout(subresource);
|
auto layout = pTexture->GetSubresourceLayout(
|
||||||
|
subresource.aspectMask, subresourceIndex);
|
||||||
|
|
||||||
auto initialData = pInitialData
|
if (pInitialData && pInitialData[subresourceIndex].pSysMem) {
|
||||||
? &pInitialData[D3D11CalcSubresource(level, layer, image->info().mipLevels)]
|
const auto& initialData = pInitialData[subresourceIndex];
|
||||||
: nullptr;
|
|
||||||
|
|
||||||
for (uint32_t z = 0; z < blockCount.depth; z++) {
|
for (uint32_t z = 0; z < blockCount.depth; z++) {
|
||||||
for (uint32_t y = 0; y < blockCount.height; y++) {
|
for (uint32_t y = 0; y < blockCount.height; y++) {
|
||||||
auto size = blockCount.width * image->formatInfo()->elementSize;
|
auto size = blockCount.width * formatInfo->elementSize;
|
||||||
auto dst = image->mapPtr(layout.offset + y * layout.rowPitch + z * layout.depthPitch);
|
|
||||||
|
auto dst = pTexture->GetMapPtr(subresourceIndex, layout.Offset
|
||||||
|
+ y * layout.RowPitch
|
||||||
|
+ z * layout.DepthPitch);
|
||||||
|
|
||||||
|
auto src = reinterpret_cast<const char*>(initialData.pSysMem)
|
||||||
|
+ y * initialData.SysMemPitch
|
||||||
|
+ z * initialData.SysMemSlicePitch;
|
||||||
|
|
||||||
if (initialData) {
|
|
||||||
auto src = reinterpret_cast<const char*>(initialData->pSysMem)
|
|
||||||
+ y * initialData->SysMemPitch
|
|
||||||
+ z * initialData->SysMemSlicePitch;
|
|
||||||
std::memcpy(dst, src, size);
|
std::memcpy(dst, src, size);
|
||||||
|
|
||||||
|
if (size < layout.RowPitch)
|
||||||
|
std::memset(reinterpret_cast<char*>(dst) + size, 0, layout.RowPitch - size);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
std::memset(dst, 0, size);
|
void* dst = pTexture->GetMapPtr(subresourceIndex, layout.Offset);
|
||||||
}
|
std::memset(dst, 0, layout.Size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user