1 #ifndef _VKCOMPUTEPIPELINECONSTRUCTIONUTIL_HPP
2 #define _VKCOMPUTEPIPELINECONSTRUCTIONUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2023 LunarG, Inc.
8 * Copyright (c) 2023 Nintendo
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 *//*!
23 * \file
24 * \brief Wrapper that can construct monolithic pipeline or use
25 VK_EXT_shader_object for compute pipeline construction.
26 *//*--------------------------------------------------------------------*/
27
28 #include "vkRef.hpp"
29 #include "deSharedPtr.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkPipelineConstructionUtil.hpp"
32
33 namespace vk
34 {
35
36 enum ComputePipelineConstructionType
37 {
38 COMPUTE_PIPELINE_CONSTRUCTION_TYPE_PIPELINE = 0, // Construct monolithic pipeline
39 COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_SPIRV, // Use VK_EXT_shader_object and construct a shader object from spirv
40 COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_BINARY, // Use VK_EXT_shader_object and construct a shader object from binary
41 };
42
isComputePipelineConstructionTypeShaderObject(ComputePipelineConstructionType pipelineConstructionType)43 inline bool isComputePipelineConstructionTypeShaderObject(ComputePipelineConstructionType pipelineConstructionType)
44 {
45 return (pipelineConstructionType == COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_SPIRV ||
46 pipelineConstructionType == COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_BINARY);
47 }
48
graphicsToComputeConstructionType(PipelineConstructionType pipelineConstructionType)49 inline ComputePipelineConstructionType graphicsToComputeConstructionType(
50 PipelineConstructionType pipelineConstructionType)
51 {
52 if (pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_UNLINKED_SPIRV ||
53 pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_LINKED_SPIRV)
54 return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_SPIRV;
55 if (pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_UNLINKED_BINARY ||
56 pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_LINKED_BINARY)
57 return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_BINARY;
58 return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_PIPELINE;
59 }
60
61 void checkShaderObjectRequirements(const InstanceInterface &vki, VkPhysicalDevice physicalDevice,
62 ComputePipelineConstructionType computePipelineConstructionType);
63
64 class ComputePipelineWrapper
65 {
66 public:
67 ComputePipelineWrapper() = default;
68 ComputePipelineWrapper(const DeviceInterface &vk, VkDevice device,
69 const ComputePipelineConstructionType pipelineConstructionType);
70 ComputePipelineWrapper(const DeviceInterface &vk, VkDevice device,
71 const ComputePipelineConstructionType pipelineConstructionType,
72 const ProgramBinary &programBinary);
73
74 ComputePipelineWrapper(const ComputePipelineWrapper &) noexcept;
75 ComputePipelineWrapper(ComputePipelineWrapper &&) noexcept;
76 ~ComputePipelineWrapper(void) = default;
77
78 ComputePipelineWrapper &operator=(const ComputePipelineWrapper &rhs) noexcept;
79 ComputePipelineWrapper &operator=(ComputePipelineWrapper &&rhs) noexcept;
80
81 void setDescriptorSetLayout(VkDescriptorSetLayout descriptorSetLayout);
82 void setDescriptorSetLayouts(uint32_t setLayoutCount, const VkDescriptorSetLayout *descriptorSetLayouts);
83 void setSpecializationInfo(VkSpecializationInfo specializationInfo);
84 void setPipelineCreateFlags(VkPipelineCreateFlags pipelineCreateFlags);
85 void setPipelineCreatePNext(void *pipelineCreatePNext);
86 void setSubgroupSize(uint32_t subgroupSize);
87 void buildPipeline(void);
88 void bind(VkCommandBuffer commandBuffer);
89
90 VkPipelineLayout getPipelineLayout(void);
91
92 private:
93 void buildPipelineLayout(void);
94
95 struct InternalData;
96
97 // Store internal data that is needed only for pipeline construction.
98 de::SharedPtr<InternalData> m_internalData;
99 const ProgramBinary *m_programBinary;
100 std::vector<VkDescriptorSetLayout> m_descriptorSetLayouts;
101 VkSpecializationInfo m_specializationInfo;
102 VkPipelineCreateFlags m_pipelineCreateFlags;
103 void *m_pipelineCreatePNext;
104 uint32_t m_subgroupSize;
105
106 Move<VkPipeline> m_pipeline;
107 Move<VkPipelineLayout> m_pipelineLayout;
108 #ifndef CTS_USES_VULKANSC
109 Move<VkShaderEXT> m_shader;
110 #endif
111 };
112
113 } // namespace vk
114
115 #endif // _VKCOMPUTEPIPELINECONSTRUCTIONUTIL_HPP
116