From d2b5a9c709d1a1e360aec0efa96d098a5b3569a2 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 31 Mar 2019 11:23:27 -0700 Subject: Added swap chain usage flags --- Graphics/GraphicsEngine/interface/GraphicsTypes.h | 20 +++++++++++++++++++ .../include/SwapChainD3DBase.h | 23 +++++++++++++++------- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 10 +++++++++- 3 files changed, 45 insertions(+), 8 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index 746f6a67..d13a06f5 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1172,6 +1172,23 @@ namespace Diligent SCANLINE_ORDER ScanlineOrder = SCANLINE_ORDER_UNSPECIFIED; }; + /// Defines allowed swap chain usage flags + enum SWAP_CHAIN_USAGE_FLAGS : Uint32 + { + /// No allowed usage + SWAP_CHAIN_USAGE_NONE = 0x00L, + + /// Swap chain can be used as render target ouput + SWAP_CHAIN_USAGE_RENDER_TARGET = 0x01L, + + /// Swap chain images can be used as shader inputs + SWAP_CHAIN_USAGE_SHADER_INPUT = 0x02L, + + /// Swap chain images can be used as source of copy operation + SWAP_CHAIN_USAGE_COPY_SOURCE = 0x04L + }; + DEFINE_FLAG_ENUM_OPERATORS(SWAP_CHAIN_USAGE_FLAGS) + /// Swap chain description struct SwapChainDesc { @@ -1187,6 +1204,9 @@ namespace Diligent /// Depth buffer format. Default value is Diligent::TEX_FORMAT_D32_FLOAT TEXTURE_FORMAT DepthBufferFormat = TEX_FORMAT_D32_FLOAT; + /// Swap chain usage flags. Default value is Diligent::SWAP_CHAIN_USAGE_RENDER_TARGET + SWAP_CHAIN_USAGE_FLAGS Usage = SWAP_CHAIN_USAGE_RENDER_TARGET; + /// Sample count. Default value is 1 Uint32 SamplesCount = 1; diff --git a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h index db8a409c..c4cfa0b9 100644 --- a/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h +++ b/Graphics/GraphicsEngineD3DBase/include/SwapChainD3DBase.h @@ -87,7 +87,7 @@ namespace Diligent auto DXGIColorBuffFmt = TexFormatToDXGI_Format(m_SwapChainDesc.ColorBufferFormat); DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {}; - swapChainDesc.Width = m_SwapChainDesc.Width; + swapChainDesc.Width = m_SwapChainDesc.Width; swapChainDesc.Height = m_SwapChainDesc.Height; // Flip model swapchains (DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL and DXGI_SWAP_EFFECT_FLIP_DISCARD) only support the following Formats: // - DXGI_FORMAT_R16G16B16A16_FLOAT @@ -96,13 +96,22 @@ namespace Diligent // - DXGI_FORMAT_R10G10B10A2_UNORM // If RGBA8_UNORM_SRGB swap chain is required, we will create RGBA8_UNORM swap chain, but // create RGBA8_UNORM_SRGB render target view - swapChainDesc.Format = DXGIColorBuffFmt == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGIColorBuffFmt; - swapChainDesc.Stereo = FALSE; - swapChainDesc.SampleDesc.Count = 1; + swapChainDesc.Format = DXGIColorBuffFmt == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGIColorBuffFmt; + swapChainDesc.Stereo = FALSE; + swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - swapChainDesc.BufferCount = m_SwapChainDesc.BufferCount; - swapChainDesc.Scaling = DXGI_SCALING_NONE; + + DEV_CHECK_ERR(m_SwapChainDesc.Usage != 0, "No swap chain usage flags defined"); + swapChainDesc.BufferUsage = 0; + if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_RENDER_TARGET) + swapChainDesc.BufferUsage |= DXGI_USAGE_RENDER_TARGET_OUTPUT; + if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_SHADER_INPUT) + swapChainDesc.BufferUsage |= DXGI_USAGE_SHADER_INPUT; + //if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_COPY_SOURCE) + // ; + + swapChainDesc.BufferCount = m_SwapChainDesc.BufferCount; + swapChainDesc.Scaling = DXGI_SCALING_NONE; // DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL is the flip presentation model, where the contents of the back // buffer is preserved after the call to Present. This flag cannot be used with multisampling. diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index befa0db4..7277a744 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -271,7 +271,15 @@ void SwapChainVkImpl::CreateVulkanSwapChain() swapchain_ci.oldSwapchain = oldSwapchain; swapchain_ci.clipped = VK_TRUE; swapchain_ci.imageColorSpace = ColorSpace; - swapchain_ci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + + DEV_CHECK_ERR(m_SwapChainDesc.Usage != 0, "No swap chain usage flags defined"); + if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_RENDER_TARGET) + swapchain_ci.imageUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; + if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_SHADER_INPUT) + swapchain_ci.imageUsage |= VK_IMAGE_USAGE_SAMPLED_BIT; + if (m_SwapChainDesc.Usage & SWAP_CHAIN_USAGE_COPY_SOURCE) + swapchain_ci.imageUsage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; + // vkCmdClearColorImage() command requires the image to use VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL layout // that requires VK_IMAGE_USAGE_TRANSFER_DST_BIT to be set swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; -- cgit v1.2.3