1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Platform Synchronization tests
22 *//*--------------------------------------------------------------------*/
24 #include "vktSynchronizationSmokeTests.hpp"
26 #include "vktTestCaseUtil.hpp"
28 #include "vkPlatform.hpp"
29 #include "vkStrUtil.hpp"
31 #include "vkRefUtil.hpp"
32 #include "vkDeviceUtil.hpp"
33 #include "vkCmdUtil.hpp"
35 #include "tcuTestLog.hpp"
36 #include "tcuFormatUtil.hpp"
38 #include "deUniquePtr.hpp"
39 #include "deThread.hpp"
40 #include "vkMemUtil.hpp"
41 #include "vkQueryUtil.hpp"
42 #include "vkPrograms.hpp"
43 #include "vkTypeUtil.hpp"
44 #include "vkCmdUtil.hpp"
50 namespace synchronization
65 static const deUint64 DEFAULT_TIMEOUT = 2ull*1000*1000*1000; //!< 2 seconds in nanoseconds
67 void buildShaders (SourceCollections& shaderCollection)
69 shaderCollection.glslSources.add("glslvert") <<
72 "precision mediump float;\n"
73 "layout (location = 0) in vec4 vertexPosition;\n"
76 " gl_Position = vertexPosition;\n"
79 shaderCollection.glslSources.add("glslfrag") <<
82 "precision mediump float;\n"
83 "layout (location = 0) out vec4 outputColor;\n"
86 " outputColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
90 Move<VkDevice> createTestDevice (const PlatformInterface& vkp, VkInstance instance, const InstanceInterface& vki, VkPhysicalDevice physicalDevice, deUint32 *outQueueFamilyIndex)
92 VkDeviceQueueCreateInfo queueInfo;
93 VkDeviceCreateInfo deviceInfo;
95 const deUint32 queueCount = 2u;
96 const float queuePriority[queueCount] = { 1.0f, 1.0f };
98 const vector<VkQueueFamilyProperties> queueProps = getPhysicalDeviceQueueFamilyProperties(vki, physicalDevice);
99 const VkPhysicalDeviceFeatures physicalDeviceFeatures = getPhysicalDeviceFeatures(vki, physicalDevice);
101 for (queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
103 if ((queueProps[queueNdx].queueFlags & VK_QUEUE_GRAPHICS_BIT) == VK_QUEUE_GRAPHICS_BIT && (queueProps[queueNdx].queueCount >= queueCount))
107 if (queueNdx >= queueProps.size())
109 // No queue family index found
110 std::ostringstream msg;
111 msg << "Cannot create device with " << queueCount << " graphics queues";
113 throw tcu::NotSupportedError(msg.str());
116 deMemset(&queueInfo, 0, sizeof(queueInfo));
117 deMemset(&deviceInfo, 0, sizeof(deviceInfo));
119 deMemset(&queueInfo, 0xcd, sizeof(queueInfo));
120 queueInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
121 queueInfo.pNext = DE_NULL;
122 queueInfo.flags = (VkDeviceQueueCreateFlags)0u;
123 queueInfo.queueFamilyIndex = (deUint32)queueNdx;
124 queueInfo.queueCount = queueCount;
125 queueInfo.pQueuePriorities = queuePriority;
127 deMemset(&deviceInfo, 0xcd, sizeof(deviceInfo));
128 deviceInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
129 deviceInfo.pNext = DE_NULL;
130 deviceInfo.flags = (VkDeviceCreateFlags)0u;
131 deviceInfo.queueCreateInfoCount = 1u;
132 deviceInfo.pQueueCreateInfos = &queueInfo;
133 deviceInfo.enabledExtensionCount = 0u;
134 deviceInfo.ppEnabledExtensionNames = DE_NULL;
135 deviceInfo.enabledLayerCount = 0u;
136 deviceInfo.ppEnabledLayerNames = DE_NULL;
137 deviceInfo.pEnabledFeatures = &physicalDeviceFeatures;
139 *outQueueFamilyIndex = queueInfo.queueFamilyIndex;
141 return createDevice(vkp, instance, vki, physicalDevice, &deviceInfo);
144 struct BufferParameters
148 VkBufferUsageFlags usage;
149 VkSharingMode sharingMode;
150 deUint32 queueFamilyCount;
151 const deUint32* queueFamilyIndex;
152 VkAccessFlags inputBarrierFlags;
157 MovePtr<Allocation> allocation;
158 vector<VkMemoryBarrier> memoryBarrier;
159 vk::Move<VkBuffer> buffer;
162 void createVulkanBuffer (const DeviceInterface& vkd, VkDevice device, Allocator& allocator, const BufferParameters& bufferParameters, Buffer& buffer, MemoryRequirement visibility)
164 VkBufferCreateInfo bufferCreateParams;
166 deMemset(&bufferCreateParams, 0xcd, sizeof(bufferCreateParams));
167 bufferCreateParams.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
168 bufferCreateParams.pNext = DE_NULL;
169 bufferCreateParams.flags = 0;
170 bufferCreateParams.size = bufferParameters.size;
171 bufferCreateParams.usage = bufferParameters.usage;
172 bufferCreateParams.sharingMode = bufferParameters.sharingMode;
173 bufferCreateParams.queueFamilyIndexCount = bufferParameters.queueFamilyCount;
174 bufferCreateParams.pQueueFamilyIndices = bufferParameters.queueFamilyIndex;
176 buffer.buffer = createBuffer(vkd, device, &bufferCreateParams);
177 buffer.allocation = allocator.allocate(getBufferMemoryRequirements(vkd, device, *buffer.buffer), visibility);
179 VK_CHECK(vkd.bindBufferMemory(device, *buffer.buffer, buffer.allocation->getMemory(), buffer.allocation->getOffset()));
181 // If caller provides a host memory buffer for the allocation, then go
182 // ahead and copy the provided data into the allocation and update the
183 // barrier list with the associated access
184 if (bufferParameters.memory != DE_NULL)
186 VkMemoryBarrier barrier;
188 deMemcpy(buffer.allocation->getHostPtr(), bufferParameters.memory, (size_t)bufferParameters.size);
189 flushAlloc(vkd, device, *buffer.allocation);
191 deMemset(&barrier, 0xcd, sizeof(barrier));
192 barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
193 barrier.pNext = DE_NULL;
194 barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
195 barrier.dstAccessMask = bufferParameters.inputBarrierFlags;
197 buffer.memoryBarrier.push_back(barrier);
201 struct ImageParameters
203 VkImageType imageType;
207 VkSampleCountFlagBits samples;
208 VkImageTiling tiling;
209 VkBufferUsageFlags usage;
210 VkSharingMode sharingMode;
211 deUint32 queueFamilyCount;
212 const deUint32* queueFamilyNdxList;
213 VkImageLayout initialLayout;
214 VkImageLayout finalLayout;
215 VkAccessFlags barrierInputMask;
220 vk::Move<VkImage> image;
221 vk::Move<VkImageView> imageView;
222 MovePtr<Allocation> allocation;
223 vector<VkImageMemoryBarrier> imageMemoryBarrier;
226 void createVulkanImage (const DeviceInterface& vkd, VkDevice device, Allocator& allocator, const ImageParameters& imageParameters, Image& image, MemoryRequirement visibility)
228 VkComponentMapping componentMap;
229 VkImageSubresourceRange subresourceRange;
230 VkImageViewCreateInfo imageViewCreateInfo;
231 VkImageCreateInfo imageCreateParams;
232 VkImageMemoryBarrier imageBarrier;
234 deMemset(&imageCreateParams, 0xcd, sizeof(imageCreateParams));
235 imageCreateParams.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
236 imageCreateParams.pNext = DE_NULL;
237 imageCreateParams.flags = 0;
238 imageCreateParams.imageType = imageParameters.imageType;
239 imageCreateParams.format = imageParameters.format;
240 imageCreateParams.extent = imageParameters.extent3D;
241 imageCreateParams.mipLevels = imageParameters.mipLevels;
242 imageCreateParams.arrayLayers = 1;
243 imageCreateParams.samples = imageParameters.samples;
244 imageCreateParams.tiling = imageParameters.tiling;
245 imageCreateParams.usage = imageParameters.usage;
246 imageCreateParams.sharingMode = imageParameters.sharingMode;
247 imageCreateParams.queueFamilyIndexCount = imageParameters.queueFamilyCount;
248 imageCreateParams.pQueueFamilyIndices = imageParameters.queueFamilyNdxList;
249 imageCreateParams.initialLayout = imageParameters.initialLayout;
251 image.image = createImage(vkd, device, &imageCreateParams);
252 image.allocation = allocator.allocate(getImageMemoryRequirements(vkd, device, *image.image), visibility);
254 VK_CHECK(vkd.bindImageMemory(device, *image.image, image.allocation->getMemory(), image.allocation->getOffset()));
256 componentMap.r = VK_COMPONENT_SWIZZLE_R;
257 componentMap.g = VK_COMPONENT_SWIZZLE_G;
258 componentMap.b = VK_COMPONENT_SWIZZLE_B;
259 componentMap.a = VK_COMPONENT_SWIZZLE_A;
261 subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
262 subresourceRange.baseMipLevel = 0;
263 subresourceRange.levelCount = imageParameters.mipLevels;
264 subresourceRange.baseArrayLayer = 0;
265 subresourceRange.layerCount = 1;
267 deMemset(&imageViewCreateInfo, 0xcd, sizeof(imageViewCreateInfo));
268 imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
269 imageViewCreateInfo.pNext = DE_NULL;
270 imageViewCreateInfo.flags = 0;
271 imageViewCreateInfo.image = image.image.get();
272 imageViewCreateInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
273 imageViewCreateInfo.format = imageParameters.format;
274 imageViewCreateInfo.components = componentMap;
275 imageViewCreateInfo.subresourceRange = subresourceRange;
277 image.imageView = createImageView(vkd, device, &imageViewCreateInfo);
279 deMemset(&imageBarrier, 0xcd, sizeof(imageBarrier));
280 imageBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
281 imageBarrier.pNext = DE_NULL;
282 imageBarrier.srcAccessMask = 0;
283 imageBarrier.dstAccessMask = imageParameters.barrierInputMask;
284 imageBarrier.oldLayout = imageParameters.initialLayout;
285 imageBarrier.newLayout = imageParameters.finalLayout;
286 imageBarrier.srcQueueFamilyIndex = imageParameters.queueFamilyNdxList[0];
287 imageBarrier.dstQueueFamilyIndex = imageParameters.queueFamilyNdxList[imageParameters.queueFamilyCount-1];
288 imageBarrier.image = image.image.get();
289 imageBarrier.subresourceRange = subresourceRange;
291 image.imageMemoryBarrier.push_back(imageBarrier);
294 struct RenderPassParameters
296 VkFormat colorFormat;
297 VkSampleCountFlagBits colorSamples;
300 void createColorOnlyRenderPass (const DeviceInterface& vkd, VkDevice device, const RenderPassParameters& renderPassParameters, vk::Move<VkRenderPass>& renderPass)
302 VkAttachmentDescription colorAttachmentDesc;
303 VkAttachmentReference colorAttachmentRef;
304 VkAttachmentReference stencilAttachmentRef;
305 VkSubpassDescription subpassDesc;
306 VkRenderPassCreateInfo renderPassParams;
307 VkRenderPass newRenderPass;
309 colorAttachmentDesc.flags = 0;
310 colorAttachmentDesc.format = renderPassParameters.colorFormat;
311 colorAttachmentDesc.samples = renderPassParameters.colorSamples;
312 colorAttachmentDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
313 colorAttachmentDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
314 colorAttachmentDesc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
315 colorAttachmentDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
316 colorAttachmentDesc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
317 colorAttachmentDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
319 colorAttachmentRef.attachment = 0;
320 colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
322 stencilAttachmentRef.attachment = VK_ATTACHMENT_UNUSED;
323 stencilAttachmentRef.layout = VK_IMAGE_LAYOUT_UNDEFINED;
325 subpassDesc.flags = 0;
326 subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
327 subpassDesc.inputAttachmentCount = 0;
328 subpassDesc.pInputAttachments = DE_NULL;
329 subpassDesc.colorAttachmentCount = 1;
330 subpassDesc.pColorAttachments = &colorAttachmentRef;
331 subpassDesc.pResolveAttachments = DE_NULL;
332 subpassDesc.pDepthStencilAttachment = &stencilAttachmentRef;
333 subpassDesc.preserveAttachmentCount = 0;
334 subpassDesc.pPreserveAttachments = DE_NULL;
336 deMemset(&renderPassParams, 0xcd, sizeof(renderPassParams));
337 renderPassParams.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
338 renderPassParams.pNext = DE_NULL;
339 renderPassParams.flags = 0;
340 renderPassParams.attachmentCount = 1;
341 renderPassParams.pAttachments = &colorAttachmentDesc;
342 renderPassParams.subpassCount = 1;
343 renderPassParams.pSubpasses = &subpassDesc;
344 renderPassParams.dependencyCount = 0;
345 renderPassParams.pDependencies = DE_NULL;
347 renderPass = createRenderPass(vkd, device, &renderPassParams);
350 struct ShaderDescParams
352 VkShaderModule shaderModule;
353 VkShaderStageFlagBits stage;
364 void createVertexInfo (const vector<VertexDesc>& vertexDesc, vector<VkVertexInputBindingDescription>& bindingList, vector<VkVertexInputAttributeDescription>& attrList, VkPipelineVertexInputStateCreateInfo& vertexInputState)
366 for (vector<VertexDesc>::const_iterator vertDescIter = vertexDesc.begin(); vertDescIter != vertexDesc.end(); vertDescIter++)
368 deUint32 bindingId = 0;
369 VkVertexInputBindingDescription bindingDesc;
370 VkVertexInputAttributeDescription attrDesc;
372 bindingDesc.binding = bindingId;
373 bindingDesc.stride = vertDescIter->stride;
374 bindingDesc.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
375 bindingList.push_back(bindingDesc);
377 attrDesc.location = vertDescIter->location;
378 attrDesc.binding = bindingId;
379 attrDesc.format = vertDescIter->format;
380 attrDesc.offset = vertDescIter->offset;
381 attrList.push_back(attrDesc);
386 deMemset(&vertexInputState, 0xcd, sizeof(vertexInputState));
387 vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
388 vertexInputState.pNext = DE_NULL;
389 vertexInputState.flags = 0u;
390 vertexInputState.vertexBindingDescriptionCount = (deUint32)bindingList.size();
391 vertexInputState.pVertexBindingDescriptions = &bindingList[0];
392 vertexInputState.vertexAttributeDescriptionCount = (deUint32)attrList.size();
393 vertexInputState.pVertexAttributeDescriptions = &attrList[0];
396 void createCommandBuffer (const DeviceInterface& deviceInterface, const VkDevice device, const deUint32 queueFamilyNdx, vk::Move<VkCommandBuffer>* commandBufferRef, vk::Move<VkCommandPool>* commandPoolRef)
398 vk::Move<VkCommandPool> commandPool;
399 VkCommandBufferAllocateInfo commandBufferInfo;
400 VkCommandBuffer commandBuffer;
402 commandPool = createCommandPool(deviceInterface, device, 0u, queueFamilyNdx);
404 deMemset(&commandBufferInfo, 0xcd, sizeof(commandBufferInfo));
405 commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
406 commandBufferInfo.pNext = DE_NULL;
407 commandBufferInfo.commandPool = commandPool.get();
408 commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
409 commandBufferInfo.commandBufferCount = 1;
411 VK_CHECK(deviceInterface.allocateCommandBuffers(device, &commandBufferInfo, &commandBuffer));
412 *commandBufferRef = vk::Move<VkCommandBuffer>(vk::check<VkCommandBuffer>(commandBuffer), Deleter<VkCommandBuffer>(deviceInterface, device, commandPool.get()));
413 *commandPoolRef = commandPool;
416 void createFences (const DeviceInterface& deviceInterface, VkDevice device, bool signaled, deUint32 numFences, VkFence* fence)
418 VkFenceCreateInfo fenceState;
419 VkFenceCreateFlags signalFlag = signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0;
421 deMemset(&fenceState, 0xcd, sizeof(fenceState));
422 fenceState.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
423 fenceState.pNext = DE_NULL;
424 fenceState.flags = signalFlag;
426 for (deUint32 ndx = 0; ndx < numFences; ndx++)
427 VK_CHECK(deviceInterface.createFence(device, &fenceState, DE_NULL, &fence[ndx]));
430 void destroyFences (const DeviceInterface& deviceInterface, VkDevice device, deUint32 numFences, VkFence* fence)
432 for (deUint32 ndx = 0; ndx < numFences; ndx++)
433 deviceInterface.destroyFence(device, fence[ndx], DE_NULL);
440 deUint32 vertexBufferSize;
441 VkBuffer vertexBuffer;
443 VkCommandBuffer commandBuffer;
444 VkRenderPass renderPass;
445 VkFramebuffer framebuffer;
448 const deUint32* queueFamilyNdxList;
449 deUint32 queueFamilyNdxCount;
452 vector<VkImageMemoryBarrier>* barriers;
455 void recordRenderPass (const DeviceInterface& deviceInterface, const RenderInfo& renderInfo)
457 const VkDeviceSize bindingOffset = 0;
458 VkImageMemoryBarrier renderBarrier;
460 if (renderInfo.waitEvent)
461 deviceInterface.cmdWaitEvents(renderInfo.commandBuffer, 1, &renderInfo.event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, DE_NULL, 0, DE_NULL, 0, DE_NULL);
463 beginRenderPass(deviceInterface, renderInfo.commandBuffer, renderInfo.renderPass, renderInfo.framebuffer, makeRect2D(0, 0, renderInfo.width, renderInfo.height), tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f));
464 deviceInterface.cmdBindPipeline(renderInfo.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, renderInfo.pipeline);
465 deviceInterface.cmdBindVertexBuffers(renderInfo.commandBuffer, 0u, 1u, &renderInfo.vertexBuffer, &bindingOffset);
466 deviceInterface.cmdDraw(renderInfo.commandBuffer, renderInfo.vertexBufferSize, 1, 0, 0);
467 endRenderPass(deviceInterface, renderInfo.commandBuffer);
469 deMemset(&renderBarrier, 0xcd, sizeof(renderBarrier));
470 renderBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
471 renderBarrier.pNext = DE_NULL;
472 renderBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
473 renderBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
474 renderBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
475 renderBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
476 renderBarrier.srcQueueFamilyIndex = renderInfo.queueFamilyNdxList[0];
477 renderBarrier.dstQueueFamilyIndex = renderInfo.queueFamilyNdxList[renderInfo.queueFamilyNdxCount-1];
478 renderBarrier.image = renderInfo.image;
479 renderBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
480 renderBarrier.subresourceRange.baseMipLevel = 0;
481 renderBarrier.subresourceRange.levelCount = renderInfo.mipLevels;
482 renderBarrier.subresourceRange.baseArrayLayer = 0;
483 renderBarrier.subresourceRange.layerCount = 1;
484 renderInfo.barriers->push_back(renderBarrier);
489 VkCommandBuffer commandBuffer;
496 VkOffset3D imageOffset;
497 vector<VkBufferMemoryBarrier>* barriers;
500 void copyToCPU (const DeviceInterface& vkd, TransferInfo* transferInfo)
502 VkBufferImageCopy copyState;
504 copyState.bufferOffset = 0;
505 copyState.bufferRowLength = transferInfo->width;
506 copyState.bufferImageHeight = transferInfo->height;
507 copyState.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
508 copyState.imageSubresource.mipLevel = transferInfo->mipLevel;
509 copyState.imageSubresource.baseArrayLayer = 0;
510 copyState.imageSubresource.layerCount = 1;
511 copyState.imageOffset = transferInfo->imageOffset;
512 copyState.imageExtent.width = (deInt32)(transferInfo->width);
513 copyState.imageExtent.height = (deInt32)(transferInfo->height);
514 copyState.imageExtent.depth = 1;
516 vkd.cmdCopyImageToBuffer(transferInfo->commandBuffer, transferInfo->image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, transferInfo->buffer, 1, ©State);
519 VkBufferMemoryBarrier bufferBarrier;
520 deMemset(&bufferBarrier, 0xcd, sizeof(bufferBarrier));
521 bufferBarrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
522 bufferBarrier.pNext = DE_NULL;
523 bufferBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
524 bufferBarrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
525 bufferBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
526 bufferBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
527 bufferBarrier.buffer = transferInfo->buffer;
528 bufferBarrier.offset = 0;
529 bufferBarrier.size = transferInfo->size;
530 transferInfo->barriers->push_back(bufferBarrier);
536 const DeviceInterface& vkd;
537 const VkDevice device;
538 const deUint32 queueFamilyIndex;
539 const BinaryCollection& binaryCollection;
540 Allocator& allocator;
542 const tcu::Vec4* vertices;
543 deUint32 numVertices;
544 tcu::IVec2 renderDimension;
546 VkDeviceSize renderSize;
547 MovePtr<Allocation> renderReadBuffer;
548 MovePtr<Allocation> vertexBufferAllocation;
549 vk::Move<VkBuffer> vertexBuffer;
550 vk::Move<VkBuffer> renderBuffer;
553 vk::Move<VkImage> image;
554 vk::Move<VkImageView> imageView;
555 vk::Move<VkFramebuffer> framebuffer;
556 vk::Move<VkCommandPool> commandPool;
557 vk::Move<VkCommandBuffer> cmdBuffer;
558 vk::Move<VkRenderPass> renderPass;
559 vk::Move<VkPipelineCache> pipelineCache;
560 vk::Move<VkPipeline> pipeline;
561 MovePtr<Allocation> imageAllocation;
563 TestContext (const DeviceInterface& vkd_,
564 const VkDevice device_,
565 deUint32 queueFamilyIndex_,
566 const BinaryCollection& binaryCollection_,
567 Allocator& allocator_)
570 , queueFamilyIndex (queueFamilyIndex_)
571 , binaryCollection (binaryCollection_)
572 , allocator (allocator_)
576 createFences(vkd, device, false, DE_LENGTH_OF_ARRAY(fences), fences);
581 destroyFences(vkd, device, DE_LENGTH_OF_ARRAY(fences), fences);
585 void generateWork (TestContext& testContext)
587 const DeviceInterface& deviceInterface = testContext.vkd;
588 const deUint32 queueFamilyNdx = testContext.queueFamilyIndex;
590 // \note VkShaderModule is consumed by vkCreate*Pipelines() so it can be deleted
591 // as pipeline has been constructed.
592 const vk::Unique<VkShaderModule> vertShaderModule (createShaderModule(deviceInterface,
594 testContext.binaryCollection.get("glslvert"),
595 (VkShaderModuleCreateFlags)0));
597 const vk::Unique<VkShaderModule> fragShaderModule (createShaderModule(deviceInterface,
599 testContext.binaryCollection.get("glslfrag"),
600 (VkShaderModuleCreateFlags)0));
601 const VkPipelineShaderStageCreateInfo shaderStageParams[] =
604 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
606 (VkPipelineShaderStageCreateFlags)0,
607 VK_SHADER_STAGE_VERTEX_BIT,
610 (const VkSpecializationInfo*)DE_NULL,
613 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
615 (VkPipelineShaderStageCreateFlags)0,
616 VK_SHADER_STAGE_FRAGMENT_BIT,
619 (const VkSpecializationInfo*)DE_NULL,
623 vk::Move<VkPipelineLayout> layout;
624 vector<ShaderDescParams> shaderDescParams;
625 VertexDesc vertexDesc;
626 vector<VertexDesc> vertexDescList;
627 vector<VkVertexInputAttributeDescription> attrList;
628 vector<VkBufferMemoryBarrier> bufferMemoryBarrier;
629 deUint32 memoryBarrierNdx;
630 deUint32 bufferMemoryBarrierNdx;
631 deUint32 imageMemoryBarrierNdx;
632 vector<VkVertexInputBindingDescription> bindingList;
633 VkPipelineVertexInputStateCreateInfo vertexInputState;
634 VkPipelineInputAssemblyStateCreateInfo inputAssemblyState;
635 VkPipelineDepthStencilStateCreateInfo depthStencilState;
636 VkPipelineColorBlendAttachmentState blendAttachment;
637 VkPipelineColorBlendStateCreateInfo blendState;
638 VkPipelineLayoutCreateInfo pipelineLayoutState;
639 VkGraphicsPipelineCreateInfo pipelineState;
640 VkPipelineCacheCreateInfo cacheState;
642 VkPipelineViewportStateCreateInfo viewportInfo;
644 BufferParameters bufferParameters;
646 RenderInfo renderInfo;
647 ImageParameters imageParameters;
649 VkPipelineRasterizationStateCreateInfo rasterState;
650 VkPipelineMultisampleStateCreateInfo multisampleState;
651 VkFramebufferCreateInfo fbState;
652 VkCommandBufferBeginInfo commandBufRecordState;
653 VkCommandBufferInheritanceInfo inheritanceInfo;
654 RenderPassParameters renderPassParameters;
655 TransferInfo transferInfo;
656 vector<void*> barrierList;
658 vector<VkMemoryBarrier> memoryBarriers;
659 vector<VkBufferMemoryBarrier> bufferBarriers;
660 vector<VkImageMemoryBarrier> imageBarriers;
662 memoryBarrierNdx = 0;
663 bufferMemoryBarrierNdx = 0;
664 imageMemoryBarrierNdx = 0;
665 buffer.memoryBarrier.resize(memoryBarrierNdx);
666 bufferMemoryBarrier.resize(bufferMemoryBarrierNdx);
667 image.imageMemoryBarrier.resize(imageMemoryBarrierNdx);
669 memoryBarriers.resize(0);
670 bufferBarriers.resize(0);
671 imageBarriers.resize(0);
673 bufferParameters.memory = testContext.vertices;
674 bufferParameters.size = testContext.numVertices * sizeof(tcu::Vec4);
675 bufferParameters.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
676 bufferParameters.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
677 bufferParameters.queueFamilyCount = 1;
678 bufferParameters.queueFamilyIndex = &queueFamilyNdx;
679 bufferParameters.inputBarrierFlags = VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT;
680 createVulkanBuffer(deviceInterface, testContext.device, testContext.allocator, bufferParameters, buffer, MemoryRequirement::HostVisible);
681 testContext.vertexBufferAllocation = buffer.allocation;
682 testContext.vertexBuffer = buffer.buffer;
684 bufferParameters.memory = DE_NULL;
685 bufferParameters.size = testContext.renderSize;
686 bufferParameters.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
687 bufferParameters.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
688 bufferParameters.queueFamilyCount = 1;
689 bufferParameters.queueFamilyIndex = &queueFamilyNdx;
690 bufferParameters.inputBarrierFlags = 0;
691 createVulkanBuffer(deviceInterface, testContext.device, testContext.allocator, bufferParameters, buffer, MemoryRequirement::HostVisible);
692 testContext.renderReadBuffer = buffer.allocation;
693 testContext.renderBuffer = buffer.buffer;
695 extent.width = testContext.renderDimension.x();
696 extent.height = testContext.renderDimension.y();
699 imageParameters.imageType = VK_IMAGE_TYPE_2D;
700 imageParameters.format = VK_FORMAT_R8G8B8A8_UNORM;
701 imageParameters.extent3D = extent;
702 imageParameters.mipLevels = 1;
703 imageParameters.samples = VK_SAMPLE_COUNT_1_BIT;
704 imageParameters.tiling = VK_IMAGE_TILING_OPTIMAL;
705 imageParameters.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
706 imageParameters.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
707 imageParameters.queueFamilyCount = 1;
708 imageParameters.queueFamilyNdxList = &queueFamilyNdx;
709 imageParameters.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
710 imageParameters.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
711 imageParameters.barrierInputMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
712 createVulkanImage(deviceInterface, testContext.device, testContext.allocator, imageParameters, image, MemoryRequirement::Any);
713 testContext.imageAllocation = image.allocation;
714 testContext.image = image.image;
716 for (size_t ndx = 0; ndx < image.imageMemoryBarrier.size(); ++ndx)
717 imageBarriers.push_back(image.imageMemoryBarrier[ndx]);
719 renderPassParameters.colorFormat = VK_FORMAT_R8G8B8A8_UNORM;
720 renderPassParameters.colorSamples = VK_SAMPLE_COUNT_1_BIT;
721 createColorOnlyRenderPass(deviceInterface, testContext.device, renderPassParameters, testContext.renderPass);
723 vertexDesc.location = 0;
724 vertexDesc.format = VK_FORMAT_R32G32B32A32_SFLOAT;
725 vertexDesc.stride = sizeof(tcu::Vec4);
726 vertexDesc.offset = 0;
727 vertexDescList.push_back(vertexDesc);
729 createVertexInfo(vertexDescList, bindingList, attrList, vertexInputState);
731 deMemset(&inputAssemblyState, 0xcd, sizeof(inputAssemblyState));
732 inputAssemblyState.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
733 inputAssemblyState.pNext = DE_NULL;
734 inputAssemblyState.flags = 0u;
735 inputAssemblyState.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
736 inputAssemblyState.primitiveRestartEnable = false;
740 viewport.width = (float)testContext.renderDimension.x();
741 viewport.height = (float)testContext.renderDimension.y();
742 viewport.minDepth = 0;
743 viewport.maxDepth = 1;
745 scissor.offset.x = 0;
746 scissor.offset.y = 0;
747 scissor.extent.width = testContext.renderDimension.x();
748 scissor.extent.height = testContext.renderDimension.y();
750 deMemset(&viewportInfo, 0xcd, sizeof(viewportInfo));
751 viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
752 viewportInfo.pNext = DE_NULL;
753 viewportInfo.flags = 0;
754 viewportInfo.viewportCount = 1;
755 viewportInfo.pViewports = &viewport;
756 viewportInfo.scissorCount = 1;
757 viewportInfo.pScissors = &scissor;
759 deMemset(&rasterState, 0xcd, sizeof(rasterState));
760 rasterState.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
761 rasterState.pNext = DE_NULL;
762 rasterState.flags = 0;
763 rasterState.depthClampEnable = VK_FALSE;
764 rasterState.rasterizerDiscardEnable = VK_FALSE;
765 rasterState.polygonMode = VK_POLYGON_MODE_FILL;
766 rasterState.cullMode = VK_CULL_MODE_NONE;
767 rasterState.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
768 rasterState.depthBiasEnable = VK_FALSE;
769 rasterState.lineWidth = 1;
771 deMemset(&multisampleState, 0xcd, sizeof(multisampleState));
772 multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
773 multisampleState.pNext = DE_NULL;
774 multisampleState.flags = 0;
775 multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
776 multisampleState.sampleShadingEnable = VK_FALSE;
777 multisampleState.pSampleMask = DE_NULL;
778 multisampleState.alphaToCoverageEnable = VK_FALSE;
779 multisampleState.alphaToOneEnable = VK_FALSE;
781 deMemset(&depthStencilState, 0xcd, sizeof(depthStencilState));
782 depthStencilState.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
783 depthStencilState.pNext = DE_NULL;
784 depthStencilState.flags = 0;
785 depthStencilState.depthTestEnable = VK_FALSE;
786 depthStencilState.depthWriteEnable = VK_FALSE;
787 depthStencilState.depthCompareOp = VK_COMPARE_OP_ALWAYS;
788 depthStencilState.depthBoundsTestEnable = VK_FALSE;
789 depthStencilState.stencilTestEnable = VK_FALSE;
790 depthStencilState.front.failOp = VK_STENCIL_OP_KEEP;
791 depthStencilState.front.passOp = VK_STENCIL_OP_KEEP;
792 depthStencilState.front.depthFailOp = VK_STENCIL_OP_KEEP;
793 depthStencilState.front.compareOp = VK_COMPARE_OP_ALWAYS;
794 depthStencilState.front.compareMask = 0u;
795 depthStencilState.front.writeMask = 0u;
796 depthStencilState.front.reference = 0u;
797 depthStencilState.back = depthStencilState.front;
799 deMemset(&blendAttachment, 0xcd, sizeof(blendAttachment));
800 blendAttachment.blendEnable = VK_FALSE;
801 blendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ZERO;
802 blendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
803 blendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
804 blendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
805 blendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
806 blendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
807 blendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
809 deMemset(&blendState, 0xcd, sizeof(blendState));
810 blendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
811 blendState.pNext = DE_NULL;
812 blendState.flags = 0;
813 blendState.logicOpEnable = VK_FALSE;
814 blendState.logicOp = VK_LOGIC_OP_COPY;
815 blendState.attachmentCount = 1;
816 blendState.pAttachments = &blendAttachment;
818 deMemset(&pipelineLayoutState, 0xcd, sizeof(pipelineLayoutState));
819 pipelineLayoutState.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
820 pipelineLayoutState.pNext = DE_NULL;
821 pipelineLayoutState.flags = 0;
822 pipelineLayoutState.setLayoutCount = 0;
823 pipelineLayoutState.pSetLayouts = DE_NULL;
824 pipelineLayoutState.pushConstantRangeCount = 0;
825 pipelineLayoutState.pPushConstantRanges = DE_NULL;
826 layout = createPipelineLayout(deviceInterface, testContext.device, &pipelineLayoutState, DE_NULL);
828 deMemset(&pipelineState, 0xcd, sizeof(pipelineState));
829 pipelineState.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
830 pipelineState.pNext = DE_NULL;
831 pipelineState.flags = 0;
832 pipelineState.stageCount = DE_LENGTH_OF_ARRAY(shaderStageParams);
833 pipelineState.pStages = &shaderStageParams[0];
834 pipelineState.pVertexInputState = &vertexInputState;
835 pipelineState.pInputAssemblyState = &inputAssemblyState;
836 pipelineState.pTessellationState = DE_NULL;
837 pipelineState.pViewportState = &viewportInfo;
838 pipelineState.pRasterizationState = &rasterState;
839 pipelineState.pMultisampleState = &multisampleState;
840 pipelineState.pDepthStencilState = &depthStencilState;
841 pipelineState.pColorBlendState = &blendState;
842 pipelineState.pDynamicState = (const VkPipelineDynamicStateCreateInfo*)DE_NULL;
843 pipelineState.layout = layout.get();
844 pipelineState.renderPass = testContext.renderPass.get();
845 pipelineState.subpass = 0;
846 pipelineState.basePipelineHandle = DE_NULL;
847 pipelineState.basePipelineIndex = 0;
849 deMemset(&cacheState, 0xcd, sizeof(cacheState));
850 cacheState.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
851 cacheState.pNext = DE_NULL;
852 cacheState.flags = 0;
853 cacheState.initialDataSize = 0;
854 cacheState.pInitialData = DE_NULL;
856 testContext.pipelineCache = createPipelineCache(deviceInterface, testContext.device, &cacheState);
857 testContext.pipeline = createGraphicsPipeline(deviceInterface, testContext.device, testContext.pipelineCache.get(), &pipelineState);
859 deMemset(&fbState, 0xcd, sizeof(fbState));
860 fbState.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
861 fbState.pNext = DE_NULL;
863 fbState.renderPass = testContext.renderPass.get();
864 fbState.attachmentCount = 1;
865 fbState.pAttachments = &image.imageView.get();
866 fbState.width = (deUint32)testContext.renderDimension.x();
867 fbState.height = (deUint32)testContext.renderDimension.y();
870 testContext.framebuffer = createFramebuffer(deviceInterface, testContext.device, &fbState);
871 testContext.imageView = image.imageView;
873 deMemset(&inheritanceInfo, 0xcd, sizeof(inheritanceInfo));
874 inheritanceInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
875 inheritanceInfo.pNext = DE_NULL;
876 inheritanceInfo.renderPass = testContext.renderPass.get();
877 inheritanceInfo.subpass = 0;
878 inheritanceInfo.framebuffer = *testContext.framebuffer;
879 inheritanceInfo.occlusionQueryEnable = VK_FALSE;
880 inheritanceInfo.queryFlags = 0u;
881 inheritanceInfo.pipelineStatistics = 0u;
883 deMemset(&commandBufRecordState, 0xcd, sizeof(commandBufRecordState));
884 commandBufRecordState.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
885 commandBufRecordState.pNext = DE_NULL;
886 commandBufRecordState.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
887 commandBufRecordState.pInheritanceInfo = &inheritanceInfo;
888 VK_CHECK(deviceInterface.beginCommandBuffer(testContext.cmdBuffer.get(), &commandBufRecordState));
890 deviceInterface.cmdPipelineBarrier( testContext.cmdBuffer.get(),
891 VK_PIPELINE_STAGE_HOST_BIT,
892 VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
894 (deUint32)memoryBarriers.size(), (memoryBarriers.empty() ? DE_NULL : &memoryBarriers[0]),
895 (deUint32)bufferBarriers.size(), (bufferBarriers.empty() ? DE_NULL : &bufferBarriers[0]),
896 (deUint32)imageBarriers.size(), (imageBarriers.empty() ? DE_NULL : &imageBarriers[0]));
898 memoryBarriers.resize(0);
899 bufferBarriers.resize(0);
900 imageBarriers.resize(0);
902 renderInfo.width = testContext.renderDimension.x();
903 renderInfo.height = testContext.renderDimension.y();
904 renderInfo.vertexBufferSize = testContext.numVertices;
905 renderInfo.vertexBuffer = testContext.vertexBuffer.get();
906 renderInfo.image = testContext.image.get();
907 renderInfo.commandBuffer = testContext.cmdBuffer.get();
908 renderInfo.renderPass = testContext.renderPass.get();
909 renderInfo.framebuffer = *testContext.framebuffer;
910 renderInfo.pipeline = *testContext.pipeline;
911 renderInfo.mipLevels = 1;
912 renderInfo.queueFamilyNdxList = &queueFamilyNdx;
913 renderInfo.queueFamilyNdxCount = 1;
914 renderInfo.waitEvent = testContext.waitEvent;
915 renderInfo.event = testContext.event;
916 renderInfo.barriers = &imageBarriers;
917 recordRenderPass(deviceInterface, renderInfo);
919 deviceInterface.cmdPipelineBarrier( renderInfo.commandBuffer,
920 VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
921 VK_PIPELINE_STAGE_TRANSFER_BIT,
923 (deUint32)memoryBarriers.size(), (memoryBarriers.empty() ? DE_NULL : &memoryBarriers[0]),
924 (deUint32)bufferBarriers.size(), (bufferBarriers.empty() ? DE_NULL : &bufferBarriers[0]),
925 (deUint32)imageBarriers.size(), (imageBarriers.empty() ? DE_NULL : &imageBarriers[0]));
927 memoryBarriers.resize(0);
928 bufferBarriers.resize(0);
929 imageBarriers.resize(0);
931 transferInfo.commandBuffer = renderInfo.commandBuffer;
932 transferInfo.width = testContext.renderDimension.x();
933 transferInfo.height = testContext.renderDimension.y();
934 transferInfo.image = renderInfo.image;
935 transferInfo.buffer = testContext.renderBuffer.get();
936 transferInfo.size = testContext.renderSize;
937 transferInfo.mipLevel = 0;
938 transferInfo.imageOffset.x = 0;
939 transferInfo.imageOffset.y = 0;
940 transferInfo.imageOffset.z = 0;
941 transferInfo.barriers = &bufferBarriers;
942 copyToCPU(deviceInterface, &transferInfo);
944 deviceInterface.cmdPipelineBarrier( transferInfo.commandBuffer,
945 VK_PIPELINE_STAGE_TRANSFER_BIT,
946 VK_PIPELINE_STAGE_HOST_BIT,
948 (deUint32)memoryBarriers.size(), (memoryBarriers.empty() ? DE_NULL : &memoryBarriers[0]),
949 (deUint32)bufferBarriers.size(), (bufferBarriers.empty() ? DE_NULL : &bufferBarriers[0]),
950 (deUint32)imageBarriers.size(), (imageBarriers.empty() ? DE_NULL : &imageBarriers[0]));
952 memoryBarriers.resize(0);
953 bufferBarriers.resize(0);
954 imageBarriers.resize(0);
956 endCommandBuffer(deviceInterface, transferInfo.commandBuffer);
959 static void initSubmitInfo (VkSubmitInfo* submitInfo, deUint32 submitInfoCount)
961 for (deUint32 ndx = 0; ndx < submitInfoCount; ndx++)
963 submitInfo[ndx].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
964 submitInfo[ndx].pNext = DE_NULL;
965 submitInfo[ndx].waitSemaphoreCount = 0;
966 submitInfo[ndx].pWaitSemaphores = DE_NULL;
967 submitInfo[ndx].pWaitDstStageMask = DE_NULL;
968 submitInfo[ndx].commandBufferCount = 1;
969 submitInfo[ndx].signalSemaphoreCount = 0;
970 submitInfo[ndx].pSignalSemaphores = DE_NULL;
974 static void initTimelineSemaphoreSubmitInfo (VkTimelineSemaphoreSubmitInfoKHR* submitInfo, deUint32 submitInfoCount)
976 for (deUint32 ndx = 0; ndx < submitInfoCount; ndx++)
978 submitInfo[ndx].sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO_KHR;
979 submitInfo[ndx].pNext = DE_NULL;
980 submitInfo[ndx].waitSemaphoreValueCount = 0;
981 submitInfo[ndx].pWaitSemaphoreValues = DE_NULL;
982 submitInfo[ndx].signalSemaphoreValueCount = 0;
983 submitInfo[ndx].pSignalSemaphoreValues = DE_NULL;
987 tcu::TestStatus testFences (Context& context)
989 TestLog& log = context.getTestContext().getLog();
990 const DeviceInterface& deviceInterface = context.getDeviceInterface();
991 const VkQueue queue = context.getUniversalQueue();
992 const deUint32 queueFamilyIdx = context.getUniversalQueueFamilyIndex();
993 VkDevice device = context.getDevice();
995 VkResult fenceStatus;
996 TestContext testContext (deviceInterface, device, queueFamilyIdx, context.getBinaryCollection(), context.getDefaultAllocator());
997 VkSubmitInfo submitInfo;
1000 const tcu::Vec4 vertices[] =
1002 tcu::Vec4( 0.5f, 0.5f, 0.0f, 1.0f),
1003 tcu::Vec4(-0.5f, 0.5f, 0.0f, 1.0f),
1004 tcu::Vec4( 0.0f, -0.5f, 0.0f, 1.0f)
1007 testContext.vertices = vertices;
1008 testContext.numVertices = DE_LENGTH_OF_ARRAY(vertices);
1009 testContext.renderDimension = tcu::IVec2(256, 256);
1010 testContext.renderSize = sizeof(deUint32) * testContext.renderDimension.x() * testContext.renderDimension.y();
1012 createCommandBuffer(deviceInterface, device, queueFamilyIdx, &testContext.cmdBuffer, &testContext.commandPool);
1013 generateWork(testContext);
1015 initSubmitInfo(&submitInfo, 1);
1016 submitInfo.pCommandBuffers = &testContext.cmdBuffer.get();
1018 // Default status is unsignaled
1019 fenceStatus = deviceInterface.getFenceStatus(device, testContext.fences[0]);
1020 if (fenceStatus != VK_NOT_READY)
1022 log << TestLog::Message << "testSynchronizationPrimitives fence 0 should be reset but status is " << getResultName(fenceStatus) << TestLog::EndMessage;
1023 return tcu::TestStatus::fail("Fence in incorrect state");
1025 fenceStatus = deviceInterface.getFenceStatus(device, testContext.fences[1]);
1026 if (fenceStatus != VK_NOT_READY)
1028 log << TestLog::Message << "testSynchronizationPrimitives fence 1 should be reset but status is " << getResultName(fenceStatus) << TestLog::EndMessage;
1029 return tcu::TestStatus::fail("Fence in incorrect state");
1032 VK_CHECK(deviceInterface.queueSubmit(queue, 1, &submitInfo, testContext.fences[0]));
1034 // Wait with timeout = 0
1035 waitStatus = deviceInterface.waitForFences(device, 1, &testContext.fences[0], true, 0u);
1036 if (waitStatus != VK_SUCCESS && waitStatus != VK_TIMEOUT)
1038 // Will most likely end with VK_TIMEOUT
1039 log << TestLog::Message << "testSynchPrimitives failed to wait for a single fence" << TestLog::EndMessage;
1040 return tcu::TestStatus::fail("Failed to wait for a single fence");
1043 // Wait with a reasonable timeout
1044 waitStatus = deviceInterface.waitForFences(device, 1, &testContext.fences[0], true, DEFAULT_TIMEOUT);
1045 if (waitStatus != VK_SUCCESS && waitStatus != VK_TIMEOUT)
1047 // \note Wait can end with a timeout if DEFAULT_TIMEOUT is not sufficient
1048 log << TestLog::Message << "testSynchPrimitives failed to wait for a single fence" << TestLog::EndMessage;
1049 return tcu::TestStatus::fail("Failed to wait for a single fence");
1052 // Wait for work on fences[0] to actually complete
1053 waitStatus = deviceInterface.waitForFences(device, 1, &testContext.fences[0], true, std::numeric_limits<deUint64>::max());
1054 if (waitStatus != VK_SUCCESS)
1056 log << TestLog::Message << "testSynchPrimitives failed to wait for a fence" << TestLog::EndMessage;
1057 return tcu::TestStatus::fail("failed to wait for a fence");
1060 // Wait until timeout on a fence that has not been submitted
1061 waitStatus = deviceInterface.waitForFences(device, 1, &testContext.fences[1], true, 1);
1062 if (waitStatus != VK_TIMEOUT)
1064 log << TestLog::Message << "testSyncPrimitives failed to timeout on wait for single fence" << TestLog::EndMessage;
1065 return tcu::TestStatus::fail("failed to timeout on wait for single fence");
1068 // Check that the fence is signaled after the wait
1069 fenceStatus = deviceInterface.getFenceStatus(device, testContext.fences[0]);
1070 if (fenceStatus != VK_SUCCESS)
1072 log << TestLog::Message << "testSynchronizationPrimitives fence should be signaled but status is " << getResultName(fenceStatus) << TestLog::EndMessage;
1073 return tcu::TestStatus::fail("Fence in incorrect state");
1076 invalidateAlloc(deviceInterface, device, *testContext.renderReadBuffer);
1077 resultImage = testContext.renderReadBuffer->getHostPtr();
1079 log << TestLog::Image( "result",
1081 tcu::ConstPixelBufferAccess(tcu::TextureFormat(
1082 tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
1083 testContext.renderDimension.x(),
1084 testContext.renderDimension.y(),
1088 return TestStatus::pass("synchronization-fences passed");
1091 tcu::TestStatus testSemaphores (Context& context, VkSemaphoreTypeKHR semaphoreType)
1093 TestLog& log = context.getTestContext().getLog();
1094 const PlatformInterface& platformInterface = context.getPlatformInterface();
1095 const InstanceInterface& instanceInterface = context.getInstanceInterface();
1096 const VkPhysicalDevice physicalDevice = context.getPhysicalDevice();
1097 deUint32 queueFamilyIdx;
1098 vk::Move<VkDevice> device = createTestDevice(platformInterface, context.getInstance(), instanceInterface, physicalDevice, &queueFamilyIdx);
1099 const DeviceDriver deviceInterface (platformInterface, context.getInstance(), *device);
1100 SimpleAllocator allocator (deviceInterface,
1102 getPhysicalDeviceMemoryProperties(instanceInterface, physicalDevice));
1103 const VkQueue queue[2] =
1105 getDeviceQueue(deviceInterface, *device, queueFamilyIdx, 0),
1106 getDeviceQueue(deviceInterface, *device, queueFamilyIdx, 1)
1108 VkResult testStatus;
1109 TestContext testContext1 (deviceInterface, device.get(), queueFamilyIdx, context.getBinaryCollection(), allocator);
1110 TestContext testContext2 (deviceInterface, device.get(), queueFamilyIdx, context.getBinaryCollection(), allocator);
1111 Unique<VkSemaphore> semaphore (createSemaphoreType(deviceInterface, *device, semaphoreType));
1112 VkSubmitInfo submitInfo[2];
1113 VkTimelineSemaphoreSubmitInfoKHR timelineSubmitInfo[2];
1114 const deUint64 timelineValue = 1u;
1117 const VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
1119 const tcu::Vec4 vertices1[] =
1121 tcu::Vec4( 0.5f, 0.5f, 0.0f, 1.0f),
1122 tcu::Vec4(-0.5f, 0.5f, 0.0f, 1.0f),
1123 tcu::Vec4( 0.0f, -0.5f, 0.0f, 1.0f)
1126 const tcu::Vec4 vertices2[] =
1128 tcu::Vec4(-0.5f, -0.5f, 0.0f, 1.0f),
1129 tcu::Vec4(+0.5f, -0.5f, 0.0f, 1.0f),
1130 tcu::Vec4( 0.0f, +0.5f, 0.0f, 1.0f)
1133 testContext1.vertices = vertices1;
1134 testContext1.numVertices = DE_LENGTH_OF_ARRAY(vertices1);
1135 testContext1.renderDimension = tcu::IVec2(256, 256);
1136 testContext1.renderSize = sizeof(deUint32) * testContext1.renderDimension.x() * testContext1.renderDimension.y();
1138 testContext2.vertices = vertices2;
1139 testContext2.numVertices = DE_LENGTH_OF_ARRAY(vertices2);
1140 testContext2.renderDimension = tcu::IVec2(256, 256);
1141 testContext2.renderSize = sizeof(deUint32) * testContext2.renderDimension.x() * testContext2.renderDimension.y();
1143 createCommandBuffer(deviceInterface, device.get(), queueFamilyIdx, &testContext1.cmdBuffer, &testContext1.commandPool);
1144 generateWork(testContext1);
1146 createCommandBuffer(deviceInterface, device.get(), queueFamilyIdx, &testContext2.cmdBuffer, &testContext2.commandPool);
1147 generateWork(testContext2);
1149 initSubmitInfo(submitInfo, DE_LENGTH_OF_ARRAY(submitInfo));
1150 initTimelineSemaphoreSubmitInfo(timelineSubmitInfo, DE_LENGTH_OF_ARRAY(timelineSubmitInfo));
1152 // The difference between the two submit infos is that each will use a unique cmd buffer,
1153 // and one will signal a semaphore but not wait on a semaphore, the other will wait on the
1154 // semaphore but not signal a semaphore
1155 submitInfo[0].pCommandBuffers = &testContext1.cmdBuffer.get();
1156 submitInfo[1].pCommandBuffers = &testContext2.cmdBuffer.get();
1158 submitInfo[0].signalSemaphoreCount = 1;
1159 submitInfo[0].pSignalSemaphores = &semaphore.get();
1160 timelineSubmitInfo[0].pSignalSemaphoreValues = &timelineValue;
1161 timelineSubmitInfo[0].signalSemaphoreValueCount = 1;
1162 submitInfo[0].pNext = (semaphoreType == VK_SEMAPHORE_TYPE_TIMELINE_KHR ? &timelineSubmitInfo[0] : DE_NULL);
1163 submitInfo[1].waitSemaphoreCount = 1;
1164 submitInfo[1].pWaitSemaphores = &semaphore.get();
1165 timelineSubmitInfo[1].pWaitSemaphoreValues = &timelineValue;
1166 timelineSubmitInfo[1].waitSemaphoreValueCount = 1;
1167 submitInfo[1].pNext = (semaphoreType == VK_SEMAPHORE_TYPE_TIMELINE_KHR ? &timelineSubmitInfo[1] : DE_NULL);
1168 submitInfo[1].pWaitDstStageMask = &waitDstStageMask;
1170 VK_CHECK(deviceInterface.queueSubmit(queue[0], 1, &submitInfo[0], testContext1.fences[0]));
1172 testStatus = deviceInterface.waitForFences(device.get(), 1, &testContext1.fences[0], true, std::numeric_limits<deUint64>::max());
1173 if (testStatus != VK_SUCCESS)
1175 log << TestLog::Message << "testSynchPrimitives failed to wait for a set fence" << TestLog::EndMessage;
1176 return tcu::TestStatus::fail("failed to wait for a set fence");
1179 invalidateAlloc(deviceInterface, device.get(), *testContext1.renderReadBuffer);
1180 resultImage = testContext1.renderReadBuffer->getHostPtr();
1182 log << TestLog::Image( "result",
1184 tcu::ConstPixelBufferAccess(tcu::TextureFormat(
1185 tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
1186 testContext1.renderDimension.x(),
1187 testContext1.renderDimension.y(),
1191 VK_CHECK(deviceInterface.queueSubmit(queue[1], 1, &submitInfo[1], testContext2.fences[0]));
1193 testStatus = deviceInterface.waitForFences(device.get(), 1, &testContext2.fences[0], true, std::numeric_limits<deUint64>::max());
1194 if (testStatus != VK_SUCCESS)
1196 log << TestLog::Message << "testSynchPrimitives failed to wait for a set fence" << TestLog::EndMessage;
1197 return tcu::TestStatus::fail("failed to wait for a set fence");
1200 invalidateAlloc(deviceInterface, device.get(), *testContext2.renderReadBuffer);
1201 resultImage = testContext2.renderReadBuffer->getHostPtr();
1203 log << TestLog::Image( "result",
1205 tcu::ConstPixelBufferAccess(tcu::TextureFormat(
1206 tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8),
1207 testContext2.renderDimension.x(),
1208 testContext2.renderDimension.y(),
1212 return tcu::TestStatus::pass("synchronization-semaphores passed");
1215 tcu::TestStatus testBinarySemaphores (Context& context)
1217 return testSemaphores(context, VK_SEMAPHORE_TYPE_BINARY_KHR);
1220 tcu::TestStatus testTimelineSemaphores (Context& context)
1222 return testSemaphores(context, VK_SEMAPHORE_TYPE_TIMELINE_KHR);
1227 tcu::TestCaseGroup* createSmokeTests (tcu::TestContext& textCtx)
1229 de::MovePtr<tcu::TestCaseGroup> synchTests (new tcu::TestCaseGroup(textCtx, "smoke", "Synchronization smoke tests"));
1231 addFunctionCaseWithPrograms(synchTests.get(), "fences", "", buildShaders, testFences);
1232 addFunctionCaseWithPrograms(synchTests.get(), "binary_semaphores", "", buildShaders, testBinarySemaphores);
1233 addFunctionCaseWithPrograms(synchTests.get(), "timeline_semaphores", "", buildShaders, testTimelineSemaphores);
1235 return synchTests.release();
1238 } // synchronization