summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-09-01 19:02:31 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-09-01 19:02:31 +0000
commit590c98bfe02f1758f3828b8e3cc813c0dbee654e (patch)
treee5072aad7d2944a6b03aa1141b1a5ced90975959 /Graphics/GraphicsEngine
parentDisabled notification messages in OpenGL (diff)
downloadDiligentCore-590c98bfe02f1758f3828b8e3cc813c0dbee654e.tar.gz
DiligentCore-590c98bfe02f1758f3828b8e3cc813c0dbee654e.zip
Updated texture map/unmap intererface; implemented texture mapping in D3D12
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/TextureBase.h28
-rw-r--r--Graphics/GraphicsEngine/interface/Texture.h28
-rw-r--r--Graphics/GraphicsEngine/src/Texture.cpp56
3 files changed, 72 insertions, 40 deletions
diff --git a/Graphics/GraphicsEngine/include/TextureBase.h b/Graphics/GraphicsEngine/include/TextureBase.h
index b20e3761..949d8d98 100644
--- a/Graphics/GraphicsEngine/include/TextureBase.h
+++ b/Graphics/GraphicsEngine/include/TextureBase.h
@@ -40,6 +40,12 @@ void ValidateUpdateDataParams( const TextureDesc &TexDesc, Uint32 MipLevel, Uint
void VliadateCopyTextureDataParams( const TextureDesc& SrcTexDesc, Uint32 SrcMipLevel, Uint32 SrcSlice, const Box* pSrcBox,
const TextureDesc& DstTexDesc, Uint32 DstMipLevel, Uint32 DstSlice,
Uint32 DstX, Uint32 DstY, Uint32 DstZ );
+void ValidateMapTextureParams(const TextureDesc& TexDesc,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ MAP_TYPE MapType,
+ Uint32 MapFlags,
+ const Box* pMapRegion);
/// Base implementation of the ITexture interface
@@ -146,10 +152,16 @@ public:
Uint32 DstZ )override = 0;
/// Base implementaiton of ITexture::Map()
- virtual void Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource& MappedData )override = 0;
+ virtual void Map(IDeviceContext* pContext,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ MAP_TYPE MapType,
+ Uint32 MapFlags,
+ const Box* pMapRegion,
+ MappedTextureSubresource& MappedData)override = 0;
/// Base implementaiton of ITexture::Unmap()
- virtual void Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )override = 0;
+ virtual void Unmap( IDeviceContext* pContext, Uint32 MipLevel, Uint32 ArraySlice)override = 0;
/// Creates default texture views.
@@ -483,12 +495,20 @@ void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObj
}
template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator>
-void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Map( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData )
+void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Map(
+ IDeviceContext* pContext,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ MAP_TYPE MapType,
+ Uint32 MapFlags,
+ const Box* pMapRegion,
+ MappedTextureSubresource& MappedData)
{
+ ValidateMapTextureParams(m_Desc, MipLevel, ArraySlice, MapType, MapFlags, pMapRegion);
}
template<class BaseInterface, class TRenderDeviceImpl,class TTextureViewImpl, class TTexViewObjAllocator>
-void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Unmap( IDeviceContext* pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags )
+void TextureBase<BaseInterface, TRenderDeviceImpl, TTextureViewImpl, TTexViewObjAllocator> :: Unmap(IDeviceContext* pContext, Uint32 MipLevel, Uint32 ArraySlice)
{
}
diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h
index 121a86c3..ba739d96 100644
--- a/Graphics/GraphicsEngine/interface/Texture.h
+++ b/Graphics/GraphicsEngine/interface/Texture.h
@@ -346,10 +346,30 @@ public:
Uint32 DstY,
Uint32 DstZ) = 0;
- /// Map the texture - not implemented yet
- virtual void Map( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags, MappedTextureSubresource &MappedData ) = 0;
- /// Unmap the textute - not implemented yet
- virtual void Unmap( IDeviceContext *pContext, Uint32 Subresource, MAP_TYPE MapType, Uint32 MapFlags ) = 0;
+ /// Map the texture
+
+ /// \param [in] pContext - Pointer to the device context interface to be used to perform the operation.
+ /// \param [in] MipLevel - Mip level to map.
+ /// \param [in] ArraySlice - Array slice to map. This parameter must be 0 for non-array textures.
+ /// \param [in] MapType - Type of the map operation. See Diligent::MAP_TYPE.
+ /// \param [in] MapFlags - Special map flags. See Diligent::MAP_FLAGS.
+ /// \param [in] pMapRegion - Texture region to map. If this parameter is null, the entire subresource is mapped.
+ /// \param [out] MappedData - Mapped texture region data
+ ///
+ /// \remarks This method is supported in D3D11, D3D12 and Vulkan backends. In D3D11 backend, only the entire
+ /// subresource can be mapped, so pMapRegion must either be null, or cover the entire subresource.
+ /// In D3D11 and Vulkan backends, dynamic textures are no different from non-dynamic textures, and mapping
+ /// with MAP_FLAG_DISCARD has exactly the same behavior
+ virtual void Map( IDeviceContext* pContext,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ MAP_TYPE MapType,
+ Uint32 MapFlags,
+ const Box* pMapRegion,
+ MappedTextureSubresource& MappedData ) = 0;
+
+ /// Unmap the textute
+ virtual void Unmap(IDeviceContext *pContext, Uint32 MipLevel, Uint32 ArraySlice) = 0;
/// Returns native texture handle specific to the underlying graphics API
diff --git a/Graphics/GraphicsEngine/src/Texture.cpp b/Graphics/GraphicsEngine/src/Texture.cpp
index 76741d48..3411ee20 100644
--- a/Graphics/GraphicsEngine/src/Texture.cpp
+++ b/Graphics/GraphicsEngine/src/Texture.cpp
@@ -248,39 +248,31 @@ void VliadateCopyTextureDataParams( const TextureDesc &SrcTexDesc, Uint32 SrcMip
ValidateTextureRegion(DstTexDesc, DstMipLevel, DstSlice, DstBox);
}
+void ValidateMapTextureParams(const TextureDesc& TexDesc,
+ Uint32 MipLevel,
+ Uint32 ArraySlice,
+ MAP_TYPE MapType,
+ Uint32 MapFlags,
+ const Box* pMapRegion)
+{
+ VERIFY_TEX_PARAMS( MipLevel < TexDesc.MipLevels, "Mip level (", MipLevel, ") is out of allowed range [0, ", TexDesc.MipLevels-1, "]" );
+ if (TexDesc.Type == RESOURCE_DIM_TEX_1D_ARRAY ||
+ TexDesc.Type == RESOURCE_DIM_TEX_2D_ARRAY ||
+ TexDesc.Type == RESOURCE_DIM_TEX_CUBE ||
+ TexDesc.Type == RESOURCE_DIM_TEX_CUBE_ARRAY)
+ {
+ VERIFY_TEX_PARAMS( ArraySlice < TexDesc.ArraySize, "Array slice (", ArraySlice, ") is out of range [0,", TexDesc.ArraySize-1, "]" );
+ }
+ else
+ {
+ VERIFY_TEX_PARAMS( ArraySlice == 0, "Array slice (", ArraySlice, ") must be 0 for non-array textures" );
+ }
-//void CTexture :: Map(MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)
-//{
- //switch(MapType)
- //{
- // case MAP_READ:
- // VERIFY( "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read from" && m_Desc.Usage == USAGE_CPU_ACCESSIBLE);
- // VERIFY( "Buffer being mapped for reading was not created with CPU_ACCESS_READ flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_READ));
- // break;
-
- // case MAP_WRITE:
- // VERIFY( "Only buffers with usage USAGE_CPU_ACCESSIBLE can be written to" && m_Desc.Usage == USAGE_CPU_ACCESSIBLE );
- // VERIFY( "Buffer being mapped for writing was not created with CPU_ACCESS_WRITE flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE));
- // break;
-
- // case MAP_READ_WRITE:
- // VERIFY( "Only buffers with usage USAGE_CPU_ACCESSIBLE can be read and written" && m_Desc.Usage == USAGE_CPU_ACCESSIBLE );
- // VERIFY( "Buffer being mapped for reading & writing was not created with CPU_ACCESS_WRITE flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE));
- // VERIFY( "Buffer being mapped for reading & writing was not created with CPU_ACCESS_READ flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_READ));
- // break;
-
- // case MAP_WRITE_DISCARD:
- // VERIFY( "Only dynamic buffers can be mapped with write discard flag" && m_Desc.Usage == USAGE_DYNAMIC );
- // VERIFY( "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE) );
- // break;
-
- // case MAP_WRITE_NO_OVERWRITE:
- // VERIFY( "Only dynamic buffers can be mapped with write no overwrite flag" && m_Desc.Usage == USAGE_DYNAMIC );
- // VERIFY( "Dynamic buffer must be created with CPU_ACCESS_WRITE flag" && (m_Desc.CPUAccessFlags & CPU_ACCESS_WRITE) );
- // break;
+ if(pMapRegion != nullptr)
+ {
+ ValidateTextureRegion(TexDesc, MipLevel, ArraySlice, *pMapRegion);
+ }
- // default: VERIFY("Unknown map type" && false);
- //}
-//}
+}
} \ No newline at end of file