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 
graphicsToComputeConstructionType(PipelineConstructionType pipelineConstructionType)43 inline ComputePipelineConstructionType graphicsToComputeConstructionType (PipelineConstructionType pipelineConstructionType)
44 {
45 	if (pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_UNLINKED_SPIRV || pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_LINKED_SPIRV)
46 		return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_SPIRV;
47 	if (pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_UNLINKED_BINARY || pipelineConstructionType == PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_LINKED_BINARY)
48 		return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_SHADER_OBJECT_BINARY;
49 	return COMPUTE_PIPELINE_CONSTRUCTION_TYPE_PIPELINE;
50 }
51 
52 void checkShaderObjectRequirements (const InstanceInterface&		vki,
53 									VkPhysicalDevice				physicalDevice,
54 									ComputePipelineConstructionType	computePipelineConstructionType);
55 
56 class ComputePipelineWrapper
57 {
58 public:
59 										ComputePipelineWrapper	() = default;
60 										ComputePipelineWrapper	(const DeviceInterface&					vk,
61 																 VkDevice								device,
62 																 const ComputePipelineConstructionType	pipelineConstructionType);
63 										ComputePipelineWrapper	(const DeviceInterface&					vk,
64 																 VkDevice								device,
65 																 const ComputePipelineConstructionType	pipelineConstructionType,
66 																 const ProgramBinary&					programBinary);
67 
68 										ComputePipelineWrapper	(const ComputePipelineWrapper&) noexcept;
69 										ComputePipelineWrapper	(ComputePipelineWrapper&&) noexcept;
70 										~ComputePipelineWrapper	(void) = default;
71 
72 	ComputePipelineWrapper&				operator=				(const ComputePipelineWrapper& rhs) noexcept;
73 	ComputePipelineWrapper&				operator=				(ComputePipelineWrapper&& rhs) noexcept;
74 
75 	void								setDescriptorSetLayout	(VkDescriptorSetLayout descriptorSetLayout);
76 	void								setDescriptorSetLayouts	(deUint32 setLayoutCount, const VkDescriptorSetLayout* descriptorSetLayouts);
77 	void								setSpecializationInfo	(VkSpecializationInfo specializationInfo);
78 	void								setPipelineCreateFlags	(VkPipelineCreateFlags pipelineCreateFlags);
79 	void								setPipelineCreatePNext	(void* pipelineCreatePNext);
80 	void								setSubgroupSize			(uint32_t subgroupSize);
81 	void								buildPipeline			(void);
82 	void								bind					(VkCommandBuffer commandBuffer);
83 
84 	VkPipelineLayout					getPipelineLayout		(void);
85 
86 private:
87 	void								buildPipelineLayout		(void);
88 
89 	struct InternalData;
90 
91 	// Store internal data that is needed only for pipeline construction.
92 	de::SharedPtr<InternalData>			m_internalData;
93 	const ProgramBinary*				m_programBinary;
94 	std::vector<VkDescriptorSetLayout>	m_descriptorSetLayouts;
95 	VkSpecializationInfo				m_specializationInfo;
96 	VkPipelineCreateFlags				m_pipelineCreateFlags;
97 	void*								m_pipelineCreatePNext;
98 	uint32_t							m_subgroupSize;
99 
100 	Move<VkPipeline>					m_pipeline;
101 	Move<VkPipelineLayout>				m_pipelineLayout;
102 #ifndef CTS_USES_VULKANSC
103 	Move<VkShaderEXT>					m_shader;
104 #endif
105 };
106 
107 } // vk
108 
109 #endif // _VKCOMPUTEPIPELINECONSTRUCTIONUTIL_HPP
110