diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-04 08:16:25 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:14 +0000 |
| commit | 5d11bc3700658755a37eb0add40deb4f167c2084 (patch) | |
| tree | 07f506d19191f59f4b590f28f48814118f8dd531 /Graphics/GraphicsEngineOpenGL | |
| parent | GL backend: some cosmetic code changes (diff) | |
| download | DiligentCore-5d11bc3700658755a37eb0add40deb4f167c2084.tar.gz DiligentCore-5d11bc3700658755a37eb0add40deb4f167c2084.zip | |
Unified device object creation in D3D12, Vulkan and OpenGL
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
6 files changed, 84 insertions, 154 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp index 9074f887..ba10834e 100644 --- a/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp @@ -50,16 +50,16 @@ public: BufferGLImpl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, RenderDeviceGLImpl* pDeviceGL, - GLContextState& CtxState, const BufferDesc& BuffDesc, + GLContextState& CtxState, const BufferData* pBuffData, bool bIsDeviceInternal); BufferGLImpl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, class RenderDeviceGLImpl* pDeviceGL, - GLContextState& CtxState, const BufferDesc& BuffDesc, + GLContextState& CtxState, GLuint GLHandle, bool bIsDeviceInternal); diff --git a/Graphics/GraphicsEngineOpenGL/include/FramebufferGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/FramebufferGLImpl.hpp index d4a8461a..f7e604e2 100644 --- a/Graphics/GraphicsEngineOpenGL/include/FramebufferGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/FramebufferGLImpl.hpp @@ -50,8 +50,8 @@ public: FramebufferGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDevice, - GLContextState& CtxState, - const FramebufferDesc& Desc); + const FramebufferDesc& Desc, + GLContextState& CtxState); ~FramebufferGLImpl(); struct SubpassFramebuffers diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp index e6d9557f..5342ed3e 100644 --- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp @@ -38,12 +38,54 @@ namespace Diligent { + +class RenderDeviceGLImpl; +class PipelineStateGLImpl; +class ShaderResourceBindingGLImpl; +class BufferGLImpl; +class BufferViewGLImpl; +class TextureBaseGL; +class TextureViewGLImpl; +class ShaderGLImpl; +class SamplerGLImpl; +class FenceGLImpl; +class QueryGLImpl; +class RenderPassGLImpl; +class FramebufferGLImpl; +class BottomLevelASGLImpl; +class TopLevelASGLImpl; +class ShaderBindingTableGLImpl; +class PipelineResourceSignatureGLImpl; + +struct RenderDeviceGLImplTraits +{ + using BaseInterface = IGLDeviceBaseInterface; + + using RenderDeviceImplType = RenderDeviceGLImpl; + using PipelineStateImplType = PipelineStateGLImpl; + using ShaderResourceBindingImplType = ShaderResourceBindingGLImpl; + using BufferImplType = BufferGLImpl; + using BufferViewImplType = BufferViewGLImpl; + using TextureImplType = TextureBaseGL; + using TextureViewImplType = TextureViewGLImpl; + using ShaderImplType = ShaderGLImpl; + using SamplerImplType = SamplerGLImpl; + using FenceImplType = FenceGLImpl; + using QueryImplType = QueryGLImpl; + using RenderPassImplType = RenderPassGLImpl; + using FramebufferImplType = FramebufferGLImpl; + using BottomLevelASImplType = BottomLevelASGLImpl; + using TopLevelASImplType = TopLevelASGLImpl; + using ShaderBindingTableImplType = ShaderBindingTableGLImpl; + using PipelineResourceSignatureImplType = PipelineResourceSignatureGLImpl; +}; + /// Render device implementation in OpenGL backend. // RenderDeviceGLESImpl is inherited from RenderDeviceGLImpl -class RenderDeviceGLImpl : public RenderDeviceBase<IGLDeviceBaseInterface> +class RenderDeviceGLImpl : public RenderDeviceBase<RenderDeviceGLImplTraits> { public: - using TRenderDeviceBase = RenderDeviceBase<IGLDeviceBaseInterface>; + using TRenderDeviceBase = RenderDeviceBase<RenderDeviceGLImplTraits>; RenderDeviceGLImpl(IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator, @@ -208,9 +250,6 @@ protected: std::unique_ptr<TexRegionRender> m_pTexRegionRender; private: - template <typename PSOCreateInfoType> - void CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState, bool bIsDeviceInternal); - virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final; bool CheckExtension(const Char* ExtensionString); void FlagSupportedTexFormats(); diff --git a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp index fa4d4e10..2ef67a48 100644 --- a/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp @@ -71,8 +71,8 @@ static GLenum GetBufferBindTarget(const BufferDesc& Desc) BufferGLImpl::BufferGLImpl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, RenderDeviceGLImpl* pDeviceGL, - GLContextState& GLState, const BufferDesc& BuffDesc, + GLContextState& GLState, const BufferData* pBuffData /*= nullptr*/, bool bIsDeviceInternal) : // clang-format off @@ -189,8 +189,8 @@ static BufferDesc GetBufferDescFromGLHandle(GLContextState& GLState, BufferDesc BufferGLImpl::BufferGLImpl(IReferenceCounters* pRefCounters, FixedBlockMemoryAllocator& BuffViewObjMemAllocator, RenderDeviceGLImpl* pDeviceGL, - GLContextState& CtxState, const BufferDesc& BuffDesc, + GLContextState& CtxState, GLuint GLHandle, bool bIsDeviceInternal) : // clang-format off diff --git a/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp index ca4092a7..8e7287b9 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp @@ -80,8 +80,8 @@ static bool UseDefaultFBO(Uint32 NumRenderTargets, FramebufferGLImpl::FramebufferGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDevice, - GLContextState& CtxState, - const FramebufferDesc& Desc) : + const FramebufferDesc& Desc, + GLContextState& CtxState) : TFramebufferBase{pRefCounters, pDevice, Desc} { const auto& RPDesc = m_Desc.pRenderPass->GetDesc(); diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 789a4760..1a92be5f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -125,6 +125,13 @@ static void GLAPIENTRY openglCallbackFunction(GLenum source, } #endif // GL_KHR_debug +class BottomLevelASGLImpl +{}; +class TopLevelASGLImpl +{}; +class ShaderBindingTableGLImpl +{}; + RenderDeviceGLImpl::RenderDeviceGLImpl(IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator, IEngineFactory* pEngineFactory, @@ -136,33 +143,12 @@ RenderDeviceGLImpl::RenderDeviceGLImpl(IReferenceCounters* pRefCounters, pRefCounters, RawMemAllocator, pEngineFactory, - 0, - DeviceObjectSizes - { - sizeof(TextureBaseGL), - sizeof(TextureViewGLImpl), - sizeof(BufferGLImpl), - sizeof(BufferViewGLImpl), - sizeof(ShaderGLImpl), - sizeof(SamplerGLImpl), - sizeof(PipelineStateGLImpl), - sizeof(ShaderResourceBindingGLImpl), - sizeof(FenceGLImpl), - sizeof(QueryGLImpl), - sizeof(RenderPassGLImpl), - sizeof(FramebufferGLImpl), - 0, - 0, - 0, - sizeof(PipelineResourceSignatureGLImpl) - } + 0 }, // Device caps must be filled in before the constructor of Pipeline Cache is called! m_GLContext{InitAttribs, m_DeviceCaps, pSCDesc} // clang-format on { - static_assert(sizeof(DeviceObjectSizes) == sizeof(size_t) * 16, "Please add new objects to DeviceObjectSizes constructor"); - GLint NumExtensions = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &NumExtensions); CHECK_GL_ERROR("Failed to get the number of extensions"); @@ -508,20 +494,10 @@ void RenderDeviceGLImpl::InitTexRegionRender() void RenderDeviceGLImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer, bool bIsDeviceInternal) { - CreateDeviceObject( - "buffer", BuffDesc, ppBuffer, - [&]() // - { - auto spDeviceContext = GetImmediateContext(); - VERIFY(spDeviceContext, "Immediate device context has been destroyed"); - auto* pDeviceContextGL = spDeviceContext.RawPtr<DeviceContextGLImpl>(); - - BufferGLImpl* pBufferOGL(NEW_RC_OBJ(m_BufObjAllocator, "BufferGLImpl instance", BufferGLImpl)(m_BuffViewObjAllocator, this, pDeviceContextGL->GetContextState(), BuffDesc, pBuffData, bIsDeviceInternal)); - pBufferOGL->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer)); - pBufferOGL->CreateDefaultViews(); - OnCreateDeviceObject(pBufferOGL); - } // - ); + auto spDeviceContext = GetImmediateContext(); + VERIFY(spDeviceContext, "Immediate device context has been destroyed"); + auto* pDeviceContextGL = spDeviceContext.RawPtr<DeviceContextGLImpl>(); + CreateBufferImpl(ppBuffer, BuffDesc, std::ref(pDeviceContextGL->GetContextState()), pBuffData, bIsDeviceInternal); } void RenderDeviceGLImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* BuffData, IBuffer** ppBuffer) @@ -531,35 +507,18 @@ void RenderDeviceGLImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferDa void RenderDeviceGLImpl::CreateBufferFromGLHandle(Uint32 GLHandle, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer) { - VERIFY(GLHandle, "GL buffer handle must not be null"); - CreateDeviceObject( - "buffer", BuffDesc, ppBuffer, - [&]() // - { - auto spDeviceContext = GetImmediateContext(); - VERIFY(spDeviceContext, "Immediate device context has been destroyed"); - auto* pDeviceContextGL = spDeviceContext.RawPtr<DeviceContextGLImpl>(); + DEV_CHECK_ERR(GLHandle != 0, "GL buffer handle must not be null"); - BufferGLImpl* pBufferOGL(NEW_RC_OBJ(m_BufObjAllocator, "BufferGLImpl instance", BufferGLImpl)(m_BuffViewObjAllocator, this, pDeviceContextGL->GetContextState(), BuffDesc, GLHandle, false)); - pBufferOGL->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer)); - pBufferOGL->CreateDefaultViews(); - OnCreateDeviceObject(pBufferOGL); - } // - ); + auto spDeviceContext = GetImmediateContext(); + VERIFY(spDeviceContext, "Immediate device context has been destroyed"); + auto* pDeviceContextGL = spDeviceContext.RawPtr<DeviceContextGLImpl>(); + + CreateBufferImpl(ppBuffer, BuffDesc, std::ref(pDeviceContextGL->GetContextState()), GLHandle, /*bIsDeviceInternal =*/false); } void RenderDeviceGLImpl::CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader, bool bIsDeviceInternal) { - CreateDeviceObject( - "shader", ShaderCreateInfo.Desc, ppShader, - [&]() // - { - ShaderGLImpl* pShaderOGL(NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderGLImpl instance", ShaderGLImpl)(this, ShaderCreateInfo, bIsDeviceInternal)); - pShaderOGL->QueryInterface(IID_Shader, reinterpret_cast<IObject**>(ppShader)); - - OnCreateDeviceObject(pShaderOGL); - } // - ); + CreateShaderImpl(ppShader, ShaderCreateInfo, bIsDeviceInternal); } void RenderDeviceGLImpl::CreateShader(const ShaderCreateInfo& ShaderCreateInfo, IShader** ppShader) @@ -619,7 +578,6 @@ void RenderDeviceGLImpl::CreateTexture(const TextureDesc& TexDesc, const Texture pTextureOGL->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture)); pTextureOGL->CreateDefaultViews(); - OnCreateDeviceObject(pTextureOGL); } // ); } @@ -680,7 +638,6 @@ void RenderDeviceGLImpl::CreateTextureFromGLHandle(Uint32 GLHandle, pTextureOGL->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture)); pTextureOGL->CreateDefaultViews(); - OnCreateDeviceObject(pTextureOGL); } // ); } @@ -703,27 +660,13 @@ void RenderDeviceGLImpl::CreateDummyTexture(const TextureDesc& TexDesc, RESOURCE pTextureOGL->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture)); pTextureOGL->CreateDefaultViews(); - OnCreateDeviceObject(pTextureOGL); } // ); } void RenderDeviceGLImpl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler, bool bIsDeviceInternal) { - CreateDeviceObject( - "sampler", SamplerDesc, ppSampler, - [&]() // - { - m_SamplersRegistry.Find(SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler)); - if (*ppSampler == nullptr) - { - SamplerGLImpl* pSamplerOGL(NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerGLImpl instance", SamplerGLImpl)(this, SamplerDesc, bIsDeviceInternal)); - pSamplerOGL->QueryInterface(IID_Sampler, reinterpret_cast<IObject**>(ppSampler)); - OnCreateDeviceObject(pSamplerOGL); - m_SamplersRegistry.Add(SamplerDesc, *ppSampler); - } - } // - ); + CreateSamplerImpl(ppSampler, SamplerDesc, bIsDeviceInternal); } void RenderDeviceGLImpl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler) @@ -731,38 +674,24 @@ void RenderDeviceGLImpl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler* CreateSampler(SamplerDesc, ppSampler, false); } -template <typename PSOCreateInfoType> -void RenderDeviceGLImpl::CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState, bool bIsDeviceInternal) -{ - CreateDeviceObject( - "Pipeline state", PSOCreateInfo.PSODesc, ppPipelineState, - [&]() // - { - PipelineStateGLImpl* pPipelineStateOGL(NEW_RC_OBJ(m_PSOAllocator, "PipelineStateGLImpl instance", PipelineStateGLImpl)(this, PSOCreateInfo, bIsDeviceInternal)); - pPipelineStateOGL->QueryInterface(IID_PipelineState, reinterpret_cast<IObject**>(ppPipelineState)); - OnCreateDeviceObject(pPipelineStateOGL); - } // - ); -} - void RenderDeviceGLImpl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState, bool bIsDeviceInternal) { - CreatePipelineState(PSOCreateInfo, ppPipelineState, bIsDeviceInternal); + CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo, bIsDeviceInternal); } void RenderDeviceGLImpl::CreateComputePipelineState(const ComputePipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState, bool bIsDeviceInternal) { - CreatePipelineState(PSOCreateInfo, ppPipelineState, bIsDeviceInternal); + CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo, bIsDeviceInternal); } void RenderDeviceGLImpl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) { - return CreateGraphicsPipelineState(PSOCreateInfo, ppPipelineState, false); + CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo, false); } void RenderDeviceGLImpl::CreateComputePipelineState(const ComputePipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) { - return CreateComputePipelineState(PSOCreateInfo, ppPipelineState, false); + CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo, false); } void RenderDeviceGLImpl::CreateRayTracingPipelineState(const RayTracingPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState) @@ -773,57 +702,26 @@ void RenderDeviceGLImpl::CreateRayTracingPipelineState(const RayTracingPipelineS void RenderDeviceGLImpl::CreateFence(const FenceDesc& Desc, IFence** ppFence) { - CreateDeviceObject( - "Fence", Desc, ppFence, - [&]() // - { - FenceGLImpl* pFenceOGL(NEW_RC_OBJ(m_FenceAllocator, "FenceGLImpl instance", FenceGLImpl)(this, Desc)); - pFenceOGL->QueryInterface(IID_Fence, reinterpret_cast<IObject**>(ppFence)); - OnCreateDeviceObject(pFenceOGL); - } // - ); + CreateFenceImpl(ppFence, Desc); } void RenderDeviceGLImpl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery) { - CreateDeviceObject( - "Query", Desc, ppQuery, - [&]() // - { - QueryGLImpl* pQueryOGL(NEW_RC_OBJ(m_QueryAllocator, "QueryGLImpl instance", QueryGLImpl)(this, Desc)); - pQueryOGL->QueryInterface(IID_Query, reinterpret_cast<IObject**>(ppQuery)); - OnCreateDeviceObject(pQueryOGL); - } // - ); + CreateQueryImpl(ppQuery, Desc); } void RenderDeviceGLImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass) { - CreateDeviceObject( - "RenderPass", Desc, ppRenderPass, - [&]() // - { - RenderPassGLImpl* pRenderPassOGL(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassGLImpl instance", RenderPassGLImpl)(this, Desc)); - pRenderPassOGL->QueryInterface(IID_RenderPass, reinterpret_cast<IObject**>(ppRenderPass)); - OnCreateDeviceObject(pRenderPassOGL); - } // - ); + CreateRenderPassImpl(ppRenderPass, Desc); } void RenderDeviceGLImpl::CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer) { - CreateDeviceObject( - "Framebuffer", Desc, ppFramebuffer, - [&]() // - { - auto spDeviceContext = GetImmediateContext(); - VERIFY(spDeviceContext, "Immediate device context has been destroyed"); - auto& GLState = spDeviceContext.RawPtr<DeviceContextGLImpl>()->GetContextState(); + auto spDeviceContext = GetImmediateContext(); + VERIFY(spDeviceContext, "Immediate device context has been destroyed"); + auto& GLState = spDeviceContext.RawPtr<DeviceContextGLImpl>()->GetContextState(); - FramebufferGLImpl* pFramebufferGL(NEW_RC_OBJ(m_FramebufferAllocator, "FramebufferGLImpl instance", FramebufferGLImpl)(this, GLState, Desc)); - pFramebufferGL->QueryInterface(IID_Framebuffer, reinterpret_cast<IObject**>(ppFramebuffer)); - OnCreateDeviceObject(pFramebufferGL); - }); + CreateFramebufferImpl(ppFramebuffer, Desc, std::ref(GLState)); } void RenderDeviceGLImpl::CreatePipelineResourceSignature(const PipelineResourceSignatureDesc& Desc, @@ -836,14 +734,7 @@ void RenderDeviceGLImpl::CreatePipelineResourceSignature(const PipelineResourceS IPipelineResourceSignature** ppSignature, bool IsDeviceInternal) { - CreateDeviceObject( - "PipelineResourceSignature", Desc, ppSignature, - [&]() // - { - PipelineResourceSignatureGLImpl* pPRSGL(NEW_RC_OBJ(m_PipeResSignAllocator, "PipelineResourceSignatureGLImpl instance", PipelineResourceSignatureGLImpl)(this, Desc, IsDeviceInternal)); - pPRSGL->QueryInterface(IID_PipelineResourceSignature, reinterpret_cast<IObject**>(ppSignature)); - OnCreateDeviceObject(pPRSGL); - }); + CreatePipelineResourceSignatureImpl(ppSignature, Desc, IsDeviceInternal); } void RenderDeviceGLImpl::CreateBLAS(const BottomLevelASDesc& Desc, |
