• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VULKAN_PIPELINE_STATE_OBJECT_VK_H
17 #define VULKAN_PIPELINE_STATE_OBJECT_VK_H
18 
19 #include <cstdint>
20 #include <vulkan/vulkan_core.h>
21 
22 #include <base/containers/vector.h>
23 #include <render/device/pipeline_state_desc.h>
24 #include <render/namespace.h>
25 
26 #include "device/pipeline_state_object.h"
27 
28 RENDER_BEGIN_NAMESPACE()
29 class Device;
30 class GpuComputeProgram;
31 class GpuShaderProgram;
32 struct PipelineLayout;
33 struct LowLevelRenderPassData;
34 struct LowLevelPipelineLayoutData;
35 
36 struct PipelineStateObjectPlatformDataVk final {
37     VkPipeline pipeline { VK_NULL_HANDLE };
38     VkPipelineLayout pipelineLayout { VK_NULL_HANDLE };
39 };
40 
41 class GraphicsPipelineStateObjectVk final : public GraphicsPipelineStateObject {
42 public:
43     GraphicsPipelineStateObjectVk(Device& device, const GpuShaderProgram& gpuShaderProgram,
44         const GraphicsState& graphicsState, const PipelineLayout& pipelineLayout,
45         const VertexInputDeclarationView& vertexInputDeclaration,
46         const ShaderSpecializationConstantDataView& specializationConstants,
47         const BASE_NS::array_view<const DynamicStateEnum> dynamicStates,
48         const BASE_NS::array_view<const RenderPassSubpassDesc>& renderPassSubpassDescs, const uint32_t subpassIndex,
49         const LowLevelRenderPassData& renderPassData, const LowLevelPipelineLayoutData& pipelineLayoutData);
50     ~GraphicsPipelineStateObjectVk() override;
51 
52     const PipelineStateObjectPlatformDataVk& GetPlatformData() const;
53 
54     struct SpecializationData {
55         BASE_NS::vector<VkSpecializationMapEntry> vs;
56         BASE_NS::vector<VkSpecializationMapEntry> fs;
57 
58         // data copied into this for additional modifications
59         struct ShaderSpecializationConstantData {
60             BASE_NS::vector<ShaderSpecialization::Constant> constants;
61             BASE_NS::vector<uint32_t> data;
62         };
63         ShaderSpecializationConstantData constantData;
64 
65         SurfaceTransformFlags surfaceTransformFlags { 0U };
66 
ClearSpecializationData67         void Clear()
68         {
69             vs.clear();
70             fs.clear();
71             constantData.constants.clear();
72             constantData.data.clear();
73             surfaceTransformFlags = 0U;
74         }
75     };
76 
77 private:
78     Device& device_;
79 
80     PipelineStateObjectPlatformDataVk plat_;
81     SpecializationData specializationData_;
82 };
83 
84 class ComputePipelineStateObjectVk final : public ComputePipelineStateObject {
85 public:
86     ComputePipelineStateObjectVk(Device& device, const GpuComputeProgram& gpuComputeProgram,
87         const PipelineLayout& pipelineLayout, const ShaderSpecializationConstantDataView& specializationConstants,
88         const LowLevelPipelineLayoutData& pipelineLayoutData);
89     ~ComputePipelineStateObjectVk() override;
90 
91     const PipelineStateObjectPlatformDataVk& GetPlatformData() const;
92 
93 private:
94     Device& device_;
95 
96     PipelineStateObjectPlatformDataVk plat_;
97 };
98 RENDER_END_NAMESPACE()
99 
100 #endif // VULKAN_PIPELINE_STATE_OBJECT_VK_H
101