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