diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-04-06 15:49:17 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-04-06 15:49:17 +0000 |
| commit | 696a3cbb5a5f30d2f5000c0db90125d614ea09ca (patch) | |
| tree | f1c03f120f1cccfa94a583801179212d32d20711 /Graphics/GraphicsEngine | |
| parent | Added API info query (diff) | |
| download | DiligentCore-696a3cbb5a5f30d2f5000c0db90125d614ea09ca.tar.gz DiligentCore-696a3cbb5a5f30d2f5000c0db90125d614ea09ca.zip | |
Made IShaderSourceInputStreamFactory derived from IObject (upgraded API Version to 240021)
Diffstat (limited to 'Graphics/GraphicsEngine')
9 files changed, 243 insertions, 36 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt index 4eb8d9aa..b7fbc23d 100644 --- a/Graphics/GraphicsEngine/CMakeLists.txt +++ b/Graphics/GraphicsEngine/CMakeLists.txt @@ -6,6 +6,7 @@ set(INCLUDE include/BufferBase.h include/BufferViewBase.h include/CommandListBase.h + include/DefaultShaderSourceStreamFactory.h include/Defines.h include/DeviceContextBase.h include/DeviceObjectBase.h @@ -57,6 +58,7 @@ set(INTERFACE set(SOURCE src/APIInfo.cpp + src/DefaultShaderSourceStreamFactory.cpp src/EngineMemory.cpp src/ResourceMapping.cpp src/Texture.cpp diff --git a/Graphics/GraphicsEngine/include/DefaultShaderSourceStreamFactory.h b/Graphics/GraphicsEngine/include/DefaultShaderSourceStreamFactory.h new file mode 100644 index 00000000..9cd9b8ad --- /dev/null +++ b/Graphics/GraphicsEngine/include/DefaultShaderSourceStreamFactory.h @@ -0,0 +1,38 @@ +/* Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "../../../Common/interface/BasicFileStream.h" +#include "../../GraphicsEngine/interface/Shader.h" + +namespace Diligent +{ + +/// Creates default shader source stream factory +/// \param [in] SearchDirectories - Semicolon-seprated list of search directories. +/// \param [out] ppShaderSourceStreamFactory - Memory address where pointer to the shader source stream factory will be written. +void CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories, + IShaderSourceInputStreamFactory** ppShaderSourceStreamFactory); + +} diff --git a/Graphics/GraphicsEngine/include/EngineFactoryBase.h b/Graphics/GraphicsEngine/include/EngineFactoryBase.h index c382afff..eb3e6aeb 100644 --- a/Graphics/GraphicsEngine/include/EngineFactoryBase.h +++ b/Graphics/GraphicsEngine/include/EngineFactoryBase.h @@ -28,6 +28,7 @@ #include "Object.h" #include "EngineFactory.h" +#include "DefaultShaderSourceStreamFactory.h" namespace Diligent { @@ -84,6 +85,12 @@ public: return Diligent::GetAPIInfo(); } + virtual void CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories, + IShaderSourceInputStreamFactory** ppShaderSourceFactory)const override final + { + Diligent::CreateDefaultShaderSourceStreamFactory(SearchDirectories, ppShaderSourceFactory); + } + private: class DummyReferenceCounters final : public IReferenceCounters { diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.h b/Graphics/GraphicsEngine/include/RenderDeviceBase.h index 3ef856e7..ee713c2e 100644 --- a/Graphics/GraphicsEngine/include/RenderDeviceBase.h +++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.h @@ -184,48 +184,67 @@ public: using TObjectBase = ObjectBase<BaseInterface>; - /// \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) + /// 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; + }; + + /// \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 - number of deferred device contexts - /// \param TextureObjSize - size of the texture object, in bytes - /// \param TexViewObjSize - size of the texture view object, in bytes - /// \param BufferObjSize - size of the buffer object, in bytes - /// \param BuffViewObjSize - size of the buffer view object, in bytes - /// \param ShaderObjSize - size of the shader object, in bytes - /// \param SamplerObjSize - size of the sampler object, in bytes - /// \param PSOSize - size of the pipeline state object, in bytes - /// \param SRBSize - size of the shader resource binding object, in bytes - /// \param FenceSize - size of the fence object, in bytes + /// \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, - Uint32 NumDeferredContexts, - size_t TextureObjSize, - size_t TexViewObjSize, - size_t BufferObjSize, - size_t BuffViewObjSize, - size_t ShaderObjSize, - size_t SamplerObjSize, - size_t PSOSize, - size_t SRBSize, - size_t FenceSize) : + RenderDeviceBase(IReferenceCounters* pRefCounters, + IMemoryAllocator& RawMemAllocator, + IEngineFactory* pEngineFactory, + Uint32 NumDeferredContexts, + const DeviceObjectSizes& ObjectSizes) : TObjectBase (pRefCounters), + m_pEngineFactory (pEngineFactory), m_SamplersRegistry (RawMemAllocator, "sampler"), m_TextureFormatsInfo (TEX_FORMAT_NUM_FORMATS, TextureFormatInfoExt(), STD_ALLOCATOR_RAW_MEM(TextureFormatInfoExt, RawMemAllocator, "Allocator for vector<TextureFormatInfoExt>") ), 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, TextureObjSize, 64), - m_TexViewObjAllocator (RawMemAllocator, TexViewObjSize, 64), - m_BufObjAllocator (RawMemAllocator, BufferObjSize, 128), - m_BuffViewObjAllocator (RawMemAllocator, BuffViewObjSize, 128), - m_ShaderObjAllocator (RawMemAllocator, ShaderObjSize, 32), - m_SamplerObjAllocator (RawMemAllocator, SamplerObjSize, 32), - m_PSOAllocator (RawMemAllocator, PSOSize, 128), - m_SRBAllocator (RawMemAllocator, SRBSize, 1024), - m_ResMappingAllocator (RawMemAllocator, sizeof(ResourceMappingImpl), 16), - m_FenceAllocator (RawMemAllocator, FenceSize, 16) + 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) { // Initialize texture format info for( Uint32 Fmt = TEX_FORMAT_UNKNOWN; Fmt < TEX_FORMAT_NUM_FORMATS; ++Fmt ) @@ -323,7 +342,12 @@ public: return TexFmtInfo; } - void OnCreateDeviceObject( IDeviceObject* pNewObject ) + virtual IEngineFactory* GetEngineFactory() const override final + { + return m_pEngineFactory.RawPtr<IEngineFactory>(); + } + + void OnCreateDeviceObject(IDeviceObject* pNewObject) { } @@ -364,6 +388,8 @@ protected: template<typename TObjectType, typename TObjectDescType, typename TObjectConstructor> void CreateDeviceObject( const Char *ObjectTypeName, const TObjectDescType &Desc, TObjectType **ppObject, TObjectConstructor ConstructObject ); + RefCntAutoPtr<IEngineFactory> m_pEngineFactory; + DeviceCaps m_DeviceCaps; // All state object registries hold raw pointers. diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index 32230be1..e4db0bf3 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -26,7 +26,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240020 +#define DILIGENT_API_VERSION 240021 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/EngineFactory.h b/Graphics/GraphicsEngine/interface/EngineFactory.h index aebb654a..5508d841 100644 --- a/Graphics/GraphicsEngine/interface/EngineFactory.h +++ b/Graphics/GraphicsEngine/interface/EngineFactory.h @@ -32,6 +32,8 @@ namespace Diligent { +class IShaderSourceInputStreamFactory; + // {D932B052-4ED6-4729-A532-F31DEEC100F3} static constexpr INTERFACE_ID IID_EngineFactory = { 0xd932b052, 0x4ed6, 0x4729, { 0xa5, 0x32, 0xf3, 0x1d, 0xee, 0xc1, 0x0, 0xf3 } }; @@ -43,6 +45,12 @@ class IEngineFactory : public IObject public: /// Returns API info structure virtual const APIInfo& GetAPIInfo() const = 0; + + /// Creates default shader source input stream factory + /// \param [in] SearchDirectories - Semicolon-seprated list of search directories. + /// \param [out] ppShaderSourceStreamFactory - Memory address where pointer to the shader source stream factory will be written. + virtual void CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories, + IShaderSourceInputStreamFactory** ppShaderSourceFactory)const = 0; }; } diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index ece8eda3..333263cc 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -27,6 +27,7 @@ /// Definition of the Diligent::IRenderDevice interface and related data structures #include "../../../Primitives/interface/Object.h" +#include "EngineFactory.h" #include "GraphicsTypes.h" #include "DeviceCaps.h" #include "Constants.h" @@ -188,6 +189,12 @@ public: /// great care only if you are sure the resources are not /// in use by the GPU (such as when the device has just been idled). virtual void ReleaseStaleResources(bool ForceRelease = false) = 0; + + + /// Returns engine factory this device was created from. + /// \remark This method does not increment the reference counter of the returned interface, + /// so the application should not call Release(). + virtual IEngineFactory* GetEngineFactory() const = 0; }; } diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index c993bf4a..7b243a38 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -82,8 +82,12 @@ struct ShaderDesc : DeviceObjectAttribs }; +// {3EA98781-082F-4413-8C30-B9BA6D82DBB7} +static constexpr INTERFACE_ID IID_IShaderSourceInputStreamFactory = +{ 0x3ea98781, 0x82f, 0x4413, { 0x8c, 0x30, 0xb9, 0xba, 0x6d, 0x82, 0xdb, 0xb7 } }; + /// Shader source stream factory interface -class IShaderSourceInputStreamFactory +class IShaderSourceInputStreamFactory : public IObject { public: virtual void CreateInputStream(const Diligent::Char *Name, IFileStream **ppStream) = 0; diff --git a/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp b/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp new file mode 100644 index 00000000..d3bfbd77 --- /dev/null +++ b/Graphics/GraphicsEngine/src/DefaultShaderSourceStreamFactory.cpp @@ -0,0 +1,115 @@ +/* Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#include "pch.h" +#include "DefaultShaderSourceStreamFactory.h" +#include "ObjectBase.h" +#include "RefCntAutoPtr.h" +#include "EngineMemory.h" + +namespace Diligent +{ + +class DefaultShaderSourceStreamFactory final : public ObjectBase<IShaderSourceInputStreamFactory> +{ +public: + DefaultShaderSourceStreamFactory(IReferenceCounters* pRefCounters, const Char *SearchDirectories); + + virtual void CreateInputStream(const Char *Name, IFileStream **ppStream)override final; + + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_IShaderSourceInputStreamFactory, ObjectBase<IShaderSourceInputStreamFactory>); + +private: + std::vector<String> m_SearchDirectories; +}; + +DefaultShaderSourceStreamFactory::DefaultShaderSourceStreamFactory(IReferenceCounters* pRefCounters, const Char* SearchDirectories) : + ObjectBase<IShaderSourceInputStreamFactory>(pRefCounters) +{ + while( SearchDirectories ) + { + const char* Semicolon = strchr( SearchDirectories, ';' ); + String SearchPath; + if( Semicolon == nullptr ) + { + SearchPath = SearchDirectories; + SearchDirectories = nullptr; + } + else + { + SearchPath = String( SearchDirectories, Semicolon ); + SearchDirectories = Semicolon + 1; + } + + if( SearchPath.length() > 0 ) + { + if( SearchPath.back() != '\\' && SearchPath.back() != '/' ) + SearchPath.push_back( '\\' ); + m_SearchDirectories.push_back( SearchPath ); + } + } + m_SearchDirectories.push_back( "" ); +} + +void DefaultShaderSourceStreamFactory::CreateInputStream( const Diligent::Char *Name, IFileStream **ppStream ) +{ + bool bFileCreated = false; + Diligent::RefCntAutoPtr<BasicFileStream> pBasicFileStream; + for (const auto &SearchDir : m_SearchDirectories) + { + String FullPath = SearchDir + ( (Name[0] == '\\' || Name[0] == '/') ? Name + 1 : Name); + if (!FileSystem::FileExists(FullPath.c_str())) + continue; + pBasicFileStream = MakeNewRCObj<BasicFileStream>()( FullPath.c_str(), EFileAccessMode::Read ); + if (pBasicFileStream->IsValid()) + { + bFileCreated = true; + break; + } + else + { + pBasicFileStream.Release(); + } + } + if (bFileCreated) + { + pBasicFileStream->QueryInterface( IID_FileStream, reinterpret_cast<IObject**>(ppStream) ); + } + else + { + *ppStream = nullptr; + LOG_ERROR( "Failed to create input stream for source file ", Name ); + } +} + +void CreateDefaultShaderSourceStreamFactory(const Char* SearchDirectories, + IShaderSourceInputStreamFactory** ppShaderSourceStreamFactory) +{ + + auto& Allocator = GetRawAllocator(); + DefaultShaderSourceStreamFactory* pStreamFactory = + NEW_RC_OBJ(Allocator, "DefaultShaderSourceStreamFactory instance", DefaultShaderSourceStreamFactory)(SearchDirectories); + pStreamFactory->QueryInterface(IID_IShaderSourceInputStreamFactory, reinterpret_cast<IObject**>(ppShaderSourceStreamFactory)); +} + +} |
