1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2021 The Khronos Group Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief Vulkan Dynamic Rendering Tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "deRandom.hpp"
25 #include "deUniquePtr.hpp"
26
27 #include "tcuImageCompare.hpp"
28 #include "tcuRGBA.hpp"
29 #include "tcuTestLog.hpp"
30 #include "tcuTextureUtil.hpp"
31 #include "tcuVectorUtil.hpp"
32
33 #include "vkBarrierUtil.hpp"
34 #include "vkBuilderUtil.hpp"
35 #include "vkCmdUtil.hpp"
36 #include "vktDrawBufferObjectUtil.hpp"
37 #include "vktDynamicRenderingTests.hpp"
38 #include "vkImageUtil.hpp"
39 #include "vkObjUtil.hpp"
40 #include "vkQueryUtil.hpp"
41 #include "vkRefUtil.hpp"
42 #include "vktTestGroupUtil.hpp"
43 #include "vktTestCase.hpp"
44 #include "vkTypeUtil.hpp"
45
46 #include <iostream>
47
48 namespace vkt
49 {
50 namespace renderpass
51 {
52 namespace
53 {
54
55 using namespace vk;
56 using namespace Draw;
57
58 using de::MovePtr;
59 using de::SharedPtr;
60 using de::UniquePtr;
61
62 using tcu::IVec4;
63 using tcu::UVec2;
64 using tcu::UVec4;
65 using tcu::Vec4;
66
67 // maxColorAttachments is guaranteed to be at least 4.
68 constexpr uint32_t COLOR_ATTACHMENTS_NUMBER = 4;
69
70 constexpr uint32_t TEST_ATTACHMENT_LOAD_OP_LAST = 3;
71
72 enum TestType
73 {
74 // Draw two triangles in a single primary command buffer, beginning and ending the render pass instance.
75 TEST_TYPE_SINGLE_CMDBUF = 0,
76 // Draw two triangles in a single primary command buffer, but across two render pass instances, with the second RESUMING the first.
77 TEST_TYPE_SINGLE_CMDBUF_RESUMING,
78 // Draw two triangles in two primary command buffers, across two render pass instances, with the second RESUMING the first.
79 TEST_TYPE_TWO_CMDBUF_RESUMING,
80 // Draw two triangles in two secondary command buffers, across two render pass instances,
81 //with the second RESUMING the first, both recorded to the same primary command buffer.
82 TEST_TYPE_SECONDARY_CMDBUF_RESUMING,
83 // Draw two triangles in two secondary command buffers, across two render pass instances,
84 // with the second RESUMING the first, executed in the two primary command buffers.
85 TEST_TYPE_SECONDARY_CMDBUF_TWO_PRIMARY_RESUMING,
86 // Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in one secondary command buffer,
87 // and execute it inside a single render pass instance in one primary command buffer.
88 TEST_TYPE_CONTENTS_SECONDARY_COMMAND_BUFFER,
89 // Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
90 // and execute them inside a single render pass instance in one primary command buffer.
91 TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER,
92 // Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
93 // and execute them inside two render pass instances, with the second RESUMING the first, both recorded in the same primary command buffer.
94 TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER_RESUMING,
95 // Using CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw two triangles in two secondary command buffers,
96 // and execute them inside two render pass instances, with the second RESUMING the first, recorded into two primary command buffers.
97 TEST_TYPE_CONTENTS_2_SECONDARY_2_PRIMARY_COMDBUF_RESUMING,
98 // In one primary command buffer, record two render pass instances, with the second resuming the first.In the first,
99 // draw one triangle directly in the primary command buffer.For the second, use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR,
100 // draw the second triangle in a secondary command buffer, and execute it in that second render pass instance.
101 TEST_TYPE_CONTENTS_PRIMARY_SECONDARY_COMDBUF_RESUMING,
102 // In one primary command buffer, record two render pass instances, with the second resuming the first.In the first,
103 // use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw the first triangle in a secondary command buffer,
104 // and execute it in that first render pass instance.In the second, draw one triangle directly in the primary command buffer.
105 TEST_TYPE_CONTENTS_SECONDARY_PRIMARY_COMDBUF_RESUMING,
106 // In two primary command buffers, record two render pass instances(one in each), with the second resuming the first.In the first,
107 // draw one triangle directly in the primary command buffer.For the second, use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR,
108 // draw the second triangle in a secondary command buffer, and execute it in that second render pass instance.
109 TEST_TYPE_CONTENTS_2_PRIMARY_SECONDARY_COMDBUF_RESUMING,
110 // In two primary command buffers, record two render pass instances(one in each), with the second resuming the first.In the first,
111 // use CONTENTS_SECONDARY_COMMAND_BUFFER_BIT_KHR, draw the first triangle in a secondary command buffer, and execute it in that first
112 // render pass instance.In the second, draw one triangle directly in the primary command buffer.
113 TEST_TYPE_CONTENTS_SECONDARY_2_PRIMARY_COMDBUF_RESUMING,
114 // Draw triangles inside rendering of secondary command buffer, and after rendering is ended copy results on secondary buffer.
115 // Tests mixing inside & outside render pass commands in secondary command buffers
116 TEST_TYPE_SECONDARY_CMDBUF_OUT_OF_RENDERING_COMMANDS,
117 // Test partial binding of depth/stencil formats. 3 sets of tests:
118 // 1. Clears bound resource and leaves the other untouched.
119 // 2. Clears and draws to the resource leaving the unbound as is.
120 // 3. Previous ones with secondary commands to check inheritance works as expected
121 TEST_TYPE_PARTIAL_BINDING_DEPTH_STENCIL,
122 TEST_TYPE_LAST
123 };
124
125 enum TestAttachmentType
126 {
127 TEST_ATTACHMENT_SINGLE_COLOR = 0,
128 TEST_ATTACHMENT_DEPTH_ATTACHMENT,
129 TEST_ATTACHMENT_STENCIL_ATTACHMENT,
130 TEST_ATTACHMENT_MULTIPLE_COLOR,
131 TEST_ATTACHMENT_NONE,
132 TEST_ATTACHMENT_ALL,
133 TEST_ATTACHMENT_LAST
134 };
135
136 enum TestAttachmentStoreOp
137 {
138 TEST_ATTACHMENT_STORE_OP_STORE = VK_ATTACHMENT_STORE_OP_STORE,
139 TEST_ATTACHMENT_STORE_OP_DONT_CARE = VK_ATTACHMENT_STORE_OP_DONT_CARE,
140 TEST_ATTACHMENT_STORE_OP_LAST
141 };
142
143 struct TestParameters
144 {
145 TestType testType;
146 const Vec4 clearColor;
147 float depthClearValue;
148 uint32_t stencilClearValue;
149 const VkFormat imageFormat;
150 const UVec2 renderSize;
151 };
152
153 struct ImagesLayout
154 {
155 VkImageLayout oldColors[COLOR_ATTACHMENTS_NUMBER];
156 VkImageLayout oldStencil;
157 VkImageLayout oldDepth;
158 };
159
160 struct ImagesFormat
161 {
162 VkFormat colors[COLOR_ATTACHMENTS_NUMBER];
163 VkFormat depth;
164 VkFormat stencil;
165 };
166
167 struct ClearAttachmentData
168 {
169 std::vector<VkClearAttachment> colorDepthClear1;
170 std::vector<VkClearAttachment> colorDepthClear2;
171 VkClearAttachment stencilClear1;
172 VkClearAttachment stencilClear2;
173 VkClearRect rectColorDepth1;
174 VkClearRect rectColorDepth2;
175 VkClearRect rectStencil1;
176 VkClearRect rectStencil2;
177
ClearAttachmentDatavkt::renderpass::__anon912580460111::ClearAttachmentData178 ClearAttachmentData(const uint32_t colorAtchCount, const VkFormat depth, const VkFormat stencil)
179 {
180 if (colorAtchCount != 0)
181 {
182 for (uint32_t atchNdx = 0; atchNdx < colorAtchCount; ++atchNdx)
183 {
184 const VkClearAttachment green = {
185 VK_IMAGE_ASPECT_COLOR_BIT, atchNdx,
186 makeClearValueColorF32(0.0f, 1.0f, static_cast<float>(atchNdx) * 0.15f, 1.0f)};
187 colorDepthClear1.push_back(green);
188
189 const VkClearAttachment yellow = {
190 VK_IMAGE_ASPECT_COLOR_BIT, atchNdx,
191 makeClearValueColorF32(1.0f, 1.0f, static_cast<float>(atchNdx) * 0.15f, 1.0f)};
192 colorDepthClear2.push_back(yellow);
193 }
194 }
195
196 if (depth != VK_FORMAT_UNDEFINED)
197 {
198 const VkClearAttachment zero = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, makeClearValueDepthStencil(0.0f, 0)};
199 colorDepthClear1.push_back(zero);
200
201 const VkClearAttachment one = {VK_IMAGE_ASPECT_DEPTH_BIT, 0, makeClearValueDepthStencil(0.2f, 0)};
202 colorDepthClear2.push_back(one);
203 }
204
205 if (stencil != VK_FORMAT_UNDEFINED)
206 {
207 stencilClear1 = {VK_IMAGE_ASPECT_STENCIL_BIT, 0, makeClearValueDepthStencil(0.0f, 1)};
208
209 stencilClear2 = {VK_IMAGE_ASPECT_STENCIL_BIT, 0, makeClearValueDepthStencil(0.0f, 2)};
210
211 rectStencil1 = {
212 makeRect2D(0, 0, 32, 16),
213 0u,
214 1u,
215 };
216
217 rectStencil2 = {
218 makeRect2D(0, 16, 32, 16),
219 0u,
220 1u,
221 };
222 }
223
224 rectColorDepth1 = {
225 makeRect2D(0, 0, 16, 32),
226 0u,
227 1u,
228 };
229
230 rectColorDepth2 = {
231 makeRect2D(16, 0, 16, 32),
232 0u,
233 1u,
234 };
235 }
236 };
237
238 template <typename T>
sizeInBytes(const std::vector<T> & vec)239 inline VkDeviceSize sizeInBytes(const std::vector<T> &vec)
240 {
241 return vec.size() * sizeof(vec[0]);
242 }
243
makeImageCreateInfo(const VkFormat format,const UVec2 & size,VkImageUsageFlags usage)244 VkImageCreateInfo makeImageCreateInfo(const VkFormat format, const UVec2 &size, VkImageUsageFlags usage)
245 {
246 const VkImageCreateInfo imageParams = {
247 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
248 DE_NULL, // const void* pNext;
249 (VkImageCreateFlags)0, // VkImageCreateFlags flags;
250 VK_IMAGE_TYPE_2D, // VkImageType imageType;
251 format, // VkFormat format;
252 makeExtent3D(size.x(), size.y(), 1), // VkExtent3D extent;
253 1u, // uint32_t mipLevels;
254 1u, // uint32_t arrayLayers;
255 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
256 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
257 usage, // VkImageUsageFlags usage;
258 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
259 0u, // uint32_t queueFamilyIndexCount;
260 DE_NULL, // const uint32_t* pQueueFamilyIndices;
261 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
262 };
263 return imageParams;
264 }
265
makeGraphicsPipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule vertexModule,const VkShaderModule fragmentModule,const UVec2 renderSize,const uint32_t colorAttachmentCount,const VkFormat * pColorAttachmentFormats,const VkFormat depthAttachmentFormat,const VkFormat stencilAttachmentFormat)266 Move<VkPipeline> makeGraphicsPipeline(const DeviceInterface &vk, const VkDevice device,
267 const VkPipelineLayout pipelineLayout, const VkShaderModule vertexModule,
268 const VkShaderModule fragmentModule, const UVec2 renderSize,
269 const uint32_t colorAttachmentCount, const VkFormat *pColorAttachmentFormats,
270 const VkFormat depthAttachmentFormat, const VkFormat stencilAttachmentFormat)
271 {
272 const VkVertexInputBindingDescription vertexInputBindingDescription = {
273 0u, // uint32_t binding;
274 sizeof(Vec4), // uint32_t stride;
275 VK_VERTEX_INPUT_RATE_VERTEX, // VkVertexInputRate inputRate;
276 };
277
278 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] = {
279 {
280 0u, // uint32_t location;
281 0u, // uint32_t binding;
282 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
283 0u, // uint32_t offset;
284 },
285 };
286
287 const VkPipelineVertexInputStateCreateInfo vertexInputStateInfo = {
288 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
289 DE_NULL, // const void* pNext;
290 (VkPipelineVertexInputStateCreateFlags)0, // VkPipelineVertexInputStateCreateFlags flags;
291 1u, // uint32_t vertexBindingDescriptionCount;
292 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
293 DE_LENGTH_OF_ARRAY(vertexInputAttributeDescriptions), // uint32_t vertexAttributeDescriptionCount;
294 vertexInputAttributeDescriptions, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
295 };
296
297 const VkPipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateInfo = {
298 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
299 DE_NULL, // const void* pNext;
300 (VkPipelineInputAssemblyStateCreateFlags)0, // VkPipelineInputAssemblyStateCreateFlags flags;
301 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, // VkPrimitiveTopology topology;
302 VK_FALSE, // VkBool32 primitiveRestartEnable;
303 };
304
305 VkViewport viewport =
306 makeViewport(0.0f, 0.0f, static_cast<float>(renderSize.x()), static_cast<float>(renderSize.y()), 0.0f, 1.0f);
307 const VkRect2D rectScissorRenderSize = {{0, 0}, {renderSize.x(), renderSize.y()}};
308
309 const VkPipelineViewportStateCreateInfo pipelineViewportStateInfo = {
310 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
311 DE_NULL, // const void* pNext;
312 (VkPipelineViewportStateCreateFlags)0, // VkPipelineViewportStateCreateFlags flags;
313 1u, // uint32_t viewportCount;
314 &viewport, // const VkViewport* pViewports;
315 1u, // uint32_t scissorCount;
316 &rectScissorRenderSize, // const VkRect2D* pScissors;
317 };
318
319 const VkPipelineRasterizationStateCreateInfo pipelineRasterizationStateInfo = {
320 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
321 DE_NULL, // const void* pNext;
322 (VkPipelineRasterizationStateCreateFlags)0, // VkPipelineRasterizationStateCreateFlags flags;
323 VK_FALSE, // VkBool32 depthClampEnable;
324 VK_FALSE, // VkBool32 rasterizerDiscardEnable;
325 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
326 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
327 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
328 VK_FALSE, // VkBool32 depthBiasEnable;
329 0.0f, // float depthBiasConstantFactor;
330 0.0f, // float depthBiasClamp;
331 0.0f, // float depthBiasSlopeFactor;
332 1.0f, // float lineWidth;
333 };
334
335 const VkPipelineMultisampleStateCreateInfo pipelineMultisampleStateInfo = {
336 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
337 DE_NULL, // const void* pNext;
338 (VkPipelineMultisampleStateCreateFlags)0, // VkPipelineMultisampleStateCreateFlags flags;
339 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
340 VK_FALSE, // VkBool32 sampleShadingEnable;
341 0.0f, // float minSampleShading;
342 DE_NULL, // const VkSampleMask* pSampleMask;
343 VK_FALSE, // VkBool32 alphaToCoverageEnable;
344 VK_FALSE // VkBool32 alphaToOneEnable;
345 };
346
347 const VkStencilOpState stencilOp = makeStencilOpState(VK_STENCIL_OP_ZERO, // stencil fail
348 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // depth & stencil pass
349 VK_STENCIL_OP_INCREMENT_AND_CLAMP, // depth only fail
350 VK_COMPARE_OP_NOT_EQUAL, // compare op
351 240u, // compare mask
352 255u, // write mask
353 255u); // reference
354
355 const bool useDepth = (depthAttachmentFormat != VK_FORMAT_UNDEFINED);
356 const bool useStencil = (stencilAttachmentFormat != VK_FORMAT_UNDEFINED);
357
358 VkPipelineDepthStencilStateCreateInfo pipelineDepthStencilStateInfo = {
359 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
360 DE_NULL, // const void* pNext;
361 (VkPipelineDepthStencilStateCreateFlags)0, // VkPipelineDepthStencilStateCreateFlags flags;
362 (useDepth ? VK_TRUE : VK_FALSE), // VkBool32 depthTestEnable;
363 (useDepth ? VK_TRUE : VK_FALSE), // VkBool32 depthWriteEnable;
364 VK_COMPARE_OP_ALWAYS, // VkCompareOp depthCompareOp;
365 VK_FALSE, // VkBool32 depthBoundsTestEnable;
366 (useStencil ? VK_TRUE : VK_FALSE), // VkBool32 stencilTestEnable;
367 stencilOp, // VkStencilOpState front;
368 stencilOp, // VkStencilOpState back;
369 0.0f, // float minDepthBounds;
370 1.0f, // float maxDepthBounds;
371 };
372
373 const VkColorComponentFlags colorComponentsAll =
374 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
375
376 std::vector<VkPipelineColorBlendAttachmentState> colorBlendAttachmentState;
377
378 for (uint32_t ndx = 0; ndx < colorAttachmentCount; ++ndx)
379 {
380 const VkPipelineColorBlendAttachmentState pipelineColorBlendAttachmentState = {
381 VK_FALSE, // VkBool32 blendEnable;
382 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
383 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
384 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
385 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
386 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
387 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
388 colorComponentsAll, // VkColorComponentFlags colorWriteMask;
389 };
390
391 colorBlendAttachmentState.push_back(pipelineColorBlendAttachmentState);
392 }
393
394 const VkPipelineColorBlendStateCreateInfo pipelineColorBlendStateInfo = {
395 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
396 DE_NULL, // const void* pNext;
397 (VkPipelineColorBlendStateCreateFlags)0, // VkPipelineColorBlendStateCreateFlags flags;
398 VK_FALSE, // VkBool32 logicOpEnable;
399 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
400 colorAttachmentCount, // uint32_t attachmentCount;
401 colorBlendAttachmentState.data(), // const VkPipelineColorBlendAttachmentState* pAttachments;
402 {0.0f, 0.0f, 0.0f, 0.0f}, // float blendConstants[4];
403 };
404
405 const VkPipelineShaderStageCreateInfo pShaderStages[] = {
406 {
407 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
408 DE_NULL, // const void* pNext;
409 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
410 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
411 vertexModule, // VkShaderModule module;
412 "main", // const char* pName;
413 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
414 },
415 {
416 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
417 DE_NULL, // const void* pNext;
418 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
419 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
420 fragmentModule, // VkShaderModule module;
421 "main", // const char* pName;
422 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
423 },
424 };
425
426 const VkPipelineRenderingCreateInfoKHR renderingCreateInfo{
427 VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR, // VkStructureType sType;
428 DE_NULL, // const void* pNext;
429 0u, // uint32_t viewMask;
430 colorAttachmentCount, // uint32_t colorAttachmentCount;
431 pColorAttachmentFormats, // const VkFormat* pColorAttachmentFormats;
432 depthAttachmentFormat, // VkFormat depthAttachmentFormat;
433 stencilAttachmentFormat, // VkFormat stencilAttachmentFormat;
434 };
435
436 const VkGraphicsPipelineCreateInfo graphicsPipelineInfo = {
437 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
438 &renderingCreateInfo, // const void* pNext;
439 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
440 2u, // uint32_t stageCount;
441 pShaderStages, // const VkPipelineShaderStageCreateInfo* pStages;
442 &vertexInputStateInfo, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
443 &pipelineInputAssemblyStateInfo, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
444 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
445 &pipelineViewportStateInfo, // const VkPipelineViewportStateCreateInfo* pViewportState;
446 &pipelineRasterizationStateInfo, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
447 &pipelineMultisampleStateInfo, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
448 &pipelineDepthStencilStateInfo, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
449 &pipelineColorBlendStateInfo, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
450 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
451 pipelineLayout, // VkPipelineLayout layout;
452 VK_NULL_HANDLE, // VkRenderPass renderPass;
453 0u, // uint32_t subpass;
454 DE_NULL, // VkPipeline basePipelineHandle;
455 0, // int32_t basePipelineIndex;
456 };
457
458 return createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineInfo);
459 }
460
getSupportedStencilFormat(const InstanceInterface & vki,VkPhysicalDevice physDev)461 VkFormat getSupportedStencilFormat(const InstanceInterface &vki, VkPhysicalDevice physDev)
462 {
463 const VkFormat formatList[] = {VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
464 const VkFormatFeatureFlags requirements =
465 (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT);
466
467 for (int i = 0; i < DE_LENGTH_OF_ARRAY(formatList); ++i)
468 {
469 const auto properties = getPhysicalDeviceFormatProperties(vki, physDev, formatList[i]);
470 if ((properties.optimalTilingFeatures & requirements) == requirements)
471 return formatList[i];
472 }
473
474 return VK_FORMAT_UNDEFINED;
475 }
476
generateColorImage(const tcu::TextureFormat format,const UVec2 & renderSize,const int attachmentNdx)477 tcu::TextureLevel generateColorImage(const tcu::TextureFormat format, const UVec2 &renderSize, const int attachmentNdx)
478 {
479 tcu::TextureLevel image(format, renderSize.x(), renderSize.y());
480 const float atchNdx = static_cast<float>(attachmentNdx);
481 const Vec4 greenColor = Vec4(0.0f, 1.0f, atchNdx * 0.15f, 1.0f);
482 const Vec4 yellowColor = Vec4(1.0f, 1.0f, atchNdx * 0.15f, 1.0f);
483
484 for (uint32_t y = 0; y < renderSize.y(); ++y)
485 {
486 for (uint32_t x = 0; x < renderSize.x() / 2u; ++x)
487 {
488 image.getAccess().setPixel(greenColor, x, y);
489 }
490 for (uint32_t x = renderSize.x() / 2u; x < renderSize.x(); ++x)
491 {
492 image.getAccess().setPixel(yellowColor, x, y);
493 }
494 }
495
496 return image;
497 }
498
generateDepthImage(const tcu::TextureFormat format,const UVec2 & renderSize,float depthClearValue)499 tcu::TextureLevel generateDepthImage(const tcu::TextureFormat format, const UVec2 &renderSize, float depthClearValue)
500 {
501 tcu::TextureLevel image(format, renderSize.x(), renderSize.y());
502 const float value1 = 0.0f;
503 const float value2 = depthClearValue;
504
505 for (uint32_t y = 0; y < renderSize.y(); ++y)
506 {
507 for (uint32_t x = 0; x < renderSize.x() / 2u; ++x)
508 {
509 image.getAccess().setPixDepth(value1, x, y);
510 }
511 for (uint32_t x = renderSize.x() / 2u; x < renderSize.x(); ++x)
512 {
513 image.getAccess().setPixDepth(value2, x, y);
514 }
515 }
516
517 return image;
518 }
519
generateStencilImage(const tcu::TextureFormat format,const UVec2 & renderSize,uint32_t stencilClearValue)520 tcu::TextureLevel generateStencilImage(const tcu::TextureFormat format, const UVec2 &renderSize,
521 uint32_t stencilClearValue)
522 {
523 tcu::TextureLevel image(format, renderSize.x(), renderSize.y());
524 const IVec4 value1 = IVec4(1, 0, 0, 0);
525 const IVec4 value2 = IVec4(stencilClearValue, 0, 0, 0);
526
527 for (uint32_t x = 0; x < renderSize.x(); ++x)
528 {
529 for (uint32_t y = 0; y < renderSize.y() / 2u; ++y)
530 {
531 image.getAccess().setPixel(value1, x, y);
532 }
533 for (uint32_t y = renderSize.y() / 2u; y < renderSize.y(); ++y)
534 {
535 image.getAccess().setPixel(value2, x, y);
536 }
537 }
538
539 return image;
540 }
541
submitCommandsAndWait(const DeviceInterface & vk,const VkDevice device,const VkQueue queue,const VkCommandBuffer commandBuffer,const VkCommandBuffer commandBuffer2)542 void submitCommandsAndWait(const DeviceInterface &vk, const VkDevice device, const VkQueue queue,
543 const VkCommandBuffer commandBuffer, const VkCommandBuffer commandBuffer2)
544 {
545 const Unique<VkFence> fence(createFence(vk, device));
546 const VkCommandBuffer cmdBuffers[2] = {commandBuffer, commandBuffer2};
547
548 const VkSubmitInfo submitInfo = {
549 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
550 DE_NULL, // const void* pNext;
551 0u, // uint32_t waitSemaphoreCount;
552 DE_NULL, // const VkSemaphore* pWaitSemaphores;
553 DE_NULL, // const VkPipelineStageFlags* pWaitDstStageMask;
554 2u, // uint32_t commandBufferCount;
555 cmdBuffers, // const VkCommandBuffer* pCommandBuffers;
556 0u, // uint32_t signalSemaphoreCount;
557 nullptr, // const VkSemaphore* pSignalSemaphores;
558 };
559
560 VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence));
561 VK_CHECK(vk.waitForFences(device, 1u, &fence.get(), true, ~0ull));
562 }
563
beginSecondaryCmdBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer,VkRenderingFlagsKHR renderingFlags,const uint32_t colorAttachmentCount,const ImagesFormat & imagesFormat)564 void beginSecondaryCmdBuffer(const DeviceInterface &vk, const VkCommandBuffer commandBuffer,
565 VkRenderingFlagsKHR renderingFlags, const uint32_t colorAttachmentCount,
566 const ImagesFormat &imagesFormat)
567 {
568 const VkCommandBufferInheritanceRenderingInfoKHR inheritanceRenderingInfo{
569 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_RENDERING_INFO_KHR, // VkStructureType sType;
570 DE_NULL, // const void* pNext;
571 renderingFlags, // VkRenderingFlagsKHR flags;
572 0u, // uint32_t viewMask;
573 colorAttachmentCount, // uint32_t colorAttachmentCount;
574 (colorAttachmentCount > 0) ? imagesFormat.colors : DE_NULL, // const VkFormat* pColorAttachmentFormats;
575 imagesFormat.depth, // VkFormat depthAttachmentFormat;
576 imagesFormat.stencil, // VkFormat stencilAttachmentFormat;
577 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
578 };
579
580 const VkCommandBufferInheritanceInfo bufferInheritanceInfo = {
581 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // VkStructureType sType;
582 &inheritanceRenderingInfo, // const void* pNext;
583 VK_NULL_HANDLE, // VkRenderPass renderPass;
584 0u, // uint32_t subpass;
585 VK_NULL_HANDLE, // VkFramebuffer framebuffer;
586 VK_FALSE, // VkBool32 occlusionQueryEnable;
587 (vk::VkQueryControlFlags)0u, // VkQueryControlFlags queryFlags;
588 (vk::VkQueryPipelineStatisticFlags)0u // VkQueryPipelineStatisticFlags pipelineStatistics;
589 };
590
591 const VkCommandBufferBeginInfo commandBufBeginParams = {
592 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
593 DE_NULL, // const void* pNext;
594 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
595 VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, // VkCommandBufferUsageFlags flags;
596 &bufferInheritanceInfo};
597 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
598 }
599
beginSecondaryCmdBuffer(const DeviceInterface & vk,const VkCommandBuffer commandBuffer)600 void beginSecondaryCmdBuffer(const DeviceInterface &vk, const VkCommandBuffer commandBuffer)
601 {
602 const VkCommandBufferInheritanceInfo bufferInheritanceInfo = {
603 vk::VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // VkStructureType sType;
604 DE_NULL, // const void* pNext;
605 VK_NULL_HANDLE, // VkRenderPass renderPass;
606 0u, // uint32_t subpass;
607 VK_NULL_HANDLE, // VkFramebuffer framebuffer;
608 VK_FALSE, // VkBool32 occlusionQueryEnable;
609 (vk::VkQueryControlFlags)0u, // VkQueryControlFlags queryFlags;
610 (vk::VkQueryPipelineStatisticFlags)0u // VkQueryPipelineStatisticFlags pipelineStatistics;
611 };
612
613 const VkCommandBufferBeginInfo commandBufBeginParams = {
614 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
615 DE_NULL, // const void* pNext;
616 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
617 &bufferInheritanceInfo};
618 VK_CHECK(vk.beginCommandBuffer(commandBuffer, &commandBufBeginParams));
619 }
620
621 class DynamicRenderingTestInstance : public TestInstance
622 {
623 public:
624 DynamicRenderingTestInstance(Context &context, const TestParameters ¶meters);
625
626 protected:
627 virtual tcu::TestStatus iterate(void);
628 void initialize(void);
629 void createCmdBuffer(void);
630 virtual void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
631 const uint32_t colorAtchCount, ImagesLayout &imagesLayout, const ImagesFormat &imagesFormat);
632 void preBarier(VkCommandBuffer cmdBuffer, const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
633 const ImagesFormat &imagesFormat);
634 void beginRendering(VkCommandBuffer cmdBuffer, const std::vector<VkImageView> &attachmentBindInfos,
635 const VkRenderingFlagsKHR flags, const uint32_t colorAtchCount,
636 const ImagesFormat &imagesFormat, const VkAttachmentLoadOp loadOp,
637 const VkAttachmentStoreOp storeOp);
638 void copyImgToBuff(VkCommandBuffer commandBuffer, const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
639 const ImagesFormat &imagesFormat);
640 void verifyResults(const uint32_t colorAtchCount, const ImagesFormat &imagesFormat);
641 void verifyDepth(const tcu::TextureLevel &depthReference);
642 void verifyStencil(const tcu::TextureLevel &stencilReference);
643
644 const TestParameters m_parameters;
645 VkFormat m_formatStencilDepthImage;
646 Move<VkImage> m_imageColor[COLOR_ATTACHMENTS_NUMBER];
647 Move<VkImage> m_imageStencilDepth;
648 Move<VkImageView> m_colorAttachmentView[COLOR_ATTACHMENTS_NUMBER];
649 Move<VkImageView> m_stencilDepthAttachmentView;
650 MovePtr<Allocation> m_imageColorAlloc[COLOR_ATTACHMENTS_NUMBER];
651 MovePtr<Allocation> m_imageStencilDepthAlloc;
652 SharedPtr<Buffer> m_imageBuffer[COLOR_ATTACHMENTS_NUMBER];
653 SharedPtr<Buffer> m_imageDepthBuffer;
654 SharedPtr<Buffer> m_imageStencilBuffer;
655
656 Move<VkShaderModule> m_vertexModule;
657 Move<VkShaderModule> m_fragmentModule;
658 SharedPtr<Buffer> m_vertexBuffer;
659 Move<VkPipelineLayout> m_pipelineLayout;
660
661 Move<VkCommandPool> m_cmdPool;
662 Move<VkCommandBuffer> m_cmdBuffer;
663
664 std::vector<tcu::TextureLevel> m_referenceImages;
665 };
666
DynamicRenderingTestInstance(Context & context,const TestParameters & parameters)667 DynamicRenderingTestInstance::DynamicRenderingTestInstance(Context &context, const TestParameters ¶meters)
668 : TestInstance(context)
669 , m_parameters(parameters)
670 {
671 const VkPhysicalDeviceDynamicRenderingFeaturesKHR &dynamicRenderingFeatures(context.getDynamicRenderingFeatures());
672
673 if (dynamicRenderingFeatures.dynamicRendering == false)
674 TCU_FAIL("dynamicRendering is not supported");
675
676 initialize();
677 createCmdBuffer();
678 }
679
iterate(void)680 tcu::TestStatus DynamicRenderingTestInstance::iterate(void)
681 {
682 const DeviceInterface &vk = m_context.getDeviceInterface();
683 const VkDevice device = m_context.getDevice();
684
685 ImagesLayout imagesLayout{
686 {VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
687 VK_IMAGE_LAYOUT_UNDEFINED}, // oldColors
688 VK_IMAGE_LAYOUT_UNDEFINED, // oldLStencil
689 VK_IMAGE_LAYOUT_UNDEFINED, // oldDepth
690 };
691
692 for (int attachmentTest = 0; attachmentTest < TEST_ATTACHMENT_LAST; ++attachmentTest)
693 {
694 std::vector<VkImageView> attachmentBindInfos;
695
696 ImagesFormat imagesFormat{
697 {
698 m_parameters.imageFormat,
699 m_parameters.imageFormat,
700 m_parameters.imageFormat,
701 m_parameters.imageFormat,
702 }, // colors
703 m_formatStencilDepthImage, // depth
704 m_formatStencilDepthImage, // stencil
705 };
706
707 uint32_t colorAtchCount = 0u;
708
709 switch (attachmentTest)
710 {
711 case TEST_ATTACHMENT_SINGLE_COLOR:
712 {
713 attachmentBindInfos.push_back(*m_colorAttachmentView[0]);
714 imagesFormat.depth = VK_FORMAT_UNDEFINED;
715 imagesFormat.stencil = VK_FORMAT_UNDEFINED;
716 colorAtchCount = 1u;
717 break;
718 }
719 case TEST_ATTACHMENT_DEPTH_ATTACHMENT:
720 {
721 attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
722 imagesFormat.colors[0] = VK_FORMAT_UNDEFINED;
723 imagesFormat.stencil = VK_FORMAT_UNDEFINED;
724 break;
725 }
726 case TEST_ATTACHMENT_STENCIL_ATTACHMENT:
727 {
728 attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
729 imagesFormat.colors[0] = VK_FORMAT_UNDEFINED;
730 imagesFormat.depth = VK_FORMAT_UNDEFINED;
731 break;
732 }
733 case TEST_ATTACHMENT_MULTIPLE_COLOR:
734 {
735 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ndx++)
736 attachmentBindInfos.push_back(*m_colorAttachmentView[ndx]);
737
738 colorAtchCount = COLOR_ATTACHMENTS_NUMBER;
739 imagesFormat.depth = VK_FORMAT_UNDEFINED;
740 imagesFormat.stencil = VK_FORMAT_UNDEFINED;
741 break;
742 }
743 case TEST_ATTACHMENT_NONE:
744 {
745 imagesFormat.depth = VK_FORMAT_UNDEFINED;
746 imagesFormat.stencil = VK_FORMAT_UNDEFINED;
747 break;
748 }
749 case TEST_ATTACHMENT_ALL:
750 {
751 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ndx++)
752 attachmentBindInfos.push_back(*m_colorAttachmentView[ndx]);
753
754 attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
755 attachmentBindInfos.push_back(*m_stencilDepthAttachmentView);
756
757 colorAtchCount = COLOR_ATTACHMENTS_NUMBER;
758 break;
759 }
760 default:
761 DE_FATAL("Impossible");
762 };
763 Move<VkPipeline> pipeline = makeGraphicsPipeline(vk, device, *m_pipelineLayout, *m_vertexModule,
764 *m_fragmentModule, m_parameters.renderSize, colorAtchCount,
765 imagesFormat.colors, imagesFormat.depth, imagesFormat.stencil);
766
767 rendering(*pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat);
768 }
769 return tcu::TestStatus::pass("Pass");
770 }
771
initialize(void)772 void DynamicRenderingTestInstance::initialize(void)
773 {
774 const InstanceInterface &vki = m_context.getInstanceInterface();
775 const DeviceInterface &vk = m_context.getDeviceInterface();
776 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
777 const VkDevice device = m_context.getDevice();
778 Allocator &allocator = m_context.getDefaultAllocator();
779
780 // Vertices.
781 {
782 std::vector<Vec4> vertices;
783
784 // Draw a quad covering the whole renderarea
785 vertices.push_back(Vec4(-1.0f, 1.0f, 0.0f, 1.0f));
786 vertices.push_back(Vec4(-1.0f, -1.0f, 0.0f, 1.0f));
787 vertices.push_back(Vec4(0.0f, 1.0f, 0.0f, 1.0f));
788 vertices.push_back(Vec4(0.0f, -1.0f, 0.0f, 1.0f));
789
790 vertices.push_back(Vec4(1.0f, -1.0f, 0.2f, 1.0f));
791 vertices.push_back(Vec4(0.0f, -1.0f, 0.2f, 1.0f));
792 vertices.push_back(Vec4(1.0f, 1.0f, 0.2f, 1.0f));
793 vertices.push_back(Vec4(0.0f, 1.0f, 0.2f, 1.0f));
794
795 vertices.push_back(Vec4(-1.0f, 1.0f, 0.0f, 1.0f));
796 vertices.push_back(Vec4(-1.0f, 0.0f, 0.0f, 1.0f));
797 vertices.push_back(Vec4(1.0f, 1.0f, 0.0f, 1.0f));
798 vertices.push_back(Vec4(1.0f, 0.0f, 0.0f, 1.0f));
799
800 const VkDeviceSize bufferSize = sizeInBytes(vertices);
801 const VkBufferCreateInfo bufferInfo = makeBufferCreateInfo(bufferSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
802
803 m_vertexBuffer = Buffer::createAndAlloc(vk, device, bufferInfo, allocator, MemoryRequirement::HostVisible);
804 deMemcpy(m_vertexBuffer->getBoundMemory().getHostPtr(), vertices.data(), static_cast<std::size_t>(bufferSize));
805 flushAlloc(vk, device, m_vertexBuffer->getBoundMemory());
806 }
807
808 // Images color attachment.
809 {
810 const VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
811 const VkDeviceSize imageBufferSize = m_parameters.renderSize.x() * m_parameters.renderSize.y() *
812 tcu::getPixelSize(mapVkFormat(m_parameters.imageFormat));
813 const VkImageSubresourceRange imageSubresource =
814 makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
815 const VkImageCreateInfo imageInfo =
816 makeImageCreateInfo(m_parameters.imageFormat, m_parameters.renderSize, imageUsage);
817 const VkBufferCreateInfo bufferInfo = makeBufferCreateInfo(imageBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
818
819 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
820 {
821 m_imageColor[ndx] = makeImage(vk, device, imageInfo);
822 m_imageColorAlloc[ndx] = bindImage(vk, device, allocator, *m_imageColor[ndx], MemoryRequirement::Any);
823 m_imageBuffer[ndx] =
824 Buffer::createAndAlloc(vk, device, bufferInfo, allocator, MemoryRequirement::HostVisible);
825 m_colorAttachmentView[ndx] = makeImageView(vk, device, *m_imageColor[ndx], VK_IMAGE_VIEW_TYPE_2D,
826 m_parameters.imageFormat, imageSubresource);
827
828 const Allocation alloc = m_imageBuffer[ndx]->getBoundMemory();
829 deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(imageBufferSize));
830 flushAlloc(vk, device, alloc);
831 }
832 }
833
834 //Image stencil and depth attachment.
835 {
836 m_formatStencilDepthImage = getSupportedStencilFormat(vki, physDevice);
837
838 const VkImageAspectFlags imageDepthStencilAspec = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
839 const VkImageSubresourceRange imageStencilSubresource =
840 makeImageSubresourceRange(imageDepthStencilAspec, 0u, 1u, 0u, 1u);
841 const VkDeviceSize imageBufferStencilSize = m_parameters.renderSize.x() * m_parameters.renderSize.y() *
842 tcu::getPixelSize(mapVkFormat(VK_FORMAT_S8_UINT));
843 const VkDeviceSize imageBufferDepthSize = m_parameters.renderSize.x() * m_parameters.renderSize.y() *
844 tcu::getPixelSize(getDepthCopyFormat(m_formatStencilDepthImage));
845
846 const VkImageUsageFlags imageStenciDepthUsage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
847 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
848 VK_IMAGE_USAGE_TRANSFER_DST_BIT;
849 const VkImageCreateInfo imageInfo =
850 makeImageCreateInfo(m_formatStencilDepthImage, m_parameters.renderSize, imageStenciDepthUsage);
851 const VkBufferCreateInfo bufferStencilInfo =
852 makeBufferCreateInfo(imageBufferStencilSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
853 const VkBufferCreateInfo bufferDepthInfo =
854 makeBufferCreateInfo(imageBufferDepthSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
855
856 m_imageStencilDepth = makeImage(vk, device, imageInfo);
857 m_imageStencilDepthAlloc = bindImage(vk, device, allocator, *m_imageStencilDepth, MemoryRequirement::Any);
858
859 m_imageStencilBuffer =
860 Buffer::createAndAlloc(vk, device, bufferStencilInfo, allocator, MemoryRequirement::HostVisible);
861 m_imageDepthBuffer =
862 Buffer::createAndAlloc(vk, device, bufferDepthInfo, allocator, MemoryRequirement::HostVisible);
863 m_stencilDepthAttachmentView = makeImageView(vk, device, *m_imageStencilDepth, VK_IMAGE_VIEW_TYPE_2D,
864 m_formatStencilDepthImage, imageStencilSubresource);
865
866 const Allocation alloc = m_imageStencilBuffer->getBoundMemory();
867 deMemset(alloc.getHostPtr(), 0, static_cast<std::size_t>(imageBufferStencilSize));
868 flushAlloc(vk, device, alloc);
869
870 const Allocation allocDepth = m_imageDepthBuffer->getBoundMemory();
871 deMemset(allocDepth.getHostPtr(), 0, static_cast<std::size_t>(imageBufferDepthSize));
872 flushAlloc(vk, device, allocDepth);
873 }
874
875 m_pipelineLayout = makePipelineLayout(vk, device);
876 m_vertexModule = createShaderModule(vk, device, m_context.getBinaryCollection().get("vert"), 0u);
877 m_fragmentModule = createShaderModule(vk, device, m_context.getBinaryCollection().get("frag"), 0u);
878
879 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
880 {
881 m_referenceImages.push_back(
882 generateColorImage(mapVkFormat(m_parameters.imageFormat), m_parameters.renderSize, ndx));
883 }
884
885 m_referenceImages.push_back(
886 generateDepthImage(getDepthCopyFormat(m_formatStencilDepthImage), m_parameters.renderSize, 0.2f));
887
888 m_referenceImages.push_back(generateStencilImage(mapVkFormat(VK_FORMAT_S8_UINT), m_parameters.renderSize, 2U));
889 }
890
createCmdBuffer(void)891 void DynamicRenderingTestInstance::createCmdBuffer(void)
892 {
893 const DeviceInterface &vk = m_context.getDeviceInterface();
894 const VkDevice device = m_context.getDevice();
895
896 m_cmdPool = createCommandPool(vk, device, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
897 m_context.getUniversalQueueFamilyIndex());
898 m_cmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
899 }
900
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)901 void DynamicRenderingTestInstance::rendering(const VkPipeline pipeline,
902 const std::vector<VkImageView> &attachmentBindInfos,
903 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
904 const ImagesFormat &imagesFormat)
905 {
906 const DeviceInterface &vk = m_context.getDeviceInterface();
907 const VkDevice device = m_context.getDevice();
908 const VkQueue queue = m_context.getUniversalQueue();
909
910 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
911 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
912 {
913
914 beginCommandBuffer(vk, *m_cmdBuffer);
915 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
916
917 beginRendering(*m_cmdBuffer, attachmentBindInfos, 0, colorAtchCount, imagesFormat,
918 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
919 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
920
921 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
922
923 {
924 const VkBuffer vertexBuffer = m_vertexBuffer->object();
925 const VkDeviceSize vertexBufferOffset = 0ull;
926 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
927 }
928
929 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
930 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
931 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
932
933 vk.cmdEndRendering(*m_cmdBuffer);
934
935 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
936
937 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
938 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
939
940 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
941 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
942 {
943 verifyResults(colorAtchCount, imagesFormat);
944
945 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
946
947 beginCommandBuffer(vk, *m_cmdBuffer);
948 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
949
950 beginRendering(*m_cmdBuffer, attachmentBindInfos, 0, colorAtchCount, imagesFormat,
951 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
952 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
953
954 if (clearData.colorDepthClear1.size() != 0)
955 {
956 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
957 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
958 }
959
960 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
961 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
962
963 if (clearData.colorDepthClear2.size() != 0)
964 {
965 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
966 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
967 }
968
969 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
970 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
971
972 vk.cmdEndRendering(*m_cmdBuffer);
973
974 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
975
976 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
977 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
978
979 verifyResults(colorAtchCount, imagesFormat);
980 }
981 }
982 }
983
preBarier(VkCommandBuffer cmdBuffer,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)984 void DynamicRenderingTestInstance::preBarier(VkCommandBuffer cmdBuffer, const uint32_t colorAtchCount,
985 ImagesLayout &imagesLayout, const ImagesFormat &imagesFormat)
986 {
987 const DeviceInterface &vk = m_context.getDeviceInterface();
988
989 VkPipelineStageFlags srcStages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
990
991 std::vector<VkImageMemoryBarrier> barriers;
992
993 for (uint32_t ndx = 0; ndx < colorAtchCount; ++ndx)
994 {
995 const VkImageSubresourceRange subresource =
996 makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u);
997 const VkImageMemoryBarrier barrier = makeImageMemoryBarrier(
998 VK_ACCESS_NONE_KHR, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, imagesLayout.oldColors[ndx],
999 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, *m_imageColor[ndx], subresource);
1000 barriers.push_back(barrier);
1001 imagesLayout.oldColors[ndx] = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1002 }
1003
1004 if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1005 {
1006 const bool prevXFer = (imagesLayout.oldDepth == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1007 const VkAccessFlags srcAccess = (prevXFer ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_NONE_KHR);
1008 const VkImageSubresourceRange subresource =
1009 makeImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 1u, 0u, 1u);
1010 const VkImageMemoryBarrier barrier =
1011 makeImageMemoryBarrier(srcAccess, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldDepth,
1012 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, *m_imageStencilDepth, subresource);
1013 imagesLayout.oldDepth = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
1014 barriers.push_back(barrier);
1015
1016 if (prevXFer)
1017 srcStages |= VK_PIPELINE_STAGE_TRANSFER_BIT;
1018 }
1019
1020 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1021 {
1022 const bool prevXFer = (imagesLayout.oldStencil == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
1023 const VkAccessFlags srcAccess = (prevXFer ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_NONE_KHR);
1024 const VkImageSubresourceRange subresource =
1025 makeImageSubresourceRange(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u);
1026 const VkImageMemoryBarrier barrier =
1027 makeImageMemoryBarrier(srcAccess, VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldStencil,
1028 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, *m_imageStencilDepth, subresource);
1029 imagesLayout.oldStencil = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
1030 barriers.push_back(barrier);
1031
1032 if (prevXFer)
1033 srcStages |= VK_PIPELINE_STAGE_TRANSFER_BIT;
1034 }
1035
1036 cmdPipelineImageMemoryBarrier(vk, cmdBuffer, srcStages,
1037 VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT |
1038 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
1039 barriers.data(), barriers.size());
1040 }
1041
beginRendering(VkCommandBuffer cmdBuffer,const std::vector<VkImageView> & attachmentBindInfos,const VkRenderingFlagsKHR flags,const uint32_t colorAtchCount,const ImagesFormat & imagesFormat,const VkAttachmentLoadOp loadOp,const VkAttachmentStoreOp storeOp)1042 void DynamicRenderingTestInstance::beginRendering(VkCommandBuffer cmdBuffer,
1043 const std::vector<VkImageView> &attachmentBindInfos,
1044 const VkRenderingFlagsKHR flags, const uint32_t colorAtchCount,
1045 const ImagesFormat &imagesFormat, const VkAttachmentLoadOp loadOp,
1046 const VkAttachmentStoreOp storeOp)
1047 {
1048 const DeviceInterface &vk = m_context.getDeviceInterface();
1049 const VkClearValue clearValue = makeClearValueColor(m_parameters.clearColor);
1050 const VkClearValue depthStencilClearValue =
1051 makeClearValueDepthStencil(m_parameters.depthClearValue, m_parameters.stencilClearValue);
1052
1053 const VkRect2D renderArea = {
1054 makeOffset2D(0, 0),
1055 makeExtent2D(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1056 };
1057
1058 std::vector<VkRenderingAttachmentInfoKHR> attachments;
1059
1060 for (uint32_t ndx = 0; ndx < colorAtchCount; ++ndx)
1061 {
1062 const VkRenderingAttachmentInfoKHR renderingAtachInfo = {
1063 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
1064 DE_NULL, // const void* pNext;
1065 attachmentBindInfos[ndx], // VkImageView imageView;
1066 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout imageLayout;
1067 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
1068 VK_NULL_HANDLE, // VkImageView resolveImageView;
1069 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
1070 loadOp, // VkAttachmentLoadOp loadOp;
1071 storeOp, // VkAttachmentStoreOp storeOp;
1072 clearValue, // VkClearValue clearValue;
1073 };
1074
1075 attachments.push_back(renderingAtachInfo);
1076 }
1077
1078 if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1079 {
1080 const VkRenderingAttachmentInfoKHR renderingAtachInfo = {
1081 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
1082 DE_NULL, // const void* pNext;
1083 attachmentBindInfos[colorAtchCount], // VkImageView imageView;
1084 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout imageLayout;
1085 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
1086 VK_NULL_HANDLE, // VkImageView resolveImageView;
1087 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
1088 loadOp, // VkAttachmentLoadOp loadOp;
1089 storeOp, // VkAttachmentStoreOp storeOp;
1090 depthStencilClearValue, // VkClearValue clearValue;
1091 };
1092
1093 attachments.push_back(renderingAtachInfo);
1094 }
1095
1096 const uint32_t stencilNdx = colorAtchCount + ((imagesFormat.depth != VK_FORMAT_UNDEFINED) ? 1 : 0);
1097
1098 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1099 {
1100 const VkRenderingAttachmentInfoKHR renderingAtachInfo = {
1101 VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR, // VkStructureType sType;
1102 DE_NULL, // const void* pNext;
1103 attachmentBindInfos[stencilNdx], // VkImageView imageView;
1104 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, // VkImageLayout imageLayout;
1105 VK_RESOLVE_MODE_NONE, // VkResolveModeFlagBits resolveMode;
1106 VK_NULL_HANDLE, // VkImageView resolveImageView;
1107 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout resolveImageLayout;
1108 loadOp, // VkAttachmentLoadOp loadOp;
1109 storeOp, // VkAttachmentStoreOp storeOp;
1110 depthStencilClearValue, // VkClearValue clearValue;
1111 };
1112
1113 attachments.push_back(renderingAtachInfo);
1114 }
1115
1116 const VkRenderingInfoKHR renderingInfo = {
1117 VK_STRUCTURE_TYPE_RENDERING_INFO_KHR, // VkStructureType sType;
1118 DE_NULL, // const void* pNext;
1119 flags, // VkRenderingFlagsKHR flags;
1120 renderArea, // VkRect2D renderArea;
1121 1u, // uint32_t layerCount;
1122 0u, // uint32_t viewMask;
1123 colorAtchCount, // uint32_t colorAttachmentCount;
1124 ((colorAtchCount != 0) ? attachments.data() :
1125 DE_NULL), // const VkRenderingAttachmentInfoKHR* pColorAttachments;
1126 ((imagesFormat.depth != VK_FORMAT_UNDEFINED) ?
1127 &attachments[colorAtchCount] :
1128 DE_NULL), // const VkRenderingAttachmentInfoKHR* pDepthAttachment;
1129 ((imagesFormat.stencil != VK_FORMAT_UNDEFINED) ?
1130 &attachments[stencilNdx] :
1131 DE_NULL), // const VkRenderingAttachmentInfoKHR* pStencilAttachment;
1132 };
1133
1134 vk.cmdBeginRendering(cmdBuffer, &renderingInfo);
1135 }
1136
copyImgToBuff(VkCommandBuffer commandBuffer,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1137 void DynamicRenderingTestInstance::copyImgToBuff(VkCommandBuffer commandBuffer, const uint32_t colorAtchCount,
1138 ImagesLayout &imagesLayout, const ImagesFormat &imagesFormat)
1139 {
1140 const DeviceInterface &vk = m_context.getDeviceInterface();
1141
1142 if (imagesFormat.colors[0] != VK_FORMAT_UNDEFINED)
1143 {
1144 for (uint32_t ndx = 0; ndx < colorAtchCount; ndx++)
1145 {
1146 vk::copyImageToBuffer(vk, commandBuffer, *m_imageColor[ndx], m_imageBuffer[ndx]->object(),
1147 tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1148 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, imagesLayout.oldColors[ndx], 1u,
1149 VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_ASPECT_COLOR_BIT);
1150 imagesLayout.oldColors[ndx] = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1151 }
1152 }
1153 if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1154 {
1155 copyImageToBuffer(vk, commandBuffer, *m_imageStencilDepth, m_imageDepthBuffer->object(),
1156 tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1157 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldDepth, 1u,
1158 VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_ASPECT_DEPTH_BIT);
1159 imagesLayout.oldDepth = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1160 }
1161 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1162 {
1163 copyImageToBuffer(vk, commandBuffer, *m_imageStencilDepth, m_imageStencilBuffer->object(),
1164 tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()),
1165 VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, imagesLayout.oldStencil, 1u,
1166 VK_IMAGE_ASPECT_STENCIL_BIT, VK_IMAGE_ASPECT_STENCIL_BIT);
1167 imagesLayout.oldStencil = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
1168 }
1169 }
1170
verifyResults(const uint32_t colorAtchCount,const ImagesFormat & imagesFormat)1171 void DynamicRenderingTestInstance::verifyResults(const uint32_t colorAtchCount, const ImagesFormat &imagesFormat)
1172 {
1173 const DeviceInterface &vk = m_context.getDeviceInterface();
1174 const VkDevice device = m_context.getDevice();
1175 tcu::TestLog &log = m_context.getTestContext().getLog();
1176
1177 if (imagesFormat.colors[0] != VK_FORMAT_UNDEFINED)
1178 {
1179 for (uint32_t ndx = 0; ndx < colorAtchCount; ndx++)
1180 {
1181 const Allocation allocColor = m_imageBuffer[ndx]->getBoundMemory();
1182 invalidateAlloc(vk, device, allocColor);
1183 const tcu::ConstPixelBufferAccess resultColorImage(mapVkFormat(m_parameters.imageFormat),
1184 m_parameters.renderSize.x(), m_parameters.renderSize.y(),
1185 1u, allocColor.getHostPtr());
1186
1187 if (!tcu::floatThresholdCompare(log, "Compare Color Image", "Result comparison",
1188 m_referenceImages[ndx].getAccess(), resultColorImage, Vec4(0.02f),
1189 tcu::COMPARE_LOG_ON_ERROR))
1190 {
1191 TCU_FAIL("Rendered color image is not correct");
1192 }
1193 }
1194 }
1195
1196 if (imagesFormat.depth != VK_FORMAT_UNDEFINED)
1197 verifyDepth(m_referenceImages[COLOR_ATTACHMENTS_NUMBER]);
1198
1199 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1200 verifyStencil(m_referenceImages[COLOR_ATTACHMENTS_NUMBER + 1]);
1201 }
1202
verifyDepth(const tcu::TextureLevel & depthReference)1203 void DynamicRenderingTestInstance::verifyDepth(const tcu::TextureLevel &depthReference)
1204 {
1205 const DeviceInterface &vk = m_context.getDeviceInterface();
1206 const VkDevice device = m_context.getDevice();
1207 tcu::TestLog &log = m_context.getTestContext().getLog();
1208
1209 const Allocation allocDepth = m_imageDepthBuffer->getBoundMemory();
1210 invalidateAlloc(vk, device, allocDepth);
1211
1212 const tcu::ConstPixelBufferAccess resultDepthImage(getDepthCopyFormat(m_formatStencilDepthImage),
1213 m_parameters.renderSize.x(), m_parameters.renderSize.y(), 1u,
1214 allocDepth.getHostPtr());
1215 if (m_formatStencilDepthImage == VK_FORMAT_D24_UNORM_S8_UINT)
1216 {
1217 de::MovePtr<tcu::TextureLevel> result(new tcu::TextureLevel(
1218 mapVkFormat(m_formatStencilDepthImage), m_parameters.renderSize.x(), m_parameters.renderSize.y(), 1u));
1219 tcu::copy(tcu::getEffectiveDepthStencilAccess(result->getAccess(), tcu::Sampler::MODE_DEPTH), resultDepthImage);
1220
1221 const tcu::ConstPixelBufferAccess depthResult =
1222 tcu::getEffectiveDepthStencilAccess(result->getAccess(), tcu::Sampler::MODE_DEPTH);
1223 const tcu::ConstPixelBufferAccess expectedResult =
1224 tcu::getEffectiveDepthStencilAccess(depthReference.getAccess(), tcu::Sampler::MODE_DEPTH);
1225
1226 if (!tcu::intThresholdCompare(log, "Compare Depth Image", "Result comparison", expectedResult, depthResult,
1227 UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_ON_ERROR))
1228 {
1229 TCU_FAIL("Rendered depth image is not correct");
1230 }
1231 }
1232 else
1233 {
1234 if (!tcu::dsThresholdCompare(log, "Compare Depth Image", "Result comparison", depthReference.getAccess(),
1235 resultDepthImage, 0.02f, tcu::COMPARE_LOG_ON_ERROR))
1236 {
1237 TCU_FAIL("Rendered depth image is not correct");
1238 }
1239 }
1240 }
1241
verifyStencil(const tcu::TextureLevel & stencilReference)1242 void DynamicRenderingTestInstance::verifyStencil(const tcu::TextureLevel &stencilReference)
1243 {
1244 const DeviceInterface &vk = m_context.getDeviceInterface();
1245 const VkDevice device = m_context.getDevice();
1246 tcu::TestLog &log = m_context.getTestContext().getLog();
1247
1248 const Allocation allocStencil = m_imageStencilBuffer->getBoundMemory();
1249 invalidateAlloc(vk, device, allocStencil);
1250 const tcu::ConstPixelBufferAccess resultStencilImage(mapVkFormat(VK_FORMAT_S8_UINT), m_parameters.renderSize.x(),
1251 m_parameters.renderSize.y(), 1u, allocStencil.getHostPtr());
1252
1253 if (!tcu::intThresholdCompare(log, "Compare Stencil Image", "Result comparison", stencilReference.getAccess(),
1254 resultStencilImage, UVec4(0, 0, 0, 0), tcu::COMPARE_LOG_ON_ERROR))
1255 {
1256 TCU_FAIL("Rendered stencil image is not correct");
1257 }
1258 }
1259
1260 class SingleCmdBufferResuming : public DynamicRenderingTestInstance
1261 {
1262 public:
1263 SingleCmdBufferResuming(Context &context, const TestParameters ¶meters);
1264
1265 protected:
1266 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1267 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1268 const ImagesFormat &imagesFormat) override;
1269 };
1270
SingleCmdBufferResuming(Context & context,const TestParameters & parameters)1271 SingleCmdBufferResuming::SingleCmdBufferResuming(Context &context, const TestParameters ¶meters)
1272 : DynamicRenderingTestInstance(context, parameters)
1273 {
1274 }
1275
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1276 void SingleCmdBufferResuming::rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1277 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1278 const ImagesFormat &imagesFormat)
1279 {
1280 const DeviceInterface &vk = m_context.getDeviceInterface();
1281 const VkDevice device = m_context.getDevice();
1282 const VkQueue queue = m_context.getUniversalQueue();
1283
1284 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1285 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1286 {
1287 beginCommandBuffer(vk, *m_cmdBuffer);
1288 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1289
1290 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1291 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1292 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1293
1294 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1295
1296 {
1297 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1298 const VkDeviceSize vertexBufferOffset = 0ull;
1299 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1300 }
1301
1302 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
1303 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
1304 vk.cmdEndRendering(*m_cmdBuffer);
1305
1306 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1307 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1308 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1309
1310 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
1311
1312 vk.cmdEndRendering(*m_cmdBuffer);
1313
1314 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1315
1316 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1317 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1318
1319 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1320 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1321 {
1322 verifyResults(colorAtchCount, imagesFormat);
1323
1324 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1325
1326 beginCommandBuffer(vk, *m_cmdBuffer);
1327 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1328
1329 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1330 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1331 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1332
1333 if (clearData.colorDepthClear1.size() != 0)
1334 {
1335 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
1336 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
1337 }
1338
1339 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1340 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1341
1342 vk.cmdEndRendering(*m_cmdBuffer);
1343
1344 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1345 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1346 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1347
1348 if (clearData.colorDepthClear2.size() != 0)
1349 {
1350 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
1351 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
1352 }
1353
1354 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1355 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1356
1357 vk.cmdEndRendering(*m_cmdBuffer);
1358
1359 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1360
1361 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1362 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1363
1364 verifyResults(colorAtchCount, imagesFormat);
1365 }
1366 }
1367 }
1368
1369 class TwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
1370 {
1371 public:
1372 TwoPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
1373
1374 protected:
1375 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1376 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1377 const ImagesFormat &imagesFormat) override;
1378
1379 Move<VkCommandBuffer> m_cmdBuffer2;
1380 };
1381
TwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)1382 TwoPrimaryCmdBufferResuming::TwoPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters)
1383 : DynamicRenderingTestInstance(context, parameters)
1384 {
1385 const DeviceInterface &vk = m_context.getDeviceInterface();
1386 const VkDevice device = m_context.getDevice();
1387
1388 m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1389 }
1390
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1391 void TwoPrimaryCmdBufferResuming::rendering(const VkPipeline pipeline,
1392 const std::vector<VkImageView> &attachmentBindInfos,
1393 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1394 const ImagesFormat &imagesFormat)
1395 {
1396 const DeviceInterface &vk = m_context.getDeviceInterface();
1397 const VkDevice device = m_context.getDevice();
1398 const VkQueue queue = m_context.getUniversalQueue();
1399
1400 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1401 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1402 {
1403 // First Primary CommandBuffer
1404 beginCommandBuffer(vk, *m_cmdBuffer);
1405 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1406
1407 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1408 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1409 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1410
1411 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1412
1413 {
1414 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1415 const VkDeviceSize vertexBufferOffset = 0ull;
1416 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1417 }
1418
1419 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
1420 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
1421
1422 vk.cmdEndRendering(*m_cmdBuffer);
1423
1424 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1425
1426 // Second Primary CommandBuffer
1427 beginCommandBuffer(vk, *m_cmdBuffer2);
1428
1429 beginRendering(*m_cmdBuffer2, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1430 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1431 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1432
1433 vk.cmdBindPipeline(*m_cmdBuffer2, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1434
1435 {
1436 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1437 const VkDeviceSize vertexBufferOffset = 0ull;
1438 vk.cmdBindVertexBuffers(*m_cmdBuffer2, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1439 }
1440
1441 vk.cmdDraw(*m_cmdBuffer2, 4u, 1u, 4u, 0u);
1442
1443 vk.cmdEndRendering(*m_cmdBuffer2);
1444
1445 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1446
1447 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1448
1449 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1450
1451 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1452 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1453 {
1454 verifyResults(colorAtchCount, imagesFormat);
1455
1456 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1457
1458 // First Primary CommandBuffer
1459 beginCommandBuffer(vk, *m_cmdBuffer);
1460 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1461
1462 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1463 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1464 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1465
1466 if (clearData.colorDepthClear1.size() != 0)
1467 {
1468 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
1469 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
1470 }
1471
1472 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1473 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1474
1475 vk.cmdEndRendering(*m_cmdBuffer);
1476
1477 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1478
1479 // Second Primary CommandBuffer
1480 beginCommandBuffer(vk, *m_cmdBuffer2);
1481
1482 beginRendering(*m_cmdBuffer2, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1483 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1484 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1485
1486 if (clearData.colorDepthClear2.size() != 0)
1487 {
1488 vk.cmdClearAttachments(*m_cmdBuffer2, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
1489 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
1490 }
1491
1492 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1493 vk.cmdClearAttachments(*m_cmdBuffer2, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1494
1495 vk.cmdEndRendering(*m_cmdBuffer2);
1496
1497 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1498
1499 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1500
1501 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1502
1503 verifyResults(colorAtchCount, imagesFormat);
1504 }
1505 }
1506 }
1507
1508 class TwoSecondaryCmdBufferResuming : public DynamicRenderingTestInstance
1509 {
1510 public:
1511 TwoSecondaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
1512
1513 protected:
1514 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1515 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1516 const ImagesFormat &imagesFormat) override;
1517
1518 Move<VkCommandBuffer> m_secCmdBuffers[2];
1519 };
1520
TwoSecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)1521 TwoSecondaryCmdBufferResuming::TwoSecondaryCmdBufferResuming(Context &context, const TestParameters ¶meters)
1522 : DynamicRenderingTestInstance(context, parameters)
1523 {
1524 const DeviceInterface &vk = m_context.getDeviceInterface();
1525 const VkDevice device = m_context.getDevice();
1526
1527 m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1528 m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1529 }
1530
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1531 void TwoSecondaryCmdBufferResuming::rendering(const VkPipeline pipeline,
1532 const std::vector<VkImageView> &attachmentBindInfos,
1533 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1534 const ImagesFormat &imagesFormat)
1535 {
1536 const DeviceInterface &vk = m_context.getDeviceInterface();
1537 const VkDevice device = m_context.getDevice();
1538 const VkQueue queue = m_context.getUniversalQueue();
1539
1540 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1541 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1542 {
1543 VkCommandBuffer secCmdBuffers[2] = {*(m_secCmdBuffers[0]), *(m_secCmdBuffers[1])};
1544 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1545 const VkDeviceSize vertexBufferOffset = 0ull;
1546
1547 // secCmdBuffersFirst
1548 beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1549
1550 beginRendering(secCmdBuffers[0], attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1551 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1552 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1553
1554 vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1555 vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1556
1557 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
1558 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
1559
1560 vk.cmdEndRendering(secCmdBuffers[0]);
1561 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1562
1563 // secCmdBuffersSecond
1564 beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1565
1566 beginRendering(secCmdBuffers[1], attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1567 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1568 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1569
1570 vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1571 vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1572
1573 vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
1574
1575 vk.cmdEndRendering(secCmdBuffers[1]);
1576 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1577
1578 // Primary commandBuffer
1579 beginCommandBuffer(vk, *m_cmdBuffer);
1580 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1581
1582 vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
1583
1584 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1585 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1586
1587 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1588
1589 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1590 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1591 {
1592 verifyResults(colorAtchCount, imagesFormat);
1593
1594 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1595
1596 // secCmdBuffersFirst
1597 beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1598
1599 beginRendering(secCmdBuffers[0], attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1600 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1601 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1602
1603 if (clearData.colorDepthClear1.size() != 0)
1604 {
1605 vk.cmdClearAttachments(secCmdBuffers[0], static_cast<uint32_t>(clearData.colorDepthClear1.size()),
1606 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
1607 }
1608
1609 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1610 vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1611
1612 vk.cmdEndRendering(secCmdBuffers[0]);
1613 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1614
1615 // secCmdBuffersSecond
1616 beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1617
1618 beginRendering(secCmdBuffers[1], attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1619 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1620 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1621
1622 if (clearData.colorDepthClear2.size() != 0)
1623 {
1624 vk.cmdClearAttachments(secCmdBuffers[1], static_cast<uint32_t>(clearData.colorDepthClear2.size()),
1625 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
1626 }
1627
1628 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1629 vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1630
1631 vk.cmdEndRendering(secCmdBuffers[1]);
1632 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1633
1634 // Primary commandBuffer
1635 beginCommandBuffer(vk, *m_cmdBuffer);
1636 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1637
1638 vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
1639
1640 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1641 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1642
1643 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1644
1645 verifyResults(colorAtchCount, imagesFormat);
1646 }
1647 }
1648 }
1649
1650 class TwoSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
1651 {
1652 public:
1653 TwoSecondaryTwoPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
1654
1655 protected:
1656 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1657 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1658 const ImagesFormat &imagesFormat) override;
1659
1660 Move<VkCommandBuffer> m_cmdBuffer2;
1661 Move<VkCommandBuffer> m_secCmdBuffers[2];
1662 };
1663
TwoSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)1664 TwoSecondaryTwoPrimaryCmdBufferResuming::TwoSecondaryTwoPrimaryCmdBufferResuming(Context &context,
1665 const TestParameters ¶meters)
1666 : DynamicRenderingTestInstance(context, parameters)
1667 {
1668 const DeviceInterface &vk = m_context.getDeviceInterface();
1669 const VkDevice device = m_context.getDevice();
1670
1671 m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
1672 m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1673 m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1674 }
1675
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1676 void TwoSecondaryTwoPrimaryCmdBufferResuming::rendering(const VkPipeline pipeline,
1677 const std::vector<VkImageView> &attachmentBindInfos,
1678 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1679 const ImagesFormat &imagesFormat)
1680 {
1681 const DeviceInterface &vk = m_context.getDeviceInterface();
1682 const VkDevice device = m_context.getDevice();
1683 const VkQueue queue = m_context.getUniversalQueue();
1684
1685 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1686 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1687 {
1688 VkCommandBuffer secCmdBuffers[2] = {*(m_secCmdBuffers[0]), *(m_secCmdBuffers[1])};
1689 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1690 const VkDeviceSize vertexBufferOffset = 0ull;
1691
1692 // secCmdBuffersFirst
1693 beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1694
1695 beginRendering(secCmdBuffers[0], attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1696 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1697 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1698
1699 vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1700 vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1701
1702 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
1703 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
1704
1705 vk.cmdEndRendering(secCmdBuffers[0]);
1706 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1707
1708 // secCmdBuffersSecond
1709 beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1710
1711 beginRendering(secCmdBuffers[1], attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1712 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1713 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1714
1715 vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1716 vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1717
1718 vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
1719
1720 vk.cmdEndRendering(secCmdBuffers[1]);
1721 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1722
1723 // Primary commandBuffer
1724 beginCommandBuffer(vk, *m_cmdBuffer);
1725 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1726
1727 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
1728
1729 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1730
1731 // Primary commandBuffer2
1732 beginCommandBuffer(vk, *m_cmdBuffer2);
1733
1734 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
1735
1736 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1737 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1738
1739 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1740
1741 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1742 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1743 {
1744 verifyResults(colorAtchCount, imagesFormat);
1745
1746 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1747
1748 // secCmdBuffersFirst
1749 beginSecondaryCmdBuffer(vk, secCmdBuffers[0]);
1750
1751 beginRendering(secCmdBuffers[0], attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
1752 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1753 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1754
1755 if (clearData.colorDepthClear1.size() != 0)
1756 {
1757 vk.cmdClearAttachments(secCmdBuffers[0], static_cast<uint32_t>(clearData.colorDepthClear1.size()),
1758 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
1759 }
1760
1761 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1762 vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1763
1764 vk.cmdEndRendering(secCmdBuffers[0]);
1765 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1766
1767 // secCmdBuffersSecond
1768 beginSecondaryCmdBuffer(vk, secCmdBuffers[1]);
1769
1770 beginRendering(secCmdBuffers[1], attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
1771 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1772 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1773
1774 if (clearData.colorDepthClear2.size() != 0)
1775 {
1776 vk.cmdClearAttachments(secCmdBuffers[1], static_cast<uint32_t>(clearData.colorDepthClear2.size()),
1777 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
1778 }
1779
1780 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1781 vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1782
1783 vk.cmdEndRendering(secCmdBuffers[1]);
1784 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1785
1786 // Primary commandBuffer
1787 beginCommandBuffer(vk, *m_cmdBuffer);
1788 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1789
1790 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
1791
1792 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1793
1794 // Primary commandBuffer2
1795 beginCommandBuffer(vk, *m_cmdBuffer2);
1796
1797 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
1798
1799 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
1800 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
1801
1802 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
1803
1804 verifyResults(colorAtchCount, imagesFormat);
1805 }
1806 }
1807 }
1808
1809 class ContentsSecondaryCmdBuffer : public DynamicRenderingTestInstance
1810 {
1811 public:
1812 ContentsSecondaryCmdBuffer(Context &context, const TestParameters ¶meters);
1813
1814 protected:
1815 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1816 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1817 const ImagesFormat &imagesFormat) override;
1818
1819 Move<VkCommandBuffer> m_secCmdBuffers;
1820 };
1821
ContentsSecondaryCmdBuffer(Context & context,const TestParameters & parameters)1822 ContentsSecondaryCmdBuffer::ContentsSecondaryCmdBuffer(Context &context, const TestParameters ¶meters)
1823 : DynamicRenderingTestInstance(context, parameters)
1824 {
1825 const DeviceInterface &vk = m_context.getDeviceInterface();
1826 const VkDevice device = m_context.getDevice();
1827
1828 m_secCmdBuffers = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1829 }
1830
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1831 void ContentsSecondaryCmdBuffer::rendering(const VkPipeline pipeline,
1832 const std::vector<VkImageView> &attachmentBindInfos,
1833 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1834 const ImagesFormat &imagesFormat)
1835 {
1836 const DeviceInterface &vk = m_context.getDeviceInterface();
1837 const VkDevice device = m_context.getDevice();
1838 const VkQueue queue = m_context.getUniversalQueue();
1839
1840 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1841 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1842 {
1843 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1844 const VkDeviceSize vertexBufferOffset = 0ull;
1845
1846 // secCmdBuffers
1847 beginSecondaryCmdBuffer(vk, *m_secCmdBuffers, (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
1848
1849 vk.cmdBindPipeline(*m_secCmdBuffers, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1850 vk.cmdBindVertexBuffers(*m_secCmdBuffers, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1851
1852 vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 8u, 0u);
1853 vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 0u, 0u);
1854 vk.cmdDraw(*m_secCmdBuffers, 4u, 1u, 4u, 0u);
1855
1856 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffers));
1857
1858 // Primary commandBuffer
1859 beginCommandBuffer(vk, *m_cmdBuffer);
1860 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1861
1862 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
1863 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1864 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1865
1866 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffers));
1867
1868 vk.cmdEndRendering(*m_cmdBuffer);
1869
1870 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1871 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1872
1873 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1874
1875 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
1876 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
1877 {
1878 verifyResults(colorAtchCount, imagesFormat);
1879
1880 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
1881
1882 // secCmdBuffers
1883 beginSecondaryCmdBuffer(vk, *m_secCmdBuffers, (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
1884
1885 if (clearData.colorDepthClear1.size() != 0)
1886 {
1887 vk.cmdClearAttachments(*m_secCmdBuffers, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
1888 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
1889 }
1890
1891 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1892 vk.cmdClearAttachments(*m_secCmdBuffers, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
1893
1894 if (clearData.colorDepthClear2.size() != 0)
1895 {
1896 vk.cmdClearAttachments(*m_secCmdBuffers, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
1897 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
1898 }
1899
1900 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
1901 vk.cmdClearAttachments(*m_secCmdBuffers, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
1902
1903 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffers));
1904
1905 // Primary commandBuffer
1906 beginCommandBuffer(vk, *m_cmdBuffer);
1907 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1908
1909 beginRendering(*m_cmdBuffer, attachmentBindInfos,
1910 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR, colorAtchCount, imagesFormat,
1911 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1912 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1913
1914 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffers));
1915
1916 vk.cmdEndRendering(*m_cmdBuffer);
1917
1918 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1919 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1920
1921 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
1922
1923 verifyResults(colorAtchCount, imagesFormat);
1924 }
1925 }
1926 }
1927
1928 class ContentsTwoSecondaryCmdBuffer : public DynamicRenderingTestInstance
1929 {
1930 public:
1931 ContentsTwoSecondaryCmdBuffer(Context &context, const TestParameters ¶meters);
1932
1933 protected:
1934 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
1935 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1936 const ImagesFormat &imagesFormat) override;
1937
1938 Move<VkCommandBuffer> m_secCmdBuffers[2];
1939 };
1940
ContentsTwoSecondaryCmdBuffer(Context & context,const TestParameters & parameters)1941 ContentsTwoSecondaryCmdBuffer::ContentsTwoSecondaryCmdBuffer(Context &context, const TestParameters ¶meters)
1942 : DynamicRenderingTestInstance(context, parameters)
1943 {
1944 const DeviceInterface &vk = m_context.getDeviceInterface();
1945 const VkDevice device = m_context.getDevice();
1946
1947 m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1948 m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
1949 }
1950
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)1951 void ContentsTwoSecondaryCmdBuffer::rendering(const VkPipeline pipeline,
1952 const std::vector<VkImageView> &attachmentBindInfos,
1953 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
1954 const ImagesFormat &imagesFormat)
1955 {
1956 const DeviceInterface &vk = m_context.getDeviceInterface();
1957 const VkDevice device = m_context.getDevice();
1958 const VkQueue queue = m_context.getUniversalQueue();
1959
1960 VkCommandBuffer secCmdBuffers[2] = {*(m_secCmdBuffers[0]), *(m_secCmdBuffers[1])};
1961
1962 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
1963 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
1964 {
1965 const VkBuffer vertexBuffer = m_vertexBuffer->object();
1966 const VkDeviceSize vertexBufferOffset = 0ull;
1967
1968 // secCmdBuffers
1969 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
1970
1971 vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1972 vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1973
1974 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
1975 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
1976
1977 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
1978
1979 // secCmdBuffers2
1980 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
1981
1982 vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
1983 vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
1984
1985 vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
1986
1987 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
1988
1989 // Primary commandBuffer
1990 beginCommandBuffer(vk, *m_cmdBuffer);
1991 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
1992
1993 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR,
1994 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
1995 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
1996
1997 vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
1998
1999 vk.cmdEndRendering(*m_cmdBuffer);
2000
2001 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2002 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2003
2004 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2005
2006 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2007 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2008 {
2009 verifyResults(colorAtchCount, imagesFormat);
2010
2011 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2012
2013 // secCmdBuffers
2014 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2015
2016 if (clearData.colorDepthClear1.size() != 0)
2017 {
2018 vk.cmdClearAttachments(secCmdBuffers[0], static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2019 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2020 }
2021
2022 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2023 vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2024
2025 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2026
2027 // secCmdBuffers2
2028 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], (VkRenderingFlagsKHR)0u, colorAtchCount, imagesFormat);
2029
2030 if (clearData.colorDepthClear2.size() != 0)
2031 {
2032 vk.cmdClearAttachments(secCmdBuffers[1], static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2033 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2034 }
2035
2036 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2037 vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2038
2039 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2040
2041 // Primary commandBuffer
2042 beginCommandBuffer(vk, *m_cmdBuffer);
2043 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2044
2045 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2046 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR, colorAtchCount, imagesFormat,
2047 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2048 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2049
2050 vk.cmdExecuteCommands(*m_cmdBuffer, 2u, secCmdBuffers);
2051
2052 vk.cmdEndRendering(*m_cmdBuffer);
2053
2054 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2055 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2056
2057 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2058
2059 verifyResults(colorAtchCount, imagesFormat);
2060 }
2061 }
2062 }
2063
2064 class ContentsTwoSecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2065 {
2066 public:
2067 ContentsTwoSecondaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2068
2069 protected:
2070 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2071 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2072 const ImagesFormat &imagesFormat) override;
2073
2074 Move<VkCommandBuffer> m_secCmdBuffers[2];
2075 };
2076
ContentsTwoSecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)2077 ContentsTwoSecondaryCmdBufferResuming::ContentsTwoSecondaryCmdBufferResuming(Context &context,
2078 const TestParameters ¶meters)
2079 : DynamicRenderingTestInstance(context, parameters)
2080 {
2081 const DeviceInterface &vk = m_context.getDeviceInterface();
2082 const VkDevice device = m_context.getDevice();
2083
2084 m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2085 m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2086 }
2087
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2088 void ContentsTwoSecondaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2089 const std::vector<VkImageView> &attachmentBindInfos,
2090 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2091 const ImagesFormat &imagesFormat)
2092 {
2093 const DeviceInterface &vk = m_context.getDeviceInterface();
2094 const VkDevice device = m_context.getDevice();
2095 const VkQueue queue = m_context.getUniversalQueue();
2096
2097 VkCommandBuffer secCmdBuffers[2] = {*(m_secCmdBuffers[0]), *(m_secCmdBuffers[1])};
2098
2099 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2100 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2101 {
2102 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2103 const VkDeviceSize vertexBufferOffset = 0ull;
2104
2105 // secCmdBuffers
2106 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2107 imagesFormat);
2108
2109 vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2110 vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2111
2112 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
2113 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
2114
2115 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2116
2117 // secCmdBuffers2
2118 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2119
2120 vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2121 vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2122
2123 vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
2124
2125 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2126
2127 // Primary commandBuffer
2128 beginCommandBuffer(vk, *m_cmdBuffer);
2129 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2130
2131 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2132 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_SUSPENDING_BIT_KHR,
2133 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2134 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2135
2136 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2137
2138 vk.cmdEndRendering(*m_cmdBuffer);
2139
2140 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2141 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2142 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2143 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2144
2145 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[1]);
2146
2147 vk.cmdEndRendering(*m_cmdBuffer);
2148
2149 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2150 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2151
2152 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2153
2154 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2155 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2156 {
2157 verifyResults(colorAtchCount, imagesFormat);
2158
2159 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2160
2161 // secCmdBuffers
2162 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2163 imagesFormat);
2164
2165 if (clearData.colorDepthClear1.size() != 0)
2166 {
2167 vk.cmdClearAttachments(secCmdBuffers[0], static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2168 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2169 }
2170
2171 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2172 vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2173
2174 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2175
2176 // secCmdBuffers2
2177 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2178 imagesFormat);
2179
2180 if (clearData.colorDepthClear2.size() != 0)
2181 {
2182 vk.cmdClearAttachments(secCmdBuffers[1], static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2183 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2184 }
2185
2186 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2187 vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2188
2189 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2190
2191 // Primary commandBuffer
2192 beginCommandBuffer(vk, *m_cmdBuffer);
2193 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2194
2195 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2196 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2197 VK_RENDERING_SUSPENDING_BIT_KHR,
2198 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2199 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2200
2201 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2202
2203 vk.cmdEndRendering(*m_cmdBuffer);
2204
2205 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2206 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2207 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2208 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2209
2210 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[1]);
2211
2212 vk.cmdEndRendering(*m_cmdBuffer);
2213
2214 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2215 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2216
2217 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2218
2219 verifyResults(colorAtchCount, imagesFormat);
2220 }
2221 }
2222 }
2223
2224 class ContentsTwoSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
2225 {
2226 public:
2227 ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2228
2229 protected:
2230 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2231 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2232 const ImagesFormat &imagesFormat) override;
2233
2234 Move<VkCommandBuffer> m_cmdBuffer2;
2235 Move<VkCommandBuffer> m_secCmdBuffers[2];
2236 };
2237
ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)2238 ContentsTwoSecondaryTwoPrimaryCmdBufferResuming::ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(
2239 Context &context, const TestParameters ¶meters)
2240 : DynamicRenderingTestInstance(context, parameters)
2241 {
2242 const DeviceInterface &vk = m_context.getDeviceInterface();
2243 const VkDevice device = m_context.getDevice();
2244
2245 m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2246 m_secCmdBuffers[0] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2247 m_secCmdBuffers[1] = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2248 }
2249
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2250 void ContentsTwoSecondaryTwoPrimaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2251 const std::vector<VkImageView> &attachmentBindInfos,
2252 const uint32_t colorAtchCount,
2253 ImagesLayout &imagesLayout,
2254 const ImagesFormat &imagesFormat)
2255 {
2256 const DeviceInterface &vk = m_context.getDeviceInterface();
2257 const VkDevice device = m_context.getDevice();
2258 const VkQueue queue = m_context.getUniversalQueue();
2259
2260 VkCommandBuffer secCmdBuffers[2] = {*(m_secCmdBuffers[0]), *(m_secCmdBuffers[1])};
2261
2262 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2263 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2264 {
2265 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2266 const VkDeviceSize vertexBufferOffset = 0ull;
2267
2268 // secCmdBuffers
2269 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2270 imagesFormat);
2271
2272 vk.cmdBindPipeline(secCmdBuffers[0], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2273 vk.cmdBindVertexBuffers(secCmdBuffers[0], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2274
2275 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 8u, 0u);
2276 vk.cmdDraw(secCmdBuffers[0], 4u, 1u, 0u, 0u);
2277
2278 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2279
2280 // secCmdBuffers2
2281 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2282
2283 vk.cmdBindPipeline(secCmdBuffers[1], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2284 vk.cmdBindVertexBuffers(secCmdBuffers[1], 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2285
2286 vk.cmdDraw(secCmdBuffers[1], 4u, 1u, 4u, 0u);
2287
2288 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2289
2290 // Primary commandBuffer
2291 beginCommandBuffer(vk, *m_cmdBuffer);
2292 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2293
2294 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2295 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_SUSPENDING_BIT_KHR,
2296 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2297 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2298
2299 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2300
2301 vk.cmdEndRendering(*m_cmdBuffer);
2302
2303 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2304
2305 // Primary commandBuffer2
2306 beginCommandBuffer(vk, *m_cmdBuffer2);
2307
2308 beginRendering(*m_cmdBuffer2, attachmentBindInfos,
2309 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2310 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2311 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2312
2313 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
2314
2315 vk.cmdEndRendering(*m_cmdBuffer2);
2316
2317 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2318
2319 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2320
2321 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2322
2323 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2324 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2325 {
2326 verifyResults(colorAtchCount, imagesFormat);
2327
2328 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2329
2330 // secCmdBuffers
2331 beginSecondaryCmdBuffer(vk, secCmdBuffers[0], VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2332 imagesFormat);
2333
2334 if (clearData.colorDepthClear1.size() != 0)
2335 {
2336 vk.cmdClearAttachments(secCmdBuffers[0], static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2337 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2338 }
2339
2340 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2341 vk.cmdClearAttachments(secCmdBuffers[0], 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2342
2343 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[0]));
2344
2345 // secCmdBuffers2
2346 beginSecondaryCmdBuffer(vk, secCmdBuffers[1], VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2347 imagesFormat);
2348
2349 if (clearData.colorDepthClear2.size() != 0)
2350 {
2351 vk.cmdClearAttachments(secCmdBuffers[1], static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2352 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2353 }
2354
2355 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2356 vk.cmdClearAttachments(secCmdBuffers[1], 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2357
2358 VK_CHECK(vk.endCommandBuffer(secCmdBuffers[1]));
2359
2360 // Primary commandBuffer
2361 beginCommandBuffer(vk, *m_cmdBuffer);
2362 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2363
2364 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2365 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2366 VK_RENDERING_SUSPENDING_BIT_KHR,
2367 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2368 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2369
2370 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &secCmdBuffers[0]);
2371
2372 vk.cmdEndRendering(*m_cmdBuffer);
2373
2374 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2375
2376 // Primary commandBuffer2
2377 beginCommandBuffer(vk, *m_cmdBuffer2);
2378
2379 beginRendering(*m_cmdBuffer2, attachmentBindInfos,
2380 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2381 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2382 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2383
2384 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &secCmdBuffers[1]);
2385
2386 vk.cmdEndRendering(*m_cmdBuffer2);
2387
2388 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2389
2390 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2391
2392 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2393
2394 verifyResults(colorAtchCount, imagesFormat);
2395 }
2396 }
2397 }
2398
2399 class ContentsPrimarySecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2400 {
2401 public:
2402 ContentsPrimarySecondaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2403
2404 protected:
2405 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2406 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2407 const ImagesFormat &imagesFormat) override;
2408
2409 Move<VkCommandBuffer> m_secCmdBuffer;
2410 };
2411
ContentsPrimarySecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)2412 ContentsPrimarySecondaryCmdBufferResuming::ContentsPrimarySecondaryCmdBufferResuming(Context &context,
2413 const TestParameters ¶meters)
2414 : DynamicRenderingTestInstance(context, parameters)
2415 {
2416 const DeviceInterface &vk = m_context.getDeviceInterface();
2417 const VkDevice device = m_context.getDevice();
2418
2419 m_secCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2420 }
2421
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2422 void ContentsPrimarySecondaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2423 const std::vector<VkImageView> &attachmentBindInfos,
2424 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2425 const ImagesFormat &imagesFormat)
2426 {
2427 const DeviceInterface &vk = m_context.getDeviceInterface();
2428 const VkDevice device = m_context.getDevice();
2429 const VkQueue queue = m_context.getUniversalQueue();
2430
2431 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2432 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2433 {
2434 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2435 const VkDeviceSize vertexBufferOffset = 0ull;
2436
2437 // secCmdBuffer
2438 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2439
2440 vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2441 vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2442
2443 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 4u, 0u);
2444
2445 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2446
2447 // Primary commandBuffer
2448 beginCommandBuffer(vk, *m_cmdBuffer);
2449 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2450
2451 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2452 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2453 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2454
2455 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2456 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2457
2458 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
2459 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
2460
2461 vk.cmdEndRendering(*m_cmdBuffer);
2462
2463 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2464 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2465 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2466 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2467
2468 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2469
2470 vk.cmdEndRendering(*m_cmdBuffer);
2471
2472 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2473
2474 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2475
2476 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2477
2478 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2479 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2480 {
2481 verifyResults(colorAtchCount, imagesFormat);
2482
2483 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2484
2485 // secCmdBuffer
2486 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2487 imagesFormat);
2488
2489 if (clearData.colorDepthClear1.size() != 0)
2490 {
2491 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2492 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2493 }
2494
2495 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2496 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2497
2498 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2499
2500 // Primary commandBuffer
2501 beginCommandBuffer(vk, *m_cmdBuffer);
2502 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2503
2504 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2505 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2506 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2507
2508 if (clearData.colorDepthClear2.size() != 0)
2509 {
2510 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2511 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2512 }
2513
2514 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2515 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2516
2517 vk.cmdEndRendering(*m_cmdBuffer);
2518
2519 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2520 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2521 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2522 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2523
2524 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2525
2526 vk.cmdEndRendering(*m_cmdBuffer);
2527
2528 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2529
2530 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2531
2532 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2533
2534 verifyResults(colorAtchCount, imagesFormat);
2535 }
2536 }
2537 }
2538
2539 class ContentsSecondaryPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
2540 {
2541 public:
2542 ContentsSecondaryPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2543
2544 protected:
2545 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2546 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2547 const ImagesFormat &imagesFormat) override;
2548
2549 Move<VkCommandBuffer> m_secCmdBuffer;
2550 };
2551
ContentsSecondaryPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)2552 ContentsSecondaryPrimaryCmdBufferResuming::ContentsSecondaryPrimaryCmdBufferResuming(Context &context,
2553 const TestParameters ¶meters)
2554 : DynamicRenderingTestInstance(context, parameters)
2555 {
2556 const DeviceInterface &vk = m_context.getDeviceInterface();
2557 const VkDevice device = m_context.getDevice();
2558
2559 m_secCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2560 }
2561
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2562 void ContentsSecondaryPrimaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2563 const std::vector<VkImageView> &attachmentBindInfos,
2564 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2565 const ImagesFormat &imagesFormat)
2566 {
2567 const DeviceInterface &vk = m_context.getDeviceInterface();
2568 const VkDevice device = m_context.getDevice();
2569 const VkQueue queue = m_context.getUniversalQueue();
2570
2571 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2572 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2573 {
2574 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2575 const VkDeviceSize vertexBufferOffset = 0ull;
2576
2577 // secCmdBuffer
2578 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2579
2580 vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2581 vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2582
2583 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 8u, 0u);
2584 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 0u, 0u);
2585
2586 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2587
2588 // Primary commandBuffer
2589 beginCommandBuffer(vk, *m_cmdBuffer);
2590 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2591
2592 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2593 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_SUSPENDING_BIT_KHR,
2594 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2595 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2596
2597 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2598
2599 vk.cmdEndRendering(*m_cmdBuffer);
2600
2601 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2602 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2603 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2604
2605 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2606 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2607
2608 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 4u, 0u);
2609
2610 vk.cmdEndRendering(*m_cmdBuffer);
2611
2612 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2613
2614 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2615
2616 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2617
2618 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2619 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2620 {
2621 verifyResults(colorAtchCount, imagesFormat);
2622
2623 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2624
2625 // secCmdBuffer
2626 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2627 imagesFormat);
2628
2629 if (clearData.colorDepthClear1.size() != 0)
2630 {
2631 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2632 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2633 }
2634
2635 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2636 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2637
2638 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2639
2640 // Primary commandBuffer
2641 beginCommandBuffer(vk, *m_cmdBuffer);
2642 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2643
2644 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2645 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2646 VK_RENDERING_SUSPENDING_BIT_KHR,
2647 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2648 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2649
2650 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2651
2652 vk.cmdEndRendering(*m_cmdBuffer);
2653
2654 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2655 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2656 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2657
2658 if (clearData.colorDepthClear2.size() != 0)
2659 {
2660 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2661 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2662 }
2663
2664 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2665 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2666
2667 vk.cmdEndRendering(*m_cmdBuffer);
2668
2669 copyImgToBuff(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2670
2671 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2672
2673 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
2674
2675 verifyResults(colorAtchCount, imagesFormat);
2676 }
2677 }
2678 }
2679
2680 class ContentsTwoPrimarySecondaryCmdBufferResuming : public DynamicRenderingTestInstance
2681 {
2682 public:
2683 ContentsTwoPrimarySecondaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2684
2685 protected:
2686 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2687 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2688 const ImagesFormat &imagesFormat) override;
2689
2690 Move<VkCommandBuffer> m_cmdBuffer2;
2691 Move<VkCommandBuffer> m_secCmdBuffer;
2692 };
2693
ContentsTwoPrimarySecondaryCmdBufferResuming(Context & context,const TestParameters & parameters)2694 ContentsTwoPrimarySecondaryCmdBufferResuming::ContentsTwoPrimarySecondaryCmdBufferResuming(
2695 Context &context, const TestParameters ¶meters)
2696 : DynamicRenderingTestInstance(context, parameters)
2697 {
2698 const DeviceInterface &vk = m_context.getDeviceInterface();
2699 const VkDevice device = m_context.getDevice();
2700
2701 m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2702 m_secCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2703 }
2704
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2705 void ContentsTwoPrimarySecondaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2706 const std::vector<VkImageView> &attachmentBindInfos,
2707 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2708 const ImagesFormat &imagesFormat)
2709 {
2710 const DeviceInterface &vk = m_context.getDeviceInterface();
2711 const VkDevice device = m_context.getDevice();
2712 const VkQueue queue = m_context.getUniversalQueue();
2713
2714 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2715 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2716 {
2717 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2718 const VkDeviceSize vertexBufferOffset = 0ull;
2719
2720 // secCmdBuffer
2721 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount, imagesFormat);
2722
2723 vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2724 vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2725
2726 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 4u, 0u);
2727
2728 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2729
2730 // Primary commandBuffer
2731 beginCommandBuffer(vk, *m_cmdBuffer);
2732 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2733
2734 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2735 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2736 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2737
2738 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2739 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2740
2741 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 8u, 0u);
2742 vk.cmdDraw(*m_cmdBuffer, 4u, 1u, 0u, 0u);
2743
2744 vk.cmdEndRendering(*m_cmdBuffer);
2745 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2746
2747 // Primary commandBuffer2
2748 beginCommandBuffer(vk, *m_cmdBuffer2);
2749
2750 beginRendering(*m_cmdBuffer2, attachmentBindInfos,
2751 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2752 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2753 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2754
2755 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &(*m_secCmdBuffer));
2756
2757 vk.cmdEndRendering(*m_cmdBuffer2);
2758
2759 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2760
2761 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2762
2763 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2764
2765 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2766 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2767 {
2768 verifyResults(colorAtchCount, imagesFormat);
2769
2770 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2771
2772 // secCmdBuffer
2773 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2774 imagesFormat);
2775
2776 if (clearData.colorDepthClear1.size() != 0)
2777 {
2778 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2779 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2780 }
2781
2782 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2783 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2784
2785 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2786
2787 // Primary commandBuffer
2788 beginCommandBuffer(vk, *m_cmdBuffer);
2789 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2790
2791 beginRendering(*m_cmdBuffer, attachmentBindInfos, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2792 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2793 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2794
2795 if (clearData.colorDepthClear2.size() != 0)
2796 {
2797 vk.cmdClearAttachments(*m_cmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2798 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2799 }
2800
2801 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2802 vk.cmdClearAttachments(*m_cmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2803
2804 vk.cmdEndRendering(*m_cmdBuffer);
2805 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2806
2807 // Primary commandBuffer2
2808 beginCommandBuffer(vk, *m_cmdBuffer2);
2809
2810 beginRendering(*m_cmdBuffer2, attachmentBindInfos,
2811 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_RESUMING_BIT_KHR,
2812 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2813 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2814
2815 vk.cmdExecuteCommands(*m_cmdBuffer2, 1u, &(*m_secCmdBuffer));
2816
2817 vk.cmdEndRendering(*m_cmdBuffer2);
2818
2819 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2820
2821 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2822
2823 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2824
2825 verifyResults(colorAtchCount, imagesFormat);
2826 }
2827 }
2828 }
2829
2830 class ContentsSecondaryTwoPrimaryCmdBufferResuming : public DynamicRenderingTestInstance
2831 {
2832 public:
2833 ContentsSecondaryTwoPrimaryCmdBufferResuming(Context &context, const TestParameters ¶meters);
2834
2835 protected:
2836 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2837 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2838 const ImagesFormat &imagesFormat) override;
2839
2840 Move<VkCommandBuffer> m_cmdBuffer2;
2841 Move<VkCommandBuffer> m_secCmdBuffer;
2842 };
2843
ContentsSecondaryTwoPrimaryCmdBufferResuming(Context & context,const TestParameters & parameters)2844 ContentsSecondaryTwoPrimaryCmdBufferResuming::ContentsSecondaryTwoPrimaryCmdBufferResuming(
2845 Context &context, const TestParameters ¶meters)
2846 : DynamicRenderingTestInstance(context, parameters)
2847 {
2848 const DeviceInterface &vk = m_context.getDeviceInterface();
2849 const VkDevice device = m_context.getDevice();
2850
2851 m_cmdBuffer2 = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
2852 m_secCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
2853 }
2854
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)2855 void ContentsSecondaryTwoPrimaryCmdBufferResuming::rendering(const VkPipeline pipeline,
2856 const std::vector<VkImageView> &attachmentBindInfos,
2857 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2858 const ImagesFormat &imagesFormat)
2859 {
2860 const DeviceInterface &vk = m_context.getDeviceInterface();
2861 const VkDevice device = m_context.getDevice();
2862 const VkQueue queue = m_context.getUniversalQueue();
2863
2864 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
2865 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
2866 {
2867 const VkBuffer vertexBuffer = m_vertexBuffer->object();
2868 const VkDeviceSize vertexBufferOffset = 0ull;
2869
2870 // secCmdBuffer
2871 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount, imagesFormat);
2872
2873 vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2874 vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2875
2876 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 8u, 0u);
2877 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 0u, 0u);
2878
2879 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2880
2881 // Primary commandBuffer
2882 beginCommandBuffer(vk, *m_cmdBuffer);
2883 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2884
2885 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2886 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR | VK_RENDERING_SUSPENDING_BIT_KHR,
2887 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2888 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2889
2890 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2891
2892 vk.cmdEndRendering(*m_cmdBuffer);
2893 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2894
2895 // Primary commandBuffer2
2896 beginCommandBuffer(vk, *m_cmdBuffer2);
2897
2898 beginRendering(*m_cmdBuffer2, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2899 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2900 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2901
2902 vk.cmdBindPipeline(*m_cmdBuffer2, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
2903 vk.cmdBindVertexBuffers(*m_cmdBuffer2, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
2904
2905 vk.cmdDraw(*m_cmdBuffer2, 4u, 1u, 4u, 0u);
2906
2907 vk.cmdEndRendering(*m_cmdBuffer2);
2908
2909 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2910
2911 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2912
2913 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2914
2915 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
2916 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
2917 {
2918 verifyResults(colorAtchCount, imagesFormat);
2919
2920 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
2921
2922 // secCmdBuffer
2923 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer, VK_RENDERING_SUSPENDING_BIT_KHR, colorAtchCount,
2924 imagesFormat);
2925
2926 if (clearData.colorDepthClear1.size() != 0)
2927 {
2928 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
2929 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
2930 }
2931
2932 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2933 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
2934
2935 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
2936
2937 // Primary commandBuffer
2938 beginCommandBuffer(vk, *m_cmdBuffer);
2939 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
2940
2941 beginRendering(*m_cmdBuffer, attachmentBindInfos,
2942 VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT_KHR |
2943 VK_RENDERING_SUSPENDING_BIT_KHR,
2944 colorAtchCount, imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2945 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2946
2947 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
2948
2949 vk.cmdEndRendering(*m_cmdBuffer);
2950 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2951
2952 // Primary commandBuffer2
2953 beginCommandBuffer(vk, *m_cmdBuffer2);
2954
2955 beginRendering(*m_cmdBuffer2, attachmentBindInfos, VK_RENDERING_RESUMING_BIT_KHR, colorAtchCount,
2956 imagesFormat, static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
2957 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
2958
2959 if (clearData.colorDepthClear2.size() != 0)
2960 {
2961 vk.cmdClearAttachments(*m_cmdBuffer2, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
2962 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
2963 }
2964
2965 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
2966 vk.cmdClearAttachments(*m_cmdBuffer2, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
2967
2968 vk.cmdEndRendering(*m_cmdBuffer2);
2969
2970 copyImgToBuff(*m_cmdBuffer2, colorAtchCount, imagesLayout, imagesFormat);
2971
2972 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer2));
2973
2974 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer, *m_cmdBuffer2);
2975
2976 verifyResults(colorAtchCount, imagesFormat);
2977 }
2978 }
2979 }
2980
2981 class SecondaryCmdBufferOutOfRenderingCommands : public DynamicRenderingTestInstance
2982 {
2983 public:
2984 SecondaryCmdBufferOutOfRenderingCommands(Context &context, const TestParameters ¶meters);
2985
2986 protected:
2987 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
2988 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
2989 const ImagesFormat &imagesFormat) override;
2990
2991 Move<VkCommandBuffer> m_secCmdBuffer;
2992 };
2993
SecondaryCmdBufferOutOfRenderingCommands(Context & context,const TestParameters & parameters)2994 SecondaryCmdBufferOutOfRenderingCommands::SecondaryCmdBufferOutOfRenderingCommands(Context &context,
2995 const TestParameters ¶meters)
2996 : DynamicRenderingTestInstance(context, parameters)
2997 {
2998 const DeviceInterface &vk = m_context.getDeviceInterface();
2999 const VkDevice device = m_context.getDevice();
3000
3001 m_secCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
3002 }
3003
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)3004 void SecondaryCmdBufferOutOfRenderingCommands::rendering(const VkPipeline pipeline,
3005 const std::vector<VkImageView> &attachmentBindInfos,
3006 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
3007 const ImagesFormat &imagesFormat)
3008 {
3009 const DeviceInterface &vk = m_context.getDeviceInterface();
3010 const VkDevice device = m_context.getDevice();
3011 const VkQueue queue = m_context.getUniversalQueue();
3012
3013 for (uint32_t attachmentLoadOp = 0; attachmentLoadOp < TEST_ATTACHMENT_LOAD_OP_LAST; ++attachmentLoadOp)
3014 for (uint32_t attachmentStoreOp = 0; attachmentStoreOp < TEST_ATTACHMENT_STORE_OP_LAST; ++attachmentStoreOp)
3015 {
3016 const VkBuffer vertexBuffer = m_vertexBuffer->object();
3017 const VkDeviceSize vertexBufferOffset = 0ull;
3018
3019 // Secondary command buffer
3020 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer);
3021
3022 preBarier(*m_secCmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
3023
3024 beginRendering(*m_secCmdBuffer, attachmentBindInfos, 0u, colorAtchCount, imagesFormat,
3025 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3026 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3027
3028 vk.cmdBindPipeline(*m_secCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3029 vk.cmdBindVertexBuffers(*m_secCmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3030
3031 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 8u, 0u);
3032 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 0u, 0u);
3033 vk.cmdDraw(*m_secCmdBuffer, 4u, 1u, 4u, 0u);
3034
3035 vk.cmdEndRendering(*m_secCmdBuffer);
3036
3037 copyImgToBuff(*m_secCmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
3038
3039 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3040
3041 // Primary command buffer
3042 beginCommandBuffer(vk, *m_cmdBuffer);
3043
3044 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
3045
3046 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3047
3048 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
3049
3050 if ((static_cast<VkAttachmentLoadOp>(attachmentLoadOp) == VK_ATTACHMENT_LOAD_OP_CLEAR) &&
3051 (static_cast<VkAttachmentStoreOp>(attachmentStoreOp) == VK_ATTACHMENT_STORE_OP_STORE))
3052 {
3053 verifyResults(colorAtchCount, imagesFormat);
3054
3055 const ClearAttachmentData clearData(colorAtchCount, imagesFormat.depth, imagesFormat.stencil);
3056
3057 // secCmdBuffers
3058 beginSecondaryCmdBuffer(vk, *m_secCmdBuffer);
3059
3060 preBarier(*m_secCmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
3061
3062 beginRendering(*m_secCmdBuffer, attachmentBindInfos, 0u, colorAtchCount, imagesFormat,
3063 static_cast<VkAttachmentLoadOp>(attachmentLoadOp),
3064 static_cast<VkAttachmentStoreOp>(attachmentStoreOp));
3065
3066 if (clearData.colorDepthClear1.size() != 0)
3067 {
3068 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear1.size()),
3069 clearData.colorDepthClear1.data(), 1, &clearData.rectColorDepth1);
3070 }
3071
3072 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3073 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear1, 1, &clearData.rectStencil1);
3074
3075 if (clearData.colorDepthClear2.size() != 0)
3076 {
3077 vk.cmdClearAttachments(*m_secCmdBuffer, static_cast<uint32_t>(clearData.colorDepthClear2.size()),
3078 clearData.colorDepthClear2.data(), 1, &clearData.rectColorDepth2);
3079 }
3080
3081 if (imagesFormat.stencil != VK_FORMAT_UNDEFINED)
3082 vk.cmdClearAttachments(*m_secCmdBuffer, 1u, &clearData.stencilClear2, 1, &clearData.rectStencil2);
3083
3084 vk.cmdEndRendering(*m_secCmdBuffer);
3085
3086 copyImgToBuff(*m_secCmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
3087
3088 VK_CHECK(vk.endCommandBuffer(*m_secCmdBuffer));
3089
3090 // Primary commandBuffer
3091 beginCommandBuffer(vk, *m_cmdBuffer);
3092
3093 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secCmdBuffer));
3094
3095 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3096
3097 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
3098
3099 verifyResults(colorAtchCount, imagesFormat);
3100 }
3101 }
3102 }
3103
3104 class PartialBindingDepthStencil : public DynamicRenderingTestInstance
3105 {
3106 public:
3107 PartialBindingDepthStencil(Context &context, const TestParameters ¶meters);
3108
3109 protected:
3110 void recordRenderingCommands(const DeviceInterface &vk, VkCommandBuffer cmdBuffer, const VkPipeline pipeline,
3111 const VkClearAttachment &clearValues, const VkClearRect &clearRect, bool clearOnly);
3112
3113 void baseTest(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
3114 const uint32_t colorAtchCount, ImagesLayout &imagesLayout, const ImagesFormat &imagesFormat,
3115 bool clearOnly, bool useSecondary);
3116
3117 void rendering(const VkPipeline pipeline, const std::vector<VkImageView> &attachmentBindInfos,
3118 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
3119 const ImagesFormat &imagesFormat) override;
3120
3121 Move<VkCommandBuffer> m_secondaryCmdBuffer;
3122 VkAttachmentLoadOp m_attachmentLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
3123 const VkAttachmentStoreOp m_attachmentStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
3124 };
3125
PartialBindingDepthStencil(Context & context,const TestParameters & parameters)3126 PartialBindingDepthStencil::PartialBindingDepthStencil(Context &context, const TestParameters ¶meters)
3127 : DynamicRenderingTestInstance(context, parameters)
3128 {
3129 const DeviceInterface &vk = m_context.getDeviceInterface();
3130 const VkDevice device = m_context.getDevice();
3131
3132 m_secondaryCmdBuffer = allocateCommandBuffer(vk, device, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
3133 }
3134
recordRenderingCommands(const DeviceInterface & vk,VkCommandBuffer cmdBuffer,const VkPipeline pipeline,const VkClearAttachment & clearValues,const VkClearRect & clearRect,bool clearOnly)3135 void PartialBindingDepthStencil::recordRenderingCommands(const DeviceInterface &vk, VkCommandBuffer cmdBuffer,
3136 const VkPipeline pipeline,
3137 const VkClearAttachment &clearValues,
3138 const VkClearRect &clearRect, bool clearOnly)
3139 {
3140 if (m_attachmentLoadOp == VK_ATTACHMENT_LOAD_OP_LOAD)
3141 {
3142 vk.cmdClearAttachments(cmdBuffer, 1, &clearValues, 1, &clearRect);
3143 }
3144
3145 if (!clearOnly)
3146 {
3147 vk.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
3148
3149 {
3150 const VkBuffer vertexBuffer = m_vertexBuffer->object();
3151 const VkDeviceSize vertexBufferOffset = 0ull;
3152 vk.cmdBindVertexBuffers(cmdBuffer, 0u, 1u, &vertexBuffer, &vertexBufferOffset);
3153 }
3154
3155 vk.cmdDraw(cmdBuffer, 4u, 1u, 8u, 0u);
3156 vk.cmdDraw(cmdBuffer, 4u, 1u, 0u, 0u);
3157 vk.cmdDraw(cmdBuffer, 4u, 1u, 4u, 0u);
3158 }
3159 }
3160
baseTest(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat,bool clearOnly,bool useSecondary)3161 void PartialBindingDepthStencil::baseTest(const VkPipeline pipeline,
3162 const std::vector<VkImageView> &attachmentBindInfos,
3163 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
3164 const ImagesFormat &imagesFormat, bool clearOnly, bool useSecondary)
3165 {
3166 const DeviceInterface &vk = m_context.getDeviceInterface();
3167 const VkDevice device = m_context.getDevice();
3168 const VkQueue queue = m_context.getUniversalQueue();
3169
3170 const bool usesDepth = (imagesFormat.depth != VK_FORMAT_UNDEFINED);
3171 const bool usesStencil = (imagesFormat.stencil != VK_FORMAT_UNDEFINED);
3172
3173 // Clear values before rendering is started
3174 const VkClearDepthStencilValue depthStencilClear = makeClearValueDepthStencil(0.5f, 127u).depthStencil;
3175
3176 // Clear values for attachment clear in render pass. Same one as in beginRendering
3177 VkClearValue clearValue = makeClearValueColor(m_parameters.clearColor);
3178 clearValue.depthStencil.depth = m_parameters.depthClearValue;
3179 clearValue.depthStencil.stencil = m_parameters.stencilClearValue;
3180
3181 // Expected values
3182 const float expectedDepth = usesDepth ? clearValue.depthStencil.depth : depthStencilClear.depth;
3183 const unsigned expectedStencil = usesStencil ? clearValue.depthStencil.stencil : depthStencilClear.stencil;
3184
3185 // Aspect masks
3186 VkImageAspectFlags depthMask = usesDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : static_cast<VkImageAspectFlagBits>(0u);
3187 VkImageAspectFlags stencilMask = usesStencil ? VK_IMAGE_ASPECT_STENCIL_BIT : static_cast<VkImageAspectFlagBits>(0u);
3188
3189 const VkClearAttachment clearValues = {
3190 depthMask | stencilMask, // aspectMask
3191 0, // colorAttachment
3192 clearValue // clearValue
3193 };
3194 const VkClearRect clearRect = {
3195 makeRect2D(m_parameters.renderSize), // rect
3196 0u, // baseArrayLayer
3197 1u, // layerCount
3198 };
3199
3200 if (useSecondary)
3201 {
3202 beginSecondaryCmdBuffer(vk, *m_secondaryCmdBuffer, 0u, 0u, imagesFormat);
3203 recordRenderingCommands(vk, *m_secondaryCmdBuffer, pipeline, clearValues, clearRect, clearOnly);
3204 VK_CHECK(vk.endCommandBuffer(*m_secondaryCmdBuffer));
3205 }
3206
3207 beginCommandBuffer(vk, *m_cmdBuffer);
3208
3209 // Clear before we start rendering with a different value to ensure unbound one is not modified when rendering
3210 {
3211 VkImageSubresourceRange subresource =
3212 makeImageSubresourceRange(VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 1u, 0u, 1u);
3213 VkImageMemoryBarrier barrier =
3214 makeImageMemoryBarrier(VK_ACCESS_NONE_KHR, VK_ACCESS_TRANSFER_WRITE_BIT, imagesLayout.oldDepth,
3215 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, *m_imageStencilDepth, subresource);
3216 cmdPipelineImageMemoryBarrier(vk, *m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
3217 VK_PIPELINE_STAGE_TRANSFER_BIT, &barrier, 1u);
3218 imagesLayout.oldDepth = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3219 imagesLayout.oldStencil = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3220 vk.cmdClearDepthStencilImage(*m_cmdBuffer, *m_imageStencilDepth, imagesLayout.oldDepth, &depthStencilClear, 1,
3221 &subresource);
3222 }
3223
3224 preBarier(*m_cmdBuffer, colorAtchCount, imagesLayout, imagesFormat);
3225
3226 beginRendering(*m_cmdBuffer, attachmentBindInfos,
3227 useSecondary ? VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT : 0, colorAtchCount, imagesFormat,
3228 static_cast<VkAttachmentLoadOp>(m_attachmentLoadOp),
3229 static_cast<VkAttachmentStoreOp>(m_attachmentStoreOp));
3230
3231 if (useSecondary)
3232 vk.cmdExecuteCommands(*m_cmdBuffer, 1u, &(*m_secondaryCmdBuffer));
3233 else
3234 recordRenderingCommands(vk, *m_cmdBuffer, pipeline, clearValues, clearRect, clearOnly);
3235
3236 vk.cmdEndRendering(*m_cmdBuffer);
3237
3238 // Copy images
3239 {
3240 const auto prevDepthXfer = (imagesLayout.oldDepth == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
3241 const auto prevStencilXfer = (imagesLayout.oldStencil == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
3242 const auto srcAccessDepth = (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
3243 (prevDepthXfer ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_NONE_KHR));
3244 const auto srcAccessStencil = (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
3245 (prevStencilXfer ? VK_ACCESS_TRANSFER_WRITE_BIT : VK_ACCESS_NONE_KHR));
3246
3247 copyImageToBuffer(vk, *m_cmdBuffer, *m_imageStencilDepth, m_imageDepthBuffer->object(),
3248 tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()), srcAccessDepth,
3249 imagesLayout.oldDepth, 1u, VK_IMAGE_ASPECT_DEPTH_BIT, VK_IMAGE_ASPECT_DEPTH_BIT);
3250 imagesLayout.oldDepth = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3251
3252 copyImageToBuffer(vk, *m_cmdBuffer, *m_imageStencilDepth, m_imageStencilBuffer->object(),
3253 tcu::IVec2(m_parameters.renderSize.x(), m_parameters.renderSize.y()), srcAccessStencil,
3254 imagesLayout.oldStencil, 1u, VK_IMAGE_ASPECT_STENCIL_BIT, VK_IMAGE_ASPECT_STENCIL_BIT);
3255 imagesLayout.oldStencil = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3256 }
3257
3258 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3259 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
3260
3261 // Verify depth
3262 {
3263 tcu::TextureLevel reference;
3264
3265 if (!clearOnly && usesDepth)
3266 {
3267 reference = m_referenceImages[COLOR_ATTACHMENTS_NUMBER];
3268 }
3269 else
3270 {
3271 reference = tcu::TextureLevel(getDepthCopyFormat(m_formatStencilDepthImage), m_parameters.renderSize.x(),
3272 m_parameters.renderSize.y());
3273
3274 for (int z = 0u; z < reference.getDepth(); ++z)
3275 for (int y = 0u; y < reference.getHeight(); ++y)
3276 for (int x = 0u; x < reference.getWidth(); ++x)
3277 reference.getAccess().setPixDepth(expectedDepth, x, y, z);
3278 }
3279
3280 verifyDepth(reference);
3281 }
3282
3283 // Verify stencil
3284 {
3285 tcu::TextureLevel reference;
3286
3287 if (!clearOnly && usesStencil)
3288 {
3289 reference = m_referenceImages[COLOR_ATTACHMENTS_NUMBER + 1];
3290 }
3291 else
3292 {
3293 reference = tcu::TextureLevel(mapVkFormat(VK_FORMAT_S8_UINT), m_parameters.renderSize.x(),
3294 m_parameters.renderSize.y());
3295
3296 for (int z = 0u; z < reference.getDepth(); ++z)
3297 for (int y = 0u; y < reference.getHeight(); ++y)
3298 for (int x = 0u; x < reference.getWidth(); ++x)
3299 reference.getAccess().setPixStencil(expectedStencil, x, y, z);
3300 }
3301
3302 verifyStencil(reference);
3303 }
3304 }
3305
rendering(const VkPipeline pipeline,const std::vector<VkImageView> & attachmentBindInfos,const uint32_t colorAtchCount,ImagesLayout & imagesLayout,const ImagesFormat & imagesFormat)3306 void PartialBindingDepthStencil::rendering(const VkPipeline pipeline,
3307 const std::vector<VkImageView> &attachmentBindInfos,
3308 const uint32_t colorAtchCount, ImagesLayout &imagesLayout,
3309 const ImagesFormat &imagesFormat)
3310 {
3311 // Only test when one of both depth or stencil is enabled
3312 // If no depth/stencil format is available, both will be undefined and therefore pass
3313 if ((imagesFormat.depth != VK_FORMAT_UNDEFINED) ^ (imagesFormat.stencil != VK_FORMAT_UNDEFINED))
3314 {
3315 tcu::TestLog &log = m_context.getTestContext().getLog();
3316
3317 log << tcu::TestLog::Message << "Checking depth format " << getFormatName(imagesFormat.depth)
3318 << " and stencil format " << getFormatName(imagesFormat.stencil) << tcu::TestLog::EndMessage;
3319
3320 log << tcu::TestLog::Message << "Attachment load op LOAD" << tcu::TestLog::EndMessage;
3321 m_attachmentLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
3322 log << tcu::TestLog::Message << "Primary clear only" << tcu::TestLog::EndMessage;
3323 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, true, false);
3324 log << tcu::TestLog::Message << "Primary non trivial draw" << tcu::TestLog::EndMessage;
3325 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, false, false);
3326 log << tcu::TestLog::Message << "Secondary clear only" << tcu::TestLog::EndMessage;
3327 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, true, true);
3328 log << tcu::TestLog::Message << "Secondary non trivial draw" << tcu::TestLog::EndMessage;
3329 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, false, true);
3330
3331 log << tcu::TestLog::Message << "Attachment load op CLEAR" << tcu::TestLog::EndMessage;
3332 m_attachmentLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
3333 log << tcu::TestLog::Message << "Primary clear only" << tcu::TestLog::EndMessage;
3334 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, true, false);
3335 log << tcu::TestLog::Message << "Primary non trivial draw" << tcu::TestLog::EndMessage;
3336 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, false, false);
3337 log << tcu::TestLog::Message << "Secondary clear only" << tcu::TestLog::EndMessage;
3338 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, true, true);
3339 log << tcu::TestLog::Message << "Secondary non trivial draw" << tcu::TestLog::EndMessage;
3340 baseTest(pipeline, attachmentBindInfos, colorAtchCount, imagesLayout, imagesFormat, false, true);
3341 }
3342 }
3343
3344 class BaseTestCase : public TestCase
3345 {
3346 public:
3347 BaseTestCase(tcu::TestContext &context, const std::string &name, const TestParameters ¶meters);
3348 virtual ~BaseTestCase(void);
3349
3350 protected:
3351 virtual void checkSupport(Context &context) const;
3352 virtual void initPrograms(SourceCollections &programCollection) const;
3353 virtual TestInstance *createInstance(Context &context) const;
3354
3355 const TestParameters m_parameters;
3356 };
3357
BaseTestCase(tcu::TestContext & context,const std::string & name,const TestParameters & parameters)3358 BaseTestCase::BaseTestCase(tcu::TestContext &context, const std::string &name, const TestParameters ¶meters)
3359 : TestCase(context, name)
3360 , m_parameters(parameters)
3361 {
3362 }
3363
~BaseTestCase()3364 BaseTestCase::~BaseTestCase()
3365 {
3366 }
3367
checkSupport(Context & context) const3368 void BaseTestCase::checkSupport(Context &context) const
3369 {
3370 if (!context.requireDeviceFunctionality("VK_KHR_dynamic_rendering"))
3371 TCU_THROW(NotSupportedError, "VK_KHR_dynamic_rendering not supported");
3372 }
3373
initPrograms(SourceCollections & programCollection) const3374 void BaseTestCase::initPrograms(SourceCollections &programCollection) const
3375 {
3376 // Vertex
3377 {
3378 std::ostringstream src;
3379 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
3380 << "\n"
3381 << "layout(location = 0) in highp vec4 position;\n"
3382 << "layout(location = 0) out highp vec4 vsColor;\n"
3383 << "\n"
3384 << "out gl_PerVertex {\n"
3385 << " vec4 gl_Position;\n"
3386 << "};\n"
3387 << "\n"
3388 << "void main (void)\n"
3389 << "{\n"
3390 << " gl_Position = position;\n"
3391 << " vsColor = vec4(gl_Position.z * 5.0f, 1.0f, 0.0f, 1.0f);\n"
3392 << "}\n";
3393 programCollection.glslSources.add("vert") << glu::VertexSource(src.str());
3394 }
3395
3396 // Fragment multi color attachment
3397 {
3398 std::ostringstream src;
3399 src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
3400 << "\n"
3401 << "layout(location = 0) in highp vec4 vsColor;\n";
3402
3403 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
3404 src << "layout(location = " << ndx << ") out highp vec4 fsColor" << ndx << ";\n";
3405
3406 src << "\n"
3407 << "void main (void)\n"
3408 << "{\n"
3409 << " vec4 color = vsColor;\n";
3410 for (uint32_t ndx = 0; ndx < COLOR_ATTACHMENTS_NUMBER; ++ndx)
3411 {
3412 src << " color.z = 0.15f * " << ndx << ".0f;\n"
3413 << " fsColor" << ndx << " = color;\n";
3414 }
3415 src << "}\n";
3416 programCollection.glslSources.add("frag") << glu::FragmentSource(src.str());
3417 }
3418 }
3419
createInstance(Context & context) const3420 TestInstance *BaseTestCase::createInstance(Context &context) const
3421 {
3422 switch (m_parameters.testType)
3423 {
3424 case TEST_TYPE_SINGLE_CMDBUF:
3425 {
3426 return new DynamicRenderingTestInstance(context, m_parameters);
3427 }
3428 case TEST_TYPE_SINGLE_CMDBUF_RESUMING:
3429 {
3430 return new SingleCmdBufferResuming(context, m_parameters);
3431 }
3432 case TEST_TYPE_TWO_CMDBUF_RESUMING:
3433 {
3434 return new TwoPrimaryCmdBufferResuming(context, m_parameters);
3435 }
3436 case TEST_TYPE_SECONDARY_CMDBUF_RESUMING:
3437 {
3438 return new TwoSecondaryCmdBufferResuming(context, m_parameters);
3439 }
3440 case TEST_TYPE_SECONDARY_CMDBUF_TWO_PRIMARY_RESUMING:
3441 {
3442 return new TwoSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3443 }
3444 case TEST_TYPE_CONTENTS_SECONDARY_COMMAND_BUFFER:
3445 {
3446 return new ContentsSecondaryCmdBuffer(context, m_parameters);
3447 }
3448 case TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER:
3449 {
3450 return new ContentsTwoSecondaryCmdBuffer(context, m_parameters);
3451 }
3452 case TEST_TYPE_CONTENTS_2_SECONDARY_COMMAND_BUFFER_RESUMING:
3453 {
3454 return new ContentsTwoSecondaryCmdBufferResuming(context, m_parameters);
3455 }
3456 case TEST_TYPE_CONTENTS_2_SECONDARY_2_PRIMARY_COMDBUF_RESUMING:
3457 {
3458 return new ContentsTwoSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3459 }
3460 case TEST_TYPE_CONTENTS_PRIMARY_SECONDARY_COMDBUF_RESUMING:
3461 {
3462 return new ContentsPrimarySecondaryCmdBufferResuming(context, m_parameters);
3463 }
3464 case TEST_TYPE_CONTENTS_SECONDARY_PRIMARY_COMDBUF_RESUMING:
3465 {
3466 return new ContentsSecondaryPrimaryCmdBufferResuming(context, m_parameters);
3467 }
3468 case TEST_TYPE_CONTENTS_2_PRIMARY_SECONDARY_COMDBUF_RESUMING:
3469 {
3470 return new ContentsTwoPrimarySecondaryCmdBufferResuming(context, m_parameters);
3471 }
3472 case TEST_TYPE_CONTENTS_SECONDARY_2_PRIMARY_COMDBUF_RESUMING:
3473 {
3474 return new ContentsSecondaryTwoPrimaryCmdBufferResuming(context, m_parameters);
3475 }
3476 case TEST_TYPE_SECONDARY_CMDBUF_OUT_OF_RENDERING_COMMANDS:
3477 {
3478 return new SecondaryCmdBufferOutOfRenderingCommands(context, m_parameters);
3479 }
3480 case TEST_TYPE_PARTIAL_BINDING_DEPTH_STENCIL:
3481 {
3482 return new PartialBindingDepthStencil(context, m_parameters);
3483 }
3484 default:
3485 DE_FATAL("Impossible");
3486 }
3487 return nullptr;
3488 }
3489
dynamicRenderingTests(tcu::TestContext & testCtx,const TestParameters & parameters)3490 tcu::TestNode *dynamicRenderingTests(tcu::TestContext &testCtx, const TestParameters ¶meters)
3491 {
3492 const std::string testName[TEST_TYPE_LAST] = {
3493 "single_cmdbuffer",
3494 "single_cmdbuffer_resuming",
3495 "2_cmdbuffers_resuming",
3496 "2_secondary_cmdbuffers_resuming",
3497 "2_secondary_2_primary_cmdbuffers_resuming",
3498 "contents_secondary_cmdbuffers",
3499 "contents_2_secondary_cmdbuffers",
3500 "contents_2_secondary_cmdbuffers_resuming",
3501 "contents_2_secondary_2_primary_cmdbuffers_resuming",
3502 "contents_primary_secondary_cmdbuffers_resuming",
3503 "contents_secondary_primary_cmdbuffers_resuming",
3504 "contents_2_primary_secondary_cmdbuffers_resuming",
3505 "contents_secondary_2_primary_cmdbuffers_resuming",
3506 "secondary_cmdbuffer_out_of_rendering_commands",
3507 "partial_binding_depth_stencil",
3508 };
3509
3510 // Dynamic Rendering tests
3511 return new BaseTestCase(testCtx, testName[parameters.testType], parameters);
3512 }
3513
3514 } // namespace
3515
createDynamicRenderingBasicTests(tcu::TestContext & testCtx)3516 tcu::TestCaseGroup *createDynamicRenderingBasicTests(tcu::TestContext &testCtx)
3517 {
3518 // Basic dynamic rendering tests
3519 de::MovePtr<tcu::TestCaseGroup> dynamicRenderingGroup(new tcu::TestCaseGroup(testCtx, "basic"));
3520
3521 for (int testType = 0; testType < TEST_TYPE_LAST; ++testType)
3522 {
3523 const TestParameters parameters = {
3524 static_cast<TestType>(testType), // TestType testType;
3525 Vec4(0.0f, 0.0f, 0.0f, 1.0f), // const Vec4 clearColor;
3526 1.0f, // float depthClearValue;
3527 0U, // uint32_t stencilClearValue;
3528 VK_FORMAT_R8G8B8A8_UNORM, // const VkFormat imageFormat;
3529 (UVec2(32, 32)) // const UVec2 renderSize;
3530 };
3531
3532 dynamicRenderingGroup->addChild(dynamicRenderingTests(testCtx, parameters));
3533 }
3534
3535 return dynamicRenderingGroup.release();
3536 }
3537
3538 } // namespace renderpass
3539 } // namespace vkt
3540