diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/FrameCaptureBus.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/FrameCaptureBus.h index 919d1b7468..93600ec08f 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/FrameCaptureBus.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Utils/FrameCaptureBus.h @@ -31,6 +31,11 @@ namespace AZ { public: virtual ~FrameCaptureRequests() = default; + + //! Return true if frame capture is available. + //! It may return false if null renderer is used. + //! If the frame capture is not available, all capture functions in this interface would return false + virtual bool CanCapture() const = 0; //! Capture final screen output for the specified window and save it to given file path. //! The image format is determinate by file extension diff --git a/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.cpp b/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.cpp index 7374fdaf71..9f6d2a343d 100644 --- a/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.cpp @@ -8,6 +8,8 @@ #include "FrameCaptureSystemComponent.h" +#include + #include #include #include @@ -254,8 +256,18 @@ namespace AZ return AZStd::string(resolvedPath); } + bool FrameCaptureSystemComponent::CanCapture() const + { + return !AZ::RHI::IsNullRenderer(); + } + bool FrameCaptureSystemComponent::CaptureScreenshotForWindow(const AZStd::string& filePath, AzFramework::NativeWindowHandle windowHandle) { + if (!CanCapture()) + { + return false; + } + InitReadback(); if (m_state != State::Idle) @@ -301,6 +313,11 @@ namespace AZ bool FrameCaptureSystemComponent::CaptureScreenshotWithPreview(const AZStd::string& outputFilePath) { + if (!CanCapture()) + { + return false; + } + InitReadback(); if (m_state != State::Idle) @@ -350,6 +367,11 @@ namespace AZ bool FrameCaptureSystemComponent::CapturePassAttachment(const AZStd::vector& passHierarchy, const AZStd::string& slot, const AZStd::string& outputFilePath, RPI::PassAttachmentReadbackOption option) { + if (!CanCapture()) + { + return false; + } + InitReadback(); if (m_state != State::Idle) @@ -396,6 +418,11 @@ namespace AZ bool FrameCaptureSystemComponent::CapturePassAttachmentWithCallback(const AZStd::vector& passHierarchy, const AZStd::string& slotName , RPI::AttachmentReadback::CallbackFunction callback, RPI::PassAttachmentReadbackOption option) { + if (!CanCapture()) + { + return false; + } + bool result = CapturePassAttachment(passHierarchy, slotName, "", option); // Append state change to user provided call back diff --git a/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.h b/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.h index 5dbaa5dee6..20e233ce62 100644 --- a/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.h +++ b/Gems/Atom/Feature/Common/Code/Source/FrameCaptureSystemComponent.h @@ -34,6 +34,7 @@ namespace AZ void Deactivate() override; // FrameCaptureRequestBus overrides ... + bool CanCapture() const override; bool CaptureScreenshot(const AZStd::string& filePath) override; bool CaptureScreenshotForWindow(const AZStd::string& filePath, AzFramework::NativeWindowHandle windowHandle) override; bool CaptureScreenshotWithPreview(const AZStd::string& outputFilePath) override; diff --git a/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.cpp b/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.cpp new file mode 100644 index 0000000000..dc3743c101 --- /dev/null +++ b/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.cpp @@ -0,0 +1,20 @@ +/* + * 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 + * + */ +#include + + +namespace AZ +{ + namespace Null + { + RHI::Ptr Fence::Create() + { + return aznew Fence(); + } + } +} diff --git a/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.h b/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.h new file mode 100644 index 0000000000..fb64727362 --- /dev/null +++ b/Gems/Atom/RHI/Null/Code/Source/RHI/Fence.h @@ -0,0 +1,40 @@ +/* + * 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 + * + */ +#pragma once + +#include + +namespace AZ +{ + namespace Null + { + class Fence + : public RHI::Fence + { + using Base = RHI::Fence; + public: + AZ_RTTI(Fence, "{34908F40-A7DE-4EE8-A871-71ACE0C24972}", Base); + AZ_CLASS_ALLOCATOR(Fence, AZ::SystemAllocator, 0); + + static RHI::Ptr Create(); + + private: + Fence() = default; + + ////////////////////////////////////////////////////////////////////////// + // RHI::Fence + RHI::ResultCode InitInternal([[maybe_unused]] RHI::Device& device, [[maybe_unused]] RHI::FenceState initialState) override { return RHI::ResultCode::Success;} + void ShutdownInternal() override {} + void SignalOnCpuInternal() override {} + void WaitOnCpuInternal() const override {} + void ResetInternal() override {} + RHI::FenceState GetFenceStateInternal() const override { return RHI::FenceState::Signaled;}; + ////////////////////////////////////////////////////////////////////////// + }; + } +} diff --git a/Gems/Atom/RHI/Null/Code/Source/RHI/SystemComponent.cpp b/Gems/Atom/RHI/Null/Code/Source/RHI/SystemComponent.cpp index d72de7996e..091084b097 100644 --- a/Gems/Atom/RHI/Null/Code/Source/RHI/SystemComponent.cpp +++ b/Gems/Atom/RHI/Null/Code/Source/RHI/SystemComponent.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,7 @@ namespace AZ RHI::Ptr SystemComponent::CreateFence() { - return nullptr; + return Fence::Create(); } RHI::Ptr SystemComponent::CreateBuffer() diff --git a/Gems/Atom/RHI/Null/Code/atom_rhi_null_private_common_files.cmake b/Gems/Atom/RHI/Null/Code/atom_rhi_null_private_common_files.cmake index 13e16be77b..ad57002dd3 100644 --- a/Gems/Atom/RHI/Null/Code/atom_rhi_null_private_common_files.cmake +++ b/Gems/Atom/RHI/Null/Code/atom_rhi_null_private_common_files.cmake @@ -21,6 +21,8 @@ set(FILES Source/RHI/CommandQueue.h Source/RHI/Device.cpp Source/RHI/Device.h + Source/RHI/Fence.cpp + Source/RHI/Fence.h Source/RHI/FrameGraphCompiler.cpp Source/RHI/FrameGraphCompiler.h Source/RHI/FrameGraphExecuter.cpp diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/AttachmentReadback.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/AttachmentReadback.cpp index 319cf85fe5..146c37fe1b 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/AttachmentReadback.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Pass/AttachmentReadback.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,11 @@ namespace AZ bool AttachmentReadback::ReadPassAttachment(const PassAttachment* attachment, const AZ::Name& readbackName) { + if (AZ::RHI::IsNullRenderer()) + { + return false; + } + if (!IsReady()) { AZ_Assert(false, "AttachmentReadback is not ready to readback an attachment");