| 306 | } |
| 307 | |
| 308 | bool 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 | |
| 350 | class BufferDownloadDataTask : public ThreadPoolTask |
| 351 | { |
no test coverage detected