OpenGL and Vulkan resource tracing

This commit is contained in:
Jack Andersen 2018-05-19 20:11:49 -10:00
parent 7eb10885ad
commit 578432eb2f
10 changed files with 83 additions and 56 deletions

View File

@ -72,6 +72,22 @@ namespace boo
# endif # endif
#endif #endif
#ifndef NDEBUG
#define __BooTraceArgs , const char* file, int line
#define __BooTraceArgsUse , file, line
#define __BooTraceInitializer , m_file(file), m_line(line)
#define __BooTraceFields const char* m_file; int m_line;
#define BooCommitTransaction(...) commitTransaction(__VA_ARGS__, __FILE__, __LINE__)
#define BooNewPoolBuffer(...) newPoolBuffer(__VA_ARGS__, __FILE__, __LINE__)
#else
#define __BooTraceArgs
#define __BooTraceArgsUse
#define __BooTraceInitializer
#define __BooTraceFields
#define BooCommitTransaction(...) commitTransaction(__VA_ARGS__)
#define BooNewPoolBuffer(...) newPoolBuffer(__VA_ARGS__)
#endif
} }
#endif #endif

View File

@ -26,7 +26,7 @@ public:
friend class GLDataFactoryImpl; friend class GLDataFactoryImpl;
GLDataFactory& m_parent; GLDataFactory& m_parent;
ObjToken<BaseGraphicsData> m_data; ObjToken<BaseGraphicsData> m_data;
Context(GLDataFactory& parent); Context(GLDataFactory& parent __BooTraceArgs);
~Context(); ~Context();
public: public:
Platform platform() const { return Platform::OpenGL; } Platform platform() const { return Platform::OpenGL; }

View File

@ -293,9 +293,9 @@ struct IGraphicsDataFactory
} }
}; };
virtual void commitTransaction(const std::function<bool(Context& ctx)>&)=0; virtual void commitTransaction(const std::function<bool(Context& ctx)>& __BooTraceArgs)=0;
virtual ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count)=0; virtual ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs)=0;
virtual void setDisplayGamma(float gamma)=0; virtual void setDisplayGamma(float gamma)=0;
}; };

View File

@ -131,7 +131,7 @@ public:
friend class VulkanDataFactoryImpl; friend class VulkanDataFactoryImpl;
VulkanDataFactory& m_parent; VulkanDataFactory& m_parent;
boo::ObjToken<BaseGraphicsData> m_data; boo::ObjToken<BaseGraphicsData> m_data;
Context(VulkanDataFactory& parent); Context(VulkanDataFactory& parent __BooTraceArgs);
~Context(); ~Context();
public: public:
Platform platform() const {return Platform::Vulkan;} Platform platform() const {return Platform::Vulkan;}

View File

@ -43,6 +43,8 @@ struct BaseGraphicsData : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>
static std::unique_lock<std::recursive_mutex> _getHeadLock(GraphicsDataFactoryHead* head) static std::unique_lock<std::recursive_mutex> _getHeadLock(GraphicsDataFactoryHead* head)
{ return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; } { return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; }
__BooTraceFields
GraphicsDataNode<IShaderPipeline, BaseGraphicsData>* m_SPs = nullptr; GraphicsDataNode<IShaderPipeline, BaseGraphicsData>* m_SPs = nullptr;
GraphicsDataNode<IShaderDataBinding, BaseGraphicsData>* m_SBinds = nullptr; GraphicsDataNode<IShaderDataBinding, BaseGraphicsData>* m_SBinds = nullptr;
GraphicsDataNode<IGraphicsBufferS, BaseGraphicsData>* m_SBufs = nullptr; GraphicsDataNode<IGraphicsBufferS, BaseGraphicsData>* m_SBufs = nullptr;
@ -58,8 +60,8 @@ struct BaseGraphicsData : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>
std::unique_lock<std::recursive_mutex> destructorLock() override std::unique_lock<std::recursive_mutex> destructorLock() override
{ return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex}; } { return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex}; }
explicit BaseGraphicsData(GraphicsDataFactoryHead& head) explicit BaseGraphicsData(GraphicsDataFactoryHead& head __BooTraceArgs)
: ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>(&head) : ListNode<BaseGraphicsData, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer
{} {}
}; };
@ -91,6 +93,8 @@ struct BaseGraphicsPool : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>
static std::unique_lock<std::recursive_mutex> _getHeadLock(GraphicsDataFactoryHead* head) static std::unique_lock<std::recursive_mutex> _getHeadLock(GraphicsDataFactoryHead* head)
{ return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; } { return std::unique_lock<std::recursive_mutex>{head->m_dataMutex}; }
__BooTraceFields
GraphicsDataNode<IGraphicsBufferD, BaseGraphicsPool>* m_DBufs = nullptr; GraphicsDataNode<IGraphicsBufferD, BaseGraphicsPool>* m_DBufs = nullptr;
template<class T> GraphicsDataNode<T, BaseGraphicsPool>*& getHead(); template<class T> GraphicsDataNode<T, BaseGraphicsPool>*& getHead();
template<class T> size_t countForward() template<class T> size_t countForward()
@ -98,8 +102,8 @@ struct BaseGraphicsPool : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>
std::unique_lock<std::recursive_mutex> destructorLock() override std::unique_lock<std::recursive_mutex> destructorLock() override
{ return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex}; } { return std::unique_lock<std::recursive_mutex>{m_head->m_dataMutex}; }
explicit BaseGraphicsPool(GraphicsDataFactoryHead& head) explicit BaseGraphicsPool(GraphicsDataFactoryHead& head __BooTraceArgs)
: ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>(&head) : ListNode<BaseGraphicsPool, GraphicsDataFactoryHead*>(&head) __BooTraceInitializer
{} {}
}; };

