Test updating set with an empty binding
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / binding_model / vktBindingDescriptorUpdateTests.cpp
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 Tests for descriptor updates.
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktBindingDescriptorUpdateTests.hpp"
25
26 #include "vktTestCase.hpp"
27 #include "vktTestCaseUtil.hpp"
28
29 #include "vkRefUtil.hpp"
30 #include "vkMemUtil.hpp"
31 #include "vkBuilderUtil.hpp"
32 #include "vkQueryUtil.hpp"
33
34 namespace vkt
35 {
36 namespace BindingModel
37 {
38 namespace
39 {
40
41 // Test matches VkPositiveLayerTest.EmptyDescriptorUpdateTest
42 tcu::TestStatus EmptyDescriptorUpdateCase (Context& context)
43 {
44         const vk::DeviceInterface&                              vki                                     = context.getDeviceInterface();
45         const vk::VkDevice                                              device                          = context.getDevice();
46         vk::Allocator&                                                  allocator                       = context.getDefaultAllocator();
47
48         // Create layout with two uniform buffer descriptors w/ empty binding between them
49         vk::DescriptorSetLayoutBuilder                  builder;
50
51         builder.addSingleBinding(vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, vk::VK_SHADER_STAGE_ALL);
52         builder.addBinding(vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, (vk::VkShaderStageFlags)0, DE_NULL);
53         builder.addSingleBinding(vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, vk::VK_SHADER_STAGE_ALL);
54
55         vk::Unique<vk::VkDescriptorSetLayout>   layout                          (builder.build(vki, device, (vk::VkDescriptorSetLayoutCreateFlags)0));
56
57         // Create descriptor pool
58         vk::Unique<vk::VkDescriptorPool>                descriptorPool          (vk::DescriptorPoolBuilder().addType(vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 2).build(vki, device, vk::VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1));
59
60         // Create descriptor set
61         const vk::VkDescriptorSetAllocateInfo   setAllocateInfo         =
62         {
63                 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,     // VkStructureType                              sType
64                 DE_NULL,                                                                                        // const void*                                  pNext
65                 *descriptorPool,                                                                        // VkDescriptorPool                             descriptorPool
66                 1,                                                                                                      // deUint32                                             descriptorSetCount
67                 &layout.get()                                                                           // const VkDescriptorSetLayout* pSetLayouts
68         };
69
70         vk::Unique<vk::VkDescriptorSet>                 descriptorSet           (allocateDescriptorSet(vki, device, &setAllocateInfo));
71
72         // Create a buffer to be used for update
73         const vk::VkBufferCreateInfo                    bufferCreateInfo        =
74         {
75                 vk::VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,       // VkStructureType              sType
76                 DE_NULL,                                                                        // const void*                  pNext
77                 (vk::VkBufferCreateFlags)DE_NULL,                       // VkBufferCreateFlags  flags
78                 256,                                                                            // VkDeviceSize                 size
79                 vk::VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,         // VkBufferUsageFlags   usage
80                 vk::VK_SHARING_MODE_EXCLUSIVE,                          // VkSharingMode                sharingMode
81                 0,                                                                                      // deUint32                             queueFamilyIndexCount
82                 DE_NULL                                                                         // const deUint32*              pQueueFamilyIndices
83         };
84
85         vk::Unique<vk::VkBuffer>                                buffer                          (createBuffer(vki, device, &bufferCreateInfo));
86         const vk::VkMemoryRequirements                  requirements            = vk::getBufferMemoryRequirements(vki, device, *buffer);
87         de::MovePtr<vk::Allocation>                             allocation                      = allocator.allocate(requirements, vk::MemoryRequirement::Any);
88
89         VK_CHECK(vki.bindBufferMemory(device, *buffer, allocation->getMemory(), allocation->getOffset()));
90
91         // Only update the descriptor at binding 2
92         const vk::VkDescriptorBufferInfo                descriptorInfo          =
93         {
94                 *buffer,                // VkBuffer             buffer
95                 0,                              // VkDeviceSize offset
96                 VK_WHOLE_SIZE   // VkDeviceSize range
97         };
98
99         const vk::VkWriteDescriptorSet                  descriptorWrite         =
100         {
101                 vk::VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,     // VkStructureTypes                                     Type
102                 DE_NULL,                                                                        // const void*                                          pNext
103                 *descriptorSet,                                                         // VkDescriptorSet                                      dstSet
104                 2,                                                                                      // deUint32                                                     dstBinding
105                 0,                                                                                      // deUint32                                                     dstArrayElement
106                 1,                                                                                      // deUint32                                                     descriptorCount
107                 vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,          // VkDescriptorType                                     descriptorType
108                 DE_NULL,                                                                        // const VkDescriptorImageInfo*         pImageInfo
109                 &descriptorInfo,                                                        // const VkDescriptorBufferInfo*        pBufferInfo
110                 DE_NULL                                                                         // const VkBufferView*                          pTexelBufferView
111         };
112
113         vki.updateDescriptorSets(device, 1, &descriptorWrite, 0, DE_NULL);
114
115         // Test should always pass
116         return tcu::TestStatus::pass("Pass");
117 }
118
119
120 tcu::TestCaseGroup* createEmptyDescriptorUpdateTests (tcu::TestContext& testCtx)
121 {
122         de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "empty_descriptor", "Update last descriptor in a set that includes an empty binding"));
123
124         addFunctionCase(group.get(), "uniform_buffer", "", EmptyDescriptorUpdateCase);
125
126         return group.release();
127 }
128
129 } // anonymous
130
131
132 tcu::TestCaseGroup* createDescriptorUpdateTests (tcu::TestContext& testCtx)
133 {
134         de::MovePtr<tcu::TestCaseGroup> group(new tcu::TestCaseGroup(testCtx, "descriptor_update", "Update descriptor sets"));
135
136         group->addChild(createEmptyDescriptorUpdateTests(testCtx));
137
138         return group.release();
139 }
140
141 } // BindingModel
142 } // vkt