| 280 | } |
| 281 | |
| 282 | void ProbesRendererService::Update() |
| 283 | { |
| 284 | PROFILE_MEM(Graphics); |
| 285 | |
| 286 | // Calculate time delta since last update |
| 287 | auto timeNow = Time::Update.UnscaledTime; |
| 288 | auto timeSinceUpdate = timeNow - _lastProbeUpdate; |
| 289 | if (timeSinceUpdate < 0) |
| 290 | { |
| 291 | _lastProbeUpdate = timeNow; |
| 292 | timeSinceUpdate = 0; |
| 293 | } |
| 294 | |
| 295 | // Check if render job is done |
| 296 | if (_updateFrameNumber > 0 && _updateFrameNumber + PROBES_RENDERER_LATENCY_FRAMES <= Engine::FrameCount) |
| 297 | { |
| 298 | // Create async job to gather probe data from the GPU |
| 299 | GPUTexture* texture = nullptr; |
| 300 | switch (_current.Type) |
| 301 | { |
| 302 | case ProbeEntry::Types::SkyLight: |
| 303 | case ProbeEntry::Types::EnvProbe: |
| 304 | texture = _probe; |
| 305 | break; |
| 306 | } |
| 307 | ASSERT(texture && _current.UseTextureData()); |
| 308 | auto taskB = New<DownloadProbeTask>(texture, _current); |
| 309 | auto taskA = texture->DownloadDataAsync(taskB->GetData()); |
| 310 | ASSERT(taskA); |
| 311 | taskA->ContinueWith(taskB); |
| 312 | taskA->Start(); |
| 313 | |
| 314 | // Clear flag |
| 315 | _updateFrameNumber = 0; |
| 316 | _workStep = 0; |
| 317 | _current.Type = ProbeEntry::Types::Invalid; |
| 318 | } |
| 319 | else if (_current.Type == ProbeEntry::Types::Invalid && timeSinceUpdate > ProbesRenderer::UpdateDelay) |
| 320 | { |
| 321 | int32 firstValidEntryIndex = -1; |
| 322 | auto dt = Time::Update.UnscaledDeltaTime.GetTotalSeconds(); |
| 323 | for (int32 i = 0; i < _probesToBake.Count(); i++) |
| 324 | { |
| 325 | auto& e = _probesToBake[i]; |
| 326 | e.Timeout -= dt; |
| 327 | if (e.Timeout <= 0) |
| 328 | { |
| 329 | firstValidEntryIndex = i; |
| 330 | break; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // Check if need to update probe |
| 335 | if (firstValidEntryIndex >= 0 && timeSinceUpdate > ProbesRenderer::UpdateDelay) |
| 336 | { |
| 337 | if (LazyInit()) |
| 338 | return; // Shader is not yet loaded so try the next frame |
| 339 |
nothing calls this directly
no test coverage detected