From 955768292c4316f6e12c7cceff330a203a756337 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 24 Jul 2020 22:59:29 -0700 Subject: Implemente framebuffer in Vulkan --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 1 + .../include/FramebufferVkImpl.hpp | 14 ++++- .../GraphicsEngineVulkan/interface/FramebufferVk.h | 64 ++++++++++++++++++++++ .../GraphicsEngineVulkan/src/FramebufferVkImpl.cpp | 36 ++++++++++++ .../GraphicsEngineVulkan/src/RenderPassVkImpl.cpp | 2 +- .../GraphicsEngineVulkan/src/TextureVkImpl.cpp | 4 ++ 6 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index 26e89bba..93a811b1 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -59,6 +59,7 @@ set(INTERFACE interface/DeviceContextVk.h interface/EngineFactoryVk.h interface/FenceVk.h + interface/FramebufferVk.h interface/PipelineStateVk.h interface/QueryVk.h interface/RenderDeviceVk.h diff --git a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp index 63e56496..3e15852c 100644 --- a/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/FramebufferVkImpl.hpp @@ -30,8 +30,10 @@ /// \file /// Declaration of Diligent::FramebufferVkImpl class +#include "FramebufferVk.h" #include "FramebufferBase.hpp" #include "RenderDeviceVkImpl.hpp" +#include "VulkanUtilities/VulkanObjectWrappers.hpp" namespace Diligent { @@ -39,15 +41,23 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Render pass implementation in Direct3D11 backend. -class FramebufferVkImpl final : public FramebufferBase +class FramebufferVkImpl final : public FramebufferBase { public: - using TFramebufferBase = FramebufferBase; + using TFramebufferBase = FramebufferBase; FramebufferVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pDevice, const FramebufferDesc& Desc); ~FramebufferVkImpl(); + + VkFramebuffer GetVkFramebuffer() const override final + { + return m_VkFramebuffer; + } + +private: + VulkanUtilities::FramebufferWrapper m_VkFramebuffer; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h b/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h new file mode 100644 index 00000000..9edfb2eb --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/interface/FramebufferVk.h @@ -0,0 +1,64 @@ +/* + * Copyright 2019-2020 Diligent Graphics LLC + * Copyright 2015-2019 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +/// \file +/// Definition of the Diligent::IFramebufferVk interface + +#include "../../GraphicsEngine/interface/Framebuffer.h" + +DILIGENT_BEGIN_NAMESPACE(Diligent) + +// {846BE360-D89B-41AD-B089-7F2439ADCE3A} +static const INTERFACE_ID IID_FramebufferVk = + {0x846be360, 0xd89b, 0x41ad, {0xb0, 0x89, 0x7f, 0x24, 0x39, 0xad, 0xce, 0x3a}}; + +#define DILIGENT_INTERFACE_NAME IFramebufferVk +#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h" + +#define IFramebufferVkInclusiveMethods \ + /*IFramebufferInclusiveMethods*/ IDeviceObjectInclusiveMethods; \ + IFramebufferVkMethods FramebufferVk + +/// Exposes Vulkan-specific functionality of a Framebuffer object. +DILIGENT_BEGIN_INTERFACE(IFramebufferVk, IFramebuffer) +{ + /// Returns a Vulkan framebuffer object handle + VIRTUAL VkFramebuffer METHOD(GetVkFramebuffer)() CONST PURE; +}; +DILIGENT_END_INTERFACE + +#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h" + +#if DILIGENT_C_INTERFACE + +# define IFramebufferVk_GetVkFramebuffer(This) CALL_IFACE_METHOD(FramebufferVk, GetVkFramebuffer, This) + +#endif + +DILIGENT_END_NAMESPACE // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp index ba515950..2fc81319 100644 --- a/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/FramebufferVkImpl.cpp @@ -27,8 +27,12 @@ #include "pch.h" +#include + #include "FramebufferVkImpl.hpp" #include "EngineMemory.h" +#include "RenderPassVkImpl.hpp" +#include "TextureViewVkImpl.hpp" namespace Diligent { @@ -38,6 +42,38 @@ FramebufferVkImpl::FramebufferVkImpl(IReferenceCounters* pRefCounters, const FramebufferDesc& Desc) : TFramebufferBase{pRefCounters, pDevice, Desc} { + VkFramebufferCreateInfo FramebufferCI = {}; + + FramebufferCI.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + FramebufferCI.pNext = nullptr; + FramebufferCI.flags = 0; + + auto* pRenderPassVkImpl = ValidatedCast(m_Desc.pRenderPass); + FramebufferCI.renderPass = pRenderPassVkImpl->GetVkRenderPass(); + + FramebufferCI.attachmentCount = m_Desc.AttachmentCount; + + std::vector vkImgViews(m_Desc.AttachmentCount); + for (Uint32 i = 0; i < m_Desc.AttachmentCount; ++i) + { + if (auto* pView = m_Desc.ppAttachments[i]) + { + vkImgViews[i] = ValidatedCast(pView)->GetVulkanImageView(); + } + } + FramebufferCI.pAttachments = vkImgViews.data(); + + FramebufferCI.width = m_Desc.Width; + FramebufferCI.height = m_Desc.Height; + FramebufferCI.layers = m_Desc.NumArraySlices; + + const auto& LogicalDevice = pDevice->GetLogicalDevice(); + + m_VkFramebuffer = LogicalDevice.CreateFramebuffer(FramebufferCI, m_Desc.Name); + if (!m_VkFramebuffer) + { + LOG_ERROR_AND_THROW("Failed to create Vulkan framebuffer"); + } } FramebufferVkImpl::~FramebufferVkImpl() diff --git a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp index 23483370..5ebab9c1 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderPassVkImpl.cpp @@ -52,7 +52,7 @@ RenderPassVkImpl::RenderPassVkImpl(IReferenceCounters* pRefCounters, auto& vkAttachment = vkAttachments[i]; vkAttachment.flags = 0; vkAttachment.format = TexFormatToVkFormat(Attachment.Format); - vkAttachment.samples = static_cast(0x01 << (Attachment.SampleCount - 1)); + vkAttachment.samples = static_cast(Attachment.SampleCount); vkAttachment.loadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.LoadOp); vkAttachment.storeOp = AttachmentStoreOpToVkAttachmentStoreOp(Attachment.StoreOp); vkAttachment.stencilLoadOp = AttachmentLoadOpToVkAttachmentLoadOp(Attachment.StencilLoadOp); diff --git a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp index 2a634162..ca04f900 100644 --- a/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp @@ -139,6 +139,10 @@ TextureVkImpl::TextureVkImpl(IReferenceCounters* pRefCounters, { ImageCI.usage |= VK_IMAGE_USAGE_SAMPLED_BIT; } + if (m_Desc.BindFlags & BIND_INPUT_ATTACHMENT) + { + ImageCI.usage |= VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + } if (m_Desc.MiscFlags & MISC_TEXTURE_FLAG_GENERATE_MIPS) { -- cgit v1.2.3