|
@@ -5,15 +5,28 @@
|
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
*
|
|
|
*/
|
|
|
-#include <RHI/SwapChain.h>
|
|
|
+
|
|
|
+#include <RHI/SwapChain_Windows.h>
|
|
|
+
|
|
|
#include <RHI/Device.h>
|
|
|
#include <RHI/Conversions.h>
|
|
|
+#include <RHI/Image.h>
|
|
|
#include <RHI/NsightAftermath.h>
|
|
|
|
|
|
namespace AZ
|
|
|
{
|
|
|
namespace DX12
|
|
|
{
|
|
|
+ RHI::Ptr<SwapChain> SwapChain::Create()
|
|
|
+ {
|
|
|
+ return aznew SwapChain();
|
|
|
+ }
|
|
|
+
|
|
|
+ Device& SwapChain::GetDevice() const
|
|
|
+ {
|
|
|
+ return static_cast<Device&>(RHI::SwapChain::GetDevice());
|
|
|
+ }
|
|
|
+
|
|
|
RHI::ResultCode SwapChain::InitInternal(RHI::Device& deviceBase, const RHI::SwapChainDescriptor& descriptor, RHI::SwapChainDimensions* nativeDimensions)
|
|
|
{
|
|
|
// Check whether tearing support is available for full screen borderless windowed mode.
|
|
@@ -165,6 +178,47 @@ namespace AZ
|
|
|
return GetCurrentImageIndex();
|
|
|
}
|
|
|
|
|
|
+ RHI::ResultCode SwapChain::InitImageInternal(const InitImageRequest& request)
|
|
|
+ {
|
|
|
+ Device& device = GetDevice();
|
|
|
+
|
|
|
+ Microsoft::WRL::ComPtr<ID3D12Resource> resource;
|
|
|
+ DX12::AssertSuccess(m_swapChain->GetBuffer(request.m_imageIndex, IID_GRAPHICS_PPV_ARGS(resource.GetAddressOf())));
|
|
|
+
|
|
|
+ D3D12_RESOURCE_ALLOCATION_INFO allocationInfo;
|
|
|
+ device.GetImageAllocationInfo(request.m_descriptor, allocationInfo);
|
|
|
+
|
|
|
+ Name name(AZStd::string::format("SwapChainImage_%d", request.m_imageIndex));
|
|
|
+
|
|
|
+ Image& image = static_cast<Image&>(*request.m_image);
|
|
|
+ image.m_memoryView = MemoryView(resource.Get(), 0, allocationInfo.SizeInBytes, allocationInfo.Alignment, MemoryViewType::Image);
|
|
|
+ image.SetName(name);
|
|
|
+ image.GenerateSubresourceLayouts();
|
|
|
+ // Overwrite m_initialAttachmentState because Swapchain images are created with D3D12_RESOURCE_STATE_COMMON state
|
|
|
+ image.SetAttachmentState(D3D12_RESOURCE_STATE_COMMON);
|
|
|
+
|
|
|
+ RHI::HeapMemoryUsage& memoryUsage = m_memoryUsage.GetHeapMemoryUsage(RHI::HeapMemoryLevel::Device);
|
|
|
+ memoryUsage.m_reservedInBytes += allocationInfo.SizeInBytes;
|
|
|
+ memoryUsage.m_residentInBytes += allocationInfo.SizeInBytes;
|
|
|
+
|
|
|
+ return RHI::ResultCode::Success;
|
|
|
+ }
|
|
|
+
|
|
|
+ void SwapChain::ShutdownResourceInternal(RHI::Resource& resourceBase)
|
|
|
+ {
|
|
|
+ Image& image = static_cast<Image&>(resourceBase);
|
|
|
+
|
|
|
+ const size_t sizeInBytes = image.GetMemoryView().GetSize();
|
|
|
+
|
|
|
+ RHI::HeapMemoryUsage& memoryUsage = m_memoryUsage.GetHeapMemoryUsage(RHI::HeapMemoryLevel::Device);
|
|
|
+ memoryUsage.m_reservedInBytes -= sizeInBytes;
|
|
|
+ memoryUsage.m_residentInBytes -= sizeInBytes;
|
|
|
+
|
|
|
+ GetDevice().QueueForRelease(image.m_memoryView);
|
|
|
+
|
|
|
+ image.m_memoryView = {};
|
|
|
+ }
|
|
|
+
|
|
|
RHI::ResultCode SwapChain::ResizeInternal(const RHI::SwapChainDimensions& dimensions, RHI::SwapChainDimensions* nativeDimensions)
|
|
|
{
|
|
|
GetDevice().WaitForIdle();
|