From e32b7a7c870e87f1524c6255a302ed596b411d66 Mon Sep 17 00:00:00 2001 From: rgba16f <82187279+rgba16f@users.noreply.github.com> Date: Wed, 14 Jul 2021 15:14:42 -0500 Subject: [PATCH] Mac m1 fixes (#2150) * Update the Mac Editor plist application bundle identifier to be different than Lumberyard Fix the editor to have runtime dependencies on the scene modules. Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com> * Fix Metal RHI calling unsupported timestamp query api on M1 Macs. Add Query for Timestamps supported on device initialization. Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com> * Remove AZ::Scene* runtime dependencies from EmotionFX gem and add AZ::SceneUI as a runtime dependency of SceneProcessing::Editor module. Signed-off-by: rgba16f <82187279+rgba16f@users.noreply.github.com> --- Code/Editor/Platform/Mac/gui_info.plist | 2 +- .../Plugins/EditorCommon/CMakeLists.txt | 4 ++++ .../Metal/Code/Source/RHI/CommandListBase.cpp | 23 +++++++++++++++--- .../Metal/Code/Source/RHI/CommandListBase.h | 2 ++ .../Atom/RHI/Metal/Code/Source/RHI/Device.cpp | 24 +++++++++++++++---- Gems/SceneProcessing/Code/CMakeLists.txt | 1 + 6 files changed, 47 insertions(+), 9 deletions(-) diff --git a/Code/Editor/Platform/Mac/gui_info.plist b/Code/Editor/Platform/Mac/gui_info.plist index 0ec7b59e98..5b5f94e977 100644 --- a/Code/Editor/Platform/Mac/gui_info.plist +++ b/Code/Editor/Platform/Mac/gui_info.plist @@ -5,7 +5,7 @@ CFBundleExecutable Editor CFBundleIdentifier - com.Amazon.Lumberyard.Editor + org.O3DE.Editor CFBundlePackageType APPL CFBundleSignature diff --git a/Code/Editor/Plugins/EditorCommon/CMakeLists.txt b/Code/Editor/Plugins/EditorCommon/CMakeLists.txt index 96d9cce5b7..048f77cd0c 100644 --- a/Code/Editor/Plugins/EditorCommon/CMakeLists.txt +++ b/Code/Editor/Plugins/EditorCommon/CMakeLists.txt @@ -46,4 +46,8 @@ ly_add_target( AZ::AzCore AZ::AzToolsFramework AZ::AzQtComponents + RUNTIME_DEPENDENCIES + AZ::AzCore + AZ::AzToolsFramework + AZ::AzQtComponents ) diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.cpp b/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.cpp index 675a593bc8..9df5f3362d 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.cpp +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.cpp @@ -30,6 +30,7 @@ namespace AZ { AZ_UNUSED(device); m_hardwareQueueClass = hardwareQueueClass; + m_supportsInterDrawTimestamps = AZ::RHI::QueryTypeFlags::Timestamp == (device->GetFeatures().m_queryTypesMask[static_cast(hardwareQueueClass)] & AZ::RHI::QueryTypeFlags::Timestamp); } void CommandListBase::Reset() @@ -64,7 +65,10 @@ namespace AZ [m_encoder endEncoding]; m_encoder = nil; #if AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING - m_timeStampQueue.clear(); + if (m_supportsInterDrawTimestamps) + { + m_timeStampQueue.clear(); + } #endif } } @@ -144,9 +148,12 @@ namespace AZ m_isEncoded = true; #if AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING - for(auto& timeStamp: m_timeStampQueue) + if (m_supportsInterDrawTimestamps) { - SampleCounters(timeStamp.m_counterSampleBuffer, timeStamp.m_timeStampIndex); + for(auto& timeStamp: m_timeStampQueue) + { + SampleCounters(timeStamp.m_counterSampleBuffer, timeStamp.m_timeStampIndex); + } } #endif } @@ -195,6 +202,11 @@ namespace AZ #if AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING void CommandListBase::SampleCounters(id counterSampleBuffer, uint32_t sampleIndex) { + if (!m_supportsInterDrawTimestamps) + { + return; + } + AZ_Assert(sampleIndex >= 0, "Invalid sample index"); //useBarrier - Inserting a barrier ensures that encoded work is complete before the GPU samples the hardware counters. //If it is true there is a performance penalty but you will get consistent results @@ -231,6 +243,11 @@ namespace AZ void CommandListBase::SamplePassCounters(id counterSampleBuffer, uint32_t sampleIndex) { + if (!m_supportsInterDrawTimestamps) + { + return; + } + if(m_encoder == nil) { //Queue the query to be activated upon encoder creation. Applies to timestamp queries diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.h b/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.h index 70678aed01..a344222e63 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.h +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/CommandListBase.h @@ -101,6 +101,8 @@ namespace AZ const AZStd::set>* m_residentHeaps = nullptr; + bool m_supportsInterDrawTimestamps = AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING; // iOS/TVOS = false, MacOS = defaults to true + #if AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING struct TimeStampData { diff --git a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp index 5e23353b65..0da2ea6aaa 100644 --- a/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp +++ b/Gems/Atom/RHI/Metal/Code/Source/RHI/Device.cpp @@ -328,14 +328,28 @@ namespace AZ m_features.m_indirectDrawSupport = false; RHI::QueryTypeFlags counterSamplingFlags = RHI::QueryTypeFlags::None; - -#if AZ_TRAIT_ATOM_METAL_COUNTER_SAMPLING - counterSamplingFlags |= (RHI::QueryTypeFlags::Timestamp | RHI::QueryTypeFlags::PipelineStatistics); - m_features.m_queryTypesMask[static_cast(RHI::HardwareQueueClass::Copy)] = RHI::QueryTypeFlags::Timestamp; + + bool supportsInterDrawTimestamps = true; +#if defined(__IPHONE_14_0) || defined(__MAC_11_0) || defined(__TVOS_14_0) + if (@available(macOS 11.0, iOS 14, tvOS 14, *)) + { + supportsInterDrawTimestamps = [m_metalDevice supportsCounterSampling:MTLCounterSamplingPointAtDrawBoundary]; + } + else #endif + { + supportsInterDrawTimestamps = ![m_metalDevice.name containsString:@"Apple"]; // Apple GPU's don't support inter draw timestamps at the M1/A14 generation + } + + if (supportsInterDrawTimestamps) + { + counterSamplingFlags |= (RHI::QueryTypeFlags::Timestamp | RHI::QueryTypeFlags::PipelineStatistics); + m_features.m_queryTypesMask[static_cast(RHI::HardwareQueueClass::Copy)] = RHI::QueryTypeFlags::Timestamp; + } + m_features.m_queryTypesMask[static_cast(RHI::HardwareQueueClass::Graphics)] = RHI::QueryTypeFlags::Occlusion | counterSamplingFlags; //Compute queue can do gfx work - m_features.m_queryTypesMask[static_cast(RHI::HardwareQueueClass::Compute)] = RHI::QueryTypeFlags::Occlusion |counterSamplingFlags; + m_features.m_queryTypesMask[static_cast(RHI::HardwareQueueClass::Compute)] = RHI::QueryTypeFlags::Occlusion | counterSamplingFlags; m_features.m_occlusionQueryPrecise = true; //Values taken from https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf diff --git a/Gems/SceneProcessing/Code/CMakeLists.txt b/Gems/SceneProcessing/Code/CMakeLists.txt index 9aa5bc6763..b33e157e51 100644 --- a/Gems/SceneProcessing/Code/CMakeLists.txt +++ b/Gems/SceneProcessing/Code/CMakeLists.txt @@ -61,6 +61,7 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS) RUNTIME_DEPENDENCIES AZ::SceneCore AZ::SceneData + AZ::SceneUI ) # the SceneProcessing.Editor module above is only used in Builders and Tools. ly_create_alias(NAME SceneProcessing.Builders NAMESPACE Gem TARGETS Gem::SceneProcessing.Editor)