diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-07-24 03:41:58 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-08-02 19:21:35 +0000 |
| commit | b35dbd3450904e5300f96f6e650d38964078fca7 (patch) | |
| tree | 99cc7d8a5401b3296e6a29fce096268ca899ac19 /Graphics/GraphicsEngine | |
| parent | Added IRenderPassVk interface (diff) | |
| download | DiligentCore-b35dbd3450904e5300f96f6e650d38964078fca7.tar.gz DiligentCore-b35dbd3450904e5300f96f6e650d38964078fca7.zip | |
Implemented RenderPassAttachmentDesc struct; added render pass creation test; WIP implementation of render pass initialization in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/include/RenderPassBase.hpp | 46 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/RenderPass.h | 88 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/RenderPassBase.cpp | 99 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/ResourceMappingBase.cpp (renamed from Graphics/GraphicsEngine/src/ResourceMapping.cpp) | 0 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/TextureBase.cpp (renamed from Graphics/GraphicsEngine/src/Texture.cpp) | 6 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/src/pch.cpp | 31 |
7 files changed, 233 insertions, 42 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt index 0c522bed..d7b51d87 100644 --- a/Graphics/GraphicsEngine/CMakeLists.txt +++ b/Graphics/GraphicsEngine/CMakeLists.txt @@ -63,8 +63,9 @@ set(SOURCE src/APIInfo.cpp src/DefaultShaderSourceStreamFactory.cpp src/EngineMemory.cpp - src/ResourceMapping.cpp - src/Texture.cpp + src/ResourceMappingBase.cpp + src/RenderPassBase.cpp + src/TextureBase.cpp ) add_library(Diligent-GraphicsEngine STATIC ${SOURCE} ${INTERFACE} ${INCLUDE}) diff --git a/Graphics/GraphicsEngine/include/RenderPassBase.hpp b/Graphics/GraphicsEngine/include/RenderPassBase.hpp index c10f39a1..03fecd78 100644 --- a/Graphics/GraphicsEngine/include/RenderPassBase.hpp +++ b/Graphics/GraphicsEngine/include/RenderPassBase.hpp @@ -37,6 +37,8 @@ namespace Diligent { +void ValidateRenderPassDesc(const RenderPassDesc& Desc); + /// Template class implementing base functionality for the render pass object. /// \tparam BaseInterface - base interface that this class will inheret @@ -60,10 +62,52 @@ public: const RenderPassDesc& Desc, bool bIsDeviceInternal = false) : TDeviceObjectBase{pRefCounters, pDevice, Desc, bIsDeviceInternal} - {} + { + ValidateRenderPassDesc(Desc); + + if (Desc.AttachmentCount != 0) + { + auto* pAttachments = + ALLOCATE(GetRawAllocator(), "Memory for RenderPassAttachmentDesc array", RenderPassAttachmentDesc, Desc.AttachmentCount); + this->m_Desc.pAttachments = pAttachments; + for (Uint32 i = 0; i < Desc.AttachmentCount; ++i) + { + pAttachments[i] = Desc.pAttachments[i]; + } + } + + if (Desc.SubpassCount != 0) + { + auto* pSubpasses = + ALLOCATE(GetRawAllocator(), "Memory for SubpassDesc array", SubpassDesc, Desc.SubpassCount); + this->m_Desc.pSubpasses = pSubpasses; + for (Uint32 i = 0; i < Desc.SubpassCount; ++i) + { + pSubpasses[i] = Desc.pSubpasses[i]; + } + } + + if (Desc.DependencyCount != 0) + { + auto* pDependencies = + ALLOCATE(GetRawAllocator(), "Memory for SubpassDependencyDesc array", SubpassDependencyDesc, Desc.DependencyCount); + this->m_Desc.pDependencies = pDependencies; + for (Uint32 i = 0; i < Desc.DependencyCount; ++i) + { + pDependencies[i] = Desc.pDependencies[i]; + } + } + } ~RenderPassBase() { + auto& RawAllocator = GetRawAllocator(); + if (this->m_Desc.pAttachments != nullptr) + RawAllocator.Free(const_cast<RenderPassAttachmentDesc*>(this->m_Desc.pAttachments)); + if (this->m_Desc.pSubpasses != nullptr) + RawAllocator.Free(const_cast<SubpassDesc*>(this->m_Desc.pSubpasses)); + if (this->m_Desc.pDependencies != nullptr) + RawAllocator.Free(const_cast<SubpassDependencyDesc*>(this->m_Desc.pDependencies)); } IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_RenderPass, TDeviceObjectBase) diff --git a/Graphics/GraphicsEngine/interface/RenderPass.h b/Graphics/GraphicsEngine/interface/RenderPass.h index 2e7c8b63..36cfc46c 100644 --- a/Graphics/GraphicsEngine/interface/RenderPass.h +++ b/Graphics/GraphicsEngine/interface/RenderPass.h @@ -40,11 +40,87 @@ DILIGENT_BEGIN_NAMESPACE(Diligent) static const struct INTERFACE_ID IID_RenderPass = { 0xb818dec7, 0x174d, 0x447a, { 0xa8, 0xe4, 0x94, 0xd2, 0x1c, 0x57, 0xb4, 0xa } }; +/// Render pass attachment load operation +DILIGENT_TYPED_ENUM(ATTACHMENT_LOAD_OP, Uint8) +{ + /// The previous contents of the texture within the render area will be preserved. + ATTACHMENT_LOAD_OP_LOAD = 0, + + /// The contents within the render area will be cleared to a uniform value, which is + /// specified when a render pass instance is begun + ATTACHMENT_LOAD_OP_CLEAR, + + /// The previous contents within the area need not be preserved; the contents of + /// the attachment will be undefined inside the render area. + ATTACHMENT_LOAD_OP_DONT_CARE +}; + +/// Render pass attachment store operation +DILIGENT_TYPED_ENUM(ATTACHMENT_STORE_OP, Uint8) +{ + /// The contents generated during the render pass and within the render area are written to memory. + ATTACHMENT_STORE_OP_STORE = 0, + + /// The contents within the render area are not needed after rendering, and may be discarded; + /// the contents of the attachment will be undefined inside the render area. + ATTACHMENT_STORE_OP_DONT_CARE +}; + + /// Render pass attachment description. struct RenderPassAttachmentDesc { - int Dummy; + /// The format of the texture view that will be used for the attachment. + TEXTURE_FORMAT Format DEFAULT_INITIALIZER(TEX_FORMAT_UNKNOWN); + + /// The number of samples in the texture. + Uint8 SampleCount DEFAULT_INITIALIZER(1); + + /// Load operation that specifies how the contents of color and depth components of + /// the attachment are treated at the beginning of the subpass where it is first used. + ATTACHMENT_LOAD_OP LoadOp DEFAULT_INITIALIZER(ATTACHMENT_LOAD_OP_LOAD); + + /// Store operation how the contents of color and depth components of the attachment + /// are treated at the end of the subpass where it is last used. + ATTACHMENT_STORE_OP StoreOp DEFAULT_INITIALIZER(ATTACHMENT_STORE_OP_STORE); + + /// Load operation that specifies how the contents of the stencil component of the + /// attachment is treated at the beginning of the subpass where it is first used. + /// This value is ignored when the format does not have stencil component. + ATTACHMENT_LOAD_OP StencilLoadOp DEFAULT_INITIALIZER(ATTACHMENT_LOAD_OP_LOAD); + + /// Store operation how the contents of the stencil component of the attachment + /// is treated at the end of the subpass where it is last used. + /// This value is ignored when the format does not have stencil component. + ATTACHMENT_STORE_OP StencilStoreOp DEFAULT_INITIALIZER(ATTACHMENT_STORE_OP_STORE); + + /// The state the attachment texture subresource will be in when a render pass instance begins. + RESOURCE_STATE InitialState DEFAULT_INITIALIZER(RESOURCE_STATE_UNKNOWN); + + /// The state the attachment texture subresource will be transitioned to when a render pass instance ends. + RESOURCE_STATE FinalState DEFAULT_INITIALIZER(RESOURCE_STATE_UNKNOWN); + + +#if DILIGENT_CPP_INTERFACE + /// Tests if two structures are equivalent + + /// \param [in] RHS - reference to the structure to perform comparison with + /// \return + /// - True if all members of the two structures are equal. + /// - False otherwise + bool operator == (const RenderPassAttachmentDesc& RHS)const + { + return Format == RHS.Format && + SampleCount == RHS.SampleCount && + LoadOp == RHS.LoadOp && + StoreOp == RHS.StoreOp && + StencilLoadOp == RHS.StencilLoadOp && + StencilStoreOp == RHS.StencilStoreOp && + InitialState == RHS.InitialState && + FinalState == RHS.FinalState; + } +#endif }; typedef struct RenderPassAttachmentDesc RenderPassAttachmentDesc; @@ -67,22 +143,22 @@ typedef struct SubpassDependencyDesc SubpassDependencyDesc; /// Render pass description struct RenderPassDesc DILIGENT_DERIVE(DeviceObjectAttribs) - /// The number of attachments. + /// The number of attachments used by the render pass. Uint32 AttachmentCount DEFAULT_INITIALIZER(0); /// Pointer to the array of subpass attachments, see Diligent::RenderPassAttachmentDesc. const RenderPassAttachmentDesc* pAttachments DEFAULT_INITIALIZER(nullptr); - /// The number of subpasses. + /// The number of subpasses in the render pass. Uint32 SubpassCount DEFAULT_INITIALIZER(0); /// Pointer to the array of subpass descriptions, see Diligent::SubpassDesc. const SubpassDesc* pSubpasses DEFAULT_INITIALIZER(nullptr); - /// The number of subpass dependencies. + /// The number of memory dependencies between pairs of subpasses. Uint32 DependencyCount DEFAULT_INITIALIZER(0); - /// The array of subpass dependencies, see Diligent::SubpassDependencyDesc. + /// Pointer to the array of subpass dependencies, see Diligent::SubpassDependencyDesc. const SubpassDependencyDesc* pDependencies DEFAULT_INITIALIZER(nullptr); }; typedef struct RenderPassDesc RenderPassDesc; @@ -95,6 +171,8 @@ typedef struct RenderPassDesc RenderPassDesc; /// Render pass has no methods. class IRenderPass : public IDeviceObject { +public: + virtual const RenderPassDesc& GetDesc() const override = 0; }; #else diff --git a/Graphics/GraphicsEngine/src/RenderPassBase.cpp b/Graphics/GraphicsEngine/src/RenderPassBase.cpp new file mode 100644 index 00000000..4c4e0abd --- /dev/null +++ b/Graphics/GraphicsEngine/src/RenderPassBase.cpp @@ -0,0 +1,99 @@ +/* + * 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. + */ + +#include "pch.h" +#include "RenderPassBase.hpp" +#include "GraphicsAccessories.hpp" +#include "Align.hpp" + +namespace Diligent +{ + +void ValidateRenderPassDesc(const RenderPassDesc& Desc) +{ +#define LOG_RENDER_PASS_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Render pass '", (Desc.Name ? Desc.Name : ""), "': ", ##__VA_ARGS__) + + for (Uint32 i = 0; i < Desc.AttachmentCount; ++i) + { + const auto& Attachment = Desc.pAttachments[i]; + if (Attachment.Format == TEX_FORMAT_UNKNOWN) + LOG_RENDER_PASS_ERROR_AND_THROW("the format of attachment ", i, " is unknown"); + + if (Attachment.SampleCount == 0) + LOG_RENDER_PASS_ERROR_AND_THROW("the sample count of attachment ", i, " is zero"); + + if (!IsPowerOfTwo(Attachment.SampleCount)) + LOG_RENDER_PASS_ERROR_AND_THROW("the sample count of attachment ", i, "(", Attachment.SampleCount, ") is not power of two"); + + const auto& FmtInfo = GetTextureFormatAttribs(Attachment.Format); + if (FmtInfo.ComponentType == COMPONENT_TYPE_DEPTH || + FmtInfo.ComponentType == COMPONENT_TYPE_DEPTH_STENCIL) + { + if (Attachment.InitialState != RESOURCE_STATE_DEPTH_WRITE && + Attachment.InitialState != RESOURCE_STATE_DEPTH_READ && + Attachment.InitialState != RESOURCE_STATE_UNORDERED_ACCESS && + Attachment.InitialState != RESOURCE_STATE_SHADER_RESOURCE && + Attachment.InitialState != RESOURCE_STATE_RESOLVE_DEST && + Attachment.InitialState != RESOURCE_STATE_RESOLVE_SOURCE) + { + LOG_RENDER_PASS_ERROR_AND_THROW("the initial state of depth-stencil attachment ", i, " (", GetResourceStateString(Attachment.InitialState), ") is invalid"); + } + + if (Attachment.FinalState != RESOURCE_STATE_DEPTH_WRITE && + Attachment.FinalState != RESOURCE_STATE_DEPTH_READ && + Attachment.FinalState != RESOURCE_STATE_UNORDERED_ACCESS && + Attachment.FinalState != RESOURCE_STATE_SHADER_RESOURCE && + Attachment.FinalState != RESOURCE_STATE_RESOLVE_DEST && + Attachment.FinalState != RESOURCE_STATE_RESOLVE_SOURCE) + { + LOG_RENDER_PASS_ERROR_AND_THROW("the final state of depth-stencil attachment ", i, " (", GetResourceStateString(Attachment.FinalState), ") is invalid"); + } + } + else + { + if (Attachment.InitialState != RESOURCE_STATE_RENDER_TARGET && + Attachment.InitialState != RESOURCE_STATE_UNORDERED_ACCESS && + Attachment.InitialState != RESOURCE_STATE_SHADER_RESOURCE && + Attachment.InitialState != RESOURCE_STATE_RESOLVE_DEST && + Attachment.InitialState != RESOURCE_STATE_RESOLVE_SOURCE) + { + LOG_RENDER_PASS_ERROR_AND_THROW("the initial state of color attachment ", i, " (", GetResourceStateString(Attachment.InitialState), ") is invalid"); + } + + if (Attachment.FinalState != RESOURCE_STATE_RENDER_TARGET && + Attachment.FinalState != RESOURCE_STATE_UNORDERED_ACCESS && + Attachment.FinalState != RESOURCE_STATE_SHADER_RESOURCE && + Attachment.FinalState != RESOURCE_STATE_RESOLVE_DEST && + Attachment.FinalState != RESOURCE_STATE_RESOLVE_SOURCE) + { + LOG_RENDER_PASS_ERROR_AND_THROW("the final state of color attachment ", i, " (", GetResourceStateString(Attachment.FinalState), ") is invalid"); + } + } + } +} + +} // namespace Diligent diff --git a/Graphics/GraphicsEngine/src/ResourceMapping.cpp b/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp index bf34056c..bf34056c 100644 --- a/Graphics/GraphicsEngine/src/ResourceMapping.cpp +++ b/Graphics/GraphicsEngine/src/ResourceMappingBase.cpp diff --git a/Graphics/GraphicsEngine/src/Texture.cpp b/Graphics/GraphicsEngine/src/TextureBase.cpp index 4cfdbd0b..e7073aae 100644 --- a/Graphics/GraphicsEngine/src/Texture.cpp +++ b/Graphics/GraphicsEngine/src/TextureBase.cpp @@ -34,7 +34,7 @@ namespace Diligent void ValidateTextureDesc(const TextureDesc& Desc) { -#define LOG_TEXTURE_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Texture \"", Desc.Name ? Desc.Name : "", "\": ", ##__VA_ARGS__) +#define LOG_TEXTURE_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Texture '", (Desc.Name ? Desc.Name : ""), "': ", ##__VA_ARGS__) if (Desc.Type == RESOURCE_DIM_UNDEFINED) { @@ -90,7 +90,7 @@ void ValidateTextureDesc(const TextureDesc& Desc) MaxDim = std::max(Desc.Width, Desc.Height); else if (Desc.Type == RESOURCE_DIM_TEX_3D) MaxDim = std::max(std::max(Desc.Width, Desc.Height), Desc.Depth); - VERIFY(MaxDim >= (1U << (Desc.MipLevels - 1)), "Texture \"", Desc.Name ? Desc.Name : "", "\": Incorrect number of Mip levels (", Desc.MipLevels, ")"); + VERIFY(MaxDim >= (1U << (Desc.MipLevels - 1)), "Texture '", Desc.Name ? Desc.Name : "", "': Incorrect number of Mip levels (", Desc.MipLevels, ")"); if (Desc.SampleCount > 1) { @@ -138,7 +138,7 @@ void ValidateTextureRegion(const TextureDesc& TexDesc, Uint32 MipLevel, Uint32 S { \ if (!(Expr)) \ { \ - LOG_ERROR("Texture \"", TexDesc.Name ? TexDesc.Name : "", "\": ", ##__VA_ARGS__); \ + LOG_ERROR("Texture '", (TexDesc.Name ? TexDesc.Name : ""), "': ", ##__VA_ARGS__); \ } \ } while (false) diff --git a/Graphics/GraphicsEngine/src/pch.cpp b/Graphics/GraphicsEngine/src/pch.cpp deleted file mode 100644 index 07ab47d2..00000000 --- a/Graphics/GraphicsEngine/src/pch.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2015-2018 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 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * 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. - */ - -// stdafx.cpp : source file that includes just the standard includes -// RenderEngine.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "pch.h" - -// TODO: reference any additional headers you need in STDAFX.H -// and not in this file |
