29 #include "RenderDevice.h" 30 #include "DeviceObjectBase.h" 32 #include "ResourceMappingImpl.h" 33 #include "StateObjectsRegistry.h" 34 #include "HashUtils.h" 35 #include "ObjectBase.h" 36 #include "DeviceContext.h" 37 #include "SwapChain.h" 38 #include "GraphicsAccessories.h" 39 #include "FixedBlockMemoryAllocator.h" 40 #include "EngineMemory.h" 41 #include "STDAllocator.h" 53 return Diligent::ComputeHash(
77 return Diligent::ComputeHash( static_cast<int>( StOpDesc.
StencilFailOp ),
90 return Diligent::ComputeHash( DepthStencilDesc.
DepthEnable,
92 static_cast<int>(DepthStencilDesc.
DepthFunc),
107 return Diligent::ComputeHash( static_cast<int>( RasterizerDesc.
FillMode ),
108 static_cast<int>( RasterizerDesc.
CullMode ),
125 std::size_t Seed = 0;
129 Diligent::HashCombine( Seed,
131 static_cast<int>( rt.SrcBlend ),
132 static_cast<int>( rt.DestBlend ),
133 static_cast<int>( rt.BlendOp ),
134 static_cast<int>( rt.SrcBlendAlpha ),
135 static_cast<int>( rt.DestBlendAlpha ),
136 static_cast<int>( rt.BlendOpAlpha ),
137 rt.RenderTargetWriteMask );
139 Diligent::HashCombine( Seed,
153 std::size_t Seed = 0;
154 Diligent::HashCombine( Seed,
155 static_cast<Diligent::Int32>(TexViewDesc.
ViewType),
156 static_cast<Diligent::Int32>(TexViewDesc.
TextureDim),
157 static_cast<Diligent::Int32>(TexViewDesc.
Format),
180 template<
typename BaseInterface>
181 class RenderDeviceBase :
public ObjectBase<BaseInterface>
185 typedef ObjectBase<BaseInterface> TObjectBase;
201 IMemoryAllocator &RawMemAllocator,
202 Uint32 NumDeferredContexts,
203 size_t TextureObjSize,
204 size_t TexViewObjSize,
205 size_t BufferObjSize,
206 size_t BuffViewObjSize,
207 size_t ShaderObjSize,
208 size_t SamplerObjSize,
213 m_TexFmtInfoInitFlags(
TEX_FORMAT_NUM_FORMATS, false, STD_ALLOCATOR_RAW_MEM(bool, RawMemAllocator,
"Allocator for vector<bool>") ),
228 static_cast<TextureFormatAttribs&>(m_TextureFormatsInfo[Fmt]) = GetTextureFormatAttribs( static_cast<TEXTURE_FORMAT>(Fmt) );
272 for( Uint32 fmt = 0; fmt < _countof(FilterableFormats); ++fmt )
273 m_TextureFormatsInfo[ FilterableFormats[fmt] ].Filterable =
true;
280 IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_RenderDevice, ObjectBase<BaseInterface> )
283 virtual void CreateResourceMapping(
const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping )
override final;
295 const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat];
296 VERIFY( TexFmtInfo.Format == TexFormat,
"Sanity check failed" );
304 const auto& TexFmtInfo = m_TextureFormatsInfo[TexFormat];
305 VERIFY( TexFmtInfo.Format == TexFormat,
"Sanity check failed" );
306 if( !m_TexFmtInfoInitFlags[TexFormat] )
308 if( TexFmtInfo.Supported )
309 TestTextureFormat(TexFormat);
310 m_TexFmtInfoInitFlags[TexFormat] =
true;
342 RefCntAutoPtr<IDeviceContext> GetDeferredContext(
size_t Ctx){
return m_wpDeferredContexts[Ctx].Lock(); }
346 FixedBlockMemoryAllocator& GetSRBAllocator(){
return m_SRBAllocator;}
353 template<
typename TObjectType,
typename TObjectDescType,
typename TObjectConstructor>
354 void CreateDeviceObject(
const Char *ObjectTypeName,
const TObjectDescType &Desc, TObjectType **ppObject, TObjectConstructor ConstructObject );
356 DeviceCaps m_DeviceCaps;
362 std::vector<TextureFormatInfoExt, STDAllocatorRawMem<TextureFormatInfoExt> > m_TextureFormatsInfo;
363 std::vector<bool, STDAllocatorRawMem<bool> > m_TexFmtInfoInitFlags;
370 std::vector< RefCntWeakPtr<IDeviceContext>, STDAllocatorRawMem<RefCntWeakPtr<IDeviceContext> > >
m_wpDeferredContexts;
384 template<
typename BaseInterface>
387 VERIFY( ppMapping !=
nullptr,
"Null pointer provided" );
388 if( ppMapping ==
nullptr )
390 VERIFY( *ppMapping ==
nullptr,
"Overwriting reference to existing object may cause memory leaks" );
393 pResourceMapping->QueryInterface( IID_ResourceMapping, reinterpret_cast<IObject**>(ppMapping) );
396 for(
auto *pEntry = MappingDesc.
pEntries; pEntry->
Name && pEntry->pObject; ++pEntry )
398 (*ppMapping)->AddResourceArray( pEntry->Name, pEntry->ArrayIndex, &pEntry->pObject, 1,
true );
411 template<
typename BaseInterface>
412 template<
typename TObjectType,
typename TObjectDescType,
typename TObjectConstructor>
415 VERIFY( ppObject !=
nullptr,
"Null pointer provided" );
419 VERIFY( *ppObject ==
nullptr,
"Overwriting reference to existing object may cause memory leaks" );
434 catch(
const std::runtime_error & )
436 VERIFY( *ppObject ==
nullptr,
"Object was created despite error" );
439 (*ppObject)->Release();
442 auto ObjectDescString = GetObjectDescString( Desc );
443 if( ObjectDescString.length() )
445 LOG_ERROR(
"Failed to create ", ObjectTypeName,
" object \"", Desc.Name ? Desc.Name :
"",
"\"\n", ObjectDescString );
449 LOG_ERROR(
"Failed to create ", ObjectTypeName,
" object \"", Desc.Name ? Desc.Name :
"",
"\"" );
STENCIL_OP StencilPassOp
The stencil operation to perform when stencil testing and depth testing both pass.
Definition: DepthStencilState.h:101
TEXTURE_FORMAT
Texture formats.
Definition: GraphicsTypes.h:244
FixedBlockMemoryAllocator m_ResMappingAllocator
Allocator for resource mapping objects.
Definition: RenderDeviceBase.h:380
COMPARISON_FUNCTION StencilFunc
A function that compares stencil data against existing stencil data. See Diligent::COMPARISON_FUNCTIO...
Definition: DepthStencilState.h:105
RESOURCE_DIMENSION TextureDim
View interpretation of the original texture. For instance, one slice of a 2D texture array can be vie...
Definition: TextureView.h:65
void SetDeferredContext(size_t Ctx, IDeviceContext *pDeferredCtx)
Set weak reference to the deferred context.
Definition: RenderDeviceBase.h:329
virtual void CreateResourceMapping(const ResourceMappingDesc &MappingDesc, IResourceMapping **ppMapping) override final
Implementation of IRenderDevice::CreateResourceMapping().
Definition: RenderDeviceBase.h:385
Four-component unsigned-normalized-integer block-compression format with 5 bits for R...
Definition: GraphicsTypes.h:615
Int32 DepthBias
Constant value added to the depth of a given pixel.
Definition: RasterizerState.h:105
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
Single-component 8-bit unsigned-normalized-integer format. D3D counterpart: DXGI_FORMAT_R8_UNORM. OpenGL counterpart: GL_R8.
Definition: GraphicsTypes.h:510
Unknown format.
Definition: GraphicsTypes.h:247
FixedBlockMemoryAllocator m_TexObjAllocator
Allocator for texture objects.
Definition: RenderDeviceBase.h:372
ResourceMappingEntry * pEntries
Pointer to the array of resource mapping entries. The last element in the array must be default value...
Definition: ResourceMapping.h:65
Two-component 32-bit signed-normalized-integer format with 16-bit channels. D3D counterpart: DXGI_F...
Definition: GraphicsTypes.h:409
Two-component unsigned-normalized-integer block-compression format with 8 bits for R and 8 bits for G...
Definition: GraphicsTypes.h:667
float MaxLOD
Specifies the maximum value that LOD is clamped to before accessing the texture MIP levels...
Definition: Sampler.h:95
Four-component unsigned-normalized-integer block-compression format with 5 bits for R...
Definition: GraphicsTypes.h:563
Uint8 StencilWriteMask
Identify which bits of the depth-stencil buffer are accessed when writing stencil data...
Definition: DepthStencilState.h:166
RefCntWeakPtr< IDeviceContext > m_wpImmediateContext
Weak reference to the immediate context. Immediate context holds strong reference to the device...
Definition: RenderDeviceBase.h:367
Single-component 32-bit floating-point format. D3D counterpart: DXGI_FORMAT_R32_FLOAT. OpenGL counterpart: GL_R32F.
Definition: GraphicsTypes.h:425
StateObjectsRegistry< SamplerDesc > m_SamplersRegistry
Sampler state registry.
Definition: RenderDeviceBase.h:361
Bool AlphaToCoverageEnable
Specifies whether to use alpha-to-coverage as a multisampling technique when setting a pixel to a ren...
Definition: BlendState.h:355
Bool DepthEnable
Enable depth-stencil operations. When it is set to False, depth test always passes, depth writes are disabled, and no stencil operations are performed.
Definition: DepthStencilState.h:150
Uint8 StencilReadMask
Identify which bits of the depth-stencil buffer are accessed when reading stencil data...
Definition: DepthStencilState.h:163
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
void SetImmediateContext(IDeviceContext *pImmediateContext)
Set weak reference to the immediate context.
Definition: RenderDeviceBase.h:322
FILL_MODE FillMode
Determines traingle fill mode, see Diligent::FILL_MODE for details.
Definition: RasterizerState.h:93
Definition: AdvancedMath.h:316
Bool DepthClipEnable
Enable clipping based on distance.
Definition: RasterizerState.h:117
Bool FrontCounterClockwise
Determines if a triangle is front- or back-facing. If this parameter is True, a triangle will be cons...
Definition: RasterizerState.h:102
TEXTURE_ADDRESS_MODE AddressV
Texture address mode for V coordinate, see Diligent::TEXTURE_ADDRESS_MODE for details.
Definition: Sampler.h:69
Device capabilities.
Definition: DeviceCaps.h:96
FixedBlockMemoryAllocator m_TexViewObjAllocator
Allocator for texture view objects.
Definition: RenderDeviceBase.h:373
Two-component 16-bit unsigned-normalized-integer format with 8-bit channels. D3D counterpart: DXGI_...
Definition: GraphicsTypes.h:458
Four-component 64-bit unsigned-normalized-integer format with 16-bit channels. D3D counterpart: DXG...
Definition: GraphicsTypes.h:297
StencilOpDesc FrontFace
Identify stencil operations for the front-facing triangles, see Diligent::StencilOpDesc.
Definition: DepthStencilState.h:169
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:46
One-component unsigned-normalized-integer block-compression format with 8 bits for R channel...
Definition: GraphicsTypes.h:641
Single-component 16-bit unsigned-normalized-integer format. D3D counterpart: DXGI_FORMAT_R16_UNORM...
Definition: GraphicsTypes.h:488
Resouce mapping.
Definition: ResourceMapping.h:80
Two-component 32-bit half-precision floating-point format with 16-bit channels. D3D counterpart: DX...
Definition: GraphicsTypes.h:393
Uint32 MostDetailedMip
Most detailed mip level to use.
Definition: TextureView.h:72
virtual const TextureFormatInfo & GetTextureFormatInfo(TEXTURE_FORMAT TexFormat) override final
Implementation of IRenderDevice::GetTextureFormatInfo().
Definition: RenderDeviceBase.h:292
Four-component 32-bit signed-normalized-integer format with 8-bit channels. D3D counterpart: DXGI_F...
Definition: GraphicsTypes.h:381
STENCIL_OP StencilFailOp
The stencil operation to perform when stencil testing fails.
Definition: DepthStencilState.h:95
Single-component 8-bit unsigned-normalized-integer format for alpha only. D3D counterpart: DXGI_FOR...
Definition: GraphicsTypes.h:527
Three-component 16-bit unsigned-normalized-integer format with 5 bits for blue, 6 bits for green...
Definition: GraphicsTypes.h:681
std::vector< RefCntWeakPtr< IDeviceContext >, STDAllocatorRawMem< RefCntWeakPtr< IDeviceContext > > > m_wpDeferredContexts
Weak references to deferred contexts.
Definition: RenderDeviceBase.h:370
Describes stencil operations that are performed based on the results of depth test.
Definition: DepthStencilState.h:92
Four-component 32-bit unsigned-normalized-integer format with 8-bit channels. D3D counterpart: DXGI...
Definition: GraphicsTypes.h:369
TEXTURE_ADDRESS_MODE AddressU
Texture address mode for U coordinate, see Diligent::TEXTURE_ADDRESS_MODE for details.
Definition: Sampler.h:66
FixedBlockMemoryAllocator m_PSOAllocator
Allocator for pipeline state objects.
Definition: RenderDeviceBase.h:378
TEXTURE_ADDRESS_MODE AddressW
Texture address mode for W coordinate, see Diligent::TEXTURE_ADDRESS_MODE for details.
Definition: Sampler.h:72
Three-component 32-bit format encoding three partial precision channels using 11 bits for red and gre...
Definition: GraphicsTypes.h:361
Sampler description.
Definition: Sampler.h:52
Blend state description.
Definition: BlendState.h:351
Four-component unsigned-normalized integer format analogous to UYVY encoding. D3D counterpart: DXGI...
Definition: GraphicsTypes.h:541
Float32 MipLODBias
Offset from the calculated mipmap level. For example, if a sampler calculates that a texture should b...
Definition: Sampler.h:77
Single-component 16-bit half-precisoin floating-point format. D3D counterpart: DXGI_FORMAT_R16_FLOA...
Definition: GraphicsTypes.h:478
Bool ScissorEnable
Enable scissor-rectangle culling. All pixels outside an active scissor rectangle are culled...
Definition: RasterizerState.h:120
Four-component unsigned-normalized-integer block-compression format with 5 bits for R...
Definition: GraphicsTypes.h:589
COMPARISON_FUNCTION ComparisonFunc
A function that compares sampled data against existing sampled data when comparsion filter is used...
Definition: Sampler.h:84
float MinLOD
Specifies the minimum value that LOD is clamped to before accessing the texture MIP levels...
Definition: Sampler.h:91
FixedBlockMemoryAllocator m_BufObjAllocator
Allocator for buffer objects.
Definition: RenderDeviceBase.h:374
Device context interface.
Definition: DeviceContext.h:443
Template class implementing state object registry.
Definition: StateObjectsRegistry.h:58
Resource mapping description.
Definition: ResourceMapping.h:60
size_t GetNumDeferredContexts() const
Returns number of deferred contexts.
Definition: RenderDeviceBase.h:336
Four-component unsigned-normalized-integer block-compression sRGB format with 5 bits for R...
Definition: GraphicsTypes.h:572
FixedBlockMemoryAllocator m_BuffViewObjAllocator
Allocator for buffer view objects.
Definition: RenderDeviceBase.h:375
Base implementation of a render device.
Definition: DeviceObjectBase.h:36
STENCIL_OP StencilDepthFailOp
The stencil operation to perform when stencil testing passes and depth testing fails.
Definition: DepthStencilState.h:98
Implementation of weak pointers.
Definition: RefCntAutoPtr.h:38
Two-component 32-bit format with 24 bits for unsigned-normalized-integer data and 8 bits of unreferen...
Definition: GraphicsTypes.h:445
Two-component 64-bit floating-point format with 32-bit channels. D3D counterpart: DXGI_FORMAT_R32G3...
Definition: GraphicsTypes.h:320
Bool DepthWriteEnable
Enable or disable writes to a depth buffer.
Definition: DepthStencilState.h:153
CULL_MODE CullMode
Determines traingle cull mode, see Diligent::CULL_MODE for details.
Definition: RasterizerState.h:96
Four-component 64-bit signed-normalized-integer format with 16-bit channels. D3D counterpart: DXGI_...
Definition: GraphicsTypes.h:308
Float32 SlopeScaledDepthBias
Scalar that scales the given pixel's slope before adding to the pixel's depth.
Definition: RasterizerState.h:112
StencilOpDesc BackFace
Identify stencil operations for the back-facing triangles, see Diligent::StencilOpDesc.
Definition: DepthStencilState.h:172
Rasterizer state description.
Definition: RasterizerState.h:90
Memory allocator that allocates memory in a fixed-size chunks.
Definition: FixedBlockMemoryAllocator.h:50
Four-component unsigned-normalized-integer block-compression sRGB format with 5 bits for R...
Definition: GraphicsTypes.h:624
One-component signed-normalized-integer block-compression format with 8 bits for R channel...
Definition: GraphicsTypes.h:650
virtual const DeviceCaps & GetDeviceCaps() const override final
Implementation of IRenderDevice::GetDeviceCaps().
Definition: RenderDeviceBase.h:286
Texture view description.
Definition: TextureView.h:55
TEXTURE_VIEW_TYPE ViewType
Describes the texture view type, see Diligent::TEXTURE_VIEW_TYPE for details.
Definition: TextureView.h:58
Two-component signed-normalized-integer block-compression format with 8 bits for R and 8 bits for G c...
Definition: GraphicsTypes.h:676
Three partial-precision floating pointer numbers sharing single exponent encoded into a 32-bit value...
Definition: GraphicsTypes.h:536
Four-component unsigned-normalized integer format analogous to YUY2 encoding. D3D counterpart: DXGI...
Definition: GraphicsTypes.h:546
Bool IndependentBlendEnable
Specifies whether to enable independent blending in simultaneous render targets. If set to False...
Definition: BlendState.h:359
void CreateDeviceObject(const Char *ObjectTypeName, const TObjectDescType &Desc, TObjectType **ppObject, TObjectConstructor ConstructObject)
Helper template function to facilitate device object creation.
Definition: RenderDeviceBase.h:413
Bool StencilEnable
Enable stencil opertaions.
Definition: DepthStencilState.h:160
const Char * Name
Object name.
Definition: ResourceMapping.h:41
Depth stencil state description.
Definition: DepthStencilState.h:145
Single-component 8-bit signed-normalized-integer format. D3D counterpart: DXGI_FORMAT_R8_SNORM. OpenGL counterpart: GL_R8_SNORM.
Definition: GraphicsTypes.h:518
Extended texture format description.
Definition: GraphicsTypes.h:1115
static constexpr int MaxRenderTargets
Constant member defining the maximum number of render targets.
Definition: BlendState.h:362
Four-component 32-bit unsigned-normalized-integer sRGB format with 8-bit channels. D3D counterpart: DXGI_FORMAT_R8G8B8A8_UNORM_SRGB. OpenGL counterpart: GL_SRGB8_ALPHA8.
Definition: GraphicsTypes.h:373
Float32 DepthBiasClamp
Maximum depth bias of a pixel.
Definition: RasterizerState.h:109
FixedBlockMemoryAllocator m_SRBAllocator
Allocator for shader resource binding objects.
Definition: RenderDeviceBase.h:379
Helper member containing the total number of texture formats in the enumeration.
Definition: GraphicsTypes.h:772
Uint32 NumMipLevels
Total number of mip levels for the view of the texture. Render target and depth stencil views can add...
Definition: TextureView.h:79
FILTER_TYPE MipFilter
Mip filter, see Diligent::FILTER_TYPE for details. Only FILTER_TYPE_POINT, FILTER_TYPE_LINEAR, FILTER_TYPE_ANISOTROPIC, and FILTER_TYPE_COMPARISON_ANISOTROPIC are allowed.
Definition: Sampler.h:63
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)
Definition: RenderDeviceBase.h:200
Template class that implements reference counting.
Definition: RefCntAutoPtr.h:71
Float32 BorderColor[4]
Border color to use if TEXTURE_ADDRESS_BORDER is specified for AddressU, AddressV, or AddressW.
Definition: Sampler.h:87
Uint32 MaxAnisotropy
Maximum anisotropy level for the anisotropic filter.
Definition: Sampler.h:80
FILTER_TYPE MinFilter
Texture minification filter, see Diligent::FILTER_TYPE for details.
Definition: Sampler.h:55
Four-component 128-bit floating-point format with 32-bit channels. D3D counterpart: DXGI_FORMAT_R32...
Definition: GraphicsTypes.h:255
FixedBlockMemoryAllocator m_SamplerObjAllocator
Allocator for sampler objects.
Definition: RenderDeviceBase.h:377
Two-component 16-bit signed-normalized-integer format with 8-bit channels. D3D counterpart: DXGI_FO...
Definition: GraphicsTypes.h:466
Implementation of the resource mapping.
Definition: ResourceMappingImpl.h:93
Four-component signed-normalized-integer block-compression sRGB format with 5 bits for R...
Definition: GraphicsTypes.h:598
Uint32 NumArraySlices
For a texture array, number of array slices to address in the view. Set to 0 to address all array sli...
Definition: TextureView.h:94
FILTER_TYPE MagFilter
Texture magnification filter, see Diligent::FILTER_TYPE for details.
Definition: Sampler.h:58
TEXTURE_FORMAT Format
View format. If default value Diligent::TEX_FORMAT_UNKNOWN is provided, the view format will match th...
Definition: TextureView.h:69
Two-component 32-bit unsigned-normalized-integer format with 16-bit channels. D3D counterpart: DXGI...
Definition: GraphicsTypes.h:399
Two-component 64-bit format with 32-bit floating-point R channel and 8+24-bits of typeless data...
Definition: GraphicsTypes.h:340
Uint32 AccessFlags
For an unordered access view, allowed access flags. See Diligent::UAV_ACCESS_FLAG for details...
Definition: TextureView.h:103
Four-component 64-bit half-precision floating-point format with 16-bit channels. D3D counterpart: D...
Definition: GraphicsTypes.h:291
COMPARISON_FUNCTION DepthFunc
A function that compares depth data against existing depth data. See Diligent::COMPARISON_FUNCTION fo...
Definition: DepthStencilState.h:157
RenderTargetBlendDesc RenderTargets[MaxRenderTargets]
An array of RenderTargetBlendDesc structures that describe the blend states for render targets...
Definition: BlendState.h:366
FixedBlockMemoryAllocator m_ShaderObjAllocator
Allocator for shader objects.
Definition: RenderDeviceBase.h:376
Bool AntialiasedLineEnable
Specifies whether to enable line antialiasing.
Definition: RasterizerState.h:123
virtual const TextureFormatInfoExt & GetTextureFormatInfoExt(TEXTURE_FORMAT TexFormat) override final
Implementation of IRenderDevice::GetTextureFormatInfoExt().
Definition: RenderDeviceBase.h:301
Single-component 16-bit signed-normalized-integer format. D3D counterpart: DXGI_FORMAT_R16_SNORM. OpenGL counterpart: GL_R16_SNORM. OpenGLES: GL_EXT_texture_norm16 extension is required.
Definition: GraphicsTypes.h:498
Basic texture format description.
Definition: GraphicsTypes.h:1101
Uint32 FirstArraySlice
For a texture array, first array slice to address in the view.
Definition: TextureView.h:84