diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/Android/Vulkan/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/Android/Vulkan/PlatformLimits.azasset deleted file mode 100644 index 37becd9eef..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/Android/Vulkan/PlatformLimits.azasset +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "Vulkan::PlatformLimitsDescriptor" - } - } -} diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/Linux/Vulkan/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/Linux/Vulkan/PlatformLimits.azasset deleted file mode 100644 index 37becd9eef..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/Linux/Vulkan/PlatformLimits.azasset +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "Vulkan::PlatformLimitsDescriptor" - } - } -} diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/Mac/Metal/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/Mac/Metal/PlatformLimits.azasset deleted file mode 100644 index 573862cc40..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/Mac/Metal/PlatformLimits.azasset +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "Metal::PlatformLimitsDescriptor" - } - } -} - diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/DX12/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/DX12/PlatformLimits.azasset deleted file mode 100644 index 3c88544e62..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/DX12/PlatformLimits.azasset +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "DX12::PlatformLimitsDescriptor", - - "m_descriptorHeapLimits": { - "DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV": [1000000, 1000000], - "DESCRIPTOR_HEAP_TYPE_SAMPLER": [2048, 2048], - "DESCRIPTOR_HEAP_TYPE_RTV": [2048, 0], - "DESCRIPTOR_HEAP_TYPE_DSV": [2048, 0] - } - } - } -} diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/Vulkan/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/Vulkan/PlatformLimits.azasset deleted file mode 100644 index 37becd9eef..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/Windows/Vulkan/PlatformLimits.azasset +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "Vulkan::PlatformLimitsDescriptor" - } - } -} diff --git a/Gems/Atom/Feature/Common/Assets/Config/Platform/iOS/Metal/PlatformLimits.azasset b/Gems/Atom/Feature/Common/Assets/Config/Platform/iOS/Metal/PlatformLimits.azasset deleted file mode 100644 index 4556073118..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Config/Platform/iOS/Metal/PlatformLimits.azasset +++ /dev/null @@ -1,12 +0,0 @@ -{ - "Type": "JsonSerialization", - "Version": 0, - "ClassName": "PlatformLimits", - "ClassData": { - "m_platformLimitsDescriptor": - { - "$type": "Metal::PlatformLimitsDescriptor" - } - } -} - diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceDescriptor.h b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceDescriptor.h index 87e2b03181..b7f7a6754f 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceDescriptor.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceDescriptor.h @@ -22,14 +22,14 @@ namespace AZ class DeviceDescriptor { public: - virtual ~DeviceDescriptor() = default; AZ_RTTI(DeviceDescriptor, "{8446A34C-A079-44B8-A20F-45D9CAB1FAFD}"); static void Reflect(AZ::ReflectContext* context); DeviceDescriptor() = default; + virtual ~DeviceDescriptor(); uint32_t m_frameCountMax = RHI::Limits::Device::FrameCountMax; - ConstPtr m_platformLimitsDescriptor = nullptr; + Ptr m_platformLimitsDescriptor = nullptr; }; } } diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/PlatformLimitsDescriptor.h b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/PlatformLimitsDescriptor.h index 4cec15651c..2d85420694 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/PlatformLimitsDescriptor.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/PlatformLimitsDescriptor.h @@ -20,7 +20,7 @@ namespace AZ { struct TransientAttachmentPoolBudgets { - AZ_TYPE_INFO(TransientAttachmentPoolBudgets, "{CE39BBEF-C9CD-4B9A-BA41-C886D9F063BC}"); + AZ_TYPE_INFO(AZ::RHI::TransientAttachmentPoolBudgets, "{CE39BBEF-C9CD-4B9A-BA41-C886D9F063BC}"); static void Reflect(AZ::ReflectContext* context); //! Defines the maximum amount of memory the pool is allowed to consume for transient buffers. @@ -53,8 +53,8 @@ namespace AZ : public AZStd::intrusive_base { public: - AZ_RTTI(PlatformLimitsDescriptor, "{3A7B2BE4-0337-4F59-B4FC-B7E529EBE6C5}"); - AZ_CLASS_ALLOCATOR(PlatformLimitsDescriptor, AZ::SystemAllocator, 0); + AZ_RTTI(AZ::RHI::PlatformLimitsDescriptor, "{3A7B2BE4-0337-4F59-B4FC-B7E529EBE6C5}"); + AZ_CLASS_ALLOCATOR(AZ::RHI::PlatformLimitsDescriptor, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context); static RHI::Ptr Create(); @@ -67,13 +67,15 @@ namespace AZ HeapPagingParameters m_pagingParameters; HeapMemoryHintParameters m_usageHintParameters; HeapAllocationStrategy m_heapAllocationStrategy = HeapAllocationStrategy::MemoryHint; + + void LoadPlatformLimitsDescriptor(const char* rhiName); }; class PlatformLimits final { public: - AZ_RTTI(PlatformLimits, "{48158F25-5044-441C-A2B2-2D3E9255B0C3}"); - AZ_CLASS_ALLOCATOR(PlatformLimits, AZ::SystemAllocator, 0); + AZ_RTTI(AZ::RHI::PlatformLimits, "{48158F25-5044-441C-A2B2-2D3E9255B0C3}"); + AZ_CLASS_ALLOCATOR(AZ::RHI::PlatformLimits, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context); Ptr m_platformLimitsDescriptor = nullptr; diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/RHISystemDescriptor.h b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/RHISystemDescriptor.h index b9fae5593f..8c512662e7 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/RHISystemDescriptor.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/RHISystemDescriptor.h @@ -26,8 +26,6 @@ namespace AZ //! The set of globally declared draw list tags, which will be registered with the registry at startup. AZStd::vector m_drawListTags; - - const RHI::PlatformLimits* m_platformLimits = nullptr; }; } // namespace RHI } // namespace AZ diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/Device.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/Device.h index e7ad98c074..f9df29cf74 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/Device.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/Device.h @@ -60,10 +60,6 @@ namespace AZ //! been called), and an error code is returned. ResultCode Init(PhysicalDevice& physicalDevice); - //! Called to initialize anything that wasn't done as part of Init. DeviceDescriptor is passed down - //! as part of this API. This is called after AssetCatalog is loaded and hence any file can be loaded at this point - ResultCode PostInit(const DeviceDescriptor& descriptor); - //! Begins execution of a frame. The device internally manages a set of command queues. This //! method will synchronize the CPU with the GPU according to the number of in-light frames //! configured on the device. This means you should make sure any manipulation of N-buffered @@ -147,7 +143,9 @@ namespace AZ DeviceFeatures m_features; DeviceLimits m_limits; ResourcePoolDatabase m_resourcePoolDatabase; - + + DeviceDescriptor m_descriptor; + using FormatCapabilitiesList = AZStd::array(Format::Count)>; private: @@ -165,10 +163,6 @@ namespace AZ //! Called when just the device is being initialized. virtual ResultCode InitInternal(PhysicalDevice& physicalDevice) = 0; - - //! Called to initialize anything that wasnt done as part of InitInternal. - //! This is called after AssetCatalog is loaded and hence any file can be loaded at this point - virtual ResultCode PostInitInternal(const DeviceDescriptor& descriptor) = 0; //! Called when the device is being shutdown. virtual void ShutdownInternal() = 0; @@ -190,6 +184,9 @@ namespace AZ //! Fills the capabilities for each format. virtual void FillFormatsCapabilitiesInternal(FormatCapabilitiesList& formatsCapabilities) = 0; + + //! Initialize limits and resources associated with them. + virtual ResultCode InitializeLimits() = 0; /////////////////////////////////////////////////////////////////// void CalculateDepthStencilNearestSupportedFormats(); @@ -198,8 +195,6 @@ namespace AZ //! All platform specific format mappings should be executed before this function is called void FillRemainingSupportedFormats(); - DeviceDescriptor m_descriptor; - // The physical device backing this logical device instance. Ptr m_physicalDevice; diff --git a/Gems/Atom/RHI/Code/Include/Atom/RHI/RHISystem.h b/Gems/Atom/RHI/Code/Include/Atom/RHI/RHISystem.h index e37fd75148..25026b5b87 100644 --- a/Gems/Atom/RHI/Code/Include/Atom/RHI/RHISystem.h +++ b/Gems/Atom/RHI/Code/Include/Atom/RHI/RHISystem.h @@ -68,7 +68,6 @@ namespace AZ RHI::FrameScheduler m_frameScheduler; RHI::FrameSchedulerCompileRequest m_compileRequest; - ConstPtr m_platformLimitsDescriptor = nullptr; RHI::CpuProfilerImpl m_cpuProfiler; }; } // namespace RPI diff --git a/Gems/Atom/RHI/Code/Source/RHI.Reflect/DeviceDescriptor.cpp b/Gems/Atom/RHI/Code/Source/RHI.Reflect/DeviceDescriptor.cpp index 709a870c81..8f36d38934 100644 --- a/Gems/Atom/RHI/Code/Source/RHI.Reflect/DeviceDescriptor.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI.Reflect/DeviceDescriptor.cpp @@ -24,5 +24,11 @@ namespace AZ ; } } + + DeviceDescriptor::~DeviceDescriptor() + { + m_platformLimitsDescriptor = nullptr; + } + } } diff --git a/Gems/Atom/RHI/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp b/Gems/Atom/RHI/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp index 02bcb3432f..250f03716d 100644 --- a/Gems/Atom/RHI/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp @@ -7,6 +7,7 @@ */ #include #include +#include namespace AZ { @@ -17,8 +18,8 @@ namespace AZ if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_platformLimitsDescriptor", &PlatformLimits::m_platformLimitsDescriptor) + ->Version(1) + ->Field("PlatformLimitsDescriptor", &PlatformLimits::m_platformLimitsDescriptor) ; } } @@ -28,10 +29,10 @@ namespace AZ if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_bufferBudgetInBytes", &TransientAttachmentPoolBudgets::m_bufferBudgetInBytes) - ->Field("m_imageBudgetInBytes", &TransientAttachmentPoolBudgets::m_imageBudgetInBytes) - ->Field("m_renderTargetBudgetInBytes", &TransientAttachmentPoolBudgets::m_renderTargetBudgetInBytes) + ->Version(1) + ->Field("BufferBudgetInBytes", &TransientAttachmentPoolBudgets::m_bufferBudgetInBytes) + ->Field("ImageBudgetInBytes", &TransientAttachmentPoolBudgets::m_imageBudgetInBytes) + ->Field("RenderTargetBudgetInBytes", &TransientAttachmentPoolBudgets::m_renderTargetBudgetInBytes) ; } } @@ -41,13 +42,13 @@ namespace AZ if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_stagingBufferBudgetInBytes", &PlatformDefaultValues::m_stagingBufferBudgetInBytes) - ->Field("m_asyncQueueStagingBufferSizeInBytes", &PlatformDefaultValues::m_asyncQueueStagingBufferSizeInBytes) - ->Field("m_mediumStagingBufferPageSizeInBytes", &PlatformDefaultValues::m_mediumStagingBufferPageSizeInBytes) - ->Field("m_largestStagingBufferPageSizeInBytes", &PlatformDefaultValues::m_largestStagingBufferPageSizeInBytes) - ->Field("m_imagePoolPageSizeInBytes", &PlatformDefaultValues::m_imagePoolPageSizeInBytes) - ->Field("m_bufferPoolPageSizeInBytes", &PlatformDefaultValues::m_bufferPoolPageSizeInBytes) + ->Version(1) + ->Field("StagingBufferBudgetInBytes", &PlatformDefaultValues::m_stagingBufferBudgetInBytes) + ->Field("AsyncQueueStagingBufferSizeInBytes", &PlatformDefaultValues::m_asyncQueueStagingBufferSizeInBytes) + ->Field("MediumStagingBufferPageSizeInBytes", &PlatformDefaultValues::m_mediumStagingBufferPageSizeInBytes) + ->Field("LargestStagingBufferPageSizeInBytes", &PlatformDefaultValues::m_largestStagingBufferPageSizeInBytes) + ->Field("ImagePoolPageSizeInBytes", &PlatformDefaultValues::m_imagePoolPageSizeInBytes) + ->Field("BufferPoolPageSizeInBytes", &PlatformDefaultValues::m_bufferPoolPageSizeInBytes) ; } } @@ -58,12 +59,12 @@ namespace AZ if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(1) - ->Field("m_transientAttachmentPoolBudgets", &PlatformLimitsDescriptor::m_transientAttachmentPoolBudgets) - ->Field("m_platformDefaultValues", &PlatformLimitsDescriptor::m_platformDefaultValues) - ->Field("m_pagingParameters", &PlatformLimitsDescriptor::m_pagingParameters) - ->Field("m_usageHintParameters", &PlatformLimitsDescriptor::m_usageHintParameters) - ->Field("m_heapAllocationStrategy", &PlatformLimitsDescriptor::m_heapAllocationStrategy) + ->Version(2) + ->Field("TransientAttachmentPoolBudgets", &PlatformLimitsDescriptor::m_transientAttachmentPoolBudgets) + ->Field("PlatformDefaultValues", &PlatformLimitsDescriptor::m_platformDefaultValues) + ->Field("PagingParameters", &PlatformLimitsDescriptor::m_pagingParameters) + ->Field("UsageHintParameters", &PlatformLimitsDescriptor::m_usageHintParameters) + ->Field("HeapAllocationStrategy", &PlatformLimitsDescriptor::m_heapAllocationStrategy) ; } } @@ -72,5 +73,18 @@ namespace AZ { return aznew PlatformLimitsDescriptor; } + + void PlatformLimitsDescriptor::LoadPlatformLimitsDescriptor(const char* rhiName) + { + auto settingsRegistry = AZ::SettingsRegistry::Get(); + AZStd::string platformLimitsRegPath = AZStd::string::format("/Amazon/Atom/RHI/PlatformLimits/%s", rhiName); + if (!(settingsRegistry && + settingsRegistry->GetObject(this, azrtti_typeid(this), platformLimitsRegPath.c_str()))) + { + AZ_Warning( + "Device", false, "Platform limits for %s %s is not loaded correctly. Will use default values.", + AZ_TRAIT_OS_PLATFORM_NAME, rhiName); + } + } } } diff --git a/Gems/Atom/RHI/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/Code/Source/RHI/Device.cpp index b7a1e2315c..3af09717df 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/Device.cpp @@ -77,7 +77,7 @@ namespace AZ m_physicalDevice = &physicalDevice; - const ResultCode resultCode = InitInternal(physicalDevice); + RHI::ResultCode resultCode = InitInternal(physicalDevice); if (resultCode == ResultCode::Success) { @@ -90,6 +90,9 @@ namespace AZ // Assume all formats that haven't been mapped yet are supported and map to themselves FillRemainingSupportedFormats(); + + // Initialize limits and resources that are associated with them + resultCode = InitializeLimits(); } else { @@ -98,29 +101,6 @@ namespace AZ return resultCode; } - - ResultCode Device::PostInit(const DeviceDescriptor& descriptor) - { - if (Validation::IsEnabled()) - { - if (!IsInitialized()) - { - AZ_Error("Device", false, "Device is not initialized."); - return ResultCode::InvalidOperation; - } - } - - m_descriptor = descriptor; - const ResultCode resultCode = PostInitInternal(descriptor); - - if (resultCode != ResultCode::Success) - { - AZ_Error("Device", false, "Device is not initialized."); - return ResultCode::InvalidOperation; - } - - return resultCode; - } void Device::Shutdown() { diff --git a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp index 5e08696ec2..8f8b7677fd 100644 --- a/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp +++ b/Gems/Atom/RHI/Code/Source/RHI/RHISystem.cpp @@ -30,42 +30,26 @@ namespace AZ void RHISystem::InitDevice() { - m_device = InitInternalDevice(); Interface::Register(this); + m_device = InitInternalDevice(); } void RHISystem::Init(const RHISystemDescriptor& descriptor) { m_cpuProfiler.Init(); - RHI::FrameSchedulerDescriptor frameSchedulerDescriptor; - if (descriptor.m_platformLimits) - { - m_platformLimitsDescriptor = descriptor.m_platformLimits->m_platformLimitsDescriptor; - } - - //If platformlimits.azasset file is not provided create an object with default config values. - if (!m_platformLimitsDescriptor) - { - m_platformLimitsDescriptor = PlatformLimitsDescriptor::Create(); - } + Ptr platformLimitsDescriptor = m_device->GetDescriptor().m_platformLimitsDescriptor; - RHI::DeviceDescriptor deviceDesc; - deviceDesc.m_platformLimitsDescriptor = m_platformLimitsDescriptor; - if (m_device->PostInit(deviceDesc) != RHI::ResultCode::Success) - { - AZ_Assert(false, "RHISystem", "Unable to initialize RHI! \n"); - return; - } + RHI::FrameSchedulerDescriptor frameSchedulerDescriptor; m_drawListTagRegistry = RHI::DrawListTagRegistry::Create(); m_pipelineStateCache = RHI::PipelineStateCache::Create(*m_device); - frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_renderTargetBudgetInBytes = m_platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_renderTargetBudgetInBytes; - frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_imageBudgetInBytes = m_platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_imageBudgetInBytes; - frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_bufferBudgetInBytes = m_platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_bufferBudgetInBytes; + frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_renderTargetBudgetInBytes = platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_renderTargetBudgetInBytes; + frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_imageBudgetInBytes = platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_imageBudgetInBytes; + frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_bufferBudgetInBytes = platformLimitsDescriptor->m_transientAttachmentPoolBudgets.m_bufferBudgetInBytes; - switch (m_platformLimitsDescriptor->m_heapAllocationStrategy) + switch (platformLimitsDescriptor->m_heapAllocationStrategy) { case HeapAllocationStrategy::Fixed: { @@ -75,19 +59,19 @@ namespace AZ case HeapAllocationStrategy::Paging: { RHI::HeapPagingParameters heapAllocationParameters; - heapAllocationParameters.m_collectLatency = m_platformLimitsDescriptor->m_pagingParameters.m_collectLatency; - heapAllocationParameters.m_initialAllocationPercentage = m_platformLimitsDescriptor->m_pagingParameters.m_initialAllocationPercentage; - heapAllocationParameters.m_pageSizeInBytes = m_platformLimitsDescriptor->m_pagingParameters.m_pageSizeInBytes; + heapAllocationParameters.m_collectLatency = platformLimitsDescriptor->m_pagingParameters.m_collectLatency; + heapAllocationParameters.m_initialAllocationPercentage = platformLimitsDescriptor->m_pagingParameters.m_initialAllocationPercentage; + heapAllocationParameters.m_pageSizeInBytes = platformLimitsDescriptor->m_pagingParameters.m_pageSizeInBytes; frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_heapParameters = RHI::HeapAllocationParameters(heapAllocationParameters); break; } case HeapAllocationStrategy::MemoryHint: { RHI::HeapMemoryHintParameters heapAllocationParameters; - heapAllocationParameters.m_heapSizeScaleFactor = m_platformLimitsDescriptor->m_usageHintParameters.m_heapSizeScaleFactor; - heapAllocationParameters.m_collectLatency = m_platformLimitsDescriptor->m_usageHintParameters.m_collectLatency; - heapAllocationParameters.m_maxHeapWastedPercentage = m_platformLimitsDescriptor->m_usageHintParameters.m_maxHeapWastedPercentage; - heapAllocationParameters.m_minHeapSizeInBytes = m_platformLimitsDescriptor->m_usageHintParameters.m_minHeapSizeInBytes; + heapAllocationParameters.m_heapSizeScaleFactor = platformLimitsDescriptor->m_usageHintParameters.m_heapSizeScaleFactor; + heapAllocationParameters.m_collectLatency = platformLimitsDescriptor->m_usageHintParameters.m_collectLatency; + heapAllocationParameters.m_maxHeapWastedPercentage = platformLimitsDescriptor->m_usageHintParameters.m_maxHeapWastedPercentage; + heapAllocationParameters.m_minHeapSizeInBytes = platformLimitsDescriptor->m_usageHintParameters.m_minHeapSizeInBytes; frameSchedulerDescriptor.m_transientAttachmentPoolDescriptor.m_heapParameters = RHI::HeapAllocationParameters(heapAllocationParameters); break; } @@ -98,7 +82,7 @@ namespace AZ } } - frameSchedulerDescriptor.m_platformLimitsDescriptor = m_platformLimitsDescriptor; + frameSchedulerDescriptor.m_platformLimitsDescriptor = platformLimitsDescriptor; m_frameScheduler.Init(*m_device, frameSchedulerDescriptor); // Register draw list tags declared from content. @@ -183,6 +167,7 @@ namespace AZ RHI::Ptr device = RHI::Factory::Get().CreateDevice(); if (device->Init(*physicalDeviceFound) == RHI::ResultCode::Success) { + PlatformLimitsDescriptor::Create(); return device; } @@ -195,10 +180,9 @@ namespace AZ Interface::Unregister(this); m_frameScheduler.Shutdown(); - m_platformLimitsDescriptor = nullptr; m_pipelineStateCache = nullptr; if (m_device) - { + { m_device->PreShutdown(); AZ_Assert(m_device->use_count()==1, "The ref count for Device is %i but it should be 1 here to ensure all the resources are released", m_device->use_count()); m_device = nullptr; @@ -293,7 +277,7 @@ namespace AZ ConstPtr RHISystem::GetPlatformLimitsDescriptor() const { - return m_platformLimitsDescriptor; + return m_device->GetDescriptor().m_platformLimitsDescriptor; } void RHISystem::QueueRayTracingShaderTableForBuild(RayTracingShaderTable* rayTracingShaderTable) diff --git a/Gems/Atom/RHI/Code/Tests/Device.cpp b/Gems/Atom/RHI/Code/Tests/Device.cpp index 654653ceb9..0f424a5405 100644 --- a/Gems/Atom/RHI/Code/Tests/Device.cpp +++ b/Gems/Atom/RHI/Code/Tests/Device.cpp @@ -17,6 +17,11 @@ namespace UnitTest m_descriptor.m_description = "UnitTest Fake Device"; } + Device::Device() + { + m_descriptor.m_platformLimitsDescriptor = aznew RHI::PlatformLimitsDescriptor; + } + RHI::PhysicalDeviceList PhysicalDevice::Enumerate() { return RHI::PhysicalDeviceList{aznew PhysicalDevice}; @@ -29,7 +34,6 @@ namespace UnitTest RHI::Ptr device = RHI::Factory::Get().CreateDevice(); device->Init(*physicalDevices[0]); - device->PostInit(RHI::DeviceDescriptor{}); return device; } diff --git a/Gems/Atom/RHI/Code/Tests/Device.h b/Gems/Atom/RHI/Code/Tests/Device.h index e11bd75983..d3177fc823 100644 --- a/Gems/Atom/RHI/Code/Tests/Device.h +++ b/Gems/Atom/RHI/Code/Tests/Device.h @@ -31,10 +31,11 @@ namespace UnitTest public: AZ_CLASS_ALLOCATOR(Device, AZ::SystemAllocator, 0); + Device(); + private: AZ::RHI::ResultCode InitInternal(AZ::RHI::PhysicalDevice&) override { return AZ::RHI::ResultCode::Success; } - AZ::RHI::ResultCode PostInitInternal(const AZ::RHI::DeviceDescriptor&) override { return AZ::RHI::ResultCode::Success; } void ShutdownInternal() override {} @@ -54,7 +55,9 @@ namespace UnitTest } void FillFormatsCapabilitiesInternal([[maybe_unused]] FormatCapabilitiesList& formatsCapabilities) override {} - + + AZ::RHI::ResultCode InitializeLimits() override { return AZ::RHI::ResultCode::Success; } + void PreShutdown() override {} AZ::RHI::ResourceMemoryRequirements GetResourceMemoryRequirements([[maybe_unused]] const AZ::RHI::ImageDescriptor& descriptor) { return AZ::RHI::ResourceMemoryRequirements{}; }; diff --git a/Gems/Atom/RHI/DX12/Code/Include/Atom/RHI.Reflect/DX12/PlatformLimitsDescriptor.h b/Gems/Atom/RHI/DX12/Code/Include/Atom/RHI.Reflect/DX12/PlatformLimitsDescriptor.h index 06e15d0ca6..cbf1fd11f6 100644 --- a/Gems/Atom/RHI/DX12/Code/Include/Atom/RHI.Reflect/DX12/PlatformLimitsDescriptor.h +++ b/Gems/Atom/RHI/DX12/Code/Include/Atom/RHI.Reflect/DX12/PlatformLimitsDescriptor.h @@ -23,11 +23,11 @@ namespace AZ DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, DESCRIPTOR_HEAP_TYPE_SAMPLER, DESCRIPTOR_HEAP_TYPE_RTV, - DESCRIPTOR_HEAP_TYPE_DSV); + DESCRIPTOR_HEAP_TYPE_DSV); struct FrameGraphExecuterData { - AZ_TYPE_INFO(FrameGraphExecuterData, "{C21547F6-DE48-4F82-B812-1A187101AB4E}"); + AZ_TYPE_INFO(AZ::DX12::FrameGraphExecuterData, "{C21547F6-DE48-4F82-B812-1A187101AB4E}"); static void Reflect(AZ::ReflectContext* context); //Cost per draw/dispatch item @@ -52,15 +52,15 @@ namespace AZ { using Base = RHI::PlatformLimitsDescriptor; public: - AZ_RTTI(DX12::PlatformLimitsDescriptor, "{ADCC8071-FCE4-4FA1-A048-DF8982951A0D}", Base); - AZ_CLASS_ALLOCATOR(PlatformLimitsDescriptor, AZ::SystemAllocator, 0); + AZ_RTTI(AZ::DX12::PlatformLimitsDescriptor, "{ADCC8071-FCE4-4FA1-A048-DF8982951A0D}", Base); + AZ_CLASS_ALLOCATOR(AZ::DX12::PlatformLimitsDescriptor, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context); PlatformLimitsDescriptor() = default; static const uint32_t NumHeapFlags = 2;// D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE + 1; - //! string key: stringifed version of DESCRIPTOR_HEAP_TYPE. + //! string key: string version of DESCRIPTOR_HEAP_TYPE. //! int array: Max count for descriptors AZStd::unordered_map> m_descriptorHeapLimits; diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp index 3c685051ea..980264aa9b 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp @@ -19,8 +19,8 @@ namespace AZ { serializeContext->Class() ->Version(0) - ->Field("m_descriptorHeapLimits", &PlatformLimitsDescriptor::m_descriptorHeapLimits) - ->Field("m_frameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) + ->Field("DescriptorHeapLimits", &PlatformLimitsDescriptor::m_descriptorHeapLimits) + ->Field("FrameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) ; } } @@ -31,11 +31,11 @@ namespace AZ { serializeContext->Class() ->Version(0) - ->Field("m_itemCost", &FrameGraphExecuterData::m_itemCost) - ->Field("m_attachmentCost", &FrameGraphExecuterData::m_attachmentCost) - ->Field("m_swapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) - ->Field("m_commandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) - ->Field("m_commandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) + ->Field("ItemCost", &FrameGraphExecuterData::m_itemCost) + ->Field("AttachmentCost", &FrameGraphExecuterData::m_attachmentCost) + ->Field("SwapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) + ->Field("CommandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) + ->Field("CommandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) ; } } diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp index 9d23dfa43d..30ed07bd22 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ +#include #include #include #include @@ -29,6 +30,13 @@ namespace AZ void DeviceCompileMemoryStatisticsInternal(RHI::MemoryStatisticsBuilder& builder, IDXGIAdapterX* dxgiAdapter); } + Device::Device() + { + RHI::Ptr platformLimitsDescriptor = aznew PlatformLimitsDescriptor(); + platformLimitsDescriptor->LoadPlatformLimitsDescriptor(RHI::Factory::Get().GetName().GetCStr()); + m_descriptor.m_platformLimitsDescriptor = RHI::Ptr(platformLimitsDescriptor); + } + RHI::Ptr Device::Create() { return aznew Device(); @@ -43,35 +51,31 @@ namespace AZ } InitFeatures(); + return RHI::ResultCode::Success; } - RHI::ResultCode Device::PostInitInternal(const RHI::DeviceDescriptor& descriptor) + RHI::ResultCode Device::InitializeLimits() { m_allocationInfoCache.SetInitFunction([](auto& cache) { cache.set_capacity(64); }); { ReleaseQueue::Descriptor releaseQueueDescriptor; - releaseQueueDescriptor.m_collectLatency = descriptor.m_frameCountMax - 1; + releaseQueueDescriptor.m_collectLatency = m_descriptor.m_frameCountMax - 1; m_releaseQueue.Init(releaseQueueDescriptor); } m_descriptorContext = AZStd::make_shared(); - RHI::ConstPtr rhiDescriptor = descriptor.m_platformLimitsDescriptor; - if (RHI::ConstPtr platLimitsDesc = azrtti_cast(rhiDescriptor)) - { - m_descriptorContext->Init(m_dx12Device.get(), platLimitsDesc); - } - else - { - AZ_Assert(false, "Missing PlatformLimits config file for DX12 backend"); - } + RHI::ConstPtr rhiDescriptor = m_descriptor.m_platformLimitsDescriptor; + RHI::ConstPtr platLimitsDesc = azrtti_cast(rhiDescriptor); + AZ_Assert(platLimitsDesc != nullptr, "Missing PlatformLimits config file for DX12 backend"); + m_descriptorContext->Init(m_dx12Device.get(), platLimitsDesc); { CommandListAllocator::Descriptor commandListAllocatorDescriptor; commandListAllocatorDescriptor.m_device = this; - commandListAllocatorDescriptor.m_frameCountMax = descriptor.m_frameCountMax; + commandListAllocatorDescriptor.m_frameCountMax = m_descriptor.m_frameCountMax; commandListAllocatorDescriptor.m_descriptorContext = m_descriptorContext; m_commandListAllocator.Init(commandListAllocatorDescriptor); } @@ -80,9 +84,9 @@ namespace AZ StagingMemoryAllocator::Descriptor allocatorDesc; allocatorDesc.m_device = this; - allocatorDesc.m_mediumPageSizeInBytes = RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_mediumStagingBufferPageSizeInBytes; - allocatorDesc.m_largePageSizeInBytes = RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_largestStagingBufferPageSizeInBytes; - allocatorDesc.m_collectLatency = descriptor.m_frameCountMax; + allocatorDesc.m_mediumPageSizeInBytes = platLimitsDesc->m_platformDefaultValues.m_mediumStagingBufferPageSizeInBytes; + allocatorDesc.m_largePageSizeInBytes = platLimitsDesc->m_platformDefaultValues.m_largestStagingBufferPageSizeInBytes; + allocatorDesc.m_collectLatency = m_descriptor.m_frameCountMax; m_stagingMemoryAllocator.Init(allocatorDesc); } @@ -90,7 +94,7 @@ namespace AZ m_commandQueueContext.Init(*this); - m_asyncUploadQueue.Init(*this, AsyncUploadQueue::Descriptor(RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_asyncQueueStagingBufferSizeInBytes)); + m_asyncUploadQueue.Init(*this, AsyncUploadQueue::Descriptor(platLimitsDesc->m_platformDefaultValues.m_asyncQueueStagingBufferSizeInBytes)); m_samplerCache.SetCapacity(SamplerCacheCapacity); diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.h b/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.h index 9119545342..4d1f2c4ac9 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.h +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/Device.h @@ -143,12 +143,11 @@ namespace AZ bool IsAftermathInitialized() const; private: - Device() = default; + Device(); ////////////////////////////////////////////////////////////////////////// // RHI::Device RHI::ResultCode InitInternal(RHI::PhysicalDevice& physicalDevice) override; - RHI::ResultCode PostInitInternal(const RHI::DeviceDescriptor & params) override; void ShutdownInternal() override; void CompileMemoryStatisticsInternal(RHI::MemoryStatisticsBuilder& builder) override; @@ -158,6 +157,7 @@ namespace AZ void WaitForIdleInternal() override; AZStd::chrono::microseconds GpuTimestampToMicroseconds(uint64_t gpuTimestamp, RHI::HardwareQueueClass queueClass) const override; void FillFormatsCapabilitiesInternal(FormatCapabilitiesList& formatsCapabilities) override; + RHI::ResultCode InitializeLimits() override; AZStd::vector GetValidSwapChainImageFormats(const RHI::WindowHandle& windowHandle) const override; void PreShutdown() override; RHI::ResourceMemoryRequirements GetResourceMemoryRequirements(const RHI::ImageDescriptor & descriptor) override; diff --git a/Gems/Atom/RHI/Metal/Code/Include/Atom/RHI.Reflect/Metal/PlatformLimitsDescriptor.h b/Gems/Atom/RHI/Metal/Code/Include/Atom/RHI.Reflect/Metal/PlatformLimitsDescriptor.h index ace3e08142..375b532d39 100644 --- a/Gems/Atom/RHI/Metal/Code/Include/Atom/RHI.Reflect/Metal/PlatformLimitsDescriptor.h +++ b/Gems/Atom/RHI/Metal/Code/Include/Atom/RHI.Reflect/Metal/PlatformLimitsDescriptor.h @@ -18,7 +18,7 @@ namespace AZ { struct FrameGraphExecuterData { - AZ_TYPE_INFO(FrameGraphExecuterData, "{BD831EFB-CC74-46F8-BE48-118B2E8F07D0}"); + AZ_TYPE_INFO(AZ::Metal::FrameGraphExecuterData, "{BD831EFB-CC74-46F8-BE48-118B2E8F07D0}"); static void Reflect(AZ::ReflectContext* context); //Cost per draw/dispatch item @@ -43,8 +43,8 @@ namespace AZ { using Base = RHI::PlatformLimitsDescriptor; public: - AZ_RTTI(Metal::PlatformLimitsDescriptor, "{B89F116F-9FEF-4BCA-9EC7-9FF8F772B7FD}", Base); - AZ_CLASS_ALLOCATOR(PlatformLimitsDescriptor, AZ::SystemAllocator, 0); + AZ_RTTI(AZ::Metal::PlatformLimitsDescriptor, "{B89F116F-9FEF-4BCA-9EC7-9FF8F772B7FD}", Base); + AZ_CLASS_ALLOCATOR(AZ::Metal::PlatformLimitsDescriptor, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context); FrameGraphExecuterData m_frameGraphExecuterData; diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp b/Gems/Atom/RHI/Metal/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp index bdf405d157..4788244775 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp @@ -18,8 +18,8 @@ namespace AZ if (SerializeContext* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_frameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) + ->Version(1) + ->Field("FrameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) ; } } @@ -29,12 +29,12 @@ namespace AZ if (auto* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_itemCost", &FrameGraphExecuterData::m_itemCost) - ->Field("m_attachmentCost", &FrameGraphExecuterData::m_attachmentCost) - ->Field("m_swapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) - ->Field("m_commandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) - ->Field("m_commandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) + ->Version(1) + ->Field("ItemCost", &FrameGraphExecuterData::m_itemCost) + ->Field("AttachmentCost", &FrameGraphExecuterData::m_attachmentCost) + ->Field("SwapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) + ->Field("CommandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) + ->Field("CommandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) ; } } diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp index 5591bcc843..782ea7174b 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp @@ -5,7 +5,9 @@ * SPDX-License-Identifier: Apache-2.0 OR MIT * */ +#include #include +#include #include #include #include @@ -27,6 +29,13 @@ namespace AZ { namespace Metal { + Device::Device() + { + RHI::Ptr platformLimitsDescriptor = aznew PlatformLimitsDescriptor(); + platformLimitsDescriptor->LoadPlatformLimitsDescriptor(RHI::Factory::Get().GetName().GetCStr()); + m_descriptor.m_platformLimitsDescriptor = RHI::Ptr(platformLimitsDescriptor); + } + RHI::Ptr Device::Create() { return aznew Device(); @@ -42,24 +51,24 @@ namespace AZ return RHI::ResultCode::Success; } - RHI::ResultCode Device::PostInitInternal(const RHI::DeviceDescriptor& descriptor) + RHI::ResultCode Device::InitializeLimits() { { ReleaseQueue::Descriptor releaseQueueDescriptor; - releaseQueueDescriptor.m_collectLatency = descriptor.m_frameCountMax; + releaseQueueDescriptor.m_collectLatency = m_descriptor.m_frameCountMax; m_releaseQueue.Init(releaseQueueDescriptor); } { CommandListAllocator::Descriptor commandListAllocatorDescriptor; - commandListAllocatorDescriptor.m_frameCountMax = descriptor.m_frameCountMax; + commandListAllocatorDescriptor.m_frameCountMax = m_descriptor.m_frameCountMax; m_commandListAllocator.Init(commandListAllocatorDescriptor, this); } m_pipelineLayoutCache.Init(*this); m_commandQueueContext.Init(*this); - m_asyncUploadQueue.Init(*this, AsyncUploadQueue::Descriptor(RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_asyncQueueStagingBufferSizeInBytes)); + m_asyncUploadQueue.Init(*this, AsyncUploadQueue::Descriptor(m_descriptor.m_platformLimitsDescriptor->m_platformDefaultValues.m_asyncQueueStagingBufferSizeInBytes)); BufferMemoryAllocator::Descriptor allocatorDescriptor; allocatorDescriptor.m_device = this; @@ -77,6 +86,7 @@ namespace AZ m_samplerCache = [[NSCache alloc]init]; [m_samplerCache setName:@"SamplerCache"]; + return RHI::ResultCode::Success; } diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.h b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.h index 9cdeee7eae..90dd4ff4a0 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.h +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.h @@ -154,12 +154,11 @@ namespace AZ void ObjectCollectionNotify(RHI::ObjectCollectorNotifyFunction notifyFunction) override; private: - Device() = default; + Device(); ////////////////////////////////////////////////////////////////////////// // RHI::Device RHI::ResultCode InitInternal(RHI::PhysicalDevice& physicalDevice) override; - RHI::ResultCode PostInitInternal(const RHI::DeviceDescriptor& params) override; void ShutdownInternal() override; void CompileMemoryStatisticsInternal(RHI::MemoryStatisticsBuilder& builder) override; void UpdateCpuTimingStatisticsInternal(RHI::CpuTimingStatistics& cpuTimingStatistics) const override; @@ -168,6 +167,7 @@ namespace AZ void WaitForIdleInternal() override; AZStd::chrono::microseconds GpuTimestampToMicroseconds(uint64_t gpuTimestamp, RHI::HardwareQueueClass queueClass) const override; void FillFormatsCapabilitiesInternal(FormatCapabilitiesList& formatsCapabilities) override; + RHI::ResultCode InitializeLimits() override; void PreShutdown() override; AZStd::vector GetValidSwapChainImageFormats(const RHI::WindowHandle& windowHandle) const override; ////////////////////////////////////////////////////////////////////////// diff --git a/Gems/Atom/RHI/Null/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/Null/Code/Source/RHI/Device.cpp index 08a2c4f411..b056071327 100644 --- a/Gems/Atom/RHI/Null/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/Null/Code/Source/RHI/Device.cpp @@ -16,6 +16,11 @@ namespace AZ return aznew Device(); } + Device::Device() + { + m_descriptor.m_platformLimitsDescriptor = aznew RHI::PlatformLimitsDescriptor; + } + void Device::FillFormatsCapabilitiesInternal(FormatCapabilitiesList& formatsCapabilities) { formatsCapabilities.fill(static_cast(~0)); diff --git a/Gems/Atom/RHI/Null/Code/Source/RHI/Device.h b/Gems/Atom/RHI/Null/Code/Source/RHI/Device.h index cd44135e62..27873887d4 100644 --- a/Gems/Atom/RHI/Null/Code/Source/RHI/Device.h +++ b/Gems/Atom/RHI/Null/Code/Source/RHI/Device.h @@ -25,12 +25,11 @@ namespace AZ static RHI::Ptr Create(); private: - Device() = default; + Device(); ////////////////////////////////////////////////////////////////////////// // RHI::Device - RHI::ResultCode InitInternal([[maybe_unused]] RHI::PhysicalDevice& physicalDevice) override { return RHI::ResultCode::Success;} - RHI::ResultCode PostInitInternal([[maybe_unused]] const RHI::DeviceDescriptor& params) override { return RHI::ResultCode::Success;} + RHI::ResultCode InitInternal([[maybe_unused]] RHI::PhysicalDevice& physicalDevice) override { return RHI::ResultCode::Success; } void ShutdownInternal() override {} void CompileMemoryStatisticsInternal([[maybe_unused]] RHI::MemoryStatisticsBuilder& builder) override {} void UpdateCpuTimingStatisticsInternal([[maybe_unused]] RHI::CpuTimingStatistics& cpuTimingStatistics) const override {} @@ -39,6 +38,7 @@ namespace AZ void WaitForIdleInternal() override {} AZStd::chrono::microseconds GpuTimestampToMicroseconds([[maybe_unused]] uint64_t gpuTimestamp, [[maybe_unused]] RHI::HardwareQueueClass queueClass) const override { return AZStd::chrono::microseconds();} void FillFormatsCapabilitiesInternal([[maybe_unused]] FormatCapabilitiesList& formatsCapabilities) override; + RHI::ResultCode InitializeLimits() override { return RHI::ResultCode::Success; } void PreShutdown() override {} RHI::ResourceMemoryRequirements GetResourceMemoryRequirements([[maybe_unused]] const RHI::ImageDescriptor& descriptor) override { return RHI::ResourceMemoryRequirements();} RHI::ResourceMemoryRequirements GetResourceMemoryRequirements([[maybe_unused]] const RHI::BufferDescriptor& descriptor) override { return RHI::ResourceMemoryRequirements();} diff --git a/Gems/Atom/RHI/Registry/Platform/Android/PlatformLimits.setreg b/Gems/Atom/RHI/Registry/Platform/Android/PlatformLimits.setreg new file mode 100644 index 0000000000..6ce3c88bbb --- /dev/null +++ b/Gems/Atom/RHI/Registry/Platform/Android/PlatformLimits.setreg @@ -0,0 +1,27 @@ +// +// Copyright (c) Contributors to the Open 3D Engine Project. +// For complete copyright and license terms please see the LICENSE at the root of this distribution. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// +// + +{ + "Amazon": + { + "Atom": + { + "RHI": + { + "PlatformLimits": + { + "metal": + { + "$type": "AZ::Vulkan::PlatformLimitsDescriptor" + } + } + } + } + } +} diff --git a/Gems/Atom/RHI/Registry/Platform/Linux/PlatformLimits.setreg b/Gems/Atom/RHI/Registry/Platform/Linux/PlatformLimits.setreg new file mode 100644 index 0000000000..7c60aeb098 --- /dev/null +++ b/Gems/Atom/RHI/Registry/Platform/Linux/PlatformLimits.setreg @@ -0,0 +1,27 @@ +// +// Copyright (c) Contributors to the Open 3D Engine Project. +// For complete copyright and license terms please see the LICENSE at the root of this distribution. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// +// + +{ + "Amazon": + { + "Atom": + { + "RHI": + { + "PlatformLimits": + { + "vulkan": + { + "$type": "AZ::Vulkan::PlatformLimitsDescriptor" + } + } + } + } + } +} diff --git a/Gems/Atom/RHI/Registry/Platform/Mac/PlatformLimits.setreg b/Gems/Atom/RHI/Registry/Platform/Mac/PlatformLimits.setreg new file mode 100644 index 0000000000..508287b762 --- /dev/null +++ b/Gems/Atom/RHI/Registry/Platform/Mac/PlatformLimits.setreg @@ -0,0 +1,27 @@ +// +// Copyright (c) Contributors to the Open 3D Engine Project. +// For complete copyright and license terms please see the LICENSE at the root of this distribution. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// +// + +{ + "Amazon": + { + "Atom": + { + "RHI": + { + "PlatformLimits": + { + "metal": + { + "$type": "AZ::Metal::PlatformLimitsDescriptor" + } + } + } + } + } +} diff --git a/Gems/Atom/RHI/Registry/Platform/Windows/PlatformLimits.setreg b/Gems/Atom/RHI/Registry/Platform/Windows/PlatformLimits.setreg new file mode 100644 index 0000000000..dd1273953b --- /dev/null +++ b/Gems/Atom/RHI/Registry/Platform/Windows/PlatformLimits.setreg @@ -0,0 +1,38 @@ +// +// Copyright (c) Contributors to the Open 3D Engine Project. +// For complete copyright and license terms please see the LICENSE at the root of this distribution. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// +// + +{ + "Amazon": + { + "Atom": + { + "RHI": + { + "PlatformLimits": + { + "dx12": + { + "$type": "AZ::DX12::PlatformLimitsDescriptor", + "DescriptorHeapLimits": + { + "DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV": [1000000, 1000000], + "DESCRIPTOR_HEAP_TYPE_SAMPLER": [2048, 2048], + "DESCRIPTOR_HEAP_TYPE_RTV": [2048, 0], + "DESCRIPTOR_HEAP_TYPE_DSV": [2048, 0] + } + }, + "vulkan": + { + "$type": "AZ::Vulkan::PlatformLimitsDescriptor" + } + } + } + } + } +} diff --git a/Gems/Atom/RHI/Registry/Platform/iOS/PlatformLimits.setreg b/Gems/Atom/RHI/Registry/Platform/iOS/PlatformLimits.setreg new file mode 100644 index 0000000000..508287b762 --- /dev/null +++ b/Gems/Atom/RHI/Registry/Platform/iOS/PlatformLimits.setreg @@ -0,0 +1,27 @@ +// +// Copyright (c) Contributors to the Open 3D Engine Project. +// For complete copyright and license terms please see the LICENSE at the root of this distribution. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// +// + +{ + "Amazon": + { + "Atom": + { + "RHI": + { + "PlatformLimits": + { + "metal": + { + "$type": "AZ::Metal::PlatformLimitsDescriptor" + } + } + } + } + } +} diff --git a/Gems/Atom/RHI/Vulkan/Code/Include/Atom/RHI.Reflect/Vulkan/PlatformLimitsDescriptor.h b/Gems/Atom/RHI/Vulkan/Code/Include/Atom/RHI.Reflect/Vulkan/PlatformLimitsDescriptor.h index d23a51f781..5e41da9627 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Include/Atom/RHI.Reflect/Vulkan/PlatformLimitsDescriptor.h +++ b/Gems/Atom/RHI/Vulkan/Code/Include/Atom/RHI.Reflect/Vulkan/PlatformLimitsDescriptor.h @@ -20,7 +20,7 @@ namespace AZ { struct FrameGraphExecuterData { - AZ_TYPE_INFO(FrameGraphExecuterData, "{648B4414-7208-4BFD-8E8F-CF2CA923ABCF}"); + AZ_TYPE_INFO(AZ::Vulkan::FrameGraphExecuterData, "{648B4414-7208-4BFD-8E8F-CF2CA923ABCF}"); static void Reflect(AZ::ReflectContext* context); //Cost per draw/dispatch item @@ -45,8 +45,8 @@ namespace AZ { using Base = RHI::PlatformLimitsDescriptor; public: - AZ_RTTI(Vulkan::PlatformLimitsDescriptor, "{23673F3F-1562-4D1B-B130-553B35B48C64}", Base); - AZ_CLASS_ALLOCATOR(PlatformLimitsDescriptor, AZ::SystemAllocator, 0); + AZ_RTTI(AZ::Vulkan::PlatformLimitsDescriptor, "{23673F3F-1562-4D1B-B130-553B35B48C64}", Base); + AZ_CLASS_ALLOCATOR(AZ::Vulkan::PlatformLimitsDescriptor, AZ::SystemAllocator, 0); static void Reflect(AZ::ReflectContext* context); FrameGraphExecuterData m_frameGraphExecuterData; diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp index d5692cb4d4..8af53c431b 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI.Reflect/PlatformLimitsDescriptor.cpp @@ -18,8 +18,8 @@ namespace AZ if (SerializeContext* serializeContext = azrtti_cast(context)) { serializeContext->Class() - ->Version(0) - ->Field("m_frameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) + ->Version(1) + ->Field("FrameGraphExecuterData", &PlatformLimitsDescriptor::m_frameGraphExecuterData) ; } } @@ -30,11 +30,11 @@ namespace AZ { serializeContext->Class() ->Version(0) - ->Field("m_itemCost", &FrameGraphExecuterData::m_itemCost) - ->Field("m_attachmentCost", &FrameGraphExecuterData::m_attachmentCost) - ->Field("m_swapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) - ->Field("m_commandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) - ->Field("m_commandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) + ->Field("ItemCost", &FrameGraphExecuterData::m_itemCost) + ->Field("AttachmentCost", &FrameGraphExecuterData::m_attachmentCost) + ->Field("SwapChainsPerCommandList", &FrameGraphExecuterData::m_swapChainsPerCommandList) + ->Field("CommandListCostThresholdMin", &FrameGraphExecuterData::m_commandListCostThresholdMin) + ->Field("CommandListsPerScopeMax", &FrameGraphExecuterData::m_commandListsPerScopeMax) ; } } diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/BufferPool.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/BufferPool.cpp index 6371b12526..12d5f9bf79 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/BufferPool.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/BufferPool.cpp @@ -49,7 +49,7 @@ namespace AZ { auto& device = static_cast(deviceBase); - VkDeviceSize bufferPageSizeInBytes = RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_bufferPoolPageSizeInBytes; + VkDeviceSize bufferPageSizeInBytes = device.GetDescriptor().m_platformLimitsDescriptor->m_platformDefaultValues.m_bufferPoolPageSizeInBytes; VkMemoryPropertyFlags additionalMemoryPropertyFlags = 0; if (const auto* descriptor = azrtti_cast(&descriptorBase)) { diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp index 05ff8bb2a6..d6cf28e78f 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp @@ -7,6 +7,8 @@ */ #include +#include +#include #include #include #include @@ -31,6 +33,13 @@ namespace AZ { namespace Vulkan { + Device::Device() + { + RHI::Ptr platformLimitsDescriptor = aznew PlatformLimitsDescriptor(); + platformLimitsDescriptor->LoadPlatformLimitsDescriptor(RHI::Factory::Get().GetName().GetCStr()); + m_descriptor.m_platformLimitsDescriptor = RHI::Ptr(platformLimitsDescriptor); + } + RHI::Ptr Device::Create() { return aznew Device(); @@ -232,7 +241,7 @@ namespace AZ return RHI::ResultCode::Success; } - RHI::ResultCode Device::PostInitInternal( const RHI::DeviceDescriptor& descriptor) + RHI::ResultCode Device::InitializeLimits() { CommandQueueContext::Descriptor commandQueueContextDescriptor; commandQueueContextDescriptor.m_frameCountMax = RHI::Limits::Device::FrameCountMax; @@ -241,7 +250,7 @@ namespace AZ // Initialize member variables. ReleaseQueue::Descriptor releaseQueueDescriptor; - releaseQueueDescriptor.m_collectLatency = descriptor.m_frameCountMax - 1; + releaseQueueDescriptor.m_collectLatency = m_descriptor.m_frameCountMax - 1; m_releaseQueue.Init(releaseQueueDescriptor); @@ -272,7 +281,7 @@ namespace AZ poolDesc.m_heapMemoryLevel = RHI::HeapMemoryLevel::Host; poolDesc.m_hostMemoryAccess = RHI::HostMemoryAccess::Write; poolDesc.m_bindFlags = RHI::BufferBindFlags::CopyRead; - poolDesc.m_budgetInBytes = RHI::RHISystemInterface::Get()->GetPlatformLimitsDescriptor()->m_platformDefaultValues.m_stagingBufferBudgetInBytes; + poolDesc.m_budgetInBytes = m_descriptor.m_platformLimitsDescriptor->m_platformDefaultValues.m_stagingBufferBudgetInBytes; result = m_stagingBufferPool->Init(*this, poolDesc); RETURN_RESULT_IF_UNSUCCESSFUL(result); diff --git a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.h b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.h index 28e56d1fa9..5a8ed04c11 100644 --- a/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.h +++ b/Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.h @@ -110,7 +110,7 @@ namespace AZ void DestroyBufferResource(VkBuffer vkBuffer) const; private: - Device() = default; + Device(); ////////////////////////////////////////////////////////////////////////// // RHI::Object @@ -120,7 +120,6 @@ namespace AZ ////////////////////////////////////////////////////////////////////////// // RHI::Device RHI::ResultCode InitInternal(RHI::PhysicalDevice& physicalDevice) override; - RHI::ResultCode PostInitInternal(const RHI::DeviceDescriptor& params) override; void ShutdownInternal() override; void BeginFrameInternal() override; @@ -131,6 +130,7 @@ namespace AZ AZStd::vector GetValidSwapChainImageFormats(const RHI::WindowHandle& windowHandle) const override; AZStd::chrono::microseconds GpuTimestampToMicroseconds(uint64_t gpuTimestamp, RHI::HardwareQueueClass queueClass) const override; void FillFormatsCapabilitiesInternal(FormatCapabilitiesList& formatsCapabilities) override; + RHI::ResultCode InitializeLimits() override; void PreShutdown() override; RHI::ResourceMemoryRequirements GetResourceMemoryRequirements(const RHI::ImageDescriptor& descriptor) override; RHI::ResourceMemoryRequirements GetResourceMemoryRequirements(const RHI::BufferDescriptor& descriptor) override; diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/RPISystem.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/RPISystem.cpp index efc050eb68..5eb9bd2d46 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/RPISystem.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/RPISystem.cpp @@ -349,19 +349,6 @@ namespace AZ return; } - //[GFX TODO][ATOM-5867] - Move file loading code within RHI to reduce coupling with RPI - AZStd::string platformLimitsFilePath = AZStd::string::format("config/platform/%s/%s/platformlimits.azasset", AZ_TRAIT_OS_PLATFORM_NAME, GetRenderApiName().GetCStr()); - AZStd::to_lower(platformLimitsFilePath.begin(), platformLimitsFilePath.end()); - - Data::Asset platformLimitsAsset; - platformLimitsAsset = RPI::AssetUtils::LoadCriticalAsset(platformLimitsFilePath.c_str(), RPI::AssetUtils::TraceLevel::None); - // Only read the m_platformLimits if the platformLimitsAsset is ready. - // The platformLimitsAsset may not exist for null renderer which is allowed - if (platformLimitsAsset.IsReady()) - { - m_descriptor.m_rhiSystemDescriptor.m_platformLimits = RPI::GetDataFromAnyAsset(platformLimitsAsset); - } - m_commonShaderAssetForSrgs = AssetUtils::LoadCriticalAsset( m_descriptor.m_commonSrgsShaderAssetPath.c_str()); if (!m_commonShaderAssetForSrgs.IsReady()) { diff --git a/Gems/Atom/RPI/Code/Tests/Common/RHI/Factory.cpp b/Gems/Atom/RPI/Code/Tests/Common/RHI/Factory.cpp index 115ccb3819..62af2852e6 100644 --- a/Gems/Atom/RPI/Code/Tests/Common/RHI/Factory.cpp +++ b/Gems/Atom/RPI/Code/Tests/Common/RHI/Factory.cpp @@ -47,7 +47,6 @@ namespace UnitTest RHI::Ptr device = Get().CreateDevice(); device->Init(*physicalDevices[0]); - device->PostInit(RHI::DeviceDescriptor{}); return device; } diff --git a/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.cpp b/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.cpp index 3d40aa27cf..a8d2ac2b0b 100644 --- a/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.cpp +++ b/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.cpp @@ -20,6 +20,11 @@ namespace UnitTest m_descriptor.m_description = "UnitTest Fake Device"; } + Device::Device() + { + m_descriptor.m_platformLimitsDescriptor = aznew RHI::PlatformLimitsDescriptor; + } + RHI::PhysicalDeviceList PhysicalDevice::Enumerate() { return RHI::PhysicalDeviceList{ aznew PhysicalDevice }; diff --git a/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.h b/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.h index be362c60d6..c3768c1ce6 100644 --- a/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.h +++ b/Gems/Atom/RPI/Code/Tests/Common/RHI/Stubs.h @@ -52,10 +52,10 @@ namespace UnitTest { public: AZ_CLASS_ALLOCATOR(Device, AZ::SystemAllocator, 0); + Device(); private: AZ::RHI::ResultCode InitInternal(AZ::RHI::PhysicalDevice&) override { return AZ::RHI::ResultCode::Success; } - AZ::RHI::ResultCode PostInitInternal(const AZ::RHI::DeviceDescriptor&) override { return AZ::RHI::ResultCode::Success; } void ShutdownInternal() override {} void BeginFrameInternal() override {} void EndFrameInternal() override {} @@ -67,6 +67,7 @@ namespace UnitTest return AZStd::chrono::microseconds(); } void FillFormatsCapabilitiesInternal([[maybe_unused]] FormatCapabilitiesList& formatsCapabilities) override {} + AZ::RHI::ResultCode InitializeLimits() override { return AZ::RHI::ResultCode::Success; } void PreShutdown() override {} AZ::RHI::ResourceMemoryRequirements GetResourceMemoryRequirements([[maybe_unused]] const AZ::RHI::ImageDescriptor& descriptor) { return AZ::RHI::ResourceMemoryRequirements{}; }; AZ::RHI::ResourceMemoryRequirements GetResourceMemoryRequirements([[maybe_unused]] const AZ::RHI::BufferDescriptor& descriptor) { return AZ::RHI::ResourceMemoryRequirements{}; };