summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-03-04 08:16:25 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:14 +0000
commit5d11bc3700658755a37eb0add40deb4f167c2084 (patch)
tree07f506d19191f59f4b590f28f48814118f8dd531 /Graphics
parentGL backend: some cosmetic code changes (diff)
downloadDiligentCore-5d11bc3700658755a37eb0add40deb4f167c2084.tar.gz
DiligentCore-5d11bc3700658755a37eb0add40deb4f167c2084.zip
Unified device object creation in D3D12, Vulkan and OpenGL
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/RenderDeviceBase.hpp432
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp49
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp182
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp15
-rw-r--r--Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.hpp17
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/BufferGLImpl.hpp4
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/FramebufferGLImpl.hpp4
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp49
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/BufferGLImpl.cpp4
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp4
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp173
-rw-r--r--Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp48
-rw-r--r--Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp211
13 files changed, 494 insertions, 698 deletions
diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
index 928dd792..faafb9d2 100644
--- a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
+++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp
@@ -175,84 +175,48 @@ namespace Diligent
/// Base implementation of a render device
-/// \tparam BaseInterface - base interface that this class will inheret.
-/// \warning
-/// Render device must *NOT* hold strong references to any
-/// object it creates to avoid circular dependencies.
-/// Device context, swap chain and all object the device creates
-/// keep strong reference to the device.
-/// Device only holds weak reference to the immediate context.
-template <typename BaseInterface>
-class RenderDeviceBase : public ObjectBase<BaseInterface>
+/// \tparam RenderDeviceImplTraits - Render device implementation type traits.
+///
+/// \warning Render device must *NOT* hold strong references to any object it creates
+/// to avoid cyclic dependencies. Device context, swap chain and all object
+/// the device creates keep strong reference to the device.
+/// Device only holds weak reference to the immediate context.
+template <typename RenderDeviceImplTraits>
+class RenderDeviceBase : public ObjectBase<typename RenderDeviceImplTraits::BaseInterface>
{
public:
- using TObjectBase = ObjectBase<BaseInterface>;
-
- /// Describes the sizes of device objects
- struct DeviceObjectSizes
- {
- /// Size of the texture object (TextureD3D12Impl, TextureVkImpl, etc.), in bytes
- const size_t TextureObjSize;
-
- /// Size of the texture view object (TextureViewD3D12Impl, TextureViewVkImpl, etc.), in bytes
- const size_t TexViewObjSize;
-
- /// Size of the buffer object (BufferD3D12Impl, BufferVkImpl, etc.), in bytes
- const size_t BufferObjSize;
-
- /// Size of the buffer view object (BufferViewD3D12Impl, BufferViewVkImpl, etc.), in bytes
- const size_t BuffViewObjSize;
-
- /// Size of the shader object (ShaderD3D12Impl, ShaderVkImpl, etc.), in bytes
- const size_t ShaderObjSize;
-
- /// Size of the sampler object (SamplerD3D12Impl, SamplerVkImpl, etc.), in bytes
- const size_t SamplerObjSize;
-
- /// Size of the pipeline state object (PipelineStateD3D12Impl, PipelineStateVkImpl, etc.), in bytes
- const size_t PSOSize;
-
- /// Size of the shader resource binding object (ShaderResourceBindingD3D12Impl, ShaderResourceBindingVkImpl, etc.), in bytes
- const size_t SRBSize;
-
- /// Size of the fence object (FenceD3D12Impl, FenceVkImpl, etc.), in bytes
- const size_t FenceSize;
-
- /// Size of the query object (QueryD3D12Impl, QueryVkImpl, etc.), in bytes
- const size_t QuerySize;
-
- /// Size of the render pass object (RenderPassD3D12Impl, RenderPassVkImpl, etc.), in bytes
- const size_t RenderPassObjSize;
-
- /// Size of the framebuffer object (FramebufferD3D12Impl, FramebufferVkImpl, etc.), in bytes
- const size_t FramebufferObjSize;
-
- /// Size of the BLAS object (BottomLevelASD3D12Impl, BottomLevelASVkImpl, etc.), in bytes
- const size_t BLASObjSize;
-
- /// Size of the TLAS object (TopLevelASD3D12Impl, TopLevelASVkImpl, etc.), in bytes
- const size_t TLASObjSize;
-
- /// Size of the SBT object (ShaderBindingTableD3D12Impl, ShaderBindingtableVkImpl, etc.), in bytes
- const size_t SBTObjSize;
-
- /// Size of the pipeline resource signature object (PipelineResourceSignatureD3D12Impl, PipelineResourceSignatureVkImpl, etc.), in bytes
- const size_t PipeResSignObjSize;
- };
+ using BaseInterface = typename RenderDeviceImplTraits::BaseInterface;
+ using TObjectBase = ObjectBase<BaseInterface>;
+
+ using RenderDeviceImplType = typename RenderDeviceImplTraits::RenderDeviceImplType;
+ using PipelineStateImplType = typename RenderDeviceImplTraits::PipelineStateImplType;
+ using ShaderResourceBindingImplType = typename RenderDeviceImplTraits::ShaderResourceBindingImplType;
+ using BufferImplType = typename RenderDeviceImplTraits::BufferImplType;
+ using BufferViewImplType = typename RenderDeviceImplTraits::BufferViewImplType;
+ using TextureImplType = typename RenderDeviceImplTraits::TextureImplType;
+ using TextureViewImplType = typename RenderDeviceImplTraits::TextureViewImplType;
+ using ShaderImplType = typename RenderDeviceImplTraits::ShaderImplType;
+ using SamplerImplType = typename RenderDeviceImplTraits::SamplerImplType;
+ using FenceImplType = typename RenderDeviceImplTraits::FenceImplType;
+ using QueryImplType = typename RenderDeviceImplTraits::QueryImplType;
+ using RenderPassImplType = typename RenderDeviceImplTraits::RenderPassImplType;
+ using FramebufferImplType = typename RenderDeviceImplTraits::FramebufferImplType;
+ using BottomLevelASImplType = typename RenderDeviceImplTraits::BottomLevelASImplType;
+ using TopLevelASImplType = typename RenderDeviceImplTraits::TopLevelASImplType;
+ using ShaderBindingTableImplType = typename RenderDeviceImplTraits::ShaderBindingTableImplType;
+ using PipelineResourceSignatureImplType = typename RenderDeviceImplTraits::PipelineResourceSignatureImplType;
/// \param pRefCounters - Reference counters object that controls the lifetime of this render device
/// \param RawMemAllocator - Allocator that will be used to allocate memory for all device objects (including render device itself)
/// \param pEngineFactory - Engine factory that was used to create this device
/// \param NumDeferredContexts - The number of deferred device contexts
- /// \param ObjectSizes - Device object sizes
///
/// \remarks Render device uses fixed block allocators (see FixedBlockMemoryAllocator) to allocate memory for
/// device objects. The object sizes provided to constructor are used to initialize the allocators.
- RenderDeviceBase(IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
- IEngineFactory* pEngineFactory,
- Uint32 NumDeferredContexts,
- const DeviceObjectSizes& ObjectSizes) :
+ RenderDeviceBase(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ IEngineFactory* pEngineFactory,
+ Uint32 NumDeferredContexts) :
// clang-format off
TObjectBase {pRefCounters},
m_pEngineFactory {pEngineFactory},
@@ -261,23 +225,23 @@ public:
m_TexFmtInfoInitFlags (TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator, "Allocator for vector<bool>")),
m_wpDeferredContexts (NumDeferredContexts, RefCntWeakPtr<IDeviceContext>(), STD_ALLOCATOR_RAW_MEM(RefCntWeakPtr<IDeviceContext>, RawMemAllocator, "Allocator for vector< RefCntWeakPtr<IDeviceContext> >")),
m_RawMemAllocator {RawMemAllocator},
- m_TexObjAllocator {RawMemAllocator, ObjectSizes.TextureObjSize, 64 },
- m_TexViewObjAllocator {RawMemAllocator, ObjectSizes.TexViewObjSize, 64 },
- m_BufObjAllocator {RawMemAllocator, ObjectSizes.BufferObjSize, 128 },
- m_BuffViewObjAllocator {RawMemAllocator, ObjectSizes.BuffViewObjSize, 128 },
- m_ShaderObjAllocator {RawMemAllocator, ObjectSizes.ShaderObjSize, 32 },
- m_SamplerObjAllocator {RawMemAllocator, ObjectSizes.SamplerObjSize, 32 },
- m_PSOAllocator {RawMemAllocator, ObjectSizes.PSOSize, 128 },
- m_SRBAllocator {RawMemAllocator, ObjectSizes.SRBSize, 1024},
- m_ResMappingAllocator {RawMemAllocator, sizeof(ResourceMappingImpl), 16 },
- m_FenceAllocator {RawMemAllocator, ObjectSizes.FenceSize, 16 },
- m_QueryAllocator {RawMemAllocator, ObjectSizes.QuerySize, 16 },
- m_RenderPassAllocator {RawMemAllocator, ObjectSizes.RenderPassObjSize, 16 },
- m_FramebufferAllocator {RawMemAllocator, ObjectSizes.FramebufferObjSize, 16 },
- m_BLASAllocator {RawMemAllocator, ObjectSizes.BLASObjSize, 16 },
- m_TLASAllocator {RawMemAllocator, ObjectSizes.TLASObjSize, 16 },
- m_SBTAllocator {RawMemAllocator, ObjectSizes.SBTObjSize, 16 },
- m_PipeResSignAllocator {RawMemAllocator, ObjectSizes.PipeResSignObjSize, 128 },
+ m_TexObjAllocator {RawMemAllocator, sizeof(TextureImplType), 64},
+ m_TexViewObjAllocator {RawMemAllocator, sizeof(TextureViewImplType), 64},
+ m_BufObjAllocator {RawMemAllocator, sizeof(BufferImplType), 128},
+ m_BuffViewObjAllocator {RawMemAllocator, sizeof(BufferViewImplType), 128},
+ m_ShaderObjAllocator {RawMemAllocator, sizeof(ShaderImplType), 32},
+ m_SamplerObjAllocator {RawMemAllocator, sizeof(SamplerImplType), 32},
+ m_PSOAllocator {RawMemAllocator, sizeof(PipelineStateImplType), 128},
+ m_SRBAllocator {RawMemAllocator, sizeof(ShaderResourceBindingImplType), 1024},
+ m_ResMappingAllocator {RawMemAllocator, sizeof(ResourceMappingImpl), 16},
+ m_FenceAllocator {RawMemAllocator, sizeof(FenceImplType), 16},
+ m_QueryAllocator {RawMemAllocator, sizeof(QueryImplType), 16},
+ m_RenderPassAllocator {RawMemAllocator, sizeof(RenderPassImplType), 16},
+ m_FramebufferAllocator {RawMemAllocator, sizeof(FramebufferImplType), 16},
+ m_BLASAllocator {RawMemAllocator, sizeof(BottomLevelASImplType), 16},
+ m_TLASAllocator {RawMemAllocator, sizeof(TopLevelASImplType), 16},
+ m_SBTAllocator {RawMemAllocator, sizeof(ShaderBindingTableImplType), 16},
+ m_PipeResSignAllocator {RawMemAllocator, sizeof(PipelineResourceSignatureImplType), 128},
m_DeviceProperties {}
// clang-format on
{
@@ -344,7 +308,24 @@ public:
}
/// Implementation of IRenderDevice::CreateResourceMapping().
- virtual void DILIGENT_CALL_TYPE CreateResourceMapping(const ResourceMappingDesc& MappingDesc, IResourceMapping** ppMapping) override final;
+ virtual void DILIGENT_CALL_TYPE CreateResourceMapping(const ResourceMappingDesc& MappingDesc, IResourceMapping** ppMapping) override final
+ {
+ DEV_CHECK_ERR(ppMapping != nullptr, "Null pointer provided");
+ if (ppMapping == nullptr)
+ return;
+ DEV_CHECK_ERR(*ppMapping == nullptr, "Overwriting reference to existing object may cause memory leaks");
+
+ auto* pResourceMapping{NEW_RC_OBJ(m_ResMappingAllocator, "ResourceMappingImpl instance", ResourceMappingImpl)(GetRawAllocator())};
+ pResourceMapping->QueryInterface(IID_ResourceMapping, reinterpret_cast<IObject**>(ppMapping));
+ if (MappingDesc.pEntries)
+ {
+ for (auto* pEntry = MappingDesc.pEntries; pEntry->Name && pEntry->pObject; ++pEntry)
+ {
+ (*ppMapping)->AddResourceArray(pEntry->Name, pEntry->ArrayIndex, &pEntry->pObject, 1, true);
+ }
+ }
+ }
+
/// Implementation of IRenderDevice::GetDeviceCaps().
virtual const DeviceCaps& DILIGENT_CALL_TYPE GetDeviceCaps() const override final
@@ -387,10 +368,6 @@ public:
return m_pEngineFactory.RawPtr<IEngineFactory>();
}
- void OnCreateDeviceObject(IDeviceObject* pNewObject)
- {
- }
-
StateObjectsRegistry<SamplerDesc>& GetSamplerRegistry() { return m_SamplersRegistry; }
/// Set weak reference to the immediate context
@@ -424,9 +401,209 @@ protected:
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) = 0;
/// Helper template function to facilitate device object creation
- template <typename TObjectType, typename TObjectDescType, typename TObjectConstructor>
- void CreateDeviceObject(const Char* ObjectTypeName, const TObjectDescType& Desc, TObjectType** ppObject, TObjectConstructor ConstructObject);
+ /// \tparam ObjectType - The type of the object being created (IBuffer, ITexture, etc.).
+ /// \tparam ObjectDescType - The type of the object description structure (BufferDesc, TextureDesc, etc.).
+ /// \tparam ObjectConstructorType - The type of the function that constructs the object.
+ ///
+ /// \param ObjectTypeName - String name of the object type ("buffer", "texture", etc.).
+ /// \param Desc - Object description.
+ /// \param ppObject - Memory address where the pointer to the created object will be stored.
+ /// \param ConstructObject - Function that constructs the object.
+ template <typename ObjectType, typename ObjectDescType, typename ObjectConstructorType>
+ void CreateDeviceObject(const Char* ObjectTypeName,
+ const ObjectDescType& Desc,
+ ObjectType** ppObject,
+ ObjectConstructorType ConstructObject)
+ {
+ DEV_CHECK_ERR(ppObject != nullptr, "Null pointer provided");
+ if (!ppObject)
+ return;
+
+ DEV_CHECK_ERR(*ppObject == nullptr, "Overwriting reference to existing object may cause memory leaks");
+ // Do not release *ppObject here!
+ // Should this happen, RefCntAutoPtr<> will take care of this!
+ //if( *ppObject )
+ //{
+ // (*ppObject)->Release();
+ // *ppObject = nullptr;
+ //}
+
+ *ppObject = nullptr;
+
+ try
+ {
+ ConstructObject();
+ }
+ catch (...)
+ {
+ VERIFY(*ppObject == nullptr, "Object was created despite error");
+ if (*ppObject)
+ {
+ (*ppObject)->Release();
+ *ppObject = nullptr;
+ }
+ const auto ObjectDescString = GetObjectDescString(Desc);
+ if (!ObjectDescString.empty())
+ {
+ LOG_ERROR("Failed to create ", ObjectTypeName, " object '", (Desc.Name ? Desc.Name : ""), "'\n", ObjectDescString);
+ }
+ else
+ {
+ LOG_ERROR("Failed to create ", ObjectTypeName, " object '", (Desc.Name ? Desc.Name : ""), "'");
+ }
+ }
+ }
+
+ template <typename PSOCreateInfoType, typename... ExtraArgsType>
+ void CreatePipelineStateImpl(IPipelineState** ppPipelineState, const PSOCreateInfoType& PSOCreateInfo, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Pipeline State", PSOCreateInfo.PSODesc, ppPipelineState,
+ [&]() //
+ {
+ auto* pPipelineStateImpl{NEW_RC_OBJ(m_PSOAllocator, "Pipeline State instance", PipelineStateImplType)(static_cast<RenderDeviceImplType*>(this), PSOCreateInfo, ExtraArgs...)};
+ pPipelineStateImpl->QueryInterface(IID_PipelineState, reinterpret_cast<IObject**>(ppPipelineState));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateBufferImpl(IBuffer** ppBuffer, const BufferDesc& BuffDesc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Buffer", BuffDesc, ppBuffer,
+ [&]() //
+ {
+ auto* pBufferImpl{NEW_RC_OBJ(m_BufObjAllocator, "Buffer instance", BufferImplType)(m_BuffViewObjAllocator, static_cast<RenderDeviceImplType*>(this), BuffDesc, ExtraArgs...)};
+ pBufferImpl->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer));
+ pBufferImpl->CreateDefaultViews();
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateTextureImpl(ITexture** ppTexture, const TextureDesc& TexDesc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Texture", TexDesc, ppTexture,
+ [&]() //
+ {
+ auto* pTextureImpl{NEW_RC_OBJ(m_TexObjAllocator, "Texture instance", TextureImplType)(m_TexViewObjAllocator, static_cast<RenderDeviceImplType*>(this), TexDesc, ExtraArgs...)};
+ pTextureImpl->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture));
+ pTextureImpl->CreateDefaultViews();
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateShaderImpl(IShader** ppShader, const ShaderCreateInfo& ShaderCI, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Shader", ShaderCI.Desc, ppShader,
+ [&]() //
+ {
+ auto* pShaderImpl{NEW_RC_OBJ(m_ShaderObjAllocator, "Shader instance", ShaderImplType)(static_cast<RenderDeviceImplType*>(this), ShaderCI, ExtraArgs...)};
+ pShaderImpl->QueryInterface(IID_Shader, reinterpret_cast<IObject**>(ppShader));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateSamplerImpl(ISampler** ppSampler, const SamplerDesc& SamplerDesc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Sampler", SamplerDesc, ppSampler,
+ [&]() //
+ {
+ m_SamplersRegistry.Find(SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler));
+ if (*ppSampler == nullptr)
+ {
+ auto* pSamplerImpl{NEW_RC_OBJ(m_SamplerObjAllocator, "Sampler instance", SamplerImplType)(static_cast<RenderDeviceImplType*>(this), SamplerDesc, ExtraArgs...)};
+ pSamplerImpl->QueryInterface(IID_Sampler, reinterpret_cast<IObject**>(ppSampler));
+ m_SamplersRegistry.Add(SamplerDesc, *ppSampler);
+ }
+ });
+ }
+
+ void CreateFenceImpl(IFence** ppFence, const FenceDesc& Desc)
+ {
+ CreateDeviceObject("Fence", Desc, ppFence,
+ [&]() //
+ {
+ auto* pFenceImpl{NEW_RC_OBJ(m_FenceAllocator, "Fence instance", FenceImplType)(static_cast<RenderDeviceImplType*>(this), Desc)};
+ pFenceImpl->QueryInterface(IID_Fence, reinterpret_cast<IObject**>(ppFence));
+ });
+ }
+
+ void CreateQueryImpl(IQuery** ppQuery, const QueryDesc& Desc)
+ {
+ CreateDeviceObject("Query", Desc, ppQuery,
+ [&]() //
+ {
+ auto* pQueryImpl{NEW_RC_OBJ(m_QueryAllocator, "Query instance", QueryImplType)(static_cast<RenderDeviceImplType*>(this), Desc)};
+ pQueryImpl->QueryInterface(IID_Query, reinterpret_cast<IObject**>(ppQuery));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateRenderPassImpl(IRenderPass** ppRenderPass, const RenderPassDesc& Desc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("RenderPass", Desc, ppRenderPass,
+ [&]() //
+ {
+ auto* pRenderPassImpl{NEW_RC_OBJ(m_RenderPassAllocator, "Render instance", RenderPassImplType)(static_cast<RenderDeviceImplType*>(this), Desc, ExtraArgs...)};
+ pRenderPassImpl->QueryInterface(IID_RenderPass, reinterpret_cast<IObject**>(ppRenderPass));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateFramebufferImpl(IFramebuffer** ppFramebuffer, const FramebufferDesc& Desc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("Framebuffer", Desc, ppFramebuffer,
+ [&]() //
+ {
+ auto* pFramebufferImpl{NEW_RC_OBJ(m_FramebufferAllocator, "Framebuffer instance", FramebufferImplType)(static_cast<RenderDeviceImplType*>(this), Desc, ExtraArgs...)};
+ pFramebufferImpl->QueryInterface(IID_Framebuffer, reinterpret_cast<IObject**>(ppFramebuffer));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateBLASImpl(IBottomLevelAS** ppBLAS, const BottomLevelASDesc& Desc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("BottomLevelAS", Desc, ppBLAS,
+ [&]() //
+ {
+ auto* pBottomLevelASImpl(NEW_RC_OBJ(m_BLASAllocator, "BottomLevelAS instance", BottomLevelASImplType)(static_cast<RenderDeviceImplType*>(this), Desc, ExtraArgs...));
+ pBottomLevelASImpl->QueryInterface(IID_BottomLevelAS, reinterpret_cast<IObject**>(ppBLAS));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreateTLASImpl(ITopLevelAS** ppTLAS, const TopLevelASDesc& Desc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("TopLevelAS", Desc, ppTLAS,
+ [&]() //
+ {
+ auto* pTopLevelASImpl(NEW_RC_OBJ(m_TLASAllocator, "TopLevelAS instance", TopLevelASImplType)(static_cast<RenderDeviceImplType*>(this), Desc, ExtraArgs...));
+ pTopLevelASImpl->QueryInterface(IID_TopLevelAS, reinterpret_cast<IObject**>(ppTLAS));
+ });
+ }
+
+ void CreateSBTImpl(IShaderBindingTable** ppSBT, const ShaderBindingTableDesc& Desc)
+ {
+ CreateDeviceObject("ShaderBindingTable", Desc, ppSBT,
+ [&]() //
+ {
+ auto* pSBTImpl(NEW_RC_OBJ(m_SBTAllocator, "ShaderBindingTable instance", ShaderBindingTableImplType)(static_cast<RenderDeviceImplType*>(this), Desc));
+ pSBTImpl->QueryInterface(IID_ShaderBindingTable, reinterpret_cast<IObject**>(ppSBT));
+ });
+ }
+
+ template <typename... ExtraArgsType>
+ void CreatePipelineResourceSignatureImpl(IPipelineResourceSignature** ppSignature, const PipelineResourceSignatureDesc& Desc, const ExtraArgsType&... ExtraArgs)
+ {
+ CreateDeviceObject("PipelineResourceSignature", Desc, ppSignature,
+ [&]() //
+ {
+ auto* pPRSImpl(NEW_RC_OBJ(m_PipeResSignAllocator, "PipelineResourceSignature instance", PipelineResourceSignatureImplType)(static_cast<RenderDeviceImplType*>(this), Desc, ExtraArgs...));
+ pPRSImpl->QueryInterface(IID_PipelineResourceSignature, reinterpret_cast<IObject**>(ppSignature));
+ });
+ }
+
+
+protected:
RefCntAutoPtr<IEngineFactory> m_pEngineFactory;
DeviceCaps m_DeviceCaps;
@@ -466,75 +643,4 @@ protected:
FixedBlockMemoryAllocator m_PipeResSignAllocator; ///< Allocator for pipeline resource signature objects
};
-
-template <typename BaseInterface>
-void RenderDeviceBase<BaseInterface>::CreateResourceMapping(const ResourceMappingDesc& MappingDesc, IResourceMapping** ppMapping)
-{
- VERIFY(ppMapping != nullptr, "Null pointer provided");
- if (ppMapping == nullptr)
- return;
- VERIFY(*ppMapping == nullptr, "Overwriting reference to existing object may cause memory leaks");
-
- auto* pResourceMapping(NEW_RC_OBJ(m_ResMappingAllocator, "ResourceMappingImpl instance", ResourceMappingImpl)(GetRawAllocator()));
- pResourceMapping->QueryInterface(IID_ResourceMapping, reinterpret_cast<IObject**>(ppMapping));
- if (MappingDesc.pEntries)
- {
- for (auto* pEntry = MappingDesc.pEntries; pEntry->Name && pEntry->pObject; ++pEntry)
- {
- (*ppMapping)->AddResourceArray(pEntry->Name, pEntry->ArrayIndex, &pEntry->pObject, 1, true);
- }
- }
-}
-
-
-/// \tparam TObjectType - The type of the object being created (IBuffer, ITexture, etc.).
-/// \tparam TObjectDescType - The type of the object description structure (BufferDesc, TextureDesc, etc.).
-/// \tparam TObjectConstructor - The type of the function that constructs the object.
-/// \param ObjectTypeName - String name of the object type ("buffer", "texture", etc.).
-/// \param Desc - Object description.
-/// \param ppObject - Memory address where the pointer to the created object will be stored.
-/// \param ConstructObject - Function that constructs the object.
-template <typename BaseInterface>
-template <typename TObjectType, typename TObjectDescType, typename TObjectConstructor>
-void RenderDeviceBase<BaseInterface>::CreateDeviceObject(const Char* ObjectTypeName, const TObjectDescType& Desc, TObjectType** ppObject, TObjectConstructor ConstructObject)
-{
- VERIFY(ppObject != nullptr, "Null pointer provided");
- if (!ppObject)
- return;
-
- VERIFY(*ppObject == nullptr, "Overwriting reference to existing object may cause memory leaks");
- // Do not release *ppObject here!
- // Should this happen, RefCntAutoPtr<> will take care of this!
- //if( *ppObject )
- //{
- // (*ppObject)->Release();
- // *ppObject = nullptr;
- //}
-
- *ppObject = nullptr;
-
- try
- {
- ConstructObject();
- }
- catch (const std::runtime_error&)
- {
- VERIFY(*ppObject == nullptr, "Object was created despite error");
- if (*ppObject)
- {
- (*ppObject)->Release();
- *ppObject = nullptr;
- }
- auto ObjectDescString = GetObjectDescString(Desc);
- if (ObjectDescString.length())
- {
- LOG_ERROR("Failed to create ", ObjectTypeName, " object '", (Desc.Name ? Desc.Name : ""), "'\n", ObjectDescString);
- }
- else
- {
- LOG_ERROR("Failed to create ", ObjectTypeName, " object '", (Desc.Name ? Desc.Name : ""), "'");
- }
- }
-}
-
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
index 37ce8965..5224d50c 100644
--- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
@@ -66,11 +66,53 @@
namespace Diligent
{
+class RenderDeviceD3D12Impl;
+class PipelineStateD3D12Impl;
+class ShaderResourceBindingD3D12Impl;
+class BufferD3D12Impl;
+class BufferViewD3D12Impl;
+class TextureD3D12Impl;
+class TextureViewD3D12Impl;
+class ShaderD3D12Impl;
+class SamplerD3D12Impl;
+class FenceD3D12Impl;
+class QueryD3D12Impl;
+class RenderPassD3D12Impl;
+class FramebufferD3D12Impl;
+class BottomLevelASD3D12Impl;
+class TopLevelASD3D12Impl;
+class ShaderBindingTableD3D12Impl;
+class PipelineResourceSignatureD3D12Impl;
+
+struct RenderDeviceD3D12ImplTraits
+{
+ using BaseInterface = IRenderDeviceD3D12;
+
+ using RenderDeviceImplType = RenderDeviceD3D12Impl;
+ using PipelineStateImplType = PipelineStateD3D12Impl;
+ using ShaderResourceBindingImplType = ShaderResourceBindingD3D12Impl;
+ using BufferImplType = BufferD3D12Impl;
+ using BufferViewImplType = BufferViewD3D12Impl;
+ using TextureImplType = TextureD3D12Impl;
+ using TextureViewImplType = TextureViewD3D12Impl;
+ using ShaderImplType = ShaderD3D12Impl;
+ using SamplerImplType = SamplerD3D12Impl;
+ using FenceImplType = FenceD3D12Impl;
+ using QueryImplType = QueryD3D12Impl;
+ using RenderPassImplType = RenderPassD3D12Impl;
+ using FramebufferImplType = FramebufferD3D12Impl;
+ using BottomLevelASImplType = BottomLevelASD3D12Impl;
+ using TopLevelASImplType = TopLevelASD3D12Impl;
+ using ShaderBindingTableImplType = ShaderBindingTableD3D12Impl;
+ using PipelineResourceSignatureImplType = PipelineResourceSignatureD3D12Impl;
+};
+
/// Render device implementation in Direct3D12 backend.
-class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase<RenderDeviceD3DBase<IRenderDeviceD3D12>, ICommandQueueD3D12>
+class RenderDeviceD3D12Impl final : public RenderDeviceNextGenBase<RenderDeviceD3DBase<RenderDeviceD3D12ImplTraits>, ICommandQueueD3D12>
{
public:
- using TRenderDeviceBase = RenderDeviceNextGenBase<RenderDeviceD3DBase<IRenderDeviceD3D12>, ICommandQueueD3D12>;
+ using BaseInterface = IRenderDeviceD3D12;
+ using TRenderDeviceBase = RenderDeviceNextGenBase<RenderDeviceD3DBase<RenderDeviceD3D12ImplTraits>, ICommandQueueD3D12>;
RenderDeviceD3D12Impl(IReferenceCounters* pRefCounters,
IMemoryAllocator& RawMemAllocator,
@@ -254,9 +296,6 @@ public:
}
private:
- template <typename PSOCreateInfoType>
- void CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState);
-
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
void FreeCommandContext(PooledCommandContext&& Ctx);
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
index f90447f5..0de19a77 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
@@ -107,26 +107,7 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
pEngineFactory,
CommandQueueCount,
ppCmdQueues,
- EngineCI.NumDeferredContexts,
- DeviceObjectSizes
- {
- sizeof(TextureD3D12Impl),
- sizeof(TextureViewD3D12Impl),
- sizeof(BufferD3D12Impl),
- sizeof(BufferViewD3D12Impl),
- sizeof(ShaderD3D12Impl),
- sizeof(SamplerD3D12Impl),
- sizeof(PipelineStateD3D12Impl),
- sizeof(ShaderResourceBindingD3D12Impl),
- sizeof(FenceD3D12Impl),
- sizeof(QueryD3D12Impl),
- sizeof(RenderPassD3D12Impl),
- sizeof(FramebufferD3D12Impl),
- sizeof(BottomLevelASD3D12Impl),
- sizeof(TopLevelASD3D12Impl),
- sizeof(ShaderBindingTableD3D12Impl),
- sizeof(PipelineResourceSignatureD3D12Impl)
- }
+ EngineCI.NumDeferredContexts
},
m_pd3d12Device {pd3d12Device},
m_EngineAttribs {EngineCI },
@@ -152,8 +133,6 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
m_RootSignatureCache {*this}
// clang-format on
{
- static_assert(sizeof(DeviceObjectSizes) == sizeof(size_t) * 16, "Please add new objects to DeviceObjectSizes constructor");
-
// set device properties
{
static_assert(sizeof(DeviceProperties) == sizeof(Uint32) * 1, "Please set new properties below");
@@ -591,84 +570,42 @@ void RenderDeviceD3D12Impl::TestTextureFormat(TEXTURE_FORMAT TexFormat)
}
}
-template <typename PSOCreateInfoType>
-void RenderDeviceD3D12Impl::CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState)
-{
- CreateDeviceObject("Pipeline State", PSOCreateInfo.PSODesc, ppPipelineState,
- [&]() //
- {
- PipelineStateD3D12Impl* pPipelineStateD3D12{NEW_RC_OBJ(m_PSOAllocator, "PipelineStateD3D12Impl instance", PipelineStateD3D12Impl)(this, PSOCreateInfo)};
- pPipelineStateD3D12->QueryInterface(IID_PipelineState, reinterpret_cast<IObject**>(ppPipelineState));
- OnCreateDeviceObject(pPipelineStateD3D12);
- });
-}
-
-
void RenderDeviceD3D12Impl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
void RenderDeviceD3D12Impl::CreateComputePipelineState(const ComputePipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
void RenderDeviceD3D12Impl::CreateRayTracingPipelineState(const RayTracingPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
void RenderDeviceD3D12Impl::CreateBufferFromD3DResource(ID3D12Resource* pd3d12Buffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer)
{
- CreateDeviceObject("buffer", BuffDesc, ppBuffer,
- [&]() //
- {
- BufferD3D12Impl* pBufferD3D12{NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D12Impl instance", BufferD3D12Impl)(m_BuffViewObjAllocator, this, BuffDesc, InitialState, pd3d12Buffer)};
- pBufferD3D12->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer));
- pBufferD3D12->CreateDefaultViews();
- OnCreateDeviceObject(pBufferD3D12);
- });
+ CreateBufferImpl(ppBuffer, BuffDesc, InitialState, pd3d12Buffer);
}
void RenderDeviceD3D12Impl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)
{
- CreateDeviceObject("buffer", BuffDesc, ppBuffer,
- [&]() //
- {
- BufferD3D12Impl* pBufferD3D12{NEW_RC_OBJ(m_BufObjAllocator, "BufferD3D12Impl instance", BufferD3D12Impl)(m_BuffViewObjAllocator, this, BuffDesc, pBuffData)};
- pBufferD3D12->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer));
- pBufferD3D12->CreateDefaultViews();
- OnCreateDeviceObject(pBufferD3D12);
- });
+ CreateBufferImpl(ppBuffer, BuffDesc, pBuffData);
}
void RenderDeviceD3D12Impl::CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)
{
- CreateDeviceObject("shader", ShaderCI.Desc, ppShader,
- [&]() //
- {
- ShaderD3D12Impl* pShaderD3D12{NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderD3D12Impl instance", ShaderD3D12Impl)(this, ShaderCI)};
- pShaderD3D12->QueryInterface(IID_Shader, reinterpret_cast<IObject**>(ppShader));
-
- OnCreateDeviceObject(pShaderD3D12);
- });
+ CreateShaderImpl(ppShader, ShaderCI);
}
void RenderDeviceD3D12Impl::CreateTextureFromD3DResource(ID3D12Resource* pd3d12Texture, RESOURCE_STATE InitialState, ITexture** ppTexture)
{
TextureDesc TexDesc;
TexDesc.Name = "Texture from d3d12 resource";
- CreateDeviceObject("texture", TexDesc, ppTexture,
- [&]() //
- {
- TextureD3D12Impl* pTextureD3D12{NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, InitialState, pd3d12Texture)};
-
- pTextureD3D12->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture));
- pTextureD3D12->CreateDefaultViews();
- OnCreateDeviceObject(pTextureD3D12);
- });
+ CreateTextureImpl(ppTexture, TexDesc, InitialState, pd3d12Texture);
}
void RenderDeviceD3D12Impl::CreateTexture(const TextureDesc& TexDesc, ID3D12Resource* pd3d12Texture, RESOURCE_STATE InitialState, TextureD3D12Impl** ppTexture)
@@ -683,75 +620,32 @@ void RenderDeviceD3D12Impl::CreateTexture(const TextureDesc& TexDesc, ID3D12Reso
void RenderDeviceD3D12Impl::CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)
{
- CreateDeviceObject("texture", TexDesc, ppTexture,
- [&]() //
- {
- TextureD3D12Impl* pTextureD3D12{NEW_RC_OBJ(m_TexObjAllocator, "TextureD3D12Impl instance", TextureD3D12Impl)(m_TexViewObjAllocator, this, TexDesc, pData)};
-
- pTextureD3D12->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture));
- pTextureD3D12->CreateDefaultViews();
- OnCreateDeviceObject(pTextureD3D12);
- });
+ CreateTextureImpl(ppTexture, TexDesc, pData);
}
void RenderDeviceD3D12Impl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)
{
- CreateDeviceObject("sampler", SamplerDesc, ppSampler,
- [&]() //
- {
- m_SamplersRegistry.Find(SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler));
- if (*ppSampler == nullptr)
- {
- SamplerD3D12Impl* pSamplerD3D12{NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerD3D12Impl instance", SamplerD3D12Impl)(this, SamplerDesc)};
- pSamplerD3D12->QueryInterface(IID_Sampler, reinterpret_cast<IObject**>(ppSampler));
- OnCreateDeviceObject(pSamplerD3D12);
- m_SamplersRegistry.Add(SamplerDesc, *ppSampler);
- }
- });
+ CreateSamplerImpl(ppSampler, SamplerDesc);
}
void RenderDeviceD3D12Impl::CreateFence(const FenceDesc& Desc, IFence** ppFence)
{
- CreateDeviceObject("Fence", Desc, ppFence,
- [&]() //
- {
- FenceD3D12Impl* pFenceD3D12{NEW_RC_OBJ(m_FenceAllocator, "FenceD3D12Impl instance", FenceD3D12Impl)(this, Desc)};
- pFenceD3D12->QueryInterface(IID_Fence, reinterpret_cast<IObject**>(ppFence));
- OnCreateDeviceObject(pFenceD3D12);
- });
+ CreateFenceImpl(ppFence, Desc);
}
void RenderDeviceD3D12Impl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery)
{
- CreateDeviceObject("Query", Desc, ppQuery,
- [&]() //
- {
- QueryD3D12Impl* pQueryD3D12{NEW_RC_OBJ(m_QueryAllocator, "QueryD3D12Impl instance", QueryD3D12Impl)(this, Desc)};
- pQueryD3D12->QueryInterface(IID_Query, reinterpret_cast<IObject**>(ppQuery));
- OnCreateDeviceObject(pQueryD3D12);
- });
+ CreateQueryImpl(ppQuery, Desc);
}
void RenderDeviceD3D12Impl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass)
{
- CreateDeviceObject("RenderPass", Desc, ppRenderPass,
- [&]() //
- {
- RenderPassD3D12Impl* pRenderPassD3D12{NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassD3D12Impl instance", RenderPassD3D12Impl)(this, Desc)};
- pRenderPassD3D12->QueryInterface(IID_RenderPass, reinterpret_cast<IObject**>(ppRenderPass));
- OnCreateDeviceObject(pRenderPassD3D12);
- });
+ CreateRenderPassImpl(ppRenderPass, Desc);
}
void RenderDeviceD3D12Impl::CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer)
{
- CreateDeviceObject("Framebuffer", Desc, ppFramebuffer,
- [&]() //
- {
- FramebufferD3D12Impl* pFramebufferD3D12{NEW_RC_OBJ(m_FramebufferAllocator, "FramebufferD3D12Impl instance", FramebufferD3D12Impl)(this, Desc)};
- pFramebufferD3D12->QueryInterface(IID_Framebuffer, reinterpret_cast<IObject**>(ppFramebuffer));
- OnCreateDeviceObject(pFramebufferD3D12);
- });
+ CreateFramebufferImpl(ppFramebuffer, Desc);
}
void RenderDeviceD3D12Impl::CreateBLASFromD3DResource(ID3D12Resource* pd3d12BLAS,
@@ -759,25 +653,13 @@ void RenderDeviceD3D12Impl::CreateBLASFromD3DResource(ID3D12Resource* p
RESOURCE_STATE InitialState,
IBottomLevelAS** ppBLAS)
{
- CreateDeviceObject("buffer", Desc, ppBLAS,
- [&]() //
- {
- BottomLevelASD3D12Impl* pBottomLevelASD3D12{NEW_RC_OBJ(m_BLASAllocator, "BottomLevelASD3D12Impl instance", BottomLevelASD3D12Impl)(this, Desc, InitialState, pd3d12BLAS)};
- pBottomLevelASD3D12->QueryInterface(IID_BottomLevelAS, reinterpret_cast<IObject**>(ppBLAS));
- OnCreateDeviceObject(pBottomLevelASD3D12);
- });
+ CreateBLASImpl(ppBLAS, Desc, InitialState, pd3d12BLAS);
}
void RenderDeviceD3D12Impl::CreateBLAS(const BottomLevelASDesc& Desc,
IBottomLevelAS** ppBLAS)
{
- CreateDeviceObject("BottomLevelAS", Desc, ppBLAS,
- [&]() //
- {
- BottomLevelASD3D12Impl* pBottomLevelASD3D12(NEW_RC_OBJ(m_BLASAllocator, "BottomLevelASD3D12Impl instance", BottomLevelASD3D12Impl)(this, Desc));
- pBottomLevelASD3D12->QueryInterface(IID_BottomLevelAS, reinterpret_cast<IObject**>(ppBLAS));
- OnCreateDeviceObject(pBottomLevelASD3D12);
- });
+ CreateBLASImpl(ppBLAS, Desc);
}
void RenderDeviceD3D12Impl::CreateTLASFromD3DResource(ID3D12Resource* pd3d12TLAS,
@@ -785,37 +667,19 @@ void RenderDeviceD3D12Impl::CreateTLASFromD3DResource(ID3D12Resource* pd3d
RESOURCE_STATE InitialState,
ITopLevelAS** ppTLAS)
{
- CreateDeviceObject("TopLevelAS", Desc, ppTLAS,
- [&]() //
- {
- TopLevelASD3D12Impl* pTopLevelASD3D12{NEW_RC_OBJ(m_TLASAllocator, "TopLevelASD3D12Impl instance", TopLevelASD3D12Impl)(this, Desc, InitialState, pd3d12TLAS)};
- pTopLevelASD3D12->QueryInterface(IID_TopLevelAS, reinterpret_cast<IObject**>(ppTLAS));
- OnCreateDeviceObject(pTopLevelASD3D12);
- });
+ CreateTLASImpl(ppTLAS, Desc, InitialState, pd3d12TLAS);
}
void RenderDeviceD3D12Impl::CreateTLAS(const TopLevelASDesc& Desc,
ITopLevelAS** ppTLAS)
{
- CreateDeviceObject("TopLevelAS", Desc, ppTLAS,
- [&]() //
- {
- TopLevelASD3D12Impl* pTopLevelASD3D12(NEW_RC_OBJ(m_TLASAllocator, "TopLevelASD3D12Impl instance", TopLevelASD3D12Impl)(this, Desc));
- pTopLevelASD3D12->QueryInterface(IID_TopLevelAS, reinterpret_cast<IObject**>(ppTLAS));
- OnCreateDeviceObject(pTopLevelASD3D12);
- });
+ CreateTLASImpl(ppTLAS, Desc);
}
void RenderDeviceD3D12Impl::CreateSBT(const ShaderBindingTableDesc& Desc,
IShaderBindingTable** ppSBT)
{
- CreateDeviceObject("ShaderBindingTable", Desc, ppSBT,
- [&]() //
- {
- ShaderBindingTableD3D12Impl* pSBTD3D12(NEW_RC_OBJ(m_SBTAllocator, "ShaderBindingTableD3D12Impl instance", ShaderBindingTableD3D12Impl)(this, Desc));
- pSBTD3D12->QueryInterface(IID_ShaderBindingTable, reinterpret_cast<IObject**>(ppSBT));
- OnCreateDeviceObject(pSBTD3D12);
- });
+ CreateSBTImpl(ppSBT, Desc);
}
void RenderDeviceD3D12Impl::CreatePipelineResourceSignature(const PipelineResourceSignatureDesc& Desc,
@@ -828,13 +692,7 @@ void RenderDeviceD3D12Impl::CreatePipelineResourceSignature(const PipelineResour
IPipelineResourceSignature** ppSignature,
bool IsDeviceInternal)
{
- CreateDeviceObject("PipelineResourceSignature", Desc, ppSignature,
- [&]() //
- {
- PipelineResourceSignatureD3D12Impl* pPRSD3D12(NEW_RC_OBJ(m_PipeResSignAllocator, "PipelineResourceSignatureD3D12Impl instance", PipelineResourceSignatureD3D12Impl)(this, Desc, IsDeviceInternal));
- pPRSD3D12->QueryInterface(IID_PipelineResourceSignature, reinterpret_cast<IObject**>(ppSignature));
- OnCreateDeviceObject(pPRSD3D12);
- });
+ CreatePipelineResourceSignatureImpl(ppSignature, Desc, IsDeviceInternal);
}
DescriptorHeapAllocation RenderDeviceD3D12Impl::AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count /*= 1*/)
diff --git a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
index 504e4761..1f245a6d 100644
--- a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
@@ -39,16 +39,15 @@ namespace Diligent
/// Base implementation of a D3D render device
-template <typename BaseInterface>
-class RenderDeviceD3DBase : public RenderDeviceBase<BaseInterface>
+template <typename RenderDeviceImplTraits>
+class RenderDeviceD3DBase : public RenderDeviceBase<RenderDeviceImplTraits>
{
public:
- RenderDeviceD3DBase(IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
- IEngineFactory* pEngineFactory,
- Uint32 NumDeferredContexts,
- const DeviceObjectSizes& ObjectSizes) :
- RenderDeviceBase<BaseInterface>{pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts, ObjectSizes}
+ RenderDeviceD3DBase(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ IEngineFactory* pEngineFactory,
+ Uint32 NumDeferredContexts) :
+ RenderDeviceBase<RenderDeviceImplTraits>{pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts}
{
// Flag texture formats always supported in D3D11 and D3D12
diff --git a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.hpp b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.hpp
index 55e71a21..c143aa74 100644
--- a/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.hpp
+++ b/Graphics/GraphicsEngineNextGenBase/include/RenderDeviceNextGenBase.hpp
@@ -49,16 +49,13 @@ template <class TBase, typename CommandQueueType>
class RenderDeviceNextGenBase : public TBase
{
public:
- using typename TBase::DeviceObjectSizes;
-
- RenderDeviceNextGenBase(IReferenceCounters* pRefCounters,
- IMemoryAllocator& RawMemAllocator,
- IEngineFactory* pEngineFactory,
- size_t CmdQueueCount,
- CommandQueueType** Queues,
- Uint32 NumDeferredContexts,
- const DeviceObjectSizes& ObjectSizes) :
- TBase{pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts, ObjectSizes},
+ RenderDeviceNextGenBase(IReferenceCounters* pRefCounters,
+ IMemoryAllocator& RawMemAllocator,
+ IEngineFactory* pEngineFactory,
+ size_t CmdQueueCount,
+ CommandQueueType** Queues,
+ Uint32 NumDeferredContexts) :
+ TBase{pRefCounters, RawMemAllocator, pEngineFactory, NumDeferredContexts},
m_CmdQueueCount{CmdQueueCount}
{
m_CommandQueues = ALLOCATE(this->m_RawMemAllocator, "Raw memory for the device command/release queues", CommandQueue, m_CmdQueueCount);
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,
diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp
index 3c5abb22..7e003fca 100644
--- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.hpp
@@ -54,11 +54,52 @@
namespace Diligent
{
+class RenderDeviceVkImpl;
+class PipelineStateVkImpl;
+class ShaderResourceBindingVkImpl;
+class BufferVkImpl;
+class BufferViewVkImpl;
+class TextureVkImpl;
+class TextureViewVkImpl;
+class ShaderVkImpl;
+class SamplerVkImpl;
+class FenceVkImpl;
+class QueryVkImpl;
+class RenderPassVkImpl;
+class FramebufferVkImpl;
+class BottomLevelASVkImpl;
+class TopLevelASVkImpl;
+class ShaderBindingTableVkImpl;
+class PipelineResourceSignatureVkImpl;
+
+struct RenderDeviceVkImplTraits
+{
+ using BaseInterface = IRenderDeviceVk;
+
+ using RenderDeviceImplType = RenderDeviceVkImpl;
+ using PipelineStateImplType = PipelineStateVkImpl;
+ using ShaderResourceBindingImplType = ShaderResourceBindingVkImpl;
+ using BufferImplType = BufferVkImpl;
+ using BufferViewImplType = BufferViewVkImpl;
+ using TextureImplType = TextureVkImpl;
+ using TextureViewImplType = TextureViewVkImpl;
+ using ShaderImplType = ShaderVkImpl;
+ using SamplerImplType = SamplerVkImpl;
+ using FenceImplType = FenceVkImpl;
+ using QueryImplType = QueryVkImpl;
+ using RenderPassImplType = RenderPassVkImpl;
+ using FramebufferImplType = FramebufferVkImpl;
+ using BottomLevelASImplType = BottomLevelASVkImpl;
+ using TopLevelASImplType = TopLevelASVkImpl;
+ using ShaderBindingTableImplType = ShaderBindingTableVkImpl;
+ using PipelineResourceSignatureImplType = PipelineResourceSignatureVkImpl;
+};
+
/// Render device implementation in Vulkan backend.
-class RenderDeviceVkImpl final : public RenderDeviceNextGenBase<RenderDeviceBase<IRenderDeviceVk>, ICommandQueueVk>
+class RenderDeviceVkImpl final : public RenderDeviceNextGenBase<RenderDeviceBase<RenderDeviceVkImplTraits>, ICommandQueueVk>
{
public:
- using TRenderDeviceBase = RenderDeviceNextGenBase<RenderDeviceBase<IRenderDeviceVk>, ICommandQueueVk>;
+ using TRenderDeviceBase = RenderDeviceNextGenBase<RenderDeviceBase<RenderDeviceVkImplTraits>, ICommandQueueVk>;
RenderDeviceVkImpl(IReferenceCounters* pRefCounters,
IMemoryAllocator& RawMemAllocator,
@@ -234,9 +275,6 @@ public:
}
private:
- template <typename PSOCreateInfoType>
- void CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState);
-
virtual void TestTextureFormat(TEXTURE_FORMAT TexFormat) override final;
// Submits command buffer(s) for execution to the command queue and
diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
index c61e28ed..cf66b3ce 100644
--- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
@@ -65,26 +65,7 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters*
pEngineFactory,
CommandQueueCount,
CmdQueues,
- EngineCI.NumDeferredContexts,
- DeviceObjectSizes
- {
- sizeof(TextureVkImpl),
- sizeof(TextureViewVkImpl),
- sizeof(BufferVkImpl),
- sizeof(BufferViewVkImpl),
- sizeof(ShaderVkImpl),
- sizeof(SamplerVkImpl),
- sizeof(PipelineStateVkImpl),
- sizeof(ShaderResourceBindingVkImpl),
- sizeof(FenceVkImpl),
- sizeof(QueryVkImpl),
- sizeof(RenderPassVkImpl),
- sizeof(FramebufferVkImpl),
- sizeof(BottomLevelASVkImpl),
- sizeof(TopLevelASVkImpl),
- sizeof(ShaderBindingTableVkImpl),
- sizeof(PipelineResourceSignatureVkImpl),
- }
+ EngineCI.NumDeferredContexts
},
m_VulkanInstance {Instance },
m_PhysicalDevice {std::move(PhysicalDevice)},
@@ -174,7 +155,6 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters*
// clang-format on
{
static_assert(sizeof(VulkanDescriptorPoolSize) == sizeof(Uint32) * 11, "Please add new descriptors to m_DescriptorSetAllocator and m_DynamicDescriptorPool constructors");
- static_assert(sizeof(DeviceObjectSizes) == sizeof(size_t) * 16, "Please add new objects to DeviceObjectSizes constructor");
// set device properties
{
@@ -567,94 +547,41 @@ void RenderDeviceVkImpl::TestTextureFormat(TEXTURE_FORMAT TexFormat)
}
}
-template <typename PSOCreateInfoType>
-void RenderDeviceVkImpl::CreatePipelineState(const PSOCreateInfoType& PSOCreateInfo, IPipelineState** ppPipelineState)
-{
- CreateDeviceObject(
- "Pipeline State", PSOCreateInfo.PSODesc, ppPipelineState,
- [&]() //
- {
- PipelineStateVkImpl* pPipelineStateVk(NEW_RC_OBJ(m_PSOAllocator, "PipelineStateVkImpl instance", PipelineStateVkImpl)(this, PSOCreateInfo));
- pPipelineStateVk->QueryInterface(IID_PipelineState, reinterpret_cast<IObject**>(ppPipelineState));
- OnCreateDeviceObject(pPipelineStateVk);
- } //
- );
-}
-
void RenderDeviceVkImpl::CreateGraphicsPipelineState(const GraphicsPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
-
void RenderDeviceVkImpl::CreateComputePipelineState(const ComputePipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
void RenderDeviceVkImpl::CreateRayTracingPipelineState(const RayTracingPipelineStateCreateInfo& PSOCreateInfo, IPipelineState** ppPipelineState)
{
- CreatePipelineState(PSOCreateInfo, ppPipelineState);
+ CreatePipelineStateImpl(ppPipelineState, PSOCreateInfo);
}
void RenderDeviceVkImpl::CreateBufferFromVulkanResource(VkBuffer vkBuffer, const BufferDesc& BuffDesc, RESOURCE_STATE InitialState, IBuffer** ppBuffer)
{
- CreateDeviceObject(
- "buffer", BuffDesc, ppBuffer,
- [&]() //
- {
- BufferVkImpl* pBufferVk(NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, InitialState, vkBuffer));
- pBufferVk->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer));
- pBufferVk->CreateDefaultViews();
- OnCreateDeviceObject(pBufferVk);
- } //
- );
+ CreateBufferImpl(ppBuffer, BuffDesc, InitialState, vkBuffer);
}
-
void RenderDeviceVkImpl::CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)
{
- CreateDeviceObject(
- "buffer", BuffDesc, ppBuffer,
- [&]() //
- {
- BufferVkImpl* pBufferVk(NEW_RC_OBJ(m_BufObjAllocator, "BufferVkImpl instance", BufferVkImpl)(m_BuffViewObjAllocator, this, BuffDesc, pBuffData));
- pBufferVk->QueryInterface(IID_Buffer, reinterpret_cast<IObject**>(ppBuffer));
- pBufferVk->CreateDefaultViews();
- OnCreateDeviceObject(pBufferVk);
- } //
- );
+ CreateBufferImpl(ppBuffer, BuffDesc, pBuffData);
}
void RenderDeviceVkImpl::CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)
{
- CreateDeviceObject(
- "shader", ShaderCI.Desc, ppShader,
- [&]() //
- {
- ShaderVkImpl* pShaderVk(NEW_RC_OBJ(m_ShaderObjAllocator, "ShaderVkImpl instance", ShaderVkImpl)(this, ShaderCI));
- pShaderVk->QueryInterface(IID_Shader, reinterpret_cast<IObject**>(ppShader));
-
- OnCreateDeviceObject(pShaderVk);
- } //
- );
+ CreateShaderImpl(ppShader, ShaderCI);
}
void RenderDeviceVkImpl::CreateTextureFromVulkanImage(VkImage vkImage, const TextureDesc& TexDesc, RESOURCE_STATE InitialState, ITexture** ppTexture)
{
- CreateDeviceObject(
- "texture", TexDesc, ppTexture,
- [&]() //
- {
- TextureVkImpl* pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, InitialState, vkImage);
-
- pTextureVk->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture));
- pTextureVk->CreateDefaultViews();
- OnCreateDeviceObject(pTextureVk);
- } //
- );
+ CreateTextureImpl(ppTexture, TexDesc, InitialState, vkImage);
}
@@ -673,76 +600,29 @@ void RenderDeviceVkImpl::CreateTexture(const TextureDesc& TexDesc, VkImage vkImg
void RenderDeviceVkImpl::CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)
{
- CreateDeviceObject(
- "texture", TexDesc, ppTexture,
- [&]() //
- {
- TextureVkImpl* pTextureVk = NEW_RC_OBJ(m_TexObjAllocator, "TextureVkImpl instance", TextureVkImpl)(m_TexViewObjAllocator, this, TexDesc, pData);
-
- pTextureVk->QueryInterface(IID_Texture, reinterpret_cast<IObject**>(ppTexture));
- pTextureVk->CreateDefaultViews();
- OnCreateDeviceObject(pTextureVk);
- } //
- );
+ CreateTextureImpl(ppTexture, TexDesc, pData);
}
void RenderDeviceVkImpl::CreateSampler(const SamplerDesc& SamplerDesc, ISampler** ppSampler)
{
- CreateDeviceObject(
- "sampler", SamplerDesc, ppSampler,
- [&]() //
- {
- m_SamplersRegistry.Find(SamplerDesc, reinterpret_cast<IDeviceObject**>(ppSampler));
- if (*ppSampler == nullptr)
- {
- SamplerVkImpl* pSamplerVk(NEW_RC_OBJ(m_SamplerObjAllocator, "SamplerVkImpl instance", SamplerVkImpl)(this, SamplerDesc));
- pSamplerVk->QueryInterface(IID_Sampler, reinterpret_cast<IObject**>(ppSampler));
- OnCreateDeviceObject(pSamplerVk);
- m_SamplersRegistry.Add(SamplerDesc, *ppSampler);
- }
- } //
- );
+ CreateSamplerImpl(ppSampler, SamplerDesc);
}
void RenderDeviceVkImpl::CreateFence(const FenceDesc& Desc, IFence** ppFence)
{
- CreateDeviceObject(
- "Fence", Desc, ppFence,
- [&]() //
- {
- FenceVkImpl* pFenceVk(NEW_RC_OBJ(m_FenceAllocator, "FenceVkImpl instance", FenceVkImpl)(this, Desc));
- pFenceVk->QueryInterface(IID_Fence, reinterpret_cast<IObject**>(ppFence));
- OnCreateDeviceObject(pFenceVk);
- } //
- );
+ CreateFenceImpl(ppFence, Desc);
}
void RenderDeviceVkImpl::CreateQuery(const QueryDesc& Desc, IQuery** ppQuery)
{
- CreateDeviceObject(
- "Query", Desc, ppQuery,
- [&]() //
- {
- QueryVkImpl* pQueryVk(NEW_RC_OBJ(m_QueryAllocator, "QueryVkImpl instance", QueryVkImpl)(this, Desc));
- pQueryVk->QueryInterface(IID_Query, reinterpret_cast<IObject**>(ppQuery));
- OnCreateDeviceObject(pQueryVk);
- } //
- );
+ CreateQueryImpl(ppQuery, Desc);
}
void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc,
IRenderPass** ppRenderPass,
bool IsDeviceInternal)
{
- CreateDeviceObject(
- "RenderPass", Desc, ppRenderPass,
- [&]() //
- {
- RenderPassVkImpl* pRenderPassVk(NEW_RC_OBJ(m_RenderPassAllocator, "RenderPassVkImpl instance", RenderPassVkImpl)(this, Desc, IsDeviceInternal));
- pRenderPassVk->QueryInterface(IID_RenderPass, reinterpret_cast<IObject**>(ppRenderPass));
- OnCreateDeviceObject(pRenderPassVk);
- } //
- );
+ CreateRenderPassImpl(ppRenderPass, Desc, IsDeviceInternal);
}
void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPass** ppRenderPass)
@@ -752,14 +632,7 @@ void RenderDeviceVkImpl::CreateRenderPass(const RenderPassDesc& Desc, IRenderPas
void RenderDeviceVkImpl::CreateFramebuffer(const FramebufferDesc& Desc, IFramebuffer** ppFramebuffer)
{
- CreateDeviceObject(
- "Framebuffer", Desc, ppFramebuffer,
- [&]() //
- {
- FramebufferVkImpl* pFramebufferVk(NEW_RC_OBJ(m_FramebufferAllocator, "FramebufferVkImpl instance", FramebufferVkImpl)(this, Desc));
- pFramebufferVk->QueryInterface(IID_Framebuffer, reinterpret_cast<IObject**>(ppFramebuffer));
- OnCreateDeviceObject(pFramebufferVk);
- });
+ CreateFramebufferImpl(ppFramebuffer, Desc);
}
void RenderDeviceVkImpl::CreateBLASFromVulkanResource(VkAccelerationStructureKHR vkBLAS,
@@ -767,28 +640,13 @@ void RenderDeviceVkImpl::CreateBLASFromVulkanResource(VkAccelerationStructureKHR
RESOURCE_STATE InitialState,
IBottomLevelAS** ppBLAS)
{
- CreateDeviceObject(
- "BottomLevelAS", Desc, ppBLAS,
- [&]() //
- {
- BottomLevelASVkImpl* pBottomLevelASVk(NEW_RC_OBJ(m_BLASAllocator, "BottomLevelASVkImpl instance", BottomLevelASVkImpl)(this, Desc, InitialState, vkBLAS));
- pBottomLevelASVk->QueryInterface(IID_BottomLevelAS, reinterpret_cast<IObject**>(ppBLAS));
- OnCreateDeviceObject(pBottomLevelASVk);
- } //
- );
+ CreateBLASImpl(ppBLAS, Desc, InitialState, vkBLAS);
}
void RenderDeviceVkImpl::CreateBLAS(const BottomLevelASDesc& Desc,
IBottomLevelAS** ppBLAS)
{
- CreateDeviceObject(
- "BottomLevelAS", Desc, ppBLAS,
- [&]() //
- {
- BottomLevelASVkImpl* pBottomLevelASVk(NEW_RC_OBJ(m_BLASAllocator, "BottomLevelASVkImpl instance", BottomLevelASVkImpl)(this, Desc));
- pBottomLevelASVk->QueryInterface(IID_BottomLevelAS, reinterpret_cast<IObject**>(ppBLAS));
- OnCreateDeviceObject(pBottomLevelASVk);
- });
+ CreateBLASImpl(ppBLAS, Desc);
}
void RenderDeviceVkImpl::CreateTLASFromVulkanResource(VkAccelerationStructureKHR vkTLAS,
@@ -796,41 +654,19 @@ void RenderDeviceVkImpl::CreateTLASFromVulkanResource(VkAccelerationStructureKHR
RESOURCE_STATE InitialState,
ITopLevelAS** ppTLAS)
{
- CreateDeviceObject(
- "TopLevelAS", Desc, ppTLAS,
- [&]() //
- {
- TopLevelASVkImpl* pTopLevelASVk(NEW_RC_OBJ(m_BLASAllocator, "TopLevelASVkImpl instance", TopLevelASVkImpl)(this, Desc, InitialState, vkTLAS));
- pTopLevelASVk->QueryInterface(IID_TopLevelAS, reinterpret_cast<IObject**>(ppTLAS));
- OnCreateDeviceObject(pTopLevelASVk);
- } //
- );
+ CreateTLASImpl(ppTLAS, Desc, InitialState, vkTLAS);
}
void RenderDeviceVkImpl::CreateTLAS(const TopLevelASDesc& Desc,
ITopLevelAS** ppTLAS)
{
- CreateDeviceObject(
- "TopLevelAS", Desc, ppTLAS,
- [&]() //
- {
- TopLevelASVkImpl* pTopLevelASVk(NEW_RC_OBJ(m_TLASAllocator, "TopLevelASVkImpl instance", TopLevelASVkImpl)(this, Desc));
- pTopLevelASVk->QueryInterface(IID_TopLevelAS, reinterpret_cast<IObject**>(ppTLAS));
- OnCreateDeviceObject(pTopLevelASVk);
- });
+ CreateTLASImpl(ppTLAS, Desc);
}
void RenderDeviceVkImpl::CreateSBT(const ShaderBindingTableDesc& Desc,
IShaderBindingTable** ppSBT)
{
- CreateDeviceObject(
- "ShaderBindingTable", Desc, ppSBT,
- [&]() //
- {
- ShaderBindingTableVkImpl* pSBTVk(NEW_RC_OBJ(m_SBTAllocator, "ShaderBindingTableVkImpl instance", ShaderBindingTableVkImpl)(this, Desc));
- pSBTVk->QueryInterface(IID_ShaderBindingTable, reinterpret_cast<IObject**>(ppSBT));
- OnCreateDeviceObject(pSBTVk);
- });
+ CreateSBTImpl(ppSBT, Desc);
}
void RenderDeviceVkImpl::CreatePipelineResourceSignature(const PipelineResourceSignatureDesc& Desc,
@@ -843,14 +679,7 @@ void RenderDeviceVkImpl::CreatePipelineResourceSignature(const PipelineResourceS
IPipelineResourceSignature** ppSignature,
bool IsDeviceInternal)
{
- CreateDeviceObject(
- "PipelineResourceSignature", Desc, ppSignature,
- [&]() //
- {
- PipelineResourceSignatureVkImpl* pPRSVk(NEW_RC_OBJ(m_PipeResSignAllocator, "PipelineResourceSignatureVkImpl instance", PipelineResourceSignatureVkImpl)(this, Desc, IsDeviceInternal));
- pPRSVk->QueryInterface(IID_PipelineResourceSignature, reinterpret_cast<IObject**>(ppSignature));
- OnCreateDeviceObject(pPRSVk);
- });
+ CreatePipelineResourceSignatureImpl(ppSignature, Desc, IsDeviceInternal);
}
} // namespace Diligent