1 /* 2 * Copyright (c) 2022 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 VkImageAspectFlags aspectFlags { 0u }; 41 }; 42 Attachment attachments[PipelineStateConstants::MAX_RENDER_PASS_ATTACHMENT_COUNT]; 43 }; 44 45 struct LowLevelRenderPassDataVk final : public LowLevelRenderPassData { 46 LowLevelRenderPassCompatibilityDescVk renderPassCompatibilityDesc; 47 48 // these are not dynamic state values 49 VkViewport viewport { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; 50 VkRect2D scissor { { 0, 0 }, { 0, 0 } }; 51 VkExtent2D framebufferSize { 0, 0 }; 52 uint32_t viewMask { 0u }; 53 54 uint64_t renderPassCompatibilityHash { 0 }; 55 uint64_t renderPassHash { 0 }; 56 57 VkRenderPass renderPassCompatibility { VK_NULL_HANDLE }; 58 VkRenderPass renderPass { VK_NULL_HANDLE }; 59 uint32_t subpassIndex { 0u }; 60 61 uint64_t frameBufferHash { 0 }; 62 63 VkFramebuffer framebuffer { VK_NULL_HANDLE }; 64 65 bool isSwapchain { false }; 66 SurfaceTransformFlags surfaceTransformFlags { 0U }; 67 }; 68 69 struct LowLevelPipelineLayoutDataVk final : public LowLevelPipelineLayoutData { 70 VkPipelineLayout pipelineLayout { VK_NULL_HANDLE }; 71 PLUGIN_STATIC_ASSERT(PipelineLayoutConstants::MAX_DESCRIPTOR_SET_COUNT == 4u); 72 LowLevelDescriptorSetVk descriptorSetLayouts[PipelineLayoutConstants::MAX_DESCRIPTOR_SET_COUNT]; 73 }; 74 75 // Can be used only from a single thread. 76 // Typically one context creates of RenderPassCreatorVk to control render pass creation. 77 class RenderPassCreatorVk final { 78 public: 79 RenderPassCreatorVk() = default; 80 ~RenderPassCreatorVk() = default; 81 82 // self-contained, only uses member vector for temporary storage 83 VkRenderPass CreateRenderPass(const DeviceVk& deviceVk, const RenderCommandBeginRenderPass& beginRenderPass, 84 const LowLevelRenderPassDataVk& lowLevelRenderPassData); 85 VkRenderPass CreateRenderPassCompatibility(const DeviceVk& deviceVk, 86 const RenderCommandBeginRenderPass& beginRenderPass, const LowLevelRenderPassDataVk& lowLevelRenderPassData); 87 void DestroyRenderPass(VkDevice device, VkRenderPass renderPass); 88 89 struct RenderPassStorage1 { 90 BASE_NS::vector<VkSubpassDescription> subpassDescriptions; 91 BASE_NS::vector<VkSubpassDependency> subpassDependencies; 92 BASE_NS::vector<VkAttachmentReference> attachmentReferences; 93 94 BASE_NS::vector<uint32_t> multiViewMasks; 95 }; 96 struct RenderPassStorage2 { 97 BASE_NS::vector<VkSubpassDescription2KHR> subpassDescriptions; 98 BASE_NS::vector<VkSubpassDependency2KHR> subpassDependencies; 99 BASE_NS::vector<VkAttachmentReference2KHR> attachmentReferences; 100 BASE_NS::vector<VkSubpassDescriptionDepthStencilResolveKHR> subpassDescriptionsDepthStencilResolve; 101 #if (RENDER_VULKAN_FSR_ENABLED == 1) 102 BASE_NS::vector<VkFragmentShadingRateAttachmentInfoKHR> fragmentShadingRateAttachmentInfos; 103 #endif 104 }; 105 106 private: 107 RenderPassStorage1 rps1_; 108 RenderPassStorage2 rps2_; 109 }; 110 RENDER_END_NAMESPACE() 111 112 #endif // VUKAN_PIPELINE_CREATE_FUNCTIONS_VK_H 113