• 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 	PipelineConstructionType	pipelineConstructionType;
47 	bool						usePipelineCache;
48 };
49 
checkSupport(Context & context,const MatchedAttachmentsTestParams params)50 void checkSupport(Context& context, const MatchedAttachmentsTestParams params)
51 {
52 	checkPipelineLibraryRequirements(context.getInstanceInterface(), context.getPhysicalDevice(), params.pipelineConstructionType);
53 }
54 
initPrograms(SourceCollections & programCollection,const MatchedAttachmentsTestParams params)55 void initPrograms (SourceCollections& programCollection, const MatchedAttachmentsTestParams params)
56 {
57 	DE_UNREF(params);
58 
59 	programCollection.glslSources.add("color_vert") << glu::VertexSource(
60 		"#version 450\n"
61 		"\n"
62 		"void main(){\n"
63 		"    gl_Position = vec4(1);\n"
64 		"}\n");
65 
66 	programCollection.glslSources.add("color_frag") << glu::FragmentSource(
67 		"#version 450\n"
68 		"\n"
69 		"layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
70 		"layout(location=0) out vec4 color;\n"
71 		"void main() {\n"
72 		"   color = subpassLoad(x);\n"
73 		"}\n");
74 }
75 
testMatchedAttachments(Context & context,const MatchedAttachmentsTestParams params)76 tcu::TestStatus testMatchedAttachments (Context& context, const MatchedAttachmentsTestParams params)
77 {
78 	const DeviceInterface&							vk								= context.getDeviceInterface();
79 	const VkDevice									vkDevice						= context.getDevice();
80 	const Unique<VkShaderModule>					vertexShaderModule				(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_vert"), 0));
81 	const Unique<VkShaderModule>					fragmentShaderModule			(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("color_frag"), 0));
82 
83 	const VkDescriptorSetLayoutBinding				descriptorSetLayoutBinding		=
84 	{
85 		0u,										// deUint32              binding;
86 		VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,	// VkDescriptorType      descriptorType;
87 		1u,										// deUint32              descriptorCount;
88 		VK_SHADER_STAGE_FRAGMENT_BIT,			// VkShaderStageFlags    stageFlags;
89 		DE_NULL									// const VkSampler*      pImmutableSamplers;
90 	};
91 
92 	const VkDescriptorSetLayoutCreateInfo			descriptorSetLayoutCreateInfo	 =
93 	{
94 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,	// VkStructureType                        sType;
95 		DE_NULL,												// const void*                            pNext;
96 		0u,														// VkDescriptorSetLayoutCreateFlags       flags;
97 		1u,														// deUint32                               bindingCount;
98 		&descriptorSetLayoutBinding								// const VkDescriptorSetLayoutBinding*    pBindings;
99 	} ;
100 
101 	const Unique<VkDescriptorSetLayout>				descriptorSetLayout				(createDescriptorSetLayout(vk, vkDevice, &descriptorSetLayoutCreateInfo, DE_NULL));
102 
103 	const VkPipelineLayoutCreateInfo				pipelineLayoutCreateInfo		=
104 	{
105 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	// VkStructureType                 sType;
106 		DE_NULL,										// const void*                     pNext;
107 		0u,												// VkPipelineLayoutCreateFlags     flags;
108 		1u,												// deUint32                        setLayoutCount;
109 		&(*descriptorSetLayout),						// const VkDescriptorSetLayout*    pSetLayouts;
110 		0u,												// deUint32                        pushConstantRangeCount;
111 		DE_NULL											// const VkPushConstantRange*      pPushConstantRanges;
112 	};
113 
114 	const Unique<VkPipelineLayout>					pipelineLayout					(createPipelineLayout(vk, vkDevice, &pipelineLayoutCreateInfo, DE_NULL));
115 
116 	const VkAttachmentDescription					descs[2]						=
117 	{
118 		{
119 			0u,											// VkAttachmentDescriptionFlags    flags;
120 			VK_FORMAT_R8G8B8A8_UNORM,					// VkFormat                        format;
121 			VK_SAMPLE_COUNT_1_BIT,						// VkSampleCountFlagBits           samples;
122 			VK_ATTACHMENT_LOAD_OP_LOAD,					// VkAttachmentLoadOp              loadOp;
123 			VK_ATTACHMENT_STORE_OP_STORE,				// VkAttachmentStoreOp             storeOp;
124 			VK_ATTACHMENT_LOAD_OP_LOAD,					// VkAttachmentLoadOp              stencilLoadOp;
125 			VK_ATTACHMENT_STORE_OP_STORE,				// VkAttachmentStoreOp             stencilStoreOp;
126 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,	// VkImageLayout                   initialLayout;
127 			VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL	// VkImageLayout                   finalLayout;
128 		},
129 		{
130 			0u,								// VkAttachmentDescriptionFlags    flags;
131 			VK_FORMAT_R8G8B8A8_UNORM,		// VkFormat                        format;
132 			VK_SAMPLE_COUNT_1_BIT,			// VkSampleCountFlagBits           samples;
133 			VK_ATTACHMENT_LOAD_OP_LOAD,		// VkAttachmentLoadOp              loadOp;
134 			VK_ATTACHMENT_STORE_OP_STORE,	// VkAttachmentStoreOp             storeOp;
135 			VK_ATTACHMENT_LOAD_OP_LOAD,		// VkAttachmentLoadOp              stencilLoadOp;
136 			VK_ATTACHMENT_STORE_OP_STORE,	// VkAttachmentStoreOp             stencilStoreOp;
137 			VK_IMAGE_LAYOUT_GENERAL,		// VkImageLayout                   initialLayout;
138 			VK_IMAGE_LAYOUT_GENERAL			// VkImageLayout                   finalLayout;
139 		}
140 	};
141 
142 	const VkAttachmentReference						color							=
143 	{
144 		0u,											// deUint32         attachment;
145 		VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL	// VkImageLayout    layout;
146 	};
147 
148 	const VkAttachmentReference						input							=
149 	{
150 		1u,						// deUint32         attachment;
151 		VK_IMAGE_LAYOUT_GENERAL	// VkImageLayout    layout;
152 	};
153 
154 	const VkSubpassDescription						subpassDescription				=
155 	{
156 		0u,									// VkSubpassDescriptionFlags       flags;
157 		VK_PIPELINE_BIND_POINT_GRAPHICS,	// VkPipelineBindPoint             pipelineBindPoint;
158 		1u,									// deUint32                        inputAttachmentCount;
159 		&input,								// const VkAttachmentReference*    pInputAttachments;
160 		1u,									// deUint32                        colorAttachmentCount;
161 		&color,								// const VkAttachmentReference*    pColorAttachments;
162 		DE_NULL,							// const VkAttachmentReference*    pResolveAttachments;
163 		DE_NULL,							// const VkAttachmentReference*    pDepthStencilAttachment;
164 		0u,									// deUint32                        preserveAttachmentCount;
165 		DE_NULL								// const deUint32*                 pPreserveAttachments;
166 	};
167 
168 	const VkRenderPassCreateInfo					renderPassCreateInfo			=
169 	{
170 		VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,	// VkStructureType                   sType;
171 		DE_NULL,									// const void*                       pNext;
172 		0u,											// VkRenderPassCreateFlags           flags;
173 		2u,											// deUint32                          attachmentCount;
174 		descs,										// const VkAttachmentDescription*    pAttachments;
175 		1u,											// deUint32                          subpassCount;
176 		&subpassDescription,						// const VkSubpassDescription*       pSubpasses;
177 		0u,											// deUint32                          dependencyCount;
178 		DE_NULL										// const VkSubpassDependency*        pDependencies;
179 	};
180 
181 	const Unique<VkRenderPass>						renderPass						(createRenderPass(vk, vkDevice, &renderPassCreateInfo, DE_NULL));
182 
183 	const VkPipelineCacheCreateInfo					pipelineCacheCreateInfo			=
184 	{
185 		VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO,					// VkStructureType               sType;
186 		DE_NULL,														// const void*                   pNext;
187 #ifndef CTS_USES_VULKANSC
188 		(VkPipelineCacheCreateFlags)0u,									// VkPipelineCacheCreateFlags    flags;
189 		0u,																// size_t                        initialDataSize;
190 		DE_NULL															// const void*                   pInitialData;
191 #else
192 		VK_PIPELINE_CACHE_CREATE_READ_ONLY_BIT |
193 			VK_PIPELINE_CACHE_CREATE_USE_APPLICATION_STORAGE_BIT,	// VkPipelineCacheCreateFlags        flags;
194 		context.getResourceInterface()->getCacheDataSize(),			// deUintptr                         initialDataSize;
195 		context.getResourceInterface()->getCacheData()				// const void*                       pInitialData;
196 #endif // CTS_USES_VULKANSC
197 	};
198 
199 	const Unique<VkPipelineCache>					pipelineCache					(createPipelineCache(vk, vkDevice, &pipelineCacheCreateInfo));
200 
201 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateCreateInfo		=
202 	{
203 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,	// VkStructureType                             sType;
204 		DE_NULL,													// const void*                                 pNext;
205 		0u,															// VkPipelineVertexInputStateCreateFlags       flags;
206 		0u,															// deUint32                                    vertexBindingDescriptionCount;
207 		DE_NULL,													// const VkVertexInputBindingDescription*      pVertexBindingDescriptions;
208 		0u,															// deUint32                                    vertexAttributeDescriptionCount;
209 		DE_NULL														// const VkVertexInputAttributeDescription*    pVertexAttributeDescriptions;
210 	};
211 
212 	const VkDynamicState							dynamicState[]					=
213 	{
214 		VK_DYNAMIC_STATE_VIEWPORT,
215 		VK_DYNAMIC_STATE_SCISSOR
216 	};
217 
218 	const VkPipelineDynamicStateCreateInfo			dynamicStateCreateInfo			=
219 	{
220 		VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,	// VkStructureType                      sType;
221 		DE_NULL,												// const void*                          pNext;
222 		0u,														// VkPipelineDynamicStateCreateFlags    flags;
223 		2u,														// deUint32                             dynamicStateCount;
224 		dynamicState											// const VkDynamicState*                pDynamicStates;
225 	};
226 
227 	const std::vector<VkViewport>	viewport{};
228 	const std::vector<VkRect2D>		scissor	{};
229 	GraphicsPipelineWrapper			graphicsPipeline(vk, vkDevice, params.pipelineConstructionType);
230 	graphicsPipeline.setDynamicState(&dynamicStateCreateInfo)
231 					.setDefaultRasterizationState()
232 					.setDefaultMultisampleState()
233 					.setDefaultColorBlendState()
234 					.setupVertexInputState(&vertexInputStateCreateInfo)
235 					.setupPreRasterizationShaderState(viewport,
236 													  scissor,
237 													  *pipelineLayout,
238 													  *renderPass,
239 													  0u,
240 													  *vertexShaderModule)
241 					.setupFragmentShaderState(*pipelineLayout, *renderPass, 0u, *fragmentShaderModule)
242 					.setupFragmentOutputState(*renderPass, 0u)
243 					.setMonolithicPipelineLayout(*pipelineLayout)
244 					.buildPipeline(params.usePipelineCache ? *pipelineCache : DE_NULL);
245 
246 	// Passes as long as createGraphicsPipeline didn't crash.
247 	return tcu::TestStatus::pass("Pass");
248 }
249 
addMatchedAttachmentsTestCasesWithFunctions(tcu::TestCaseGroup * group,PipelineConstructionType pipelineConstructionType)250 void addMatchedAttachmentsTestCasesWithFunctions (tcu::TestCaseGroup* group, PipelineConstructionType pipelineConstructionType)
251 {
252 	const MatchedAttachmentsTestParams useCache = { pipelineConstructionType, true };
253 	addFunctionCaseWithPrograms(group, "cache", "", checkSupport, initPrograms, testMatchedAttachments, useCache);
254 
255 	const MatchedAttachmentsTestParams noCache = { pipelineConstructionType, false };
256 	addFunctionCaseWithPrograms(group, "no_cache", "", checkSupport, initPrograms, testMatchedAttachments, noCache);
257 }
258 
259 } // anonymous
260 
createMatchedAttachmentsTests(tcu::TestContext & testCtx,PipelineConstructionType pipelineConstructionType)261 tcu::TestCaseGroup* createMatchedAttachmentsTests (tcu::TestContext& testCtx, PipelineConstructionType pipelineConstructionType)
262 {
263 	return createTestGroup(testCtx, "matched_attachments", "Matched attachments tests", addMatchedAttachmentsTestCasesWithFunctions, pipelineConstructionType);
264 }
265 
266 } // pipeline
267 } // vkt
268