Add additional UploadMipMapAsync for GPUTexture update with custom row/slice pitch

This commit is contained in:
Wojciech Figat
2022-02-08 18:04:44 +01:00
parent 7e2e764e1e
commit f67371d524
6 changed files with 46 additions and 24 deletions

View File

@@ -595,17 +595,21 @@ void GPUTexture::OnReleaseGPU()
_residentMipLevels = 0;
}
GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipIndex)
GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, bool copyData)
{
ASSERT(IsRegularTexture() && IsAllocated());
//ASSERT(Math::IsInRange(mipIndex, HighestResidentMipIndex() - 1, MipLevels() - 1) && mipIndex < MipLevels() && data.IsValid());
uint32 rowPitch, slicePitch;
ComputePitch(mipIndex, rowPitch, slicePitch);
return UploadMipMapAsync(data, mipIndex, rowPitch, slicePitch, copyData);
}
GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, int32 rowPitch, int32 slicePitch, bool copyData)
{
ASSERT(IsAllocated());
ASSERT(mipIndex < MipLevels() && data.IsValid());
ASSERT(data.Length() == SlicePitch(mipIndex) * ArraySize());
// Create task
auto task = ::New<GPUUploadTextureMipTask>(this, mipIndex, data, false);
ASSERT(task && task->HasReference(this));
ASSERT(data.Length() >= slicePitch);
// TODO: support texture data upload to the GPU on a main thread during rendering without this async task (faster direct upload)
auto task = ::New<GPUUploadTextureMipTask>(this, mipIndex, data, rowPitch, slicePitch, copyData);
ASSERT_LOW_LAYER(task && task->HasReference(this));
return task;
}

View File

@@ -524,8 +524,20 @@ public:
/// </summary>
/// <param name="data">Data to upload (it must be valid for the next a few frames due to GPU latency and async works executing)</param>
/// <param name="mipIndex">Mip level index.</param>
/// <param name="copyData">If true, the data will be copied to the async execution task instead of using the input pointer provided.</param>
/// <returns>Created async task or null if cannot.</returns>
GPUTask* UploadMipMapAsync(const BytesContainer& data, int32 mipIndex);
GPUTask* UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, bool copyData = false);
/// <summary>
/// Uploads mip map data to the GPU. Creates async GPU task.
/// </summary>
/// <param name="data">Data to upload (it must be valid for the next a few frames due to GPU latency and async works executing)</param>
/// <param name="mipIndex">Mip level index.</param>
/// <param name="rowPitch">The data row pitch.</param>
/// <param name="slicePitch">The data slice pitch.</param>
/// <param name="copyData">If true, the data will be copied to the async execution task instead of using the input pointer provided.</param>
/// <returns>Created async task or null if cannot.</returns>
GPUTask* UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, int32 rowPitch, int32 slicePitch, bool copyData = false);
/// <summary>
/// Stops current thread execution to gather texture data from the GPU.

View File

@@ -316,7 +316,7 @@ private:
public:
StreamTextureMipTask(StreamingTexture* texture, int32 mipIndex)
: GPUUploadTextureMipTask(texture->GetTexture(), mipIndex, Span<byte>(nullptr, 0), false)
: GPUUploadTextureMipTask(texture->GetTexture(), mipIndex, Span<byte>(nullptr, 0), 0, 0, false)
, _streamingTexture(texture)
, _dataLock(_streamingTexture->GetOwner()->LockData())
{