Fix GPUTexture::GetData to properly handle volume textures
This commit is contained in:
@@ -179,7 +179,7 @@ void GPUTextureViewVulkan::DescriptorAsStorageImage(GPUContextVulkan* context, V
|
||||
context->AddImageBarrier(this, VK_IMAGE_LAYOUT_GENERAL);
|
||||
}
|
||||
|
||||
bool GPUTextureVulkan::GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch)
|
||||
bool GPUTextureVulkan::GetData(int32 arrayIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch)
|
||||
{
|
||||
if (!IsStaging())
|
||||
{
|
||||
@@ -189,12 +189,12 @@ bool GPUTextureVulkan::GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex,
|
||||
GPUDeviceLock lock(_device);
|
||||
|
||||
// Internally it's a buffer, so adapt resource index and offset
|
||||
const uint32 subresource = mipMapIndex + arrayOrDepthSliceIndex * MipLevels();
|
||||
const uint32 subresource = mipMapIndex + arrayIndex * MipLevels();
|
||||
// TODO: rowAlign/sliceAlign on Vulkan texture ???
|
||||
int32 offsetInBytes = ComputeBufferOffset(subresource, 1, 1);
|
||||
int32 lengthInBytes = ComputeSubresourceSize(subresource, 1, 1);
|
||||
int32 rowPitch = ComputeRowPitch(mipMapIndex, 1);
|
||||
int32 depthPicth = ComputeSlicePitch(mipMapIndex, 1);
|
||||
int32 depthPitch = ComputeSlicePitch(mipMapIndex, 1);
|
||||
|
||||
// Map the staging resource mip map for reading
|
||||
auto allocation = StagingBuffer->GetAllocation();
|
||||
@@ -205,31 +205,7 @@ bool GPUTextureVulkan::GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex,
|
||||
// Shift mapped buffer to the beginning of the mip data start
|
||||
mapped = (void*)((byte*)mapped + offsetInBytes);
|
||||
|
||||
// Check if target row pitch is the same
|
||||
if (mipRowPitch == rowPitch || mipRowPitch == 0)
|
||||
{
|
||||
// Init mip info
|
||||
data.Lines = depthPicth / rowPitch;
|
||||
data.DepthPitch = depthPicth;
|
||||
data.RowPitch = rowPitch;
|
||||
|
||||
// Copy data
|
||||
data.Data.Copy((byte*)mapped, depthPicth);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Init mip info
|
||||
data.Lines = depthPicth / rowPitch;
|
||||
data.DepthPitch = mipRowPitch * data.Lines;
|
||||
data.RowPitch = mipRowPitch;
|
||||
|
||||
// Copy data
|
||||
data.Data.Allocate(data.DepthPitch);
|
||||
for (uint32 i = 0; i < data.Lines; i++)
|
||||
{
|
||||
Platform::MemoryCopy(data.Data.Get() + data.RowPitch * i, ((byte*)mapped) + rowPitch * i, data.RowPitch);
|
||||
}
|
||||
}
|
||||
data.Copy(mapped, rowPitch, depthPitch, Depth(), mipRowPitch);
|
||||
|
||||
// Unmap resource
|
||||
vmaUnmapMemory(_device->Allocator, allocation);
|
||||
|
||||
@@ -133,36 +133,30 @@ public:
|
||||
{
|
||||
return (GPUTextureView*)&_handlesPerSlice[arrayOrDepthIndex];
|
||||
}
|
||||
|
||||
GPUTextureView* View(int32 arrayOrDepthIndex, int32 mipMapIndex) const override
|
||||
{
|
||||
return (GPUTextureView*)&_handlesPerMip[arrayOrDepthIndex][mipMapIndex];
|
||||
}
|
||||
|
||||
GPUTextureView* ViewArray() const override
|
||||
{
|
||||
ASSERT(ArraySize() > 1);
|
||||
return (GPUTextureView*)&_handleArray;
|
||||
}
|
||||
|
||||
GPUTextureView* ViewVolume() const override
|
||||
{
|
||||
ASSERT(IsVolume());
|
||||
return (GPUTextureView*)&_handleVolume;
|
||||
}
|
||||
|
||||
GPUTextureView* ViewReadOnlyDepth() const override
|
||||
{
|
||||
ASSERT(_desc.Flags & GPUTextureFlags::ReadOnlyDepthView);
|
||||
return (GPUTextureView*)&_handleReadOnlyDepth;
|
||||
}
|
||||
|
||||
void* GetNativePtr() const override
|
||||
{
|
||||
return (void*)_image;
|
||||
}
|
||||
|
||||
bool GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch) override;
|
||||
bool GetData(int32 arrayIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch) override;
|
||||
|
||||
// [ResourceOwnerVulkan]
|
||||
GPUResource* AsGPUResource() const override
|
||||
|
||||
Reference in New Issue
Block a user