• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2018 The Khronos Group Inc.
6  * Copyright (c) 2018 Google Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Matched attachments tests
23  *//*--------------------------------------------------------------------*/
24 
25 #include "vktPipelineMatchedAttachmentsTests.hpp"
26 #include "vktTestCase.hpp"
27 #include "vktTestCaseUtil.hpp"
28 #include "vktTestGroupUtil.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkPrograms.hpp"
31 #include "vkRefUtil.hpp"
32 #include "deUniquePtr.hpp"
33 
34 namespace vkt
35 {
36 namespace pipeline
37 {
38 
39 using namespace vk;
40 
41 namespace
42 {
43 
44 struct MatchedAttachmentsTestParams
45 {
46 	bool	usePipelineCache;
47 };
48 
initPrograms(SourceCollections & programCollection,const MatchedAttachmentsTestParams params)49 void initPrograms (SourceCollections& programCollection, const MatchedAttachmentsTestParams params)
50 {
51 	DE_UNREF(params);
52 
53 	programCollection.glslSources.add("color_vert") << glu::VertexSource(
54 		"#version 450\n"
55 		"\n"
56 		"void main(){\n"
57 		"    gl_Position = vec4(1);\n"
58 		"}\n");
59 
60 	programCollection.glslSources.add("color_frag") << glu::FragmentSource(
61 		"#version 450\n"
62 		"\n"
63 		"layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
64 		"layout(location=0) out vec4 color;\n"
65 		"void main() {\n"
66 		"   color = subpassLoad(x);\n"
67 		"}\n");
68 }
69 
testMatchedAttachments(Context & context,const MatchedAttachmentsTestParams params)70 tcu::TestStatus testMatchedAttachments (Context& context, const MatchedAttachmentsTestParams params)
71 {
72 	const DeviceInterface&							vk								= context.getDeviceInterface();
73 	const VkDevice									vkDevice						= context.getDevice();
74 	const Unique<VkShaderModule>					vertexShaderModule				(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_vert"), 0));
75 	const Unique<VkShaderModule>					fragmentShaderModule			(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_frag"), 0));
76 
77 	const VkDescriptorSetLayoutBinding				descriptorSetLayoutBinding		=
78 	{
79 		0u,										// deUint32              binding;
80 		VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,	// VkDescriptorType      descriptorType;
81 		1u,										// deUint32              descriptorCount;
82 		VK_SHADER_STAGE_FRAGMENT_BIT,			// VkShaderStageFlags    stageFlags;
83 		DE_NULL									// const VkSampler*      pImmutableSamplers;
84 	};
85 
86 	const VkDescriptorSetLayoutCreateInfo			descriptorSetLayoutCreateInfo	 =
87 	{
88 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,	// VkStructureType                        sType;
89 		DE_NULL,												// const void*                            pNext;
90 		0u,														// VkDescriptorSetLayoutCreateFlags       flags;
91 		1u,														// deUint32                               bindingCount;
92 		&descriptorSetLayoutBinding								// const VkDescriptorSetLayoutBinding*    pBindings;
93 	} ;
94 
95 	const Unique<VkDescriptorSetLayout>				descriptorSetLayout				(createDescriptorSetLayout(vk, vkDevice, &descriptorSetLayoutCreateInfo, DE_NULL));
96 
97 	const VkPipelineLayoutCreateInfo				pipelineLayoutCreateInfo		=
98 	{
99 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	// VkStructureType                 sType;
100 		DE_NULL,										// const void*                     pNext;
101 		0u,												// VkPipelineLayoutCreateFlags     flags;
102 		1u,												// deUint32                        setLayoutCount;
103 		&(*descriptorSetLayout),						// const VkDescriptorSetLayout*    pSetLayouts;
104 		0u,												// deUint32                        pushConstantRangeCount;
105 		DE_NULL											// const VkPushConstantRange*      pPushConstantRanges;
106 	};
107 
108 	const Unique<VkPipelineLayout>					pipelineLayout					(createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo, DE_NULL));
109 
110 	const VkAttachmentDescription					descs[2]						=
111 	{
112 		{
113 			0u,											// VkAttachmentDescriptionFlags    flags;
114 			VK_FORMAT_R8G8B8A8_UNORM,					// VkFormat                        format;
115 			VK_SAMPLE_COUNT_1_BIT,						// VkSampleCountFlagBits           samples;
116 			VK_ATTACHMENT_LOAD_OP_LOAD,					// VkAttachmentLoadOp              loadOp;
117 			VK_ATTACHMENT_STORE_OP_STORE,				// VkAttachmentStoreOp             storeOp;
118 			VK_ATTACHMENT_LOAD_OP_LOAD,					// VkAttachmentLoadOp              stencilLoadOp;
119 			VK_ATTACHMENT_STORE_OP_STORE,				// VkAttachmentStoreOp             stencilStoreOp;
120 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,	// VkImageLayout                   initialLayout;
121 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL	// VkImageLayout                   finalLayout;
122 		},
123 		{
124 			0u,								// VkAttachmentDescriptionFlags    flags;
125 			VK_FORMAT_R8G8B8A8_UNORM,		// VkFormat                        format;
126 			VK_SAMPLE_COUNT_1_BIT,			// VkSampleCountFlagBits           samples;
127 			VK_ATTACHMENT_LOAD_OP_LOAD,		// VkAttachmentLoadOp              loadOp;
128 			VK_ATTACHMENT_STORE_OP_STORE,	// VkAttachmentStoreOp             storeOp;
129 			VK_ATTACHMENT_LOAD_OP_LOAD,		// VkAttachmentLoadOp              stencilLoadOp;
130 			VK_ATTACHMENT_STORE_OP_STORE,	// VkAttachmentStoreOp             stencilStoreOp;
131 			VK_IMAGE_LAYOUT_GENERAL,		// VkImageLayout                   initialLayout;
132 			VK_IMAGE_LAYOUT_GENERAL			// VkImageLayout                   finalLayout;
133 		}
134 	};
135 
136 	const VkAttachmentReference						color							=
137 	{
138 		0u,											// deUint32         attachment;
139 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL	// VkImageLayout    layout;
140 	};
141 
142 	const VkAttachmentReference						input							=
143 	{
144 		1u,						// deUint32         attachment;
145 		VK_IMAGE_LAYOUT_GENERAL	// VkImageLayout    layout;
146 	};
147 
148 	const VkSubpassDescription						subpassDescription				=
149 	{
150 		0u,									// VkSubpassDescriptionFlags       flags;
151 		VK_PIPELINE_BIND_POINT_GRAPHICS,	// VkPipelineBindPoint             pipelineBindPoint;
152 		1u,									// deUint32                        inputAttachmentCount;
153 		&input,								// const VkAttachmentReference*    pInputAttachments;
154 		1u,									// deUint32                        colorAttachmentCount;
155 		&color,								// const VkAttachmentReference*    pColorAttachments;
156 		DE_NULL,							// const VkAttachmentReference*    pResolveAttachments;
157 		DE_NULL,							// const VkAttachmentReference*    pDepthStencilAttachment;
158 		0u,									// deUint32                        preserveAttachmentCount;
159 		DE_NULL								// const deUint32*                 pPreserveAttachments;
160 	};
161 
162 	const VkRenderPassCreateInfo					renderPassCreateInfo			=
163 	{
164 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,	// VkStructureType                   sType;
165 		DE_NULL,									// const void*                       pNext;
166 		0u,											// VkRenderPassCreateFlags           flags;
167 		2u,											// deUint32                          attachmentCount;
168 		descs,										// const VkAttachmentDescription*    pAttachments;
169 		1u,											// deUint32                          subpassCount;
170 		&subpassDescription,						// const VkSubpassDescription*       pSubpasses;
171 		0u,											// deUint32                          dependencyCount;
172 		DE_NULL										// const VkSubpassDependency*        pDependencies;
173 	};
174 
175 	const Unique<VkRenderPass>						renderPass						(createRenderPass(vk, vkDevice, &renderPassCreateInfo, DE_NULL));
176 
177 	const VkPipelineCacheCreateInfo					pipelineCacheCreateInfo			=
178 	{
179 		VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,	// VkStructureType               sType;
180 		DE_NULL,										// const void*                   pNext;
181 		0u,												// VkPipelineCacheCreateFlags    flags;
182 		0u,												// size_t                        initialDataSize;
183 		DE_NULL											// const void*                   pInitialData;
184 	};
185 
186 	const Unique<VkPipelineCache>					pipelineCache					(createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
187 
188 	const VkPipelineShaderStageCreateInfo			stages[]						=
189 	{
190 		{
191 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType;
192 			DE_NULL,												// const void*                         pNext;
193 			0u,														// VkPipelineShaderStageCreateFlags    flags;
194 			VK_SHADER_STAGE_VERTEX_BIT,								// VkShaderStageFlagBits               stage;
195 			*vertexShaderModule,									// VkShaderModule                      module;
196 			"main",													// const char*                         pName;
197 			DE_NULL													// const VkSpecializationInfo*         pSpecializationInfo;
198 		},
199 		{
200 			VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType                     sType;
201 			DE_NULL,												// const void*                         pNext;
202 			0u,														// VkPipelineShaderStageCreateFlags    flags;
203 			VK_SHADER_STAGE_FRAGMENT_BIT,							// VkShaderStageFlagBits               stage;
204 			*fragmentShaderModule,									// VkShaderModule                      module;
205 			"main",													// const char*                         pName;
206 			DE_NULL													// const VkSpecializationInfo*         pSpecializationInfo;
207 		}
208 	};
209 
210 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfo		=
211 	{
212 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType                             sType;
213 		DE_NULL,													// const void*                                 pNext;
214 		0u,															// VkPipelineVertexInputStateCreateFlags       flags;
215 		0u,															// deUint32                                    vertexBindingDescriptionCount;
216 		DE_NULL,													// const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
217 		0u,															// deUint32                                    vertexAttributeDescriptionCount;
218 		DE_NULL														// const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
219 	};
220 
221 	const VkPipelineInputAssemblyStateCreateInfo	inputAssemblyStateCreateInfo	=
222 	{
223 		VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,	// VkStructureType                            sType;
224 		DE_NULL,														// const void*                                pNext;
225 		0u,																// VkPipelineInputAssemblyStateCreateFlags    flags;
226 		VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,							// VkPrimitiveTopology                        topology;
227 		VK_FALSE														// VkBool32                                   primitiveRestartEnable;
228 	};
229 
230 	const VkPipelineViewportStateCreateInfo			viewportStateCreateInfo			=
231 	{
232 		VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,	// VkStructureType                       sType;
233 		DE_NULL,												// const void*                           pNext;
234 		0u,														// VkPipelineViewportStateCreateFlags    flags;
235 		1u,														// deUint32                              viewportCount;
236 		DE_NULL,												// const VkViewport*                     pViewports;
237 		1u,														// deUint32                              scissorCount;
238 		DE_NULL													// const VkRect2D*                       pScissors;
239 	};
240 
241 	const VkPipelineRasterizationStateCreateInfo	rasterizationStateCreateInfo	=
242 	{
243 		VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,	// VkStructureType                            sType;
244 		DE_NULL,													// const void*                                pNext;
245 		0u,															// VkPipelineRasterizationStateCreateFlags    flags;
246 		VK_FALSE,													// VkBool32                                   depthClampEnable;
247 		VK_FALSE,													// VkBool32                                   rasterizerDiscardEnable;
248 		VK_POLYGON_MODE_FILL,										// VkPolygonMode                              polygonMode;
249 		VK_CULL_MODE_BACK_BIT,										// VkCullModeFlags                            cullMode;
250 		VK_FRONT_FACE_CLOCKWISE,									// VkFrontFace                                frontFace;
251 		VK_FALSE,													// VkBool32                                   depthBiasEnable;
252 		0.0f,														// float                                      depthBiasConstantFactor;
253 		0.0f,														// float                                      depthBiasClamp;
254 		0.0f,														// float                                      depthBiasSlopeFactor;
255 		1.0f														// float                                      lineWidth;
256 	};
257 
258 	const VkPipelineMultisampleStateCreateInfo		multisampleStateCreateInfo		=
259 	{
260 		VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,	// VkStructureType                          sType;
261 		DE_NULL,													// const void*                              pNext;
262 		0u,															// VkPipelineMultisampleStateCreateFlags    flags;
263 		VK_SAMPLE_COUNT_1_BIT,										// VkSampleCountFlagBits                    rasterizationSamples;
264 		VK_FALSE,													// VkBool32                                 sampleShadingEnable;
265 		0.0f,														// float                                    minSampleShading;
266 		DE_NULL,													// const VkSampleMask*                      pSampleMask;
267 		VK_FALSE,													// VkBool32                                 alphaToCoverageEnable;
268 		VK_FALSE													// VkBool32                                 alphaToOneEnable;
269 	};
270 
271 	const VkPipelineColorBlendAttachmentState		colorBlendAttachmentState		=
272 	{
273 		VK_FALSE,				// VkBool32                 blendEnable;
274 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            srcColorBlendFactor;
275 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstColorBlendFactor;
276 		VK_BLEND_OP_ADD,		// VkBlendOp                colorBlendOp;
277 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            srcAlphaBlendFactor;
278 		VK_BLEND_FACTOR_ZERO,	// VkBlendFactor            dstAlphaBlendFactor;
279 		VK_BLEND_OP_ADD,		// VkBlendOp                alphaBlendOp;
280 		0xf						// VkColorComponentFlags    colorWriteMask;
281 	};
282 
283 	const VkPipelineColorBlendStateCreateInfo		colorBlendStateCreateInfo		=
284 	{
285 		VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,	// VkStructureType                               sType;
286 		DE_NULL,													// const void*                                   pNext;
287 		0u,															// VkPipelineColorBlendStateCreateFlags          flags;
288 		VK_FALSE,													// VkBool32                                      logicOpEnable;
289 		VK_LOGIC_OP_COPY,											// VkLogicOp                                     logicOp;
290 		1u,															// deUint32                                      attachmentCount;
291 		&colorBlendAttachmentState,									// const VkPipelineColorBlendAttachmentState*    pAttachments;
292 		{ 1.0f, 1.0f, 1.0f, 1.0f }									// float                                         blendConstants[4];
293 	};
294 
295 	const VkDynamicState							dynamicState[]					=
296 	{
297 		VK_DYNAMIC_STATE_VIEWPORT,
298 		VK_DYNAMIC_STATE_SCISSOR
299 	};
300 
301 	const VkPipelineDynamicStateCreateInfo			dynamicStateCreateInfo			=
302 	{
303 		VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,	// VkStructureType                      sType;
304 		DE_NULL,												// const void*                          pNext;
305 		0u,														// VkPipelineDynamicStateCreateFlags    flags;
306 		2u,														// deUint32                             dynamicStateCount;
307 		dynamicState											// const VkDynamicState*                pDynamicStates;
308 	};
309 
310 	const VkGraphicsPipelineCreateInfo				graphicsPipelineCreateInfo		=
311 	{
312 		VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,	// VkStructureType                                  sType;
313 		DE_NULL,											// const void*                                      pNext;
314 		0u,													// VkPipelineCreateFlags                            flags;
315 		2u,													// deUint32                                         stageCount;
316 		stages,												// const VkPipelineShaderStageCreateInfo*           pStages;
317 		&vertexInputStateCreateInfo,						// const VkPipelineVertexInputStateCreateInfo*      pVertexInputState;
318 		&inputAssemblyStateCreateInfo,						// const VkPipelineInputAssemblyStateCreateInfo*    pInputAssemblyState;
319 		DE_NULL,											// const VkPipelineTessellationStateCreateInfo*     pTessellationState;
320 		&viewportStateCreateInfo,							// const VkPipelineViewportStateCreateInfo*         pViewportState;
321 		&rasterizationStateCreateInfo,						// const VkPipelineRasterizationStateCreateInfo*    pRasterizationState;
322 		&multisampleStateCreateInfo,						// const VkPipelineMultisampleStateCreateInfo*      pMultisampleState;
323 		DE_NULL,											// const VkPipelineDepthStencilStateCreateInfo*     pDepthStencilState;
324 		&colorBlendStateCreateInfo,							// const VkPipelineColorBlendStateCreateInfo*       pColorBlendState;
325 		&dynamicStateCreateInfo,							// const VkPipelineDynamicStateCreateInfo*          pDynamicState;
326 		*pipelineLayout,									// VkPipelineLayout                                 layout;
327 		*renderPass,										// VkRenderPass                                     renderPass;
328 		0u,													// deUint32                                         subpass;
329 		DE_NULL,											// VkPipeline                                       basePipelineHandle;
330 		0													// int                                              basePipelineIndex;
331 	};
332 
333 	createGraphicsPipeline(vk, vkDevice, params.usePipelineCache ? *pipelineCache : DE_NULL, &graphicsPipelineCreateInfo);
334 
335 	// Passes as long as createGraphicsPipeline didn't crash.
336 	return tcu::TestStatus::pass("Pass");
337 }
338 
addMatchedAttachmentsTestCasesWithFunctions(tcu::TestCaseGroup * group)339 void addMatchedAttachmentsTestCasesWithFunctions (tcu::TestCaseGroup* group)
340 {
341 	const MatchedAttachmentsTestParams useCache = { true };
342 	addFunctionCaseWithPrograms(group, "cache", "", initPrograms, testMatchedAttachments, useCache);
343 
344 	const MatchedAttachmentsTestParams noCache = { false };
345 	addFunctionCaseWithPrograms(group, "no_cache", "", initPrograms, testMatchedAttachments, noCache);
346 }
347 
348 } // anonymous
349 
createMatchedAttachmentsTests(tcu::TestContext & testCtx)350 tcu::TestCaseGroup* createMatchedAttachmentsTests (tcu::TestContext& testCtx)
351 {
352 	return createTestGroup(testCtx, "matched_attachments", "Matched attachments tests", addMatchedAttachmentsTestCasesWithFunctions);
353 }
354 
355 } // pipeline
356 } // vkt
357