diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-11-25 04:31:42 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-11-25 04:31:42 +0000 |
| commit | 17b24246757390d29be93ce3447745e7b4936f5a (patch) | |
| tree | 7c0ad81014bd2c61debf7f3b4c89c445eab73beb /Graphics/GraphicsEngineVulkan | |
| parent | Updated parameter order of IDeviceContext::CopyBuffer (diff) | |
| download | DiligentCore-17b24246757390d29be93ce3447745e7b4936f5a.tar.gz DiligentCore-17b24246757390d29be93ce3447745e7b4936f5a.zip | |
Renamed/moved ITexture::Map() to IDeviceContext::MapTextureSubresource()
Renamed/moved ITexture::Unmap() to IDeviceContext::UnmapTextureSubresource()
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
4 files changed, 58 insertions, 85 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index e4ab87d2..2f743864 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -112,6 +112,17 @@ public: Uint32 DstY, Uint32 DstZ)override final; + virtual void MapTextureSubresource( ITexture* pTexture, + Uint32 MipLevel, + Uint32 ArraySlice, + MAP_TYPE MapType, + Uint32 MapFlags, + const Box* pMapRegion, + MappedTextureSubresource& MappedData )override final; + + + virtual void UnmapTextureSubresource(ITexture* pTexture, Uint32 MipLevel, Uint32 ArraySlice)override final; + virtual void FinishCommandList(class ICommandList** ppCommandList)override final; virtual void ExecuteCommandList(class ICommandList* pCommandList)override final; @@ -157,30 +168,17 @@ public: } void UpdateBufferRegion(BufferVkImpl* pBuffVk, Uint64 DstOffset, Uint64 NumBytes, VkBuffer vkSrcBuffer, Uint64 SrcOffset); - void UpdateBufferRegion(BufferVkImpl* pBuffVk, const void* pData, Uint64 DstOffset, Uint64 NumBytes); void CopyBufferRegion(BufferVkImpl* pSrcBuffVk, BufferVkImpl* pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes); void CopyTextureRegion(TextureVkImpl* pSrcTexture, TextureVkImpl* pDstTexture, const VkImageCopy &CopyRegion); - void UpdateTextureRegion(const void* pSrcData, - Uint32 SrcStride, - Uint32 SrcDepthStride, - TextureVkImpl& TextureVk, - Uint32 MipLevel, - Uint32 Slice, - const Box& DstBox); - - void MapTexture(TextureVkImpl& TextureVk, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - Uint32 MapFlags, - const Box& MapRegion, - MappedTextureSubresource& MappedData); - - void UnmapTexture(TextureVkImpl& TextureVk, - Uint32 MipLevel, - Uint32 ArraySlice); + void UpdateTextureRegion(const void* pSrcData, + Uint32 SrcStride, + Uint32 SrcDepthStride, + TextureVkImpl& TextureVk, + Uint32 MipLevel, + Uint32 Slice, + const Box& DstBox); void GenerateMips(class TextureViewVkImpl& TexView) { diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h index 7bf6c4db..bfddb2cb 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h @@ -63,16 +63,6 @@ public: virtual void QueryInterface( const Diligent::INTERFACE_ID& IID, IObject** ppInterface )override; - //virtual void CopyData(CTexture* pSrcTexture, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size); - virtual void Map(IDeviceContext* pContext, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - Uint32 MapFlags, - const Box* pMapRegion, - MappedTextureSubresource& MappedData)override; - virtual void Unmap(IDeviceContext* pContext, Uint32 MipLevel, Uint32 ArraySlice)override; - virtual VkImage GetVkImage()const override final{ return m_VulkanImage; } virtual void* GetNativeHandle()override final { diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index d314d8db..6b2f4e48 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1458,7 +1458,7 @@ namespace Diligent const auto& DeviceLimits = m_pDevice.RawPtr<const RenderDeviceVkImpl>()->GetPhysicalDevice().GetProperties().limits; // Source buffer offset must be multiple of 4 (18.4) auto BufferOffsetAlignment = std::max(DeviceLimits.optimalBufferCopyOffsetAlignment, VkDeviceSize{4}); - // If the calling command�s VkImage parameter is a compressed image, bufferOffset must be a multiple of + // If the calling command's VkImage parameter is a compressed image, bufferOffset must be a multiple of // the compressed texel block size in bytes (18.4) const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) @@ -1579,20 +1579,44 @@ namespace Diligent &CopyRegion); } - void DeviceContextVkImpl::MapTexture( TextureVkImpl& TextureVk, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - Uint32 MapFlags, - const Box& MapRegion, - MappedTextureSubresource& MappedData ) + void DeviceContextVkImpl::MapTextureSubresource( ITexture* pTexture, + Uint32 MipLevel, + Uint32 ArraySlice, + MAP_TYPE MapType, + Uint32 MapFlags, + const Box* pMapRegion, + MappedTextureSubresource& MappedData ) { + TDeviceContextBase::MapTextureSubresource(pTexture, MipLevel, ArraySlice, MapType, MapFlags, pMapRegion, MappedData); + + TextureVkImpl& TextureVk = *ValidatedCast<TextureVkImpl>(pTexture); const auto& TexDesc = TextureVk.GetDesc(); - auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, MapRegion); + + if (MapType != MAP_WRITE) + { + LOG_ERROR("Textures can currently only be mapped for writing in Vulkan backend"); + MappedData = MappedTextureSubresource{}; + return; + } + + if ((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0) + LOG_WARNING_MESSAGE_ONCE("Mapping textures with flags MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE has no effect in Vulkan backend"); + + Box FullExtentBox; + if (pMapRegion == nullptr) + { + FullExtentBox.MaxX = std::max(TexDesc.Width >> MipLevel, 1u); + FullExtentBox.MaxY = std::max(TexDesc.Height >> MipLevel, 1u); + if (TexDesc.Type == RESOURCE_DIM_TEX_3D) + FullExtentBox.MaxZ = std::max(TexDesc.Depth >> MipLevel, 1u); + pMapRegion = &FullExtentBox; + } + + auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, *pMapRegion); const auto& DeviceLimits = m_pDevice.RawPtr<RenderDeviceVkImpl>()->GetPhysicalDevice().GetProperties().limits; // Source buffer offset must be multiple of 4 (18.4) auto Alignment = std::max(DeviceLimits.optimalBufferCopyOffsetAlignment, VkDeviceSize{4}); - // If the calling command�s VkImage parameter is a compressed image, bufferOffset must be a multiple of + // If the calling command's VkImage parameter is a compressed image, bufferOffset must be a multiple of // the compressed texel block size in bytes (18.4) const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) @@ -1610,10 +1634,13 @@ namespace Diligent LOG_ERROR_MESSAGE("Mip level ", MipLevel, ", slice ", ArraySlice, " of texture '", TexDesc.Name, "' has already been mapped"); } - void DeviceContextVkImpl::UnmapTexture( TextureVkImpl& TextureVk, - Uint32 MipLevel, - Uint32 ArraySlice) + void DeviceContextVkImpl::UnmapTextureSubresource(ITexture* pTexture, + Uint32 MipLevel, + Uint32 ArraySlice) { + TDeviceContextBase::UnmapTextureSubresource( pTexture, MipLevel, ArraySlice); + + TextureVkImpl& TextureVk = *ValidatedCast<TextureVkImpl>(pTexture); const auto& TexDesc = TextureVk.GetDesc(); auto UploadSpaceIt = m_MappedTextures.find(MappedTextureKey{&TextureVk, MipLevel, ArraySlice}); if(UploadSpaceIt != m_MappedTextures.end()) diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index f1169c04..7f04d036 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -494,48 +494,6 @@ TextureVkImpl :: ~TextureVkImpl() m_pDevice->SafeReleaseDeviceObject(std::move(m_MemoryAllocation), m_Desc.CommandQueueMask); } -void TextureVkImpl :: Map(IDeviceContext* pContext, - Uint32 MipLevel, - Uint32 ArraySlice, - MAP_TYPE MapType, - Uint32 MapFlags, - const Box* pMapRegion, - MappedTextureSubresource& MappedData) -{ - TTextureBase::Map(pContext, MipLevel, ArraySlice, MapType, MapFlags, pMapRegion, MappedData); - - auto* pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pContext); - MappedData = MappedTextureSubresource{}; - - Box FullExtentBox; - if (pMapRegion == nullptr) - { - FullExtentBox.MaxX = std::max(m_Desc.Width >> MipLevel, 1u); - FullExtentBox.MaxY = std::max(m_Desc.Height >> MipLevel, 1u); - if (m_Desc.Type == RESOURCE_DIM_TEX_3D) - FullExtentBox.MaxZ = std::max(m_Desc.Depth >> MipLevel, 1u); - pMapRegion = &FullExtentBox; - } - - if(MapType == MAP_WRITE) - { - if( (MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0 ) - LOG_WARNING_MESSAGE_ONCE("Mapping textures with flags MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE has no effect in Vulkan backend"); - pDeviceContextVk->MapTexture(*this, MipLevel, ArraySlice, MapType, MapFlags, *pMapRegion, MappedData); - } - else - { - LOG_ERROR("Textures can currently only be mapped for writing in D3D12 backend"); - } -} - -void TextureVkImpl::Unmap(IDeviceContext *pContext, Uint32 MipLevel, Uint32 ArraySlice) -{ - TTextureBase::Unmap(pContext, MipLevel, ArraySlice); - auto* pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pContext); - pDeviceContextVk->UnmapTexture(*this, MipLevel, ArraySlice); -} - VulkanUtilities::ImageViewWrapper TextureVkImpl::CreateImageView(TextureViewDesc& ViewDesc) { VERIFY(ViewDesc.ViewType == TEXTURE_VIEW_SHADER_RESOURCE || |
