diff --git a/Libraries/ionGraphics/IGraphicsImplementation.h b/Libraries/ionGraphics/IGraphicsImplementation.h index 3a046dd..b4538b6 100644 --- a/Libraries/ionGraphics/IGraphicsImplementation.h +++ b/Libraries/ionGraphics/IGraphicsImplementation.h @@ -51,6 +51,8 @@ namespace ion virtual void DiagnosticCaptureBegin() = 0; virtual void DiagnosticCaptureEnd() = 0; + virtual void AnnotateBeginEvent(string const & eventName) = 0; + virtual void AnnotateEndEvent(string const & eventName) = 0; }; diff --git a/Libraries/ionGraphicsD3D11/CD3D11Implementation.cpp b/Libraries/ionGraphicsD3D11/CD3D11Implementation.cpp index 5586001..b5e2eb8 100644 --- a/Libraries/ionGraphicsD3D11/CD3D11Implementation.cpp +++ b/Libraries/ionGraphicsD3D11/CD3D11Implementation.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -89,6 +90,8 @@ namespace ion CheckedDXCall( Device->CreateRasterizerState(& RasterizerDesc, & RasterizerState) ); ImmediateContext->RSSetState(RasterizerState); + CheckedDXCall( ImmediateContext->QueryInterface(IID_PPV_ARGS(& UserDefinedAnnotation)) ); + // Depth Settings D3D11_DEPTH_STENCIL_DESC DepthDesc; @@ -240,5 +243,31 @@ namespace ion } } + void CD3D11Implementation::AnnotateBeginEvent(string const & eventName) + { + if (UserDefinedAnnotation) + { + std::wstring temp = std::wstring(eventName.begin(), eventName.end()); + UserDefinedAnnotation->BeginEvent(temp.c_str()); + EventStack.push_back(eventName); + } + } + + void CD3D11Implementation::AnnotateEndEvent(string const & eventName) + { + if (UserDefinedAnnotation) + { + UserDefinedAnnotation->EndEvent(); + + string const stackTop = EventStack.back(); + EventStack.pop_back(); + + if (stackTop != eventName) + { + Log::Warn("CD3D11Implementation: Popped '%s' from the event stack, but ended '%s' event."); + } + } + } + } } diff --git a/Libraries/ionGraphicsD3D11/CD3D11Implementation.h b/Libraries/ionGraphicsD3D11/CD3D11Implementation.h index e0daba4..a1563ef 100644 --- a/Libraries/ionGraphicsD3D11/CD3D11Implementation.h +++ b/Libraries/ionGraphicsD3D11/CD3D11Implementation.h @@ -11,6 +11,7 @@ struct ID3D11Device; struct ID3D11DeviceContext; struct ID3D11Debug; struct IDXGraphicsAnalysis; +struct ID3DUserDefinedAnnotation; namespace ion { @@ -60,6 +61,8 @@ namespace ion void UseReverseDepth(bool const reverseDepth = true) {} void DiagnosticCaptureBegin(); void DiagnosticCaptureEnd(); + void AnnotateBeginEvent(string const & eventName); + void AnnotateEndEvent(string const & eventName); protected: @@ -70,7 +73,9 @@ namespace ion ID3D11DeviceContext * ImmediateContext = nullptr; ID3D11Debug * DebugDevice = nullptr; - IDXGraphicsAnalysis * GraphicsAnalysis; + IDXGraphicsAnalysis * GraphicsAnalysis = nullptr; + ID3DUserDefinedAnnotation * UserDefinedAnnotation = nullptr; + vector EventStack; D3D11::CDrawContext * DrawContext = nullptr; diff --git a/Libraries/ionScene/CRenderPass.cpp b/Libraries/ionScene/CRenderPass.cpp index a228a5e..3c8988a 100644 --- a/Libraries/ionScene/CRenderPass.cpp +++ b/Libraries/ionScene/CRenderPass.cpp @@ -25,6 +25,11 @@ namespace ion this->RenderTarget = RenderTarget; } + void CRenderPass::SetName(string const & name) + { + Name = name; + } + string const & CRenderPass::GetName() const { return Name; diff --git a/Libraries/ionScene/CRenderPass.h b/Libraries/ionScene/CRenderPass.h index dec875e..e2aedf2 100644 --- a/Libraries/ionScene/CRenderPass.h +++ b/Libraries/ionScene/CRenderPass.h @@ -24,6 +24,7 @@ namespace ion virtual void SetGraphicsContext(SharedPointer GraphicsContext); virtual void SetRenderTarget(SharedPointer RenderTarget); + virtual void SetName(string const & name); virtual string const & GetName() const; virtual CGraphicsAPI * GetGraphicsAPI(); virtual SharedPointer GetGraphicsContext(); diff --git a/Libraries/ionScene/CSceneManager.cpp b/Libraries/ionScene/CSceneManager.cpp index cccc65e..2031621 100644 --- a/Libraries/ionScene/CSceneManager.cpp +++ b/Libraries/ionScene/CSceneManager.cpp @@ -10,11 +10,24 @@ namespace ion void CSceneManager::DrawAll() { - std::for_each(RenderPasses.begin(), RenderPasses.end(), [](Scene::CRenderPass * RenderPass) + SingletonPointer GraphicsAPI; + + int i = 0; + for (Scene::CRenderPass * pass : RenderPasses) { - RenderPass->Load(); - RenderPass->Draw(); - }); + string passName = pass->GetName(); + if (passName == "") + { + passName = String::Build("RenderPass%d", i); + } + + GraphicsAPI->GetImplementation()->AnnotateBeginEvent(passName); + pass->Load(); + pass->Draw(); + GraphicsAPI->GetImplementation()->AnnotateEndEvent(passName); + + i ++; + } } void CSceneManager::AddRenderPass(Scene::CRenderPass * RenderPass)