1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Copyright (c) 2015 Google Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 *//*--------------------------------------------------------------------*/
23 #include "vktApiBufferComputeInstance.hpp"
24 #include "vktApiComputeInstanceResultBuffer.hpp"
25 #include "vkRefUtil.hpp"
26 #include "vkBuilderUtil.hpp"
27 #include "vkTypeUtil.hpp"
36 Move<VkBuffer> createDataBuffer (vkt::Context& context,
40 deUint32 initDataSize,
42 de::MovePtr<Allocation>* outAllocation)
44 const DeviceInterface& vki = context.getDeviceInterface();
45 const VkDevice device = context.getDevice();
46 Allocator& allocator = context.getDefaultAllocator();
48 DE_ASSERT(offset + initDataSize <= bufferSize);
50 const VkBufferUsageFlags usageFlags = (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
51 const VkBufferCreateInfo createInfo =
53 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
56 (VkDeviceSize)bufferSize, // size
58 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
59 0u, // queueFamilyCount
60 DE_NULL, // pQueueFamilyIndices
62 Move<VkBuffer> buffer(createBuffer(vki, device, &createInfo));
64 const VkMemoryRequirements requirements = getBufferMemoryRequirements(vki, device, *buffer);
65 de::MovePtr<Allocation> allocation = allocator.allocate(requirements, MemoryRequirement::HostVisible);
67 VK_CHECK(vki.bindBufferMemory(device, *buffer, allocation->getMemory(), allocation->getOffset()));
69 void* const mapPtr = allocation->getHostPtr();
72 deMemset(mapPtr, uninitData, (size_t)offset);
74 deMemset((deUint8 *)mapPtr + offset, initData, initDataSize);
75 deMemset((deUint8 *)mapPtr + offset + initDataSize, uninitData,
76 (size_t)bufferSize - (size_t)offset - initDataSize);
78 flushMappedMemoryRange(vki, device, allocation->getMemory(), allocation->getOffset(), bufferSize);
80 *outAllocation = allocation;
84 Move<VkBuffer> createColorDataBuffer (deUint32 offset,
86 const tcu::Vec4& color1,
87 const tcu::Vec4& color2,
88 de::MovePtr<Allocation>* outAllocation,
89 vkt::Context& context)
91 const DeviceInterface& vki = context.getDeviceInterface();
92 const VkDevice device = context.getDevice();
93 Allocator& allocator = context.getDefaultAllocator();
95 DE_ASSERT(offset + sizeof(tcu::Vec4[2]) <= bufferSize);
97 const VkBufferUsageFlags usageFlags = (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
98 const VkBufferCreateInfo createInfo =
100 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
103 (VkDeviceSize) bufferSize, // size
105 VK_SHARING_MODE_EXCLUSIVE, // sharingMode
106 0u, // queueFamilyCount
107 DE_NULL, // pQueueFamilyIndices
109 Move<VkBuffer> buffer(createBuffer(vki, device, &createInfo));
111 const VkMemoryRequirements requirements = getBufferMemoryRequirements(vki, device, *buffer);
112 de::MovePtr<Allocation> allocation = allocator.allocate(requirements, MemoryRequirement::HostVisible);
114 VK_CHECK(vki.bindBufferMemory(device, *buffer, allocation->getMemory(), allocation->getOffset()));
116 void* mapPtr = allocation->getHostPtr();
119 deMemset(mapPtr, 0x5A, (size_t) offset);
121 deMemcpy((deUint8 *) mapPtr + offset, color1.getPtr(), sizeof(tcu::Vec4));
122 deMemcpy((deUint8 *) mapPtr + offset + sizeof(tcu::Vec4), color2.getPtr(), sizeof(tcu::Vec4));
123 deMemset((deUint8 *) mapPtr + offset + 2 * sizeof(tcu::Vec4), 0x5A,
124 (size_t) bufferSize - (size_t) offset - 2 * sizeof(tcu::Vec4));
126 flushMappedMemoryRange(vki, device, allocation->getMemory(), allocation->getOffset(), bufferSize);
128 *outAllocation = allocation;
132 Move<VkDescriptorSetLayout> createDescriptorSetLayout (vkt::Context& context)
135 const DeviceInterface& vki = context.getDeviceInterface();
136 const VkDevice device = context.getDevice();
138 DescriptorSetLayoutBuilder builder;
140 builder.addSingleBinding(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT);
141 builder.addSingleBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_COMPUTE_BIT);
143 return builder.build(vki, device);
146 Move<VkDescriptorPool> createDescriptorPool (vkt::Context& context)
148 const DeviceInterface& vki = context.getDeviceInterface();
149 const VkDevice device = context.getDevice();
151 return vk::DescriptorPoolBuilder()
152 .addType(vk::VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
153 .addType(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,1u)
154 .build(vki, device, vk::VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 1);
157 Move<VkDescriptorSet> createDescriptorSet (vkt::Context& context,
158 VkDescriptorPool pool,
159 VkDescriptorSetLayout layout,
164 const DeviceInterface& vki = context.getDeviceInterface();
165 const VkDevice device = context.getDevice();
167 const vk::VkDescriptorBufferInfo resultInfo = makeDescriptorBufferInfo(resBuf, 0u, (vk::VkDeviceSize) ComputeInstanceResultBuffer::DATA_SIZE);
168 const vk::VkDescriptorBufferInfo bufferInfo = makeDescriptorBufferInfo(buffer, (vk::VkDeviceSize)offset, (vk::VkDeviceSize)sizeof(tcu::Vec4[2]));
170 const vk::VkDescriptorSetAllocateInfo allocInfo =
172 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
178 vk::Move<vk::VkDescriptorSet> descriptorSet = allocateDescriptorSet(vki, device, &allocInfo);
180 DescriptorSetUpdateBuilder builder;
183 builder.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &resultInfo);
186 builder.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &bufferInfo);
188 builder.update(vki, device);
189 return descriptorSet;
192 Move<VkDescriptorSet> createDescriptorSet (VkDescriptorPool pool,
193 VkDescriptorSetLayout layout,
199 vkt::Context& context)
201 const DeviceInterface& vki = context.getDeviceInterface();
202 const VkDevice device = context.getDevice();
204 const vk::VkDescriptorBufferInfo resultInfo = makeDescriptorBufferInfo(resBuf, 0u, (vk::VkDeviceSize) ComputeInstanceResultBuffer::DATA_SIZE);
205 const vk::VkDescriptorBufferInfo bufferInfos[2] =
207 vk::makeDescriptorBufferInfo(viewA, (vk::VkDeviceSize)offsetA, (vk::VkDeviceSize)sizeof(tcu::Vec4[2])),
208 vk::makeDescriptorBufferInfo(viewB, (vk::VkDeviceSize)offsetB, (vk::VkDeviceSize)sizeof(tcu::Vec4[2])),
211 const vk::VkDescriptorSetAllocateInfo allocInfo =
213 vk::VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
219 vk::Move<vk::VkDescriptorSet> descriptorSet = allocateDescriptorSet(vki, device, &allocInfo);
221 DescriptorSetUpdateBuilder builder;
224 builder.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(0u), VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, &resultInfo);
227 builder.writeSingle(*descriptorSet, DescriptorSetUpdateBuilder::Location::binding(1u), VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, &bufferInfos[0]);
229 builder.update(vki, device);
230 return descriptorSet;