• 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 Intel Corporation
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 VK_EXT_conditional_rendering extension tests.
23 *//*--------------------------------------------------------------------*/
24 
25 #include "vktConditionalDrawAndClearTests.hpp"
26 
27 #include "vktTestCaseUtil.hpp"
28 #include "vktDrawBaseClass.hpp"
29 #include "vktDrawTestCaseUtil.hpp"
30 #include "vkBuilderUtil.hpp"
31 #include "vkObjUtil.hpp"
32 #include "vkCmdUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkTypeUtil.hpp"
35 
36 #include <bitset>
37 
38 namespace vkt
39 {
40 namespace conditional
41 {
42 namespace
43 {
44 
45 using namespace vk;
46 using namespace Draw;
47 
48 enum ConditionalBufferMemory { LOCAL, HOST };
49 
50 struct ClearTestParams
51 {
52 	bool						m_discard;
53 	bool						m_invert;
54 	bool						m_testDepth;
55 	bool						m_partialClear;
56 	bool						m_useOffset;
57 	bool						m_clearAttachmentTwice;
58 	ConditionalBufferMemory		m_memoryType;
59 };
60 
61 const ClearTestParams clearColorTestGrid[] =
62 {
63 	{ false,	false,		false,		false,		false,		false,		HOST },
64 	{ true,		false,		false,		false,		false,		false,		HOST },
65 	{ false,	true,		false,		false,		false,		false,		HOST },
66 	{ true,		true,		false,		false,		false,		false,		HOST },
67 	{ false,	false,		false,		true,		false,		false,		HOST },
68 	{ true,		false,		false,		true,		false,		false,		HOST },
69 	{ false,	true,		false,		true,		false,		false,		HOST },
70 	{ true,		true,		false,		true,		false,		false,		HOST },
71 	{ false,	false,		false,		true,		true,		false,		HOST },
72 	{ true,		false,		false,		true,		true,		false,		HOST },
73 	{ false,	true,		false,		true,		true,		false,		HOST },
74 	{ true,		true,		false,		true,		true,		false,		HOST },
75 	{ true,		true,		false,		false,		true,		false,		HOST },
76 
77 	{ false,	false,		false,		false,		false,		false,		LOCAL },
78 	{ true,		false,		false,		false,		false,		false,		LOCAL },
79 	{ false,	true,		false,		false,		false,		false,		LOCAL },
80 	{ true,		true,		false,		false,		false,		false,		LOCAL },
81 	{ false,	false,		false,		true,		false,		false,		LOCAL },
82 	{ true,		false,		false,		true,		false,		false,		LOCAL },
83 	{ false,	true,		false,		true,		false,		false,		LOCAL },
84 	{ true,		true,		false,		true,		false,		false,		LOCAL },
85 	{ false,	false,		false,		true,		true,		false,		LOCAL },
86 	{ true,		false,		false,		true,		true,		false,		LOCAL },
87 	{ false,	true,		false,		true,		true,		false,		LOCAL },
88 	{ true,		true,		false,		true,		true,		false,		LOCAL },
89 	{ true,		true,		false,		false,		true,		false,		LOCAL },
90 };
91 
92 const ClearTestParams clearDepthTestGrid[] =
93 {
94 	{ false,	false,		true,		false,		false,		false,		HOST },
95 	{ true,		false,		true,		false,		false,		false,		HOST },
96 	{ false,	 true,		true,		false,		false,		false,		HOST },
97 	{ true,		true,		true,		false,		false,		false,		HOST },
98 	{ false,	false,		true,		true,		false,		false,		HOST },
99 	{ true,		false,		true,		true,		false,		false,		HOST },
100 	{ false,	true,		true,		true,		false,		false,		HOST },
101 	{ true,		true,		true,		true,		false,		false,		HOST },
102 	{ false,	false,		true,		true,		true,		false,		HOST },
103 	{ true,		false,		true,		true,		true,		false,		HOST },
104 	{ false,	true,		true,		true,		true,		false,		HOST },
105 	{ true,		true,		true,		true,		true,		false,		HOST },
106 
107 	{ false,	false,		true,		false,		false,		false,		LOCAL },
108 	{ true,		false,		true,		false,		false,		false,		LOCAL },
109 	{ false,	 true,		true,		false,		false,		false,		LOCAL },
110 	{ true,		true,		true,		false,		false,		false,		LOCAL },
111 	{ false,	false,		true,		true,		false,		false,		LOCAL },
112 	{ true,		false,		true,		true,		false,		false,		LOCAL },
113 	{ false,	true,		true,		true,		false,		false,		LOCAL },
114 	{ true,		true,		true,		true,		false,		false,		LOCAL },
115 	{ false,	false,		true,		true,		true,		false,		LOCAL },
116 	{ true,		false,		true,		true,		true,		false,		LOCAL },
117 	{ false,	true,		true,		true,		true,		false,		LOCAL },
118 	{ true,		true,		true,		true,		true,		false,		LOCAL },
119 };
120 
121 const ClearTestParams clearColorTwiceGrid[] =
122 {
123 	{ false,	false,		false,		false,		false,		true,		HOST },
124 	{ true,		false,		false,		false,		false,		true,		HOST },
125 	{ false,	true,		false,		false,		false,		true,		HOST },
126 	{ true,		true,		false,		false,		false,		true,		HOST },
127 	{ false,	true,		false,		true,		true,		true,		HOST },
128 	{ true,		true,		false,		true,		true,		true,		HOST },
129 
130 	{ false,	false,		false,		false,		false,		true,		LOCAL },
131 	{ true,		false,		false,		false,		false,		true,		LOCAL },
132 	{ false,	true,		false,		false,		false,		true,		LOCAL },
133 	{ true,		true,		false,		false,		false,		true,		LOCAL },
134 	{ false,	true,		false,		true,		true,		true,		LOCAL },
135 	{ true,		true,		false,		true,		true,		true,		LOCAL },
136 };
137 
138 const ClearTestParams clearDepthTwiceGrid[] =
139 {
140 	{ false,	false,		true,		false,		false,		true,		HOST },
141 	{ true,		false,		true,		false,		false,		true,		HOST },
142 	{ false,	true,		true,		false,		false,		true,		HOST },
143 	{ true,		true,		true,		false,		false,		true,		HOST },
144 	{ false,	true,		true,		true,		true,		true,		HOST },
145 	{ true,		true,		true,		true,		true,		true,		HOST },
146 
147 	{ false,	false,		true,		false,		false,		true,		LOCAL },
148 	{ true,		false,		true,		false,		false,		true,		LOCAL },
149 	{ false,	true,		true,		false,		false,		true,		LOCAL },
150 	{ true,		true,		true,		false,		false,		true,		LOCAL },
151 	{ false,	true,		true,		true,		true,		true,		LOCAL },
152 	{ true,		true,		true,		true,		true,		true,		LOCAL },
153 };
154 
155 enum TogglePredicateMode { FILL, COPY, NONE };
156 
157 struct DrawTestParams
158 {
159 	bool						m_discard; //controls the setting of the predicate for conditional rendering.Initial state, may be toggled later depending on the m_togglePredicate setting.
160 	bool						m_invert;
161 	bool						m_useOffset;
162 	deUint32					m_beginSequenceBits; //bits 0..3 control BEFORE which of the 4 draw calls the vkCmdBeginConditionalRenderingEXT call is executed. Least significant bit corresponds to the first draw call.
163 	deUint32					m_endSequenceBits; //bits 0..3 control AFTER which of the 4 draw calls the vkCmdEndConditionalRenderingEXT call is executed. Least significant bit corresponds to the first draw call.
164 	deUint32					m_resultBits; //used for reference image preparation.
165 	bool						m_togglePredicate; //if true, toggle the predicate setting before rendering.
166 	TogglePredicateMode			m_toggleMode; //method of the predicate toggling
167 	ConditionalBufferMemory		m_memoryType; //type of memory used for conditional rendering buffer
168 };
169 
170 enum
171 {
172 	b0000 = 0x0,
173 	b0001 = 0x1,
174 	b0010 = 0x2,
175 	b0011 = 0x3,
176 	b0100 = 0x4,
177 	b0101 = 0x5,
178 	b0110 = 0x6,
179 	b0111 = 0x7,
180 	b1000 = 0x8,
181 	b1001 = 0x9,
182 	b1010 = 0xA,
183 	b1011 = 0xB,
184 	b1100 = 0xC,
185 	b1101 = 0xD,
186 	b1110 = 0xE,
187 	b1111 = 0xF,
188 };
189 
190 const DrawTestParams drawTestGrid[] =
191 {
192 	{ false,	false,	false,	b0001, b1000, b1111, false,	NONE, HOST },
193 	{ true,		false,	false,	b0001, b1000, b0000, false,	NONE, HOST },
194 	{ true,		false,	false,	b0001, b0001, b1110, false,	NONE, HOST },
195 	{ true,		false,	false,	b1111, b1111, b0000, false,	NONE, HOST },
196 	{ true,		false,	false,	b0010, b0010, b1101, false,	NONE, HOST },
197 	{ true,		true,	false,	b1010, b1010, b0101, false,	NONE, HOST },
198 	{ false,	true,	true,	b1010, b1010, b1111, false,	NONE, HOST },
199 	{ true,		true,	true,	b0010, b1000, b0001, false,	NONE, HOST },
200 	{ true,		true,	true,	b1001, b1001, b0110, false,	NONE, HOST },
201 	{ true,		true,	true,	b0010, b1000, b1111, true,	FILL, HOST },
202 	{ true,		true,	true,	b1001, b1001, b1111, true,	FILL, HOST },
203 	{ false,	true,	true,	b1001, b1001, b0110, true,	FILL, HOST },
204 	{ true,		true,	true,	b0010, b1000, b1111, true,	COPY, HOST },
205 	{ true,		true,	true,	b1001, b1001, b1111, true,	COPY, HOST },
206 	{ false,	true,	true,	b1001, b1001, b0110, true,	COPY, HOST },
207 
208 	{ false,	false,	false,	b0001, b1000, b1111, false,	NONE, LOCAL },
209 	{ true,		false,	false,	b0001, b1000, b0000, false,	NONE, LOCAL },
210 	{ true,		false,	false,	b0001, b0001, b1110, false,	NONE, LOCAL },
211 	{ true,		false,	false,	b1111, b1111, b0000, false,	NONE, LOCAL },
212 	{ true,		false,	false,	b0010, b0010, b1101, false,	NONE, LOCAL },
213 	{ true,		true,	false,	b1010, b1010, b0101, false,	NONE, LOCAL },
214 	{ false,	true,	true,	b1010, b1010, b1111, false,	NONE, LOCAL },
215 	{ true,		true,	true,	b0010, b1000, b0001, false,	NONE, LOCAL },
216 	{ true,		true,	true,	b1001, b1001, b0110, false,	NONE, LOCAL },
217 	{ true,		true,	true,	b0010, b1000, b1111, true,	FILL, LOCAL },
218 	{ true,		true,	true,	b1001, b1001, b1111, true,	FILL, LOCAL },
219 	{ false,	true,	true,	b1001, b1001, b0110, true,	FILL, LOCAL },
220 	{ true,		true,	true,	b0010, b1000, b1111, true,	COPY, LOCAL },
221 	{ true,		true,	true,	b1001, b1001, b1111, true,	COPY, LOCAL },
222 	{ false,	true,	true,	b1001, b1001, b0110, true,	COPY, LOCAL },
223 };
224 
225 struct UpdateBufferWithDrawTestParams
226 {
227 	bool				m_testParams;
228 	ConditionalBufferMemory		m_memoryType;
229 };
230 
231 const UpdateBufferWithDrawTestParams UpdateBufferWithDrawTestGrind[] =
232 {
233 	{ true,		HOST },
234 	{ false,	HOST },
235 
236 	{ true,		LOCAL },
237 	{ false,	LOCAL },
238 };
239 
generateClearTestName(const ClearTestParams & clearTestParams)240 std::string generateClearTestName(const ClearTestParams& clearTestParams)
241 {
242 	std::string		name			=	(clearTestParams.m_discard		? "discard_"	:	"no_discard_");
243 	name			+=	(clearTestParams.m_invert		? "invert_"		:	"no_invert_");
244 	name			+=	(clearTestParams.m_partialClear	? "partial_"	:	"full_");
245 	name			+=	(clearTestParams.m_useOffset	? "offset_"		:	"no_offset_");
246 	name			+=  (clearTestParams.m_memoryType   ? "host_memory" :	"local_memory");
247 	return name;
248 }
249 
generateDrawTestName(uint32_t ndx,const DrawTestParams & drawTestParams)250 std::string generateDrawTestName(uint32_t ndx, const DrawTestParams& drawTestParams)
251 {
252 	std::string		name = "case_";
253 	name			+=	de::toString(ndx);
254 	name			+=  (drawTestParams.m_memoryType   ? "_host_memory" :	"_local_memory");
255 	return name;
256 }
257 
258 
generateUpdateBufferWithDrawTestName(const UpdateBufferWithDrawTestParams & updateBufferTestParams)259 std::string generateUpdateBufferWithDrawTestName(const UpdateBufferWithDrawTestParams& updateBufferTestParams)
260 {
261 	std::string name = "update_with_rendering_";
262 	name			+= (updateBufferTestParams.m_testParams	? "discard_"	: "no_discard_");
263 	name			+= (updateBufferTestParams.m_memoryType ? "host_memory" : "local_memory");
264 	return name;
265 }
266 
getBit(deUint32 src,int ndx)267 inline deUint32 getBit(deUint32 src, int ndx)
268 {
269 	return (src >> ndx) & 1;
270 }
271 
isBitSet(deUint32 src,int ndx)272 inline bool isBitSet(deUint32 src, int ndx)
273 {
274 	return getBit(src, ndx) != 0;
275 }
276 
277 class ConditionalRenderingBaseTestInstance : public TestInstance
278 {
279 public:
280 									ConditionalRenderingBaseTestInstance					(Context& context);
281 protected:
282 	virtual tcu::TestStatus			iterate													(void) = 0;
283 	void							createInitBufferWithPredicate							(ConditionalBufferMemory memoryType, bool discard, bool invert, deUint32 offsetMultiplier, VkBufferUsageFlagBits extraUsage);
284 	void							createTargetColorImageAndImageView						(void);
285 	void							createTargetDepthImageAndImageView						(void);
286 	void							createRenderPass										(VkFormat format, VkImageLayout layout);
287 	void							createFramebuffer										(VkImageView imageView);
288 	void							clearWithClearColorImage								(const VkClearColorValue& color);
289 	void							clearWithClearDepthStencilImage							(const VkClearDepthStencilValue& value);
290 	void							clearColorWithClearAttachments							(const VkClearColorValue& color, bool partial);
291 	void							clearDepthWithClearAttachments							(const VkClearDepthStencilValue& depthStencil, bool partial);
292 	void							createResultBuffer										(VkFormat format);
293 	void							createVertexBuffer										(void);
294 	void							createPipelineLayout									(void);
295 	void							createAndUpdateDescriptorSet							(void);
296 	void							createPipeline											(void);
297 	void							copyResultImageToBuffer									(VkImageAspectFlags imageAspectFlags, VkImage image);
298 	void							draw													(void);
299 	void							imageMemoryBarrier										(VkImage image, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout,
300 																							VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageAspectFlags imageAspectFlags);
301 	void							bufferMemoryBarrier										(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask,
302 																							VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask);
303 	void							prepareReferenceImageOneColor							(tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColor);
304 	void							prepareReferenceImageOneColor							(tcu::PixelBufferAccess& reference, const tcu::Vec4& color);
305 	void							prepareReferenceImageOneDepth							(tcu::PixelBufferAccess& reference, const VkClearDepthStencilValue& clearValue);
306 	void							prepareReferenceImageDepthClearPartial					(tcu::PixelBufferAccess& reference, const VkClearDepthStencilValue& clearValueInitial, const VkClearDepthStencilValue& clearValueFinal);
307 	void							prepareReferenceImageColorClearPartial					(tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColorInitial, const VkClearColorValue& clearColorFinal);
308 
309 	const InstanceInterface&		m_vki;
310 	const DeviceInterface&			m_vkd;
311 	const VkDevice					m_device;
312 	const VkPhysicalDevice			m_physicalDevice;
313 	const VkQueue					m_queue;
314 	de::SharedPtr<Buffer>			m_conditionalRenderingBuffer;
315 	de::SharedPtr<Buffer>			m_resultBuffer;
316 	de::SharedPtr<Buffer>			m_vertexBuffer;
317 	de::SharedPtr<Image>			m_colorTargetImage;
318 	de::SharedPtr<Image>			m_depthTargetImage;
319 	Move<VkImageView>				m_colorTargetView;
320 	Move<VkImageView>				m_depthTargetView;
321 	Move<VkRenderPass>				m_renderPass;
322 	Move<VkFramebuffer>				m_framebuffer;
323 	Move<VkCommandPool>				m_cmdPool;
324 	Move<VkCommandBuffer>			m_cmdBufferPrimary;
325 	Move<VkDescriptorPool>			m_descriptorPool;
326 	Move<VkDescriptorSetLayout>		m_descriptorSetLayout;
327 	Move<VkDescriptorSet>			m_descriptorSet;
328 	Move<VkPipelineLayout>			m_pipelineLayout;
329 	Move<VkShaderModule>			m_vertexShaderModule;
330 	Move<VkShaderModule>			m_fragmentShaderModule;
331 	Move<VkPipeline>				m_pipeline;
332 	VkDeviceSize					m_conditionalRenderingBufferOffset;
333 
334 	enum
335 	{
336 		WIDTH = 256,
337 		HEIGHT = 256
338 	};
339 };
340 
341 class ConditionalRenderingClearAttachmentsTestInstance : public ConditionalRenderingBaseTestInstance
342 {
343 public:
344 									ConditionalRenderingClearAttachmentsTestInstance		(Context& context, const ClearTestParams& testParams);
345 protected:
346 	virtual tcu::TestStatus			iterate													(void);
347 	ClearTestParams					m_testParams;
348 };
349 
350 class ConditionalRenderingDrawTestInstance : public ConditionalRenderingBaseTestInstance
351 {
352 public:
353 									ConditionalRenderingDrawTestInstance					(Context& context, const DrawTestParams& testParams);
354 protected:
355 	//Execute 4 draw calls, each can be drawn with or without conditional rendering. Each draw call renders to the different part of an image - this is achieved by
356 	//using push constant and 'discard' in the fragment shader. This way it is possible to tell which of the rendering command were discarded by the conditional rendering mechanism.
357 	virtual tcu::TestStatus			iterate													(void);
358 	void							createPipelineLayout									(void);
359 	void							prepareReferenceImage									(tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColor, deUint32 resultBits);
360 
361 	DrawTestParams					m_testParams;
362 	de::SharedPtr<Buffer>			m_conditionalRenderingBufferForCopy;
363 };
364 
365 class ConditionalRenderingUpdateBufferWithDrawTestInstance : public ConditionalRenderingBaseTestInstance
366 {
367 public:
368 									ConditionalRenderingUpdateBufferWithDrawTestInstance	(Context& context, UpdateBufferWithDrawTestParams testParams);
369 protected:
370 	virtual tcu::TestStatus			iterate													(void);
371 	void							createAndUpdateDescriptorSets							(void);
372 	void							createPipelines											(void);
373 	void							createRenderPass										(VkFormat format, VkImageLayout layout);
374 	Move<VkDescriptorSet>			m_descriptorSetUpdate;
375 	Move<VkShaderModule>			m_vertexShaderModuleDraw;
376 	Move<VkShaderModule>			m_fragmentShaderModuleDraw;
377 	Move<VkShaderModule>			m_vertexShaderModuleUpdate;
378 	Move<VkShaderModule>			m_fragmentShaderModuleDiscard;
379 	Move<VkPipeline>				m_pipelineDraw;
380 	Move<VkPipeline>				m_pipelineUpdate;
381 	UpdateBufferWithDrawTestParams	m_testParams;
382 };
383 
ConditionalRenderingBaseTestInstance(Context & context)384 ConditionalRenderingBaseTestInstance::ConditionalRenderingBaseTestInstance (Context& context)
385 	: TestInstance							(context)
386 	, m_vki									(m_context.getInstanceInterface())
387 	, m_vkd									(m_context.getDeviceInterface())
388 	, m_device								(m_context.getDevice())
389 	, m_physicalDevice						(m_context.getPhysicalDevice())
390 	, m_queue								(m_context.getUniversalQueue())
391 	, m_conditionalRenderingBufferOffset	(0)
392 {
393 }
394 
createInitBufferWithPredicate(ConditionalBufferMemory memoryType,bool discard,bool invert,deUint32 offsetMultiplier=0,VkBufferUsageFlagBits extraUsage=(VkBufferUsageFlagBits)0)395 void ConditionalRenderingBaseTestInstance::createInitBufferWithPredicate (ConditionalBufferMemory memoryType, bool discard, bool invert, deUint32 offsetMultiplier = 0, VkBufferUsageFlagBits extraUsage = (VkBufferUsageFlagBits)0)
396 {
397 	m_conditionalRenderingBufferOffset		= sizeof(deUint32) * offsetMultiplier;
398 
399 	const VkDeviceSize						dataSize										= sizeof(deUint32) + m_conditionalRenderingBufferOffset;
400 	deUint32								predicate										= discard ? invert : !invert;
401 	const auto								usage											= (memoryType ? VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT : VK_BUFFER_USAGE_TRANSFER_SRC_BIT) | extraUsage;
402 
403 	de::SharedPtr<Draw::Buffer> buffer = Buffer::createAndAlloc
404 	(
405 		m_vkd, m_device,
406 		BufferCreateInfo( dataSize, usage ),
407 		m_context.getDefaultAllocator(),
408 		MemoryRequirement::HostVisible
409 	);
410 
411 	void * conditionalRenderingBufferDataPointer = static_cast<char*>(buffer->getBoundMemory().getHostPtr()) + m_conditionalRenderingBufferOffset;
412 
413 	deMemcpy(conditionalRenderingBufferDataPointer, &predicate, static_cast<size_t>(sizeof(deUint32)));
414 	flushMappedMemoryRange(m_vkd, m_device, buffer->getBoundMemory().getMemory(), buffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
415 
416 	if(memoryType == ConditionalBufferMemory::LOCAL)
417 	{
418 		m_conditionalRenderingBuffer = Buffer::createAndAlloc
419 		(
420 			m_vkd, m_device,
421 			BufferCreateInfo
422 			(
423 				dataSize,
424 				VK_BUFFER_USAGE_CONDITIONAL_RENDERING_BIT_EXT
425 				| VK_BUFFER_USAGE_TRANSFER_DST_BIT
426 				| extraUsage
427 			),
428 			m_context.getDefaultAllocator(),
429 			MemoryRequirement::Local
430 		);
431 
432 		auto cmdBuffer = vk::allocateCommandBuffer
433 		(
434 			m_vkd, m_device,
435 			*m_cmdPool,
436 			vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY
437 		);
438 
439 		const vk::VkCommandBufferBeginInfo commandBufferBeginInfo =
440 		{
441 			vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
442 			DE_NULL,
443 			vk::VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
444 			nullptr
445 		};
446 
447 		VK_CHECK(m_vkd.beginCommandBuffer(*cmdBuffer, &commandBufferBeginInfo));
448 
449 		vk::VkBufferCopy copyInfo
450 		{
451 			buffer->getBoundMemory().getOffset(),
452 			m_conditionalRenderingBuffer->getBoundMemory().getOffset(),
453 			static_cast<size_t>(dataSize)
454 		};
455 		m_vkd.cmdCopyBuffer(*cmdBuffer, buffer->object(), m_conditionalRenderingBuffer->object(), 1, &copyInfo);
456 		m_vkd.endCommandBuffer(*cmdBuffer);
457 
458 		vk::VkSubmitInfo submitInfo{};
459 		submitInfo.sType = vk::VK_STRUCTURE_TYPE_SUBMIT_INFO;
460 		submitInfo.commandBufferCount = 1;
461 		submitInfo.pCommandBuffers = &(*cmdBuffer);
462 
463 		auto queue = m_context.getUniversalQueue();
464 
465 		m_vkd.queueSubmit(queue, 1, &submitInfo, 0);
466 
467 		m_vkd.queueWaitIdle(queue);
468 	}
469 	else
470 	{
471 		m_conditionalRenderingBuffer = buffer;
472 	}
473 }
474 
createTargetColorImageAndImageView(void)475 void ConditionalRenderingBaseTestInstance::createTargetColorImageAndImageView (void)
476 {
477 	const VkExtent3D			targetImageExtent		= { WIDTH, HEIGHT, 1 };
478 
479 	const ImageCreateInfo		targetImageCreateInfo(	VK_IMAGE_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM, targetImageExtent, 1, 1, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_TILING_OPTIMAL,
480 														VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
481 
482 	m_colorTargetImage			= Image::createAndAlloc(m_vkd, m_device, targetImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
483 
484 	const ImageViewCreateInfo	colorTargetViewInfo(m_colorTargetImage->object(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_R8G8B8A8_UNORM);
485 
486 	m_colorTargetView			= createImageView(m_vkd, m_device, &colorTargetViewInfo);
487 }
488 
createTargetDepthImageAndImageView(void)489 void ConditionalRenderingBaseTestInstance::createTargetDepthImageAndImageView (void)
490 {
491 	const VkExtent3D			targetImageExtent		= { WIDTH, HEIGHT, 1 };
492 
493 	const ImageCreateInfo		targetImageCreateInfo(VK_IMAGE_TYPE_2D, VK_FORMAT_D32_SFLOAT, targetImageExtent, 1, 1, VK_SAMPLE_COUNT_1_BIT, VK_IMAGE_TILING_OPTIMAL,
494 													  VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT);
495 
496 	m_depthTargetImage			= Image::createAndAlloc(m_vkd, m_device, targetImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex());
497 
498 	const ImageViewCreateInfo	depthTargetViewInfo(m_depthTargetImage->object(), VK_IMAGE_VIEW_TYPE_2D, VK_FORMAT_D32_SFLOAT);
499 
500 	m_depthTargetView			= createImageView(m_vkd, m_device, &depthTargetViewInfo);
501 }
502 
createRenderPass(VkFormat format,VkImageLayout layout)503 void ConditionalRenderingBaseTestInstance::createRenderPass (VkFormat format, VkImageLayout layout)
504 {
505 	RenderPassCreateInfo			renderPassCreateInfo;
506 
507 	renderPassCreateInfo.addAttachment(AttachmentDescription(format,
508 															 VK_SAMPLE_COUNT_1_BIT,
509 															 VK_ATTACHMENT_LOAD_OP_LOAD,
510 															 VK_ATTACHMENT_STORE_OP_STORE,
511 															 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
512 															 VK_ATTACHMENT_STORE_OP_STORE,
513 															 isDepthStencilFormat(format) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
514 															 isDepthStencilFormat(format) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
515 
516 	const VkAttachmentReference		attachmentReference =
517 	{
518 		0u,														// deUint32				attachment
519 		layout													// VkImageLayout		layout
520 	};
521 
522 	renderPassCreateInfo.addSubpass(SubpassDescription(VK_PIPELINE_BIND_POINT_GRAPHICS,
523 													   0,
524 													   0,
525 													   DE_NULL,
526 													   isDepthStencilFormat(format) ? 0 : 1,
527 													   isDepthStencilFormat(format) ? DE_NULL : &attachmentReference,
528 													   DE_NULL,
529 													   isDepthStencilFormat(format) ? attachmentReference : AttachmentReference(),
530 													   0,
531 													   DE_NULL));
532 
533 	m_renderPass					= vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo);
534 }
535 
createFramebuffer(VkImageView imageView)536 void ConditionalRenderingBaseTestInstance::createFramebuffer (VkImageView imageView)
537 {
538 	const VkFramebufferCreateInfo	framebufferCreateInfo =
539 	{
540 		VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,			// VkStructureType				sType
541 		DE_NULL,											// const void*					pNext
542 		(VkFramebufferCreateFlags)0,						// VkFramebufferCreateFlags		flags;
543 		*m_renderPass,										// VkRenderPass					renderPass
544 		1,													// deUint32						attachmentCount
545 		&imageView,											// const VkImageView*			pAttachments
546 		WIDTH,												// deUint32						width
547 		HEIGHT,												// deUint32						height
548 		1													// deUint32						layers
549 	};
550 	m_framebuffer					= vk::createFramebuffer(m_vkd, m_device, &framebufferCreateInfo);
551 }
552 
imageMemoryBarrier(VkImage image,VkAccessFlags srcAccessMask,VkAccessFlags dstAccessMask,VkImageLayout oldLayout,VkImageLayout newLayout,VkPipelineStageFlags srcStageMask,VkPipelineStageFlags dstStageMask,VkImageAspectFlags imageAspectFlags)553 void ConditionalRenderingBaseTestInstance::imageMemoryBarrier (	VkImage image, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout,
554 																VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkImageAspectFlags imageAspectFlags)
555 {
556 	const struct VkImageSubresourceRange	subRangeColor =
557 	{
558 		imageAspectFlags,								// VkImageAspectFlags		aspectMask
559 		0u,												// deUint32					baseMipLevel
560 		1u,												// deUint32					mipLevels
561 		0u,												// deUint32					baseArrayLayer
562 		1u,												// deUint32					arraySize
563 	};
564 	const VkImageMemoryBarrier				imageBarrier =
565 	{
566 		VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,			// VkStructureType			sType
567 		DE_NULL,										// const void*				pNext
568 		srcAccessMask,									// VkAccessFlags			srcAccessMask
569 		dstAccessMask,									// VkAccessFlags			dstAccessMask
570 		oldLayout,										// VkImageLayout			oldLayout
571 		newLayout,										// VkImageLayout			newLayout
572 		VK_QUEUE_FAMILY_IGNORED,						// deUint32					srcQueueFamilyIndex
573 		VK_QUEUE_FAMILY_IGNORED,						// deUint32					dstQueueFamilyIndex
574 		image,											// VkImage					image
575 		subRangeColor									// VkImageSubresourceRange	subresourceRange
576 	};
577 
578 	m_vkd.cmdPipelineBarrier(*m_cmdBufferPrimary, srcStageMask, dstStageMask, DE_FALSE, 0u, DE_NULL, 0u, DE_NULL, 1u, &imageBarrier);
579 }
580 
bufferMemoryBarrier(VkBuffer buffer,VkDeviceSize offset,VkDeviceSize size,VkAccessFlags srcAccessMask,VkAccessFlags dstAccessMask,VkPipelineStageFlags srcStageMask,VkPipelineStageFlags dstStageMask)581 void ConditionalRenderingBaseTestInstance::bufferMemoryBarrier (VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask,
582 																VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask)
583 {
584 	const VkBufferMemoryBarrier bufferBarrier =
585 	{
586 		VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,		//VkStructureType			sType;
587 		DE_NULL,										//const void*				pNext;
588 		srcAccessMask,									//VkAccessFlags				srcAccessMask;
589 		dstAccessMask,									//VkAccessFlags				dstAccessMask;
590 		VK_QUEUE_FAMILY_IGNORED,						//uint32_t					srcQueueFamilyIndex;
591 		VK_QUEUE_FAMILY_IGNORED,						//uint32_t					dstQueueFamilyIndex;
592 		buffer,											//VkBuffer					buffer;
593 		offset,											//VkDeviceSize				offset;
594 		size											//VkDeviceSize				size;
595 	};
596 
597 	m_vkd.cmdPipelineBarrier(*m_cmdBufferPrimary, srcStageMask, dstStageMask, DE_FALSE, 0u, DE_NULL, 1u, &bufferBarrier, 0u, DE_NULL);
598 }
599 
prepareReferenceImageOneColor(tcu::PixelBufferAccess & reference,const VkClearColorValue & clearColor)600 void ConditionalRenderingBaseTestInstance::prepareReferenceImageOneColor (tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColor)
601 {
602 	for (int w = 0; w < WIDTH; ++w)
603 		for (int h = 0; h < HEIGHT; ++h)
604 			reference.setPixel(tcu::Vec4(clearColor.float32[0], clearColor.float32[1], clearColor.float32[2], clearColor.float32[3]), w, h);
605 }
606 
prepareReferenceImageOneColor(tcu::PixelBufferAccess & reference,const tcu::Vec4 & color)607 void ConditionalRenderingBaseTestInstance::prepareReferenceImageOneColor (tcu::PixelBufferAccess& reference, const tcu::Vec4& color)
608 {
609 	for (int w = 0; w < WIDTH; ++w)
610 		for (int h = 0; h < HEIGHT; ++h)
611 			reference.setPixel(tcu::Vec4(color), w, h);
612 }
613 
prepareReferenceImageOneDepth(tcu::PixelBufferAccess & reference,const VkClearDepthStencilValue & clearValue)614 void ConditionalRenderingBaseTestInstance::prepareReferenceImageOneDepth (tcu::PixelBufferAccess& reference, const VkClearDepthStencilValue& clearValue)
615 {
616 	for (int w = 0; w < WIDTH; ++w)
617 		for (int h = 0; h < HEIGHT; ++h)
618 			reference.setPixDepth(clearValue.depth, w, h);
619 }
620 
prepareReferenceImageDepthClearPartial(tcu::PixelBufferAccess & reference,const VkClearDepthStencilValue & clearValueInitial,const VkClearDepthStencilValue & clearValueFinal)621 void ConditionalRenderingBaseTestInstance::prepareReferenceImageDepthClearPartial (tcu::PixelBufferAccess& reference, const VkClearDepthStencilValue& clearValueInitial, const VkClearDepthStencilValue& clearValueFinal)
622 {
623 	for (int w = 0; w < WIDTH; ++w)
624 		for (int h = 0; h < HEIGHT; ++h)
625 		{
626 			if
627 				(w >= (WIDTH / 2) && h >= (HEIGHT / 2)) reference.setPixDepth(clearValueFinal.depth, w, h);
628 			else
629 				reference.setPixDepth(clearValueInitial.depth, w, h);
630 		}
631 }
632 
prepareReferenceImageColorClearPartial(tcu::PixelBufferAccess & reference,const VkClearColorValue & clearColorInitial,const VkClearColorValue & clearColorFinal)633 void ConditionalRenderingBaseTestInstance::prepareReferenceImageColorClearPartial (tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColorInitial, const VkClearColorValue& clearColorFinal)
634 {
635 	for (int w = 0; w < WIDTH; ++w)
636 		for (int h = 0; h < HEIGHT; ++h)
637 		{
638 			if
639 				(w >= (WIDTH / 2) && h >= (HEIGHT / 2)) reference.setPixel(tcu::Vec4(clearColorFinal.float32[0], clearColorFinal.float32[1], clearColorFinal.float32[2], clearColorFinal.float32[3]), w, h);
640 			else
641 				reference.setPixel(tcu::Vec4(clearColorInitial.float32[0], clearColorInitial.float32[1], clearColorInitial.float32[2], clearColorInitial.float32[3]), w, h);
642 		}
643 }
644 
clearWithClearColorImage(const VkClearColorValue & color)645 void ConditionalRenderingBaseTestInstance::clearWithClearColorImage (const VkClearColorValue& color)
646 {
647 	const struct VkImageSubresourceRange	subRangeColor =
648 	{
649 		VK_IMAGE_ASPECT_COLOR_BIT,	// VkImageAspectFlags		aspectMask
650 		0u,							// deUint32					baseMipLevel
651 		1u,							// deUint32					mipLevels
652 		0u,							// deUint32					baseArrayLayer
653 		1u,							// deUint32					arraySize
654 	};
655 	m_vkd.cmdClearColorImage(*m_cmdBufferPrimary, m_colorTargetImage->object(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &color, 1, &subRangeColor);
656 }
657 
clearWithClearDepthStencilImage(const VkClearDepthStencilValue & value)658 void ConditionalRenderingBaseTestInstance::clearWithClearDepthStencilImage (const VkClearDepthStencilValue& value)
659 {
660 	const struct VkImageSubresourceRange	subRangeColor =
661 	{
662 		VK_IMAGE_ASPECT_DEPTH_BIT,	// VkImageAspectFlags	aspectMask
663 		0u,							// deUint32				baseMipLevel
664 		1u,							// deUint32				mipLevels
665 		0u,							// deUint32				baseArrayLayer
666 		1u,							// deUint32				arraySize
667 	};
668 	m_vkd.cmdClearDepthStencilImage(*m_cmdBufferPrimary, m_depthTargetImage->object(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &value, 1, &subRangeColor);
669 }
670 
clearColorWithClearAttachments(const VkClearColorValue & color,bool partial)671 void ConditionalRenderingBaseTestInstance::clearColorWithClearAttachments (const VkClearColorValue& color, bool partial)
672 {
673 	const VkClearAttachment		clearAttachment =
674 	{
675 		VK_IMAGE_ASPECT_COLOR_BIT,	// VkImageAspectFlags		aspectMask;
676 		0u,							// deUint32					colorAttachment;
677 		{ color }					// VkClearValue				clearValue;
678 	};
679 	VkRect2D					renderArea			= { { 0, 0 },{ WIDTH, HEIGHT } };
680 
681 	if (partial)
682 	{
683 		renderArea.offset.x = WIDTH / 2;
684 		renderArea.offset.y = HEIGHT / 2;
685 		renderArea.extent.width = WIDTH / 2;
686 		renderArea.extent.height = HEIGHT / 2;
687 	}
688 
689 	const VkClearRect			clearRect =
690 	{
691 		renderArea,					// VkRect2D					rect;
692 		0u,							// deUint32					baseArrayLayer;
693 		1u							// deUint32					layerCount;
694 	};
695 
696 	m_vkd.cmdClearAttachments(*m_cmdBufferPrimary, 1, &clearAttachment, 1, &clearRect);
697 }
698 
clearDepthWithClearAttachments(const VkClearDepthStencilValue & depthStencil,bool partial)699 void ConditionalRenderingBaseTestInstance::clearDepthWithClearAttachments (const VkClearDepthStencilValue& depthStencil, bool partial)
700 {
701 	const VkClearAttachment clearAttachment =
702 	{
703 		VK_IMAGE_ASPECT_DEPTH_BIT,												// VkImageAspectFlags		aspectMask;
704 		0u,																		// deUint32					colorAttachment;
705 		makeClearValueDepthStencil(depthStencil.depth, depthStencil.stencil)	// VkClearValue				clearValue;
706 	};
707 	VkRect2D				renderArea			= { { 0, 0 },{ WIDTH, HEIGHT } };
708 
709 	if (partial)
710 	{
711 		renderArea.offset.x = WIDTH / 2;
712 		renderArea.offset.y = HEIGHT / 2;
713 		renderArea.extent.width = WIDTH / 2;
714 		renderArea.extent.height = HEIGHT / 2;
715 	}
716 
717 	const VkClearRect		clearRect =
718 	{
719 		renderArea,																// VkRect2D					rect;
720 		0u,																		// deUint32					baseArrayLayer;
721 		1u																		// deUint32					layerCount;
722 	};
723 	m_vkd.cmdClearAttachments(*m_cmdBufferPrimary, 1, &clearAttachment, 1, &clearRect);
724 }
725 
createResultBuffer(VkFormat format)726 void ConditionalRenderingBaseTestInstance::createResultBuffer (VkFormat format)
727 {
728 	VkDeviceSize		size	= WIDTH * HEIGHT * mapVkFormat(format).getPixelSize();
729 	m_resultBuffer				= Buffer::createAndAlloc(m_vkd, m_device, BufferCreateInfo(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
730 }
731 
createVertexBuffer(void)732 void ConditionalRenderingBaseTestInstance::createVertexBuffer (void)
733 {
734 	float triangleData[]							= {	-1.0f,		-1.0f,		0.0f,	1.0f,
735 														-1.0f,		1.0f,		0.0f,	1.0f,
736 														1.0f,		1.0f,		0.0f,	1.0f,
737 														1.0f,		-1.0f,		0.0f,	1.0f };
738 
739 	m_vertexBuffer									= Buffer::createAndAlloc(m_vkd, m_device, BufferCreateInfo(sizeof(triangleData), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT), m_context.getDefaultAllocator(), MemoryRequirement::HostVisible);
740 
741 	void * vertexBufferDataPointer					= m_vertexBuffer->getBoundMemory().getHostPtr();
742 
743 	deMemcpy(vertexBufferDataPointer, triangleData, sizeof(triangleData));
744 	flushMappedMemoryRange(m_vkd, m_device, m_vertexBuffer->getBoundMemory().getMemory(), m_vertexBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
745 }
746 
createPipelineLayout(void)747 void ConditionalRenderingBaseTestInstance::createPipelineLayout (void)
748 {
749 	const VkPipelineLayoutCreateInfo	pipelineLayoutParams =
750 	{
751 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	// VkStructureType				sType
752 		DE_NULL,										// const void*					pNext
753 		(VkPipelineLayoutCreateFlags)0,					// VkPipelineLayoutCreateFlags	flags
754 		1u,												// deUint32						descriptorSetCount
755 		&(m_descriptorSetLayout.get()),					// const VkDescriptorSetLayout*	pSetLayouts
756 		0u,												// deUint32						pushConstantRangeCount
757 		DE_NULL											// const VkPushConstantRange*	pPushConstantRanges
758 	};
759 
760 	m_pipelineLayout					= vk::createPipelineLayout(m_vkd, m_device, &pipelineLayoutParams);
761 }
762 
createAndUpdateDescriptorSet(void)763 void ConditionalRenderingBaseTestInstance::createAndUpdateDescriptorSet (void)
764 {
765 	const VkDescriptorSetAllocateInfo	allocInfo =
766 	{
767 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,			// VkStructureType								sType
768 		DE_NULL,												// const void*									pNext
769 		*m_descriptorPool,										// VkDescriptorPool								descriptorPool
770 		1u,														// deUint32										setLayoutCount
771 		&(m_descriptorSetLayout.get())							// const VkDescriptorSetLayout*					pSetLayouts
772 	};
773 
774 	m_descriptorSet						= allocateDescriptorSet(m_vkd, m_device, &allocInfo);
775 	VkDescriptorBufferInfo				descriptorInfo			= makeDescriptorBufferInfo(m_vertexBuffer->object(), (VkDeviceSize)0u, sizeof(float) * 16);
776 
777 	DescriptorSetUpdateBuilder()
778 		.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfo)
779 		.update(m_vkd, m_device);
780 }
781 
createPipeline(void)782 void ConditionalRenderingBaseTestInstance::createPipeline (void)
783 {
784 	const std::vector<VkViewport>					viewports(1, makeViewport(tcu::UVec2(WIDTH, HEIGHT)));
785 	const std::vector<VkRect2D>						scissors(1, makeRect2D(tcu::UVec2(WIDTH, HEIGHT)));
786 	const VkPrimitiveTopology						topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
787 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateParams =
788 	{
789 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,										// VkStructureType								sType
790 		DE_NULL,																						// const void*									pNext
791 		0u,																								// vkPipelineVertexInputStateCreateFlags		flags
792 		0u,																								// deUint32										bindingCount
793 		DE_NULL,																						// const VkVertexInputBindingDescription*		pVertexBindingDescriptions
794 		0u,																								// deUint32										attributeCount
795 		DE_NULL,																						// const VkVertexInputAttributeDescription*		pVertexAttributeDescriptions
796 	};
797 
798 	m_pipeline										= makeGraphicsPipeline(m_vkd,						// const DeviceInterface&						vk
799 																		   m_device,					// const VkDevice								device
800 																		   *m_pipelineLayout,			// const VkPipelineLayout						pipelineLayout
801 																		   *m_vertexShaderModule,		// const VkShaderModule							vertexShaderModule
802 																		   DE_NULL,						// const VkShaderModule							tessellationControlShaderModule
803 																		   DE_NULL,						// const VkShaderModule							tessellationEvalShaderModule
804 																		   DE_NULL,						// const VkShaderModule							geometryShaderModule
805 																		   *m_fragmentShaderModule,		// const VkShaderModule							fragmentShaderModule
806 																		   *m_renderPass,				// const VkRenderPass							renderPass
807 																		   viewports,					// const std::vector<VkViewport>&				viewports
808 																		   scissors,					// const std::vector<VkRect2D>&					scissors
809 																		   topology,					// const VkPrimitiveTopology					topology
810 																		   0u,							// const deUint32								subpass
811 																		   0u,							// const deUint32								patchControlPoints
812 																		   &vertexInputStateParams);	// const VkPipelineVertexInputStateCreateInfo*	vertexInputStateCreateInfo
813 }
814 
copyResultImageToBuffer(VkImageAspectFlags imageAspectFlags,VkImage image)815 void ConditionalRenderingBaseTestInstance::copyResultImageToBuffer (VkImageAspectFlags imageAspectFlags, VkImage image)
816 {
817 	const VkBufferImageCopy region_all =
818 	{
819 		0,												// VkDeviceSize					bufferOffset
820 		0,												// deUint32						bufferRowLength
821 		0,												// deUint32						bufferImageHeight
822 		{ imageAspectFlags, 0, 0, 1 },					// VkImageSubresourceLayers		imageSubresource
823 		{ 0, 0, 0 },									// VkOffset3D					imageOffset
824 		{ WIDTH, HEIGHT, 1 }							// VkExtent3D					imageExtent
825 	};
826 
827 	m_vkd.cmdCopyImageToBuffer(*m_cmdBufferPrimary, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_resultBuffer->object(), 1, &region_all);
828 }
829 
draw(void)830 void ConditionalRenderingBaseTestInstance::draw (void)
831 {
832 	m_vkd.cmdDraw(*m_cmdBufferPrimary, 4, 1, 0, 0);
833 }
834 
ConditionalRenderingClearAttachmentsTestInstance(Context & context,const ClearTestParams & testParams)835 ConditionalRenderingClearAttachmentsTestInstance::ConditionalRenderingClearAttachmentsTestInstance (Context& context, const ClearTestParams& testParams)
836 	: ConditionalRenderingBaseTestInstance	(context)
837 	, m_testParams							(testParams)
838 {}
839 
iterate(void)840 tcu::TestStatus ConditionalRenderingClearAttachmentsTestInstance::iterate (void)
841 {
842 	const deUint32								queueFamilyIndex		= m_context.getUniversalQueueFamilyIndex();
843 	deUint32									offsetMultiplier		= 0;
844 	VkClearColorValue							clearColorInitial		= { { 0.0f, 0.0f, 1.0f, 1.0f } };
845 	VkClearColorValue							clearColorMiddle		= { { 1.0f, 0.0f, 0.0f, 1.0f } };
846 	VkClearColorValue							clearColorFinal			= { { 0.0f, 1.0f, 0.0f, 1.0f } };
847 	VkClearDepthStencilValue					clearDepthValueInitial	= { 0.4f, 0 };
848 	VkClearDepthStencilValue					clearDepthValueMiddle	= { 0.6f, 0 };
849 	VkClearDepthStencilValue					clearDepthValueFinal	= { 0.9f, 0 };
850 
851 	if (m_testParams.m_useOffset) offsetMultiplier = 3;
852 
853 	m_cmdPool									= createCommandPool(m_vkd, m_device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
854 
855 	createInitBufferWithPredicate(m_testParams.m_memoryType, m_testParams.m_discard, m_testParams.m_invert, offsetMultiplier);
856 	m_testParams.m_testDepth ? createTargetDepthImageAndImageView() : createTargetColorImageAndImageView();
857 	createResultBuffer(m_testParams.m_testDepth ? VK_FORMAT_D32_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM);
858 
859 	m_cmdBufferPrimary							= allocateCommandBuffer(m_vkd, m_device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
860 
861 	createRenderPass(m_testParams.m_testDepth ? VK_FORMAT_D32_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM, m_testParams.m_testDepth ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
862 	createFramebuffer(m_testParams.m_testDepth ? m_depthTargetView.get() : m_colorTargetView.get());
863 
864 	const VkConditionalRenderingBeginInfoEXT	conditionalRenderingBeginInfo =
865 	{
866 		VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT,																						//VkStructureType					sType;
867 		DE_NULL,																																	//const void*						pNext;
868 		m_conditionalRenderingBuffer->object(),																										//VkBuffer							buffer;
869 		sizeof(deUint32) * offsetMultiplier,																										//VkDeviceSize						offset;
870 		(m_testParams.m_invert ? (VkConditionalRenderingFlagsEXT) VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT : (VkConditionalRenderingFlagsEXT) 0)	//VkConditionalRenderingFlagsEXT	flags;
871 	};
872 
873 	beginCommandBuffer(m_vkd, *m_cmdBufferPrimary);
874 
875 	imageMemoryBarrier(m_testParams.m_testDepth ? m_depthTargetImage->object() : m_colorTargetImage->object(),										//VkImage							 image
876 					   0u,																															//VkAccessFlags						srcAccessMask
877 					   VK_ACCESS_TRANSFER_WRITE_BIT,																								//VkAccessFlags						dstAccessMask
878 					   VK_IMAGE_LAYOUT_UNDEFINED,																									//VkImageLayout						oldLayout
879 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																						//VkImageLayout						newLayout
880 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																								//VkPipelineStageFlags				srcStageMask
881 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																								//VkPipelineStageFlags				dstStageMask
882 					   m_testParams.m_testDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT);											//VkImageAspectFlags				flags
883 
884 	m_testParams.m_testDepth					?	clearWithClearDepthStencilImage(clearDepthValueInitial)
885 												:	clearWithClearColorImage(clearColorInitial);
886 
887 	imageMemoryBarrier(m_testParams.m_testDepth ? m_depthTargetImage->object() : m_colorTargetImage->object(),										//VkImage							image
888 					   VK_ACCESS_TRANSFER_WRITE_BIT,																								//VkAccessFlags						srcAccessMask
889 					   m_testParams.m_testDepth ? (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT)
890 												: (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),						//VkAccessFlags						dstAccessMask
891 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																						//VkImageLayout						oldLayout
892 					   m_testParams.m_testDepth ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,		//VkImageLayout						newLayout
893 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																								//VkPipelineStageFlags				srcStageMask
894 					   m_testParams.m_testDepth ? VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,				//VkPipelineStageFlags				dstStageMask
895 					   m_testParams.m_testDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT);											//VkImageAspectFlags				flags
896 
897 	if (m_testParams.m_clearAttachmentTwice)
898 	{
899 		beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
900 
901 		m_testParams.m_testDepth	? clearDepthWithClearAttachments(clearDepthValueMiddle, m_testParams.m_partialClear)
902 									: clearColorWithClearAttachments(clearColorMiddle, m_testParams.m_partialClear);
903 
904 		m_vkd.cmdBeginConditionalRenderingEXT(*m_cmdBufferPrimary, &conditionalRenderingBeginInfo);
905 
906 		m_testParams.m_testDepth	? clearDepthWithClearAttachments(clearDepthValueFinal, m_testParams.m_partialClear)
907 									: clearColorWithClearAttachments(clearColorFinal, m_testParams.m_partialClear);
908 
909 		m_vkd.cmdEndConditionalRenderingEXT(*m_cmdBufferPrimary);
910 
911 		endRenderPass(m_vkd, *m_cmdBufferPrimary);
912 	}
913 	else
914 	{
915 		m_vkd.cmdBeginConditionalRenderingEXT(*m_cmdBufferPrimary, &conditionalRenderingBeginInfo);
916 
917 		beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
918 
919 		m_testParams.m_testDepth	?	clearDepthWithClearAttachments(clearDepthValueFinal, m_testParams.m_partialClear)
920 									:	clearColorWithClearAttachments(clearColorFinal, m_testParams.m_partialClear);
921 
922 		endRenderPass(m_vkd, *m_cmdBufferPrimary);
923 		m_vkd.cmdEndConditionalRenderingEXT(*m_cmdBufferPrimary);
924 	}
925 
926 	imageMemoryBarrier(m_testParams.m_testDepth ? m_depthTargetImage->object() : m_colorTargetImage->object(),										//VkImage							image
927 					   m_testParams.m_testDepth ? (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT)
928 												: (VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT),						//VkAccessFlags						dstAccessMask
929 					   VK_ACCESS_TRANSFER_READ_BIT,																									//VkAccessFlags						dstAccessMask
930 					   m_testParams.m_testDepth ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,		//VkImageLayout						oldLayout
931 					   VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,																						//VkImageLayout						newLayout
932 					   m_testParams.m_testDepth ? VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT : VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,				//VkPipelineStageFlags				srcStageMask
933 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																								//VkPipelineStageFlags				dstStageMask
934 					   m_testParams.m_testDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT);											//VkImageAspectFlags				flags
935 
936 	copyResultImageToBuffer(m_testParams.m_testDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT, m_testParams.m_testDepth ? m_depthTargetImage->object() : m_colorTargetImage->object());
937 
938 	const vk::VkBufferMemoryBarrier bufferMemoryBarrier =
939 	{
940 		vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
941 		DE_NULL,
942 		vk::VK_ACCESS_TRANSFER_WRITE_BIT,
943 		vk::VK_ACCESS_HOST_READ_BIT,
944 		VK_QUEUE_FAMILY_IGNORED,
945 		VK_QUEUE_FAMILY_IGNORED,
946 		m_resultBuffer->object(),
947 		0u,
948 		VK_WHOLE_SIZE
949 	};
950 
951 	m_vkd.cmdPipelineBarrier(*m_cmdBufferPrimary, vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &bufferMemoryBarrier, 0u, DE_NULL);
952 
953 	endCommandBuffer(m_vkd, *m_cmdBufferPrimary);
954 
955 	submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
956 
957 	invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
958 
959 	tcu::ConstPixelBufferAccess					result(mapVkFormat(m_testParams.m_testDepth ? VK_FORMAT_D32_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
960 
961 	std::vector<float>							referenceData((m_testParams.m_testDepth ? 1 : 4) * WIDTH * HEIGHT, 0);
962 	tcu::PixelBufferAccess						reference(mapVkFormat(m_testParams.m_testDepth ? VK_FORMAT_D32_SFLOAT : VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), referenceData.data());
963 
964 	if (!m_testParams.m_partialClear)
965 	{
966 		m_testParams.m_testDepth	? prepareReferenceImageOneDepth(reference, m_testParams.m_discard ? (m_testParams.m_clearAttachmentTwice ? clearDepthValueMiddle : clearDepthValueInitial) : clearDepthValueFinal)
967 									: prepareReferenceImageOneColor(reference, m_testParams.m_discard ? (m_testParams.m_clearAttachmentTwice ? clearColorMiddle : clearColorInitial) : clearColorFinal);
968 	}
969 	else
970 	{
971 		m_testParams.m_testDepth	? prepareReferenceImageDepthClearPartial(reference, clearDepthValueInitial, m_testParams.m_discard ? (m_testParams.m_clearAttachmentTwice ? clearDepthValueMiddle : clearDepthValueInitial) : clearDepthValueFinal)
972 									: prepareReferenceImageColorClearPartial(reference, clearColorInitial, m_testParams.m_discard ? (m_testParams.m_clearAttachmentTwice ? clearColorMiddle : clearColorInitial) : clearColorFinal);
973 	}
974 
975 	if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Comparison", "Comparison", reference, result, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR))
976 		return tcu::TestStatus::fail("Fail");
977 
978 	return tcu::TestStatus::pass("Pass");
979 }
980 
ConditionalRenderingDrawTestInstance(Context & context,const DrawTestParams & testParams)981 ConditionalRenderingDrawTestInstance::ConditionalRenderingDrawTestInstance (Context& context, const DrawTestParams& testParams)
982 	: ConditionalRenderingBaseTestInstance	(context)
983 	, m_testParams							(testParams)
984 {}
985 
iterate(void)986 tcu::TestStatus ConditionalRenderingDrawTestInstance::iterate (void)
987 {
988 	const deUint32						queueFamilyIndex				= m_context.getUniversalQueueFamilyIndex();
989 	VkClearColorValue					clearColorInitial				= { { 0.0f, 0.0f, 1.0f, 1.0f } };
990 	deUint32							offsetMultiplier				= 0;
991 
992 	if (m_testParams.m_useOffset) offsetMultiplier = 3;
993 
994 	VkBufferUsageFlagBits				bufferUsageExtraFlags			= (VkBufferUsageFlagBits)0;
995 	if (m_testParams.m_togglePredicate)
996 		bufferUsageExtraFlags = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
997 
998 	m_cmdPool							= createCommandPool(m_vkd, m_device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
999 
1000 	createInitBufferWithPredicate(m_testParams.m_memoryType, m_testParams.m_discard, m_testParams.m_invert, offsetMultiplier, bufferUsageExtraFlags);
1001 
1002 	if (m_testParams.m_toggleMode == COPY)
1003 	{
1004 		//we need another buffer to copy from, with toggled predicate value
1005 		m_conditionalRenderingBufferForCopy.swap(m_conditionalRenderingBuffer);
1006 		createInitBufferWithPredicate(m_testParams.m_memoryType, !m_testParams.m_discard, m_testParams.m_invert, offsetMultiplier, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
1007 		m_conditionalRenderingBufferForCopy.swap(m_conditionalRenderingBuffer);
1008 	}
1009 	createTargetColorImageAndImageView();
1010 	createResultBuffer(VK_FORMAT_R8G8B8A8_UNORM);
1011 	createVertexBuffer();
1012 
1013 	m_cmdBufferPrimary					= allocateCommandBuffer(m_vkd, m_device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1014 
1015 	createRenderPass(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1016 	createFramebuffer(m_colorTargetView.get());
1017 
1018 	DescriptorSetLayoutBuilder			builder;
1019 
1020 	builder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_ALL);
1021 
1022 	m_descriptorSetLayout				= builder.build(m_vkd, m_device, (VkDescriptorSetLayoutCreateFlags)0);
1023 
1024 	m_descriptorPool					= DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
1025 																 .build(m_vkd, m_device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1u);
1026 
1027 	createPipelineLayout();
1028 	createAndUpdateDescriptorSet();
1029 
1030 	m_vertexShaderModule				= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("position_only.vert"), 0);
1031 	m_fragmentShaderModule				= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("only_color_out.frag"), 0);
1032 
1033 	createPipeline();
1034 
1035 	VkConditionalRenderingBeginInfoEXT	conditionalRenderingBeginInfo =
1036 	{
1037 		VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT,																		//VkStructureType					sType;
1038 		DE_NULL,																													//const void*						pNext;
1039 		m_conditionalRenderingBuffer->object(),																						//VkBuffer							buffer;
1040 		sizeof(deUint32) * offsetMultiplier,																						//VkDeviceSize						offset;
1041 		(m_testParams.m_invert	? (VkConditionalRenderingFlagsEXT)VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT
1042 								: (VkConditionalRenderingFlagsEXT)0)																//VkConditionalRenderingFlagsEXT	flags;
1043 	};
1044 
1045 	beginCommandBuffer(m_vkd, *m_cmdBufferPrimary);
1046 
1047 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1048 					   0u,																											//VkAccessFlags						srcAccessMask
1049 					   VK_ACCESS_TRANSFER_WRITE_BIT,																				//VkAccessFlags						dstAccessMask
1050 					   VK_IMAGE_LAYOUT_UNDEFINED,																					//VkImageLayout						oldLayout
1051 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																		//VkImageLayout						newLayout
1052 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				srcStageMask
1053 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				dstStageMask
1054 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1055 
1056 	clearWithClearColorImage(clearColorInitial);
1057 
1058 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1059 					   VK_ACCESS_TRANSFER_WRITE_BIT,																				//VkAccessFlags						srcAccessMask
1060 					   VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,									//VkAccessFlags						dstAccessMask
1061 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																		//VkImageLayout						oldLayout
1062 					   VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,																	//VkImageLayout						newLayout
1063 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				srcStageMask
1064 					   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,																//VkPipelineStageFlags				dstStageMask
1065 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1066 
1067 	m_vkd.cmdBindPipeline(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipeline);
1068 	m_vkd.cmdBindDescriptorSets(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &(*m_descriptorSet), 0, DE_NULL);
1069 
1070 	if (m_testParams.m_togglePredicate)
1071 	{
1072 		if (m_testParams.m_toggleMode == FILL)
1073 		{
1074 			m_testParams.m_discard		= !m_testParams.m_discard;
1075 			deUint32 predicate			= m_testParams.m_discard ? m_testParams.m_invert : !m_testParams.m_invert;
1076 			m_vkd.cmdFillBuffer(*m_cmdBufferPrimary, m_conditionalRenderingBuffer->object(), m_conditionalRenderingBufferOffset, sizeof(predicate), predicate);
1077 			bufferMemoryBarrier(m_conditionalRenderingBuffer->object(), m_conditionalRenderingBufferOffset, sizeof(predicate), VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT,
1078 								VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT);
1079 		}
1080 		if (m_testParams.m_toggleMode == COPY)
1081 		{
1082 			VkBufferCopy region =
1083 			{
1084 				m_conditionalRenderingBufferOffset,																					//VkDeviceSize						srcOffset;
1085 				m_conditionalRenderingBufferOffset,																					//VkDeviceSize						dstOffset;
1086 				sizeof(deUint32)																									//VkDeviceSize						size;
1087 			};
1088 			m_vkd.cmdCopyBuffer(*m_cmdBufferPrimary, m_conditionalRenderingBufferForCopy->object(), m_conditionalRenderingBuffer->object(), 1, &region);
1089 			bufferMemoryBarrier(m_conditionalRenderingBuffer->object(), m_conditionalRenderingBufferOffset, sizeof(deUint32), VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT,
1090 								VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT);
1091 		}
1092 	}
1093 
1094 	beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
1095 
1096 	deInt32								data[4]							= { -1, -1, -1, -1 };
1097 	void*								dataPtr							= data;
1098 
1099 	for (int drawNdx = 0; drawNdx < 4; drawNdx++)
1100 	{
1101 		data[0] = drawNdx;
1102 		m_vkd.cmdPushConstants(*m_cmdBufferPrimary, *m_pipelineLayout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dataPtr);
1103 
1104 		if (isBitSet(m_testParams.m_beginSequenceBits, drawNdx))
1105 			m_vkd.cmdBeginConditionalRenderingEXT(*m_cmdBufferPrimary, &conditionalRenderingBeginInfo);
1106 
1107 		draw();
1108 
1109 		if (isBitSet(m_testParams.m_endSequenceBits, drawNdx))
1110 			m_vkd.cmdEndConditionalRenderingEXT(*m_cmdBufferPrimary);
1111 	}
1112 
1113 	endRenderPass(m_vkd, *m_cmdBufferPrimary);
1114 
1115 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1116 					   VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,																		//VkAccessFlags						srcAccessMask
1117 					   VK_ACCESS_TRANSFER_READ_BIT,																					//VkAccessFlags						dstAccessMask
1118 					   VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,																	//VkImageLayout						oldLayout
1119 					   VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,																		//VkImageLayout						newLayout
1120 					   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,																//VkPipelineStageFlags				srcStageMask
1121 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				dstStageMask
1122 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1123 
1124 	copyResultImageToBuffer(VK_IMAGE_ASPECT_COLOR_BIT, m_colorTargetImage->object());
1125 
1126 	const vk::VkBufferMemoryBarrier bufferMemoryBarrier =
1127 	{
1128 		vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
1129 		DE_NULL,
1130 		vk::VK_ACCESS_TRANSFER_WRITE_BIT,
1131 		vk::VK_ACCESS_HOST_READ_BIT,
1132 		VK_QUEUE_FAMILY_IGNORED,
1133 		VK_QUEUE_FAMILY_IGNORED,
1134 		m_resultBuffer->object(),
1135 		0u,
1136 		VK_WHOLE_SIZE
1137 	};
1138 
1139 	m_vkd.cmdPipelineBarrier(*m_cmdBufferPrimary, vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &bufferMemoryBarrier, 0u, DE_NULL);
1140 
1141 	endCommandBuffer(m_vkd, *m_cmdBufferPrimary);
1142 
1143 	submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
1144 
1145 	invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
1146 
1147 	tcu::ConstPixelBufferAccess			result(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
1148 
1149 	std::vector<float>					referenceData(4 * WIDTH * HEIGHT, 0.5f);
1150 	tcu::PixelBufferAccess				reference(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), referenceData.data());
1151 
1152 	prepareReferenceImage(reference, clearColorInitial, m_testParams.m_resultBits);
1153 
1154 	if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Comparison", "Comparison", reference, result, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR))
1155 		return tcu::TestStatus::fail("Fail");
1156 
1157 	return tcu::TestStatus::pass("Pass");
1158 }
1159 
createPipelineLayout(void)1160 void ConditionalRenderingDrawTestInstance::createPipelineLayout (void)
1161 {
1162 	const VkPushConstantRange			pushConstantRange =
1163 	{
1164 		VK_SHADER_STAGE_FRAGMENT_BIT,					//VkShaderStageFlags			stageFlags;
1165 		0,												//deUint32						offset;
1166 		16												//deUint32						size;
1167 	};
1168 
1169 	const VkPipelineLayoutCreateInfo	pipelineLayoutParams =
1170 	{
1171 		VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,	//VkStructureType				sType
1172 		DE_NULL,										//const void*					pNext
1173 		(VkPipelineLayoutCreateFlags)0,					//VkPipelineLayoutCreateFlags	flags
1174 		1u,												//deUint32						descriptorSetCount
1175 		&(m_descriptorSetLayout.get()),					//const VkDescriptorSetLayout*	pSetLayouts
1176 		1u,												//deUint32						pushConstantRangeCount
1177 		&pushConstantRange								//const VkPushConstantRange*	pPushConstantRanges
1178 	};
1179 
1180 	m_pipelineLayout					= vk::createPipelineLayout(m_vkd, m_device, &pipelineLayoutParams);
1181 }
1182 
prepareReferenceImage(tcu::PixelBufferAccess & reference,const VkClearColorValue & clearColor,deUint32 resultBits)1183 void ConditionalRenderingDrawTestInstance::prepareReferenceImage (tcu::PixelBufferAccess& reference, const VkClearColorValue& clearColor, deUint32 resultBits)
1184 {
1185 	for (int w = 0; w < WIDTH; w++)
1186 		for (int h = 0; h < HEIGHT; h++)
1187 			reference.setPixel(tcu::Vec4(clearColor.float32), w, h);
1188 
1189 	int step = (HEIGHT / 4);
1190 	for (int w = 0; w < WIDTH; w++)
1191 		for (int h = 0; h < HEIGHT; h++)
1192 		{
1193 			if (h < step && isBitSet(resultBits, 0)) reference.setPixel(tcu::Vec4(0, 1, 0, 1), w, h);
1194 			if (h >= step && h < (step * 2) && isBitSet(resultBits, 1)) reference.setPixel(tcu::Vec4(0, 1, 0, 1), w, h);
1195 			if (h >= (step * 2) && h < (step * 3) && isBitSet(resultBits, 2)) reference.setPixel(tcu::Vec4(0, 1, 0, 1), w, h);
1196 			if (h >= (step * 3) && isBitSet(resultBits, 3)) reference.setPixel(tcu::Vec4(0, 1, 0, 1), w, h);
1197 		}
1198 }
1199 
ConditionalRenderingUpdateBufferWithDrawTestInstance(Context & context,UpdateBufferWithDrawTestParams testParams)1200 ConditionalRenderingUpdateBufferWithDrawTestInstance::ConditionalRenderingUpdateBufferWithDrawTestInstance (Context& context, UpdateBufferWithDrawTestParams testParams)
1201 	: ConditionalRenderingBaseTestInstance	(context)
1202 	, m_testParams							(testParams)
1203 {}
1204 
createAndUpdateDescriptorSets(void)1205 void ConditionalRenderingUpdateBufferWithDrawTestInstance::createAndUpdateDescriptorSets (void)
1206 {
1207 	//the same descriptor set layout can be used for the creation of both descriptor sets
1208 	const VkDescriptorSetAllocateInfo	allocInfo =
1209 	{
1210 		VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,			//VkStructureType						sType
1211 		DE_NULL,												//const void*							pNext
1212 		*m_descriptorPool,										//VkDescriptorPool						descriptorPool
1213 		1u,														//deUint32								setLayoutCount
1214 		&(m_descriptorSetLayout.get())							//const VkDescriptorSetLayout*			pSetLayouts
1215 	};
1216 
1217 	m_descriptorSet						= allocateDescriptorSet(m_vkd, m_device, &allocInfo);
1218 	VkDescriptorBufferInfo				descriptorInfo			= makeDescriptorBufferInfo(m_vertexBuffer->object(), (VkDeviceSize)0u, sizeof(float) * 16);
1219 
1220 	DescriptorSetUpdateBuilder()
1221 		.writeSingle(*m_descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfo)
1222 		.update(m_vkd, m_device);
1223 
1224 	m_descriptorSetUpdate				= allocateDescriptorSet(m_vkd, m_device, &allocInfo);
1225 	VkDescriptorBufferInfo				descriptorInfoUpdate	= makeDescriptorBufferInfo(m_conditionalRenderingBuffer->object(), (VkDeviceSize)0u, sizeof(deUint32));
1226 
1227 	DescriptorSetUpdateBuilder()
1228 		.writeSingle(*m_descriptorSetUpdate, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &descriptorInfoUpdate)
1229 		.update(m_vkd, m_device);
1230 }
1231 
createPipelines(void)1232 void ConditionalRenderingUpdateBufferWithDrawTestInstance::createPipelines (void)
1233 {
1234 	const std::vector<VkViewport>					viewports(1, makeViewport(tcu::UVec2(WIDTH, HEIGHT)));
1235 	const std::vector<VkRect2D>						scissors(1, makeRect2D(tcu::UVec2(WIDTH, HEIGHT)));
1236 	const VkPrimitiveTopology						topology														= VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
1237 	const VkPipelineVertexInputStateCreateInfo		vertexInputStateParams =
1238 	{
1239 		VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,													//VkStructureType								sType
1240 		DE_NULL,																									//const void*									pNext
1241 		0u,																											//vkPipelineVertexInputStateCreateFlags			flags
1242 		0u,																											//deUint32										bindingCount
1243 		DE_NULL,																									//const VkVertexInputBindingDescription*		pVertexBindingDescriptions
1244 		0u,																											//deUint32										attributeCount
1245 		DE_NULL,																									//const VkVertexInputAttributeDescription*		pVertexAttributeDescriptions
1246 	};
1247 
1248 	m_pipelineDraw									= makeGraphicsPipeline(m_vkd,									//const DeviceInterface&						vk
1249 																		   m_device,								//const VkDevice								device
1250 																		   *m_pipelineLayout,						//const VkPipelineLayout						pipelineLayout
1251 																		   *m_vertexShaderModuleDraw,				//const VkShaderModule							vertexShaderModule
1252 																		   DE_NULL,									//const VkShaderModule							tessellationControlShaderModule
1253 																		   DE_NULL,									//const VkShaderModule							tessellationEvalShaderModule
1254 																		   DE_NULL,									//const VkShaderModule							geometryShaderModule
1255 																		   *m_fragmentShaderModuleDraw,				//const VkShaderModule							fragmentShaderModule
1256 																		   *m_renderPass,							//const VkRenderPass							renderPass
1257 																		   viewports,								//const std::vector<VkViewport>&				viewports
1258 																		   scissors,								//const std::vector<VkRect2D>&					scissors
1259 																		   topology,								//const VkPrimitiveTopology						topology
1260 																		   0u,										//const deUint32								subpass
1261 																		   0u,										//const deUint32								patchControlPoints
1262 																		   &vertexInputStateParams);				//const VkPipelineVertexInputStateCreateInfo*	vertexInputStateCreateInfo
1263 
1264 	m_pipelineUpdate								= makeGraphicsPipeline(m_vkd,									//const DeviceInterface&						vk
1265 																		   m_device,								//const VkDevice								device
1266 																		   *m_pipelineLayout,						//const VkPipelineLayout						pipelineLayout
1267 																		   *m_vertexShaderModuleUpdate,				//const VkShaderModule							vertexShaderModule
1268 																		   DE_NULL,									//const VkShaderModule							tessellationControlShaderModule
1269 																		   DE_NULL,									//const VkShaderModule							tessellationEvalShaderModule
1270 																		   DE_NULL,									//const VkShaderModule							geometryShaderModule
1271 																		   *m_fragmentShaderModuleDiscard,			//const VkShaderModule							fragmentShaderModule
1272 																		   *m_renderPass,							//const VkRenderPass							renderPass
1273 																		   viewports,								//const std::vector<VkViewport>&				viewports
1274 																		   scissors,								//const std::vector<VkRect2D>&					scissors
1275 																		   topology,								//const VkPrimitiveTopology						topology
1276 																		   0u,										//const deUint32								subpass
1277 																		   0u,										//const deUint32								patchControlPoints
1278 																		   &vertexInputStateParams);				//const VkPipelineVertexInputStateCreateInfo*	vertexInputStateCreateInfo
1279 }
1280 
createRenderPass(VkFormat format,VkImageLayout layout)1281 void ConditionalRenderingUpdateBufferWithDrawTestInstance::createRenderPass (VkFormat format, VkImageLayout layout)
1282 {
1283 	RenderPassCreateInfo			renderPassCreateInfo;
1284 
1285 	renderPassCreateInfo.addAttachment(AttachmentDescription(format,
1286 															 VK_SAMPLE_COUNT_1_BIT,
1287 															 VK_ATTACHMENT_LOAD_OP_LOAD,
1288 															 VK_ATTACHMENT_STORE_OP_STORE,
1289 															 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
1290 															 VK_ATTACHMENT_STORE_OP_STORE,
1291 															 isDepthStencilFormat(format) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
1292 															 isDepthStencilFormat(format) ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL));
1293 
1294 	const VkAttachmentReference		attachmentReference =
1295 	{
1296 		0u,														// deUint32				attachment
1297 		layout													// VkImageLayout		layout
1298 	};
1299 
1300 	renderPassCreateInfo.addSubpass(SubpassDescription(VK_PIPELINE_BIND_POINT_GRAPHICS,
1301 													   0,
1302 													   0,
1303 													   DE_NULL,
1304 													   isDepthStencilFormat(format) ? 0 : 1,
1305 													   isDepthStencilFormat(format) ? DE_NULL : &attachmentReference,
1306 													   DE_NULL,
1307 													   isDepthStencilFormat(format) ? attachmentReference : AttachmentReference(),
1308 													   0,
1309 													   DE_NULL));
1310 
1311 	VkSubpassDependency				dependency =
1312 	{
1313 		0,														//deUint32				srcSubpass;
1314 		0,														//deUint32				dstSubpass;
1315 		VK_PIPELINE_STAGE_VERTEX_SHADER_BIT,					//VkPipelineStageFlags	srcStageMask;
1316 		VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT,		//VkPipelineStageFlags	dstStageMask;
1317 		VK_ACCESS_SHADER_WRITE_BIT,								//VkAccessFlags			srcAccessMask;
1318 		VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT,			//VkAccessFlags			dstAccessMask;
1319 		(VkDependencyFlags)0									//VkDependencyFlags		dependencyFlags;
1320 	};
1321 
1322 	renderPassCreateInfo.addDependency(dependency);
1323 
1324 	m_renderPass					= vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo);
1325 }
1326 
iterate(void)1327 tcu::TestStatus ConditionalRenderingUpdateBufferWithDrawTestInstance::iterate (void)
1328 {
1329 	const deUint32							queueFamilyIndex						= m_context.getUniversalQueueFamilyIndex();
1330 	VkClearColorValue						clearColorInitial						= { { 0.0f, 0.0f, 1.0f, 1.0f } };
1331 
1332 	m_cmdPool								= createCommandPool(m_vkd, m_device, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
1333 
1334 	createInitBufferWithPredicate(m_testParams.m_memoryType, m_testParams.m_testParams, true, 0, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
1335 
1336 	createTargetColorImageAndImageView();
1337 	createResultBuffer(VK_FORMAT_R8G8B8A8_UNORM);
1338 	createVertexBuffer();
1339 
1340 	m_cmdBufferPrimary						= allocateCommandBuffer(m_vkd, m_device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1341 
1342 	createRenderPass(VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1343 	createFramebuffer(m_colorTargetView.get());
1344 
1345 	DescriptorSetLayoutBuilder				builder;
1346 	builder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_ALL);
1347 	m_descriptorSetLayout					= builder.build(m_vkd, m_device, (VkDescriptorSetLayoutCreateFlags)0);
1348 
1349 	m_descriptorPool						= DescriptorPoolBuilder().addType(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2)
1350 																	 .build(m_vkd, m_device, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 2u);
1351 
1352 	createPipelineLayout();
1353 	createAndUpdateDescriptorSets();
1354 
1355 	m_vertexShaderModuleDraw				= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("position_only.vert"), 0);
1356 	m_fragmentShaderModuleDraw				= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("only_color_out.frag"), 0);
1357 	m_vertexShaderModuleUpdate				= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("update.vert"), 0);
1358 	m_fragmentShaderModuleDiscard			= createShaderModule(m_vkd, m_device, m_context.getBinaryCollection().get("discard.frag"), 0);
1359 
1360 	createPipelines();
1361 
1362 	VkConditionalRenderingBeginInfoEXT		conditionalRenderingBeginInfo =
1363 	{
1364 		VK_STRUCTURE_TYPE_CONDITIONAL_RENDERING_BEGIN_INFO_EXT,																		//VkStructureType					sType;
1365 		DE_NULL,																													//const void*						pNext;
1366 		m_conditionalRenderingBuffer->object(),																						//VkBuffer							buffer;
1367 		0,																															//VkDeviceSize						offset;
1368 		VK_CONDITIONAL_RENDERING_INVERTED_BIT_EXT																					//VkConditionalRenderingFlagsEXT	flags;
1369 	};
1370 
1371 	beginCommandBuffer(m_vkd, *m_cmdBufferPrimary);
1372 
1373 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1374 					   0u,																											//VkAccessFlags						srcAccessMask
1375 					   VK_ACCESS_TRANSFER_WRITE_BIT,																				//VkAccessFlags						dstAccessMask
1376 					   VK_IMAGE_LAYOUT_UNDEFINED,																					//VkImageLayout						oldLayout
1377 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																		//VkImageLayout						newLayout
1378 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				srcStageMask
1379 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				dstStageMask
1380 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1381 
1382 	clearWithClearColorImage(clearColorInitial);
1383 
1384 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1385 					   VK_ACCESS_TRANSFER_WRITE_BIT,																				//VkAccessFlags						srcAccessMask
1386 					   VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,									//VkAccessFlags						dstAccessMask
1387 					   VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,																		//VkImageLayout						oldLayout
1388 					   VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,																	//VkImageLayout						newLayout
1389 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				srcStageMask
1390 					   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,																//VkPipelineStageFlags				dstStageMask
1391 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1392 
1393 	beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
1394 
1395 	m_vkd.cmdBindPipeline(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineUpdate);
1396 	m_vkd.cmdBindDescriptorSets(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &(*m_descriptorSetUpdate), 0, DE_NULL);
1397 
1398 	draw();
1399 
1400 	endRenderPass(m_vkd, *m_cmdBufferPrimary);
1401 
1402 	bufferMemoryBarrier(m_conditionalRenderingBuffer->object(), m_conditionalRenderingBufferOffset, sizeof(deUint32), VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT,
1403 						VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, VK_PIPELINE_STAGE_CONDITIONAL_RENDERING_BIT_EXT);
1404 
1405 	beginRenderPass(m_vkd, *m_cmdBufferPrimary, *m_renderPass, *m_framebuffer, makeRect2D(0, 0, WIDTH, HEIGHT));
1406 
1407 	m_vkd.cmdBindPipeline(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineDraw);
1408 	m_vkd.cmdBindDescriptorSets(*m_cmdBufferPrimary, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &(*m_descriptorSet), 0, DE_NULL);
1409 
1410 	m_vkd.cmdBeginConditionalRenderingEXT(*m_cmdBufferPrimary, &conditionalRenderingBeginInfo);
1411 	draw();
1412 	m_vkd.cmdEndConditionalRenderingEXT(*m_cmdBufferPrimary);
1413 
1414 	endRenderPass(m_vkd, *m_cmdBufferPrimary);
1415 
1416 	imageMemoryBarrier(m_colorTargetImage->object(),																				//VkImage							image
1417 					   VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,																		//VkAccessFlags						srcAccessMask
1418 					   VK_ACCESS_TRANSFER_READ_BIT,																					//VkAccessFlags						dstAccessMask
1419 					   VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,																	//VkImageLayout						oldLayout
1420 					   VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,																		//VkImageLayout						newLayout
1421 					   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,																//VkPipelineStageFlags				srcStageMask
1422 					   VK_PIPELINE_STAGE_TRANSFER_BIT,																				//VkPipelineStageFlags				dstStageMask
1423 					   VK_IMAGE_ASPECT_COLOR_BIT);																					//VkImageAspectFlags				flags
1424 
1425 	copyResultImageToBuffer(VK_IMAGE_ASPECT_COLOR_BIT, m_colorTargetImage->object());
1426 
1427 	const vk::VkBufferMemoryBarrier bufferMemoryBarrier =
1428 	{
1429 		vk::VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
1430 		DE_NULL,
1431 		vk::VK_ACCESS_TRANSFER_WRITE_BIT,
1432 		vk::VK_ACCESS_HOST_READ_BIT,
1433 		VK_QUEUE_FAMILY_IGNORED,
1434 		VK_QUEUE_FAMILY_IGNORED,
1435 		m_resultBuffer->object(),
1436 		0u,
1437 		VK_WHOLE_SIZE
1438 	};
1439 
1440 	m_vkd.cmdPipelineBarrier(*m_cmdBufferPrimary, vk::VK_PIPELINE_STAGE_TRANSFER_BIT, vk::VK_PIPELINE_STAGE_HOST_BIT, 0u, 0u, DE_NULL, 1u, &bufferMemoryBarrier, 0u, DE_NULL);
1441 
1442 	endCommandBuffer(m_vkd, *m_cmdBufferPrimary);
1443 
1444 	submitCommandsAndWait(m_vkd, m_device, m_queue, *m_cmdBufferPrimary);
1445 
1446 	invalidateMappedMemoryRange(m_vkd, m_device, m_resultBuffer->getBoundMemory().getMemory(), m_resultBuffer->getBoundMemory().getOffset(), VK_WHOLE_SIZE);
1447 
1448 	tcu::ConstPixelBufferAccess			result(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), m_resultBuffer->getBoundMemory().getHostPtr());
1449 
1450 	std::vector<float>					referenceData(4 * WIDTH * HEIGHT, 0.0f);
1451 	tcu::PixelBufferAccess				reference(mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), tcu::IVec3(WIDTH, HEIGHT, 1), referenceData.data());
1452 
1453 	m_testParams.m_testParams ? prepareReferenceImageOneColor(reference, tcu::Vec4(0,1,0,1)) : prepareReferenceImageOneColor(reference, clearColorInitial);
1454 
1455 	if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Comparison", "Comparison", reference, result, tcu::Vec4(0.01f), tcu::COMPARE_LOG_ON_ERROR))
1456 		return tcu::TestStatus::fail("Fail");
1457 
1458 	return tcu::TestStatus::pass("Pass");
1459 }
1460 
1461 struct AddProgramsDraw
1462 {
initvkt::conditional::__anon17db5d880111::AddProgramsDraw1463 	void init (SourceCollections& sources, DrawTestParams testParams) const
1464 	{
1465 		DE_UNREF(testParams);
1466 
1467 		const char* const		vertexShader =
1468 			"#version 430\n"
1469 
1470 			"layout(std430, binding = 0) buffer BufferPos {\n"
1471 			"vec4 p[100];\n"
1472 			"} pos;\n"
1473 
1474 			"out gl_PerVertex{\n"
1475 			"vec4 gl_Position;\n"
1476 			"};\n"
1477 
1478 			"void main() {\n"
1479 			"gl_Position = pos.p[gl_VertexIndex];\n"
1480 			"}\n";
1481 
1482 		sources.glslSources.add("position_only.vert") << glu::VertexSource(vertexShader);
1483 
1484 		const char* const		fragmentShader =
1485 			"#version 430\n"
1486 
1487 			"layout(location = 0) out vec4 my_FragColor;\n"
1488 
1489 			"layout (push_constant) uniform AreaSelect {\n"
1490 			"	ivec4 number;\n"
1491 			"} Area;\n"
1492 
1493 			"void main() {\n"
1494 			"	if((gl_FragCoord.y < 64) && (Area.number.x != 0)) discard;\n"
1495 			"	if((gl_FragCoord.y >= 64) && (gl_FragCoord.y < 128) && (Area.number.x != 1)) discard;\n"
1496 			"	if((gl_FragCoord.y >= 128) && (gl_FragCoord.y < 192) && (Area.number.x != 2)) discard;\n"
1497 			"	if((gl_FragCoord.y >= 192) && (Area.number.x != 3)) discard;\n"
1498 			"	my_FragColor = vec4(0,1,0,1);\n"
1499 			"}\n";
1500 
1501 		sources.glslSources.add("only_color_out.frag") << glu::FragmentSource(fragmentShader);
1502 	}
1503 };
1504 
1505 struct AddProgramsUpdateBufferUsingRendering
1506 {
initvkt::conditional::__anon17db5d880111::AddProgramsUpdateBufferUsingRendering1507 	void init (SourceCollections& sources, UpdateBufferWithDrawTestParams testParams) const
1508 	{
1509 		std::string				atomicOperation			= (testParams.m_testParams ? "atomicMin(predicate.p, 0);" : "atomicMax(predicate.p, 1);");
1510 
1511 		std::string				vertexShaderUpdate =
1512 			"#version 430\n"
1513 
1514 			"layout(std430, binding = 0) buffer Predicate {\n"
1515 			"uint p;\n"
1516 			"} predicate;\n"
1517 
1518 			"out gl_PerVertex{\n"
1519 			"vec4 gl_Position;\n"
1520 			"};\n"
1521 
1522 			"void main() {\n" +
1523 			atomicOperation +
1524 			"gl_Position = vec4(1.0);\n"
1525 			"}\n";
1526 
1527 		sources.glslSources.add("update.vert") << glu::VertexSource(vertexShaderUpdate);
1528 
1529 		const char* const		vertexShaderDraw =
1530 			"#version 430\n"
1531 
1532 			"layout(std430, binding = 0) buffer BufferPos {\n"
1533 			"vec4 p[100];\n"
1534 			"} pos;\n"
1535 
1536 			"out gl_PerVertex{\n"
1537 			"vec4 gl_Position;\n"
1538 			"};\n"
1539 
1540 			"void main() {\n"
1541 			"gl_Position = pos.p[gl_VertexIndex];\n"
1542 			"}\n";
1543 
1544 		sources.glslSources.add("position_only.vert") << glu::VertexSource(vertexShaderDraw);
1545 
1546 		const char* const		fragmentShaderDiscard =
1547 			"#version 430\n"
1548 
1549 			"layout(location = 0) out vec4 my_FragColor;\n"
1550 
1551 			"void main() {\n"
1552 			"	discard;\n"
1553 			"}\n";
1554 
1555 		sources.glslSources.add("discard.frag")
1556 			<< glu::FragmentSource(fragmentShaderDiscard);
1557 
1558 		const char* const		fragmentShaderDraw =
1559 			"#version 430\n"
1560 
1561 			"layout(location = 0) out vec4 my_FragColor;\n"
1562 
1563 			"void main() {\n"
1564 			"	my_FragColor = vec4(0,1,0,1);\n"
1565 			"}\n";
1566 
1567 		sources.glslSources.add("only_color_out.frag") << glu::FragmentSource(fragmentShaderDraw);
1568 	}
1569 };
1570 
checkSupport(Context & context)1571 void checkSupport (Context& context)
1572 {
1573 	context.requireDeviceFunctionality("VK_EXT_conditional_rendering");
1574 }
1575 
checkFan(Context & context)1576 void checkFan (Context& context)
1577 {
1578 	checkSupport(context);
1579 
1580 	if (context.isDeviceFunctionalitySupported("VK_KHR_portability_subset") &&
1581 		!context.getPortabilitySubsetFeatures().triangleFans)
1582 	{
1583 		TCU_THROW(NotSupportedError, "VK_KHR_portability_subset: Triangle fans are not supported by this implementation");
1584 	}
1585 }
1586 
checkFanAndVertexStores(Context & context)1587 void checkFanAndVertexStores (Context& context)
1588 {
1589 	checkFan(context);
1590 
1591 	const auto& features = context.getDeviceFeatures();
1592 	if (!features.vertexPipelineStoresAndAtomics)
1593 		TCU_THROW(NotSupportedError, "Vertex pipeline stores and atomics not supported");
1594 }
1595 
1596 } // unnamed namespace
1597 
ConditionalRenderingDrawAndClearTests(tcu::TestContext & testCtx)1598 ConditionalRenderingDrawAndClearTests::ConditionalRenderingDrawAndClearTests (tcu::TestContext &testCtx)
1599 	: TestCaseGroup (testCtx, "draw_clear", "VK_EXT_conditional_rendering extension tests")
1600 {
1601 	/* Left blank on purpose */
1602 }
1603 
init(void)1604 void ConditionalRenderingDrawAndClearTests::init (void)
1605 {
1606 	tcu::TestCaseGroup*	clear	= new tcu::TestCaseGroup(m_testCtx, "clear", "Tests using vkCmdClearAttachments.");
1607 	tcu::TestCaseGroup*	color	= new tcu::TestCaseGroup(m_testCtx, "color", "Test color clear.");
1608 	tcu::TestCaseGroup*	depth	= new tcu::TestCaseGroup(m_testCtx, "depth", "Test depth clear.");
1609 	tcu::TestCaseGroup*	draw	= new tcu::TestCaseGroup(m_testCtx, "draw", "Test drawing.");
1610 
1611 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(clearColorTestGrid); testNdx++)
1612 		color->addChild(new InstanceFactory1WithSupport<ConditionalRenderingClearAttachmentsTestInstance, ClearTestParams, FunctionSupport0>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, generateClearTestName(clearColorTestGrid[testNdx]), "Color clear test.", clearColorTestGrid[testNdx], checkSupport));
1613 
1614 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(clearDepthTestGrid); testNdx++)
1615 		depth->addChild(new InstanceFactory1WithSupport<ConditionalRenderingClearAttachmentsTestInstance, ClearTestParams, FunctionSupport0>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, generateClearTestName(clearDepthTestGrid[testNdx]), "Depth clear test.", clearDepthTestGrid[testNdx], checkSupport));
1616 
1617 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(clearColorTwiceGrid); testNdx++)
1618 		color->addChild(new InstanceFactory1WithSupport<ConditionalRenderingClearAttachmentsTestInstance, ClearTestParams, FunctionSupport0>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "clear_attachment_twice_" + generateClearTestName(clearColorTwiceGrid[testNdx]), "Color clear test.", clearColorTwiceGrid[testNdx], checkSupport));
1619 
1620 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(clearDepthTwiceGrid); testNdx++)
1621 		depth->addChild(new InstanceFactory1WithSupport<ConditionalRenderingClearAttachmentsTestInstance, ClearTestParams, FunctionSupport0>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, "clear_attachment_twice_" + generateClearTestName(clearDepthTwiceGrid[testNdx]), "Depth clear test.", clearDepthTwiceGrid[testNdx], checkSupport));
1622 
1623 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(drawTestGrid); testNdx++)
1624 		draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingDrawTestInstance, DrawTestParams, FunctionSupport0, AddProgramsDraw>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, generateDrawTestName(testNdx, drawTestGrid[testNdx]), "Draw test.", AddProgramsDraw(), drawTestGrid[testNdx], checkFan));
1625 
1626 	for (int testNdx = 0; testNdx < DE_LENGTH_OF_ARRAY(UpdateBufferWithDrawTestGrind); testNdx++)
1627 		draw->addChild(new InstanceFactory1WithSupport<ConditionalRenderingUpdateBufferWithDrawTestInstance, UpdateBufferWithDrawTestParams, FunctionSupport0, AddProgramsUpdateBufferUsingRendering>(m_testCtx, tcu::NODETYPE_SELF_VALIDATE, generateUpdateBufferWithDrawTestName(UpdateBufferWithDrawTestGrind[testNdx]), "Draw test.", AddProgramsUpdateBufferUsingRendering(), UpdateBufferWithDrawTestGrind[testNdx], checkFanAndVertexStores));
1628 
1629 	clear->addChild(color);
1630 	clear->addChild(depth);
1631 	addChild(clear);
1632 	addChild(draw);
1633 }
1634 
1635 } // Draw
1636 } // vkt
1637