30 #include "DeviceObjectBase.h" 31 #include "GraphicsAccessories.h" 32 #include "STDAllocator.h" 38 void ValidateTextureDesc(
const TextureDesc& TexDesc);
39 void ValidateUpdateDataParams(
const TextureDesc &TexDesc, Uint32 MipLevel, Uint32 Slice,
const Box &DstBox,
const TextureSubResData &SubresData );
40 void VliadateCopyTextureDataParams(
const TextureDesc &SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice,
const Box *pSrcBox,
41 const TextureDesc &DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice,
42 Uint32 DstX, Uint32 DstY, Uint32 DstZ );
51 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
65 TTexViewObjAllocator &TexViewObjAllocator,
68 bool bIsDeviceInternal =
false ) :
71 m_dbgTexViewObjAllocator(TexViewObjAllocator),
73 m_pDefaultSRV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)),
74 m_pDefaultRTV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)),
75 m_pDefaultDSV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator)),
76 m_pDefaultUAV(nullptr, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>(TexViewObjAllocator))
99 UNEXPECTED(
"Unkwnown texture type" );
104 ValidateTextureDesc( this->
m_Desc );
107 IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Texture, TDeviceObjectBase )
117 virtual void UpdateData( IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice,
const Box &DstBox,
const TextureSubResData &SubresData )
override = 0;
120 virtual void CopyData( IDeviceContext *pContext,
121 ITexture *pSrcTexture,
129 Uint32 DstZ )
override = 0;
132 virtual void Map( IDeviceContext *pContext, Uint32 Subresource,
MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData )
override = 0;
135 virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource,
MAP_TYPE MapType, Uint32 MapFlags )
override = 0;
151 virtual void CreateViewInternal(
const struct TextureViewDesc &ViewDesc, ITextureView **ppView,
bool bIsDefaultView ) = 0;
154 TTexViewObjAllocator &m_dbgTexViewObjAllocator;
158 std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>>
m_pDefaultSRV;
160 std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>>
m_pDefaultRTV;
162 std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>>
m_pDefaultDSV;
164 std::unique_ptr<TTextureViewImpl, STDDeleter<TTextureViewImpl, TTexViewObjAllocator>>
m_pDefaultUAV;
175 default: UNEXPECTED(
"Unknown view type" );
return nullptr;
183 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
184 void TextureBase<BaseInterface, TTextureViewImpl, TTexViewObjAllocator> :: CorrectTextureViewDesc(
struct TextureViewDesc &ViewDesc)
186 #define TEX_VIEW_VALIDATION_ERROR(...) LOG_ERROR_AND_THROW( "Texture view \"", ViewDesc.Name ? ViewDesc.Name : "", "\": ", ##__VA_ARGS__ ) 189 TEX_VIEW_VALIDATION_ERROR(
"Texture view type is not specified" );
191 if( ViewDesc.MostDetailedMip + ViewDesc.NumMipLevels > this->m_Desc.MipLevels )
192 TEX_VIEW_VALIDATION_ERROR(
"Most detailed mip (", ViewDesc.MostDetailedMip,
") and number of mip levels in the view (", ViewDesc.NumMipLevels,
") specify more levels than target texture has (", this->m_Desc.MipLevels,
")" );
195 ViewDesc.Format = GetDefaultTextureViewFormat( this->m_Desc.Format, ViewDesc.ViewType, this->m_Desc.BindFlags );
201 switch (ViewDesc.ViewType)
204 ViewDesc.TextureDim = this->m_Desc.Type;
213 default: UNEXPECTED(
"Unexpected view type");
218 ViewDesc.TextureDim = this->m_Desc.Type;
222 switch( this->m_Desc.Type )
227 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture 1D view: only Texture 1D is allowed" );
235 TEX_VIEW_VALIDATION_ERROR(
"Incorrect view type for Texture 1D Array: only Texture 1D or Texture 1D Array are allowed" );
242 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture 2D view: only Texture 2D is allowed" );
250 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture 2D Array view: only Texture 2D or Texture 2D Array are allowed" );
257 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture 3D view: only Texture 3D is allowed" );
268 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture cube SRV: Texture 2D, Texture 2D array or Texture Cube is allowed" );
276 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture cube non-shader resource view: Texture 2D or Texture 2D array is allowed" );
289 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture cube array SRV: Texture 2D, Texture 2D array, Texture Cube or Texture Cube Array is allowed" );
297 TEX_VIEW_VALIDATION_ERROR(
"Incorrect texture type for Texture cube array non-shader resource view: Texture 2D or Texture 2D array is allowed" );
303 UNEXPECTED(
"Unexpected texture type" );
310 if(ViewDesc.NumArraySlices != 6 && ViewDesc.NumArraySlices != 0)
311 TEX_VIEW_VALIDATION_ERROR(
"Texture cube SRV is expected to have 6 array slices, while ", ViewDesc.NumArraySlices,
" is provided" );
312 if(ViewDesc.FirstArraySlice != 0)
313 TEX_VIEW_VALIDATION_ERROR(
"First slice (", ViewDesc.FirstArraySlice,
") must be 0 for non-array texture cube SRV" );
318 if((ViewDesc.NumArraySlices % 6) != 0)
319 TEX_VIEW_VALIDATION_ERROR(
"Number of slices in texture cube array SRV is expected to be multiple of 6. ", ViewDesc.NumArraySlices,
" slices provided." );
325 if(ViewDesc.FirstArraySlice != 0)
326 TEX_VIEW_VALIDATION_ERROR(
"First slice (", ViewDesc.FirstArraySlice,
") must be 0 for non-array texture 1D/2D views" );
328 if(ViewDesc.NumArraySlices > 1)
329 TEX_VIEW_VALIDATION_ERROR(
"Number of slices in the view (", ViewDesc.NumArraySlices,
") must be 1 (or 0) for non-array texture 1D/2D views" );
336 if( ViewDesc.FirstArraySlice + ViewDesc.NumArraySlices > this->m_Desc.ArraySize )
337 TEX_VIEW_VALIDATION_ERROR(
"First slice (", ViewDesc.FirstArraySlice,
") and number of slices in the view (", ViewDesc.NumArraySlices,
") specify more slices than target texture has (", this->m_Desc.ArraySize,
")" );
341 auto MipDepth = this->m_Desc.Depth >> ViewDesc.MostDetailedMip;
342 if( ViewDesc.FirstDepthSlice + ViewDesc.NumDepthSlices > MipDepth )
343 TEX_VIEW_VALIDATION_ERROR(
"First slice (", ViewDesc.FirstDepthSlice,
") and number of slices in the view (", ViewDesc.NumDepthSlices,
") specify more slices than target 3D texture mip level has (", MipDepth,
")" );
347 UNEXPECTED(
"Unexpected texture dimension");
350 #undef TEX_VIEW_VALIDATION_ERROR 352 if( ViewDesc.NumMipLevels == 0 )
355 ViewDesc.NumMipLevels = this->m_Desc.MipLevels - ViewDesc.MostDetailedMip;
357 ViewDesc.NumMipLevels = 1;
360 if( ViewDesc.NumArraySlices == 0 )
366 ViewDesc.NumArraySlices = this->m_Desc.ArraySize - ViewDesc.FirstArraySlice;
369 auto MipDepth = this->m_Desc.Depth >> ViewDesc.MostDetailedMip;
370 ViewDesc.NumDepthSlices = MipDepth - ViewDesc.FirstDepthSlice;
373 ViewDesc.NumArraySlices = 1;
380 const auto *FmtName = GetTextureFormatAttribs( ViewDesc.Format ).Name;
381 LOG_WARNING_MESSAGE( FmtName,
" render target view is created.\n" 382 "There might be an issue in OpenGL driver on NVidia hardware: when rendering to SNORM textures, all negative values are clamped to zero.\n" 383 "Use UNORM format instead." );
387 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
390 const auto& TexFmtAttribs = GetTextureFormatAttribs(this->m_Desc.Format);
402 CreateViewInternal( ViewDesc, &pSRV,
true );
403 m_pDefaultSRV.reset( static_cast<TTextureViewImpl*>(pSRV) );
412 CreateViewInternal( ViewDesc, &pRTV,
true );
413 m_pDefaultRTV.reset( static_cast<TTextureViewImpl*>(pRTV) );
422 CreateViewInternal( ViewDesc, &pDSV,
true );
423 m_pDefaultDSV.reset( static_cast<TTextureViewImpl*>(pDSV) );
433 CreateViewInternal( ViewDesc, &pUAV,
true );
434 m_pDefaultUAV.reset( static_cast<TTextureViewImpl*>(pUAV) );
440 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
443 ValidateUpdateDataParams( this->m_Desc, MipLevel, Slice, DstBox, SubresData );
446 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
458 VERIFY( pContext,
"pContext is null" );
459 VERIFY( pSrcTexture,
"pSrcTexture is null" );
460 VliadateCopyTextureDataParams( pSrcTexture->
GetDesc(), SrcMipLevel, SrcSlice, pSrcBox,
461 this->GetDesc(), DstMipLevel, DstSlice, DstX, DstY, DstZ );
464 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
469 template<
class BaseInterface,
class TTextureViewImpl,
class TTexViewObjAllocator>
Cube-map texture.
Definition: GraphicsTypes.h:181
virtual void Unmap(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags) override=0
Base implementaiton of ITexture::Unmap()
Definition: TextureBase.h:470
Texture description.
Definition: Texture.h:82
Two-dimensional texture.
Definition: GraphicsTypes.h:178
A texture can be bound as a render target.
Definition: GraphicsTypes.h:71
One-dimensional texture.
Definition: GraphicsTypes.h:176
TEXTURE_VIEW_TYPE
Texture view type.
Definition: GraphicsTypes.h:190
Render device interface.
Definition: RenderDevice.h:55
Unknown format.
Definition: GraphicsTypes.h:247
Two-component 32-bit signed-normalized-integer format with 16-bit channels. D3D counterpart: DXGI_F...
Definition: GraphicsTypes.h:409
void CreateDefaultViews()
Creates default texture views.
Definition: TextureBase.h:388
virtual const TextureDesc & GetDesc() const =0
Returns the texture description used to create the object.
ITextureView * GetDefaultView(TEXTURE_VIEW_TYPE ViewType) override
Implementation of ITexture::GetDefaultView().
Definition: TextureBase.h:167
Cube-map array texture.
Definition: GraphicsTypes.h:182
Helper value that stores that total number of texture views.
Definition: GraphicsTypes.h:212
A buffer or a texture can be bound as a shader resource.
Definition: GraphicsTypes.h:68
Allow read and write operations on the UAV.
Definition: TextureView.h:51
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Undefined view type.
Definition: GraphicsTypes.h:193
virtual void UpdateData(IDeviceContext *pContext, Uint32 MipLevel, Uint32 Slice, const Box &DstBox, const TextureSubResData &SubresData) override=0
Base implementaiton of ITexture::UpdateData(); validates input parameters.
Definition: TextureBase.h:441
Describes data for one subresource.
Definition: Texture.h:193
Undefined component type.
Definition: GraphicsTypes.h:1029
Four-component 32-bit signed-normalized-integer format with 8-bit channels. D3D counterpart: DXGI_F...
Definition: GraphicsTypes.h:381
Uint32 MipLevels
Number of Mip levels in the texture. Multisampled textures can only have 1 Mip level. Specify 0 to generate full mipmap chain.
Definition: Texture.h:106
Uint32 Width
Texture width, in pixels.
Definition: Texture.h:88
Device context interface.
Definition: DeviceContext.h:443
A texture can be bound as a depth-stencil target.
Definition: GraphicsTypes.h:72
Box.
Definition: GraphicsTypes.h:1005
A texture view will define a depth stencil view that will be used as the target for rendering operati...
Definition: GraphicsTypes.h:205
Texture view interface.
Definition: TextureView.h:163
virtual void CopyData(IDeviceContext *pContext, ITexture *pSrcTexture, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box *pSrcBox, Uint32 DstMipLevel, Uint32 DstSlice, Uint32 DstX, Uint32 DstY, Uint32 DstZ) override=0
Base implementaiton of ITexture::CopyData(); validates input parameters.
Definition: TextureBase.h:447
Four-component 64-bit signed-normalized-integer format with 16-bit channels. D3D counterpart: DXGI_...
Definition: GraphicsTypes.h:308
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
TextureDesc m_Desc
Object description.
Definition: DeviceObjectBase.h:138
One-dimensional texture array.
Definition: GraphicsTypes.h:177
A buffer or a texture can be bound as an unordered access view.
Definition: GraphicsTypes.h:73
Single-component 8-bit signed-normalized-integer format. D3D counterpart: DXGI_FORMAT_R8_SNORM. OpenGL counterpart: GL_R8_SNORM.
Definition: GraphicsTypes.h:518
virtual void Map(IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData) override=0
Base implementaiton of ITexture::Map()
Definition: TextureBase.h:465
RESOURCE_DIMENSION Type
Texture type. See Diligent::RESOURCE_DIMENSION for details.
Definition: Texture.h:85
A texture view will define an unordered access view that will be used for unordered read/write operat...
Definition: GraphicsTypes.h:209
Three-dimensional texture.
Definition: GraphicsTypes.h:180
std::unique_ptr< TTextureViewImpl, STDDeleter< TTextureViewImpl, TTexViewObjAllocator > > m_pDefaultUAV
Default UAV addressing the entire texture.
Definition: TextureBase.h:164
TextureBase(IReferenceCounters *pRefCounters, TTexViewObjAllocator &TexViewObjAllocator, IRenderDevice *pDevice, const TextureDesc &Desc, bool bIsDeviceInternal=false)
Definition: TextureBase.h:64
std::unique_ptr< TTextureViewImpl, STDDeleter< TTextureViewImpl, TTexViewObjAllocator > > m_pDefaultSRV
Default SRV addressing the entire texture.
Definition: TextureBase.h:158
std::unique_ptr< TTextureViewImpl, STDDeleter< TTextureViewImpl, TTexViewObjAllocator > > m_pDefaultRTV
Default RTV addressing the most detailed mip level.
Definition: TextureBase.h:160
Two-component 16-bit signed-normalized-integer format with 8-bit channels. D3D counterpart: DXGI_FO...
Definition: GraphicsTypes.h:466
Texture type undefined.
Definition: GraphicsTypes.h:174
A texture view will define a shader resource view that will be used as the source for the shader read...
Definition: GraphicsTypes.h:197
Uint32 AccessFlags
For an unordered access view, allowed access flags. See Diligent::UAV_ACCESS_FLAG for details...
Definition: TextureView.h:103
Template class implementing base functionality for a device object.
Definition: DeviceObjectBase.h:42
std::unique_ptr< TTextureViewImpl, STDDeleter< TTextureViewImpl, TTexViewObjAllocator > > m_pDefaultDSV
Default DSV addressing the most detailed mip level.
Definition: TextureBase.h:162
Base implementation of the ITexture interface.
Definition: TextureBase.h:52
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
virtual void CreateViewInternal(const struct TextureViewDesc &ViewDesc, ITextureView **ppView, bool bIsDefaultView)=0
Pure virtual function that creates texture view for the specific engine implementation.
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
A texture view will define a render target view that will be used as the target for rendering operati...
Definition: GraphicsTypes.h:201
Two-dimensional texture array.
Definition: GraphicsTypes.h:179
Texture inteface.
Definition: Texture.h:276
virtual void CreateView(const struct TextureViewDesc &ViewDesc, ITextureView **ppView) override
Implementaiton of ITexture::CreateView(); calls CreateViewInternal() virtual function that creates te...
Definition: TextureBase.h:111