1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
4 *
5 * Copyright (c) 2018 Google 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 Descriptor set tests
22 *//*--------------------------------------------------------------------*/
23
24 #include "amber/vktAmberTestCase.hpp"
25 #include "vktApiDescriptorSetTests.hpp"
26 #include "vktTestCaseUtil.hpp"
27 #include "vkCmdUtil.hpp"
28 #include "vkMemUtil.hpp"
29 #include "vktApiBufferComputeInstance.hpp"
30 #include "vktApiComputeInstanceResultBuffer.hpp"
31 #include "vkBufferWithMemory.hpp"
32 #include "vkObjUtil.hpp"
33
34 #include "vkQueryUtil.hpp"
35 #include "vkRefUtil.hpp"
36 #include "vkPrograms.hpp"
37
38 namespace vkt
39 {
40 namespace api
41 {
42
43 namespace
44 {
45
46 using namespace std;
47 using namespace vk;
48
49 // Descriptor set layout used to create a pipeline layout is destroyed prior to creating a pipeline
createPipelineLayoutDestroyDescriptorSetLayout(const DeviceInterface & vk,const VkDevice & device)50 Move<VkPipelineLayout> createPipelineLayoutDestroyDescriptorSetLayout (const DeviceInterface& vk, const VkDevice& device)
51 {
52 const VkDescriptorSetLayoutCreateInfo descriptorSetLayoutInfo =
53 {
54 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
55 DE_NULL, // const void* pNext;
56 (VkDescriptorSetLayoutCreateFlags)0, // VkDescriptorSetLayoutCreateFlags flags;
57 0u, // deUint32 bindingCount;
58 DE_NULL, // const VkDescriptorSetLayoutBinding* pBindings;
59 };
60
61 Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(vk, device, &descriptorSetLayoutInfo));
62
63 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
64 {
65 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
66 DE_NULL, // const void* pNext;
67 (VkPipelineLayoutCreateFlags)0, // VkPipelineLayoutCreateFlags flags;
68 1u, // deUint32 setLayoutCount;
69 &descriptorSetLayout.get(), // const VkDescriptorSetLayout* pSetLayouts;
70 0u, // deUint32 pushConstantRangeCount;
71 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
72 };
73
74 return createPipelineLayout(vk, device, &pipelineLayoutCreateInfo);
75 }
76
descriptorSetLayoutLifetimeGraphicsTest(Context & context)77 tcu::TestStatus descriptorSetLayoutLifetimeGraphicsTest (Context& context)
78 {
79 const DeviceInterface& vk = context.getDeviceInterface();
80 const VkDevice device = context.getDevice();
81 deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
82 const VkQueue queue = context.getUniversalQueue();
83
84 Unique<VkPipelineLayout> pipelineLayout (createPipelineLayoutDestroyDescriptorSetLayout(vk, device));
85
86 const Unique<VkShaderModule> vertexShaderModule (createShaderModule(vk, device, context.getBinaryCollection().get("vertex"), 0));
87
88 const VkPipelineShaderStageCreateInfo shaderStageCreateInfo =
89 {
90 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
91 DE_NULL, // const void* pNext;
92 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
93 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
94 vertexShaderModule.get(), // VkShaderModule shader;
95 "main", // const char* pName;
96 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
97 };
98
99 const VkPipelineVertexInputStateCreateInfo vertexInputStateCreateInfo =
100 {
101 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
102 DE_NULL, // const void* pNext;
103 (VkPipelineVertexInputStateCreateFlags)0, // VkPipelineVertexInputStateCreateFlags flags;
104 0u, // deUint32 vertexBindingDescriptionCount;
105 DE_NULL, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
106 0u, // deUint32 vertexAttributeDescriptionCount;
107 DE_NULL // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
108 };
109
110 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateCreateInfo =
111 {
112 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
113 DE_NULL, // const void* pNext;
114 (VkPipelineInputAssemblyStateCreateFlags)0, // VkPipelineInputAssemblyStateCreateFlags flags;
115 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, // VkPrimitiveTopology topology;
116 VK_FALSE // VkBool32 primitiveRestartEnable;
117 };
118
119 const VkPipelineRasterizationStateCreateInfo rasterizationStateCreateInfo =
120 {
121 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
122 DE_NULL, // const void* pNext;
123 (VkPipelineRasterizationStateCreateFlags)0, // VkPipelineRasterizationStateCreateFlags flags;
124 VK_FALSE, // VkBool32 depthClampEnable;
125 VK_TRUE, // VkBool32 rasterizerDiscardEnable;
126 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
127 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
128 VK_FRONT_FACE_CLOCKWISE, // VkFrontFace frontFace;
129 VK_FALSE, // VkBool32 depthBiasEnable;
130 0.0f, // float depthBiasConstantFactor;
131 0.0f, // float depthBiasClamp;
132 0.0f, // float depthBiasSlopeFactor;
133 1.0f // float lineWidth;
134 };
135
136 const VkSubpassDescription subpassDescription =
137 {
138 (VkSubpassDescriptionFlags)0, // VkSubpassDescriptionFlags flags;
139 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint
140 0u, // deUint32 inputAttachmentCount
141 DE_NULL, // const VkAttachmentReference* pInputAttachments
142 0u, // deUint32 colorAttachmentCount
143 DE_NULL, // const VkAttachmentReference* pColorAttachments
144 DE_NULL, // const VkAttachmentReference* pResolveAttachments
145 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment
146 0u, // deUint32 preserveAttachmentCount
147 DE_NULL // const deUint32* pPreserveAttachments
148 };
149
150 const VkRenderPassCreateInfo renderPassCreateInfo =
151 {
152 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
153 DE_NULL, // const void* pNext;
154 (VkRenderPassCreateFlags)0, // VkRenderPassCreateFlags flags;
155 0u, // deUint32 attachmentCount
156 DE_NULL, // const VkAttachmentDescription* pAttachments
157 1u, // deUint32 subpassCount
158 &subpassDescription, // const VkSubpassDescription* pSubpasses
159 0u, // deUint32 dependencyCount
160 DE_NULL // const VkSubpassDependency* pDependencies
161 };
162
163 Unique<VkRenderPass> renderPass (createRenderPass(vk, device, &renderPassCreateInfo));
164
165 const VkGraphicsPipelineCreateInfo graphicsPipelineCreateInfo =
166 {
167 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
168 DE_NULL, // const void* pNext;
169 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags;
170 1u, // deUint32 stageCount;
171 &shaderStageCreateInfo, // const VkPipelineShaderStageCreateInfo* pStages;
172 &vertexInputStateCreateInfo, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
173 &inputAssemblyStateCreateInfo, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
174 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
175 DE_NULL, // const VkPipelineViewportStateCreateInfo* pViewportState;
176 &rasterizationStateCreateInfo, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
177 DE_NULL, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
178 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
179 DE_NULL, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
180 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
181 pipelineLayout.get(), // VkPipelineLayout layout;
182 renderPass.get(), // VkRenderPass renderPass;
183 0u, // deUint32 subpass;
184 DE_NULL, // VkPipeline basePipelineHandle;
185 0 // int basePipelineIndex;
186 };
187
188 Unique<VkPipeline> graphicsPipeline (createGraphicsPipeline(vk, device, DE_NULL, &graphicsPipelineCreateInfo));
189
190
191 VkFramebufferCreateInfo framebufferCreateInfo
192 {
193 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType
194 DE_NULL, // const void* pNext
195 0, // VkFramebufferCreateFlags flags
196 *renderPass, // VkRenderPass renderPass
197 0, // uint32_t attachmentCount
198 DE_NULL, // const VkImageView* pAttachments
199 16, // uint32_t width
200 16, // uint32_t height
201 1 // uint32_t layers
202 };
203
204 Move <VkFramebuffer> framebuffer = createFramebuffer(vk, device, &framebufferCreateInfo);
205
206 const VkCommandPoolCreateInfo cmdPoolInfo =
207 {
208 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // Stype
209 DE_NULL, // PNext
210 DE_NULL, // flags
211 queueFamilyIndex, // queuefamilyindex
212 };
213
214 const Unique<VkCommandPool> cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
215
216 const VkCommandBufferAllocateInfo cmdBufParams =
217 {
218 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
219 DE_NULL, // const void* pNext;
220 *cmdPool, // VkCommandPool pool;
221 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
222 1u, // uint32_t bufferCount;
223 };
224
225 const Unique<VkCommandBuffer> cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
226
227 const VkRenderPassBeginInfo renderPassBeginInfo =
228 {
229 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
230 DE_NULL,
231 *renderPass,
232 *framebuffer,
233 {{0, 0}, {16, 16}},
234 0,
235 DE_NULL
236 };
237
238 beginCommandBuffer(vk, *cmdBuf, 0u);
239 {
240 vk.cmdBeginRenderPass(*cmdBuf, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
241 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
242 vk.cmdDraw(*cmdBuf, 3u, 1u, 0, 0);
243 vk.cmdEndRenderPass(*cmdBuf);
244 }
245 endCommandBuffer(vk, *cmdBuf);
246
247 submitCommandsAndWait(vk, device, queue, *cmdBuf);
248
249 // Test should always pass
250 return tcu::TestStatus::pass("Pass");
251 }
252
descriptorSetLayoutLifetimeComputeTest(Context & context)253 tcu::TestStatus descriptorSetLayoutLifetimeComputeTest (Context& context)
254 {
255 const DeviceInterface& vk = context.getDeviceInterface();
256 const VkDevice device = context.getDevice();
257 deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
258 const VkQueue queue = context.getUniversalQueue();
259 Allocator& allocator = context.getDefaultAllocator();
260 const ComputeInstanceResultBuffer result(vk, device, allocator, 0.0f);
261
262
263 Unique<VkPipelineLayout> pipelineLayout (createPipelineLayoutDestroyDescriptorSetLayout(vk, device));
264
265 const Unique<VkShaderModule> computeShaderModule (createShaderModule(vk, device, context.getBinaryCollection().get("compute"), 0));
266
267 const VkPipelineShaderStageCreateInfo shaderStageCreateInfo =
268 {
269 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
270 DE_NULL, // const void* pNext;
271 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
272 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
273 computeShaderModule.get(), // VkShaderModule shader;
274 "main", // const char* pName;
275 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
276 };
277
278 const VkComputePipelineCreateInfo computePipelineCreateInfo =
279 {
280 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType
281 DE_NULL, // const void* pNext
282 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags
283 shaderStageCreateInfo, // VkPipelineShaderStageCreateInfo stage
284 pipelineLayout.get(), // VkPipelineLayout layout
285 DE_NULL, // VkPipeline basePipelineHandle
286 0 // int basePipelineIndex
287 };
288
289 const deUint32 offset = (0u);
290 const deUint32 addressableSize = 256;
291 const deUint32 dataSize = 8;
292 de::MovePtr<Allocation> bufferMem;
293 const Unique<VkBuffer> buffer (createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem));
294 const Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(context));
295 const Unique<VkDescriptorPool> descriptorPool (createDescriptorPool(context));
296 const Unique<VkDescriptorSet> descriptorSet (createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer()));
297
298 Unique<VkPipeline> computePipeline (createComputePipeline(vk, device, DE_NULL, &computePipelineCreateInfo));
299
300 const VkCommandPoolCreateInfo cmdPoolInfo =
301 {
302 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // Stype
303 DE_NULL, // PNext
304 DE_NULL, // flags
305 queueFamilyIndex, // queuefamilyindex
306 };
307
308 const Unique<VkCommandPool> cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
309
310 const VkCommandBufferAllocateInfo cmdBufParams =
311 {
312 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
313 DE_NULL, // const void* pNext;
314 *cmdPool, // VkCommandPool pool;
315 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
316 1u, // uint32_t bufferCount;
317 };
318
319 const Unique<VkCommandBuffer> cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
320
321 beginCommandBuffer(vk, *cmdBuf, 0u);
322 {
323 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *computePipeline);
324 vk.cmdBindDescriptorSets(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, 1u, &*descriptorSet, 0, 0);
325 vk.cmdDispatch(*cmdBuf, 1u, 1u, 1u);
326 }
327 endCommandBuffer(vk, *cmdBuf);
328
329 submitCommandsAndWait(vk, device, queue, *cmdBuf);
330
331 // Test should always pass
332 return tcu::TestStatus::pass("Pass");
333 }
334
emptyDescriptorSetLayoutTest(Context & context,VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags)335 tcu::TestStatus emptyDescriptorSetLayoutTest (Context& context, VkDescriptorSetLayoutCreateFlags descriptorSetLayoutCreateFlags)
336 {
337 const DeviceInterface& vk = context.getDeviceInterface();
338 const VkDevice device = context.getDevice();
339
340 if (descriptorSetLayoutCreateFlags == VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR)
341 if (!context.isDeviceFunctionalitySupported("VK_KHR_push_descriptor"))
342 TCU_THROW(NotSupportedError, "VK_KHR_push_descriptor extension not supported");
343
344 const VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo =
345 {
346 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
347 DE_NULL, // const void* pNext;
348 descriptorSetLayoutCreateFlags, // VkDescriptorSetLayoutCreateFlags flags;
349 0u, // deUint32 bindingCount;
350 DE_NULL // const VkDescriptorSetLayoutBinding* pBindings;
351 };
352
353 Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(vk, device, &descriptorSetLayoutCreateInfo));
354
355 // Test should always pass
356 return tcu::TestStatus::pass("Pass");
357 }
358
descriptorSetLayoutBindingOrderingTest(Context & context)359 tcu::TestStatus descriptorSetLayoutBindingOrderingTest (Context& context)
360 {
361 /*
362 This test tests that if dstBinding has fewer than
363 descriptorCount array elements remaining starting from dstArrayElement,
364 then the remainder will be used to update the subsequent binding.
365 */
366
367 const DeviceInterface& vk = context.getDeviceInterface();
368 const VkDevice device = context.getDevice();
369 deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
370 const VkQueue queue = context.getUniversalQueue();
371
372 const Unique<VkShaderModule> computeShaderModule (createShaderModule(vk, device, context.getBinaryCollection().get("compute"), 0));
373
374 de::MovePtr<BufferWithMemory> buffer;
375 buffer = de::MovePtr<BufferWithMemory>(new BufferWithMemory(vk,
376 device,
377 context.getDefaultAllocator(),
378 makeBufferCreateInfo(4u, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT),
379 MemoryRequirement::HostVisible));
380 deUint32 *bufferPtr = (deUint32 *)buffer->getAllocation().getHostPtr();
381 *bufferPtr = 5;
382
383 de::MovePtr<BufferWithMemory> resultBuffer;
384 resultBuffer = de::MovePtr<BufferWithMemory>(new BufferWithMemory(vk,
385 device,
386 context.getDefaultAllocator(),
387 makeBufferCreateInfo(4u * 3, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT),
388 MemoryRequirement::HostVisible));
389
390 const VkDescriptorBufferInfo descriptorBufferInfos[] =
391 {
392 {
393 buffer->get(), // VkBuffer buffer
394 0u, // VkDeviceSize offset
395 VK_WHOLE_SIZE // VkDeviceSize range
396 },
397 {
398 buffer->get(), // VkBuffer buffer
399 0u, // VkDeviceSize offset
400 VK_WHOLE_SIZE // VkDeviceSize range
401 },
402 {
403 buffer->get(), // VkBuffer buffer
404 0u, // VkDeviceSize offset
405 VK_WHOLE_SIZE // VkDeviceSize range
406 },
407 };
408
409 const VkDescriptorBufferInfo descriptorBufferInfoResult =
410 {
411 resultBuffer->get(), // VkBuffer buffer
412 0u, // VkDeviceSize offset
413 VK_WHOLE_SIZE // VkDeviceSize range
414 };
415
416 const VkDescriptorSetLayoutBinding layoutBindings[] =
417 {
418 {
419 0u, // deUint32 binding;
420 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
421 2u, // deUint32 descriptorCount;
422 VK_SHADER_STAGE_ALL, // VkShaderStageFlags stageFlags;
423 DE_NULL // const VkSampler* pImmutableSamplers;
424 },
425 {
426 1u, // deUint32 binding;
427 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType;
428 1u, // deUint32 descriptorCount;
429 VK_SHADER_STAGE_ALL, // VkShaderStageFlags stageFlags;
430 DE_NULL // const VkSampler* pImmutableSamplers;
431 },
432 {
433 2u, // deUint32 binding;
434 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, // VkDescriptorType descriptorType;
435 1u, // deUint32 descriptorCount;
436 VK_SHADER_STAGE_ALL, // VkShaderStageFlags stageFlags;
437 DE_NULL // const VkSampler* pImmutableSamplers;
438 }
439 };
440
441 const VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo =
442 {
443 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
444 DE_NULL, // const void* pNext;
445 0u, // VkDescriptorSetLayoutCreateFlags flags;
446 DE_LENGTH_OF_ARRAY(layoutBindings), // deUint32 bindingCount;
447 layoutBindings // const VkDescriptorSetLayoutBinding* pBindings;
448 };
449
450 Move<VkDescriptorSetLayout> descriptorSetLayout(createDescriptorSetLayout(vk, device, &descriptorSetLayoutCreateInfo));
451
452 const VkDescriptorPoolSize poolSize[] =
453 {
454 {
455 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType type
456 3u // uint32_t descriptorCount
457 },
458 {
459 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, // VkDescriptorType type
460 1u // uint32_t descriptorCount
461 }
462 };
463
464 const VkDescriptorPoolCreateInfo descriptorPoolCreateInfo =
465 {
466 VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType
467 DE_NULL, // const void* pNext
468 0u, // VkDescriptorPoolCreateFlags flags
469 1u, // uint32_t maxSets
470 2u, // uint32_t poolSizeCount
471 poolSize // const VkDescriptorPoolSize* pPoolSizes
472 };
473
474 Move<VkDescriptorPool> descriptorPool(createDescriptorPool(vk, device, &descriptorPoolCreateInfo));
475
476 VkDescriptorSet descriptorSet;
477 {
478 const VkDescriptorSetAllocateInfo allocInfo =
479 {
480 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, // VkStructure sType
481 DE_NULL, // const void* pNext
482 *descriptorPool, // VkDescriptorPool descriptorPool
483 1u, // uint32_t descriptorSetCount
484 &*descriptorSetLayout // const VkDescriptorSetLayout* pSetLayouts
485 };
486
487 VK_CHECK(vk.allocateDescriptorSets(device, &allocInfo, &descriptorSet));
488 }
489
490 const VkWriteDescriptorSet descriptorWrite =
491 {
492 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType
493 DE_NULL, // const void* pNext
494 descriptorSet, // VkDescriptorSet dstSet
495 0u, // deUint32 dstBinding
496 0u, // deUint32 dstArrayElement
497 3u, // deUint32 descriptorCount
498 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, // VkDescriptorType descriptorType
499 DE_NULL, // const VkDescriptorImageInfo pImageInfo
500 descriptorBufferInfos, // const VkDescriptorBufferInfo* pBufferInfo
501 DE_NULL // const VkBufferView* pTexelBufferView
502 };
503
504 const VkWriteDescriptorSet descriptorWriteResult =
505 {
506 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType
507 DE_NULL, // const void* pNext
508 descriptorSet, // VkDescriptorSet dstSet
509 2u, // deUint32 dstBinding
510 0u, // deUint32 dstArrayElement
511 1u, // deUint32 descriptorCount
512 VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, // VkDescriptorType descriptorType
513 DE_NULL, // const VkDescriptorImageInfo pImageInfo
514 &descriptorBufferInfoResult, // const VkDescriptorBufferInfo* pBufferInfo
515 DE_NULL // const VkBufferView* pTexelBufferView
516 };
517
518 const VkCommandPoolCreateInfo cmdPoolInfo =
519 {
520 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType Stype
521 DE_NULL, // const void* PNext
522 DE_NULL, // VkCommandPoolCreateFlags flags
523 queueFamilyIndex, // uint32_t queuefamilyindex
524 };
525
526 const Unique<VkCommandPool> cmdPool(createCommandPool(vk, device, &cmdPoolInfo));
527
528 const VkCommandBufferAllocateInfo cmdBufParams =
529 {
530 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
531 DE_NULL, // const void* pNext;
532 *cmdPool, // VkCommandPool pool;
533 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
534 1u, // uint32_t bufferCount;
535 };
536
537 const Unique<VkCommandBuffer> cmdBuf(allocateCommandBuffer(vk, device, &cmdBufParams));
538
539 const VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
540 {
541 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType
542 DE_NULL, // const void* pNext
543 0, // VkPipelineLayoutCreateFlags flags
544 1u, // uint32_t setLayoutCount
545 &*descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts
546 0u, // uint32_t pushConstantRangeCount
547 nullptr // const VkPushConstantRange* pPushConstantRanges
548 };
549
550 Move<VkPipelineLayout> pipelineLayout(createPipelineLayout(vk, device, &pipelineLayoutCreateInfo));
551
552 const VkPipelineShaderStageCreateInfo shaderStageCreateInfo =
553 {
554 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
555 DE_NULL, // const void* pNext;
556 (VkPipelineShaderStageCreateFlags)0, // VkPipelineShaderStageCreateFlags flags;
557 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
558 computeShaderModule.get(), // VkShaderModule shader;
559 "main", // const char* pName;
560 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
561 };
562
563 const VkComputePipelineCreateInfo computePipelineCreateInfo =
564 {
565 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType
566 DE_NULL, // const void* pNext
567 (VkPipelineCreateFlags)0, // VkPipelineCreateFlags flags
568 shaderStageCreateInfo, // VkPipelineShaderStageCreateInfo stage
569 *pipelineLayout, // VkPipelineLayout layout
570 DE_NULL, // VkPipeline basePipelineHandle
571 0 // int basePipelineIndex
572 };
573
574 Unique<VkPipeline> computePipeline(createComputePipeline(vk, device, DE_NULL, &computePipelineCreateInfo));
575
576 beginCommandBuffer(vk, *cmdBuf, 0u);
577 {
578 vk.cmdBindPipeline(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *computePipeline);
579 vk.updateDescriptorSets(device, 1u, &descriptorWrite, 0u, DE_NULL);
580 vk.updateDescriptorSets(device, 1u, &descriptorWriteResult, 0u, DE_NULL);
581 vk.cmdBindDescriptorSets(*cmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, 1u, &descriptorSet, 0, nullptr);
582 flushAlloc(vk, device, buffer->getAllocation());
583 vk.cmdDispatch(*cmdBuf, 1u, 1u, 1u);
584 }
585
586 endCommandBuffer(vk, *cmdBuf);
587 submitCommandsAndWait(vk, device, queue, *cmdBuf);
588
589 const Allocation& bufferAllocationResult = resultBuffer->getAllocation();
590 invalidateAlloc(vk, device, bufferAllocationResult);
591
592 const deUint32* resultPtr = static_cast<deUint32*>(bufferAllocationResult.getHostPtr());
593
594 if (resultPtr[0] == 5 && resultPtr[1] == 5 && resultPtr[2] == 5)
595 return tcu::TestStatus::pass("Pass");
596 else
597 return tcu::TestStatus::fail("Fail");
598 }
599 } // anonymous
600
createDescriptorSetLayoutLifetimeGraphicsSource(SourceCollections & dst)601 void createDescriptorSetLayoutLifetimeGraphicsSource (SourceCollections& dst)
602 {
603 dst.glslSources.add("vertex") << glu::VertexSource(
604 "#version 310 es\n"
605 "void main (void)\n"
606 "{\n"
607 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
608 "}\n");
609 }
610
createDescriptorSetLayoutLifetimeComputeSource(SourceCollections & dst)611 void createDescriptorSetLayoutLifetimeComputeSource (SourceCollections& dst)
612 {
613 dst.glslSources.add("compute") << glu::ComputeSource(
614 "#version 310 es\n"
615 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
616 "void main (void)\n"
617 "{\n"
618 "}\n");
619 }
620
createDescriptorSetLayoutBindingOrderingSource(SourceCollections & dst)621 void createDescriptorSetLayoutBindingOrderingSource (SourceCollections& dst)
622 {
623 dst.glslSources.add("compute") << glu::ComputeSource(
624 "#version 310 es\n"
625 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
626 "layout (set = 0, binding = 0) uniform UniformBuffer0 {\n"
627 " int data;\n"
628 "} uniformbufferarray[2];\n"
629 "layout (set = 0, binding = 1) uniform UniformBuffer2 {\n"
630 " int data;\n"
631 "} uniformbuffer2;\n"
632 "layout (set = 0, binding = 2) buffer StorageBuffer {\n"
633 " int result0;\n"
634 " int result1;\n"
635 " int result2;\n"
636 "} results;\n"
637 "\n"
638 "void main (void)\n"
639 "{\n"
640 " results.result0 = uniformbufferarray[0].data;\n"
641 " results.result1 = uniformbufferarray[1].data;\n"
642 " results.result2 = uniformbuffer2.data;\n"
643 "}\n");
644 }
645
createDescriptorSetLayoutLifetimeTests(tcu::TestContext & testCtx)646 tcu::TestCaseGroup* createDescriptorSetLayoutLifetimeTests (tcu::TestContext& testCtx)
647 {
648 de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutLifetimeTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout_lifetime", "Descriptor set layout lifetime tests"));
649
650 addFunctionCaseWithPrograms(descriptorSetLayoutLifetimeTests.get(), "graphics", "Test descriptor set layout lifetime in graphics pipeline", createDescriptorSetLayoutLifetimeGraphicsSource, descriptorSetLayoutLifetimeGraphicsTest);
651 addFunctionCaseWithPrograms(descriptorSetLayoutLifetimeTests.get(), "compute", "Test descriptor set layout lifetime in compute pipeline", createDescriptorSetLayoutLifetimeComputeSource, descriptorSetLayoutLifetimeComputeTest);
652
653 return descriptorSetLayoutLifetimeTests.release();
654 }
655
createEmptyDescriptorSetLayoutTests(tcu::TestContext & testCtx)656 tcu::TestCaseGroup* createEmptyDescriptorSetLayoutTests (tcu::TestContext& testCtx)
657 {
658 de::MovePtr<tcu::TestCaseGroup> emptyDescriptorSetLayoutTests(new tcu::TestCaseGroup(testCtx, "empty_set", "Create empty descriptor set layout tests"));
659
660 addFunctionCase(emptyDescriptorSetLayoutTests.get(), "normal", "Create empty desciptor set layout", emptyDescriptorSetLayoutTest, (VkDescriptorSetLayoutCreateFlags)0u);
661 addFunctionCase(emptyDescriptorSetLayoutTests.get(), "push_descriptor", "Create empty push descriptor set layout", emptyDescriptorSetLayoutTest, (VkDescriptorSetLayoutCreateFlags)VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR);
662
663 return emptyDescriptorSetLayoutTests.release();
664 }
665
createDescriptorSetLayoutBindingOrderingTests(tcu::TestContext & testCtx)666 tcu::TestCaseGroup* createDescriptorSetLayoutBindingOrderingTests (tcu::TestContext& testCtx)
667 {
668 de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutBindingOrderingTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout_binding", "Create descriptor set layout ordering tests"));
669 addFunctionCaseWithPrograms(descriptorSetLayoutBindingOrderingTests.get(), "update_subsequent_binding", "Test subsequent binding update with remaining elements", createDescriptorSetLayoutBindingOrderingSource, descriptorSetLayoutBindingOrderingTest);
670
671 static const char dataDir[] = "api/descriptor_set/descriptor_set_layout_binding";
672 descriptorSetLayoutBindingOrderingTests->addChild(cts_amber::createAmberTestCase(testCtx, "layout_binding_order", "Test descriptor set layout binding order", dataDir, "layout_binding_order.amber"));
673
674 return descriptorSetLayoutBindingOrderingTests.release();
675 }
676
createDescriptorSetLayoutTests(tcu::TestContext & testCtx)677 tcu::TestCaseGroup* createDescriptorSetLayoutTests (tcu::TestContext& testCtx)
678 {
679 de::MovePtr<tcu::TestCaseGroup> descriptorSetLayoutTests(new tcu::TestCaseGroup(testCtx, "descriptor_set_layout", "Descriptor set layout tests"));
680
681 descriptorSetLayoutTests->addChild(createEmptyDescriptorSetLayoutTests(testCtx));
682
683 return descriptorSetLayoutTests.release();
684 }
685
createDescriptorSetTests(tcu::TestContext & testCtx)686 tcu::TestCaseGroup* createDescriptorSetTests (tcu::TestContext& testCtx)
687 {
688 de::MovePtr<tcu::TestCaseGroup> descriptorSetTests(new tcu::TestCaseGroup(testCtx, "descriptor_set", "Descriptor set tests"));
689
690 descriptorSetTests->addChild(createDescriptorSetLayoutLifetimeTests(testCtx));
691 descriptorSetTests->addChild(createDescriptorSetLayoutTests(testCtx));
692 descriptorSetTests->addChild(createDescriptorSetLayoutBindingOrderingTests(testCtx));
693
694 return descriptorSetTests.release();
695 }
696
697 } // api
698 } // vkt
699