mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Support destination pitch in packImageData
This commit is contained in:
parent
d3112c320b
commit
11bbc07ea1
@ -1021,7 +1021,7 @@ namespace dxvk {
|
|||||||
auto stagingSlice = AllocStagingBuffer(util::computeImageDataSize(packedFormat, extent));
|
auto stagingSlice = AllocStagingBuffer(util::computeImageDataSize(packedFormat, extent));
|
||||||
|
|
||||||
util::packImageData(stagingSlice.mapPtr(0),
|
util::packImageData(stagingSlice.mapPtr(0),
|
||||||
pSrcData, SrcRowPitch, SrcDepthPitch,
|
pSrcData, SrcRowPitch, SrcDepthPitch, 0, 0,
|
||||||
dstTexture->GetVkImageType(), extent, 1,
|
dstTexture->GetVkImageType(), extent, 1,
|
||||||
formatInfo, formatInfo->aspectMask);
|
formatInfo, formatInfo->aspectMask);
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ namespace dxvk {
|
|||||||
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) {
|
if (mapMode != D3D11_COMMON_TEXTURE_MAP_MODE_NONE) {
|
||||||
util::packImageData(pTexture->GetMappedBuffer(id)->mapPtr(0),
|
util::packImageData(pTexture->GetMappedBuffer(id)->mapPtr(0),
|
||||||
pInitialData[id].pSysMem, pInitialData[id].SysMemPitch, pInitialData[id].SysMemSlicePitch,
|
pInitialData[id].pSysMem, pInitialData[id].SysMemPitch, pInitialData[id].SysMemSlicePitch,
|
||||||
pTexture->GetVkImageType(), mipLevelExtent, 1, formatInfo, formatInfo->aspectMask);
|
0, 0, pTexture->GetVkImageType(), mipLevelExtent, 1, formatInfo, formatInfo->aspectMask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,10 @@ namespace dxvk::util {
|
|||||||
void packImageData(
|
void packImageData(
|
||||||
void* dstBytes,
|
void* dstBytes,
|
||||||
const void* srcBytes,
|
const void* srcBytes,
|
||||||
VkDeviceSize rowPitch,
|
VkDeviceSize srcRowPitch,
|
||||||
VkDeviceSize slicePitch,
|
VkDeviceSize srcSlicePitch,
|
||||||
|
VkDeviceSize dstRowPitchIn,
|
||||||
|
VkDeviceSize dstSlicePitchIn,
|
||||||
VkImageType imageType,
|
VkImageType imageType,
|
||||||
VkExtent3D imageExtent,
|
VkExtent3D imageExtent,
|
||||||
uint32_t imageLayers,
|
uint32_t imageLayers,
|
||||||
@ -85,7 +87,7 @@ namespace dxvk::util {
|
|||||||
VkImageAspectFlags aspectMask) {
|
VkImageAspectFlags aspectMask) {
|
||||||
for (uint32_t i = 0; i < imageLayers; i++) {
|
for (uint32_t i = 0; i < imageLayers; i++) {
|
||||||
auto dstData = reinterpret_cast< char*>(dstBytes);
|
auto dstData = reinterpret_cast< char*>(dstBytes);
|
||||||
auto srcData = reinterpret_cast<const char*>(srcBytes) + i * slicePitch;
|
auto srcData = reinterpret_cast<const char*>(srcBytes);
|
||||||
|
|
||||||
for (auto aspects = aspectMask; aspects; ) {
|
for (auto aspects = aspectMask; aspects; ) {
|
||||||
auto aspect = vk::getNextAspect(aspects);
|
auto aspect = vk::getNextAspect(aspects);
|
||||||
@ -105,36 +107,54 @@ namespace dxvk::util {
|
|||||||
VkDeviceSize bytesPerSlice = blockCount.height * bytesPerRow;
|
VkDeviceSize bytesPerSlice = blockCount.height * bytesPerRow;
|
||||||
VkDeviceSize bytesTotal = blockCount.depth * bytesPerSlice;
|
VkDeviceSize bytesTotal = blockCount.depth * bytesPerSlice;
|
||||||
|
|
||||||
const bool directCopy = ((bytesPerRow == rowPitch ) || (blockCount.height == 1))
|
VkDeviceSize dstRowPitch = dstRowPitchIn ? dstRowPitchIn : bytesPerRow;
|
||||||
&& ((bytesPerSlice == slicePitch) || (blockCount.depth == 1));
|
VkDeviceSize dstSlicePitch = dstSlicePitchIn ? dstSlicePitchIn : bytesPerSlice;
|
||||||
|
|
||||||
|
const bool directCopy = ((bytesPerRow == srcRowPitch && bytesPerRow == dstRowPitch ) || (blockCount.height == 1))
|
||||||
|
&& ((bytesPerSlice == srcSlicePitch && bytesPerSlice == dstSlicePitch) || (blockCount.depth == 1));
|
||||||
|
|
||||||
if (directCopy) {
|
if (directCopy) {
|
||||||
std::memcpy(dstData, srcData, bytesTotal);
|
std::memcpy(dstData, srcData, bytesTotal);
|
||||||
dstData += bytesTotal;
|
|
||||||
|
|
||||||
switch (imageType) {
|
switch (imageType) {
|
||||||
case VK_IMAGE_TYPE_1D: srcData += bytesPerRow; break;
|
case VK_IMAGE_TYPE_1D:
|
||||||
case VK_IMAGE_TYPE_2D: srcData += blockCount.height * rowPitch; break;
|
srcData += srcRowPitch;
|
||||||
case VK_IMAGE_TYPE_3D: srcData += blockCount.depth * slicePitch; break;
|
dstData += dstRowPitch;
|
||||||
|
break;
|
||||||
|
case VK_IMAGE_TYPE_2D:
|
||||||
|
srcData += blockCount.height * srcRowPitch;
|
||||||
|
dstData += blockCount.height * dstRowPitch;
|
||||||
|
break;
|
||||||
|
case VK_IMAGE_TYPE_3D:
|
||||||
|
srcData += blockCount.depth * srcSlicePitch;
|
||||||
|
dstData += blockCount.depth * dstSlicePitch;
|
||||||
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (uint32_t i = 0; i < blockCount.depth; i++) {
|
for (uint32_t i = 0; i < blockCount.depth; i++) {
|
||||||
for (uint32_t j = 0; j < blockCount.height; j++) {
|
for (uint32_t j = 0; j < blockCount.height; j++) {
|
||||||
std::memcpy(
|
std::memcpy(
|
||||||
dstData + j * bytesPerRow,
|
dstData + j * dstRowPitch,
|
||||||
srcData + j * rowPitch,
|
srcData + j * srcRowPitch,
|
||||||
bytesPerRow);
|
bytesPerRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (imageType) {
|
switch (imageType) {
|
||||||
case VK_IMAGE_TYPE_1D: srcData += bytesPerRow; break;
|
case VK_IMAGE_TYPE_1D:
|
||||||
case VK_IMAGE_TYPE_2D: srcData += blockCount.height * rowPitch; break;
|
srcData += srcRowPitch;
|
||||||
case VK_IMAGE_TYPE_3D: srcData += slicePitch; break;
|
dstData += dstRowPitch;
|
||||||
|
break;
|
||||||
|
case VK_IMAGE_TYPE_2D:
|
||||||
|
srcData += blockCount.height * srcRowPitch;
|
||||||
|
dstData += blockCount.height * dstRowPitch;
|
||||||
|
break;
|
||||||
|
case VK_IMAGE_TYPE_3D:
|
||||||
|
srcData += srcSlicePitch;
|
||||||
|
dstData += dstSlicePitch;
|
||||||
|
break;
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
dstData += bytesPerSlice;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,17 @@ namespace dxvk::util {
|
|||||||
VkDeviceSize pitchPerLayer);
|
VkDeviceSize pitchPerLayer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Writes tightly packed image data to a buffer
|
* \brief Repacks image data to a buffer
|
||||||
*
|
*
|
||||||
|
* Note that passing destination pitches of 0 means that the data is
|
||||||
|
* tightly packed, while a source pitch of 0 will not show this behaviour
|
||||||
|
* in order to match client API behaviour for initialization.
|
||||||
* \param [in] dstBytes Destination buffer pointer
|
* \param [in] dstBytes Destination buffer pointer
|
||||||
* \param [in] srcBytes Pointer to source data
|
* \param [in] srcBytes Pointer to source data
|
||||||
* \param [in] rowPitch Number of bytes between rows
|
* \param [in] srcRowPitch Number of bytes between rows to read
|
||||||
* \param [in] slicePitch Number of bytes between layers
|
* \param [in] srcSlicePitch Number of bytes between layers to read
|
||||||
|
* \param [in] dstRowPitch Number of bytes between rows to write
|
||||||
|
* \param [in] dstSlicePitch Number of bytes between layers to write
|
||||||
* \param [in] imageType Image type (2D, 3D etc)
|
* \param [in] imageType Image type (2D, 3D etc)
|
||||||
* \param [in] imageExtent Image extent, in pixels
|
* \param [in] imageExtent Image extent, in pixels
|
||||||
* \param [in] imageLayers Image layer count
|
* \param [in] imageLayers Image layer count
|
||||||
@ -55,8 +60,10 @@ namespace dxvk::util {
|
|||||||
void packImageData(
|
void packImageData(
|
||||||
void* dstBytes,
|
void* dstBytes,
|
||||||
const void* srcBytes,
|
const void* srcBytes,
|
||||||
VkDeviceSize rowPitch,
|
VkDeviceSize srcRowPitch,
|
||||||
VkDeviceSize slicePitch,
|
VkDeviceSize srcSlicePitch,
|
||||||
|
VkDeviceSize dstRowPitchIn,
|
||||||
|
VkDeviceSize dstSlicePitchIn,
|
||||||
VkImageType imageType,
|
VkImageType imageType,
|
||||||
VkExtent3D imageExtent,
|
VkExtent3D imageExtent,
|
||||||
uint32_t imageLayers,
|
uint32_t imageLayers,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user