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