Explorar o código

For Android, create a public, common bufferpool object for Passes/SRGs, to save Host memory. (#14547)

Signed-off-by: Jackie9527 <[email protected]>
Jackie9527 %!s(int64=2) %!d(string=hai) anos
pai
achega
a427a226ce

+ 10 - 1
Gems/Atom/RHI/Vulkan/Code/Source/RHI.Reflect/BufferPoolDescriptor.cpp

@@ -27,7 +27,16 @@ namespace AZ
 
         BufferPoolDescriptor::BufferPoolDescriptor()
         {
-            m_bufferPoolPageSizeInBytes = RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_bufferPoolPageSizeInBytes;
+            if (auto device = RHI::RHISystemInterface::Get()->GetDevice())
+            {
+                m_bufferPoolPageSizeInBytes =
+                    RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_bufferPoolPageSizeInBytes;
+            }
+            else
+            {
+                m_bufferPoolPageSizeInBytes = RHI::DefaultValues::Memory::BufferPoolPageSizeInBytes;
+            }
+            
         }
     }
 }

+ 20 - 0
Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp

@@ -390,6 +390,20 @@ namespace AZ
             result = m_stagingBufferPool->Init(*this, poolDesc);
             RETURN_RESULT_IF_UNSUCCESSFUL(result);
 
+            {
+                m_constantBufferPool = BufferPool::Create();
+                static int index = 0;
+                m_constantBufferPool->SetName(Name(AZStd::string::format("ConstantPool_%d", ++index)));
+
+                BufferPoolDescriptor bufferPoolDescriptor;
+                bufferPoolDescriptor.m_bindFlags = RHI::BufferBindFlags::Constant;
+                bufferPoolDescriptor.m_heapMemoryLevel = RHI::HeapMemoryLevel::Host;
+                bufferPoolDescriptor.m_bufferPoolPageSizeInBytes =
+                    m_descriptor.m_platformLimitsDescriptor->m_platformDefaultValues.m_bufferPoolPageSizeInBytes;
+                result = m_constantBufferPool->Init(*this, bufferPoolDescriptor);
+                RETURN_RESULT_IF_UNSUCCESSFUL(result);
+            }
+
             const auto& physicalDevice = static_cast<const PhysicalDevice&>(GetPhysicalDevice());
             if (!physicalDevice.IsFeatureSupported(DeviceFeature::NullDescriptor))
             {
@@ -627,6 +641,7 @@ namespace AZ
 
             m_bindlessDescriptorPool.Shutdown();
             m_stagingBufferPool.reset();
+            m_constantBufferPool.reset();
             m_renderPassCache.first.Clear();
             m_framebufferCache.first.Clear();
             m_descriptorSetLayoutCache.first.Clear();
@@ -1217,5 +1232,10 @@ namespace AZ
         {
             return m_imageShadingRateMode;
         }
+
+        RHI::Ptr<BufferPool> Device::GetConstantBufferPool()
+        {
+            return m_constantBufferPool;
+        }
     }
 }

+ 4 - 0
Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.h

@@ -129,6 +129,8 @@ namespace AZ
 
             ShadingRateImageMode GetImageShadingRateMode() const;
 
+            RHI::Ptr<BufferPool> GetConstantBufferPool();
+
         private:
             Device();
 
@@ -186,6 +188,8 @@ namespace AZ
 
             RHI::Ptr<BufferPool> m_stagingBufferPool;
 
+            RHI::Ptr<BufferPool> m_constantBufferPool;
+
             ReleaseQueue m_releaseQueue;
             CommandQueueContext m_commandQueueContext;
 

+ 1 - 10
Gems/Atom/RHI/Vulkan/Code/Source/RHI/ShaderResourceGroupPool.cpp

@@ -34,16 +34,7 @@ namespace AZ
 
             m_descriptorSetCount = RHI::Limits::Device::FrameCountMax;
 
-            const uint32_t constantSize = layout.GetConstantDataSize();
-            if (constantSize > 0)
-            {
-                BufferPoolDescriptor bufferPoolDescriptor;
-                bufferPoolDescriptor.m_bindFlags = RHI::BufferBindFlags::Constant;
-                bufferPoolDescriptor.m_heapMemoryLevel = RHI::HeapMemoryLevel::Host;
-                m_constantBufferPool = BufferPool::Create();
-                m_constantBufferPool->SetName(AZ::Name(AZStd::string::format("%s_ConstantBufferPool", GetName().GetCStr())));
-                m_constantBufferPool->Init(device, bufferPoolDescriptor);
-            }
+            m_constantBufferPool = device.GetConstantBufferPool();
 
             DescriptorSetLayout::Descriptor layoutDescriptor;
             layoutDescriptor.m_device = &device;