• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef VUKAN_PIPELINE_CREATE_FUNCTIONS_VK_H
17 #define VUKAN_PIPELINE_CREATE_FUNCTIONS_VK_H
18 
19 #include <vulkan/vulkan_core.h>
20 
21 #include <base/containers/vector.h>
22 #include <render/device/pipeline_layout_desc.h>
23 #include <render/device/pipeline_state_desc.h>
24 #include <render/namespace.h>
25 
26 #include "device/device.h"
27 #include "util/log.h"
28 #include "vulkan/node_context_descriptor_set_manager_vk.h"
29 
30 RENDER_BEGIN_NAMESPACE()
31 class DeviceVk;
32 struct RenderCommandBeginRenderPass;
33 struct RenderPassDesc;
34 struct RenderPassSubpassDesc;
35 
36 struct LowLevelRenderPassCompatibilityDescVk final {
37     struct Attachment {
38         VkFormat format { VkFormat::VK_FORMAT_UNDEFINED };
39         VkSampleCountFlagBits sampleCountFlags { VK_SAMPLE_COUNT_1_BIT };
40     };
41     Attachment attachments[PipelineStateConstants::MAX_RENDER_PASS_ATTACHMENT_COUNT];
42 };
43 
44 struct LowLevelRenderPassDataVk final : public LowLevelRenderPassData {
45     LowLevelRenderPassCompatibilityDescVk renderPassCompatibilityDesc;
46 
47     // these are not dynamic state values
48     VkViewport viewport { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
49     VkRect2D scissor { { 0, 0 }, { 0, 0 } };
50     VkExtent2D framebufferSize { 0, 0 };
51 
52     uint64_t renderPassCompatibilityHash { 0 };
53     uint64_t renderPassHash { 0 };
54 
55     VkRenderPass renderPassCompatibility { VK_NULL_HANDLE };
56     VkRenderPass renderPass { VK_NULL_HANDLE };
57     uint32_t subpassIndex { 0u };
58 
59     uint64_t frameBufferHash { 0 };
60 
61     VkFramebuffer framebuffer { VK_NULL_HANDLE };
62 };
63 
64 struct LowLevelPipelineLayoutDataVk final : public LowLevelPipelineLayoutData {
65     VkPipelineLayout pipelineLayout { VK_NULL_HANDLE };
66     PLUGIN_STATIC_ASSERT(PipelineLayoutConstants::MAX_DESCRIPTOR_SET_COUNT == 4u);
67     LowLevelDescriptorSetVk descriptorSetLayouts[PipelineLayoutConstants::MAX_DESCRIPTOR_SET_COUNT];
68 };
69 
70 // Can be used only from a single thread.
71 // Typically one context creates of RenderPassCreatorVk to control render pass creation.
72 class RenderPassCreatorVk final {
73 public:
74     RenderPassCreatorVk() = default;
75     ~RenderPassCreatorVk() = default;
76 
77     // self-contained, only uses member vector for temporary storage
78     VkRenderPass CreateRenderPass(const DeviceVk& deviceVk, const RenderCommandBeginRenderPass& beginRenderPass,
79         const LowLevelRenderPassDataVk& lowLevelRenderPassData);
80     VkRenderPass CreateRenderPassCompatibility(const DeviceVk& deviceVk, const RenderPassDesc& renderPassDesc,
81         const LowLevelRenderPassDataVk& lowLevelRenderPassData,
82         const BASE_NS::array_view<const RenderPassSubpassDesc>& renderPassSubpassDescs);
83     void DestroyRenderPass(VkDevice device, VkRenderPass renderPass);
84 
85     struct RenderPassStorage1 {
86         BASE_NS::vector<VkSubpassDescription> subpassDescriptions;
87         BASE_NS::vector<VkSubpassDependency> subpassDependencies;
88         BASE_NS::vector<VkAttachmentReference> attachmentReferences;
89     };
90     struct RenderPassStorage2 {
91         BASE_NS::vector<VkSubpassDescription2KHR> subpassDescriptions;
92         BASE_NS::vector<VkSubpassDependency2KHR> subpassDependencies;
93         BASE_NS::vector<VkAttachmentReference2KHR> attachmentReferences;
94         BASE_NS::vector<VkSubpassDescriptionDepthStencilResolveKHR> subpassDescriptionsDepthStencilResolve;
95     };
96 
97 private:
98     RenderPassStorage1 rps1_;
99     RenderPassStorage2 rps2_;
100 };
101 RENDER_END_NAMESPACE()
102 
103 #endif // VUKAN_PIPELINE_CREATE_FUNCTIONS_VK_H
104