MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DownloadData

Method DownloadData

Source/Engine/Graphics/GPUBuffer.cpp:308–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308bool GPUBuffer::DownloadData(BytesContainer& result)
309{
310 // Skip for empty ones
311 if (GetSize() == 0)
312 {
313 LOG(Warning, "Cannot download GPU buffer data from an empty buffer.");
314 return true;
315 }
316 if (_desc.Usage == GPUResourceUsage::StagingReadback || _desc.Usage == GPUResourceUsage::Dynamic || _desc.Usage == GPUResourceUsage::Staging)
317 {
318 // Use faster path for staging resources
319 return GetData(result);
320 }
321 PROFILE_CPU();
322
323 // Ensure not running on main thread
324 if (IsInMainThread())
325 {
326 // TODO: support mesh data download from GPU on a main thread during rendering
327 LOG(Warning, "Cannot download GPU buffer data on a main thread. Use staging readback buffer or invoke this function from another thread.");
328 return true;
329 }
330
331 // Create async task
332 auto task = DownloadDataAsync(result);
333 if (task == nullptr)
334 {
335 LOG(Warning, "Cannot create async download task for resource {0}.", ToString());
336 return true;
337 }
338
339 // Wait for work to be done
340 task->Start();
341 if (task->Wait())
342 {
343 LOG(Warning, "Resource \'{0}\' copy failed.", ToString());
344 return true;
345 }
346
347 return false;
348}
349
350class BufferDownloadDataTask : public ThreadPoolTask
351{

Callers 4

UpdateLightmapsMethod · 0.45
generateHemispheresMethod · 0.45
SaveMethod · 0.45

Calls 6

GetDataFunction · 0.85
IsInMainThreadFunction · 0.85
GetSizeFunction · 0.70
ToStringFunction · 0.70
StartMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected