From 96d747a2093fddc1cf957b63c9e1d9305e7ba740 Mon Sep 17 00:00:00 2001 From: ueshita Date: Tue, 26 Mar 2024 09:55:16 +0900 Subject: [PATCH] Add support GpuTimer for LLGI (#1008) --- Dev/Cpp/3rdParty/LLGI | 2 +- Dev/Cpp/CMakeLists.txt | 2 +- .../Effekseer/Effekseer/Effekseer.Manager.cpp | 5 + .../Effekseer/Renderer/Effekseer.GpuTimer.h | 2 + Dev/Cpp/EffekseerRendererLLGI/CMakeLists.txt | 2 + .../EffekseerRendererLLGI.GpuTimer.cpp | 166 ++++++++++++++++++ .../EffekseerRendererLLGI.GpuTimer.h | 62 +++++++ .../EffekseerRendererLLGI.Renderer.cpp | 26 +++ ...ffekseerRendererLLGI.RendererImplemented.h | 13 ++ Dev/Editor/Effekseer/GUI/Dock/Profiler.cs | 2 +- Examples/CustomAsyncLoader/main.cpp | 14 +- Examples/CustomLoader/main.cpp | 14 +- Examples/DirectX11/DeviceDX11.cpp | 7 +- Examples/DirectX11/DeviceDX11.h | 2 +- Examples/DirectX11/main.cpp | 4 +- Examples/DirectX12/DeviceDX12.cpp | 7 +- Examples/DirectX12/DeviceDX12.h | 2 +- Examples/DirectX12/main.cpp | 4 +- Examples/DirectX9/DeviceDX9.cpp | 23 ++- Examples/DirectX9/DeviceDX9.h | 5 +- Examples/DirectX9/main.cpp | 14 +- Examples/Distortion/main.cpp | 10 +- Examples/GpuParticles/main.cpp | 8 + Examples/Metal/DeviceMetal.h | 2 +- Examples/Metal/DeviceMetal.mm | 7 +- Examples/NetworkClient/main.cpp | 14 +- Examples/NetworkServer/CMakeLists.txt | 38 +++- Examples/NetworkServer/main.cpp | 33 +++- Examples/OpenGL/DeviceGLFW.cpp | 23 ++- Examples/OpenGL/DeviceGLFW.h | 5 +- Examples/OpenGL/main.cpp | 14 +- Examples/SortHandle/main.cpp | 14 +- Examples/Trigger/main.cpp | 10 +- Examples/Vulkan/DeviceVulkan.cpp | 7 +- Examples/Vulkan/DeviceVulkan.h | 2 +- Examples/Vulkan/main.cpp | 4 +- 36 files changed, 488 insertions(+), 81 deletions(-) create mode 100644 Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.cpp create mode 100644 Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.h diff --git a/Dev/Cpp/3rdParty/LLGI b/Dev/Cpp/3rdParty/LLGI index 8bf0548640..99c483aa50 160000 --- a/Dev/Cpp/3rdParty/LLGI +++ b/Dev/Cpp/3rdParty/LLGI @@ -1 +1 @@ -Subproject commit 8bf05486407f7751ce3f06a46a22cb23b7cdfdd7 +Subproject commit 99c483aa508cf770401e5800ed600273aa490307 diff --git a/Dev/Cpp/CMakeLists.txt b/Dev/Cpp/CMakeLists.txt index cd77b62759..5fb930e5a0 100644 --- a/Dev/Cpp/CMakeLists.txt +++ b/Dev/Cpp/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.15) if(APPLE) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version" FORCE) endif() project(Effekseer C CXX) diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Manager.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Manager.cpp index ca15256a1e..648348c859 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Manager.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Manager.cpp @@ -1441,6 +1441,11 @@ void ManagerImplemented::Update(const UpdateParameter& parameter) EndUpdate(); ExecuteSounds(); + + if (m_gpuTimer) + { + m_gpuTimer->UpdateResults(); + } } void ManagerImplemented::DoUpdate(const UpdateParameter& parameter, int times) diff --git a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.GpuTimer.h b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.GpuTimer.h index a32fbd8f86..3bd165fda4 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.GpuTimer.h +++ b/Dev/Cpp/Effekseer/Effekseer/Renderer/Effekseer.GpuTimer.h @@ -26,6 +26,8 @@ class GpuTimer : public ReferenceObject virtual ~GpuTimer() = default; + virtual void UpdateResults() {} + virtual void BeginStage(GpuStage stage) {} virtual void EndStage(GpuStage stage) {} diff --git a/Dev/Cpp/EffekseerRendererLLGI/CMakeLists.txt b/Dev/Cpp/EffekseerRendererLLGI/CMakeLists.txt index d8d1161cfe..6fe3823a28 100644 --- a/Dev/Cpp/EffekseerRendererLLGI/CMakeLists.txt +++ b/Dev/Cpp/EffekseerRendererLLGI/CMakeLists.txt @@ -8,6 +8,7 @@ set(PublicHeaders set(LocalHeaders EffekseerRendererLLGI/EffekseerRendererLLGI.Base.h EffekseerRendererLLGI/EffekseerRendererLLGI.Base.Pre.h + EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.h EffekseerRendererLLGI/EffekseerRendererLLGI.GpuParticles.h EffekseerRendererLLGI/EffekseerRendererLLGI.MaterialLoader.h EffekseerRendererLLGI/EffekseerRendererLLGI.ModelRenderer.h @@ -20,6 +21,7 @@ set(LocalHeaders set(LocalSources EffekseerRendererLLGI/Common.cpp + EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.cpp EffekseerRendererLLGI/EffekseerRendererLLGI.GpuParticles.cpp EffekseerRendererLLGI/EffekseerRendererLLGI.MaterialLoader.cpp EffekseerRendererLLGI/EffekseerRendererLLGI.ModelRenderer.cpp diff --git a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.cpp b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.cpp new file mode 100644 index 0000000000..fd24e00515 --- /dev/null +++ b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.cpp @@ -0,0 +1,166 @@ +#include "EffekseerRendererLLGI.GpuTimer.h" + +namespace EffekseerRendererLLGI +{ + +GpuTimer::GpuTimer(RendererImplemented* renderer, bool hasRefCount) + : m_renderer(renderer) +{ + m_renderer->AddRef(); + m_renderer->GetStandardRenderer()->UpdateGpuTimerCount(+1); +} + +GpuTimer::~GpuTimer() +{ + m_renderer->GetStandardRenderer()->UpdateGpuTimerCount(-1); + m_renderer->Release(); +} + +void GpuTimer::BeginStage(Effekseer::GpuStage stage) +{ + assert(stage != Effekseer::GpuStage::None); + + uint32_t index = static_cast(stage); + assert(m_stageState[index] != State::DuringStage); + + if (m_stageState[index] == State::AfterStage) + { + UpdateResults(stage); + } + + m_stageState[index] = State::DuringStage; + m_currentStage = stage; +} + +void GpuTimer::EndStage(Effekseer::GpuStage stage) +{ + assert(stage != Effekseer::GpuStage::None); + + uint32_t index = static_cast(stage); + assert(m_stageState[index] == State::DuringStage); + + m_stageState[index] = State::AfterStage; + m_currentStage = Effekseer::GpuStage::None; +} + +void GpuTimer::UpdateResults() +{ + for (uint32_t index = 1; index < 5; index++) + { + if (m_stageState[index] == State::AfterStage) + { + UpdateResults(static_cast(index)); + } + } + + for (auto& [object, timeData] : m_timeData) + { + m_renderer->ResetQuery(timeData.queries.get()); + } +} + +void GpuTimer::UpdateResults(Effekseer::GpuStage stage) +{ + auto graphicsDevice = m_renderer->GetGraphicsDevice().DownCast(); + + assert(stage != Effekseer::GpuStage::None); + uint32_t index = static_cast(stage); + + for (auto& [object, timeData] : m_timeData) + { + timeData.result = 0; + + uint64_t elapsedTime = 0; + for (uint32_t phase = 0; phase < NUM_PHASES; phase++) + { + if (timeData.queryedStage[phase] == stage) + { + if (timeData.queries) + { + uint64_t startTime = timeData.queries->GetQueryResult(QueryIndex(phase, TIMESTAMP_START)); + uint64_t stopTime = timeData.queries->GetQueryResult(QueryIndex(phase, TIMESTAMP_STOP)); + elapsedTime += graphicsDevice->GetGraphics()->TimestampToMicroseconds(stopTime - startTime); + } + timeData.queryedStage[phase] = Effekseer::GpuStage::None; + } + } + timeData.result = static_cast(elapsedTime); + } + + m_stageState[index] = State::ResultUpdated; +} + +void GpuTimer::AddTimer(const void* object) +{ + assert(m_timeData.find(object) == m_timeData.end()); + + auto graphicsDevice = m_renderer->GetGraphicsDevice().DownCast(); + + TimeData timeData; + timeData.queries = LLGI::CreateUniqueReference(graphicsDevice->GetGraphics()->CreateQuery( + LLGI::QueryType::Timestamp, NUM_QUERIES_PER_TIMER)); + + m_timeData.emplace(object, std::move(timeData)); +} + +void GpuTimer::RemoveTimer(const void* object) +{ + auto it = m_timeData.find(object); + if (it != m_timeData.end()) + { + TimeData& timeData = it->second; + m_timeData.erase(it); + } +} + +void GpuTimer::Start(const void* object) +{ + assert(m_currentStage != Effekseer::GpuStage::None); + + auto it = m_timeData.find(object); + if (it != m_timeData.end()) + { + TimeData& timeData = it->second; + for (uint32_t phase = 0; phase < NUM_PHASES; phase++) + { + if (timeData.queryedStage[phase] == Effekseer::GpuStage::None) + { + m_renderer->RecordTimestamp(timeData.queries.get(), QueryIndex(phase, TIMESTAMP_START)); + timeData.queryedStage[phase] = m_currentStage; + break; + } + } + } +} + +void GpuTimer::Stop(const void* object) +{ + assert(m_currentStage != Effekseer::GpuStage::None); + + auto it = m_timeData.find(object); + if (it != m_timeData.end()) + { + TimeData& timeData = it->second; + for (uint32_t phase = 0; phase < NUM_PHASES; phase++) + { + if (timeData.queryedStage[phase] == m_currentStage) + { + m_renderer->RecordTimestamp(timeData.queries.get(), QueryIndex(phase, TIMESTAMP_STOP)); + break; + } + } + } +} + +int32_t GpuTimer::GetResult(const void* object) +{ + auto it = m_timeData.find(object); + if (it != m_timeData.end()) + { + TimeData& timeData = it->second; + return timeData.result; + } + return 0; +} + +} // namespace EffekseerRendererLLGI diff --git a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.h b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.h new file mode 100644 index 0000000000..9b8916a286 --- /dev/null +++ b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.GpuTimer.h @@ -0,0 +1,62 @@ + +#pragma once + +#include +#include "GraphicsDevice.h" +#include "EffekseerRendererLLGI.RendererImplemented.h" +#include + +namespace EffekseerRendererLLGI +{ + +class GpuTimer : public ::Effekseer::GpuTimer +{ + static constexpr uint32_t NUM_PHASES = 2; + static constexpr uint32_t NUM_TIMESTAMPS = 2; + static constexpr uint32_t NUM_QUERIES_PER_TIMER = NUM_PHASES * NUM_TIMESTAMPS; + + static constexpr uint32_t TIMESTAMP_START = 0; + static constexpr uint32_t TIMESTAMP_STOP = 1; + static constexpr uint32_t QueryIndex(uint32_t phase, uint32_t timestamp) { + return phase * NUM_TIMESTAMPS + timestamp; + } + +public: + GpuTimer(RendererImplemented* renderer, bool hasRefCount); + + virtual ~GpuTimer(); + + void UpdateResults(Effekseer::GpuStage stage); + +public: // GpuTimer + virtual void UpdateResults() override; + virtual void BeginStage(Effekseer::GpuStage stage) override; + virtual void EndStage(Effekseer::GpuStage stage) override; + virtual void AddTimer(const void* object) override; + virtual void RemoveTimer(const void* object) override; + virtual void Start(const void* object) override; + virtual void Stop(const void* object) override; + virtual int32_t GetResult(const void* object) override; + +private: + RendererImplemented* m_renderer = nullptr; + + struct TimeData + { + LLGI::unique_ref queries; + Effekseer::GpuStage queryedStage[NUM_PHASES] = {}; + int32_t result = 0; + }; + std::unordered_map m_timeData; + + enum class State { + NoResult, + DuringStage, + AfterStage, + ResultUpdated, + }; + State m_stageState[8] = {}; + Effekseer::GpuStage m_currentStage = {}; +}; + +} // namespace EffekseerRendererLLGI \ No newline at end of file diff --git a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.Renderer.cpp b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.Renderer.cpp index bb285266e3..63c15dd3d8 100644 --- a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.Renderer.cpp +++ b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.Renderer.cpp @@ -8,6 +8,7 @@ #include "EffekseerRendererLLGI.ModelRenderer.h" #include "EffekseerRendererLLGI.Shader.h" #include "EffekseerRendererLLGI.GpuParticles.h" +#include "EffekseerRendererLLGI.GpuTimer.h" #include #include @@ -598,6 +599,11 @@ ::Effekseer::TrackRendererRef RendererImplemented::CreateTrackRenderer() return ::Effekseer::TrackRendererRef(new ::EffekseerRenderer::TrackRendererBase(this)); } +::Effekseer::GpuTimerRef RendererImplemented::CreateGpuTimer() +{ + return ::Effekseer::GpuTimerRef(new ::EffekseerRendererLLGI::GpuTimer(this, false)); +} + ::Effekseer::GpuParticleSystemRef RendererImplemented::CreateGpuParticleSystem(const Effekseer::GpuParticleSystem::Settings& settings) { auto gpuParticleSystem = ::Effekseer::GpuParticleSystemRef(new ::EffekseerRendererLLGI::GpuParticleSystem(this)); @@ -838,4 +844,24 @@ void RendererImplemented::ResetRenderState() m_renderState->Update(true); } +void RendererImplemented::ResetQuery(LLGI::Query* query) +{ + GetCurrentCommandList()->ResetQuery(query); +} + +void RendererImplemented::BeginQuery(LLGI::Query* query, uint32_t queryIndex) +{ + GetCurrentCommandList()->BeginQuery(query, queryIndex); +} + +void RendererImplemented::EndQuery(LLGI::Query* query, uint32_t queryIndex) +{ + GetCurrentCommandList()->EndQuery(query, queryIndex); +} + +void RendererImplemented::RecordTimestamp(LLGI::Query* query, uint32_t queryIndex) +{ + GetCurrentCommandList()->RecordTimestamp(query, queryIndex); +} + } // namespace EffekseerRendererLLGI diff --git a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.RendererImplemented.h b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.RendererImplemented.h index 100f613d31..46ad29dde6 100644 --- a/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.RendererImplemented.h +++ b/Dev/Cpp/EffekseerRendererLLGI/EffekseerRendererLLGI/EffekseerRendererLLGI.RendererImplemented.h @@ -162,6 +162,11 @@ class RendererImplemented : public Renderer, public ::Effekseer::ReferenceObject @brief 軌跡レンダラーを生成する。 */ ::Effekseer::TrackRendererRef CreateTrackRenderer() override; + + /** + @brief GPUタイマーを生成する。 + */ + ::Effekseer::GpuTimerRef CreateGpuTimer() override; /** @brief GPUパーティクルシステムを生成する。 @@ -217,6 +222,14 @@ class RendererImplemented : public Renderer, public ::Effekseer::ReferenceObject void ResetRenderState() override; + void ResetQuery(LLGI::Query* query); + + void BeginQuery(LLGI::Query* query, uint32_t queryIndex); + + void EndQuery(LLGI::Query* query, uint32_t queryIndex); + + void RecordTimestamp(LLGI::Query* query, uint32_t queryIndex); + virtual int GetRef() override { return ::Effekseer::ReferenceObject::GetRef(); diff --git a/Dev/Editor/Effekseer/GUI/Dock/Profiler.cs b/Dev/Editor/Effekseer/GUI/Dock/Profiler.cs index 4935048904..e6ea94b053 100644 --- a/Dev/Editor/Effekseer/GUI/Dock/Profiler.cs +++ b/Dev/Editor/Effekseer/GUI/Dock/Profiler.cs @@ -165,7 +165,7 @@ public void Update(swig.GUIManager gui, ref Texts texts) HandleCountChart.Update(gui); gui.Text(texts.ProfilerCpuUsage + ": " + CpuTimeChart.LatestValue + "us"); CpuTimeChart.Update(gui); - gui.Text(texts.ProfilerCpuUsage + ": " + GpuTimeChart.LatestValue + "us"); + gui.Text(texts.ProfilerGpuUsage + ": " + GpuTimeChart.LatestValue + "us"); GpuTimeChart.Update(gui); } } diff --git a/Examples/CustomAsyncLoader/main.cpp b/Examples/CustomAsyncLoader/main.cpp index 5c8a66faaf..8f8f8744c2 100644 --- a/Examples/CustomAsyncLoader/main.cpp +++ b/Examples/CustomAsyncLoader/main.cpp @@ -114,9 +114,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about DirectX - // DirectXの処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -146,8 +146,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/CustomLoader/main.cpp b/Examples/CustomLoader/main.cpp index f8e90c1599..d632f5d718 100644 --- a/Examples/CustomLoader/main.cpp +++ b/Examples/CustomLoader/main.cpp @@ -256,9 +256,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about DirectX - // DirectXの処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -288,8 +288,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/DirectX11/DeviceDX11.cpp b/Examples/DirectX11/DeviceDX11.cpp index f8820298d4..b20aaabea7 100644 --- a/Examples/DirectX11/DeviceDX11.cpp +++ b/Examples/DirectX11/DeviceDX11.cpp @@ -190,7 +190,7 @@ void DeviceDX11::EndRenderPass() { } -void DeviceDX11::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceDX11::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a graphics device // 描画デバイスの作成 @@ -217,4 +217,9 @@ void DeviceDX11::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) efkManager->SetModelLoader(efkRenderer->CreateModelLoader()); efkManager->SetMaterialLoader(efkRenderer->CreateMaterialLoader()); efkManager->SetCurveLoader(Effekseer::MakeRefPtr()); + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/DirectX11/DeviceDX11.h b/Examples/DirectX11/DeviceDX11.h index f26915ac90..b7fff793e4 100644 --- a/Examples/DirectX11/DeviceDX11.h +++ b/Examples/DirectX11/DeviceDX11.h @@ -73,7 +73,7 @@ class DeviceDX11 void BeginRenderPass(); void EndRenderPass(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRendererDX11::RendererRef GetEffekseerRenderer() { return efkRenderer; diff --git a/Examples/DirectX11/main.cpp b/Examples/DirectX11/main.cpp index 13a0cbf212..7e4a7f9bb9 100644 --- a/Examples/DirectX11/main.cpp +++ b/Examples/DirectX11/main.cpp @@ -125,8 +125,8 @@ int main(int argc, char** argv) // 描画パスの終了 device.EndRenderPass(); - // Execute functions about DirectX - // DirectXの処理 + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/DirectX12/DeviceDX12.cpp b/Examples/DirectX12/DeviceDX12.cpp index 518d05c8d1..7feac25511 100644 --- a/Examples/DirectX12/DeviceDX12.cpp +++ b/Examples/DirectX12/DeviceDX12.cpp @@ -139,7 +139,7 @@ void DeviceDX12::PresentDevice() platform->Present(); } -void DeviceDX12::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceDX12::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a graphics device // 描画デバイスの作成 @@ -175,4 +175,9 @@ void DeviceDX12::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) efkManager->SetModelLoader(efkRenderer->CreateModelLoader()); efkManager->SetMaterialLoader(efkRenderer->CreateMaterialLoader()); efkManager->SetCurveLoader(Effekseer::MakeRefPtr()); + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/DirectX12/DeviceDX12.h b/Examples/DirectX12/DeviceDX12.h index 9050a4cf53..a69d5bb000 100644 --- a/Examples/DirectX12/DeviceDX12.h +++ b/Examples/DirectX12/DeviceDX12.h @@ -80,7 +80,7 @@ class DeviceDX12 void EndRenderPass(); void PresentDevice(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRenderer::RendererRef GetEffekseerRenderer() { return efkRenderer; diff --git a/Examples/DirectX12/main.cpp b/Examples/DirectX12/main.cpp index 3917da9836..b0bb636bb8 100644 --- a/Examples/DirectX12/main.cpp +++ b/Examples/DirectX12/main.cpp @@ -126,8 +126,8 @@ int main(int argc, char** argv) // 描画パスの終了 device.EndRenderPass(); - // Execute functions about DirectX - // DirectXの処理 + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/DirectX9/DeviceDX9.cpp b/Examples/DirectX9/DeviceDX9.cpp index 551cd3cf3a..093a784e2b 100644 --- a/Examples/DirectX9/DeviceDX9.cpp +++ b/Examples/DirectX9/DeviceDX9.cpp @@ -65,12 +65,6 @@ void DeviceDX9::Terminate() CoUninitialize(); } -void DeviceDX9::ClearScreen() -{ - d3d9Device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); - d3d9Device->BeginScene(); -} - void DeviceDX9::PresentDevice() { d3d9Device->EndScene(); @@ -143,7 +137,17 @@ bool DeviceDX9::NewFrame() return result; } -void DeviceDX9::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceDX9::BeginRenderPass() +{ + d3d9Device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); + d3d9Device->BeginScene(); +} + +void DeviceDX9::EndRenderPass() +{ +} + +void DeviceDX9::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a graphics device // 描画デバイスの作成 @@ -183,4 +187,9 @@ void DeviceDX9::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) // サウンドデータの読込機能を設定する。 // ユーザーが独自で拡張できる。現在はファイルから読み込んでいる。 efkManager->SetSoundLoader(efkSound->CreateSoundLoader()); + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/DirectX9/DeviceDX9.h b/Examples/DirectX9/DeviceDX9.h index 0c0a7b9512..8ad75b9690 100644 --- a/Examples/DirectX9/DeviceDX9.h +++ b/Examples/DirectX9/DeviceDX9.h @@ -56,11 +56,12 @@ class DeviceDX9 bool Initialize(const char* windowTitle, Utils::Vec2I windowSize); void Terminate(); - void ClearScreen(); void PresentDevice(); bool NewFrame(); + void BeginRenderPass(); + void EndRenderPass(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRendererDX9::RendererRef GetEffekseerRenderer() { return efkRenderer; diff --git a/Examples/DirectX9/main.cpp b/Examples/DirectX9/main.cpp index 29f2f9a6d3..9f82d01251 100644 --- a/Examples/DirectX9/main.cpp +++ b/Examples/DirectX9/main.cpp @@ -95,9 +95,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about DirectX - // DirectXの処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -127,8 +127,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/Distortion/main.cpp b/Examples/Distortion/main.cpp index 836dcb46a6..026381230b 100644 --- a/Examples/Distortion/main.cpp +++ b/Examples/Distortion/main.cpp @@ -263,9 +263,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Clear render target buffer - // レンダリングターゲットをクリア - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -320,6 +320,10 @@ int main(int argc, char** argv) efkRenderer->EndRendering(); } + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + // Update the display // ディスプレイを更新 device.PresentDevice(); diff --git a/Examples/GpuParticles/main.cpp b/Examples/GpuParticles/main.cpp index 1db85be0a4..59108067b2 100644 --- a/Examples/GpuParticles/main.cpp +++ b/Examples/GpuParticles/main.cpp @@ -136,6 +136,10 @@ int main(int argc, char** argv) // 描画パスの開始 device.BeginRenderPass(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); + // Specify a projection matrix // 投影行列を設定 efkRenderer->SetProjectionMatrix(projectionMatrix); @@ -164,6 +168,10 @@ int main(int argc, char** argv) // 描画パスの終了 device.EndRenderPass(); + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + // Update the display // ディスプレイを更新 device.PresentDevice(); diff --git a/Examples/Metal/DeviceMetal.h b/Examples/Metal/DeviceMetal.h index d5c9ee7140..629cf1746b 100644 --- a/Examples/Metal/DeviceMetal.h +++ b/Examples/Metal/DeviceMetal.h @@ -52,6 +52,6 @@ class DeviceMetal void EndRenderPass(); void PresentDevice(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRenderer::RendererRef GetEffekseerRenderer() { return efkRenderer; } }; diff --git a/Examples/Metal/DeviceMetal.mm b/Examples/Metal/DeviceMetal.mm index e1a633bbd0..fb4bd83a90 100644 --- a/Examples/Metal/DeviceMetal.mm +++ b/Examples/Metal/DeviceMetal.mm @@ -183,7 +183,7 @@ platform->Present(); } -void DeviceMetal::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceMetal::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a renderer of effects // エフェクトのレンダラーの作成 @@ -214,4 +214,9 @@ efkManager->SetModelLoader(efkRenderer->CreateModelLoader()); efkManager->SetMaterialLoader(efkRenderer->CreateMaterialLoader()); efkManager->SetCurveLoader(Effekseer::MakeRefPtr()); + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/NetworkClient/main.cpp b/Examples/NetworkClient/main.cpp index d07bb7b1f9..e101e019c1 100644 --- a/Examples/NetworkClient/main.cpp +++ b/Examples/NetworkClient/main.cpp @@ -38,12 +38,16 @@ int main(int argc, char** argv) efkClient->Reload(efkManager, EFK_EXAMPLE_ASSETS_DIR_U16 u"Laser01_reload.efkefc", u"Laser01"); } - // Execute functions about Rendering - // 描画の処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/NetworkServer/CMakeLists.txt b/Examples/NetworkServer/CMakeLists.txt index 672515cf55..8c14b1e268 100644 --- a/Examples/NetworkServer/CMakeLists.txt +++ b/Examples/NetworkServer/CMakeLists.txt @@ -7,16 +7,34 @@ set (DEVICE_SRC_FILES ../OpenGL/DeviceGLFW.cpp ../OpenGL/DeviceGLFW.h) if (WIN32) list (APPEND DEVICE_SRC_FILES ../DirectX9/DeviceDX9.cpp ../DirectX9/DeviceDX9.h) list (APPEND DEVICE_SRC_FILES ../DirectX11/DeviceDX11.cpp ../DirectX11/DeviceDX11.h) + list (APPEND DEVICE_SRC_FILES ../DirectX12/DeviceDX12.cpp ../DirectX12/DeviceDX12.h) +endif () + +if (BUILD_VULKAN) + list (APPEND DEVICE_SRC_FILES ../Vulkan/DeviceVulkan.cpp ../Vulkan/DeviceVulkan.h) endif () add_executable(${PROJECT_NAME} main.cpp ${DEVICE_SRC_FILES}) -set (MODULE_INCLUDE_PATHS ${EFK_RUNTIME_ROOT}/Effekseer ${EFK_RUNTIME_ROOT}/EffekseerRendererGL ../Utils) +set (MODULE_INCLUDE_PATHS + ${EFK_RUNTIME_ROOT}/Effekseer + ${EFK_RUNTIME_ROOT}/EffekseerRendererGL + ${EFK_RUNTIME_ROOT}/EffekseerRendererLLGI + ${EFK_RUNTIME_ROOT}/3rdParty/LLGI/src/ + ../Utils +) if (WIN32) - list (APPEND MODULE_INCLUDE_PATHS ${EFK_RUNTIME_ROOT}/EffekseerRendererDX9) - list (APPEND MODULE_INCLUDE_PATHS ${EFK_RUNTIME_ROOT}/EffekseerRendererDX11) - list (APPEND MODULE_INCLUDE_PATHS ${EFK_RUNTIME_ROOT}/EffekseerSoundXAudio2) + list (APPEND MODULE_INCLUDE_PATHS + ${EFK_RUNTIME_ROOT}/EffekseerRendererDX9 + ${EFK_RUNTIME_ROOT}/EffekseerRendererDX11 + ${EFK_RUNTIME_ROOT}/EffekseerRendererDX12 + ${EFK_RUNTIME_ROOT}/EffekseerSoundXAudio2 + ) +endif () + +if (BUILD_VULKAN) + list (APPEND MODULE_INCLUDE_PATHS ${Vulkan_INCLUDE_DIR} ${EFK_RUNTIME_ROOT}/EffekseerRendererVulkan) endif () target_include_directories( @@ -37,9 +55,21 @@ set (MODULE_LIBRARIES Effekseer EffekseerRendererGL ${EFK_EXAMPLES_GLFW} Example if (WIN32) list (APPEND MODULE_LIBRARIES EffekseerRendererDX9) list (APPEND MODULE_LIBRARIES EffekseerRendererDX11) + list (APPEND MODULE_LIBRARIES EffekseerRendererDX12) list (APPEND MODULE_LIBRARIES EffekseerSoundXAudio2) endif () +if (BUILD_VULKAN) + list (APPEND MODULE_LIBRARIES + ${Vulkan_LIBRARIES} + glslang + glslang-default-resource-limits + SPIRV + OSDependent + EffekseerRendererVulkan + ) +endif () + target_link_libraries( ${PROJECT_NAME} PRIVATE diff --git a/Examples/NetworkServer/main.cpp b/Examples/NetworkServer/main.cpp index 06cba3055e..c581e97d2a 100644 --- a/Examples/NetworkServer/main.cpp +++ b/Examples/NetworkServer/main.cpp @@ -3,6 +3,8 @@ #define DEVICE_OPENGL //#define DEVICE_DX9 //#define DEVICE_DX11 +//#define DEVICE_DX12 +//#define DEVICE_VULKAN #include #include @@ -15,6 +17,10 @@ #include "../DirectX9/DeviceDX9.h" #elif defined(DEVICE_DX11) #include "../DirectX11/DeviceDX11.h" +#elif defined(DEVICE_DX12) +#include "../DirectX12/DeviceDX12.h" +#elif defined(DEVICE_VULKAN) +#include "../Vulkan/DeviceVulkan.h" #endif const Utils::Vec2I screenSize = {1280, 720}; @@ -30,6 +36,12 @@ int main(int argc, char** argv) #elif defined(DEVICE_DX11) DeviceDX11 device; device.Initialize("NetworkServer (DirectX11)", screenSize); +#elif defined(DEVICE_DX12) + DeviceDX12 device; + device.Initialize("NetworkServer (DirectX12)", screenSize); +#elif defined(DEVICE_VULKAN) + DeviceVulkan device; + device.Initialize("NetworkServer (Vulkan)", screenSize); #endif // Create a manager of effects @@ -38,7 +50,7 @@ int main(int argc, char** argv) // Setup effekseer modules // Effekseerのモジュールをセットアップする - device.SetupEffekseerModules(efkManager); + device.SetupEffekseerModules(efkManager, true); auto efkRenderer = device.GetEffekseerRenderer(); // Create a server for effect @@ -82,6 +94,11 @@ int main(int argc, char** argv) if (time % 120 == 0) { + if (efkHandle) + { + efkManager->StopEffect(efkHandle); + } + // Play an effect // エフェクトの再生 efkHandle = efkManager->Play(effect, 0, 0, 0); @@ -98,9 +115,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about Rendering - // 描画の処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -130,8 +147,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/OpenGL/DeviceGLFW.cpp b/Examples/OpenGL/DeviceGLFW.cpp index a1f0d553da..834ca8f2e3 100644 --- a/Examples/OpenGL/DeviceGLFW.cpp +++ b/Examples/OpenGL/DeviceGLFW.cpp @@ -51,12 +51,6 @@ void DeviceGLFW::Terminate() } } -void DeviceGLFW::ClearScreen() -{ - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} - bool DeviceGLFW::NewFrame() { if (glfwWindowShouldClose(glfwWindow)) @@ -74,12 +68,22 @@ bool DeviceGLFW::NewFrame() return true; } +void DeviceGLFW::BeginRenderPass() +{ + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void DeviceGLFW::EndRenderPass() +{ +} + void DeviceGLFW::PresentDevice() { glfwSwapBuffers(glfwWindow); } -void DeviceGLFW::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceGLFW::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a graphics device // 描画デバイスの作成 @@ -121,4 +125,9 @@ void DeviceGLFW::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) // ユーザーが独自で拡張できる。現在はファイルから読み込んでいる。 efkManager->SetSoundLoader(efkSound->CreateSoundLoader()); #endif + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/OpenGL/DeviceGLFW.h b/Examples/OpenGL/DeviceGLFW.h index ddbbc2b348..b2af4a24a8 100644 --- a/Examples/OpenGL/DeviceGLFW.h +++ b/Examples/OpenGL/DeviceGLFW.h @@ -35,11 +35,12 @@ class DeviceGLFW bool Initialize(const char* windowTitle, Utils::Vec2I windowSize); void Terminate(); - void ClearScreen(); bool NewFrame(); + void BeginRenderPass(); + void EndRenderPass(); void PresentDevice(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRendererGL::RendererRef GetEffekseerRenderer() { return efkRenderer; diff --git a/Examples/OpenGL/main.cpp b/Examples/OpenGL/main.cpp index aa9b5725ae..643d097177 100644 --- a/Examples/OpenGL/main.cpp +++ b/Examples/OpenGL/main.cpp @@ -75,9 +75,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about DirectX - // DirectXの処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -107,8 +107,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about DirectX - // DirectXの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/SortHandle/main.cpp b/Examples/SortHandle/main.cpp index d42407e4c9..d0fcff6d79 100644 --- a/Examples/SortHandle/main.cpp +++ b/Examples/SortHandle/main.cpp @@ -118,9 +118,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Execute functions about OpenGL - // OpenGLの処理 - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Begin to rendering effects // エフェクトの描画開始処理を行う。 @@ -147,8 +147,12 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); - // Execute functions about OpenGL - // OpenGLの処理 + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++; diff --git a/Examples/Trigger/main.cpp b/Examples/Trigger/main.cpp index fc8003ca4e..60d98b9a1a 100644 --- a/Examples/Trigger/main.cpp +++ b/Examples/Trigger/main.cpp @@ -91,9 +91,9 @@ int main(int argc, char** argv) Effekseer::Manager::UpdateParameter updateParameter; efkManager->Update(updateParameter); - // Clear render target buffer - // レンダリングターゲットをクリア - device.ClearScreen(); + // Begin to rendering pass + // 描画パスの開始 + device.BeginRenderPass(); // Update a time // 時間を更新する @@ -123,6 +123,10 @@ int main(int argc, char** argv) // エフェクトの描画終了処理を行う。 efkRenderer->EndRendering(); + // Finish to rendering pass + // 描画パスの終了 + device.EndRenderPass(); + // Update the display // ディスプレイを更新 device.PresentDevice(); diff --git a/Examples/Vulkan/DeviceVulkan.cpp b/Examples/Vulkan/DeviceVulkan.cpp index b6504703fe..e649399d43 100644 --- a/Examples/Vulkan/DeviceVulkan.cpp +++ b/Examples/Vulkan/DeviceVulkan.cpp @@ -125,7 +125,7 @@ void DeviceVulkan::PresentDevice() platform->Present(); } -void DeviceVulkan::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) +void DeviceVulkan::SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler) { // Create a graphics device // 描画デバイスの作成 @@ -169,4 +169,9 @@ void DeviceVulkan::SetupEffekseerModules(::Effekseer::ManagerRef efkManager) efkManager->SetModelLoader(efkRenderer->CreateModelLoader()); efkManager->SetMaterialLoader(efkRenderer->CreateMaterialLoader()); efkManager->SetCurveLoader(Effekseer::MakeRefPtr()); + + if (usingProfiler) + { + efkManager->SetGpuTimer(efkRenderer->CreateGpuTimer()); + } } diff --git a/Examples/Vulkan/DeviceVulkan.h b/Examples/Vulkan/DeviceVulkan.h index 1407dfbcc7..89255d3eda 100644 --- a/Examples/Vulkan/DeviceVulkan.h +++ b/Examples/Vulkan/DeviceVulkan.h @@ -73,6 +73,6 @@ class DeviceVulkan void EndRenderPass(); void PresentDevice(); - void SetupEffekseerModules(::Effekseer::ManagerRef efkManager); + void SetupEffekseerModules(::Effekseer::ManagerRef efkManager, bool usingProfiler = false); ::EffekseerRenderer::RendererRef GetEffekseerRenderer() { return efkRenderer; } }; diff --git a/Examples/Vulkan/main.cpp b/Examples/Vulkan/main.cpp index 60df86701e..bbd679ed13 100644 --- a/Examples/Vulkan/main.cpp +++ b/Examples/Vulkan/main.cpp @@ -110,8 +110,8 @@ int main(int argc, char** argv) // 描画パスの終了 device.EndRenderPass(); - // Execute functions about DirectX - // DirectXの処理 + // Update the display + // ディスプレイを更新 device.PresentDevice(); time++;