summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-04-13 02:34:18 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-04-13 02:34:18 +0000
commit321dfe299cd3b15bd0216113068f13dfa4b99cf0 (patch)
treefcbd6d410bdc1bb5b659471350dddf1e71e615ce /Graphics/GraphicsEngineVulkan
parentOptimized memory layout of ObjectBase<> (reduced size by 40 bytes on msvc x64) (diff)
downloadDiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.tar.gz
DiligentCore-321dfe299cd3b15bd0216113068f13dfa4b99cf0.zip
Updated ALLOCATE macros to make it more convenient
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/GenerateMipsVkHelper.cpp12
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp6
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp9
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp3
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp3
9 files changed, 18 insertions, 23 deletions
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<VkSampler*>(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<std::shared_ptr<const SPIRVShaderResources>, MaxShadersInPipeline> ShaderResources;
std::array<std::vector<uint32_t>, 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<ShaderResourceLayoutVk*>(pResLayoutRawMem);
- m_StaticResCaches = reinterpret_cast<ShaderResourceCacheVk*>(pStaticResCacheRawMem);
- m_StaticVarsMgrs = reinterpret_cast<ShaderVariableManagerVk*>(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<ShaderVariableManagerVk*>(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<DescriptorSet*>(m_pMemory);
auto* pCurrResPtr = reinterpret_cast<Resource*>(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<const SPIRVShaderRes
if (MemSize == 0)
return;
- auto* pRawMem = ALLOCATE(Allocator, "Raw memory buffer for shader resource layout resources", MemSize);
+ auto* pRawMem = ALLOCATE_RAW(Allocator, "Raw memory buffer for shader resource layout resources", MemSize);
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void> >(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<ShaderVariableVkImpl*>(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<SPIRVShaderResources>(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<TextureViewVkImpl::MipLevelViewAutoPtrType*>(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)