From d359125adafd13e80d79267e742a5f599f6fc390 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 13 Nov 2020 14:22:50 -0800 Subject: Added comparison operators for LayoutElement and InputLayoutDesc; updated texture test to support Metal. --- Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp index 8d1c187d..de95de16 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.hpp @@ -127,6 +127,8 @@ private: Uint32 m_DynamicOffsetAlignment = 0; VkDeviceSize m_BufferMemoryAlignedOffset = 0; + // TODO (assiduous): improve cache performance, move dynamic allocations to + // device context. std::vector> m_DynamicAllocations; VulkanUtilities::BufferWrapper m_VulkanBuffer; -- cgit v1.2.3 From 88869c4a9145a6964e819617e1f13f1d7798d00b Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 16 Nov 2020 20:54:00 -0800 Subject: Moved GetBufferToTextureCopyInfo to GraphicsAccessories --- .../include/DeviceContextVkImpl.hpp | 14 ---- .../src/DeviceContextVkImpl.cpp | 77 +++------------------- 2 files changed, 10 insertions(+), 81 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 9976d014..03a6603c 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -387,20 +387,6 @@ private: inline void DisposeVkCmdBuffer(Uint32 CmdQueue, VkCommandBuffer vkCmdBuff, Uint64 FenceValue); inline void DisposeCurrentCmdBuffer(Uint32 CmdQueue, Uint64 FenceValue); - struct BufferToTextureCopyInfo - { - Uint32 RowSize = 0; - Uint32 Stride = 0; - Uint32 StrideInTexels = 0; - Uint32 DepthStride = 0; - Uint32 MemorySize = 0; - Uint32 RowCount = 0; - Box Region; - }; - BufferToTextureCopyInfo GetBufferToTextureCopyInfo(const TextureDesc& TexDesc, - Uint32 MipLevel, - const Box& Region) const; - void CopyBufferToTexture(VkBuffer vkSrcBuffer, Uint32 SrcBufferOffset, Uint32 SrcBufferRowStrideInTexels, diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index c8b231c2..f2b70ff7 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -1721,64 +1721,6 @@ void DeviceContextVkImpl::CopyTextureRegion(TextureVkImpl* pSrcT ++m_State.NumCommands; } -DeviceContextVkImpl::BufferToTextureCopyInfo DeviceContextVkImpl::GetBufferToTextureCopyInfo( - const TextureDesc& TexDesc, - Uint32 MipLevel, - const Box& Region) const -{ - BufferToTextureCopyInfo CopyInfo; - const auto& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format); - VERIFY_EXPR(Region.MaxX > Region.MinX && Region.MaxY > Region.MinY && Region.MaxZ > Region.MinZ); - auto UpdateRegionWidth = Region.MaxX - Region.MinX; - auto UpdateRegionHeight = Region.MaxY - Region.MinY; - auto UpdateRegionDepth = Region.MaxZ - Region.MinZ; - if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) - { - // Align update region size by the block size. This is only necessary when updating - // coarse mip levels. Otherwise UpdateRegionWidth/Height should be multiples of block size - VERIFY_EXPR((FmtAttribs.BlockWidth & (FmtAttribs.BlockWidth - 1)) == 0); - VERIFY_EXPR((FmtAttribs.BlockHeight & (FmtAttribs.BlockHeight - 1)) == 0); - const auto BlockAlignedRegionWidth = (UpdateRegionWidth + (FmtAttribs.BlockWidth - 1)) & ~(FmtAttribs.BlockWidth - 1); - const auto BlockAlignedRegionHeight = (UpdateRegionHeight + (FmtAttribs.BlockHeight - 1)) & ~(FmtAttribs.BlockHeight - 1); - CopyInfo.RowSize = BlockAlignedRegionWidth / Uint32{FmtAttribs.BlockWidth} * Uint32{FmtAttribs.ComponentSize}; - CopyInfo.RowCount = BlockAlignedRegionHeight / FmtAttribs.BlockHeight; - - // (imageExtent.width + imageOffset.x) must be less than or equal to the image subresource width, and - // (imageExtent.height + imageOffset.y) must be less than or equal to the image subresource height (18.4), - // so we need to clamp UpdateRegionWidth and Height - const Uint32 MipWidth = std::max(TexDesc.Width >> MipLevel, 1u); - const Uint32 MipHeight = std::max(TexDesc.Height >> MipLevel, 1u); - VERIFY_EXPR(MipWidth > Region.MinX); - UpdateRegionWidth = std::min(UpdateRegionWidth, MipWidth - Region.MinX); - VERIFY_EXPR(MipHeight > Region.MinY); - UpdateRegionHeight = std::min(UpdateRegionHeight, MipHeight - Region.MinY); - } - else - { - CopyInfo.RowSize = UpdateRegionWidth * Uint32{FmtAttribs.ComponentSize} * Uint32{FmtAttribs.NumComponents}; - CopyInfo.RowCount = UpdateRegionHeight; - } - - const auto& DeviceLimits = m_pDevice->GetPhysicalDevice().GetProperties().limits; - CopyInfo.Stride = Align(CopyInfo.RowSize, static_cast(DeviceLimits.optimalBufferCopyRowPitchAlignment)); - if (FmtAttribs.ComponentType == COMPONENT_TYPE_COMPRESSED) - { - // If the calling command's VkImage parameter is a compressed image, - // bufferRowLength must be a multiple of the compressed texel block width - // In texels (not even in compressed blocks!) - CopyInfo.StrideInTexels = CopyInfo.Stride / Uint32{FmtAttribs.ComponentSize} * Uint32{FmtAttribs.BlockWidth}; - } - else - { - CopyInfo.StrideInTexels = CopyInfo.Stride / (Uint32{FmtAttribs.ComponentSize} * Uint32{FmtAttribs.NumComponents}); - } - CopyInfo.DepthStride = CopyInfo.RowCount * CopyInfo.Stride; - CopyInfo.MemorySize = UpdateRegionDepth * CopyInfo.DepthStride; - CopyInfo.Region = Region; - return CopyInfo; -} - - void DeviceContextVkImpl::UpdateTextureRegion(const void* pSrcData, Uint32 SrcStride, Uint32 SrcDepthStride, @@ -1790,11 +1732,12 @@ void DeviceContextVkImpl::UpdateTextureRegion(const void* pSr { const auto& TexDesc = TextureVk.GetDesc(); VERIFY(TexDesc.SampleCount == 1, "Only single-sample textures can be updated with vkCmdCopyBufferToImage()"); - auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, DstBox); - const auto UpdateRegionDepth = CopyInfo.Region.MaxZ - CopyInfo.Region.MinZ; + + const auto& DeviceLimits = m_pDevice->GetPhysicalDevice().GetProperties().limits; + const auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, DstBox, static_cast(DeviceLimits.optimalBufferCopyRowPitchAlignment)); + const auto UpdateRegionDepth = CopyInfo.Region.MaxZ - CopyInfo.Region.MinZ; // For UpdateTextureRegion(), use UploadHeap, not dynamic heap - const auto& DeviceLimits = m_pDevice->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 @@ -1827,7 +1770,7 @@ void DeviceContextVkImpl::UpdateTextureRegion(const void* pSr + DepthSlice * SrcDepthStride; auto* pDstPtr = reinterpret_cast(Allocation.CPUAddress) - + row * CopyInfo.Stride + + row * CopyInfo.RowStride + DepthSlice * CopyInfo.DepthStride; // clang-format on @@ -1836,7 +1779,7 @@ void DeviceContextVkImpl::UpdateTextureRegion(const void* pSr } CopyBufferToTexture(Allocation.vkBuffer, static_cast(Allocation.AlignedOffset), - CopyInfo.StrideInTexels, + CopyInfo.RowStrideInTexels, TextureVk, CopyInfo.Region, MipLevel, @@ -1987,7 +1930,7 @@ void DeviceContextVkImpl::MapTextureSubresource(ITexture* pTextu { if (MapType != MAP_WRITE) { - LOG_ERROR("Textures can currently only be mapped for writing in Vulkan backend"); + LOG_ERROR("Dynamic textures can be mapped for writing only in Vulkan backend"); MappedData = MappedTextureSubresource{}; return; } @@ -1995,8 +1938,8 @@ void DeviceContextVkImpl::MapTextureSubresource(ITexture* pTextu if ((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_NO_OVERWRITE)) != 0) LOG_INFO_MESSAGE_ONCE("Mapping textures with flags MAP_FLAG_DISCARD or MAP_FLAG_NO_OVERWRITE has no effect in Vulkan backend"); - auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, *pMapRegion); const auto& DeviceLimits = m_pDevice->GetPhysicalDevice().GetProperties().limits; + const auto CopyInfo = GetBufferToTextureCopyInfo(TexDesc, MipLevel, *pMapRegion, static_cast(DeviceLimits.optimalBufferCopyRowPitchAlignment)); // 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 @@ -2008,7 +1951,7 @@ void DeviceContextVkImpl::MapTextureSubresource(ITexture* pTextu auto Allocation = AllocateDynamicSpace(CopyInfo.MemorySize, static_cast(Alignment)); MappedData.pData = reinterpret_cast(Allocation.pDynamicMemMgr->GetCPUAddress()) + Allocation.AlignedOffset; - MappedData.Stride = CopyInfo.Stride; + MappedData.Stride = CopyInfo.RowStride; MappedData.DepthStride = CopyInfo.DepthStride; auto it = m_MappedTextures.emplace(MappedTextureKey{&TextureVk, MipLevel, ArraySlice}, MappedTexture{CopyInfo, std::move(Allocation)}); @@ -2081,7 +2024,7 @@ void DeviceContextVkImpl::UnmapTextureSubresource(ITexture* pTexture, auto& MappedTex = UploadSpaceIt->second; CopyBufferToTexture(MappedTex.Allocation.pDynamicMemMgr->GetVkBuffer(), static_cast(MappedTex.Allocation.AlignedOffset), - MappedTex.CopyInfo.StrideInTexels, + MappedTex.CopyInfo.RowStrideInTexels, TextureVk, MappedTex.CopyInfo.Region, MipLevel, -- cgit v1.2.3