From 5967fc38d27ceb190234aa804e3fb37e64e7734d Mon Sep 17 00:00:00 2001 From: dzhdan Date: Sun, 21 Jul 2024 13:42:20 +0800 Subject: [PATCH] v1.137: HIGHLIGHTS: - bug fixes and improvements - baby steps towards better memory allocation & binding DETAILS: - updated version! - D3D12/VK: reduced code entropy around "MemoryType" - D3D12: fixed validation error: some heap flags can't be passed into "CreateCommitedResource" (STATE_CREATION ERROR #640) - D3D12: if D3D12_RESOURCE_HEAP_TIER_2 is available, prefer to merge all resources into one heap (matches VK behavior) - updated AMDAGS --- External/amdags | 2 +- Include/NRI.h | 4 +- Resources/Version.h | 2 +- Source/D3D12/AccelerationStructureD3D12.cpp | 5 +- Source/D3D12/BufferD3D12.cpp | 15 +++-- Source/D3D12/DeviceD3D12.cpp | 62 +++++++++++++++++---- Source/D3D12/DeviceD3D12.h | 6 +- Source/D3D12/MemoryD3D12.cpp | 6 +- Source/D3D12/SharedD3D12.cpp | 44 --------------- Source/D3D12/SharedD3D12.h | 5 -- Source/D3D12/TextureD3D12.cpp | 9 ++- Source/VK/BufferVK.cpp | 25 +++++---- Source/VK/DeviceVK.cpp | 34 ++++++----- Source/VK/MemoryVK.cpp | 50 ++++++++--------- Source/VK/MemoryVK.h | 2 +- Source/VK/SharedVK.h | 12 ++-- Source/VK/TextureVK.cpp | 25 +++++---- 17 files changed, 154 insertions(+), 154 deletions(-) diff --git a/External/amdags b/External/amdags index f686755b..f4e655ed 160000 --- a/External/amdags +++ b/External/amdags @@ -1 +1 @@ -Subproject commit f686755b60a18521eb2fe7b40d7b3e35125cf151 +Subproject commit f4e655ed363a91a7e0af35f5aecffa175c79a748 diff --git a/Include/NRI.h b/Include/NRI.h index 64981013..4c8ac70e 100644 --- a/Include/NRI.h +++ b/Include/NRI.h @@ -25,8 +25,8 @@ Non-goals: #include #define NRI_VERSION_MAJOR 1 -#define NRI_VERSION_MINOR 135 -#define NRI_VERSION_DATE "27 May 2024" +#define NRI_VERSION_MINOR 137 +#define NRI_VERSION_DATE "21 July 2024" #ifdef _WIN32 #define NRI_CALL __fastcall diff --git a/Resources/Version.h b/Resources/Version.h index 1131a277..d73889ed 100644 --- a/Resources/Version.h +++ b/Resources/Version.h @@ -4,7 +4,7 @@ #define STR(x) STR_HELPER(x) #define VERSION_MAJOR 1 -#define VERSION_MINOR 135 +#define VERSION_MINOR 137 #define VERSION_BUILD 0 #define VERSION_REVISION 0 diff --git a/Source/D3D12/AccelerationStructureD3D12.cpp b/Source/D3D12/AccelerationStructureD3D12.cpp index 09c4b90e..3db54fec 100644 --- a/Source/D3D12/AccelerationStructureD3D12.cpp +++ b/Source/D3D12/AccelerationStructureD3D12.cpp @@ -50,10 +50,7 @@ Result AccelerationStructureD3D12::Create(const AccelerationStructureDesc& accel } void AccelerationStructureD3D12::GetMemoryInfo(MemoryDesc& memoryDesc) const { - memoryDesc.size = m_PrebuildInfo.ResultDataMaxSizeInBytes; - memoryDesc.alignment = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT; - memoryDesc.type = GetMemoryType(D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS); - memoryDesc.mustBeDedicated = false; + m_Device.GetMemoryInfoForAccelerationStructure(m_PrebuildInfo.ResultDataMaxSizeInBytes, memoryDesc); } uint64_t AccelerationStructureD3D12::GetUpdateScratchBufferSize() const { diff --git a/Source/D3D12/BufferD3D12.cpp b/Source/D3D12/BufferD3D12.cpp index f9691e61..17843d5c 100644 --- a/Source/D3D12/BufferD3D12.cpp +++ b/Source/D3D12/BufferD3D12.cpp @@ -37,14 +37,18 @@ Result BufferD3D12::Create(const BufferD3D12Desc& bufferDesc) { } Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool isAccelerationStructureBuffer) { - MaybeUnused(isAccelerationStructureBuffer); - const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc(); - // Buffer was already created externally if (m_Buffer) return Result::SUCCESS; + const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc(); + + // STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS + D3D12_HEAP_FLAGS heapFlagsFixed = heapDesc.Flags & ~(D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS); + #ifdef NRI_USE_AGILITY_SDK + MaybeUnused(isAccelerationStructureBuffer); + if (m_Device.GetVersion() >= 10) { D3D12_RESOURCE_DESC1 desc1 = {}; GetResourceDesc((D3D12_RESOURCE_DESC*)&desc1, m_Desc); @@ -54,7 +58,7 @@ Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool if (memory->RequiresDedicatedAllocation()) { HRESULT hr = m_Device->CreateCommittedResource3( - &heapDesc.Properties, heapDesc.Flags, &desc1, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, nullptr, castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Buffer)); + &heapDesc.Properties, heapFlagsFixed, &desc1, D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, nullptr, castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Buffer)); RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device10::CreateCommittedResource3()"); } else { HRESULT hr = @@ -72,11 +76,12 @@ Result BufferD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset, bool initialState |= D3D12_RESOURCE_STATE_GENERIC_READ; else if (heapDesc.Properties.Type == D3D12_HEAP_TYPE_READBACK) initialState |= D3D12_RESOURCE_STATE_COPY_DEST; + if (isAccelerationStructureBuffer) initialState |= D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE; if (memory->RequiresDedicatedAllocation()) { - HRESULT hr = m_Device->CreateCommittedResource(&heapDesc.Properties, heapDesc.Flags, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer)); + HRESULT hr = m_Device->CreateCommittedResource(&heapDesc.Properties, heapFlagsFixed, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer)); RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateCommittedResource()"); } else { HRESULT hr = m_Device->CreatePlacedResource(*memory, offset, &desc, initialState, nullptr, IID_PPV_ARGS(&m_Buffer)); diff --git a/Source/D3D12/DeviceD3D12.cpp b/Source/D3D12/DeviceD3D12.cpp index 52a7acd5..907b2f65 100644 --- a/Source/D3D12/DeviceD3D12.cpp +++ b/Source/D3D12/DeviceD3D12.cpp @@ -287,6 +287,7 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation) { hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)); if (FAILED(hr)) REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options) failed, result = 0x%08X!", hr); + m_IsResourceHeapTier2Supported = options.ResourceHeapTier == D3D12_RESOURCE_HEAP_TIER_2; D3D12_FEATURE_DATA_D3D12_OPTIONS1 options1 = {}; hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &options1, sizeof(options1)); @@ -650,23 +651,66 @@ DescriptorPointerCPU DeviceD3D12::GetDescriptorPointerCPU(const DescriptorHandle return descriptorPointer; } +constexpr std::array HEAP_TYPES = { + D3D12_HEAP_TYPE_DEFAULT, // DEVICE +#ifdef NRI_USE_AGILITY_SDK + // Prerequisite: D3D12_FEATURE_D3D12_OPTIONS16 + D3D12_HEAP_TYPE_GPU_UPLOAD, // DEVICE_UPLOAD +#else + D3D12_HEAP_TYPE_UPLOAD, // DEVICE_UPLOAD (silent fallback to HOST_UPLOAD) +#endif + D3D12_HEAP_TYPE_UPLOAD, // HOST_UPLOAD + D3D12_HEAP_TYPE_READBACK, // HOST_READBACK +}; + +static inline MemoryType ConstructMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags) { + return ((uint32_t)heapFlags) | ((uint32_t)heapType << 16); +} + void DeviceD3D12::GetMemoryInfo(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc, MemoryDesc& memoryDesc) const { if (memoryLocation == MemoryLocation::DEVICE_UPLOAD && m_Desc.deviceUploadHeapSize == 0) memoryLocation = MemoryLocation::HOST_UPLOAD; - memoryDesc.type = GetMemoryType(memoryLocation, resourceDesc); + D3D12_HEAP_TYPE heapType = HEAP_TYPES[(uint32_t)memoryLocation]; + D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; + + if (!m_IsResourceHeapTier2Supported) { + if (resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) + heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; + else if (resourceDesc.Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) + heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; + else + heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES; + } D3D12_RESOURCE_ALLOCATION_INFO resourceAllocationInfo = m_Device->GetResourceAllocationInfo(NRI_NODE_MASK, 1, &resourceDesc); + MemoryType memoryType = ConstructMemoryType(heapType, heapFlags); + memoryDesc.size = (uint64_t)resourceAllocationInfo.SizeInBytes; memoryDesc.alignment = (uint32_t)resourceAllocationInfo.Alignment; + memoryDesc.type = memoryType; + memoryDesc.mustBeDedicated = IsDedicated(memoryType); +} + +void DeviceD3D12::GetMemoryInfoForAccelerationStructure(uint64_t size, MemoryDesc& memoryDesc) const { + D3D12_HEAP_FLAGS heapFlags = m_IsResourceHeapTier2Supported ? D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES : D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; + + memoryDesc.size = size; + memoryDesc.alignment = D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BYTE_ALIGNMENT; + memoryDesc.type = ConstructMemoryType(D3D12_HEAP_TYPE_DEFAULT, heapFlags); + memoryDesc.mustBeDedicated = false; +} + +bool DeviceD3D12::IsDedicated(MemoryType memoryType) const { + D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(memoryType); + bool isRtDs = (heapFlags & D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) == D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; - memoryDesc.mustBeDedicated = RequiresDedicatedAllocation(memoryDesc.type); + return !m_IsResourceHeapTier2Supported && isRtDs; } ComPtr DeviceD3D12::CreateCommandSignature( - D3D12_INDIRECT_ARGUMENT_TYPE indirectArgumentType, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation) { - const bool isDrawArgument = - enableDrawParametersEmulation && (indirectArgumentType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW || indirectArgumentType == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED); + D3D12_INDIRECT_ARGUMENT_TYPE type, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation) { + const bool isDrawArgument = enableDrawParametersEmulation && (type == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW || type == D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED); D3D12_INDIRECT_ARGUMENT_DESC indirectArgumentDescs[2] = {}; if (isDrawArgument) { @@ -677,9 +721,9 @@ ComPtr DeviceD3D12::CreateCommandSignature( indirectArgumentDescs[0].Constant.DestOffsetIn32BitValues = 0; indirectArgumentDescs[0].Constant.Num32BitValuesToSet = 2; - indirectArgumentDescs[1].Type = indirectArgumentType; + indirectArgumentDescs[1].Type = type; } else - indirectArgumentDescs[0].Type = indirectArgumentType; + indirectArgumentDescs[0].Type = type; D3D12_COMMAND_SIGNATURE_DESC commandSignatureDesc = {}; commandSignatureDesc.NumArgumentDescs = isDrawArgument ? 2 : 1; @@ -738,10 +782,6 @@ ID3D12CommandSignature* DeviceD3D12::GetDispatchCommandSignature() const { return m_DispatchCommandSignature.GetInterface(); } -MemoryType DeviceD3D12::GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) const { - return ::GetMemoryType(memoryLocation, resourceDesc); -} - //================================================================================================================ // DeviceBase //================================================================================================================ diff --git a/Source/D3D12/DeviceD3D12.h b/Source/D3D12/DeviceD3D12.h index 573c292d..56a2be8c 100644 --- a/Source/D3D12/DeviceD3D12.h +++ b/Source/D3D12/DeviceD3D12.h @@ -65,6 +65,8 @@ struct DeviceD3D12 final : public DeviceBase { Result GetDescriptorHandle(D3D12_DESCRIPTOR_HEAP_TYPE type, DescriptorHandle& descriptorHandle); DescriptorPointerCPU GetDescriptorPointerCPU(const DescriptorHandle& descriptorHandle); void GetMemoryInfo(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc, MemoryDesc& memoryDesc) const; + void GetMemoryInfoForAccelerationStructure(uint64_t size, MemoryDesc& memoryDesc) const; + bool IsDedicated(MemoryType memoryType) const; ID3D12CommandSignature* GetDrawCommandSignature(uint32_t stride, ID3D12RootSignature* rootSignature); ID3D12CommandSignature* GetDrawIndexedCommandSignature(uint32_t stride, ID3D12RootSignature* rootSignature); @@ -149,9 +151,8 @@ struct DeviceD3D12 final : public DeviceBase { private: void FillDesc(bool enableDrawParametersEmulation); - MemoryType GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) const; ComPtr CreateCommandSignature( - D3D12_INDIRECT_ARGUMENT_TYPE indirectArgumentType, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation = false); + D3D12_INDIRECT_ARGUMENT_TYPE type, uint32_t stride, ID3D12RootSignature* rootSignature, bool enableDrawParametersEmulation = false); private: d3d12::Ext m_Ext = {}; // don't sort: destructor must be called last! @@ -169,6 +170,7 @@ struct DeviceD3D12 final : public DeviceBase { CoreInterface m_CoreInterface = {}; uint8_t m_Version = 0; bool m_IsWrapped = false; + bool m_IsResourceHeapTier2Supported = false; std::array m_FreeDescriptorLocks; Lock m_DescriptorHeapLock; Lock m_QueueLock; diff --git a/Source/D3D12/MemoryD3D12.cpp b/Source/D3D12/MemoryD3D12.cpp index 2d8e04cc..7466a83a 100644 --- a/Source/D3D12/MemoryD3D12.cpp +++ b/Source/D3D12/MemoryD3D12.cpp @@ -6,6 +6,10 @@ using namespace nri; +static inline D3D12_HEAP_TYPE GetHeapType(MemoryType memoryType) { + return (D3D12_HEAP_TYPE)(memoryType >> 16); +} + Result MemoryD3D12::Create(const MemoryType memoryType, uint64_t size) { D3D12_HEAP_DESC heapDesc = {}; heapDesc.SizeInBytes = size; @@ -17,7 +21,7 @@ Result MemoryD3D12::Create(const MemoryType memoryType, uint64_t size) { heapDesc.Alignment = 0; heapDesc.Flags = (size ? GetHeapFlags(memoryType) : D3D12_HEAP_FLAG_NONE) | D3D12_HEAP_FLAG_CREATE_NOT_ZEROED; - if (!::RequiresDedicatedAllocation(memoryType)) { + if (!m_Device.IsDedicated(memoryType)) { HRESULT hr = m_Device->CreateHeap(&heapDesc, IID_PPV_ARGS(&m_Heap)); RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateHeap()"); } diff --git a/Source/D3D12/SharedD3D12.cpp b/Source/D3D12/SharedD3D12.cpp index 206b4db3..54bfce4d 100644 --- a/Source/D3D12/SharedD3D12.cpp +++ b/Source/D3D12/SharedD3D12.cpp @@ -16,54 +16,10 @@ D3D12_COMMAND_LIST_TYPE nri::GetCommandListType(CommandQueueType commandQueueTyp return COMMAND_LIST_TYPES[(uint32_t)commandQueueType]; } -constexpr std::array HEAP_TYPES = { - D3D12_HEAP_TYPE_DEFAULT, // DEVICE -#ifdef NRI_USE_AGILITY_SDK - // Prerequisite: D3D12_FEATURE_D3D12_OPTIONS16 - D3D12_HEAP_TYPE_GPU_UPLOAD, // DEVICE_UPLOAD -#else - D3D12_HEAP_TYPE_UPLOAD, // DEVICE_UPLOAD (silent fallback to HOST_UPLOAD) -#endif - D3D12_HEAP_TYPE_UPLOAD, // HOST_UPLOAD - D3D12_HEAP_TYPE_READBACK, // HOST_READBACK -}; - -MemoryType nri::GetMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags) { - return ((uint32_t)heapFlags) | ((uint32_t)heapType << 16); -} - -MemoryType nri::GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc) { - D3D12_HEAP_TYPE heapType = HEAP_TYPES[(uint32_t)memoryLocation]; - D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAG_NONE; - - // Required for Tier 1 resource heaps https://msdn.microsoft.com/en-us/library/windows/desktop/dn986743(v=vs.85).aspx - if (resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) - heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS; - else if (resourceDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET || resourceDesc.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) - heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; - else - heapFlags = D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES; - - return GetMemoryType(heapType, heapFlags); -} - -D3D12_HEAP_TYPE nri::GetHeapType(MemoryType memoryType) { - return (D3D12_HEAP_TYPE)(memoryType >> 16); -} - D3D12_HEAP_FLAGS nri::GetHeapFlags(MemoryType memoryType) { return (D3D12_HEAP_FLAGS)(memoryType & 0xffff); } -bool nri::RequiresDedicatedAllocation(MemoryType memoryType) { - D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(memoryType); - - if ((heapFlags & D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) == D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES) - return true; - - return false; -} - D3D12_RESOURCE_FLAGS nri::GetBufferFlags(BufferUsageBits bufferUsageMask) { D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE; diff --git a/Source/D3D12/SharedD3D12.h b/Source/D3D12/SharedD3D12.h index da5ecf61..089eb256 100644 --- a/Source/D3D12/SharedD3D12.h +++ b/Source/D3D12/SharedD3D12.h @@ -32,9 +32,6 @@ struct DescriptorHeapDesc { uint32_t descriptorSize; }; -MemoryType GetMemoryType(D3D12_HEAP_TYPE heapType, D3D12_HEAP_FLAGS heapFlags); -MemoryType GetMemoryType(MemoryLocation memoryLocation, const D3D12_RESOURCE_DESC& resourceDesc); - D3D12_RAYTRACING_ACCELERATION_STRUCTURE_TYPE GetAccelerationStructureType(AccelerationStructureType accelerationStructureType); D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS GetAccelerationStructureBuildFlags(AccelerationStructureBuildBits accelerationStructureBuildFlags); D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE GetCopyMode(CopyMode copyMode); @@ -42,7 +39,6 @@ D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE GetCopyMode(CopyMode copyMode) D3D12_RESOURCE_FLAGS GetBufferFlags(BufferUsageBits bufferUsageMask); D3D12_RESOURCE_FLAGS GetTextureFlags(TextureUsageBits textureUsageMask); -bool RequiresDedicatedAllocation(MemoryType memoryType); void ConvertGeometryDescs(D3D12_RAYTRACING_GEOMETRY_DESC* geometryDescs, const GeometryObject* geometryObjects, uint32_t geometryObjectNum); void ConvertRects(D3D12_RECT* rectsD3D12, const Rect* rects, uint32_t rectNum); bool GetTextureDesc(const TextureD3D12Desc& textureD3D12Desc, TextureDesc& textureDesc); @@ -55,7 +51,6 @@ D3D12_TEXTURE_ADDRESS_MODE GetAddressMode(AddressMode addressMode); D3D12_COMPARISON_FUNC GetComparisonFunc(CompareFunc compareFunc); D3D12_COMMAND_LIST_TYPE GetCommandListType(CommandQueueType commandQueueType); D3D12_DESCRIPTOR_HEAP_TYPE GetDescriptorHeapType(DescriptorType descriptorType); -D3D12_HEAP_TYPE GetHeapType(MemoryType memoryType); D3D12_HEAP_FLAGS GetHeapFlags(MemoryType memoryType); D3D12_PRIMITIVE_TOPOLOGY_TYPE GetPrimitiveTopologyType(Topology topology); D3D_PRIMITIVE_TOPOLOGY GetPrimitiveTopology(Topology topology, uint8_t tessControlPointNum); diff --git a/Source/D3D12/TextureD3D12.cpp b/Source/D3D12/TextureD3D12.cpp index 80a282ab..1990bc6a 100644 --- a/Source/D3D12/TextureD3D12.cpp +++ b/Source/D3D12/TextureD3D12.cpp @@ -44,8 +44,11 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) { if (m_Texture) return Result::SUCCESS; - const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc(); D3D12_CLEAR_VALUE clearValue = {GetDxgiFormat(m_Desc.format).typed}; + const D3D12_HEAP_DESC& heapDesc = memory->GetHeapDesc(); + + // STATE_CREATION ERROR #640: CREATERESOURCEANDHEAP_INVALIDHEAPMISCFLAGS + D3D12_HEAP_FLAGS heapFlagsFixed = heapDesc.Flags & ~(D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES | D3D12_HEAP_FLAG_DENY_BUFFERS); #ifdef NRI_USE_AGILITY_SDK if (m_Device.GetVersion() >= 10) { @@ -58,7 +61,7 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) { DXGI_FORMAT* castableFormats = nullptr; // TODO: add castable formats, see options12.RelaxedFormatCastingSupported if (memory->RequiresDedicatedAllocation()) { - HRESULT hr = m_Device->CreateCommittedResource3(&heapDesc.Properties, heapDesc.Flags, &desc1, initialLayout, isRenderableSurface ? &clearValue : nullptr, nullptr, + HRESULT hr = m_Device->CreateCommittedResource3(&heapDesc.Properties, heapFlagsFixed, &desc1, initialLayout, isRenderableSurface ? &clearValue : nullptr, nullptr, castableFormatNum, castableFormats, IID_PPV_ARGS(&m_Texture)); RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device10::CreateCommittedResource3()"); } else { @@ -76,7 +79,7 @@ Result TextureD3D12::BindMemory(const MemoryD3D12* memory, uint64_t offset) { if (memory->RequiresDedicatedAllocation()) { HRESULT hr = m_Device->CreateCommittedResource( - &heapDesc.Properties, heapDesc.Flags, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture)); + &heapDesc.Properties, heapFlagsFixed, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture)); RETURN_ON_BAD_HRESULT(&m_Device, hr, "ID3D12Device::CreateCommittedResource()"); } else { HRESULT hr = m_Device->CreatePlacedResource(*memory, offset, &desc, D3D12_RESOURCE_STATE_COMMON, isRenderableSurface ? &clearValue : nullptr, IID_PPV_ARGS(&m_Texture)); diff --git a/Source/VK/BufferVK.cpp b/Source/VK/BufferVK.cpp index 7d4a31e6..8ce1a745 100644 --- a/Source/VK/BufferVK.cpp +++ b/Source/VK/BufferVK.cpp @@ -116,24 +116,27 @@ void BufferVK::SetDebugName(const char* name) { } void BufferVK::GetMemoryInfo(MemoryLocation memoryLocation, MemoryDesc& memoryDesc) const { - VkMemoryDedicatedRequirements dedicatedRequirements = {VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, nullptr}; - VkMemoryRequirements2 requirements = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, &dedicatedRequirements}; - VkBufferMemoryRequirementsInfo2 info = {VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2, nullptr, m_Handle}; + VkMemoryDedicatedRequirements dedicatedRequirements = {VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS}; + + VkMemoryRequirements2 requirements = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2}; + requirements.pNext = &dedicatedRequirements; + + VkBufferMemoryRequirementsInfo2 info = {VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2}; + info.buffer = m_Handle; const auto& vk = m_Device.GetDispatchTable(); vk.GetBufferMemoryRequirements2(m_Device, &info, &requirements); - memoryDesc.mustBeDedicated = dedicatedRequirements.requiresDedicatedAllocation; - memoryDesc.alignment = (uint32_t)requirements.memoryRequirements.alignment; - memoryDesc.size = requirements.memoryRequirements.size; + MemoryTypeUnion memoryType = {}; + memoryType.unpacked.isDedicated = dedicatedRequirements.requiresDedicatedAllocation; - MemoryTypeUnpack unpack = {}; - bool found = m_Device.GetMemoryType(memoryLocation, requirements.memoryRequirements.memoryTypeBits, unpack.info); + bool found = m_Device.GetMemoryType(memoryLocation, requirements.memoryRequirements.memoryTypeBits, memoryType.unpacked); RETURN_ON_FAILURE(&m_Device, found, ReturnVoid(), "Can't find suitable memory type"); - unpack.info.isDedicated = dedicatedRequirements.requiresDedicatedAllocation; - - memoryDesc.type = unpack.type; + memoryDesc.size = requirements.memoryRequirements.size; + memoryDesc.alignment = (uint32_t)requirements.memoryRequirements.alignment; + memoryDesc.type = memoryType.packed; + memoryDesc.mustBeDedicated = dedicatedRequirements.requiresDedicatedAllocation; } inline void* BufferVK::Map(uint64_t offset, uint64_t size) { diff --git a/Source/VK/DeviceVK.cpp b/Source/VK/DeviceVK.cpp index 52c59a6c..d2d390d1 100644 --- a/Source/VK/DeviceVK.cpp +++ b/Source/VK/DeviceVK.cpp @@ -874,8 +874,8 @@ bool DeviceVK::GetMemoryType(MemoryLocation memoryLocation, uint32_t memoryTypeM bool hasDesiredFlags = (m_MemoryProps.memoryTypes[i].propertyFlags & desiredFlags) == desiredFlags; if (isSupported && hasNeededFlags && !hasUndesiredFlags && hasDesiredFlags) { - memoryTypeInfo.memoryTypeIndex = (MemoryTypeIndexType)i; - memoryTypeInfo.memoryLocation = memoryLocation; + memoryTypeInfo.index = (MemoryTypeIndex)i; + memoryTypeInfo.location = memoryLocation; return true; } @@ -888,8 +888,8 @@ bool DeviceVK::GetMemoryType(MemoryLocation memoryLocation, uint32_t memoryTypeM bool hasUndesiredFlags = undesiredFlags == 0 ? false : (m_MemoryProps.memoryTypes[i].propertyFlags & undesiredFlags) == undesiredFlags; if (isSupported && hasNeededFlags && !hasUndesiredFlags) { - memoryTypeInfo.memoryTypeIndex = (MemoryTypeIndexType)i; - memoryTypeInfo.memoryLocation = memoryLocation; + memoryTypeInfo.index = (MemoryTypeIndex)i; + memoryTypeInfo.location = memoryLocation; return true; } @@ -902,8 +902,8 @@ bool DeviceVK::GetMemoryType(MemoryLocation memoryLocation, uint32_t memoryTypeM bool hasDesiredFlags = (m_MemoryProps.memoryTypes[i].propertyFlags & desiredFlags) == desiredFlags; if (isSupported && hasNeededFlags && hasDesiredFlags) { - memoryTypeInfo.memoryTypeIndex = (MemoryTypeIndexType)i; - memoryTypeInfo.memoryLocation = memoryLocation; + memoryTypeInfo.index = (MemoryTypeIndex)i; + memoryTypeInfo.location = memoryLocation; return true; } @@ -915,8 +915,8 @@ bool DeviceVK::GetMemoryType(MemoryLocation memoryLocation, uint32_t memoryTypeM bool hasNeededFlags = (m_MemoryProps.memoryTypes[i].propertyFlags & neededFlags) == neededFlags; if (isSupported && hasNeededFlags) { - memoryTypeInfo.memoryTypeIndex = (MemoryTypeIndexType)i; - memoryTypeInfo.memoryLocation = memoryLocation; + memoryTypeInfo.index = (MemoryTypeIndex)i; + memoryTypeInfo.location = memoryLocation; return true; } @@ -933,11 +933,11 @@ bool DeviceVK::GetMemoryTypeByIndex(uint32_t index, MemoryTypeInfo& memoryTypeIn bool isHostVisible = memoryType.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; bool isDevice = memoryType.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; - memoryTypeInfo.memoryTypeIndex = (MemoryTypeIndexType)index; + memoryTypeInfo.index = (MemoryTypeIndex)index; if (isDevice) - memoryTypeInfo.memoryLocation = isHostVisible ? MemoryLocation::DEVICE_UPLOAD : MemoryLocation::DEVICE; + memoryTypeInfo.location = isHostVisible ? MemoryLocation::DEVICE_UPLOAD : MemoryLocation::DEVICE; else - memoryTypeInfo.memoryLocation = MemoryLocation::HOST_UPLOAD; + memoryTypeInfo.location = MemoryLocation::HOST_UPLOAD; return true; } @@ -1693,10 +1693,9 @@ inline Result DeviceVK::BindBufferMemory(const BufferMemoryBindingDesc* memoryBi MemoryVK& memoryImpl = *(MemoryVK*)bindingDesc.memory; BufferVK& bufferImpl = *(BufferVK*)bindingDesc.buffer; - const MemoryTypeUnpack unpack = {memoryImpl.GetType()}; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; + const MemoryTypeUnion memoryType = {memoryImpl.GetType()}; - if (memoryImpl.OwnsNativeObjects() && memoryTypeInfo.isDedicated == 1) + if (memoryImpl.OwnsNativeObjects() && memoryType.unpacked.isDedicated) memoryImpl.CreateDedicated(bufferImpl); if (bufferImpl.OwnsNativeObjects()) { @@ -1707,7 +1706,7 @@ inline Result DeviceVK::BindBufferMemory(const BufferMemoryBindingDesc* memoryBi info.memoryOffset = bindingDesc.offset; } - if (IsHostVisibleMemory(memoryTypeInfo.memoryLocation)) + if (IsHostVisibleMemory(memoryType.unpacked.location)) bufferImpl.SetHostMemory(memoryImpl, bindingDesc.offset); } @@ -1737,10 +1736,9 @@ inline Result DeviceVK::BindTextureMemory(const TextureMemoryBindingDesc* memory MemoryVK& memoryImpl = *(MemoryVK*)bindingDesc.memory; TextureVK& textureImpl = *(TextureVK*)bindingDesc.texture; - const MemoryTypeUnpack unpack = {memoryImpl.GetType()}; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; + const MemoryTypeUnion memoryType = {memoryImpl.GetType()}; - if (memoryImpl.OwnsNativeObjects() && memoryTypeInfo.isDedicated) + if (memoryImpl.OwnsNativeObjects() && memoryType.unpacked.isDedicated) memoryImpl.CreateDedicated(textureImpl); if (textureImpl.OwnsNativeObjects()) { diff --git a/Source/VK/MemoryVK.cpp b/Source/VK/MemoryVK.cpp index 1474c229..848f86cb 100644 --- a/Source/VK/MemoryVK.cpp +++ b/Source/VK/MemoryVK.cpp @@ -15,16 +15,13 @@ MemoryVK::~MemoryVK() { vk.FreeMemory(m_Device, m_Handle, m_Device.GetAllocationCallbacks()); } -Result MemoryVK::Create(const MemoryType memoryType, uint64_t size) { +Result MemoryVK::Create(MemoryType type, uint64_t size) { m_OwnsNativeObjects = true; - m_Type = memoryType; + m_Type = type; - const MemoryTypeUnpack unpack = {memoryType}; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; - - // Dedicated allocation occurs on memory binding - if (memoryTypeInfo.isDedicated) - return Result::SUCCESS; + MemoryTypeUnion memoryType = {type}; + if (memoryType.unpacked.isDedicated) + return Result::SUCCESS; // Dedicated allocation occurs on memory binding VkMemoryAllocateFlagsInfo flagsInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO}; flagsInfo.flags = (m_Device.m_IsDeviceAddressSupported ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0) | VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT; @@ -33,13 +30,13 @@ Result MemoryVK::Create(const MemoryType memoryType, uint64_t size) { VkMemoryAllocateInfo memoryInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; memoryInfo.pNext = &flagsInfo; memoryInfo.allocationSize = size; - memoryInfo.memoryTypeIndex = memoryTypeInfo.memoryTypeIndex; + memoryInfo.memoryTypeIndex = memoryType.unpacked.index; const auto& vk = m_Device.GetDispatchTable(); VkResult result = vk.AllocateMemory(m_Device, &memoryInfo, m_Device.GetAllocationCallbacks(), &m_Handle); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkAllocateMemory returned %d", (int32_t)result); - if (IsHostVisibleMemory(memoryTypeInfo.memoryLocation)) { + if (IsHostVisibleMemory(memoryType.unpacked.location)) { result = vk.MapMemory(m_Device, m_Handle, 0, size, 0, (void**)&m_MappedMemory); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkMapMemory returned %d", (int32_t)result); } @@ -50,16 +47,17 @@ Result MemoryVK::Create(const MemoryType memoryType, uint64_t size) { Result MemoryVK::Create(const MemoryVKDesc& memoryDesc) { m_OwnsNativeObjects = false; - MemoryTypeUnpack unpack = {}; - const bool found = m_Device.GetMemoryTypeByIndex(memoryDesc.memoryTypeIndex, unpack.info); + MemoryTypeUnion memoryType = {}; + + bool found = m_Device.GetMemoryTypeByIndex(memoryDesc.memoryTypeIndex, memoryType.unpacked); RETURN_ON_FAILURE(&m_Device, found, Result::INVALID_ARGUMENT, "Can't find memory by index"); m_Handle = (VkDeviceMemory)memoryDesc.vkDeviceMemory; m_MappedMemory = (uint8_t*)memoryDesc.vkMappedMemory; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; + m_Type = memoryType.packed; const auto& vk = m_Device.GetDispatchTable(); - if (!m_MappedMemory && IsHostVisibleMemory(memoryTypeInfo.memoryLocation)) { + if (!m_MappedMemory && IsHostVisibleMemory(memoryType.unpacked.location)) { VkResult result = vk.MapMemory(m_Device, m_Handle, 0, memoryDesc.size, 0, (void**)&m_MappedMemory); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkMapMemory returned %d", (int32_t)result); } @@ -72,13 +70,11 @@ Result MemoryVK::CreateDedicated(BufferVK& buffer) { RETURN_ON_FAILURE(&m_Device, m_Type != std::numeric_limits::max(), Result::FAILURE, "Can't allocate a dedicated memory: memory type is invalid."); - const MemoryTypeUnpack unpack = {m_Type}; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; - - RETURN_ON_FAILURE(&m_Device, memoryTypeInfo.isDedicated == 1, Result::FAILURE, "Can't allocate a dedicated memory: memory type is not dedicated."); + MemoryTypeUnion memoryType = {m_Type}; + RETURN_ON_FAILURE(&m_Device, memoryType.unpacked.isDedicated, Result::FAILURE, "Can't allocate a dedicated memory: memory type is not dedicated."); MemoryDesc memoryDesc = {}; - buffer.GetMemoryInfo(memoryTypeInfo.memoryLocation, memoryDesc); + buffer.GetMemoryInfo(memoryType.unpacked.location, memoryDesc); VkMemoryAllocateFlagsInfo flagsInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO}; flagsInfo.flags = (m_Device.m_IsDeviceAddressSupported ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0) | VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT; @@ -91,14 +87,14 @@ Result MemoryVK::CreateDedicated(BufferVK& buffer) { VkMemoryAllocateInfo memoryInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; memoryInfo.pNext = &dedicatedAllocateInfo; memoryInfo.allocationSize = memoryDesc.size; - memoryInfo.memoryTypeIndex = memoryTypeInfo.memoryTypeIndex; + memoryInfo.memoryTypeIndex = memoryType.unpacked.index; // No need to allocate more than one instance of host memory const auto& vk = m_Device.GetDispatchTable(); VkResult result = vk.AllocateMemory(m_Device, &memoryInfo, m_Device.GetAllocationCallbacks(), &m_Handle); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkAllocateMemory returned %d", (int32_t)result); - if (IsHostVisibleMemory(memoryTypeInfo.memoryLocation)) { + if (IsHostVisibleMemory(memoryType.unpacked.location)) { result = vk.MapMemory(m_Device, m_Handle, 0, memoryDesc.size, 0, (void**)&m_MappedMemory); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkMapMemory returned %d", (int32_t)result); } @@ -111,13 +107,11 @@ Result MemoryVK::CreateDedicated(TextureVK& texture) { RETURN_ON_FAILURE(&m_Device, m_Type != std::numeric_limits::max(), Result::FAILURE, "Can't allocate a dedicated memory: invalid memory type."); - const MemoryTypeUnpack unpack = {m_Type}; - const MemoryTypeInfo& memoryTypeInfo = unpack.info; - - RETURN_ON_FAILURE(&m_Device, memoryTypeInfo.isDedicated == 1, Result::FAILURE, "Can't allocate a dedicated memory: the memory type is not dedicated."); + const MemoryTypeUnion memoryType = {m_Type}; + RETURN_ON_FAILURE(&m_Device, memoryType.unpacked.isDedicated, Result::FAILURE, "Can't allocate a dedicated memory: the memory type is not dedicated."); MemoryDesc memoryDesc = {}; - texture.GetMemoryInfo(memoryTypeInfo.memoryLocation, memoryDesc); + texture.GetMemoryInfo(memoryType.unpacked.location, memoryDesc); VkMemoryAllocateFlagsInfo flagsInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO}; flagsInfo.flags = (m_Device.m_IsDeviceAddressSupported ? VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT : 0) | VK_MEMORY_ALLOCATE_DEVICE_MASK_BIT; @@ -130,13 +124,13 @@ Result MemoryVK::CreateDedicated(TextureVK& texture) { VkMemoryAllocateInfo memoryInfo = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; memoryInfo.pNext = &dedicatedAllocateInfo; memoryInfo.allocationSize = memoryDesc.size; - memoryInfo.memoryTypeIndex = memoryTypeInfo.memoryTypeIndex; + memoryInfo.memoryTypeIndex = memoryType.unpacked.index; const auto& vk = m_Device.GetDispatchTable(); VkResult result = vk.AllocateMemory(m_Device, &memoryInfo, m_Device.GetAllocationCallbacks(), &m_Handle); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkAllocateMemory returned %d", (int32_t)result); - if (IsHostVisibleMemory(memoryTypeInfo.memoryLocation)) { + if (IsHostVisibleMemory(memoryType.unpacked.location)) { result = vk.MapMemory(m_Device, m_Handle, 0, memoryDesc.size, 0, (void**)&m_MappedMemory); RETURN_ON_FAILURE(&m_Device, result == VK_SUCCESS, GetReturnCode(result), "vkMapMemory returned %d", (int32_t)result); } diff --git a/Source/VK/MemoryVK.h b/Source/VK/MemoryVK.h index f90a13dd..dabb6547 100644 --- a/Source/VK/MemoryVK.h +++ b/Source/VK/MemoryVK.h @@ -36,7 +36,7 @@ struct MemoryVK { ~MemoryVK(); - Result Create(const MemoryType memoryType, uint64_t size); + Result Create(MemoryType type, uint64_t size); Result Create(const MemoryVKDesc& memoryDesc); Result CreateDedicated(BufferVK& buffer); Result CreateDedicated(TextureVK& texture); diff --git a/Source/VK/SharedVK.h b/Source/VK/SharedVK.h index e2dfbfac..052940eb 100644 --- a/Source/VK/SharedVK.h +++ b/Source/VK/SharedVK.h @@ -11,17 +11,17 @@ #include "DispatchTable.h" -typedef uint16_t MemoryTypeIndexType; +typedef uint16_t MemoryTypeIndex; struct MemoryTypeInfo { - MemoryTypeIndexType memoryTypeIndex; - nri::MemoryLocation memoryLocation; + MemoryTypeIndex index; + nri::MemoryLocation location; bool isDedicated; }; static_assert(sizeof(MemoryTypeInfo) <= sizeof(nri::MemoryType), "Unexpected structure size"); -union MemoryTypeUnpack { - nri::MemoryType type; - MemoryTypeInfo info; +union MemoryTypeUnion { + nri::MemoryType packed; + MemoryTypeInfo unpacked; }; template diff --git a/Source/VK/TextureVK.cpp b/Source/VK/TextureVK.cpp index 5f800d31..a8e59499 100644 --- a/Source/VK/TextureVK.cpp +++ b/Source/VK/TextureVK.cpp @@ -88,24 +88,27 @@ inline void TextureVK::SetDebugName(const char* name) { } void TextureVK::GetMemoryInfo(MemoryLocation memoryLocation, MemoryDesc& memoryDesc) const { - VkMemoryDedicatedRequirements dedicatedRequirements = {VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, nullptr}; - VkMemoryRequirements2 requirements = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, &dedicatedRequirements}; - VkImageMemoryRequirementsInfo2 info = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, nullptr, m_Handle}; + VkMemoryDedicatedRequirements dedicatedRequirements = {VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS}; + + VkMemoryRequirements2 requirements = {VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2}; + requirements.pNext = &dedicatedRequirements; + + VkImageMemoryRequirementsInfo2 info = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2}; + info.image = m_Handle; const auto& vk = m_Device.GetDispatchTable(); vk.GetImageMemoryRequirements2(m_Device, &info, &requirements); - memoryDesc.mustBeDedicated = dedicatedRequirements.prefersDedicatedAllocation || dedicatedRequirements.requiresDedicatedAllocation; - memoryDesc.alignment = (uint32_t)requirements.memoryRequirements.alignment; - memoryDesc.size = requirements.memoryRequirements.size; + MemoryTypeUnion memoryType = {}; + memoryType.unpacked.isDedicated = dedicatedRequirements.requiresDedicatedAllocation; - MemoryTypeUnpack unpack = {}; - bool found = m_Device.GetMemoryType(memoryLocation, requirements.memoryRequirements.memoryTypeBits, unpack.info); + bool found = m_Device.GetMemoryType(memoryLocation, requirements.memoryRequirements.memoryTypeBits, memoryType.unpacked); RETURN_ON_FAILURE(&m_Device, found, ReturnVoid(), "Can't find suitable memory type"); - unpack.info.isDedicated = dedicatedRequirements.requiresDedicatedAllocation; - - memoryDesc.type = unpack.type; + memoryDesc.size = requirements.memoryRequirements.size; + memoryDesc.alignment = (uint32_t)requirements.memoryRequirements.alignment; + memoryDesc.type = memoryType.packed; + memoryDesc.mustBeDedicated = dedicatedRequirements.requiresDedicatedAllocation; } #include "TextureVK.hpp"