diff --git a/Editor/ObjectWindow.cpp b/Editor/ObjectWindow.cpp index 10732c20a..60b643645 100644 --- a/Editor/ObjectWindow.cpp +++ b/Editor/ObjectWindow.cpp @@ -710,7 +710,7 @@ void ObjectWindow::Create(EditorComponent* editor) x->SetLightmapRenderRequest(true); } - scene.InvalidateBVH(); + scene.SetAccelerationStructureUpdateRequested(true); }); AddWidget(&generateLightmapButton); diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index 84e9e5779..8092650e7 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -526,6 +526,13 @@ void RenderPath3D::Update(float dt) if (getSceneUpdateEnabled()) { scene->Update(dt * wiRenderer::GetGameSpeed()); + + if (wiRenderer::GetRaytracedShadowsEnabled() || + getAO() == AO_RTAO || + getRaytracedReflectionEnabled()) + { + scene->SetAccelerationStructureUpdateRequested(true); + } } // Frustum culling for main camera: @@ -596,15 +603,18 @@ void RenderPath3D::Render() const RenderFrameSetUp(cmd); }); - // Acceleration structures: - // async compute parallel with depth prepass - cmd = device->BeginCommandList(QUEUE_COMPUTE); - device->WaitCommandList(cmd, cmd_prepareframe); - wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { + if (scene->IsAccelerationStructureUpdateRequested()) + { + // Acceleration structures: + // async compute parallel with depth prepass + cmd = device->BeginCommandList(QUEUE_COMPUTE); + device->WaitCommandList(cmd, cmd_prepareframe); + wiJobSystem::Execute(ctx, [this, cmd](wiJobArgs args) { - wiRenderer::UpdateRaytracingAccelerationStructures(*scene, cmd); + wiRenderer::UpdateRaytracingAccelerationStructures(*scene, cmd); - }); + }); + } static const uint32_t drawscene_flags = wiRenderer::DRAWSCENE_OPAQUE | diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index 761876b34..b2ab00d10 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -144,10 +144,8 @@ void RenderPath3D_PathTracing::Update(float dt) resetProgress(); } - if (sam == 0) - { - scene->InvalidateBVH(); - } + scene->SetAccelerationStructureUpdateRequested(sam == 0); + setSceneUpdateEnabled(sam == 0); RenderPath3D::Update(dt); @@ -255,7 +253,10 @@ void RenderPath3D_PathTracing::Render() const wiRenderer::UpdateRenderData(visibility_main, frameCB, cmd); - wiRenderer::UpdateRaytracingAccelerationStructures(*scene, cmd); + if (scene->IsAccelerationStructureUpdateRequested()) + { + wiRenderer::UpdateRaytracingAccelerationStructures(*scene, cmd); + } }); // Main scene: diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index e7a6fd6fa..79deab487 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -3534,7 +3534,7 @@ void UpdatePerFrameData( wiJobSystem::Wait(ctx); - if (!device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_PIPELINE) && !device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_INLINE) && scene.BVH_invalid) + if (!device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_PIPELINE) && !device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_RAYTRACING_INLINE) && scene.IsAccelerationStructureUpdateRequested()) { scene.BVH.Update(scene); } @@ -4275,12 +4275,10 @@ void UpdateRaytracingAccelerationStructures(const Scene& scene, CommandList cmd) } else { - if (scene.BVH_invalid) - { - scene.BVH_invalid = false; - scene.BVH.Build(scene, cmd); - } + scene.BVH.Build(scene, cmd); } + + scene.acceleration_structure_update_requested = false; } void OcclusionCulling_Render(const CameraComponent& camera_previous, const Visibility& vis, CommandList cmd) { @@ -7800,6 +7798,8 @@ void RefreshLightmapAtlas(const Scene& scene, CommandList cmd) for (uint32_t i = 0; i < scene.objects.GetCount(); ++i) { const ObjectComponent& object = scene.objects[i]; + if (!object.lightmap.IsValid()) + continue; if (object.IsLightmapRenderRequested()) { diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index fd5cd19ff..a920be251 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -1569,7 +1569,7 @@ namespace wiScene if (lightmap_refresh_needed.load()) { - InvalidateBVH(); + SetAccelerationStructureUpdateRequested(true); } if (lightmap_repack_needed.load()) { diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index d2ec34b71..adb8550a7 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -1280,18 +1280,17 @@ namespace wiScene }; uint32_t flags = EMPTY; + wiSpinLock locker; AABB bounds; std::vector parallel_bounds; WeatherComponent weather; wiGraphics::RaytracingAccelerationStructure TLAS; std::vector TLAS_instances; - wiGPUBVH BVH; // this is for non-hardware accelerated raytracing - mutable bool BVH_invalid = false; - void InvalidateBVH() { - BVH_invalid = true; - } + mutable bool acceleration_structure_update_requested = false; + void SetAccelerationStructureUpdateRequested(bool value = true) { acceleration_structure_update_requested = value; } + bool IsAccelerationStructureUpdateRequested() const { return acceleration_structure_update_requested; } // Occlusion query state: wiGraphics::GPUQueryHeap queryHeap[arraysize(ObjectComponent::occlusionQueries)]; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 3c5421c97..856eefaee 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates, breaking compatibility changes const int minor = 56; // minor bug fixes, alterations, refactors, updates - const int revision = 45; + const int revision = 46; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);