View File

@ -83,7 +83,7 @@ class GLDataFactoryImpl : public GLDataFactory, public GraphicsDataFactoryHead
ObjToken<IVertexFormat> m_gammaVFMT; ObjToken<IVertexFormat> m_gammaVFMT;
void SetupGammaResources() void SetupGammaResources()
{ {
commitTransaction([this](IGraphicsDataFactory::Context& ctx) BooCommitTransaction([this](IGraphicsDataFactory::Context& ctx)
{ {
const char* texNames[] = {"screenTex", "gammaLUT"}; const char* texNames[] = {"screenTex", "gammaLUT"};
m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS, m_gammaShader = static_cast<Context&>(ctx).newShaderPipeline(GammaVS, GammaFS,
@ -115,8 +115,8 @@ public:
Platform platform() const { return Platform::OpenGL; } Platform platform() const { return Platform::OpenGL; }
const SystemChar* platformName() const { return _S("OpenGL"); } const SystemChar* platformName() const { return _S("OpenGL"); }
void commitTransaction(const FactoryCommitFunc&); void commitTransaction(const FactoryCommitFunc& trans __BooTraceArgs);
ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count); ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs);
void _unregisterShareableShader(uint64_t srcKey, uint64_t binKey) { m_sharedShaders.erase(srcKey); } void _unregisterShareableShader(uint64_t srcKey, uint64_t binKey) { m_sharedShaders.erase(srcKey); }
void setDisplayGamma(float gamma) void setDisplayGamma(float gamma)
@ -1084,15 +1084,15 @@ GLDataFactory::Context::newShaderDataBinding(const ObjToken<IShaderPipeline>& pi
ubufOffs, ubufSizes, texCount, texs, texBindIdx, depthBind)}; ubufOffs, ubufSizes, texCount, texs, texBindIdx, depthBind)};
} }
GLDataFactory::Context::Context(GLDataFactory& parent) GLDataFactory::Context::Context(GLDataFactory& parent __BooTraceArgs)
: m_parent(parent), m_data(new BaseGraphicsData(static_cast<GLDataFactoryImpl&>(parent))) : m_parent(parent), m_data(new BaseGraphicsData(static_cast<GLDataFactoryImpl&>(parent) __BooTraceArgsUse))
{} {}
GLDataFactory::Context::~Context() {} GLDataFactory::Context::~Context() {}
void GLDataFactoryImpl::commitTransaction(const FactoryCommitFunc& trans) void GLDataFactoryImpl::commitTransaction(const FactoryCommitFunc& trans __BooTraceArgs)
{ {
GLDataFactory::Context ctx(*this); GLDataFactory::Context ctx(*this __BooTraceArgsUse);
if (!trans(ctx)) if (!trans(ctx))
return; return;
@ -1102,9 +1102,9 @@ void GLDataFactoryImpl::commitTransaction(const FactoryCommitFunc& trans)
//glFlush(); //glFlush();
} }
ObjToken<IGraphicsBufferD> GLDataFactoryImpl::newPoolBuffer(BufferUse use, size_t stride, size_t count) ObjToken<IGraphicsBufferD> GLDataFactoryImpl::newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs)
{ {
ObjToken<BaseGraphicsPool> pool(new BaseGraphicsPool(*this)); ObjToken<BaseGraphicsPool> pool(new BaseGraphicsPool(*this __BooTraceArgsUse));
return {new GLGraphicsBufferD<BaseGraphicsPool>(pool, use, stride * count)}; return {new GLGraphicsBufferD<BaseGraphicsPool>(pool, use, stride * count)};
} }
@ -1888,14 +1888,14 @@ ObjToken<IVertexFormat> GLDataFactory::Context::newVertexFormat
return {new GLVertexFormat(m_data, q, elementCount, elements, baseVert, baseInst)}; return {new GLVertexFormat(m_data, q, elementCount, elements, baseVert, baseInst)};
} }
IGraphicsCommandQueue* _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx) std::unique_ptr<IGraphicsCommandQueue> _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx)
{ {
return new struct GLCommandQueue(parent, glCtx); return std::make_unique<GLCommandQueue>(parent, glCtx);
} }
IGraphicsDataFactory* _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx) std::unique_ptr<IGraphicsDataFactory> _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx)
{ {
return new class GLDataFactoryImpl(parent, glCtx); return std::make_unique<GLDataFactoryImpl>(parent, glCtx);
} }
} }

