Skip to content

Commit

Permalink
[ionGraphics] [ionGraphicsD3D11] Add support for graphics event annot…
Browse files Browse the repository at this point in the history
…ation, used by graphics debugger
  • Loading branch information
iondune committed Jun 15, 2020
1 parent 1f5ecac commit c749808
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Libraries/ionGraphics/IGraphicsImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

Expand Down
29 changes: 29 additions & 0 deletions Libraries/ionGraphicsD3D11/CD3D11Implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <ionWindow/CWindow.h>

#include <d3d11.h>
#include <d3d11_1.h>
#include <dxgi.h>
#include <d3dcompiler.h>

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.");
}
}
}

}
}
7 changes: 6 additions & 1 deletion Libraries/ionGraphicsD3D11/CD3D11Implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct ID3D11Device;
struct ID3D11DeviceContext;
struct ID3D11Debug;
struct IDXGraphicsAnalysis;
struct ID3DUserDefinedAnnotation;

namespace ion
{
Expand Down Expand Up @@ -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:

Expand All @@ -70,7 +73,9 @@ namespace ion
ID3D11DeviceContext * ImmediateContext = nullptr;
ID3D11Debug * DebugDevice = nullptr;

IDXGraphicsAnalysis * GraphicsAnalysis;
IDXGraphicsAnalysis * GraphicsAnalysis = nullptr;
ID3DUserDefinedAnnotation * UserDefinedAnnotation = nullptr;
vector<string> EventStack;

D3D11::CDrawContext * DrawContext = nullptr;

Expand Down
5 changes: 5 additions & 0 deletions Libraries/ionScene/CRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace ion
this->RenderTarget = RenderTarget;
}

void CRenderPass::SetName(string const & name)
{
Name = name;
}

string const & CRenderPass::GetName() const
{
return Name;
Expand Down
1 change: 1 addition & 0 deletions Libraries/ionScene/CRenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace ion
virtual void SetGraphicsContext(SharedPointer<Graphics::IGraphicsContext> GraphicsContext);
virtual void SetRenderTarget(SharedPointer<Graphics::IRenderTarget> RenderTarget);

virtual void SetName(string const & name);
virtual string const & GetName() const;
virtual CGraphicsAPI * GetGraphicsAPI();
virtual SharedPointer<Graphics::IGraphicsContext> GetGraphicsContext();
Expand Down
21 changes: 17 additions & 4 deletions Libraries/ionScene/CSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ namespace ion

void CSceneManager::DrawAll()
{
std::for_each(RenderPasses.begin(), RenderPasses.end(), [](Scene::CRenderPass * RenderPass)
SingletonPointer<CGraphicsAPI> 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)
Expand Down

0 comments on commit c749808

Please sign in to comment.