From 321dfe299cd3b15bd0216113068f13dfa4b99cf0 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 12 Apr 2019 19:34:18 -0700 Subject: Updated ALLOCATE macros to make it more convenient --- Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp | 12 ++++++------ Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp | 6 +++--- Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp | 9 +++------ .../GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp | 3 +-- Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp | 2 +- Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp | 2 +- Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp | 2 +- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 2 +- Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp | 3 +-- 9 files changed, 18 insertions(+), 23 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp index 58b2b122..3d53a03a 100644 --- a/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp +++ b/Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp @@ -297,8 +297,8 @@ namespace Diligent VERIFY_EXPR(ResourceStateToVkImageLayout(RESOURCE_STATE_SHADER_RESOURCE) == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Note that mip levels are relative to the view's most detailed mip - auto LowestMip = ViewDesc.NumMipLevels - 1; - for (uint32_t TopMip = 0; TopMip < LowestMip; ) + auto BottomMip = ViewDesc.NumMipLevels - 1; + for (uint32_t TopMip = 0; TopMip < BottomMip; ) { // In Vulkan all subresources of a view must be transitioned to the same layout, so // we can't bind the entire texture and have to bind single mip level at a time @@ -321,8 +321,8 @@ namespace Diligent // in the low bits. Zeros indicate we can divide by two without truncating. uint32_t AdditionalMips = PlatformMisc::GetLSB(DstWidth | DstHeight); uint32_t NumMips = 1 + (AdditionalMips > 3 ? 3 : AdditionalMips); - if (TopMip + NumMips > LowestMip) - NumMips = LowestMip - TopMip; + if (TopMip + NumMips > BottomMip) + NumMips = BottomMip - TopMip; // These are clamped to 1 after computing additional mips because clamped // dimensions should not limit us from downsampling multiple times. (E.g. @@ -356,12 +356,12 @@ namespace Diligent constexpr const Uint32 MaxMipsHandledByCS = 4; // Max number of mip levels processed by one CS shader invocation for (Uint32 u = 0; u < MaxMipsHandledByCS; ++u) { - auto* MipLevelUAV = TexView.GetMipLevelUAV(std::min(TopMip + u + 1, LowestMip)); + auto* MipLevelUAV = TexView.GetMipLevelUAV(std::min(TopMip + u + 1, BottomMip)); pOutMipVar[u]->Set(MipLevelUAV); } SubresRange.baseMipLevel = ViewDesc.MostDetailedMip + TopMip + 1; - SubresRange.levelCount = std::min(4u, LowestMip - TopMip); + SubresRange.levelCount = std::min(4u, BottomMip - TopMip); if (OriginalLayout != VK_IMAGE_LAYOUT_GENERAL) Ctx.TransitionImageLayout(*pTexVk, OriginalLayout, VK_IMAGE_LAYOUT_GENERAL, SubresRange); diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index d8383418..3ee16537 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -155,7 +155,7 @@ void PipelineLayout::DescriptorSetLayoutManager::DescriptorSetLayout::ReserveMem size_t RequiredMemory = GetMemorySize(NumBindings); if (RequiredMemory > ReservedMemory) { - void *pNewBindings = ALLOCATE(MemAllocator, "Memory buffer for descriptor set layout bindings", RequiredMemory); + void* pNewBindings = ALLOCATE_RAW(MemAllocator, "Memory buffer for descriptor set layout bindings", RequiredMemory); if (pBindings != nullptr) { memcpy(pNewBindings, pBindings, sizeof(VkDescriptorSetLayoutBinding) * NumLayoutBindings); @@ -341,8 +341,8 @@ void PipelineLayout::DescriptorSetLayoutManager::AllocateResourceSlot(const SPIR // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and // descriptorCount is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a valid pointer // to an array of descriptorCount valid VkSampler handles (13.2.1) - auto *pImmutableSamplers = reinterpret_cast(ALLOCATE(m_MemAllocator, "Memory buffer for immutable samplers", sizeof(VkSampler) * VkBinding.descriptorCount)); - for(uint32_t s=0; s < VkBinding.descriptorCount; ++s) + auto* pImmutableSamplers = ALLOCATE(m_MemAllocator, "Memory buffer for immutable samplers", VkSampler, VkBinding.descriptorCount); + for (uint32_t s=0; s < VkBinding.descriptorCount; ++s) pImmutableSamplers[s] = vkImmutableSampler; VkBinding.pImmutableSamplers = pImmutableSamplers; } diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index b4be5e89..43e99202 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -156,12 +156,9 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters* pRefCounters auto& ShaderResLayoutAllocator = GetRawAllocator(); std::array, MaxShadersInPipeline> ShaderResources; std::array, MaxShadersInPipeline> ShaderSPIRVs; - auto* pResLayoutRawMem = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutVk", sizeof(ShaderResourceLayoutVk) * m_NumShaders * 2); - auto* pStaticResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheVk", sizeof(ShaderResourceCacheVk) * m_NumShaders); - auto* pStaticVarMgrRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", sizeof(ShaderVariableManagerVk) * m_NumShaders); - m_ShaderResourceLayouts = reinterpret_cast(pResLayoutRawMem); - m_StaticResCaches = reinterpret_cast(pStaticResCacheRawMem); - m_StaticVarsMgrs = reinterpret_cast(pStaticVarMgrRawMem); + m_ShaderResourceLayouts = ALLOCATE(ShaderResLayoutAllocator, "Raw memory for ShaderResourceLayoutVk", ShaderResourceLayoutVk, m_NumShaders * 2); + m_StaticResCaches = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheVk", ShaderResourceCacheVk, m_NumShaders); + m_StaticVarsMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", ShaderVariableManagerVk, m_NumShaders); for (Uint32 s=0; s < m_NumShaders; ++s) { new (m_ShaderResourceLayouts + s) ShaderResourceLayoutVk(LogicalDevice); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 30e2ba8f..bdb85b8e 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -43,8 +43,7 @@ ShaderResourceBindingVkImpl::ShaderResourceBindingVkImpl(IReferenceCounters* pRe auto& ResourceCacheDataAllocator = pPSO->GetSRBMemoryAllocator().GetResourceCacheDataAllocator(0); pPSO->GetPipelineLayout().InitResourceCache(pRenderDeviceVkImpl, m_ShaderResourceCache, ResourceCacheDataAllocator, pPSO->GetDesc().Name); - auto* pVarMgrsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", m_NumShaders * sizeof(ShaderVariableManagerVk)); - m_pShaderVarMgrs = reinterpret_cast(pVarMgrsRawMem); + m_pShaderVarMgrs = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderVariableManagerVk", ShaderVariableManagerVk, m_NumShaders); for (Uint32 s = 0; s < m_NumShaders; ++s) { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 1d060871..4aad41d9 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -69,7 +69,7 @@ void ShaderResourceCacheVk::InitializeSets(IMemoryAllocator& MemAllocator, Uint3 #endif if (MemorySize > 0) { - m_pMemory = ALLOCATE( *m_pAllocator, "Memory for shader resource cache data", MemorySize); + m_pMemory = ALLOCATE_RAW( *m_pAllocator, "Memory for shader resource cache data", MemorySize); auto* pSets = reinterpret_cast(m_pMemory); auto* pCurrResPtr = reinterpret_cast(pSets + m_NumSets); for (Uint32 t = 0; t < NumSets; ++t) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index fdf3f830..8486d586 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -155,7 +155,7 @@ void ShaderResourceLayoutVk::AllocateMemory(std::shared_ptr >(pRawMem, Allocator); for (Uint32 s=0; s < m_NumImmutableSamplers; ++s) { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp index 9d6bbf96..50bde9da 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp @@ -80,7 +80,7 @@ ShaderVariableManagerVk::ShaderVariableManagerVk(IObject& if(m_NumVariables == 0) return; - auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader variables", MemSize); + auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader variables", MemSize); m_pVariables = reinterpret_cast(pRawMem); Uint32 VarInd = 0; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index fe712cc8..1f1a2053 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -83,7 +83,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, // Load shader resources auto& Allocator = GetRawAllocator(); - auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); + auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", SPIRVShaderResources, 1); bool IsHLSLVertexShader = CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL && m_Desc.ShaderType == SHADER_TYPE_VERTEX; auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr, IsHLSLVertexShader, m_EntryPoint); m_pShaderResources.reset(pResources, STDDeleterRawMem(Allocator)); diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 4d05b81f..eaf88459 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -543,8 +543,7 @@ void TextureVkImpl::CreateViewInternal(const TextureViewDesc& ViewDesc, ITexture m_bCSBasedMipGenerationSupported && CheckCSBasedMipGenerationSupport(TexFormatToVkFormat(pViewVk->GetDesc().Format))) { - auto* pMipLevelViewsRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for mip level views", sizeof(TextureViewVkImpl::MipLevelViewAutoPtrType) * UpdatedViewDesc.NumMipLevels * 2); - auto* pMipLevelViews = reinterpret_cast(pMipLevelViewsRawMem); + auto* pMipLevelViews = ALLOCATE(GetRawAllocator(), "Raw memory for mip level views", TextureViewVkImpl::MipLevelViewAutoPtrType, UpdatedViewDesc.NumMipLevels * 2); for (Uint32 MipLevel = 0; MipLevel < UpdatedViewDesc.NumMipLevels; ++MipLevel) { auto CreateMipLevelView = [&](TEXTURE_VIEW_TYPE ViewType, Uint32 MipLevel, TextureViewVkImpl::MipLevelViewAutoPtrType* ppMipLevelView) -- cgit v1.2.3