From 7e514bdf56e193a8b6c7fb14e73caca0ed2c9a54 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sun, 30 Jun 2019 15:12:19 +0100 Subject: [PATCH] lot of refactor, things are sort of working but not everything yet --- Documentation/ScriptingAPI-Documentation.md | 8 - Editor/Editor.cpp | 28 +- Editor/Editor.h | 2 +- WickedEngine/LoadingScreen_BindLua.cpp | 8 - WickedEngine/MainComponent.cpp | 33 +- WickedEngine/MainComponent.h | 2 +- WickedEngine/RenderPath.h | 2 +- WickedEngine/RenderPath2D.cpp | 47 +-- WickedEngine/RenderPath2D.h | 2 +- WickedEngine/RenderPath2D_BindLua.cpp | 8 - WickedEngine/RenderPath3D.cpp | 22 +- WickedEngine/RenderPath3D.h | 2 +- WickedEngine/RenderPath3D_BindLua.cpp | 8 - WickedEngine/RenderPath3D_Deferred.cpp | 51 ++- .../RenderPath3D_Deferred_BindLua.cpp | 8 - WickedEngine/RenderPath3D_Forward.cpp | 57 +-- WickedEngine/RenderPath3D_Forward_BindLua.cpp | 8 - WickedEngine/RenderPath3D_PathTracing.cpp | 30 +- WickedEngine/RenderPath3D_PathTracing.h | 2 +- WickedEngine/RenderPath3D_TiledDeferred.cpp | 51 ++- .../RenderPath3D_TiledDeferred_BindLua.cpp | 8 - WickedEngine/RenderPath3D_TiledForward.cpp | 46 +-- .../RenderPath3D_TiledForward_BindLua.cpp | 8 - WickedEngine/RenderPath_BindLua.cpp | 101 ------ WickedEngine/RenderPath_BindLua.h | 8 - WickedEngine/wiBackLog.cpp | 8 +- WickedEngine/wiBackLog.h | 2 +- WickedEngine/wiEmittedParticle.cpp | 2 +- WickedEngine/wiEnums.h | 15 - WickedEngine/wiGUI.cpp | 20 +- WickedEngine/wiGUI.h | 11 +- WickedEngine/wiGraphicsDevice.h | 28 +- WickedEngine/wiGraphicsDevice_DX11.cpp | 226 ++++++------ WickedEngine/wiGraphicsDevice_DX11.h | 14 +- WickedEngine/wiGraphicsDevice_DX12.cpp | 193 +++++----- WickedEngine/wiGraphicsDevice_DX12.h | 15 +- WickedEngine/wiGraphicsDevice_Vulkan.cpp | 330 +++++++----------- WickedEngine/wiGraphicsDevice_Vulkan.h | 15 +- WickedEngine/wiHairParticle.h | 1 + WickedEngine/wiHelper.cpp | 2 +- WickedEngine/wiProfiler.cpp | 10 +- WickedEngine/wiProfiler.h | 9 +- WickedEngine/wiRenderer.cpp | 4 - WickedEngine/wiSceneSystem.cpp | 2 +- WickedEngine/wiWidget.cpp | 105 +++--- WickedEngine/wiWidget.h | 20 +- 46 files changed, 664 insertions(+), 918 deletions(-) diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index d9c45409b..acfe45db2 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -505,14 +505,6 @@ A RenderPath is a high level system that represents a part of the whole applicat - [constructor]RenderPath() - GetContent() : Resource result - Initialize() -- Load() -- Unload() -- Start() -- Stop() -- FixedUpdate() -- Update(opt float dt = 0) -- Render() -- Compose() - OnStart(string task) - OnStop(string task) - GetLayerMask() : uint result diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index a460dac43..fd751048b 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1483,9 +1483,9 @@ void EditorComponent::Render() const __super::Render(); } -void EditorComponent::Compose() const +void EditorComponent::Compose(GRAPHICSTHREAD threadID) const { - renderPath->Compose(); + renderPath->Compose(threadID); if (cinemaModeCheckBox->GetCheck()) { @@ -1529,16 +1529,16 @@ void EditorComponent::Compose() const switch (light.GetType()) { case LightComponent::POINT: - wiImage::Draw(&pointLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&pointLightTex, fx, threadID); break; case LightComponent::SPOT: - wiImage::Draw(&spotLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&spotLightTex, fx, threadID); break; case LightComponent::DIRECTIONAL: - wiImage::Draw(&dirLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&dirLightTex, fx, threadID); break; default: - wiImage::Draw(&areaLightTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&areaLightTex, fx, threadID); break; } } @@ -1575,7 +1575,7 @@ void EditorComponent::Compose() const } - wiImage::Draw(&decalTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&decalTex, fx, threadID); } } @@ -1610,7 +1610,7 @@ void EditorComponent::Compose() const } - wiImage::Draw(&forceFieldTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&forceFieldTex, fx, threadID); } } @@ -1645,7 +1645,7 @@ void EditorComponent::Compose() const } - wiImage::Draw(&cameraTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&cameraTex, fx, threadID); } } @@ -1679,7 +1679,7 @@ void EditorComponent::Compose() const } - wiImage::Draw(&armatureTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&armatureTex, fx, threadID); } } @@ -1713,7 +1713,7 @@ void EditorComponent::Compose() const } - wiImage::Draw(&emitterTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&emitterTex, fx, threadID); } } @@ -1747,17 +1747,17 @@ void EditorComponent::Compose() const } - wiImage::Draw(&hairTex, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&hairTex, fx, threadID); } } if (!selected.empty() && translator.enabled) { - translator.Draw(camera, GRAPHICSTHREAD_IMMEDIATE); + translator.Draw(camera, threadID); } - __super::Compose(); + __super::Compose(threadID); } void EditorComponent::Unload() { diff --git a/Editor/Editor.h b/Editor/Editor.h index 8aa9c1cc4..aa1e6d48c 100644 --- a/Editor/Editor.h +++ b/Editor/Editor.h @@ -72,7 +72,7 @@ public: void FixedUpdate() override; void Update(float dt) override; void Render() const override; - void Compose() const override; + void Compose(GRAPHICSTHREAD threadID) const override; void Unload() override; diff --git a/WickedEngine/LoadingScreen_BindLua.cpp b/WickedEngine/LoadingScreen_BindLua.cpp index 61a40c2f1..6ff777c6b 100644 --- a/WickedEngine/LoadingScreen_BindLua.cpp +++ b/WickedEngine/LoadingScreen_BindLua.cpp @@ -20,14 +20,6 @@ Luna::FunctionType LoadingScreen_BindLua::methods[] = { lunamethod(RenderPath2D_BindLua, SetFontOrder), lunamethod(LoadingScreen_BindLua, Initialize), - lunamethod(LoadingScreen_BindLua, Load), - lunamethod(LoadingScreen_BindLua, Unload), - lunamethod(LoadingScreen_BindLua, Start), - lunamethod(LoadingScreen_BindLua, Stop), - lunamethod(LoadingScreen_BindLua, FixedUpdate), - lunamethod(LoadingScreen_BindLua, Update), - lunamethod(LoadingScreen_BindLua, Render), - lunamethod(LoadingScreen_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 3e70c247d..034e25685 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -109,16 +109,19 @@ void MainComponent::Run() Initialize(); initialized = true; } + + GRAPHICSTHREAD threadID = wiRenderer::GetDevice()->BeginCommandList(); + if (!wiInitializer::IsInitializeFinished()) { // Until engine is not loaded, present initialization screen... - wiRenderer::GetDevice()->PresentBegin(); - wiFont(wiBackLog::getText(), wiFontParams(4, 4, infoDisplay.size)).Draw(GRAPHICSTHREAD_IMMEDIATE); - wiRenderer::GetDevice()->PresentEnd(); + wiRenderer::GetDevice()->PresentBegin(threadID); + wiFont(wiBackLog::getText(), wiFontParams(4, 4, infoDisplay.size)).Draw(threadID); + wiRenderer::GetDevice()->PresentEnd(threadID); return; } - wiProfiler::BeginFrame(); + wiProfiler::BeginFrame(threadID); auto range = wiProfiler::BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU); deltaTime = float(std::max(0.0, timer.elapsed() / 1000.0)); @@ -178,9 +181,10 @@ void MainComponent::Run() wiProfiler::EndRange(range); // CPU Frame range = wiProfiler::BeginRange("Compose", wiProfiler::DOMAIN_CPU); - wiRenderer::GetDevice()->PresentBegin(); - Compose(); - wiRenderer::GetDevice()->PresentEnd(); + wiRenderer::GetDevice()->PresentBegin(threadID); + Compose(threadID); + wiProfiler::EndFrame(threadID); + wiRenderer::GetDevice()->PresentEnd(threadID); wiProfiler::EndRange(range); // Compose wiRenderer::EndFrame(); @@ -191,7 +195,6 @@ void MainComponent::Run() startupScriptProcessed = true; } - wiProfiler::EndFrame(); } void MainComponent::Update(float dt) @@ -220,19 +223,17 @@ void MainComponent::Render() { wiLua::GetGlobal()->Render(); - auto range = wiProfiler::BeginRange("GPU Frame", wiProfiler::DOMAIN_GPU, GRAPHICSTHREAD_IMMEDIATE); if (GetActivePath() != nullptr) { GetActivePath()->Render(); } - wiProfiler::EndRange(range); // GPU Frame } -void MainComponent::Compose() +void MainComponent::Compose(GRAPHICSTHREAD threadID) { if (GetActivePath() != nullptr) { - GetActivePath()->Compose(); + GetActivePath()->Compose(threadID); } if (fadeManager.IsActive()) @@ -242,7 +243,7 @@ void MainComponent::Compose() fx.siz.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); fx.siz.y = (float)wiRenderer::GetDevice()->GetScreenHeight(); fx.opacity = fadeManager.opacity; - wiImage::Draw(wiTextureHelper::getColor(fadeManager.color), fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(wiTextureHelper::getColor(fadeManager.color), fx, threadID); } // Draw the information display @@ -294,12 +295,12 @@ void MainComponent::Compose() } } ss.precision(2); - wiFont(ss.str(), wiFontParams(4, 4, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255))).Draw(GRAPHICSTHREAD_IMMEDIATE); + wiFont(ss.str(), wiFontParams(4, 4, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, wiColor(255,255,255,255), wiColor(0,0,0,255))).Draw(threadID); } - wiProfiler::DrawData(4, 120, GRAPHICSTHREAD_IMMEDIATE); + wiProfiler::DrawData(4, 120, threadID); - wiBackLog::Draw(); + wiBackLog::Draw(threadID); } #ifndef WINSTORE_SUPPORT diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index 3e18db229..accc3b7e6 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -59,7 +59,7 @@ public: // RenderPath::Render is also called from here for the active component virtual void Render(); // This is where the application will render to the screen (backbuffer) - virtual void Compose(); + virtual void Compose(GRAPHICSTHREAD threadID); #ifndef WINSTORE_SUPPORT // You need to call this before calling Run() or Initialize() if you want to render to a Win32 window handle diff --git a/WickedEngine/RenderPath.h b/WickedEngine/RenderPath.h index 90803bf19..e236c1f78 100644 --- a/WickedEngine/RenderPath.h +++ b/WickedEngine/RenderPath.h @@ -39,7 +39,7 @@ public: virtual void Render() const {} // Compose the rendered layers (for example blend the layers together as Images) // This will be rendered to the backbuffer - virtual void Compose() const {} + virtual void Compose(GRAPHICSTHREAD threadID) const {} inline uint32_t getLayerMask() const { return layerMask; } inline void setlayerMask(uint32_t value) { layerMask = value; } diff --git a/WickedEngine/RenderPath2D.cpp b/WickedEngine/RenderPath2D.cpp index 23b00d0cd..ca0eb1e3f 100644 --- a/WickedEngine/RenderPath2D.cpp +++ b/WickedEngine/RenderPath2D.cpp @@ -112,6 +112,7 @@ void RenderPath2D::FixedUpdate() void RenderPath2D::Render() const { GraphicsDevice* device = wiRenderer::GetDevice(); + GRAPHICSTHREAD threadID = device->BeginCommandList(); const Texture2D* dsv = GetDepthStencil(); @@ -120,101 +121,101 @@ void RenderPath2D::Render() const if (GetDepthStencil() != nullptr && wiRenderer::GetResolutionScale() != 1.0f) { const Texture2D* rts[] = { &rtStenciled }; - device->BindRenderTargets(ARRAYSIZE(rts), rts, dsv, GRAPHICSTHREAD_IMMEDIATE); + device->BindRenderTargets(ARRAYSIZE(rts), rts, dsv, threadID); float clear[] = { 0,0,0,0 }; - device->ClearRenderTarget(rts[0], clear, GRAPHICSTHREAD_IMMEDIATE); + device->ClearRenderTarget(rts[0], clear, threadID); ViewPort vp; vp.Width = (float)rtStenciled.GetDesc().Width; vp.Height = (float)rtStenciled.GetDesc().Height; - device->BindViewports(1, &vp, GRAPHICSTHREAD_IMMEDIATE); + device->BindViewports(1, &vp, threadID); - wiRenderer::GetDevice()->EventBegin("STENCIL Sprite Layers", GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventBegin("STENCIL Sprite Layers", threadID); for (auto& x : layers) { for (auto& y : x.items) { if (y.sprite != nullptr && y.sprite->params.stencilComp != STENCILMODE_DISABLED) { - y.sprite->Draw(GRAPHICSTHREAD_IMMEDIATE); + y.sprite->Draw(threadID); } } } - wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventEnd(threadID); dsv = nullptr; } const Texture2D* rts[] = { &rtFinal }; - device->BindRenderTargets(ARRAYSIZE(rts), rts, dsv, GRAPHICSTHREAD_IMMEDIATE); + device->BindRenderTargets(ARRAYSIZE(rts), rts, dsv, threadID); float clear[] = { 0,0,0,0 }; - device->ClearRenderTarget(rts[0], clear, GRAPHICSTHREAD_IMMEDIATE); + device->ClearRenderTarget(rts[0], clear, threadID); ViewPort vp; vp.Width = (float)rtFinal.GetDesc().Width; vp.Height = (float)rtFinal.GetDesc().Height; - device->BindViewports(1, &vp, GRAPHICSTHREAD_IMMEDIATE); + device->BindViewports(1, &vp, threadID); if (GetDepthStencil() != nullptr) { if (wiRenderer::GetResolutionScale() != 1.0f) { - wiRenderer::GetDevice()->EventBegin("Copy STENCIL Sprite Layers", GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventBegin("Copy STENCIL Sprite Layers", threadID); wiImageParams fx; fx.enableFullScreen(); - wiImage::Draw(&rtStenciled, fx, GRAPHICSTHREAD_IMMEDIATE); - wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&rtStenciled, fx, threadID); + wiRenderer::GetDevice()->EventEnd(threadID); } else { - wiRenderer::GetDevice()->EventBegin("STENCIL Sprite Layers", GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventBegin("STENCIL Sprite Layers", threadID); for (auto& x : layers) { for (auto& y : x.items) { if (y.sprite != nullptr && y.sprite->params.stencilComp != STENCILMODE_DISABLED) { - y.sprite->Draw(GRAPHICSTHREAD_IMMEDIATE); + y.sprite->Draw(threadID); } } } - wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventEnd(threadID); } } - wiRenderer::GetDevice()->EventBegin("Sprite Layers", GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventBegin("Sprite Layers", threadID); for (auto& x : layers) { for (auto& y : x.items) { if (y.sprite != nullptr && y.sprite->params.stencilComp == STENCILMODE_DISABLED) { - y.sprite->Draw(GRAPHICSTHREAD_IMMEDIATE); + y.sprite->Draw(threadID); } if (y.font != nullptr) { - y.font->Draw(GRAPHICSTHREAD_IMMEDIATE); + y.font->Draw(threadID); } } } - wiRenderer::GetDevice()->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->EventEnd(threadID); - GetGUI().Render(); + GetGUI().Render(threadID); RenderPath::Render(); } -void RenderPath2D::Compose() const +void RenderPath2D::Compose(GRAPHICSTHREAD threadID) const { wiImageParams fx((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.enableFullScreen(); fx.blendFlag = BLENDMODE_PREMULTIPLIED; - wiImage::Draw(&rtFinal, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&rtFinal, fx, threadID); - RenderPath::Compose(); + RenderPath::Compose(threadID); } diff --git a/WickedEngine/RenderPath2D.h b/WickedEngine/RenderPath2D.h index 64f408b32..7cc88fa30 100644 --- a/WickedEngine/RenderPath2D.h +++ b/WickedEngine/RenderPath2D.h @@ -50,7 +50,7 @@ public: void Update(float dt) override; void FixedUpdate() override; void Render() const override; - void Compose() const override; + void Compose(GRAPHICSTHREAD threadID) const override; const wiGraphics::Texture2D& GetRenderResult() const { return rtFinal; } virtual const wiGraphics::Texture2D* GetDepthStencil() const { return nullptr; } diff --git a/WickedEngine/RenderPath2D_BindLua.cpp b/WickedEngine/RenderPath2D_BindLua.cpp index ed9bb75a5..32e9a01fc 100644 --- a/WickedEngine/RenderPath2D_BindLua.cpp +++ b/WickedEngine/RenderPath2D_BindLua.cpp @@ -25,14 +25,6 @@ Luna::FunctionType RenderPath2D_BindLua::methods[] = { lunamethod(RenderPath2D_BindLua, SetSpriteOrder), lunamethod(RenderPath2D_BindLua, SetFontOrder), lunamethod(RenderPath2D_BindLua, Initialize), - lunamethod(RenderPath2D_BindLua, Load), - lunamethod(RenderPath2D_BindLua, Unload), - lunamethod(RenderPath2D_BindLua, Start), - lunamethod(RenderPath2D_BindLua, Stop), - lunamethod(RenderPath2D_BindLua, FixedUpdate), - lunamethod(RenderPath2D_BindLua, Update), - lunamethod(RenderPath2D_BindLua, Render), - lunamethod(RenderPath2D_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath3D.cpp b/WickedEngine/RenderPath3D.cpp index bbcba6827..77026ace9 100644 --- a/WickedEngine/RenderPath3D.cpp +++ b/WickedEngine/RenderPath3D.cpp @@ -229,7 +229,7 @@ void RenderPath3D::Update(float dt) wiRenderer::UpdatePerFrameData(dt, getLayerMask()); } -void RenderPath3D::Compose() const +void RenderPath3D::Compose(GRAPHICSTHREAD threadID) const { GraphicsDevice* device = wiRenderer::GetDevice(); @@ -238,16 +238,16 @@ void RenderPath3D::Compose() const fx.quality = QUALITY_LINEAR; fx.enableFullScreen(); - device->EventBegin("Composition", GRAPHICSTHREAD_IMMEDIATE); - wiImage::Draw(GetLastPostprocessRT(), fx, GRAPHICSTHREAD_IMMEDIATE); - device->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + device->EventBegin("Composition", threadID); + wiImage::Draw(GetLastPostprocessRT(), fx, threadID); + device->EventEnd(threadID); if (wiRenderer::GetDebugLightCulling()) { - wiImage::Draw((Texture2D*)wiRenderer::GetTexture(TEXTYPE_2D_DEBUGUAV), wiImageParams((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw((Texture2D*)wiRenderer::GetTexture(TEXTYPE_2D_DEBUGUAV), wiImageParams((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()), threadID); } - RenderPath2D::Compose(); + RenderPath2D::Compose(threadID); } void RenderPath3D::RenderFrameSetUp(GRAPHICSTHREAD threadID) const @@ -698,7 +698,7 @@ void RenderPath3D::TemporalAAResolve(const Texture2D& srcdstSceneRT, const Textu GraphicsDevice* device = wiRenderer::GetDevice(); wiImageParams fx((float)wiRenderer::GetInternalResolution().x, (float)wiRenderer::GetInternalResolution().y); - wiRenderer::BindGBufferTextures(nullptr, &srcGbuffer1, nullptr, GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::BindGBufferTextures(nullptr, &srcGbuffer1, nullptr, threadID); device->EventBegin("Temporal AA Resolve", threadID); auto range = wiProfiler::BeginRange("Temporal AA Resolve", wiProfiler::DOMAIN_GPU, threadID); @@ -816,7 +816,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture2D& srcSceneRT, const Tex if (getMotionBlurEnabled()) { - wiRenderer::BindGBufferTextures(nullptr, &srcGbuffer1, nullptr, GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::BindGBufferTextures(nullptr, &srcGbuffer1, nullptr, threadID); device->EventBegin("Motion Blur", threadID); @@ -941,7 +941,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture2D& srcSceneRT, const Tex if (getSharpenFilterEnabled()) { - device->EventBegin("Sharpen Filter", GRAPHICSTHREAD_IMMEDIATE); + device->EventBegin("Sharpen Filter", threadID); const Texture2D* rts[] = { rt_write }; device->BindRenderTargets(ARRAYSIZE(rts), rts, nullptr, threadID); @@ -965,7 +965,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture2D& srcSceneRT, const Tex if (getColorGradingEnabled()) { - device->EventBegin("Color Grading", GRAPHICSTHREAD_IMMEDIATE); + device->EventBegin("Color Grading", threadID); const Texture2D* rts[] = { rt_write }; device->BindRenderTargets(ARRAYSIZE(rts), rts, nullptr, threadID); @@ -995,7 +995,7 @@ void RenderPath3D::RenderPostprocessChain(const Texture2D& srcSceneRT, const Tex if (getFXAAEnabled()) { - device->EventBegin("FXAA", GRAPHICSTHREAD_IMMEDIATE); + device->EventBegin("FXAA", threadID); const Texture2D* rts[] = { rt_write }; device->BindRenderTargets(ARRAYSIZE(rts), rts, nullptr, threadID); diff --git a/WickedEngine/RenderPath3D.h b/WickedEngine/RenderPath3D.h index eba069cb7..28cc8853c 100644 --- a/WickedEngine/RenderPath3D.h +++ b/WickedEngine/RenderPath3D.h @@ -189,6 +189,6 @@ public: void Update(float dt) override; void Render() const override = 0; - void Compose() const override; + void Compose(GRAPHICSTHREAD threadID) const override; }; diff --git a/WickedEngine/RenderPath3D_BindLua.cpp b/WickedEngine/RenderPath3D_BindLua.cpp index b8e5f222b..66c49a180 100644 --- a/WickedEngine/RenderPath3D_BindLua.cpp +++ b/WickedEngine/RenderPath3D_BindLua.cpp @@ -22,14 +22,6 @@ Luna::FunctionType RenderPath3D_BindLua::methods[] = { lunamethod(RenderPath3D_BindLua, GetContent), lunamethod(RenderPath3D_BindLua, Initialize), - lunamethod(RenderPath3D_BindLua, Load), - lunamethod(RenderPath3D_BindLua, Unload), - lunamethod(RenderPath3D_BindLua, Start), - lunamethod(RenderPath3D_BindLua, Stop), - lunamethod(RenderPath3D_BindLua, FixedUpdate), - lunamethod(RenderPath3D_BindLua, Update), - lunamethod(RenderPath3D_BindLua, Render), - lunamethod(RenderPath3D_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath3D_Deferred.cpp b/WickedEngine/RenderPath3D_Deferred.cpp index 09b2b96dd..52d259216 100644 --- a/WickedEngine/RenderPath3D_Deferred.cpp +++ b/WickedEngine/RenderPath3D_Deferred.cpp @@ -71,14 +71,20 @@ void RenderPath3D_Deferred::ResizeBuffers() void RenderPath3D_Deferred::Render() const { - RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); - RenderShadows(GRAPHICSTHREAD_IMMEDIATE); - RenderReflections(GRAPHICSTHREAD_IMMEDIATE); + GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context& ctx = device->GetJobContext(); + GRAPHICSTHREAD threadID; + + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderFrameSetUp(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderShadows(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderReflections(threadID); }); // Main scene: - { - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; - GraphicsDevice* device = wiRenderer::GetDevice(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -149,31 +155,38 @@ void RenderPath3D_Deferred::Render() const RenderDeferredComposition(threadID); RenderSSR(rtDeferred, threadID); - } + }); - DownsampleDepthBuffer(GRAPHICSTHREAD_IMMEDIATE); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::BindCommonResources(threadID); - RenderOutline(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + DownsampleDepthBuffer(threadID); - RenderLightShafts(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); - RenderVolumetrics(GRAPHICSTHREAD_IMMEDIATE); + RenderOutline(rtDeferred, threadID); - RenderParticles(false, GRAPHICSTHREAD_IMMEDIATE); + RenderLightShafts(threadID); - RenderRefractionSource(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + RenderVolumetrics(threadID); - RenderTransparents(rtDeferred, RENDERPASS_FORWARD, GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(false, threadID); - RenderParticles(true, GRAPHICSTHREAD_IMMEDIATE); + RenderRefractionSource(rtDeferred, threadID); - TemporalAAResolve(rtDeferred, rtGBuffer[1], GRAPHICSTHREAD_IMMEDIATE); + RenderTransparents(rtDeferred, RENDERPASS_FORWARD, threadID); - RenderBloom(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(true, threadID); - RenderPostprocessChain(rtDeferred, rtGBuffer[1], GRAPHICSTHREAD_IMMEDIATE); + TemporalAAResolve(rtDeferred, rtGBuffer[1], threadID); + + RenderBloom(rtDeferred, threadID); + + RenderPostprocessChain(rtDeferred, rtGBuffer[1], threadID); + + }); RenderPath2D::Render(); } diff --git a/WickedEngine/RenderPath3D_Deferred_BindLua.cpp b/WickedEngine/RenderPath3D_Deferred_BindLua.cpp index 1aafd6230..6d120fc72 100644 --- a/WickedEngine/RenderPath3D_Deferred_BindLua.cpp +++ b/WickedEngine/RenderPath3D_Deferred_BindLua.cpp @@ -20,14 +20,6 @@ Luna::FunctionType RenderPath3D_Deferred_BindLua: lunamethod(RenderPath_BindLua, GetContent), lunamethod(RenderPath_BindLua, Initialize), - lunamethod(RenderPath_BindLua, Load), - lunamethod(RenderPath_BindLua, Unload), - lunamethod(RenderPath_BindLua, Start), - lunamethod(RenderPath_BindLua, Stop), - lunamethod(RenderPath_BindLua, FixedUpdate), - lunamethod(RenderPath_BindLua, Update), - lunamethod(RenderPath_BindLua, Render), - lunamethod(RenderPath_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath3D_Forward.cpp b/WickedEngine/RenderPath3D_Forward.cpp index 2ecdb9f5e..68689ff79 100644 --- a/WickedEngine/RenderPath3D_Forward.cpp +++ b/WickedEngine/RenderPath3D_Forward.cpp @@ -49,6 +49,9 @@ void RenderPath3D_Forward::ResizeBuffers() void RenderPath3D_Forward::Render() const { GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context& ctx = device->GetJobContext(); + GRAPHICSTHREAD threadID; + const Texture2D* scene_read[] = { &rtMain[0], &rtMain[1] }; if (getMSAASampleCount() > 1) { @@ -56,13 +59,16 @@ void RenderPath3D_Forward::Render() const scene_read[1] = &rtMain_resolved[1]; } - RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); - RenderShadows(GRAPHICSTHREAD_IMMEDIATE); - RenderReflections(GRAPHICSTHREAD_IMMEDIATE); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderFrameSetUp(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderShadows(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderReflections(threadID); }); // Main scene: - { - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID, scene_read] { wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -123,36 +129,43 @@ void RenderPath3D_Forward::Render() const RenderSSAO(threadID); RenderSSR(*scene_read[0], threadID); - } + }); - DownsampleDepthBuffer(GRAPHICSTHREAD_IMMEDIATE); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID, scene_read] { - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::BindCommonResources(threadID); - RenderOutline(rtMain[0], GRAPHICSTHREAD_IMMEDIATE); + DownsampleDepthBuffer(threadID); - RenderLightShafts(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); - RenderVolumetrics(GRAPHICSTHREAD_IMMEDIATE); + RenderOutline(rtMain[0], threadID); - RenderParticles(false, GRAPHICSTHREAD_IMMEDIATE); + RenderLightShafts(threadID); - RenderRefractionSource(*scene_read[0], GRAPHICSTHREAD_IMMEDIATE); + RenderVolumetrics(threadID); - RenderTransparents(rtMain[0], RENDERPASS_FORWARD, GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(false, threadID); - if (getMSAASampleCount() > 1) - { - device->MSAAResolve(scene_read[0], &rtMain[0], GRAPHICSTHREAD_IMMEDIATE); - } + RenderRefractionSource(*scene_read[0], threadID); - RenderParticles(true, GRAPHICSTHREAD_IMMEDIATE); + RenderTransparents(rtMain[0], RENDERPASS_FORWARD, threadID); - TemporalAAResolve(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_IMMEDIATE); + if (getMSAASampleCount() > 1) + { + device->MSAAResolve(scene_read[0], &rtMain[0], threadID); + } - RenderBloom(*scene_read[0], GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(true, threadID); - RenderPostprocessChain(*scene_read[0], *scene_read[1], GRAPHICSTHREAD_IMMEDIATE); + TemporalAAResolve(*scene_read[0], *scene_read[1], threadID); + + RenderBloom(*scene_read[0], threadID); + + RenderPostprocessChain(*scene_read[0], *scene_read[1], threadID); + + }); RenderPath2D::Render(); } diff --git a/WickedEngine/RenderPath3D_Forward_BindLua.cpp b/WickedEngine/RenderPath3D_Forward_BindLua.cpp index b0e217d1a..036ab247b 100644 --- a/WickedEngine/RenderPath3D_Forward_BindLua.cpp +++ b/WickedEngine/RenderPath3D_Forward_BindLua.cpp @@ -20,14 +20,6 @@ Luna::FunctionType RenderPath3D_Forward_BindLua::m lunamethod(RenderPath_BindLua, GetContent), lunamethod(RenderPath_BindLua, Initialize), - lunamethod(RenderPath_BindLua, Load), - lunamethod(RenderPath_BindLua, Unload), - lunamethod(RenderPath_BindLua, Start), - lunamethod(RenderPath_BindLua, Stop), - lunamethod(RenderPath_BindLua, FixedUpdate), - lunamethod(RenderPath_BindLua, Update), - lunamethod(RenderPath_BindLua, Render), - lunamethod(RenderPath_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath3D_PathTracing.cpp b/WickedEngine/RenderPath3D_PathTracing.cpp index 00cdb428e..e47951faf 100644 --- a/WickedEngine/RenderPath3D_PathTracing.cpp +++ b/WickedEngine/RenderPath3D_PathTracing.cpp @@ -72,21 +72,27 @@ void RenderPath3D_PathTracing::Update(float dt) void RenderPath3D_PathTracing::Render() const { + GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context& ctx = device->GetJobContext(); + GRAPHICSTHREAD threadID; + // Setup: - { - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { + wiRenderer::UpdateRenderData(threadID); if (sam == 0) { wiRenderer::BuildSceneBVH(threadID); } - } + }); // Main scene: - { - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; - GraphicsDevice* device = wiRenderer::GetDevice(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { + + wiRenderer::BindCommonResources(threadID); if (wiRenderer::GetRaytraceDebugBVHVisualizerEnabled()) { @@ -134,16 +140,16 @@ void RenderPath3D_PathTracing::Render() const wiProfiler::EndRange(range); // Traced Scene } - } + }); RenderPath2D::Render(); } -void RenderPath3D_PathTracing::Compose() const +void RenderPath3D_PathTracing::Compose(GRAPHICSTHREAD threadID) const { GraphicsDevice* device = wiRenderer::GetDevice(); - device->EventBegin("RenderPath3D_PathTracing::Compose", GRAPHICSTHREAD_IMMEDIATE); + device->EventBegin("RenderPath3D_PathTracing::Compose", threadID); wiImageParams fx((float)device->GetScreenWidth(), (float)device->GetScreenHeight()); @@ -153,10 +159,10 @@ void RenderPath3D_PathTracing::Compose() const fx.setDistortionMap(wiTextureHelper::getBlack()); // tonemap shader uses signed distortion mask, so black = no distortion fx.setMaskMap(wiTextureHelper::getColor(wiColor::Gray())); - wiImage::Draw(&rtAccumulation, fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(&rtAccumulation, fx, threadID); - device->EventEnd(GRAPHICSTHREAD_IMMEDIATE); + device->EventEnd(threadID); - RenderPath2D::Compose(); + RenderPath2D::Compose(threadID); } diff --git a/WickedEngine/RenderPath3D_PathTracing.h b/WickedEngine/RenderPath3D_PathTracing.h index 3cca311c7..daab38dbe 100644 --- a/WickedEngine/RenderPath3D_PathTracing.h +++ b/WickedEngine/RenderPath3D_PathTracing.h @@ -19,5 +19,5 @@ public: void Update(float dt) override; void Render() const override; - void Compose() const override; + void Compose(GRAPHICSTHREAD threadID) const override; }; diff --git a/WickedEngine/RenderPath3D_TiledDeferred.cpp b/WickedEngine/RenderPath3D_TiledDeferred.cpp index 1fdd3fd42..11e554a31 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred.cpp @@ -11,14 +11,20 @@ using namespace wiGraphics; void RenderPath3D_TiledDeferred::Render() const { - RenderFrameSetUp(GRAPHICSTHREAD_IMMEDIATE); - RenderShadows(GRAPHICSTHREAD_IMMEDIATE); - RenderReflections(GRAPHICSTHREAD_IMMEDIATE); + GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context& ctx = device->GetJobContext(); + GRAPHICSTHREAD threadID; + + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderFrameSetUp(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderShadows(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderReflections(threadID); }); // Main scene: - { - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; - GraphicsDevice* device = wiRenderer::GetDevice(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -77,31 +83,38 @@ void RenderPath3D_TiledDeferred::Render() const RenderDeferredComposition(threadID); RenderSSR(rtDeferred, threadID); - } + }); - DownsampleDepthBuffer(GRAPHICSTHREAD_IMMEDIATE); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { - wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::BindCommonResources(threadID); - RenderOutline(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + DownsampleDepthBuffer(threadID); - RenderLightShafts(GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); - RenderVolumetrics(GRAPHICSTHREAD_IMMEDIATE); + RenderOutline(rtDeferred, threadID); - RenderParticles(false, GRAPHICSTHREAD_IMMEDIATE); + RenderLightShafts(threadID); - RenderRefractionSource(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + RenderVolumetrics(threadID); - RenderTransparents(rtDeferred, RENDERPASS_TILEDFORWARD, GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(false, threadID); - RenderParticles(true, GRAPHICSTHREAD_IMMEDIATE); + RenderRefractionSource(rtDeferred, threadID); - TemporalAAResolve(rtDeferred, rtGBuffer[1], GRAPHICSTHREAD_IMMEDIATE); + RenderTransparents(rtDeferred, RENDERPASS_TILEDFORWARD, threadID); - RenderBloom(rtDeferred, GRAPHICSTHREAD_IMMEDIATE); + RenderParticles(true, threadID); - RenderPostprocessChain(rtDeferred, rtGBuffer[1], GRAPHICSTHREAD_IMMEDIATE); + TemporalAAResolve(rtDeferred, rtGBuffer[1], threadID); + + RenderBloom(rtDeferred, threadID); + + RenderPostprocessChain(rtDeferred, rtGBuffer[1], threadID); + + }); RenderPath2D::Render(); } diff --git a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp b/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp index 029efdc4c..c2aad624c 100644 --- a/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp +++ b/WickedEngine/RenderPath3D_TiledDeferred_BindLua.cpp @@ -20,14 +20,6 @@ Luna::FunctionType RenderPath3D_TiledDeferre lunamethod(RenderPath_BindLua, GetContent), lunamethod(RenderPath_BindLua, Initialize), - lunamethod(RenderPath_BindLua, Load), - lunamethod(RenderPath_BindLua, Unload), - lunamethod(RenderPath_BindLua, Start), - lunamethod(RenderPath_BindLua, Stop), - lunamethod(RenderPath_BindLua, FixedUpdate), - lunamethod(RenderPath_BindLua, Update), - lunamethod(RenderPath_BindLua, Render), - lunamethod(RenderPath_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath3D_TiledForward.cpp b/WickedEngine/RenderPath3D_TiledForward.cpp index ba99ce720..ba1d4fd6c 100644 --- a/WickedEngine/RenderPath3D_TiledForward.cpp +++ b/WickedEngine/RenderPath3D_TiledForward.cpp @@ -10,6 +10,9 @@ using namespace wiGraphics; void RenderPath3D_TiledForward::Render() const { GraphicsDevice* device = wiRenderer::GetDevice(); + wiJobSystem::context& ctx = device->GetJobContext(); + GRAPHICSTHREAD threadID; + const Texture2D* scene_read[] = { &rtMain[0], &rtMain[1] }; if (getMSAASampleCount() > 1) { @@ -17,22 +20,16 @@ void RenderPath3D_TiledForward::Render() const scene_read[1] = &rtMain_resolved[1]; } - wiJobSystem::context ctx; - - wiJobSystem::Execute(ctx, [this, device] { - RenderFrameSetUp(device->BeginCommandList()); - }); - wiJobSystem::Execute(ctx, [this, device] { - RenderShadows(device->BeginCommandList()); - }); - wiJobSystem::Execute(ctx, [this, device] { - RenderReflections(device->BeginCommandList()); - }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderFrameSetUp(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderShadows(threadID); }); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, threadID] { RenderReflections(threadID); }); // Main scene: - wiJobSystem::Execute(ctx, [&] - { - GRAPHICSTHREAD threadID = device->BeginCommandList(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID] { wiRenderer::UpdateCameraCB(wiRenderer::GetCamera(), threadID); @@ -74,12 +71,10 @@ void RenderPath3D_TiledForward::Render() const RenderLinearDepth(threadID); wiRenderer::BindDepthTextures(&depthBuffer_Copy, &rtLinearDepth, threadID); - } - ); + }); - wiJobSystem::Execute(ctx, [&] - { - GRAPHICSTHREAD threadID = device->BeginCommandList(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID, scene_read] { wiRenderer::ComputeTiledLightCulling(threadID); @@ -123,12 +118,10 @@ void RenderPath3D_TiledForward::Render() const RenderSSAO(threadID); RenderSSR(*scene_read[0], threadID); - } - ); + }); - wiJobSystem::Execute(ctx, [&] - { - GRAPHICSTHREAD threadID = device->BeginCommandList(); + threadID = device->BeginCommandList(); + wiJobSystem::Execute(ctx, [this, device, threadID, scene_read] { wiRenderer::BindCommonResources(threadID); @@ -158,10 +151,7 @@ void RenderPath3D_TiledForward::Render() const RenderBloom(*scene_read[0], threadID); RenderPostprocessChain(*scene_read[0], *scene_read[1], threadID); - } - ); - - wiJobSystem::Wait(ctx); + }); RenderPath2D::Render(); } diff --git a/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp b/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp index 45dc20b1a..1e50803b8 100644 --- a/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp +++ b/WickedEngine/RenderPath3D_TiledForward_BindLua.cpp @@ -20,14 +20,6 @@ Luna::FunctionType RenderPath3D_TiledForward_ lunamethod(RenderPath_BindLua, GetContent), lunamethod(RenderPath_BindLua, Initialize), - lunamethod(RenderPath_BindLua, Load), - lunamethod(RenderPath_BindLua, Unload), - lunamethod(RenderPath_BindLua, Start), - lunamethod(RenderPath_BindLua, Stop), - lunamethod(RenderPath_BindLua, FixedUpdate), - lunamethod(RenderPath_BindLua, Update), - lunamethod(RenderPath_BindLua, Render), - lunamethod(RenderPath_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), diff --git a/WickedEngine/RenderPath_BindLua.cpp b/WickedEngine/RenderPath_BindLua.cpp index 4e4b0b7b5..4484bc4c9 100644 --- a/WickedEngine/RenderPath_BindLua.cpp +++ b/WickedEngine/RenderPath_BindLua.cpp @@ -8,14 +8,6 @@ const char RenderPath_BindLua::className[] = "RenderPath"; Luna::FunctionType RenderPath_BindLua::methods[] = { lunamethod(RenderPath_BindLua, GetContent), lunamethod(RenderPath_BindLua, Initialize), - lunamethod(RenderPath_BindLua, Load), - lunamethod(RenderPath_BindLua, Unload), - lunamethod(RenderPath_BindLua, Start), - lunamethod(RenderPath_BindLua, Stop), - lunamethod(RenderPath_BindLua, FixedUpdate), - lunamethod(RenderPath_BindLua, Update), - lunamethod(RenderPath_BindLua, Render), - lunamethod(RenderPath_BindLua, Compose), lunamethod(RenderPath_BindLua, OnStart), lunamethod(RenderPath_BindLua, OnStop), lunamethod(RenderPath_BindLua, GetLayerMask), @@ -62,99 +54,6 @@ int RenderPath_BindLua::Initialize(lua_State* L) return 0; } -int RenderPath_BindLua::Load(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Load() component is null!"); - return 0; - } - component->Load(); - return 0; -} - -int RenderPath_BindLua::Unload(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Unload() component is null!"); - return 0; - } - component->Unload(); - return 0; -} - -int RenderPath_BindLua::Start(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Start() component is null!"); - return 0; - } - component->Start(); - return 0; -} - -int RenderPath_BindLua::Stop(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Stop() component is null!"); - return 0; - } - component->Stop(); - return 0; -} - -int RenderPath_BindLua::FixedUpdate(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "FixedUpdate() component is null!"); - return 0; - } - component->FixedUpdate(); - return 0; -} - -int RenderPath_BindLua::Update(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Update(opt float dt = 0) component is null!"); - return 0; - } - float dt = 0.f; - if (wiLua::SGetArgCount(L) > 0) - { - dt = wiLua::SGetFloat(L, 1); - } - component->Update(dt); - return 0; -} - -int RenderPath_BindLua::Render(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Render() component is null!"); - return 0; - } - component->Render(); - return 0; -} - -int RenderPath_BindLua::Compose(lua_State* L) -{ - if (component == nullptr) - { - wiLua::SError(L, "Compose() component is null!"); - return 0; - } - component->Compose(); - return 0; -} - int RenderPath_BindLua::OnStart(lua_State* L) { diff --git a/WickedEngine/RenderPath_BindLua.h b/WickedEngine/RenderPath_BindLua.h index d145b67eb..9e178d599 100644 --- a/WickedEngine/RenderPath_BindLua.h +++ b/WickedEngine/RenderPath_BindLua.h @@ -18,14 +18,6 @@ public: virtual int GetContent(lua_State* L); virtual int Initialize(lua_State* L); - virtual int Load(lua_State* L); - virtual int Unload(lua_State* L); - virtual int Start(lua_State* L); - virtual int Stop(lua_State* L); - virtual int FixedUpdate(lua_State* L); - virtual int Update(lua_State* L); - virtual int Render(lua_State* L); - virtual int Compose(lua_State* L); virtual int OnStart(lua_State* L); virtual int OnStop(lua_State* L); diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 5ffdc7fa8..0ac4a9555 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -79,7 +79,7 @@ namespace wiBackLog scroll -= 2; } } - void Draw() + void Draw(GRAPHICSTHREAD threadID) { if (state != DISABLED) { @@ -94,12 +94,12 @@ namespace wiBackLog wiImageParams fx = wiImageParams((float)wiRenderer::GetDevice()->GetScreenWidth(), (float)wiRenderer::GetDevice()->GetScreenHeight()); fx.pos = XMFLOAT3(0, pos, 0); fx.opacity = wiMath::Lerp(1, 0, -pos / wiRenderer::GetDevice()->GetScreenHeight()); - wiImage::Draw(backgroundTex.get(), fx, GRAPHICSTHREAD_IMMEDIATE); + wiImage::Draw(backgroundTex.get(), fx, threadID); font.SetText(getText()); font.params.posX = 50; font.params.posY = (int)pos + (int)scroll; - font.Draw(GRAPHICSTHREAD_IMMEDIATE); - wiFont(inputArea.str().c_str(), wiFontParams(10, wiRenderer::GetDevice()->GetScreenHeight() - 10, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_BOTTOM)).Draw(GRAPHICSTHREAD_IMMEDIATE); + font.Draw(threadID); + wiFont(inputArea.str().c_str(), wiFontParams(10, wiRenderer::GetDevice()->GetScreenHeight() - 10, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_BOTTOM)).Draw(threadID); } } diff --git a/WickedEngine/wiBackLog.h b/WickedEngine/wiBackLog.h index b3ee2654b..552b8bbaf 100644 --- a/WickedEngine/wiBackLog.h +++ b/WickedEngine/wiBackLog.h @@ -10,7 +10,7 @@ namespace wiBackLog void Toggle(); void Scroll(int direction); void Update(); - void Draw(); + void Draw(GRAPHICSTHREAD threadID); std::string getText(); void clear(); diff --git a/WickedEngine/wiEmittedParticle.cpp b/WickedEngine/wiEmittedParticle.cpp index b0fa156d1..190196166 100644 --- a/WickedEngine/wiEmittedParticle.cpp +++ b/WickedEngine/wiEmittedParticle.cpp @@ -249,7 +249,7 @@ void wiEmittedParticle::UpdateCPU(const TransformComponent& transform, float dt) if (IsDebug()) { - wiRenderer::GetDevice()->DownloadResource(counterBuffer.get(), debugDataReadbackBuffer.get(), &debugData, GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->DownloadResource(counterBuffer.get(), debugDataReadbackBuffer.get(), &debugData); } } void wiEmittedParticle::Burst(int num) diff --git a/WickedEngine/wiEnums.h b/WickedEngine/wiEnums.h index 65f6b3e7b..76e6d8a29 100644 --- a/WickedEngine/wiEnums.h +++ b/WickedEngine/wiEnums.h @@ -1,20 +1,5 @@ #pragma once -// Use GRAPHICSTHREAD_IMMEDIATE from the main thread and when drawing to backbuffer -// Use the others from other threads in conjunction with GraphicsDevice::BeginCommandList and ExecuteCommandLists -enum GRAPHICSTHREAD -{ - GRAPHICSTHREAD_IMMEDIATE, - GRAPHICSTHREAD_1, - GRAPHICSTHREAD_2, - GRAPHICSTHREAD_3, - GRAPHICSTHREAD_4, - GRAPHICSTHREAD_5, - GRAPHICSTHREAD_6, - GRAPHICSTHREAD_7, - GRAPHICSTHREAD_COUNT -}; - // Common blendmodes used across multiple systems enum BLENDMODE { diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index 0130b5d0b..d2c7f421b 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -6,7 +6,7 @@ using namespace std; -wiGUI::wiGUI(GRAPHICSTHREAD threadID) :threadID(threadID), activeWidget(nullptr), focus(false), visible(true), pointerpos(XMFLOAT2(0,0)) +wiGUI::wiGUI() : activeWidget(nullptr), focus(false), visible(true), pointerpos(XMFLOAT2(0,0)) { SetDirty(); scale_local.x = (float)wiRenderer::GetDevice()->GetScreenWidth(); @@ -64,45 +64,45 @@ void wiGUI::Update(float dt) } } -void wiGUI::Render() const +void wiGUI::Render(GRAPHICSTHREAD threadID) const { if (!visible) { return; } - wiRenderer::GetDevice()->EventBegin("GUI", GetGraphicsThread()); + wiRenderer::GetDevice()->EventBegin("GUI", threadID); for (auto&x : widgets) { if (x->parent == this && x != activeWidget) { // the contained child widgets will be rendered by the containers - x->Render(this); + x->Render(this, threadID); } } if (activeWidget != nullptr) { // render the active widget on top of everything - activeWidget->Render(this); + activeWidget->Render(this, threadID); } for (auto&x : widgets) { - x->RenderTooltip(this); + x->RenderTooltip(this, threadID); } - ResetScissor(); - wiRenderer::GetDevice()->EventEnd(GetGraphicsThread()); + ResetScissor(threadID); + wiRenderer::GetDevice()->EventEnd(threadID); } -void wiGUI::ResetScissor() const +void wiGUI::ResetScissor(GRAPHICSTHREAD threadID) const { wiGraphics::Rect scissor[1]; scissor[0].bottom = (LONG)(wiRenderer::GetDevice()->GetScreenHeight()); scissor[0].left = (LONG)(0); scissor[0].right = (LONG)(wiRenderer::GetDevice()->GetScreenWidth()); scissor[0].top = (LONG)(0); - wiRenderer::GetDevice()->BindScissorRects(1, scissor, GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, scissor, threadID); } void wiGUI::AddWidget(wiWidget* widget) diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index 50c2f293e..df3b21116 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -1,6 +1,6 @@ #pragma once #include "CommonInclude.h" -#include "wiEnums.h" +#include "wiGraphicsDevice.h" #include "wiSceneSystem.h" #include @@ -15,17 +15,16 @@ class wiGUI : public wiSceneSystem::TransformComponent private: std::list widgets; wiWidget* activeWidget; - GRAPHICSTHREAD threadID; bool focus; bool visible; XMFLOAT2 pointerpos; public: - wiGUI(GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + wiGUI(); ~wiGUI(); void Update(float dt); - void Render() const; + void Render(GRAPHICSTHREAD threadID) const; void AddWidget(wiWidget* widget); void RemoveWidget(wiWidget* widget); @@ -43,9 +42,7 @@ public: void SetVisible(bool value) { visible = value; } bool IsVisible() { return visible; } - GRAPHICSTHREAD GetGraphicsThread() const { return threadID; } - - void ResetScissor() const; + void ResetScissor(GRAPHICSTHREAD threadID) const; const XMFLOAT2& GetPointerPos() const diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index 1173b68c2..b28776b44 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -2,13 +2,27 @@ #define _GRAPHICSDEVICE_H_ #include "CommonInclude.h" -#include "wiEnums.h" #include "wiGraphicsDescriptors.h" #include "wiGraphicsResource.h" +#include "wiJobSystem.h" + +enum GRAPHICSTHREAD +{ + GRAPHICSTHREAD_0, + GRAPHICSTHREAD_1, + GRAPHICSTHREAD_2, + GRAPHICSTHREAD_3, + GRAPHICSTHREAD_4, + GRAPHICSTHREAD_5, + GRAPHICSTHREAD_6, + GRAPHICSTHREAD_7, + GRAPHICSTHREAD_8, + GRAPHICSTHREAD_9, + GRAPHICSTHREAD_COUNT +}; namespace wiGraphics { - class GraphicsDevice { protected: @@ -25,6 +39,7 @@ namespace wiGraphics bool CONSERVATIVE_RASTERIZATION = false; bool RASTERIZER_ORDERED_VIEWS = false; bool UNORDEREDACCESSTEXTURE_LOAD_EXT = false; + wiJobSystem::context jobsystem_ctx; public: @@ -68,10 +83,12 @@ namespace wiGraphics virtual void DestroyGraphicsPSO(GraphicsPSO* pso) = 0; virtual void DestroyComputePSO(ComputePSO* pso) = 0; + virtual bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) = 0; + virtual void SetName(GPUResource* pResource, const std::string& name) = 0; - virtual void PresentBegin() = 0; - virtual void PresentEnd() = 0; + virtual void PresentBegin(GRAPHICSTHREAD threadID) = 0; + virtual void PresentEnd(GRAPHICSTHREAD threadID) = 0; virtual GRAPHICSTHREAD BeginCommandList() = 0; @@ -113,6 +130,8 @@ namespace wiGraphics inline bool IsDebugDevice() const { return DEBUGDEVICE; } + inline wiJobSystem::context& GetJobContext() { return jobsystem_ctx; } + ///////////////Thread-sensitive//////////////////////// @@ -147,7 +166,6 @@ namespace wiGraphics virtual void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, GRAPHICSTHREAD threadID) = 0; virtual void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, GRAPHICSTHREAD threadID) = 0; virtual void UpdateBuffer(const GPUBuffer* buffer, const void* data, GRAPHICSTHREAD threadID, int dataSize = -1) = 0; - virtual bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) = 0; virtual void QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) = 0; virtual void QueryEnd(const GPUQuery *query, GRAPHICSTHREAD threadID) = 0; virtual bool QueryRead(const GPUQuery *query, GPUQueryResult* result) = 0; diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index cb219aa9d..4b2d417fb 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1427,7 +1427,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo { driverType = driverTypes[driverTypeIndex]; hr = D3D11CreateDevice(nullptr, driverType, nullptr, createDeviceFlags, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &device - , &featureLevel, &deviceContexts[GRAPHICSTHREAD_IMMEDIATE]); + , &featureLevel, &immediateContext); if (SUCCEEDED(hr)) break; @@ -1490,9 +1490,6 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo // ensures that the application will only render after each VSync, minimizing power consumption. hr = pDXGIDevice->SetMaximumFrameLatency(1); - hr = deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->QueryInterface(__uuidof(userDefinedAnnotations[GRAPHICSTHREAD_IMMEDIATE]), - reinterpret_cast(&userDefinedAnnotations[GRAPHICSTHREAD_IMMEDIATE])); - D3D_FEATURE_LEVEL aquiredFeatureLevel = device->GetFeatureLevel(); TESSELLATION = ((aquiredFeatureLevel >= D3D_FEATURE_LEVEL_11_0) ? true : false); @@ -1514,16 +1511,6 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiWindowRegistration::window_type windo CreateBackBufferResources(); - // Temporary allocations will use the following buffer type: - frameAllocatorDesc.ByteWidth = 4 * 1024 * 1024; - frameAllocatorDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_INDEX_BUFFER | BIND_VERTEX_BUFFER; - frameAllocatorDesc.Usage = USAGE_DYNAMIC; - frameAllocatorDesc.CPUAccessFlags = CPU_ACCESS_WRITE; - frameAllocatorDesc.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; - - // Create temporary allocator: - CreateBuffer(&frameAllocatorDesc, nullptr, &frame_allocators[GRAPHICSTHREAD_IMMEDIATE].buffer); - SetName(&frame_allocators[GRAPHICSTHREAD_IMMEDIATE].buffer, "frame_allocator[immediate]"); wiBackLog::post("Created GraphicsDevice_DX11"); } @@ -3051,20 +3038,100 @@ void GraphicsDevice_DX11::DestroyComputePSO(ComputePSO* pso) { } +bool GraphicsDevice_DX11::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) +{ + assert(resourceToDownload->type == resourceDest->type); + + if (resourceToDownload->IsBuffer()) + { + const GPUBuffer* bufferToDownload = static_cast(resourceToDownload); + const GPUBuffer* bufferDest = static_cast(resourceDest); + + if (bufferToDownload != nullptr && bufferDest != nullptr) + { + assert(bufferToDownload->desc.ByteWidth <= bufferDest->desc.ByteWidth); + assert(bufferDest->desc.Usage & USAGE_STAGING); + assert(dataDest != nullptr); + + immediateContext->CopyResource((ID3D11Resource*)bufferDest->resource, (ID3D11Resource*)bufferToDownload->resource); + + D3D11_MAPPED_SUBRESOURCE mappedResource = {}; + HRESULT hr = immediateContext->Map((ID3D11Resource*)bufferDest->resource, 0, D3D11_MAP_READ, /*async ? D3D11_MAP_FLAG_DO_NOT_WAIT :*/ 0, &mappedResource); + bool result = SUCCEEDED(hr); + if (result) + { + memcpy(dataDest, mappedResource.pData, bufferToDownload->desc.ByteWidth); + immediateContext->Unmap((ID3D11Resource*)bufferDest->resource, 0); + } + + return result; + } + } + else if (resourceToDownload->IsTexture()) + { + const Texture* textureToDownload = static_cast(resourceToDownload); + const Texture* textureDest = static_cast(resourceDest); + + if (textureToDownload != nullptr && textureDest != nullptr) + { + assert(textureToDownload->desc.Width <= textureDest->desc.Width); + assert(textureToDownload->desc.Height <= textureDest->desc.Height); + assert(textureToDownload->desc.Depth <= textureDest->desc.Depth); + assert(textureDest->desc.Usage & USAGE_STAGING); + assert(dataDest != nullptr); + + immediateContext->CopyResource((ID3D11Resource*)textureDest->resource, (ID3D11Resource*)textureToDownload->resource); + + D3D11_MAPPED_SUBRESOURCE mappedResource = {}; + HRESULT hr = immediateContext->Map((ID3D11Resource*)textureDest->resource, 0, D3D11_MAP_READ, 0, &mappedResource); + bool result = SUCCEEDED(hr); + if (result) + { + UINT cpycount = std::max(1u, textureToDownload->desc.Width) * std::max(1u, textureToDownload->desc.Height) * std::max(1u, textureToDownload->desc.Depth); + UINT cpystride = GetFormatStride(textureToDownload->desc.Format); + UINT cpysize = cpycount * cpystride; + memcpy(dataDest, mappedResource.pData, cpysize); + immediateContext->Unmap((ID3D11Resource*)textureDest->resource, 0); + } + + return result; + } + } + + return false; +} + void GraphicsDevice_DX11::SetName(GPUResource* pResource, const std::string& name) { ((ID3D11Resource*)pResource->resource)->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)name.length(), name.c_str()); } -void GraphicsDevice_DX11::PresentBegin() +void GraphicsDevice_DX11::PresentBegin(GRAPHICSTHREAD threadID) { + ViewPort viewPort; + viewPort.Width = (FLOAT)SCREENWIDTH; + viewPort.Height = (FLOAT)SCREENHEIGHT; + viewPort.MinDepth = 0.0f; + viewPort.MaxDepth = 1.0f; + viewPort.TopLeftX = 0; + viewPort.TopLeftY = 0; + BindViewports(1, &viewPort, threadID); + + deviceContexts[threadID]->OMSetRenderTargets(1, &renderTargetView, 0); + float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha + deviceContexts[threadID]->ClearRenderTargetView(renderTargetView, ClearColor); +} +void GraphicsDevice_DX11::PresentEnd(GRAPHICSTHREAD threadID) +{ + wiJobSystem::Wait(GetJobContext()); + // Execute deferred command lists: { GRAPHICSTHREAD threadID; while (active_commandlists.pop_front(threadID)) { deviceContexts[threadID]->FinishCommandList(false, &commandLists[threadID]); - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ExecuteCommandList(commandLists[threadID], false); + immediateContext->ExecuteCommandList(commandLists[threadID], false); commandLists[threadID]->Release(); commandLists[threadID] = nullptr; deviceContexts[threadID]->ClearState(); @@ -3074,40 +3141,11 @@ void GraphicsDevice_DX11::PresentBegin() } } - ViewPort viewPort; - viewPort.Width = (FLOAT)SCREENWIDTH; - viewPort.Height = (FLOAT)SCREENHEIGHT; - viewPort.MinDepth = 0.0f; - viewPort.MaxDepth = 1.0f; - viewPort.TopLeftX = 0; - viewPort.TopLeftY = 0; - BindViewports(1, &viewPort, GRAPHICSTHREAD_IMMEDIATE); - - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->OMSetRenderTargets(1, &renderTargetView, 0); - float ClearColor[4] = { 0, 0, 0, 1.0f }; // red,green,blue,alpha - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ClearRenderTargetView(renderTargetView, ClearColor); - -} -void GraphicsDevice_DX11::PresentEnd() -{ swapChain->Present(VSYNC, 0); - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->OMSetRenderTargets(0, nullptr, nullptr); - - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->ClearState(); - BindGraphicsPSO(nullptr, GRAPHICSTHREAD_IMMEDIATE); - BindComputePSO(nullptr, GRAPHICSTHREAD_IMMEDIATE); - - D3D11_RECT pRects[8]; - for (UINT i = 0; i < 8; ++i) - { - pRects[i].bottom = INT32_MAX; - pRects[i].left = INT32_MIN; - pRects[i].right = INT32_MAX; - pRects[i].top = INT32_MIN; - } - deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->RSSetScissorRects(8, pRects); + immediateContext->OMSetRenderTargets(0, nullptr, nullptr); + immediateContext->ClearState(); memset(prev_vs, 0, sizeof(prev_vs)); memset(prev_ps, 0, sizeof(prev_ps)); @@ -3141,6 +3179,7 @@ GRAPHICSTHREAD GraphicsDevice_DX11::BeginCommandList() { // need to create one more command list: threadID = (GRAPHICSTHREAD)commandlist_count.fetch_add(1); + assert(threadID < GRAPHICSTHREAD_COUNT); HRESULT hr = device->CreateDeferredContext(0, &deviceContexts[threadID]); assert(SUCCEEDED(hr)); @@ -3149,11 +3188,32 @@ GRAPHICSTHREAD GraphicsDevice_DX11::BeginCommandList() reinterpret_cast(&userDefinedAnnotations[threadID])); assert(SUCCEEDED(hr)); + // Temporary allocations will use the following buffer type: + GPUBufferDesc frameAllocatorDesc; + frameAllocatorDesc.ByteWidth = 4 * 1024 * 1024; + frameAllocatorDesc.BindFlags = BIND_SHADER_RESOURCE | BIND_INDEX_BUFFER | BIND_VERTEX_BUFFER; + frameAllocatorDesc.Usage = USAGE_DYNAMIC; + frameAllocatorDesc.CPUAccessFlags = CPU_ACCESS_WRITE; + frameAllocatorDesc.MiscFlags = RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS; hr = CreateBuffer(&frameAllocatorDesc, nullptr, &frame_allocators[threadID].buffer); assert(SUCCEEDED(hr)); SetName(&frame_allocators[threadID].buffer, "frame_allocator[deferred]"); } + + BindGraphicsPSO(nullptr, threadID); + BindComputePSO(nullptr, threadID); + + D3D11_RECT pRects[8]; + for (UINT i = 0; i < 8; ++i) + { + pRects[i].bottom = INT32_MAX; + pRects[i].left = INT32_MIN; + pRects[i].right = INT32_MAX; + pRects[i].top = INT32_MIN; + } + deviceContexts[threadID]->RSSetScissorRects(8, pRects); + active_commandlists.push_back(threadID); return threadID; } @@ -3741,68 +3801,6 @@ void GraphicsDevice_DX11::UpdateBuffer(const GPUBuffer* buffer, const void* data deviceContexts[threadID]->UpdateSubresource((ID3D11Resource*)buffer->resource, 0, &box, data, 0, 0); } } -bool GraphicsDevice_DX11::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) -{ - assert(resourceToDownload->type == resourceDest->type); - - if(resourceToDownload->IsBuffer()) - { - const GPUBuffer* bufferToDownload = static_cast(resourceToDownload); - const GPUBuffer* bufferDest = static_cast(resourceDest); - - if (bufferToDownload != nullptr && bufferDest != nullptr) - { - assert(bufferToDownload->desc.ByteWidth <= bufferDest->desc.ByteWidth); - assert(bufferDest->desc.Usage & USAGE_STAGING); - assert(dataDest != nullptr); - - deviceContexts[threadID]->CopyResource((ID3D11Resource*)bufferDest->resource, (ID3D11Resource*)bufferToDownload->resource); - - D3D11_MAPPED_SUBRESOURCE mappedResource = {}; - HRESULT hr = deviceContexts[threadID]->Map((ID3D11Resource*)bufferDest->resource, 0, D3D11_MAP_READ, /*async ? D3D11_MAP_FLAG_DO_NOT_WAIT :*/ 0, &mappedResource); - bool result = SUCCEEDED(hr); - if (result) - { - memcpy(dataDest, mappedResource.pData, bufferToDownload->desc.ByteWidth); - deviceContexts[threadID]->Unmap((ID3D11Resource*)bufferDest->resource, 0); - } - - return result; - } - } - else if(resourceToDownload->IsTexture()) - { - const Texture* textureToDownload = static_cast(resourceToDownload); - const Texture* textureDest = static_cast(resourceDest); - - if (textureToDownload != nullptr && textureDest != nullptr) - { - assert(textureToDownload->desc.Width <= textureDest->desc.Width); - assert(textureToDownload->desc.Height <= textureDest->desc.Height); - assert(textureToDownload->desc.Depth <= textureDest->desc.Depth); - assert(textureDest->desc.Usage & USAGE_STAGING); - assert(dataDest != nullptr); - - deviceContexts[threadID]->CopyResource((ID3D11Resource*)textureDest->resource, (ID3D11Resource*)textureToDownload->resource); - - D3D11_MAPPED_SUBRESOURCE mappedResource = {}; - HRESULT hr = deviceContexts[threadID]->Map((ID3D11Resource*)textureDest->resource, 0, D3D11_MAP_READ, 0, &mappedResource); - bool result = SUCCEEDED(hr); - if (result) - { - UINT cpycount = std::max(1u, textureToDownload->desc.Width) * std::max(1u, textureToDownload->desc.Height) * std::max(1u, textureToDownload->desc.Depth); - UINT cpystride = GetFormatStride(textureToDownload->desc.Format); - UINT cpysize = cpycount * cpystride; - memcpy(dataDest, mappedResource.pData, cpysize); - deviceContexts[threadID]->Unmap((ID3D11Resource*)textureDest->resource, 0); - } - - return result; - } - } - - return false; -} void GraphicsDevice_DX11::QueryBegin(const GPUQuery* query, GRAPHICSTHREAD threadID) { @@ -3822,24 +3820,24 @@ bool GraphicsDevice_DX11::QueryRead(const GPUQuery* query, GPUQueryResult* resul switch (query->desc.Type) { case GPU_QUERY_TYPE_TIMESTAMP: - hr = deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->GetData(QUERY, &result->result_timestamp, sizeof(result->result_timestamp), _flags); + hr = immediateContext->GetData(QUERY, &result->result_timestamp, sizeof(result->result_timestamp), _flags); break; case GPU_QUERY_TYPE_TIMESTAMP_DISJOINT: { D3D11_QUERY_DATA_TIMESTAMP_DISJOINT _temp; - hr = deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->GetData(QUERY, &_temp, sizeof(_temp), _flags); + hr = immediateContext->GetData(QUERY, &_temp, sizeof(_temp), _flags); result->result_disjoint = _temp.Disjoint; result->result_timestamp_frequency = _temp.Frequency; } break; case GPU_QUERY_TYPE_OCCLUSION: - hr = deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->GetData(QUERY, &result->result_passed_sample_count, sizeof(result->result_passed_sample_count), _flags); + hr = immediateContext->GetData(QUERY, &result->result_passed_sample_count, sizeof(result->result_passed_sample_count), _flags); result->result_passed = result->result_passed_sample_count != 0; break; case GPU_QUERY_TYPE_EVENT: case GPU_QUERY_TYPE_OCCLUSION_PREDICATE: default: - hr = deviceContexts[GRAPHICSTHREAD_IMMEDIATE]->GetData(QUERY, &result->result_passed, sizeof(result->result_passed), _flags); + hr = immediateContext->GetData(QUERY, &result->result_passed, sizeof(result->result_passed), _flags); break; } @@ -3864,7 +3862,7 @@ GraphicsDevice::GPUAllocation GraphicsDevice_DX11::AllocateGPU(size_t dataSize, dataSize = std::min(size_t(allocator.buffer.desc.ByteWidth), dataSize); size_t position = allocator.byteOffset; - bool wrap = position + dataSize > allocator.buffer.desc.ByteWidth || allocator.residentFrame != FRAMECOUNT; + bool wrap = position == 0 || position + dataSize > allocator.buffer.desc.ByteWidth || allocator.residentFrame != FRAMECOUNT; position = wrap ? 0 : position; // Issue buffer rename (realloc) on wrap, otherwise just append data: diff --git a/WickedEngine/wiGraphicsDevice_DX11.h b/WickedEngine/wiGraphicsDevice_DX11.h index 885b22128..506366d97 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.h +++ b/WickedEngine/wiGraphicsDevice_DX11.h @@ -23,6 +23,7 @@ namespace wiGraphics IDXGISwapChain1* swapChain = nullptr; ID3D11RenderTargetView* renderTargetView = nullptr; ID3D11Texture2D* backBuffer = nullptr; + ID3D11DeviceContext* immediateContext = nullptr; ID3D11DeviceContext* deviceContexts[GRAPHICSTHREAD_COUNT] = {}; ID3D11CommandList* commandLists[GRAPHICSTHREAD_COUNT] = {}; ID3DUserDefinedAnnotation* userDefinedAnnotations[GRAPHICSTHREAD_COUNT] = {}; @@ -57,14 +58,13 @@ namespace wiGraphics uint64_t residentFrame = 0; bool dirty = false; } frame_allocators[GRAPHICSTHREAD_COUNT]; - GPUBufferDesc frameAllocatorDesc; void commit_allocations(GRAPHICSTHREAD threadID); void CreateBackBufferResources(); - std::atomic commandlist_count = 1; // first is always immediate command list - wiContainers::ThreadSafeRingBuffer free_commandlists; - wiContainers::ThreadSafeRingBuffer active_commandlists; + std::atomic commandlist_count = 0; + wiContainers::ThreadSafeRingBuffer free_commandlists; + wiContainers::ThreadSafeRingBuffer active_commandlists; public: GraphicsDevice_DX11(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); @@ -110,11 +110,12 @@ namespace wiGraphics void DestroyGraphicsPSO(GraphicsPSO* pso) override; void DestroyComputePSO(ComputePSO* pso) override; + bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; void SetName(GPUResource* pResource, const std::string& name) override; - void PresentBegin() override; - void PresentEnd() override; + void PresentBegin(GRAPHICSTHREAD threadID) override; + void PresentEnd(GRAPHICSTHREAD threadID) override; void WaitForGPU() override; @@ -157,7 +158,6 @@ namespace wiGraphics void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, GRAPHICSTHREAD threadID) override; void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, GRAPHICSTHREAD threadID) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, GRAPHICSTHREAD threadID, int dataSize = -1) override; - bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) override; void QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) override; void QueryEnd(const GPUQuery *query, GRAPHICSTHREAD threadID) override; bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override; diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 024648b7d..6f3f110c8 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1538,41 +1538,6 @@ namespace wiGraphics // Engine functions ID3D12GraphicsCommandList* GraphicsDevice_DX12::GetDirectCommandList(GRAPHICSTHREAD threadID) { return static_cast(GetFrameResources().commandLists[threadID]); } - void GraphicsDevice_DX12::ResetCommandList(GRAPHICSTHREAD threadID) - { - // Start the command list in a default state: - - HRESULT hr = GetFrameResources().commandAllocators[threadID]->Reset(); - assert(SUCCEEDED(hr)); - hr = static_cast(GetFrameResources().commandLists[threadID])->Reset(GetFrameResources().commandAllocators[threadID], nullptr); - assert(SUCCEEDED(hr)); - - - ID3D12DescriptorHeap* heaps[] = { - GetFrameResources().ResourceDescriptorsGPU[threadID]->heap_GPU, GetFrameResources().SamplerDescriptorsGPU[threadID]->heap_GPU - }; - GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetDescriptorHeaps(ARRAYSIZE(heaps), heaps); - - GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetGraphicsRootSignature(graphicsRootSig); - GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetComputeRootSignature(computeRootSig); - - D3D12_CPU_DESCRIPTOR_HANDLE nullDescriptors[] = { - nullSampler,nullCBV,nullSRV,nullUAV - }; - GetFrameResources().ResourceDescriptorsGPU[threadID]->reset(device, nullDescriptors); - GetFrameResources().SamplerDescriptorsGPU[threadID]->reset(device, nullDescriptors); - GetFrameResources().resourceBuffer[threadID]->clear(); - - D3D12_RECT pRects[8]; - for (UINT i = 0; i < 8; ++i) - { - pRects[i].bottom = INT32_MAX; - pRects[i].left = INT32_MIN; - pRects[i].right = INT32_MAX; - pRects[i].top = INT32_MIN; - } - GetDirectCommandList((GRAPHICSTHREAD)threadID)->RSSetScissorRects(8, pRects); - } GraphicsDevice_DX12::GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen, bool debuglayer) { @@ -1733,14 +1698,6 @@ namespace wiGraphics hr = swapChain->GetBuffer(fr, __uuidof(ID3D12Resource), (void**)&frames[fr].backBuffer); frames[fr].backBufferRTV.ptr = RTAllocator->allocate(); device->CreateRenderTargetView(frames[fr].backBuffer, nullptr, frames[fr].backBufferRTV); - - hr = device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, __uuidof(ID3D12CommandAllocator), (void**)&frames[fr].commandAllocators[GRAPHICSTHREAD_IMMEDIATE]); - hr = device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, frames[fr].commandAllocators[GRAPHICSTHREAD_IMMEDIATE], nullptr, __uuidof(ID3D12GraphicsCommandList), (void**)&frames[fr].commandLists[GRAPHICSTHREAD_IMMEDIATE]); - hr = static_cast(frames[fr].commandLists[GRAPHICSTHREAD_IMMEDIATE])->Close(); - - frames[fr].ResourceDescriptorsGPU[GRAPHICSTHREAD_IMMEDIATE] = new FrameResources::DescriptorTableFrameAllocator(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 1024); - frames[fr].SamplerDescriptorsGPU[GRAPHICSTHREAD_IMMEDIATE] = new FrameResources::DescriptorTableFrameAllocator(device, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, 16); - frames[fr].resourceBuffer[GRAPHICSTHREAD_IMMEDIATE] = new FrameResources::ResourceFrameAllocator(device, 1024 * 1024 * 4); } @@ -1982,8 +1939,6 @@ namespace wiGraphics hr = device->CreateCommandSignature(&cmd_desc, nullptr, __uuidof(ID3D12CommandSignature), (void**)&drawIndexedInstancedIndirectCommandSignature); assert(SUCCEEDED(hr)); - ResetCommandList(GRAPHICSTHREAD_IMMEDIATE); - wiBackLog::post("Created GraphicsDevice_DX12"); } GraphicsDevice_DX12::~GraphicsDevice_DX12() @@ -3328,6 +3283,10 @@ namespace wiGraphics } } + bool GraphicsDevice_DX12::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) + { + return false; + } void GraphicsDevice_DX12::SetName(GPUResource* pResource, const std::string& name) { @@ -3335,8 +3294,55 @@ namespace wiGraphics } - void GraphicsDevice_DX12::PresentBegin() + void GraphicsDevice_DX12::PresentBegin(GRAPHICSTHREAD threadID) { + BindViewports(1, &viewPort, threadID); + + + // Record commands in the command list now. + // Start by setting the resource barrier. + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barrier.Transition.pResource = GetFrameResources().backBuffer; + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + GetDirectCommandList(threadID)->ResourceBarrier(1, &barrier); + + + // Set the back buffer as the render target. + GetDirectCommandList(threadID)->OMSetRenderTargets(1, &GetFrameResources().backBufferRTV, FALSE, NULL); + + + // Then set the color to clear the window to. + float color[4]; + color[0] = 0.0; + color[1] = 0.0; + color[2] = 0.0; + color[3] = 1.0; + GetDirectCommandList(threadID)->ClearRenderTargetView(GetFrameResources().backBufferRTV, color, 0, NULL); + + + } + void GraphicsDevice_DX12::PresentEnd(GRAPHICSTHREAD threadID) + { + wiJobSystem::Wait(jobsystem_ctx); + + HRESULT result; + + // Indicate that the back buffer will now be used to present. + D3D12_RESOURCE_BARRIER barrier = {}; + barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; + barrier.Transition.pResource = GetFrameResources().backBuffer; + barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; + barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; + barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; + barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; + GetDirectCommandList(threadID)->ResourceBarrier(1, &barrier); + + + // Sync up copy queue: copyQueueLock.lock(); { @@ -3372,10 +3378,10 @@ namespace wiGraphics GRAPHICSTHREAD threadID; while (active_commandlists.pop_front(threadID)) { - HRESULT hr = GetDirectCommandList((GRAPHICSTHREAD)threadID)->Close(); + HRESULT hr = GetDirectCommandList(threadID)->Close(); assert(SUCCEEDED(hr)); - cmdLists[counter] = GetDirectCommandList((GRAPHICSTHREAD)threadID); + cmdLists[counter] = GetDirectCommandList(threadID); threadIDs[counter] = threadID; counter++; @@ -3386,56 +3392,6 @@ namespace wiGraphics } - BindViewports(1, &viewPort, GRAPHICSTHREAD_IMMEDIATE); - - - // Record commands in the command list now. - // Start by setting the resource barrier. - D3D12_RESOURCE_BARRIER barrier = {}; - barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; - barrier.Transition.pResource = GetFrameResources().backBuffer; - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; - barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; - barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->ResourceBarrier(1, &barrier); - - - // Set the back buffer as the render target. - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->OMSetRenderTargets(1, &GetFrameResources().backBufferRTV, FALSE, NULL); - - - // Then set the color to clear the window to. - float color[4]; - color[0] = 0.0; - color[1] = 0.0; - color[2] = 0.0; - color[3] = 1.0; - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->ClearRenderTargetView(GetFrameResources().backBufferRTV, color, 0, NULL); - - - } - void GraphicsDevice_DX12::PresentEnd() - { - HRESULT result; - - // Indicate that the back buffer will now be used to present. - D3D12_RESOURCE_BARRIER barrier = {}; - barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; - barrier.Transition.pResource = GetFrameResources().backBuffer; - barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; - barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT; - barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; - barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; - GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->ResourceBarrier(1, &barrier); - - // Close the list of commands. - result = GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)->Close(); - - // Execute the list of commands. - directQueue->ExecuteCommandLists(1, GetFrameResources().commandLists); - - swapChain->Present(VSYNC, 0); @@ -3458,8 +3414,6 @@ namespace wiGraphics WaitForSingleObject(frameFenceEvent, INFINITE); } - ResetCommandList(GRAPHICSTHREAD_IMMEDIATE); - memset(prev_pt, 0, sizeof(prev_pt)); RESOLUTIONCHANGED = false; @@ -3472,6 +3426,7 @@ namespace wiGraphics { // need to create one more command list: threadID = (GRAPHICSTHREAD)commandlist_count.fetch_add(1); + assert(threadID < GRAPHICSTHREAD_COUNT); HRESULT hr; for (UINT fr = 0; fr < BACKBUFFER_COUNT; ++fr) @@ -3486,7 +3441,39 @@ namespace wiGraphics } } - ResetCommandList(threadID); + + // Start the command list in a default state: + + HRESULT hr = GetFrameResources().commandAllocators[threadID]->Reset(); + assert(SUCCEEDED(hr)); + hr = static_cast(GetFrameResources().commandLists[threadID])->Reset(GetFrameResources().commandAllocators[threadID], nullptr); + assert(SUCCEEDED(hr)); + + + ID3D12DescriptorHeap* heaps[] = { + GetFrameResources().ResourceDescriptorsGPU[threadID]->heap_GPU, GetFrameResources().SamplerDescriptorsGPU[threadID]->heap_GPU + }; + GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetDescriptorHeaps(ARRAYSIZE(heaps), heaps); + + GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetGraphicsRootSignature(graphicsRootSig); + GetDirectCommandList((GRAPHICSTHREAD)threadID)->SetComputeRootSignature(computeRootSig); + + D3D12_CPU_DESCRIPTOR_HANDLE nullDescriptors[] = { + nullSampler,nullCBV,nullSRV,nullUAV + }; + GetFrameResources().ResourceDescriptorsGPU[threadID]->reset(device, nullDescriptors); + GetFrameResources().SamplerDescriptorsGPU[threadID]->reset(device, nullDescriptors); + GetFrameResources().resourceBuffer[threadID]->clear(); + + D3D12_RECT pRects[8]; + for (UINT i = 0; i < 8; ++i) + { + pRects[i].bottom = INT32_MAX; + pRects[i].left = INT32_MIN; + pRects[i].right = INT32_MAX; + pRects[i].top = INT32_MIN; + } + GetDirectCommandList((GRAPHICSTHREAD)threadID)->RSSetScissorRects(8, pRects); active_commandlists.push_back(threadID); @@ -3923,10 +3910,6 @@ namespace wiGraphics GetDirectCommandList(threadID)->ResourceBarrier(1, &barrier); } - bool GraphicsDevice_DX12::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) - { - return false; - } void GraphicsDevice_DX12::QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) { diff --git a/WickedEngine/wiGraphicsDevice_DX12.h b/WickedEngine/wiGraphicsDevice_DX12.h index f03bc1718..e45cc8e8e 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.h +++ b/WickedEngine/wiGraphicsDevice_DX12.h @@ -139,11 +139,9 @@ namespace wiGraphics PRIMITIVETOPOLOGY prev_pt[GRAPHICSTHREAD_COUNT] = {}; - void ResetCommandList(GRAPHICSTHREAD threadID); - - std::atomic commandlist_count = 1; // first is always immediate command list - wiContainers::ThreadSafeRingBuffer free_commandlists; - wiContainers::ThreadSafeRingBuffer active_commandlists; + std::atomic commandlist_count = 0; + wiContainers::ThreadSafeRingBuffer free_commandlists; + wiContainers::ThreadSafeRingBuffer active_commandlists; public: GraphicsDevice_DX12(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); @@ -189,10 +187,12 @@ namespace wiGraphics void DestroyGraphicsPSO(GraphicsPSO* pso) override; void DestroyComputePSO(ComputePSO* pso) override; + bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; + void SetName(GPUResource* pResource, const std::string& name) override; - void PresentBegin() override; - void PresentEnd() override; + void PresentBegin(GRAPHICSTHREAD threadID) override; + void PresentEnd(GRAPHICSTHREAD threadID) override; virtual GRAPHICSTHREAD BeginCommandList() override; @@ -235,7 +235,6 @@ namespace wiGraphics void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, GRAPHICSTHREAD threadID) override; void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, GRAPHICSTHREAD threadID) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, GRAPHICSTHREAD threadID, int dataSize = -1) override; - bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) override; void QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) override; void QueryEnd(const GPUQuery *query, GRAPHICSTHREAD threadID) override; bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 1d9bc9108..370bf903b 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -1570,54 +1570,6 @@ namespace wiGraphics // Engine functions VkCommandBuffer GraphicsDevice_Vulkan::GetDirectCommandList(GRAPHICSTHREAD threadID) { return GetFrameResources().commandBuffers[threadID]; } - void GraphicsDevice_Vulkan::ResetCommandList(GRAPHICSTHREAD threadID) - { - VkResult res; - res = vkResetCommandPool(device, GetFrameResources().commandPools[threadID], 0); - assert(res == VK_SUCCESS); - - VkCommandBufferBeginInfo beginInfo = {}; - beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; - beginInfo.pInheritanceInfo = nullptr; // Optional - - res = vkBeginCommandBuffer(GetFrameResources().commandBuffers[threadID], &beginInfo); - assert(res == VK_SUCCESS); - - VkViewport viewports[6]; - for (UINT i = 0; i < ARRAYSIZE(viewports); ++i) - { - viewports[i].x = 0; - viewports[i].y = 0; - viewports[i].width = static_cast(SCREENWIDTH); - viewports[i].height = static_cast(SCREENHEIGHT); - viewports[i].minDepth = 0; - viewports[i].maxDepth = 1; - } - vkCmdSetViewport(GetDirectCommandList(static_cast(threadID)), 0, ARRAYSIZE(viewports), viewports); - - VkRect2D scissors[8]; - for (int i = 0; i < ARRAYSIZE(scissors); ++i) - { - scissors[i].offset.x = 0; - scissors[i].offset.y = 0; - scissors[i].extent.width = 65535; - scissors[i].extent.height = 65535; - } - vkCmdSetScissor(GetDirectCommandList(static_cast(threadID)), 0, ARRAYSIZE(scissors), scissors); - - float blendConstants[] = { 1,1,1,1 }; - vkCmdSetBlendConstants(GetDirectCommandList(static_cast(threadID)), blendConstants); - - - // reset descriptor allocators: - GetFrameResources().ResourceDescriptorsGPU[threadID]->reset(); - - // reset immediate resource allocators: - GetFrameResources().resourceBuffer[threadID]->clear(); - - renderPass[threadID].reset(); - } GraphicsDevice_Vulkan::GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen, bool debuglayer) { @@ -2186,41 +2138,6 @@ namespace wiGraphics } } - // Create immediate command buffer: - { - QueueFamilyIndices queueFamilyIndices = findQueueFamilies(physicalDevice, surface); - - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; - - VkCommandPoolCreateInfo poolInfo = {}; - poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily; - poolInfo.flags = 0; // Optional - - if (vkCreateCommandPool(device, &poolInfo, nullptr, &frame.commandPools[threadID]) != VK_SUCCESS) { - throw std::runtime_error("failed to create command pool!"); - } - - VkCommandBufferAllocateInfo commandBufferInfo = {}; - commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - commandBufferInfo.commandBufferCount = 1; - commandBufferInfo.commandPool = frame.commandPools[threadID]; - commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - - if (vkAllocateCommandBuffers(device, &commandBufferInfo, &frame.commandBuffers[threadID]) != VK_SUCCESS) { - throw std::runtime_error("failed to create command buffers!"); - } - - VkCommandBufferBeginInfo beginInfo = {}; - beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; - beginInfo.pInheritanceInfo = nullptr; // Optional - - VkResult res = vkBeginCommandBuffer(frame.commandBuffers[threadID], &beginInfo); - assert(res == VK_SUCCESS); - - } - // Create immediate resource allocators: for (int threadID = 0; threadID < GRAPHICSTHREAD_COUNT; ++threadID) @@ -2400,8 +2317,6 @@ namespace wiGraphics } } - ResetCommandList(GRAPHICSTHREAD_IMMEDIATE); - wiBackLog::post("Created GraphicsDevice_Vulkan"); } GraphicsDevice_Vulkan::~GraphicsDevice_Vulkan() @@ -4217,6 +4132,10 @@ namespace wiGraphics pso->pipeline = WI_NULL_HANDLE; } + bool GraphicsDevice_Vulkan::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) + { + return false; + } void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const std::string& name) { @@ -4224,8 +4143,61 @@ namespace wiGraphics } - void GraphicsDevice_Vulkan::PresentBegin() + void GraphicsDevice_Vulkan::PresentBegin(GRAPHICSTHREAD threadID) { + renderPass[threadID].disable(GetDirectCommandList(threadID)); + + VkClearValue clearColor = { 0.0f, 0.0f, 0.0f, 1.0f }; + + renderPass[threadID].dirty = true; + renderPass[threadID].attachmentCount = 1; + renderPass[threadID].attachments[0] = GetFrameResources().swapChainImageView; + renderPass[threadID].attachmentsExtents = swapChainExtent; + renderPass[threadID].clearColor[0] = clearColor; + renderPass[threadID].overrideRenderPass = defaultRenderPass; + renderPass[threadID].overrideFramebuffer = GetFrameResources().swapChainFramebuffer; + + renderPass[threadID].validate(device, GetDirectCommandList(threadID)); + + + VkClearAttachment clearInfo = {}; + clearInfo.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + clearInfo.clearValue = clearColor; + clearInfo.colorAttachment = 0; + + VkClearRect rect = {}; + rect.baseArrayLayer = 0; + rect.layerCount = 1; + rect.rect.offset.x = 0; + rect.rect.offset.y = 0; + rect.rect.extent.width = SCREENWIDTH; + rect.rect.extent.height = SCREENHEIGHT; + + vkCmdClearAttachments(GetDirectCommandList(threadID), 1, &clearInfo, 1, &rect); + + + } + void GraphicsDevice_Vulkan::PresentEnd(GRAPHICSTHREAD threadID) + { + wiJobSystem::Wait(jobsystem_ctx); + + VkResult res; + + uint64_t currentframe = GetFrameCount() % BACKBUFFER_COUNT; + uint32_t imageIndex; + vkAcquireNextImageKHR(device, swapChain, 0xFFFFFFFFFFFFFFFF, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex); + assert(imageIndex == currentframe); + + + + // ...end presentation render pass + renderPass[threadID].disable(GetDirectCommandList(threadID)); + + if (vkEndCommandBuffer(GetDirectCommandList(threadID)) != VK_SUCCESS) { + throw std::runtime_error("failed to record command buffer!"); + } + + // Sync up copy queue: copyQueueLock.lock(); { @@ -4269,6 +4241,9 @@ namespace wiGraphics } copyQueueLock.unlock(); + + VkSemaphore signalSemaphores[] = { renderFinishedSemaphore }; + // Execute deferred command lists: { VkCommandBuffer cmdLists[GRAPHICSTHREAD_COUNT]; @@ -4278,11 +4253,11 @@ namespace wiGraphics GRAPHICSTHREAD threadID; while (active_commandlists.pop_front(threadID)) { - if (vkEndCommandBuffer(GetDirectCommandList((GRAPHICSTHREAD)threadID)) != VK_SUCCESS) { + if (vkEndCommandBuffer(GetDirectCommandList(threadID)) != VK_SUCCESS) { throw std::runtime_error("failed to record command buffer!"); } - cmdLists[counter] = GetDirectCommandList((GRAPHICSTHREAD)threadID); + cmdLists[counter] = GetDirectCommandList(threadID); threadIDs[counter] = threadID; counter++; @@ -4292,131 +4267,22 @@ namespace wiGraphics VkSubmitInfo submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submitInfo.waitSemaphoreCount = 0; - submitInfo.pWaitSemaphores = nullptr; - submitInfo.pWaitDstStageMask = nullptr; + VkSemaphore waitSemaphores[] = { imageAvailableSemaphore }; + VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; + submitInfo.waitSemaphoreCount = 1; + submitInfo.pWaitSemaphores = waitSemaphores; + submitInfo.pWaitDstStageMask = waitStages; submitInfo.commandBufferCount = counter; submitInfo.pCommandBuffers = cmdLists; - submitInfo.signalSemaphoreCount = 0; - submitInfo.pSignalSemaphores = nullptr; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = signalSemaphores; - if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE) != VK_SUCCESS) { + if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, GetFrameResources().frameFence) != VK_SUCCESS) { throw std::runtime_error("failed to submit draw command buffer!"); } } - renderPass[GRAPHICSTHREAD_IMMEDIATE].disable(GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)); - - //VkClearValue clearColor = { (FRAMECOUNT % 256) / 255.0f, 0.0f, 0.0f, 1.0f }; - VkClearValue clearColor = { 0.0f, 0.0f, 0.0f, 1.0f }; - - //VkRenderPassBeginInfo renderPassInfo = {}; - //renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - //renderPassInfo.renderPass = defaultRenderPass; - //renderPassInfo.framebuffer = GetFrameResources().swapChainFramebuffer; - //renderPassInfo.renderArea.offset = { 0, 0 }; - //renderPassInfo.renderArea.extent = swapChainExtent; - //renderPassInfo.clearValueCount = 1; - //renderPassInfo.pClearValues = &clearColor; - - // Begin presentation render pass... - //vkCmdBeginRenderPass(GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE), &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); - - renderPass[GRAPHICSTHREAD_IMMEDIATE].dirty = true; - renderPass[GRAPHICSTHREAD_IMMEDIATE].attachmentCount = 1; - renderPass[GRAPHICSTHREAD_IMMEDIATE].attachments[0] = GetFrameResources().swapChainImageView; - renderPass[GRAPHICSTHREAD_IMMEDIATE].attachmentsExtents = swapChainExtent; - renderPass[GRAPHICSTHREAD_IMMEDIATE].clearColor[0] = clearColor; - renderPass[GRAPHICSTHREAD_IMMEDIATE].overrideRenderPass = defaultRenderPass; - renderPass[GRAPHICSTHREAD_IMMEDIATE].overrideFramebuffer = GetFrameResources().swapChainFramebuffer; - - renderPass[GRAPHICSTHREAD_IMMEDIATE].validate(device, GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)); - - - VkClearAttachment clearInfo = {}; - clearInfo.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - clearInfo.clearValue = clearColor; - clearInfo.colorAttachment = 0; - - VkClearRect rect = {}; - rect.baseArrayLayer = 0; - rect.layerCount = 1; - rect.rect.offset.x = 0; - rect.rect.offset.y = 0; - rect.rect.extent.width = SCREENWIDTH; - rect.rect.extent.height = SCREENHEIGHT; - - vkCmdClearAttachments(GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE), 1, &clearInfo, 1, &rect); - - - } - void GraphicsDevice_Vulkan::PresentEnd() - { - VkResult res; - - uint64_t currentframe = GetFrameCount() % BACKBUFFER_COUNT; - uint32_t imageIndex; - vkAcquireNextImageKHR(device, swapChain, 0xFFFFFFFFFFFFFFFF, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex); - assert(imageIndex == currentframe); - - - - // ...end presentation render pass - renderPass[GRAPHICSTHREAD_IMMEDIATE].disable(GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)); - - - - - //VkImageMemoryBarrier barrier = {}; - //barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; - //barrier.image = swapChainImages[imageIndex]; - //barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL; - //barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR; - //barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; - //barrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT; - //barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - //barrier.subresourceRange.baseArrayLayer = 0; - //barrier.subresourceRange.layerCount = 1; - //barrier.subresourceRange.baseMipLevel = 0; - //barrier.subresourceRange.levelCount = 1; - //vkCmdPipelineBarrier( - // GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE), - // VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - // VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - // VK_DEPENDENCY_BY_REGION_BIT, - // 0, nullptr, - // 0, nullptr, - // 1, &barrier - //); - - - - if (vkEndCommandBuffer(GetDirectCommandList(GRAPHICSTHREAD_IMMEDIATE)) != VK_SUCCESS) { - throw std::runtime_error("failed to record command buffer!"); - } - - - VkSubmitInfo submitInfo = {}; - submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - - VkSemaphore waitSemaphores[] = { imageAvailableSemaphore }; - VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; - submitInfo.waitSemaphoreCount = 1; - submitInfo.pWaitSemaphores = waitSemaphores; - submitInfo.pWaitDstStageMask = waitStages; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = GetFrameResources().commandBuffers; - - VkSemaphore signalSemaphores[] = { renderFinishedSemaphore }; - submitInfo.signalSemaphoreCount = 1; - submitInfo.pSignalSemaphores = signalSemaphores; - - if (vkQueueSubmit(graphicsQueue, 1, &submitInfo, GetFrameResources().frameFence) != VK_SUCCESS) { - throw std::runtime_error("failed to submit draw command buffer!"); - } - - VkPresentInfoKHR presentInfo = {}; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; @@ -4448,8 +4314,6 @@ namespace wiGraphics assert(res == VK_SUCCESS); } - ResetCommandList(GRAPHICSTHREAD_IMMEDIATE); - RESOLUTIONCHANGED = false; } @@ -4460,6 +4324,7 @@ namespace wiGraphics { // need to create one more command list: threadID = (GRAPHICSTHREAD)commandlist_count.fetch_add(1); + assert(threadID < GRAPHICSTHREAD_COUNT); QueueFamilyIndices queueFamilyIndices = findQueueFamilies(physicalDevice, surface); @@ -4494,7 +4359,52 @@ namespace wiGraphics } } - ResetCommandList(threadID); + + VkResult res; + res = vkResetCommandPool(device, GetFrameResources().commandPools[threadID], 0); + assert(res == VK_SUCCESS); + + VkCommandBufferBeginInfo beginInfo = {}; + beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + beginInfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT; + beginInfo.pInheritanceInfo = nullptr; // Optional + + res = vkBeginCommandBuffer(GetFrameResources().commandBuffers[threadID], &beginInfo); + assert(res == VK_SUCCESS); + + VkViewport viewports[6]; + for (UINT i = 0; i < ARRAYSIZE(viewports); ++i) + { + viewports[i].x = 0; + viewports[i].y = 0; + viewports[i].width = static_cast(SCREENWIDTH); + viewports[i].height = static_cast(SCREENHEIGHT); + viewports[i].minDepth = 0; + viewports[i].maxDepth = 1; + } + vkCmdSetViewport(GetDirectCommandList(static_cast(threadID)), 0, ARRAYSIZE(viewports), viewports); + + VkRect2D scissors[8]; + for (int i = 0; i < ARRAYSIZE(scissors); ++i) + { + scissors[i].offset.x = 0; + scissors[i].offset.y = 0; + scissors[i].extent.width = 65535; + scissors[i].extent.height = 65535; + } + vkCmdSetScissor(GetDirectCommandList(static_cast(threadID)), 0, ARRAYSIZE(scissors), scissors); + + float blendConstants[] = { 1,1,1,1 }; + vkCmdSetBlendConstants(GetDirectCommandList(static_cast(threadID)), blendConstants); + + + // reset descriptor allocators: + GetFrameResources().ResourceDescriptorsGPU[threadID]->reset(); + + // reset immediate resource allocators: + GetFrameResources().resourceBuffer[threadID]->clear(); + + renderPass[threadID].reset(); active_commandlists.push_back(threadID); @@ -5128,10 +5038,6 @@ namespace wiGraphics } - bool GraphicsDevice_Vulkan::DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) - { - return false; - } void GraphicsDevice_Vulkan::QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) { diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.h b/WickedEngine/wiGraphicsDevice_Vulkan.h index 90513fb2d..d43d58411 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.h +++ b/WickedEngine/wiGraphicsDevice_Vulkan.h @@ -198,11 +198,9 @@ namespace wiGraphics UploadBuffer* bufferUploader; UploadBuffer* textureUploader; - void ResetCommandList(GRAPHICSTHREAD threadID); - - std::atomic commandlist_count = 1; // first is always immediate command list - wiContainers::ThreadSafeRingBuffer free_commandlists; - wiContainers::ThreadSafeRingBuffer active_commandlists; + std::atomic commandlist_count = 0; + wiContainers::ThreadSafeRingBuffer free_commandlists; + wiContainers::ThreadSafeRingBuffer active_commandlists; public: GraphicsDevice_Vulkan(wiWindowRegistration::window_type window, bool fullscreen = false, bool debuglayer = false); @@ -248,10 +246,12 @@ namespace wiGraphics void DestroyGraphicsPSO(GraphicsPSO* pso) override; void DestroyComputePSO(ComputePSO* pso) override; + bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; + void SetName(GPUResource* pResource, const std::string& name) override; - void PresentBegin() override; - void PresentEnd() override; + void PresentBegin(GRAPHICSTHREAD threadID) override; + void PresentEnd(GRAPHICSTHREAD threadID) override; virtual GRAPHICSTHREAD BeginCommandList() override; @@ -294,7 +294,6 @@ namespace wiGraphics void CopyTexture2D_Region(const Texture2D* pDst, UINT dstMip, UINT dstX, UINT dstY, const Texture2D* pSrc, UINT srcMip, GRAPHICSTHREAD threadID) override; void MSAAResolve(const Texture2D* pDst, const Texture2D* pSrc, GRAPHICSTHREAD threadID) override; void UpdateBuffer(const GPUBuffer* buffer, const void* data, GRAPHICSTHREAD threadID, int dataSize = -1) override; - bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest, GRAPHICSTHREAD threadID) override; void QueryBegin(const GPUQuery *query, GRAPHICSTHREAD threadID) override; void QueryEnd(const GPUQuery *query, GRAPHICSTHREAD threadID) override; bool QueryRead(const GPUQuery* query, GPUQueryResult* result) override; diff --git a/WickedEngine/wiHairParticle.h b/WickedEngine/wiHairParticle.h index b2cbc3b5e..799f6fd73 100644 --- a/WickedEngine/wiHairParticle.h +++ b/WickedEngine/wiHairParticle.h @@ -1,6 +1,7 @@ #pragma once #include "CommonInclude.h" #include "wiGraphicsDevice.h" +#include "wiEnums.h" #include "wiECS.h" #include "wiSceneSystem_Decl.h" #include "wiIntersect.h" diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 9a1cfd6bf..79be1b0c0 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -112,7 +112,7 @@ namespace wiHelper HRESULT hr = device->CreateTexture2D(&staging_desc, nullptr, &stagingTex); assert(SUCCEEDED(hr)); - bool download_success = device->DownloadResource(&texture, &stagingTex, data.data(), GRAPHICSTHREAD_IMMEDIATE); + bool download_success = device->DownloadResource(&texture, &stagingTex, data.data()); assert(download_success); return saveTextureToFile(data, desc, fileName); diff --git a/WickedEngine/wiProfiler.cpp b/WickedEngine/wiProfiler.cpp index bc2512434..90e94af76 100644 --- a/WickedEngine/wiProfiler.cpp +++ b/WickedEngine/wiProfiler.cpp @@ -24,7 +24,7 @@ namespace wiProfiler PROFILER_DOMAIN domain = DOMAIN_CPU; std::string name; float time = 0; - GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE; + GRAPHICSTHREAD threadID = GRAPHICSTHREAD_COUNT; wiTimer cpuBegin, cpuEnd; @@ -36,7 +36,7 @@ namespace wiProfiler std::unordered_map ranges; wiRenderer::GPUQueryRing<4> disjoint; - void BeginFrame() + void BeginFrame(GRAPHICSTHREAD threadID) { if (!ENABLED) return; @@ -52,14 +52,14 @@ namespace wiProfiler disjoint.Create(wiRenderer::GetDevice(), &desc); } - wiRenderer::GetDevice()->QueryBegin(disjoint.Get_GPU(), GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->QueryBegin(disjoint.Get_GPU(), threadID); } - void EndFrame() + void EndFrame(GRAPHICSTHREAD threadID) { if (!ENABLED || !initialized) return; - wiRenderer::GetDevice()->QueryEnd(disjoint.Get_GPU(), GRAPHICSTHREAD_IMMEDIATE); + wiRenderer::GetDevice()->QueryEnd(disjoint.Get_GPU(), threadID); GPUQueryResult disjoint_result; GPUQuery* disjoint_query = disjoint.Get_CPU(); diff --git a/WickedEngine/wiProfiler.h b/WickedEngine/wiProfiler.h index 91f146d61..4f01b5995 100644 --- a/WickedEngine/wiProfiler.h +++ b/WickedEngine/wiProfiler.h @@ -1,5 +1,5 @@ #pragma once -#include "wiEnums.h" +#include "wiGraphicsDevice.h" #include "wiHashString.h" #include @@ -15,13 +15,14 @@ namespace wiProfiler typedef size_t range_id; // Begin collecting profiling data for the current frame - void BeginFrame(); + void BeginFrame(GRAPHICSTHREAD threadID); // Finalize collecting profiling data for the current frame - void EndFrame(); + void EndFrame(GRAPHICSTHREAD threadID); // Start a profiling range - range_id BeginRange(const wiHashString& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_IMMEDIATE); + // If this is a GPU profiling range, you must provide a correct GRAPHICSTHREAD as last parameter! + range_id BeginRange(const wiHashString& name, PROFILER_DOMAIN domain, GRAPHICSTHREAD threadID = GRAPHICSTHREAD_COUNT); // End a profiling range void EndRange(range_id id); diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index 550223553..e232a4dd6 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -4391,8 +4391,6 @@ void OcclusionCulling_Read() if (!culling.culledObjects.empty()) { - device->EventBegin("Occlusion Culling Read", GRAPHICSTHREAD_IMMEDIATE); - Scene& scene = GetScene(); for (uint32_t instanceIndex : culling.culledObjects) @@ -4431,8 +4429,6 @@ void OcclusionCulling_Read() // leave this frame as occluded } } - - device->EventEnd(GRAPHICSTHREAD_IMMEDIATE); } wiProfiler::EndRange(range); // Occlusion Culling Read diff --git a/WickedEngine/wiSceneSystem.cpp b/WickedEngine/wiSceneSystem.cpp index a3c7a5b4b..307a78d69 100644 --- a/WickedEngine/wiSceneSystem.cpp +++ b/WickedEngine/wiSceneSystem.cpp @@ -872,7 +872,7 @@ namespace wiSceneSystem hr = device->CreateTexture2D(&staging_desc, nullptr, &stagingTex); assert(SUCCEEDED(hr)); - bool download_success = device->DownloadResource(lightmap.get(), &stagingTex, lightmapTextureData.data(), GRAPHICSTHREAD_IMMEDIATE); + bool download_success = device->DownloadResource(lightmap.get(), &stagingTex, lightmapTextureData.data()); assert(download_success); } FORMAT ObjectComponent::GetLightmapFormat() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index d95fca881..6f1888980 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -86,7 +86,7 @@ void wiWidget::Detach() this->parent = nullptr; ApplyTransform(); } -void wiWidget::RenderTooltip(const wiGUI* gui) const +void wiWidget::RenderTooltip(const wiGUI* gui, GRAPHICSTHREAD threadID) const { if (!IsEnabled() || !IsVisible()) { @@ -97,7 +97,7 @@ void wiWidget::RenderTooltip(const wiGUI* gui) const if (tooltipTimer > 25) { - gui->ResetScissor(); + gui->ResetScissor(threadID); XMFLOAT2 tooltipPos = XMFLOAT2(gui->pointerpos.x, gui->pointerpos.y); if (tooltipPos.y > wiRenderer::GetDevice()->GetScreenHeight()*0.8f) @@ -126,15 +126,15 @@ void wiWidget::RenderTooltip(const wiGUI* gui) const static const float _border = 2; float fontWidth = (float)tooltipFont.textWidth() + _border * 2; float fontHeight = (float)tooltipFont.textHeight() + _border * 2; - wiImage::Draw(wiTextureHelper::getColor(wiColor(255, 234, 165)), wiImageParams(tooltipPos.x - _border, tooltipPos.y - _border, fontWidth, fontHeight), gui->GetGraphicsThread()); + wiImage::Draw(wiTextureHelper::getColor(wiColor(255, 234, 165)), wiImageParams(tooltipPos.x - _border, tooltipPos.y - _border, fontWidth, fontHeight), threadID); tooltipFont.SetText(tooltip); - tooltipFont.Draw(gui->GetGraphicsThread()); + tooltipFont.Draw(threadID); if (!scriptTip.empty()) { tooltipFont.SetText(scriptTip); tooltipFont.params.posY += (int)(fontHeight / 2); tooltipFont.params.color = wiColor(25, 25, 25, 110); - tooltipFont.Draw(gui->GetGraphicsThread()); + tooltipFont.Draw(threadID); } } } @@ -378,7 +378,7 @@ void wiButton::Update(wiGUI* gui, float dt) prevPos.x = pointerHitbox.pos.x; prevPos.y = pointerHitbox.pos.y; } -void wiButton::Render(const wiGUI* gui) const +void wiButton::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -389,15 +389,15 @@ void wiButton::Render(const wiGUI* gui) const wiColor color = GetColor(); - gui->ResetScissor(); + gui->ResetScissor(threadID); wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); wiFont(text, wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } void wiButton::OnClick(function func) @@ -444,7 +444,7 @@ void wiLabel::Update(wiGUI* gui, float dt) return; } } -void wiLabel::Render(const wiGUI* gui) const +void wiLabel::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -455,15 +455,15 @@ void wiLabel::Render(const wiGUI* gui) const wiColor color = GetColor(); - gui->ResetScissor(); + gui->ResetScissor(threadID); wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); wiFont(text, wiFontParams((int)translation.x + 2, (int)translation.y + 2, WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_TOP, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } @@ -595,7 +595,7 @@ void wiTextInputField::Update(wiGUI* gui, float dt) } } -void wiTextInputField::Render(const wiGUI* gui) const +void wiTextInputField::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -606,14 +606,14 @@ void wiTextInputField::Render(const wiGUI* gui) const wiColor color = GetColor(); - gui->ResetScissor(); + gui->ResetScissor(threadID); wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); string activeText = text; if (state == ACTIVE) @@ -625,7 +625,7 @@ void wiTextInputField::Render(const wiGUI* gui) const activeText = value; } wiFont(activeText, wiFontParams((int)(translation.x + 2), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } void wiTextInputField::OnInputAccepted(function func) @@ -783,7 +783,7 @@ void wiSlider::Update(wiGUI* gui, float dt) valueInputField->SetValue(value); } -void wiSlider::Render(const wiGUI* gui) const +void wiSlider::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -796,23 +796,23 @@ void wiSlider::Render(const wiGUI* gui) const float headWidth = scale.x*0.05f; - gui->ResetScissor(); + gui->ResetScissor(threadID); // trail wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x - headWidth * 0.5f, translation.y + scale.y * 0.5f - scale.y*0.1f, scale.x + headWidth, scale.y * 0.2f), gui->GetGraphicsThread()); + , wiImageParams(translation.x - headWidth * 0.5f, translation.y + scale.y * 0.5f - scale.y*0.1f, scale.x + headWidth, scale.y * 0.2f), threadID); // head float headPosX = wiMath::Lerp(translation.x, translation.x + scale.x, wiMath::Clamp(wiMath::InverseLerp(start, end, value), 0, 1)); wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(headPosX - headWidth * 0.5f, translation.y, headWidth, scale.y), gui->GetGraphicsThread()); + , wiImageParams(headPosX - headWidth * 0.5f, translation.y, headWidth, scale.y), threadID); if (parent != gui) { - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); } // text wiFont(text, wiFontParams((int)(translation.x - headWidth * 0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_RIGHT, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); //// value //stringstream ss(""); @@ -822,7 +822,7 @@ void wiSlider::Render(const wiGUI* gui) const - valueInputField->Render(gui); + valueInputField->Render(gui, threadID); } void wiSlider::OnSlide(function func) { @@ -918,7 +918,7 @@ void wiCheckBox::Update(wiGUI* gui, float dt) } } -void wiCheckBox::Render(const wiGUI* gui) const +void wiCheckBox::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -929,26 +929,26 @@ void wiCheckBox::Render(const wiGUI* gui) const wiColor color = GetColor(); - gui->ResetScissor(); + gui->ResetScissor(threadID); // control wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); // check if (GetCheck()) { wiImage::Draw(wiTextureHelper::getColor(wiColor::lerp(color, wiColor::White(), 0.8f)) , wiImageParams(translation.x + scale.x*0.25f, translation.y + scale.y*0.25f, scale.x*0.5f, scale.y*0.5f) - , gui->GetGraphicsThread()); + , threadID); } if (parent != gui) { - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); } wiFont(text, wiFontParams((int)(translation.x), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_RIGHT, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } void wiCheckBox::OnClick(function func) @@ -1109,7 +1109,7 @@ void wiComboBox::Update(wiGUI* gui, float dt) } } -void wiComboBox::Render(const wiGUI* gui) const +void wiComboBox::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -1124,35 +1124,35 @@ void wiComboBox::Render(const wiGUI* gui) const color = colors[FOCUS]; } - gui->ResetScissor(); + gui->ResetScissor(threadID); // control-base wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); // control-arrow wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x + scale.x + 1, translation.y, scale.y, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x + scale.x + 1, translation.y, scale.y, scale.y), threadID); wiFont("V", wiFontParams((int)(translation.x + scale.x + scale.y*0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); if (parent != gui) { - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); } wiFont(text, wiFontParams((int)(translation.x), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_RIGHT, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); if (selected >= 0) { wiFont(items[selected], wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } // drop-down if (state == ACTIVE) { - gui->ResetScissor(); + gui->ResetScissor(threadID); // control-list int i = 0; @@ -1177,9 +1177,9 @@ void wiComboBox::Render(const wiGUI* gui) const } } wiImage::Draw(wiTextureHelper::getColor(col) - , wiImageParams(translation.x, translation.y + _GetItemOffset(i), scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y + _GetItemOffset(i), scale.x, scale.y), threadID); wiFont(x, wiFontParams((int)(translation.x + scale.x*0.5f), (int)(translation.y + scale.y*0.5f + _GetItemOffset(i)), WIFONTSIZE_DEFAULT, WIFALIGN_CENTER, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); i++; } } @@ -1433,7 +1433,7 @@ void wiWindow::Update(wiGUI* gui, float dt) return; } } -void wiWindow::Render(const wiGUI* gui) const +void wiWindow::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { assert(gui != nullptr && "Ivalid GUI!"); @@ -1444,13 +1444,13 @@ void wiWindow::Render(const wiGUI* gui) const wiColor color = GetColor(); - gui->ResetScissor(); + gui->ResetScissor(threadID); // body if (!IsMinimized()) { wiImage::Draw(wiTextureHelper::getColor(color) - , wiImageParams(translation.x, translation.y, scale.x, scale.y), gui->GetGraphicsThread()); + , wiImageParams(translation.x, translation.y, scale.x, scale.y), threadID); } for (auto& x : childrenWidgets) @@ -1458,13 +1458,13 @@ void wiWindow::Render(const wiGUI* gui) const if (x != gui->GetActiveWidget()) { // the gui will render the active on on top of everything! - x->Render(gui); + x->Render(gui, threadID); } } - wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, gui->GetGraphicsThread()); + wiRenderer::GetDevice()->BindScissorRects(1, &scissorRect, threadID); wiFont(text, wiFontParams((int)(translation.x + resizeDragger_UpperLeft->scale.x + 2), (int)(translation.y + resizeDragger_UpperLeft->scale.y * 0.5f), WIFONTSIZE_DEFAULT, WIFALIGN_LEFT, WIFALIGN_CENTER, 0, 0, - textColor, textShadowColor)).Draw(gui->GetGraphicsThread()); + textColor, textShadowColor)).Draw(threadID); } void wiWindow::SetVisible(bool value) @@ -1649,16 +1649,15 @@ void wiColorPicker::Update(wiGUI* gui, float dt) onColorChanged(args); } } -void wiColorPicker::Render(const wiGUI* gui) const +void wiColorPicker::Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const { - wiWindow::Render(gui); + wiWindow::Render(gui, threadID); if (!IsVisible() || IsMinimized()) { return; } - GRAPHICSTHREAD threadID = gui->GetGraphicsThread(); struct Vertex { diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h index a2f30d7d3..19a5722db 100644 --- a/WickedEngine/wiWidget.h +++ b/WickedEngine/wiWidget.h @@ -85,8 +85,8 @@ public: void SetTextShadowColor(const wiColor& value) { textShadowColor = value; } virtual void Update(wiGUI* gui, float dt); - virtual void Render(const wiGUI* gui) const = 0; - void RenderTooltip(const wiGUI* gui) const; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const = 0; + void RenderTooltip(const wiGUI* gui, GRAPHICSTHREAD threadID) const; XMFLOAT3 translation; XMFLOAT3 scale; @@ -116,7 +116,7 @@ public: virtual ~wiButton(); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; void OnClick(std::function func); void OnDragStart(std::function func); @@ -133,7 +133,7 @@ public: virtual ~wiLabel(); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; }; // Text input box @@ -158,7 +158,7 @@ public: static void DeleteFromInput(); virtual void Update(wiGUI* gui, float dt) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; void OnInputAccepted(std::function func); }; @@ -186,7 +186,7 @@ public: void SetRange(float start, float end); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; void OnSlide(std::function func); }; @@ -205,7 +205,7 @@ public: bool GetCheck() const; virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; void OnClick(std::function func); }; @@ -249,7 +249,7 @@ public: std::string GetItemText(int index); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; void OnSelect(std::function func); }; @@ -275,7 +275,7 @@ public: void RemoveWidgets(bool alsoDelete = false); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; virtual void SetVisible(bool value) override; virtual void SetEnabled(bool value) override; @@ -300,7 +300,7 @@ public: virtual ~wiColorPicker(); virtual void Update(wiGUI* gui, float dt ) override; - virtual void Render(const wiGUI* gui) const override; + virtual void Render(const wiGUI* gui, GRAPHICSTHREAD threadID) const override; const XMFLOAT4& GetPickColor() const; void SetPickColor(const XMFLOAT4& value);