1 #ifndef _VKTPIPELINESPECCONSTANTUTIL_HPP
2 #define _VKTPIPELINESPECCONSTANTUTIL_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Pipeline specialization constants test utilities
24  *//*--------------------------------------------------------------------*/
25 
26 #include "vkDefs.hpp"
27 #include "vkRef.hpp"
28 #include "vkPrograms.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkQueryUtil.hpp"
32 
33 namespace vkt
34 {
35 namespace pipeline
36 {
37 
38 class GraphicsPipelineBuilder
39 {
40 public:
GraphicsPipelineBuilder(void)41 														GraphicsPipelineBuilder			(void) : m_renderSize		(16, 16)
42 																							   , m_shaderStageFlags	(0u) {}
43 
setRenderSize(const tcu::IVec2 & size)44 	GraphicsPipelineBuilder&							setRenderSize					(const tcu::IVec2& size) { m_renderSize = size; return *this; }
45 	GraphicsPipelineBuilder&							setShader						(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo);
46 	vk::Move<vk::VkPipeline>							build							(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
47 
48 private:
49 	tcu::IVec2											m_renderSize;
50 	vk::Move<vk::VkShaderModule>						m_vertexShaderModule;
51 	vk::Move<vk::VkShaderModule>						m_fragmentShaderModule;
52 	vk::Move<vk::VkShaderModule>						m_geometryShaderModule;
53 	vk::Move<vk::VkShaderModule>						m_tessControlShaderModule;
54 	vk::Move<vk::VkShaderModule>						m_tessEvaluationShaderModule;
55 	std::vector<vk::VkPipelineShaderStageCreateInfo>	m_shaderStages;
56 	vk::VkShaderStageFlags								m_shaderStageFlags;
57 
58 														GraphicsPipelineBuilder			(const GraphicsPipelineBuilder&); // "deleted"
59 	GraphicsPipelineBuilder&							operator=						(const GraphicsPipelineBuilder&);
60 };
61 
62 enum FeatureFlagBits
63 {
64 	FEATURE_TESSELLATION_SHADER					= 1u << 0,
65 	FEATURE_GEOMETRY_SHADER						= 1u << 1,
66 	FEATURE_SHADER_FLOAT_64						= 1u << 2,
67 	FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS	= 1u << 3,
68 	FEATURE_FRAGMENT_STORES_AND_ATOMICS			= 1u << 4,
69 };
70 typedef deUint32 FeatureFlags;
71 
72 vk::VkImageCreateInfo			makeImageCreateInfo		(const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage);
73 void							requireFeatures			(const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice, const FeatureFlags flags);
74 
75 // Ugly, brute-force replacement for the initializer list
76 
77 template<typename T>
makeVector(const T & o1)78 std::vector<T> makeVector (const T& o1)
79 {
80 	std::vector<T> vec;
81 	vec.reserve(1);
82 	vec.push_back(o1);
83 	return vec;
84 }
85 
86 template<typename T>
makeVector(const T & o1,const T & o2)87 std::vector<T> makeVector (const T& o1, const T& o2)
88 {
89 	std::vector<T> vec;
90 	vec.reserve(2);
91 	vec.push_back(o1);
92 	vec.push_back(o2);
93 	return vec;
94 }
95 
96 template<typename T>
makeVector(const T & o1,const T & o2,const T & o3)97 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3)
98 {
99 	std::vector<T> vec;
100 	vec.reserve(3);
101 	vec.push_back(o1);
102 	vec.push_back(o2);
103 	vec.push_back(o3);
104 	return vec;
105 }
106 
107 template<typename T>
makeVector(const T & o1,const T & o2,const T & o3,const T & o4)108 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3, const T& o4)
109 {
110 	std::vector<T> vec;
111 	vec.reserve(4);
112 	vec.push_back(o1);
113 	vec.push_back(o2);
114 	vec.push_back(o3);
115 	vec.push_back(o4);
116 	return vec;
117 }
118 
119 } // pipeline
120 } // vkt
121 
122 #endif // _VKTPIPELINESPECCONSTANTUTIL_HPP
123