View File

@ -88,7 +88,7 @@ class VulkanDataFactoryImpl : public VulkanDataFactory, public GraphicsDataFacto
ObjToken<IShaderDataBinding> m_gammaBinding; ObjToken<IShaderDataBinding> m_gammaBinding;
void SetupGammaResources() void SetupGammaResources()
{ {
commitTransaction([this](IGraphicsDataFactory::Context& ctx) BooCommitTransaction([this](IGraphicsDataFactory::Context& ctx)
{ {
const VertexElementDescriptor vfmt[] = { const VertexElementDescriptor vfmt[] = {
{nullptr, nullptr, VertexSemantic::Position4}, {nullptr, nullptr, VertexSemantic::Position4},
@ -124,9 +124,9 @@ public:
Platform platform() const {return Platform::Vulkan;} Platform platform() const {return Platform::Vulkan;}
const SystemChar* platformName() const {return _S("Vulkan");} const SystemChar* platformName() const {return _S("Vulkan");}
void commitTransaction(const FactoryCommitFunc&); void commitTransaction(const FactoryCommitFunc& __BooTraceArgs);
boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count); boo::ObjToken<IGraphicsBufferD> newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs);
void _unregisterShareableShader(uint64_t srcKey, uint64_t binKey) void _unregisterShareableShader(uint64_t srcKey, uint64_t binKey)
{ {
@ -957,8 +957,8 @@ struct VulkanData : BaseGraphicsData
VkDeviceMemory m_bufMem = VK_NULL_HANDLE; VkDeviceMemory m_bufMem = VK_NULL_HANDLE;
VkDeviceMemory m_texMem = VK_NULL_HANDLE; VkDeviceMemory m_texMem = VK_NULL_HANDLE;
explicit VulkanData(VulkanDataFactoryImpl& head) explicit VulkanData(VulkanDataFactoryImpl& head __BooTraceArgs)
: BaseGraphicsData(head), m_ctx(head.m_ctx) {} : BaseGraphicsData(head __BooTraceArgsUse), m_ctx(head.m_ctx) {}
~VulkanData() ~VulkanData()
{ {
if (m_bufMem) if (m_bufMem)
@ -972,8 +972,8 @@ struct VulkanPool : BaseGraphicsPool
{ {
VulkanContext* m_ctx; VulkanContext* m_ctx;
VkDeviceMemory m_bufMem = VK_NULL_HANDLE; VkDeviceMemory m_bufMem = VK_NULL_HANDLE;
explicit VulkanPool(VulkanDataFactoryImpl& head) explicit VulkanPool(VulkanDataFactoryImpl& head __BooTraceArgs)
: BaseGraphicsPool(head), m_ctx(head.m_ctx) {} : BaseGraphicsPool(head __BooTraceArgsUse), m_ctx(head.m_ctx) {}
~VulkanPool() ~VulkanPool()
{ {
if (m_bufMem) if (m_bufMem)
@ -3736,8 +3736,8 @@ boo::ObjToken<IShaderPipeline> VulkanDataFactory::Context::newShaderPipeline
return {retval}; return {retval};
} }
VulkanDataFactory::Context::Context(VulkanDataFactory& parent) VulkanDataFactory::Context::Context(VulkanDataFactory& parent __BooTraceArgs)
: m_parent(parent), m_data(new VulkanData(static_cast<VulkanDataFactoryImpl&>(parent))) {} : m_parent(parent), m_data(new VulkanData(static_cast<VulkanDataFactoryImpl&>(parent) __BooTraceArgsUse)) {}
VulkanDataFactory::Context::~Context() {} VulkanDataFactory::Context::~Context() {}
boo::ObjToken<IGraphicsBufferS> boo::ObjToken<IGraphicsBufferS>
@ -3820,9 +3820,9 @@ VulkanDataFactory::Context::newShaderDataBinding(
} }
void VulkanDataFactoryImpl::commitTransaction void VulkanDataFactoryImpl::commitTransaction
(const std::function<bool(IGraphicsDataFactory::Context&)>& trans) (const std::function<bool(IGraphicsDataFactory::Context&)>& trans __BooTraceArgs)
{ {
Context ctx(*this); Context ctx(*this __BooTraceArgsUse);
if (!trans(ctx)) if (!trans(ctx))
return; return;
@ -3944,10 +3944,10 @@ void VulkanDataFactoryImpl::commitTransaction
} }
boo::ObjToken<IGraphicsBufferD> boo::ObjToken<IGraphicsBufferD>
VulkanDataFactoryImpl::newPoolBuffer(BufferUse use, size_t stride, size_t count) VulkanDataFactoryImpl::newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs)
{ {
VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent->getCommandQueue()); VulkanCommandQueue* q = static_cast<VulkanCommandQueue*>(m_parent->getCommandQueue());
boo::ObjToken<BaseGraphicsPool> pool(new VulkanPool(*this)); boo::ObjToken<BaseGraphicsPool> pool(new VulkanPool(*this __BooTraceArgsUse));
VulkanPool* cpool = pool.cast<VulkanPool>(); VulkanPool* cpool = pool.cast<VulkanPool>();
VulkanGraphicsBufferD<BaseGraphicsPool>* retval = VulkanGraphicsBufferD<BaseGraphicsPool>* retval =
new VulkanGraphicsBufferD<BaseGraphicsPool>(pool, q, use, m_ctx, stride, count); new VulkanGraphicsBufferD<BaseGraphicsPool>(pool, q, use, m_ctx, stride, count);
@ -4112,15 +4112,15 @@ void VulkanCommandQueue::execute()
resetDynamicCommandBuffer(); resetDynamicCommandBuffer();
} }
IGraphicsCommandQueue* _NewVulkanCommandQueue(VulkanContext* ctx, VulkanContext::Window* windowCtx, std::unique_ptr<IGraphicsCommandQueue> _NewVulkanCommandQueue(VulkanContext* ctx, VulkanContext::Window* windowCtx,
IGraphicsContext* parent) IGraphicsContext* parent)
{ {
return new struct VulkanCommandQueue(ctx, windowCtx, parent); return std::make_unique<VulkanCommandQueue>(ctx, windowCtx, parent);
} }
IGraphicsDataFactory* _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx) std::unique_ptr<IGraphicsDataFactory> _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx)
{ {
return new class VulkanDataFactoryImpl(parent, ctx); return std::make_unique<VulkanDataFactoryImpl>(parent, ctx);
} }
} }

View File

@ -51,7 +51,7 @@ DBusConnection* RegisterDBus(const char* appName, bool& isFirst)
namespace boo namespace boo
{ {
IApplication* APP = NULL; IApplication* APP = nullptr;
int ApplicationRun(IApplication::EPlatformType platform, int ApplicationRun(IApplication::EPlatformType platform,
IApplicationCallback& cb, IApplicationCallback& cb,
std::string_view uniqueName, std::string_view uniqueName,
@ -75,7 +75,10 @@ int ApplicationRun(IApplication::EPlatformType platform,
APP = new ApplicationXlib(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor, singleInstance); APP = new ApplicationXlib(cb, uniqueName, friendlyName, pname, args, gfxApi, samples, anisotropy, deepColor, singleInstance);
else else
return 1; return 1;
return APP->run(); int ret = APP->run();
delete APP;
APP = nullptr;
return ret;
} }
} }

View File

@ -175,7 +175,7 @@ class ApplicationXlib final : public IApplication
Display* m_xDisp = nullptr; Display* m_xDisp = nullptr;
XIM m_xIM = nullptr; XIM m_xIM = nullptr;
XFontSet m_fontset; XFontSet m_fontset = nullptr;
XIMStyle m_bestStyle = 0; XIMStyle m_bestStyle = 0;
int m_xDefaultScreen = 0; int m_xDefaultScreen = 0;
int m_x11Fd, m_dbusFd, m_maxFd; int m_x11Fd, m_dbusFd, m_maxFd;
@ -408,6 +408,10 @@ public:
~ApplicationXlib() ~ApplicationXlib()
{ {
if (m_fontset)
XFreeFontSet(m_xDisp, m_fontset);
if (m_xIM)
XCloseIM(m_xIM);
XCloseDisplay(m_xDisp); XCloseDisplay(m_xDisp);
} }

View File

@ -111,13 +111,13 @@ extern "C" const size_t MAINICON_NETWM_SZ;
namespace boo namespace boo
{ {
static logvisor::Module Log("boo::WindowXlib"); static logvisor::Module Log("boo::WindowXlib");
IGraphicsCommandQueue* _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx); std::unique_ptr<IGraphicsCommandQueue> _NewGLCommandQueue(IGraphicsContext* parent, GLContext* glCtx);
IGraphicsDataFactory* _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx); std::unique_ptr<IGraphicsDataFactory> _NewGLDataFactory(IGraphicsContext* parent, GLContext* glCtx);
#if BOO_HAS_VULKAN #if BOO_HAS_VULKAN
IGraphicsCommandQueue* _NewVulkanCommandQueue(VulkanContext* ctx, std::unique_ptr<IGraphicsCommandQueue> _NewVulkanCommandQueue(VulkanContext* ctx,
VulkanContext::Window* windowCtx, VulkanContext::Window* windowCtx,
IGraphicsContext* parent); IGraphicsContext* parent);
IGraphicsDataFactory* _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx); std::unique_ptr<IGraphicsDataFactory> _NewVulkanDataFactory(IGraphicsContext* parent, VulkanContext* ctx);
#endif #endif
void _XlibUpdateLastGlxCtx(GLXContext lastGlxCtx); void _XlibUpdateLastGlxCtx(GLXContext lastGlxCtx);
void GLXExtensionCheck(); void GLXExtensionCheck();
@ -321,8 +321,8 @@ struct GraphicsContextXlibGLX : GraphicsContextXlib
GLXWindow m_glxWindow = 0; GLXWindow m_glxWindow = 0;
GLXContext m_glxCtx = 0; GLXContext m_glxCtx = 0;
IGraphicsCommandQueue* m_commandQueue = nullptr; std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
IGraphicsDataFactory* m_dataFactory = nullptr; std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
GLXContext m_mainCtx = 0; GLXContext m_mainCtx = 0;
GLXContext m_loadCtx = 0; GLXContext m_loadCtx = 0;
@ -577,12 +577,12 @@ public:
IGraphicsCommandQueue* getCommandQueue() IGraphicsCommandQueue* getCommandQueue()
{ {
return m_commandQueue; return m_commandQueue.get();
} }
IGraphicsDataFactory* getDataFactory() IGraphicsDataFactory* getDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
IGraphicsDataFactory* getMainContextDataFactory() IGraphicsDataFactory* getMainContextDataFactory()
@ -638,8 +638,8 @@ struct GraphicsContextXlibVulkan : GraphicsContextXlib
GLXFBConfig m_fbconfig = 0; GLXFBConfig m_fbconfig = 0;
int m_visualid = 0; int m_visualid = 0;
IGraphicsCommandQueue* m_commandQueue = nullptr; std::unique_ptr<IGraphicsDataFactory> m_dataFactory;
IGraphicsDataFactory* m_dataFactory = nullptr; std::unique_ptr<IGraphicsCommandQueue> m_commandQueue;
std::thread m_vsyncThread; std::thread m_vsyncThread;
bool m_vsyncRunning; bool m_vsyncRunning;
@ -888,12 +888,12 @@ public:
IGraphicsCommandQueue* getCommandQueue() IGraphicsCommandQueue* getCommandQueue()
{ {
return m_commandQueue; return m_commandQueue.get();
} }
IGraphicsDataFactory* getDataFactory() IGraphicsDataFactory* getDataFactory()
{ {
return m_dataFactory; return m_dataFactory.get();
} }
IGraphicsDataFactory* getMainContextDataFactory() IGraphicsDataFactory* getMainContextDataFactory()