Add GPUTexture.UploadData for changing texture contents via TextureData container

This commit is contained in:
Wojtek Figat
2025-06-16 22:35:50 +02:00
parent b92c18cf25
commit 5a23060e05
2 changed files with 27 additions and 2 deletions

View File

@@ -630,6 +630,23 @@ GPUTask* GPUTexture::UploadMipMapAsync(const BytesContainer& data, int32 mipInde
return task;
}
bool GPUTexture::UploadData(TextureData& data, bool copyData)
{
if (!IsAllocated())
return true;
if (data.Width != Width() || data.Height != Height() || data.Depth != Depth() || data.GetArraySize() != ArraySize() || data.Format != Format())
return true;
for (int32 arrayIndex = 0; arrayIndex < ArraySize(); arrayIndex++)
{
for (int32 mipLevel = 0; mipLevel < MipLevels(); mipLevel++)
{
TextureMipData* mip = data.GetData(arrayIndex, mipLevel);
UploadMipMapAsync(mip->Data, mipLevel, mip->RowPitch, mip->DepthPitch, copyData);
}
}
return false;
}
class TextureDownloadDataTask : public ThreadPoolTask
{
private:

View File

@@ -499,7 +499,7 @@ public:
/// <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="data">Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy.</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>
@@ -508,7 +508,7 @@ public:
/// <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="data">Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy.</param>
/// <param name="mipIndex">Mip level index.</param>
/// <param name="rowPitch">The data row pitch.</param>
/// <param name="slicePitch">The data slice pitch.</param>
@@ -516,6 +516,14 @@ public:
/// <returns>Created async task or null if cannot.</returns>
GPUTask* UploadMipMapAsync(const BytesContainer& data, int32 mipIndex, int32 rowPitch, int32 slicePitch, bool copyData = false);
/// <summary>
/// Uploads texture data to the GPU. Actual data copy to the GPU memory is performed via async task.
/// </summary>
/// <param name="data">Data to upload, it must match texture dimensions. It must be valid for the next couple of frames due to GPU async task latency or use data copy.</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>True if cannot upload data, otherwise false.</returns>
API_FUNCTION() bool UploadData(TextureData& data, bool copyData = false);
/// <summary>
/// Downloads the texture data to be accessible from CPU. For frequent access, use staging textures, otherwise current thread will be stalled to wait for the GPU frame to copy data into staging buffer.
/// </summary>