1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * Vulkan Conformance Tests 3e5c31af7Sopenharmony_ci * ------------------------ 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright (c) 2015 The Khronos Group Inc. 6e5c31af7Sopenharmony_ci * Copyright (c) 2015 Samsung Electronics Co., Ltd. 7e5c31af7Sopenharmony_ci * Copyright (c) 2015 Google Inc. 8e5c31af7Sopenharmony_ci * 9e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci * 15e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci * limitations under the License. 20e5c31af7Sopenharmony_ci * 21e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ci#include "vkDefs.hpp" 24e5c31af7Sopenharmony_ci#include "vktTestCaseUtil.hpp" 25e5c31af7Sopenharmony_ci#include "vkBuilderUtil.hpp" 26e5c31af7Sopenharmony_ci#include "vkPlatform.hpp" 27e5c31af7Sopenharmony_ci#include "vkRefUtil.hpp" 28e5c31af7Sopenharmony_ci#include "vkQueryUtil.hpp" 29e5c31af7Sopenharmony_ci#include "vkMemUtil.hpp" 30e5c31af7Sopenharmony_ci#include "vkDeviceUtil.hpp" 31e5c31af7Sopenharmony_ci#include "vkCmdUtil.hpp" 32e5c31af7Sopenharmony_ci#include "vkObjUtil.hpp" 33e5c31af7Sopenharmony_ci#include "vkImageUtil.hpp" 34e5c31af7Sopenharmony_ci#include "vkPrograms.hpp" 35e5c31af7Sopenharmony_ci#include "vkTypeUtil.hpp" 36e5c31af7Sopenharmony_ci#include "vkAllocationCallbackUtil.hpp" 37e5c31af7Sopenharmony_ci#include "vkCmdUtil.hpp" 38e5c31af7Sopenharmony_ci#include "vkBarrierUtil.hpp" 39e5c31af7Sopenharmony_ci#include "vkBufferWithMemory.hpp" 40e5c31af7Sopenharmony_ci#include "vkImageWithMemory.hpp" 41e5c31af7Sopenharmony_ci#include "tcuTextureUtil.hpp" 42e5c31af7Sopenharmony_ci#include "tcuCommandLine.hpp" 43e5c31af7Sopenharmony_ci#include "vktApiCommandBuffersTests.hpp" 44e5c31af7Sopenharmony_ci#include "vktApiBufferComputeInstance.hpp" 45e5c31af7Sopenharmony_ci#include "vktApiComputeInstanceResultBuffer.hpp" 46e5c31af7Sopenharmony_ci#include "deSharedPtr.hpp" 47e5c31af7Sopenharmony_ci#include "deRandom.hpp" 48e5c31af7Sopenharmony_ci#include <sstream> 49e5c31af7Sopenharmony_ci#include <limits> 50e5c31af7Sopenharmony_ci 51e5c31af7Sopenharmony_cinamespace vkt 52e5c31af7Sopenharmony_ci{ 53e5c31af7Sopenharmony_cinamespace api 54e5c31af7Sopenharmony_ci{ 55e5c31af7Sopenharmony_cinamespace 56e5c31af7Sopenharmony_ci{ 57e5c31af7Sopenharmony_ci 58e5c31af7Sopenharmony_ciusing namespace vk; 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_citypedef de::SharedPtr<vk::Unique<vk::VkEvent> > VkEventSp; 61e5c31af7Sopenharmony_ci 62e5c31af7Sopenharmony_ci// Global variables 63e5c31af7Sopenharmony_ciconst deUint64 INFINITE_TIMEOUT = ~(deUint64)0u; 64e5c31af7Sopenharmony_ci 65e5c31af7Sopenharmony_ci 66e5c31af7Sopenharmony_citemplate <deUint32 NumBuffers> 67e5c31af7Sopenharmony_ciclass CommandBufferBareTestEnvironment 68e5c31af7Sopenharmony_ci{ 69e5c31af7Sopenharmony_cipublic: 70e5c31af7Sopenharmony_ci CommandBufferBareTestEnvironment (Context& context, 71e5c31af7Sopenharmony_ci VkCommandPoolCreateFlags commandPoolCreateFlags); 72e5c31af7Sopenharmony_ci 73e5c31af7Sopenharmony_ci VkCommandPool getCommandPool (void) const { return *m_commandPool; } 74e5c31af7Sopenharmony_ci VkCommandBuffer getCommandBuffer (deUint32 bufferIndex) const; 75e5c31af7Sopenharmony_ci 76e5c31af7Sopenharmony_ciprotected: 77e5c31af7Sopenharmony_ci Context& m_context; 78e5c31af7Sopenharmony_ci const VkDevice m_device; 79e5c31af7Sopenharmony_ci const DeviceInterface& m_vkd; 80e5c31af7Sopenharmony_ci const VkQueue m_queue; 81e5c31af7Sopenharmony_ci const deUint32 m_queueFamilyIndex; 82e5c31af7Sopenharmony_ci Allocator& m_allocator; 83e5c31af7Sopenharmony_ci 84e5c31af7Sopenharmony_ci Move<VkCommandPool> m_commandPool; 85e5c31af7Sopenharmony_ci Move<VkCommandBuffer> m_primaryCommandBuffers[NumBuffers]; 86e5c31af7Sopenharmony_ci}; 87e5c31af7Sopenharmony_ci 88e5c31af7Sopenharmony_citemplate <deUint32 NumBuffers> 89e5c31af7Sopenharmony_ciCommandBufferBareTestEnvironment<NumBuffers>::CommandBufferBareTestEnvironment(Context& context, VkCommandPoolCreateFlags commandPoolCreateFlags) 90e5c31af7Sopenharmony_ci : m_context (context) 91e5c31af7Sopenharmony_ci , m_device (context.getDevice()) 92e5c31af7Sopenharmony_ci , m_vkd (context.getDeviceInterface()) 93e5c31af7Sopenharmony_ci , m_queue (context.getUniversalQueue()) 94e5c31af7Sopenharmony_ci , m_queueFamilyIndex (context.getUniversalQueueFamilyIndex()) 95e5c31af7Sopenharmony_ci , m_allocator (context.getDefaultAllocator()) 96e5c31af7Sopenharmony_ci{ 97e5c31af7Sopenharmony_ci m_commandPool = createCommandPool(m_vkd, m_device, commandPoolCreateFlags, m_queueFamilyIndex); 98e5c31af7Sopenharmony_ci 99e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufferAllocateInfo = 100e5c31af7Sopenharmony_ci { 101e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 102e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 103e5c31af7Sopenharmony_ci *m_commandPool, // VkCommandPool commandPool; 104e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 105e5c31af7Sopenharmony_ci NumBuffers // deUint32 commandBufferCount; 106e5c31af7Sopenharmony_ci }; 107e5c31af7Sopenharmony_ci 108e5c31af7Sopenharmony_ci allocateCommandBuffers(m_vkd, m_device, &cmdBufferAllocateInfo, m_primaryCommandBuffers); 109e5c31af7Sopenharmony_ci} 110e5c31af7Sopenharmony_ci 111e5c31af7Sopenharmony_citemplate <deUint32 NumBuffers> 112e5c31af7Sopenharmony_ciVkCommandBuffer CommandBufferBareTestEnvironment<NumBuffers>::getCommandBuffer(deUint32 bufferIndex) const 113e5c31af7Sopenharmony_ci{ 114e5c31af7Sopenharmony_ci DE_ASSERT(bufferIndex < NumBuffers); 115e5c31af7Sopenharmony_ci return m_primaryCommandBuffers[bufferIndex].get(); 116e5c31af7Sopenharmony_ci} 117e5c31af7Sopenharmony_ci 118e5c31af7Sopenharmony_ciclass CommandBufferRenderPassTestEnvironment : public CommandBufferBareTestEnvironment<1> 119e5c31af7Sopenharmony_ci{ 120e5c31af7Sopenharmony_cipublic: 121e5c31af7Sopenharmony_ci CommandBufferRenderPassTestEnvironment (Context& context, 122e5c31af7Sopenharmony_ci VkCommandPoolCreateFlags commandPoolCreateFlags); 123e5c31af7Sopenharmony_ci 124e5c31af7Sopenharmony_ci VkRenderPass getRenderPass (void) const { return *m_renderPass; } 125e5c31af7Sopenharmony_ci VkFramebuffer getFrameBuffer (void) const { return *m_frameBuffer; } 126e5c31af7Sopenharmony_ci VkCommandBuffer getPrimaryCommandBuffer (void) const { return getCommandBuffer(0); } 127e5c31af7Sopenharmony_ci VkCommandBuffer getSecondaryCommandBuffer (void) const { return *m_secondaryCommandBuffer; } 128e5c31af7Sopenharmony_ci 129e5c31af7Sopenharmony_ci void beginPrimaryCommandBuffer (VkCommandBufferUsageFlags usageFlags); 130e5c31af7Sopenharmony_ci void beginSecondaryCommandBuffer (VkCommandBufferUsageFlags usageFlags, bool framebufferHint); 131e5c31af7Sopenharmony_ci void beginRenderPass (VkSubpassContents content); 132e5c31af7Sopenharmony_ci void submitPrimaryCommandBuffer (void); 133e5c31af7Sopenharmony_ci de::MovePtr<tcu::TextureLevel> readColorAttachment (void); 134e5c31af7Sopenharmony_ci 135e5c31af7Sopenharmony_ci static const VkImageType DEFAULT_IMAGE_TYPE; 136e5c31af7Sopenharmony_ci static const VkFormat DEFAULT_IMAGE_FORMAT; 137e5c31af7Sopenharmony_ci static const VkExtent3D DEFAULT_IMAGE_SIZE; 138e5c31af7Sopenharmony_ci static const VkRect2D DEFAULT_IMAGE_AREA; 139e5c31af7Sopenharmony_ci 140e5c31af7Sopenharmony_ciprotected: 141e5c31af7Sopenharmony_ci 142e5c31af7Sopenharmony_ci Move<VkImage> m_colorImage; 143e5c31af7Sopenharmony_ci Move<VkImageView> m_colorImageView; 144e5c31af7Sopenharmony_ci Move<VkRenderPass> m_renderPass; 145e5c31af7Sopenharmony_ci Move<VkFramebuffer> m_frameBuffer; 146e5c31af7Sopenharmony_ci de::MovePtr<Allocation> m_colorImageMemory; 147e5c31af7Sopenharmony_ci Move<VkCommandPool> m_secCommandPool; 148e5c31af7Sopenharmony_ci Move<VkCommandBuffer> m_secondaryCommandBuffer; 149e5c31af7Sopenharmony_ci 150e5c31af7Sopenharmony_ci}; 151e5c31af7Sopenharmony_ci 152e5c31af7Sopenharmony_ciconst VkImageType CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_TYPE = VK_IMAGE_TYPE_2D; 153e5c31af7Sopenharmony_ciconst VkFormat CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_FORMAT = VK_FORMAT_R8G8B8A8_UINT; 154e5c31af7Sopenharmony_ciconst VkExtent3D CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE = {255, 255, 1}; 155e5c31af7Sopenharmony_ciconst VkRect2D CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_AREA = 156e5c31af7Sopenharmony_ci{ 157e5c31af7Sopenharmony_ci { 0u, 0u, }, // VkOffset2D offset; 158e5c31af7Sopenharmony_ci { DEFAULT_IMAGE_SIZE.width, DEFAULT_IMAGE_SIZE.height }, // VkExtent2D extent; 159e5c31af7Sopenharmony_ci}; 160e5c31af7Sopenharmony_ci 161e5c31af7Sopenharmony_ciCommandBufferRenderPassTestEnvironment::CommandBufferRenderPassTestEnvironment(Context& context, VkCommandPoolCreateFlags commandPoolCreateFlags) 162e5c31af7Sopenharmony_ci : CommandBufferBareTestEnvironment<1> (context, commandPoolCreateFlags) 163e5c31af7Sopenharmony_ci{ 164e5c31af7Sopenharmony_ci m_renderPass = makeRenderPass(m_vkd, m_device, DEFAULT_IMAGE_FORMAT); 165e5c31af7Sopenharmony_ci 166e5c31af7Sopenharmony_ci { 167e5c31af7Sopenharmony_ci const VkImageCreateInfo imageCreateInfo = 168e5c31af7Sopenharmony_ci { 169e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 170e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 171e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 172e5c31af7Sopenharmony_ci DEFAULT_IMAGE_TYPE, // VkImageType imageType; 173e5c31af7Sopenharmony_ci DEFAULT_IMAGE_FORMAT, // VkFormat format; 174e5c31af7Sopenharmony_ci DEFAULT_IMAGE_SIZE, // VkExtent3D extent; 175e5c31af7Sopenharmony_ci 1, // deUint32 mipLevels; 176e5c31af7Sopenharmony_ci 1, // deUint32 arrayLayers; 177e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 178e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 179e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | 180e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_SRC_BIT | 181e5c31af7Sopenharmony_ci VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage; 182e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 183e5c31af7Sopenharmony_ci 1, // deUint32 queueFamilyIndexCount; 184e5c31af7Sopenharmony_ci &m_queueFamilyIndex, // const deUint32* pQueueFamilyIndices; 185e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout; 186e5c31af7Sopenharmony_ci }; 187e5c31af7Sopenharmony_ci 188e5c31af7Sopenharmony_ci m_colorImage = createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL); 189e5c31af7Sopenharmony_ci } 190e5c31af7Sopenharmony_ci 191e5c31af7Sopenharmony_ci m_colorImageMemory = m_allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, *m_colorImage), MemoryRequirement::Any); 192e5c31af7Sopenharmony_ci VK_CHECK(m_vkd.bindImageMemory(m_device, *m_colorImage, m_colorImageMemory->getMemory(), m_colorImageMemory->getOffset())); 193e5c31af7Sopenharmony_ci 194e5c31af7Sopenharmony_ci { 195e5c31af7Sopenharmony_ci const VkImageViewCreateInfo imageViewCreateInfo = 196e5c31af7Sopenharmony_ci { 197e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType; 198e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 199e5c31af7Sopenharmony_ci 0u, // VkImageViewCreateFlags flags; 200e5c31af7Sopenharmony_ci *m_colorImage, // VkImage image; 201e5c31af7Sopenharmony_ci VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType; 202e5c31af7Sopenharmony_ci DEFAULT_IMAGE_FORMAT, // VkFormat format; 203e5c31af7Sopenharmony_ci { 204e5c31af7Sopenharmony_ci VK_COMPONENT_SWIZZLE_R, 205e5c31af7Sopenharmony_ci VK_COMPONENT_SWIZZLE_G, 206e5c31af7Sopenharmony_ci VK_COMPONENT_SWIZZLE_B, 207e5c31af7Sopenharmony_ci VK_COMPONENT_SWIZZLE_A 208e5c31af7Sopenharmony_ci }, // VkComponentMapping components; 209e5c31af7Sopenharmony_ci { 210e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask; 211e5c31af7Sopenharmony_ci 0u, // deUint32 baseMipLevel; 212e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 213e5c31af7Sopenharmony_ci 0u, // deUint32 baseArrayLayer; 214e5c31af7Sopenharmony_ci 1u, // deUint32 arraySize; 215e5c31af7Sopenharmony_ci }, // VkImageSubresourceRange subresourceRange; 216e5c31af7Sopenharmony_ci }; 217e5c31af7Sopenharmony_ci 218e5c31af7Sopenharmony_ci m_colorImageView = createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL); 219e5c31af7Sopenharmony_ci } 220e5c31af7Sopenharmony_ci 221e5c31af7Sopenharmony_ci { 222e5c31af7Sopenharmony_ci const VkImageView attachmentViews[1] = 223e5c31af7Sopenharmony_ci { 224e5c31af7Sopenharmony_ci *m_colorImageView 225e5c31af7Sopenharmony_ci }; 226e5c31af7Sopenharmony_ci 227e5c31af7Sopenharmony_ci const VkFramebufferCreateInfo framebufferCreateInfo = 228e5c31af7Sopenharmony_ci { 229e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType; 230e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 231e5c31af7Sopenharmony_ci 0u, // VkFramebufferCreateFlags flags; 232e5c31af7Sopenharmony_ci *m_renderPass, // VkRenderPass renderPass; 233e5c31af7Sopenharmony_ci 1, // deUint32 attachmentCount; 234e5c31af7Sopenharmony_ci attachmentViews, // const VkImageView* pAttachments; 235e5c31af7Sopenharmony_ci DEFAULT_IMAGE_SIZE.width, // deUint32 width; 236e5c31af7Sopenharmony_ci DEFAULT_IMAGE_SIZE.height, // deUint32 height; 237e5c31af7Sopenharmony_ci 1u, // deUint32 layers; 238e5c31af7Sopenharmony_ci }; 239e5c31af7Sopenharmony_ci 240e5c31af7Sopenharmony_ci m_frameBuffer = createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL); 241e5c31af7Sopenharmony_ci } 242e5c31af7Sopenharmony_ci 243e5c31af7Sopenharmony_ci m_secCommandPool = createCommandPool(m_vkd, m_device, commandPoolCreateFlags, m_queueFamilyIndex); 244e5c31af7Sopenharmony_ci 245e5c31af7Sopenharmony_ci { 246e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufferAllocateInfo = 247e5c31af7Sopenharmony_ci { 248e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 249e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 250e5c31af7Sopenharmony_ci *m_secCommandPool, // VkCommandPool commandPool; 251e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 252e5c31af7Sopenharmony_ci 1u // deUint32 commandBufferCount; 253e5c31af7Sopenharmony_ci }; 254e5c31af7Sopenharmony_ci 255e5c31af7Sopenharmony_ci m_secondaryCommandBuffer = allocateCommandBuffer(m_vkd, m_device, &cmdBufferAllocateInfo); 256e5c31af7Sopenharmony_ci 257e5c31af7Sopenharmony_ci } 258e5c31af7Sopenharmony_ci} 259e5c31af7Sopenharmony_ci 260e5c31af7Sopenharmony_civoid CommandBufferRenderPassTestEnvironment::beginRenderPass(VkSubpassContents content) 261e5c31af7Sopenharmony_ci{ 262e5c31af7Sopenharmony_ci vk::beginRenderPass(m_vkd, m_primaryCommandBuffers[0].get(), *m_renderPass, *m_frameBuffer, DEFAULT_IMAGE_AREA, tcu::UVec4(17, 59, 163, 251), content); 263e5c31af7Sopenharmony_ci} 264e5c31af7Sopenharmony_ci 265e5c31af7Sopenharmony_civoid CommandBufferRenderPassTestEnvironment::beginPrimaryCommandBuffer(VkCommandBufferUsageFlags usageFlags) 266e5c31af7Sopenharmony_ci{ 267e5c31af7Sopenharmony_ci beginCommandBuffer(m_vkd, m_primaryCommandBuffers[0].get(), usageFlags); 268e5c31af7Sopenharmony_ci} 269e5c31af7Sopenharmony_ci 270e5c31af7Sopenharmony_civoid CommandBufferRenderPassTestEnvironment::beginSecondaryCommandBuffer(VkCommandBufferUsageFlags usageFlags, bool framebufferHint) 271e5c31af7Sopenharmony_ci{ 272e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo commandBufferInheritanceInfo = 273e5c31af7Sopenharmony_ci { 274e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // VkStructureType sType; 275e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 276e5c31af7Sopenharmony_ci *m_renderPass, // VkRenderPass renderPass; 277e5c31af7Sopenharmony_ci 0u, // deUint32 subpass; 278e5c31af7Sopenharmony_ci (framebufferHint ? *m_frameBuffer : DE_NULL), // VkFramebuffer framebuffer; 279e5c31af7Sopenharmony_ci VK_FALSE, // VkBool32 occlusionQueryEnable; 280e5c31af7Sopenharmony_ci 0u, // VkQueryControlFlags queryFlags; 281e5c31af7Sopenharmony_ci 0u // VkQueryPipelineStatisticFlags pipelineStatistics; 282e5c31af7Sopenharmony_ci }; 283e5c31af7Sopenharmony_ci 284e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo commandBufferBeginInfo = 285e5c31af7Sopenharmony_ci { 286e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType; 287e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 288e5c31af7Sopenharmony_ci usageFlags, // VkCommandBufferUsageFlags flags; 289e5c31af7Sopenharmony_ci &commandBufferInheritanceInfo // const VkCommandBufferInheritanceInfo* pInheritanceInfo; 290e5c31af7Sopenharmony_ci }; 291e5c31af7Sopenharmony_ci 292e5c31af7Sopenharmony_ci VK_CHECK(m_vkd.beginCommandBuffer(*m_secondaryCommandBuffer, &commandBufferBeginInfo)); 293e5c31af7Sopenharmony_ci 294e5c31af7Sopenharmony_ci} 295e5c31af7Sopenharmony_ci 296e5c31af7Sopenharmony_civoid CommandBufferRenderPassTestEnvironment::submitPrimaryCommandBuffer(void) 297e5c31af7Sopenharmony_ci{ 298e5c31af7Sopenharmony_ci submitCommandsAndWait(m_vkd, m_device, m_queue, m_primaryCommandBuffers[0].get()); 299e5c31af7Sopenharmony_ci} 300e5c31af7Sopenharmony_ci 301e5c31af7Sopenharmony_cide::MovePtr<tcu::TextureLevel> CommandBufferRenderPassTestEnvironment::readColorAttachment () 302e5c31af7Sopenharmony_ci{ 303e5c31af7Sopenharmony_ci Move<VkBuffer> buffer; 304e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferAlloc; 305e5c31af7Sopenharmony_ci const tcu::TextureFormat tcuFormat = mapVkFormat(DEFAULT_IMAGE_FORMAT); 306e5c31af7Sopenharmony_ci const VkDeviceSize pixelDataSize = DEFAULT_IMAGE_SIZE.height * DEFAULT_IMAGE_SIZE.height * tcuFormat.getPixelSize(); 307e5c31af7Sopenharmony_ci de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(tcuFormat, DEFAULT_IMAGE_SIZE.width, DEFAULT_IMAGE_SIZE.height)); 308e5c31af7Sopenharmony_ci 309e5c31af7Sopenharmony_ci // Create destination buffer 310e5c31af7Sopenharmony_ci { 311e5c31af7Sopenharmony_ci const VkBufferCreateInfo bufferParams = 312e5c31af7Sopenharmony_ci { 313e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType; 314e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 315e5c31af7Sopenharmony_ci 0u, // VkBufferCreateFlags flags; 316e5c31af7Sopenharmony_ci pixelDataSize, // VkDeviceSize size; 317e5c31af7Sopenharmony_ci VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage; 318e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 319e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 320e5c31af7Sopenharmony_ci DE_NULL // const deUint32* pQueueFamilyIndices; 321e5c31af7Sopenharmony_ci }; 322e5c31af7Sopenharmony_ci 323e5c31af7Sopenharmony_ci buffer = createBuffer(m_vkd, m_device, &bufferParams); 324e5c31af7Sopenharmony_ci bufferAlloc = m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible); 325e5c31af7Sopenharmony_ci VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset())); 326e5c31af7Sopenharmony_ci } 327e5c31af7Sopenharmony_ci 328e5c31af7Sopenharmony_ci // Copy image to buffer 329e5c31af7Sopenharmony_ci beginPrimaryCommandBuffer(0); 330e5c31af7Sopenharmony_ci copyImageToBuffer(m_vkd, m_primaryCommandBuffers[0].get(), *m_colorImage, *buffer, tcu::IVec2(DEFAULT_IMAGE_SIZE.width, DEFAULT_IMAGE_SIZE.height)); 331e5c31af7Sopenharmony_ci endCommandBuffer(m_vkd, m_primaryCommandBuffers[0].get()); 332e5c31af7Sopenharmony_ci 333e5c31af7Sopenharmony_ci submitPrimaryCommandBuffer(); 334e5c31af7Sopenharmony_ci 335e5c31af7Sopenharmony_ci // Read buffer data 336e5c31af7Sopenharmony_ci invalidateAlloc(m_vkd, m_device, *bufferAlloc); 337e5c31af7Sopenharmony_ci tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), bufferAlloc->getHostPtr())); 338e5c31af7Sopenharmony_ci 339e5c31af7Sopenharmony_ci return resultLevel; 340e5c31af7Sopenharmony_ci} 341e5c31af7Sopenharmony_ci 342e5c31af7Sopenharmony_ci 343e5c31af7Sopenharmony_ci// Testcases 344e5c31af7Sopenharmony_ci/********* 19.1. Command Pools (5.1 in VK 1.0 Spec) ***************************/ 345e5c31af7Sopenharmony_citcu::TestStatus createPoolNullParamsTest(Context& context) 346e5c31af7Sopenharmony_ci{ 347e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 348e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 349e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 350e5c31af7Sopenharmony_ci 351e5c31af7Sopenharmony_ci createCommandPool(vk, vkDevice, 0u, queueFamilyIndex); 352e5c31af7Sopenharmony_ci 353e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 354e5c31af7Sopenharmony_ci} 355e5c31af7Sopenharmony_ci 356e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 357e5c31af7Sopenharmony_citcu::TestStatus createPoolNonNullAllocatorTest(Context& context) 358e5c31af7Sopenharmony_ci{ 359e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 360e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 361e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 362e5c31af7Sopenharmony_ci const VkAllocationCallbacks* allocationCallbacks = getSystemAllocator(); 363e5c31af7Sopenharmony_ci 364e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 365e5c31af7Sopenharmony_ci { 366e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 367e5c31af7Sopenharmony_ci DE_NULL, // pNext; 368e5c31af7Sopenharmony_ci 0u, // flags; 369e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 370e5c31af7Sopenharmony_ci }; 371e5c31af7Sopenharmony_ci 372e5c31af7Sopenharmony_ci createCommandPool(vk, vkDevice, &cmdPoolParams, allocationCallbacks); 373e5c31af7Sopenharmony_ci 374e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 375e5c31af7Sopenharmony_ci} 376e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 377e5c31af7Sopenharmony_ci 378e5c31af7Sopenharmony_citcu::TestStatus createPoolTransientBitTest(Context& context) 379e5c31af7Sopenharmony_ci{ 380e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 381e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 382e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 383e5c31af7Sopenharmony_ci 384e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 385e5c31af7Sopenharmony_ci { 386e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 387e5c31af7Sopenharmony_ci DE_NULL, // pNext; 388e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // flags; 389e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 390e5c31af7Sopenharmony_ci }; 391e5c31af7Sopenharmony_ci 392e5c31af7Sopenharmony_ci createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL); 393e5c31af7Sopenharmony_ci 394e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 395e5c31af7Sopenharmony_ci} 396e5c31af7Sopenharmony_ci 397e5c31af7Sopenharmony_citcu::TestStatus createPoolResetBitTest(Context& context) 398e5c31af7Sopenharmony_ci{ 399e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 400e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 401e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 402e5c31af7Sopenharmony_ci 403e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 404e5c31af7Sopenharmony_ci { 405e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 406e5c31af7Sopenharmony_ci DE_NULL, // pNext; 407e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 408e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 409e5c31af7Sopenharmony_ci }; 410e5c31af7Sopenharmony_ci 411e5c31af7Sopenharmony_ci createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL); 412e5c31af7Sopenharmony_ci 413e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 414e5c31af7Sopenharmony_ci} 415e5c31af7Sopenharmony_ci 416e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 417e5c31af7Sopenharmony_citcu::TestStatus resetPoolReleaseResourcesBitTest(Context& context) 418e5c31af7Sopenharmony_ci{ 419e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 420e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 421e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 422e5c31af7Sopenharmony_ci 423e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 424e5c31af7Sopenharmony_ci { 425e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 426e5c31af7Sopenharmony_ci DE_NULL, // pNext; 427e5c31af7Sopenharmony_ci 0u, // flags; 428e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 429e5c31af7Sopenharmony_ci }; 430e5c31af7Sopenharmony_ci 431e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL)); 432e5c31af7Sopenharmony_ci 433e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT)); 434e5c31af7Sopenharmony_ci 435e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 436e5c31af7Sopenharmony_ci} 437e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 438e5c31af7Sopenharmony_ci 439e5c31af7Sopenharmony_citcu::TestStatus resetPoolNoFlagsTest(Context& context) 440e5c31af7Sopenharmony_ci{ 441e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 442e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 443e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 444e5c31af7Sopenharmony_ci 445e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 446e5c31af7Sopenharmony_ci { 447e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 448e5c31af7Sopenharmony_ci DE_NULL, // pNext; 449e5c31af7Sopenharmony_ci 0u, // flags; 450e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 451e5c31af7Sopenharmony_ci }; 452e5c31af7Sopenharmony_ci 453e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL)); 454e5c31af7Sopenharmony_ci 455e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, 0u)); 456e5c31af7Sopenharmony_ci 457e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Command Pool allocated correctly."); 458e5c31af7Sopenharmony_ci} 459e5c31af7Sopenharmony_ci 460e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 461e5c31af7Sopenharmony_cibool executeCommandBuffer (const VkDevice device, 462e5c31af7Sopenharmony_ci const DeviceInterface& vk, 463e5c31af7Sopenharmony_ci const VkQueue queue, 464e5c31af7Sopenharmony_ci const VkCommandBuffer commandBuffer, 465e5c31af7Sopenharmony_ci const bool exitBeforeEndCommandBuffer = false) 466e5c31af7Sopenharmony_ci{ 467e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, device)); 468e5c31af7Sopenharmony_ci beginCommandBuffer(vk, commandBuffer, 0u); 469e5c31af7Sopenharmony_ci { 470e5c31af7Sopenharmony_ci const VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 471e5c31af7Sopenharmony_ci vk.cmdSetEvent(commandBuffer, *event, stageMask); 472e5c31af7Sopenharmony_ci if (exitBeforeEndCommandBuffer) 473e5c31af7Sopenharmony_ci return exitBeforeEndCommandBuffer; 474e5c31af7Sopenharmony_ci } 475e5c31af7Sopenharmony_ci endCommandBuffer(vk, commandBuffer); 476e5c31af7Sopenharmony_ci 477e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, commandBuffer); 478e5c31af7Sopenharmony_ci 479e5c31af7Sopenharmony_ci // check if buffer has been executed 480e5c31af7Sopenharmony_ci const VkResult result = vk.getEventStatus(device, *event); 481e5c31af7Sopenharmony_ci return result == VK_EVENT_SET; 482e5c31af7Sopenharmony_ci} 483e5c31af7Sopenharmony_ci 484e5c31af7Sopenharmony_citcu::TestStatus resetPoolReuseTest (Context& context) 485e5c31af7Sopenharmony_ci{ 486e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 487e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 488e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 489e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 490e5c31af7Sopenharmony_ci 491e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 492e5c31af7Sopenharmony_ci { 493e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 494e5c31af7Sopenharmony_ci DE_NULL, // pNext; 495e5c31af7Sopenharmony_ci 0u, // flags; 496e5c31af7Sopenharmony_ci queueFamilyIndex // queueFamilyIndex; 497e5c31af7Sopenharmony_ci }; 498e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams, DE_NULL)); 499e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 500e5c31af7Sopenharmony_ci { 501e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 502e5c31af7Sopenharmony_ci DE_NULL, // pNext; 503e5c31af7Sopenharmony_ci *cmdPool, // commandPool; 504e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 505e5c31af7Sopenharmony_ci 1u // bufferCount; 506e5c31af7Sopenharmony_ci }; 507e5c31af7Sopenharmony_ci const Move<VkCommandBuffer> commandBuffers[] = 508e5c31af7Sopenharmony_ci { 509e5c31af7Sopenharmony_ci allocateCommandBuffer(vk, vkDevice, &cmdBufParams), 510e5c31af7Sopenharmony_ci allocateCommandBuffer(vk, vkDevice, &cmdBufParams) 511e5c31af7Sopenharmony_ci }; 512e5c31af7Sopenharmony_ci 513e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 514e5c31af7Sopenharmony_ci bool canFinishEarlier = context.getTestContext().getCommandLine().isSubProcess(); 515e5c31af7Sopenharmony_ci#else 516e5c31af7Sopenharmony_ci bool canFinishEarlier = true; 517e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 518e5c31af7Sopenharmony_ci 519e5c31af7Sopenharmony_ci if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[0])) && canFinishEarlier) 520e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed"); 521e5c31af7Sopenharmony_ci if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[1]), true) && canFinishEarlier) 522e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed"); 523e5c31af7Sopenharmony_ci 524e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandPool(vkDevice, *cmdPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT)); 525e5c31af7Sopenharmony_ci 526e5c31af7Sopenharmony_ci if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[0])) && canFinishEarlier) 527e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed"); 528e5c31af7Sopenharmony_ci if (!executeCommandBuffer(vkDevice, vk, queue, *(commandBuffers[1])) && canFinishEarlier) 529e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed"); 530e5c31af7Sopenharmony_ci 531e5c31af7Sopenharmony_ci { 532e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> afterResetCommandBuffers(allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 533e5c31af7Sopenharmony_ci if (!executeCommandBuffer(vkDevice, vk, queue, *afterResetCommandBuffers) && canFinishEarlier) 534e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed"); 535e5c31af7Sopenharmony_ci } 536e5c31af7Sopenharmony_ci 537e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Passed"); 538e5c31af7Sopenharmony_ci} 539e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 540e5c31af7Sopenharmony_ci 541e5c31af7Sopenharmony_ci/******** 19.2. Command Buffer Lifetime (5.2 in VK 1.0 Spec) ******************/ 542e5c31af7Sopenharmony_citcu::TestStatus allocatePrimaryBufferTest(Context& context) 543e5c31af7Sopenharmony_ci{ 544e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 545e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 546e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 547e5c31af7Sopenharmony_ci 548e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 549e5c31af7Sopenharmony_ci { 550e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 551e5c31af7Sopenharmony_ci DE_NULL, // pNext; 552e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 553e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 554e5c31af7Sopenharmony_ci }; 555e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 556e5c31af7Sopenharmony_ci 557e5c31af7Sopenharmony_ci // Command buffer 558e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 559e5c31af7Sopenharmony_ci { 560e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 561e5c31af7Sopenharmony_ci DE_NULL, // pNext; 562e5c31af7Sopenharmony_ci *cmdPool, // commandPool; 563e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 564e5c31af7Sopenharmony_ci 1u, // bufferCount; 565e5c31af7Sopenharmony_ci }; 566e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 567e5c31af7Sopenharmony_ci 568e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Buffer was created correctly."); 569e5c31af7Sopenharmony_ci} 570e5c31af7Sopenharmony_ci 571e5c31af7Sopenharmony_citcu::TestStatus allocateManyPrimaryBuffersTest(Context& context) 572e5c31af7Sopenharmony_ci{ 573e5c31af7Sopenharmony_ci 574e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 575e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 576e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 577e5c31af7Sopenharmony_ci 578e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 579e5c31af7Sopenharmony_ci { 580e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 581e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 582e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 583e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 584e5c31af7Sopenharmony_ci }; 585e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 586e5c31af7Sopenharmony_ci 587e5c31af7Sopenharmony_ci // \todo Determining the minimum number of command buffers should be a function of available system memory and driver capabilities. 588e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 589e5c31af7Sopenharmony_ci #if (DE_PTR_SIZE == 4) 590e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 1024; 591e5c31af7Sopenharmony_ci #else 592e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 10000; 593e5c31af7Sopenharmony_ci #endif 594e5c31af7Sopenharmony_ci#else 595e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 100; 596e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 597e5c31af7Sopenharmony_ci 598e5c31af7Sopenharmony_ci // Command buffer 599e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 600e5c31af7Sopenharmony_ci { 601e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 602e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 603e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 604e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 605e5c31af7Sopenharmony_ci minCommandBuffer, // uint32_t bufferCount; 606e5c31af7Sopenharmony_ci }; 607e5c31af7Sopenharmony_ci 608e5c31af7Sopenharmony_ci // do not keep the handles to buffers, as they will be freed with command pool 609e5c31af7Sopenharmony_ci 610e5c31af7Sopenharmony_ci // allocate the minimum required amount of buffers 611e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[minCommandBuffer]; 612e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 613e5c31af7Sopenharmony_ci 614e5c31af7Sopenharmony_ci std::ostringstream out; 615e5c31af7Sopenharmony_ci out << "allocateManyPrimaryBuffersTest succeded: created " << minCommandBuffer << " command buffers"; 616e5c31af7Sopenharmony_ci 617e5c31af7Sopenharmony_ci return tcu::TestStatus::pass(out.str()); 618e5c31af7Sopenharmony_ci} 619e5c31af7Sopenharmony_ci 620e5c31af7Sopenharmony_citcu::TestStatus allocateSecondaryBufferTest(Context& context) 621e5c31af7Sopenharmony_ci{ 622e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 623e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 624e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 625e5c31af7Sopenharmony_ci 626e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 627e5c31af7Sopenharmony_ci { 628e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 629e5c31af7Sopenharmony_ci DE_NULL, // pNext; 630e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 631e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 632e5c31af7Sopenharmony_ci }; 633e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 634e5c31af7Sopenharmony_ci 635e5c31af7Sopenharmony_ci // Command buffer 636e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 637e5c31af7Sopenharmony_ci { 638e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 639e5c31af7Sopenharmony_ci DE_NULL, // pNext; 640e5c31af7Sopenharmony_ci *cmdPool, // commandPool; 641e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level; 642e5c31af7Sopenharmony_ci 1u, // bufferCount; 643e5c31af7Sopenharmony_ci }; 644e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 645e5c31af7Sopenharmony_ci 646e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Buffer was created correctly."); 647e5c31af7Sopenharmony_ci} 648e5c31af7Sopenharmony_ci 649e5c31af7Sopenharmony_citcu::TestStatus allocateManySecondaryBuffersTest(Context& context) 650e5c31af7Sopenharmony_ci{ 651e5c31af7Sopenharmony_ci 652e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 653e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 654e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 655e5c31af7Sopenharmony_ci 656e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 657e5c31af7Sopenharmony_ci { 658e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 659e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 660e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 661e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 662e5c31af7Sopenharmony_ci }; 663e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 664e5c31af7Sopenharmony_ci 665e5c31af7Sopenharmony_ci // \todo Determining the minimum number of command buffers should be a function of available system memory and driver capabilities. 666e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 667e5c31af7Sopenharmony_ci #if (DE_PTR_SIZE == 4) 668e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 1024; 669e5c31af7Sopenharmony_ci #else 670e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 10000; 671e5c31af7Sopenharmony_ci #endif 672e5c31af7Sopenharmony_ci#else 673e5c31af7Sopenharmony_ci const unsigned minCommandBuffer = 100; 674e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 675e5c31af7Sopenharmony_ci 676e5c31af7Sopenharmony_ci // Command buffer 677e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 678e5c31af7Sopenharmony_ci { 679e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 680e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 681e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 682e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 683e5c31af7Sopenharmony_ci minCommandBuffer, // uint32_t bufferCount; 684e5c31af7Sopenharmony_ci }; 685e5c31af7Sopenharmony_ci 686e5c31af7Sopenharmony_ci // do not keep the handles to buffers, as they will be freed with command pool 687e5c31af7Sopenharmony_ci 688e5c31af7Sopenharmony_ci // allocate the minimum required amount of buffers 689e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[minCommandBuffer]; 690e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 691e5c31af7Sopenharmony_ci 692e5c31af7Sopenharmony_ci std::ostringstream out; 693e5c31af7Sopenharmony_ci out << "allocateManySecondaryBuffersTest succeded: created " << minCommandBuffer << " command buffers"; 694e5c31af7Sopenharmony_ci 695e5c31af7Sopenharmony_ci return tcu::TestStatus::pass(out.str()); 696e5c31af7Sopenharmony_ci} 697e5c31af7Sopenharmony_ci 698e5c31af7Sopenharmony_citcu::TestStatus executePrimaryBufferTest(Context& context) 699e5c31af7Sopenharmony_ci{ 700e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 701e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 702e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 703e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 704e5c31af7Sopenharmony_ci 705e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 706e5c31af7Sopenharmony_ci { 707e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 708e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 709e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 710e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 711e5c31af7Sopenharmony_ci }; 712e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 713e5c31af7Sopenharmony_ci 714e5c31af7Sopenharmony_ci // Command buffer 715e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 716e5c31af7Sopenharmony_ci { 717e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 718e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 719e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 720e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 721e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 722e5c31af7Sopenharmony_ci }; 723e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 724e5c31af7Sopenharmony_ci 725e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 726e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 727e5c31af7Sopenharmony_ci 728e5c31af7Sopenharmony_ci // reset event 729e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 730e5c31af7Sopenharmony_ci 731e5c31af7Sopenharmony_ci // record primary command buffer 732e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 733e5c31af7Sopenharmony_ci { 734e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 735e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 736e5c31af7Sopenharmony_ci 737e5c31af7Sopenharmony_ci // record setting event 738e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 739e5c31af7Sopenharmony_ci } 740e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 741e5c31af7Sopenharmony_ci 742e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 743e5c31af7Sopenharmony_ci 744e5c31af7Sopenharmony_ci // check if buffer has been executed 745e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 746e5c31af7Sopenharmony_ci if (result == VK_EVENT_SET) 747e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Execute Primary Command Buffer succeeded"); 748e5c31af7Sopenharmony_ci 749e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Execute Primary Command Buffer FAILED"); 750e5c31af7Sopenharmony_ci} 751e5c31af7Sopenharmony_ci 752e5c31af7Sopenharmony_citcu::TestStatus executeLargePrimaryBufferTest(Context& context) 753e5c31af7Sopenharmony_ci{ 754e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 755e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 756e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 757e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 758e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 759e5c31af7Sopenharmony_ci const deUint32 LARGE_BUFFER_SIZE = 10000; 760e5c31af7Sopenharmony_ci#else 761e5c31af7Sopenharmony_ci const deUint32 LARGE_BUFFER_SIZE = 100; 762e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 763e5c31af7Sopenharmony_ci 764e5c31af7Sopenharmony_ci 765e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 766e5c31af7Sopenharmony_ci { 767e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 768e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 769e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 770e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 771e5c31af7Sopenharmony_ci }; 772e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 773e5c31af7Sopenharmony_ci 774e5c31af7Sopenharmony_ci // Command buffer 775e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 776e5c31af7Sopenharmony_ci { 777e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 778e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 779e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 780e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 781e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 782e5c31af7Sopenharmony_ci }; 783e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 784e5c31af7Sopenharmony_ci 785e5c31af7Sopenharmony_ci std::vector<VkEventSp> events; 786e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx) 787e5c31af7Sopenharmony_ci events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice)))); 788e5c31af7Sopenharmony_ci 789e5c31af7Sopenharmony_ci // record primary command buffer 790e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 791e5c31af7Sopenharmony_ci { 792e5c31af7Sopenharmony_ci // set all the events 793e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx) 794e5c31af7Sopenharmony_ci { 795e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 796e5c31af7Sopenharmony_ci } 797e5c31af7Sopenharmony_ci } 798e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 799e5c31af7Sopenharmony_ci 800e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 801e5c31af7Sopenharmony_ci 802e5c31af7Sopenharmony_ci // check if the buffer was executed correctly - all events had their status 803e5c31af7Sopenharmony_ci // changed 804e5c31af7Sopenharmony_ci tcu::TestStatus testResult = tcu::TestStatus::incomplete(); 805e5c31af7Sopenharmony_ci 806e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < LARGE_BUFFER_SIZE; ++ndx) 807e5c31af7Sopenharmony_ci { 808e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, events[ndx]->get()) != VK_EVENT_SET) 809e5c31af7Sopenharmony_ci { 810e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::fail("An event was not set."); 811e5c31af7Sopenharmony_ci break; 812e5c31af7Sopenharmony_ci } 813e5c31af7Sopenharmony_ci } 814e5c31af7Sopenharmony_ci 815e5c31af7Sopenharmony_ci if (!testResult.isComplete()) 816e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::pass("All events set correctly."); 817e5c31af7Sopenharmony_ci 818e5c31af7Sopenharmony_ci return testResult; 819e5c31af7Sopenharmony_ci} 820e5c31af7Sopenharmony_ci 821e5c31af7Sopenharmony_citcu::TestStatus resetBufferImplicitlyTest(Context& context) 822e5c31af7Sopenharmony_ci{ 823e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 824e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 825e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 826e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 827e5c31af7Sopenharmony_ci 828e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 829e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().commandPoolResetCommandBuffer == VK_FALSE) 830e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandPoolResetCommandBuffer not supported by this implementation"); 831e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 832e5c31af7Sopenharmony_ci 833e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 834e5c31af7Sopenharmony_ci { 835e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 836e5c31af7Sopenharmony_ci DE_NULL, // pNext; 837e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 838e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 839e5c31af7Sopenharmony_ci }; 840e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 841e5c31af7Sopenharmony_ci 842e5c31af7Sopenharmony_ci // Command buffer 843e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 844e5c31af7Sopenharmony_ci { 845e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 846e5c31af7Sopenharmony_ci DE_NULL, // pNext; 847e5c31af7Sopenharmony_ci *cmdPool, // pool; 848e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 849e5c31af7Sopenharmony_ci 1u, // bufferCount; 850e5c31af7Sopenharmony_ci }; 851e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 852e5c31af7Sopenharmony_ci 853e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 854e5c31af7Sopenharmony_ci 855e5c31af7Sopenharmony_ci // Put the command buffer in recording state. 856e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuf, 0u); 857e5c31af7Sopenharmony_ci { 858e5c31af7Sopenharmony_ci // Set the event 859e5c31af7Sopenharmony_ci vk.cmdSetEvent(*cmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 860e5c31af7Sopenharmony_ci } 861e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuf); 862e5c31af7Sopenharmony_ci 863e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, cmdBuf.get()); 864e5c31af7Sopenharmony_ci 865e5c31af7Sopenharmony_ci // Check if the buffer was executed 866e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, *event) != VK_EVENT_SET) 867e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed to set the event."); 868e5c31af7Sopenharmony_ci 869e5c31af7Sopenharmony_ci // Reset the event 870e5c31af7Sopenharmony_ci vk.resetEvent(vkDevice, *event); 871e5c31af7Sopenharmony_ci if(vk.getEventStatus(vkDevice, *event) != VK_EVENT_RESET) 872e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Failed to reset the event."); 873e5c31af7Sopenharmony_ci 874e5c31af7Sopenharmony_ci // Reset the command buffer by putting it in recording state again. This 875e5c31af7Sopenharmony_ci // should empty the command buffer. 876e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuf, 0u); 877e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuf); 878e5c31af7Sopenharmony_ci 879e5c31af7Sopenharmony_ci // Submit the command buffer after resetting. It should have no commands 880e5c31af7Sopenharmony_ci // recorded, so the event should remain unsignaled. 881e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, cmdBuf.get()); 882e5c31af7Sopenharmony_ci 883e5c31af7Sopenharmony_ci // Check if the event remained unset. 884e5c31af7Sopenharmony_ci if(vk.getEventStatus(vkDevice, *event) == VK_EVENT_RESET) 885e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Buffer was reset correctly."); 886e5c31af7Sopenharmony_ci else 887e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Buffer was not reset correctly."); 888e5c31af7Sopenharmony_ci} 889e5c31af7Sopenharmony_ci 890e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 891e5c31af7Sopenharmony_ci 892e5c31af7Sopenharmony_ciusing de::SharedPtr; 893e5c31af7Sopenharmony_citypedef SharedPtr<Unique<VkEvent> > VkEventShared; 894e5c31af7Sopenharmony_ci 895e5c31af7Sopenharmony_citemplate<typename T> 896e5c31af7Sopenharmony_ciinline SharedPtr<Unique<T> > makeSharedPtr (Move<T> move) 897e5c31af7Sopenharmony_ci{ 898e5c31af7Sopenharmony_ci return SharedPtr<Unique<T> >(new Unique<T>(move)); 899e5c31af7Sopenharmony_ci} 900e5c31af7Sopenharmony_ci 901e5c31af7Sopenharmony_cibool submitAndCheck (Context& context, std::vector<VkCommandBuffer>& cmdBuffers, std::vector <VkEventShared>& events) 902e5c31af7Sopenharmony_ci{ 903e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 904e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 905e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 906e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 907e5c31af7Sopenharmony_ci 908e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo = 909e5c31af7Sopenharmony_ci { 910e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 911e5c31af7Sopenharmony_ci DE_NULL, // pNext 912e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 913e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 914e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 915e5c31af7Sopenharmony_ci static_cast<deUint32>(cmdBuffers.size()), // commandBufferCount 916e5c31af7Sopenharmony_ci &cmdBuffers[0], // pCommandBuffers 917e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 918e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 919e5c31af7Sopenharmony_ci }; 920e5c31af7Sopenharmony_ci 921e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get())); 922e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), 0u, INFINITE_TIMEOUT)); 923e5c31af7Sopenharmony_ci 924e5c31af7Sopenharmony_ci for(int eventNdx = 0; eventNdx < static_cast<int>(events.size()); ++eventNdx) 925e5c31af7Sopenharmony_ci { 926e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, **events[eventNdx]) != VK_EVENT_SET) 927e5c31af7Sopenharmony_ci return false; 928e5c31af7Sopenharmony_ci vk.resetEvent(vkDevice, **events[eventNdx]); 929e5c31af7Sopenharmony_ci } 930e5c31af7Sopenharmony_ci 931e5c31af7Sopenharmony_ci return true; 932e5c31af7Sopenharmony_ci} 933e5c31af7Sopenharmony_ci 934e5c31af7Sopenharmony_civoid createCommadBuffers (const DeviceInterface& vk, 935e5c31af7Sopenharmony_ci const VkDevice vkDevice, 936e5c31af7Sopenharmony_ci deUint32 bufferCount, 937e5c31af7Sopenharmony_ci VkCommandPool pool, 938e5c31af7Sopenharmony_ci const VkCommandBufferLevel cmdBufferLevel, 939e5c31af7Sopenharmony_ci VkCommandBuffer* pCommandBuffers) 940e5c31af7Sopenharmony_ci{ 941e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 942e5c31af7Sopenharmony_ci { 943e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 944e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 945e5c31af7Sopenharmony_ci pool, // VkCommandPool pool; 946e5c31af7Sopenharmony_ci cmdBufferLevel, // VkCommandBufferLevel level; 947e5c31af7Sopenharmony_ci bufferCount, // uint32_t bufferCount; 948e5c31af7Sopenharmony_ci }; 949e5c31af7Sopenharmony_ci VK_CHECK(vk.allocateCommandBuffers(vkDevice, &cmdBufParams, pCommandBuffers)); 950e5c31af7Sopenharmony_ci} 951e5c31af7Sopenharmony_ci 952e5c31af7Sopenharmony_civoid addCommandsToBuffer (const DeviceInterface& vk, std::vector<VkCommandBuffer>& cmdBuffers, std::vector <VkEventShared>& events) 953e5c31af7Sopenharmony_ci{ 954e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 955e5c31af7Sopenharmony_ci { 956e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 957e5c31af7Sopenharmony_ci DE_NULL, 958e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 959e5c31af7Sopenharmony_ci 0u, // subpass 960e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 961e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 962e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 963e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 964e5c31af7Sopenharmony_ci }; 965e5c31af7Sopenharmony_ci 966e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 967e5c31af7Sopenharmony_ci { 968e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 969e5c31af7Sopenharmony_ci DE_NULL, // pNext 970e5c31af7Sopenharmony_ci 0u, // flags 971e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, // pInheritanceInfo; 972e5c31af7Sopenharmony_ci }; 973e5c31af7Sopenharmony_ci 974e5c31af7Sopenharmony_ci for(int bufferNdx = 0; bufferNdx < static_cast<int>(cmdBuffers.size()); ++bufferNdx) 975e5c31af7Sopenharmony_ci { 976e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[bufferNdx], &cmdBufBeginInfo)); 977e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[bufferNdx], **events[bufferNdx % events.size()], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 978e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffers[bufferNdx]); 979e5c31af7Sopenharmony_ci } 980e5c31af7Sopenharmony_ci} 981e5c31af7Sopenharmony_ci 982e5c31af7Sopenharmony_cibool executeSecondaryCmdBuffer (Context& context, 983e5c31af7Sopenharmony_ci VkCommandPool pool, 984e5c31af7Sopenharmony_ci std::vector<VkCommandBuffer>& cmdBuffersSecondary, 985e5c31af7Sopenharmony_ci std::vector <VkEventShared>& events) 986e5c31af7Sopenharmony_ci{ 987e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 988e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 989e5c31af7Sopenharmony_ci std::vector<VkCommandBuffer> cmdBuffer (1); 990e5c31af7Sopenharmony_ci 991e5c31af7Sopenharmony_ci createCommadBuffers(vk, vkDevice, 1u, pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, &cmdBuffer[0]); 992e5c31af7Sopenharmony_ci beginCommandBuffer(vk, cmdBuffer[0], 0u); 993e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(cmdBuffer[0], static_cast<deUint32>(cmdBuffersSecondary.size()), &cmdBuffersSecondary[0]); 994e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffer[0]); 995e5c31af7Sopenharmony_ci 996e5c31af7Sopenharmony_ci bool returnValue = submitAndCheck(context, cmdBuffer, events); 997e5c31af7Sopenharmony_ci vk.freeCommandBuffers(vkDevice, pool, 1u, &cmdBuffer[0]); 998e5c31af7Sopenharmony_ci return returnValue; 999e5c31af7Sopenharmony_ci} 1000e5c31af7Sopenharmony_ci 1001e5c31af7Sopenharmony_citcu::TestStatus trimCommandPoolTest (Context& context, const VkCommandBufferLevel cmdBufferLevel) 1002e5c31af7Sopenharmony_ci{ 1003e5c31af7Sopenharmony_ci if (!context.isDeviceFunctionalitySupported("VK_KHR_maintenance1")) 1004e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance1 not supported"); 1005e5c31af7Sopenharmony_ci 1006e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1007e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1008e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1009e5c31af7Sopenharmony_ci 1010e5c31af7Sopenharmony_ci //test parameters 1011e5c31af7Sopenharmony_ci const deUint32 cmdBufferIterationCount = 300u; 1012e5c31af7Sopenharmony_ci const deUint32 cmdBufferCount = 10u; 1013e5c31af7Sopenharmony_ci 1014e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1015e5c31af7Sopenharmony_ci { 1016e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 1017e5c31af7Sopenharmony_ci DE_NULL, // pNext; 1018e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 1019e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 1020e5c31af7Sopenharmony_ci }; 1021e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1022e5c31af7Sopenharmony_ci 1023e5c31af7Sopenharmony_ci std::vector <VkEventShared> events; 1024e5c31af7Sopenharmony_ci for (deUint32 ndx = 0u; ndx < cmdBufferCount; ++ndx) 1025e5c31af7Sopenharmony_ci events.push_back(makeSharedPtr(createEvent(vk, vkDevice))); 1026e5c31af7Sopenharmony_ci 1027e5c31af7Sopenharmony_ci { 1028e5c31af7Sopenharmony_ci std::vector<VkCommandBuffer> cmdBuffers(cmdBufferCount); 1029e5c31af7Sopenharmony_ci createCommadBuffers(vk, vkDevice, cmdBufferCount, *cmdPool, cmdBufferLevel, &cmdBuffers[0]); 1030e5c31af7Sopenharmony_ci 1031e5c31af7Sopenharmony_ci for (deUint32 cmdBufferIterationrNdx = 0; cmdBufferIterationrNdx < cmdBufferIterationCount; ++cmdBufferIterationrNdx) 1032e5c31af7Sopenharmony_ci { 1033e5c31af7Sopenharmony_ci addCommandsToBuffer(vk, cmdBuffers, events); 1034e5c31af7Sopenharmony_ci 1035e5c31af7Sopenharmony_ci //Peak, situation when we use a lot more command buffers 1036e5c31af7Sopenharmony_ci if (cmdBufferIterationrNdx % 10u == 0) 1037e5c31af7Sopenharmony_ci { 1038e5c31af7Sopenharmony_ci std::vector<VkCommandBuffer> cmdBuffersPeak(cmdBufferCount * 10u); 1039e5c31af7Sopenharmony_ci createCommadBuffers(vk, vkDevice, static_cast<deUint32>(cmdBuffersPeak.size()), *cmdPool, cmdBufferLevel, &cmdBuffersPeak[0]); 1040e5c31af7Sopenharmony_ci addCommandsToBuffer(vk, cmdBuffersPeak, events); 1041e5c31af7Sopenharmony_ci 1042e5c31af7Sopenharmony_ci switch(cmdBufferLevel) 1043e5c31af7Sopenharmony_ci { 1044e5c31af7Sopenharmony_ci case VK_COMMAND_BUFFER_LEVEL_PRIMARY: 1045e5c31af7Sopenharmony_ci if (!submitAndCheck(context, cmdBuffersPeak, events)) 1046e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Fail"); 1047e5c31af7Sopenharmony_ci break; 1048e5c31af7Sopenharmony_ci case VK_COMMAND_BUFFER_LEVEL_SECONDARY: 1049e5c31af7Sopenharmony_ci if (!executeSecondaryCmdBuffer(context, *cmdPool, cmdBuffersPeak, events)) 1050e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Fail"); 1051e5c31af7Sopenharmony_ci break; 1052e5c31af7Sopenharmony_ci default: 1053e5c31af7Sopenharmony_ci DE_ASSERT(0); 1054e5c31af7Sopenharmony_ci } 1055e5c31af7Sopenharmony_ci vk.freeCommandBuffers(vkDevice, *cmdPool, static_cast<deUint32>(cmdBuffersPeak.size()), &cmdBuffersPeak[0]); 1056e5c31af7Sopenharmony_ci } 1057e5c31af7Sopenharmony_ci 1058e5c31af7Sopenharmony_ci vk.trimCommandPool(vkDevice, *cmdPool, (VkCommandPoolTrimFlags)0); 1059e5c31af7Sopenharmony_ci 1060e5c31af7Sopenharmony_ci switch(cmdBufferLevel) 1061e5c31af7Sopenharmony_ci { 1062e5c31af7Sopenharmony_ci case VK_COMMAND_BUFFER_LEVEL_PRIMARY: 1063e5c31af7Sopenharmony_ci if (!submitAndCheck(context, cmdBuffers, events)) 1064e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Fail"); 1065e5c31af7Sopenharmony_ci break; 1066e5c31af7Sopenharmony_ci case VK_COMMAND_BUFFER_LEVEL_SECONDARY: 1067e5c31af7Sopenharmony_ci if (!executeSecondaryCmdBuffer(context, *cmdPool, cmdBuffers, events)) 1068e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Fail"); 1069e5c31af7Sopenharmony_ci break; 1070e5c31af7Sopenharmony_ci default: 1071e5c31af7Sopenharmony_ci DE_ASSERT(0); 1072e5c31af7Sopenharmony_ci } 1073e5c31af7Sopenharmony_ci 1074e5c31af7Sopenharmony_ci for (deUint32 bufferNdx = cmdBufferIterationrNdx % 3u; bufferNdx < cmdBufferCount; bufferNdx+=2u) 1075e5c31af7Sopenharmony_ci { 1076e5c31af7Sopenharmony_ci vk.freeCommandBuffers(vkDevice, *cmdPool, 1u, &cmdBuffers[bufferNdx]); 1077e5c31af7Sopenharmony_ci createCommadBuffers(vk, vkDevice, 1u, *cmdPool, cmdBufferLevel, &cmdBuffers[bufferNdx]); 1078e5c31af7Sopenharmony_ci } 1079e5c31af7Sopenharmony_ci } 1080e5c31af7Sopenharmony_ci } 1081e5c31af7Sopenharmony_ci 1082e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Pass"); 1083e5c31af7Sopenharmony_ci} 1084e5c31af7Sopenharmony_ci 1085e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1086e5c31af7Sopenharmony_ci 1087e5c31af7Sopenharmony_ci/******** 19.3. Command Buffer Recording (5.3 in VK 1.0 Spec) *****************/ 1088e5c31af7Sopenharmony_citcu::TestStatus recordSinglePrimaryBufferTest(Context& context) 1089e5c31af7Sopenharmony_ci{ 1090e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1091e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1092e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1093e5c31af7Sopenharmony_ci 1094e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1095e5c31af7Sopenharmony_ci { 1096e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1097e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1098e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1099e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1100e5c31af7Sopenharmony_ci }; 1101e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1102e5c31af7Sopenharmony_ci 1103e5c31af7Sopenharmony_ci // Command buffer 1104e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1105e5c31af7Sopenharmony_ci { 1106e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1107e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1108e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1109e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1110e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1111e5c31af7Sopenharmony_ci }; 1112e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1113e5c31af7Sopenharmony_ci 1114e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1115e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1116e5c31af7Sopenharmony_ci 1117e5c31af7Sopenharmony_ci // record primary command buffer 1118e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 1119e5c31af7Sopenharmony_ci { 1120e5c31af7Sopenharmony_ci // record setting event 1121e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 1122e5c31af7Sopenharmony_ci } 1123e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1124e5c31af7Sopenharmony_ci 1125e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Primary buffer recorded successfully."); 1126e5c31af7Sopenharmony_ci} 1127e5c31af7Sopenharmony_ci 1128e5c31af7Sopenharmony_citcu::TestStatus recordLargePrimaryBufferTest(Context &context) 1129e5c31af7Sopenharmony_ci{ 1130e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1131e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1132e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1133e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1134e5c31af7Sopenharmony_ci 1135e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1136e5c31af7Sopenharmony_ci { 1137e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1138e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1139e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1140e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1141e5c31af7Sopenharmony_ci }; 1142e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1143e5c31af7Sopenharmony_ci 1144e5c31af7Sopenharmony_ci // Command buffer 1145e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1146e5c31af7Sopenharmony_ci { 1147e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1148e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1149e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1150e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1151e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1152e5c31af7Sopenharmony_ci }; 1153e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1154e5c31af7Sopenharmony_ci 1155e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1156e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1157e5c31af7Sopenharmony_ci 1158e5c31af7Sopenharmony_ci // reset event 1159e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1160e5c31af7Sopenharmony_ci 1161e5c31af7Sopenharmony_ci // record primary command buffer 1162e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 1163e5c31af7Sopenharmony_ci { 1164e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1165e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1166e5c31af7Sopenharmony_ci 1167e5c31af7Sopenharmony_ci // define minimal amount of commands to accept 1168e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 1169e5c31af7Sopenharmony_ci const long long unsigned minNumCommands = 10000llu; 1170e5c31af7Sopenharmony_ci#else 1171e5c31af7Sopenharmony_ci const long long unsigned minNumCommands = 1000llu; 1172e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1173e5c31af7Sopenharmony_ci 1174e5c31af7Sopenharmony_ci for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands ) 1175e5c31af7Sopenharmony_ci { 1176e5c31af7Sopenharmony_ci // record setting event 1177e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 1178e5c31af7Sopenharmony_ci 1179e5c31af7Sopenharmony_ci // record resetting event 1180e5c31af7Sopenharmony_ci vk.cmdResetEvent(*primCmdBuf, *event,stageMask); 1181e5c31af7Sopenharmony_ci } 1182e5c31af7Sopenharmony_ci 1183e5c31af7Sopenharmony_ci } 1184e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1185e5c31af7Sopenharmony_ci 1186e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1187e5c31af7Sopenharmony_ci 1188e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("hugeTest succeeded"); 1189e5c31af7Sopenharmony_ci} 1190e5c31af7Sopenharmony_ci 1191e5c31af7Sopenharmony_citcu::TestStatus recordSingleSecondaryBufferTest(Context& context) 1192e5c31af7Sopenharmony_ci{ 1193e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1194e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1195e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1196e5c31af7Sopenharmony_ci 1197e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1198e5c31af7Sopenharmony_ci { 1199e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1200e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1201e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1202e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1203e5c31af7Sopenharmony_ci }; 1204e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1205e5c31af7Sopenharmony_ci 1206e5c31af7Sopenharmony_ci // Command buffer 1207e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1208e5c31af7Sopenharmony_ci { 1209e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1210e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1211e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1212e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 1213e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1214e5c31af7Sopenharmony_ci }; 1215e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1216e5c31af7Sopenharmony_ci 1217e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 1218e5c31af7Sopenharmony_ci { 1219e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 1220e5c31af7Sopenharmony_ci DE_NULL, 1221e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 1222e5c31af7Sopenharmony_ci 0u, // subpass 1223e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 1224e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 1225e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 1226e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 1227e5c31af7Sopenharmony_ci }; 1228e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 1229e5c31af7Sopenharmony_ci { 1230e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 1231e5c31af7Sopenharmony_ci DE_NULL, 1232e5c31af7Sopenharmony_ci 0, // flags 1233e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 1234e5c31af7Sopenharmony_ci }; 1235e5c31af7Sopenharmony_ci 1236e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1237e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1238e5c31af7Sopenharmony_ci 1239e5c31af7Sopenharmony_ci // record primary command buffer 1240e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1241e5c31af7Sopenharmony_ci { 1242e5c31af7Sopenharmony_ci // record setting event 1243e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 1244e5c31af7Sopenharmony_ci } 1245e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1246e5c31af7Sopenharmony_ci 1247e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Secondary buffer recorded successfully."); 1248e5c31af7Sopenharmony_ci} 1249e5c31af7Sopenharmony_ci 1250e5c31af7Sopenharmony_citcu::TestStatus recordLargeSecondaryBufferTest(Context &context) 1251e5c31af7Sopenharmony_ci{ 1252e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1253e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1254e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1255e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1256e5c31af7Sopenharmony_ci 1257e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1258e5c31af7Sopenharmony_ci { 1259e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1260e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1261e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1262e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1263e5c31af7Sopenharmony_ci }; 1264e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1265e5c31af7Sopenharmony_ci const Unique<VkCommandPool> secCmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1266e5c31af7Sopenharmony_ci // Command buffer 1267e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1268e5c31af7Sopenharmony_ci { 1269e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1270e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1271e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1272e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1273e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1274e5c31af7Sopenharmony_ci }; 1275e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1276e5c31af7Sopenharmony_ci 1277e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 1278e5c31af7Sopenharmony_ci { 1279e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1280e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1281e5c31af7Sopenharmony_ci *secCmdPool, // VkCommandPool pool; 1282e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 1283e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1284e5c31af7Sopenharmony_ci }; 1285e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 1286e5c31af7Sopenharmony_ci 1287e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 1288e5c31af7Sopenharmony_ci { 1289e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 1290e5c31af7Sopenharmony_ci DE_NULL, 1291e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 1292e5c31af7Sopenharmony_ci 0u, // subpass 1293e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 1294e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 1295e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 1296e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 1297e5c31af7Sopenharmony_ci }; 1298e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 1299e5c31af7Sopenharmony_ci { 1300e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 1301e5c31af7Sopenharmony_ci DE_NULL, 1302e5c31af7Sopenharmony_ci 0, // flags 1303e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 1304e5c31af7Sopenharmony_ci }; 1305e5c31af7Sopenharmony_ci 1306e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1307e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1308e5c31af7Sopenharmony_ci 1309e5c31af7Sopenharmony_ci // reset event 1310e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1311e5c31af7Sopenharmony_ci 1312e5c31af7Sopenharmony_ci // record primary command buffer 1313e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 1314e5c31af7Sopenharmony_ci { 1315e5c31af7Sopenharmony_ci // record secondary command buffer 1316e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1317e5c31af7Sopenharmony_ci { 1318e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1319e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1320e5c31af7Sopenharmony_ci 1321e5c31af7Sopenharmony_ci // define minimal amount of commands to accept 1322e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 1323e5c31af7Sopenharmony_ci const long long unsigned minNumCommands = 10000llu; 1324e5c31af7Sopenharmony_ci#else 1325e5c31af7Sopenharmony_ci const long long unsigned minNumCommands = 1000llu; 1326e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1327e5c31af7Sopenharmony_ci 1328e5c31af7Sopenharmony_ci for ( long long unsigned currentCommands = 0; currentCommands < minNumCommands / 2; ++currentCommands ) 1329e5c31af7Sopenharmony_ci { 1330e5c31af7Sopenharmony_ci // record setting event 1331e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event,stageMask); 1332e5c31af7Sopenharmony_ci 1333e5c31af7Sopenharmony_ci // record resetting event 1334e5c31af7Sopenharmony_ci vk.cmdResetEvent(*secCmdBuf, *event,stageMask); 1335e5c31af7Sopenharmony_ci } 1336e5c31af7Sopenharmony_ci } 1337e5c31af7Sopenharmony_ci 1338e5c31af7Sopenharmony_ci // end recording of secondary buffers 1339e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1340e5c31af7Sopenharmony_ci 1341e5c31af7Sopenharmony_ci // execute secondary buffer 1342e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get()); 1343e5c31af7Sopenharmony_ci } 1344e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1345e5c31af7Sopenharmony_ci 1346e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1347e5c31af7Sopenharmony_ci 1348e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("hugeTest succeeded"); 1349e5c31af7Sopenharmony_ci} 1350e5c31af7Sopenharmony_ci 1351e5c31af7Sopenharmony_citcu::TestStatus submitPrimaryBufferTwiceTest(Context& context) 1352e5c31af7Sopenharmony_ci{ 1353e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1354e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1355e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1356e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1357e5c31af7Sopenharmony_ci 1358e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1359e5c31af7Sopenharmony_ci { 1360e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1361e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1362e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1363e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1364e5c31af7Sopenharmony_ci }; 1365e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1366e5c31af7Sopenharmony_ci 1367e5c31af7Sopenharmony_ci // Command buffer 1368e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1369e5c31af7Sopenharmony_ci { 1370e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1371e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1372e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1373e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1374e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1375e5c31af7Sopenharmony_ci }; 1376e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1377e5c31af7Sopenharmony_ci 1378e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1379e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1380e5c31af7Sopenharmony_ci 1381e5c31af7Sopenharmony_ci // reset event 1382e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1383e5c31af7Sopenharmony_ci 1384e5c31af7Sopenharmony_ci // record primary command buffer 1385e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 1386e5c31af7Sopenharmony_ci { 1387e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1388e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1389e5c31af7Sopenharmony_ci 1390e5c31af7Sopenharmony_ci // record setting event 1391e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 1392e5c31af7Sopenharmony_ci } 1393e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1394e5c31af7Sopenharmony_ci 1395e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1396e5c31af7Sopenharmony_ci 1397e5c31af7Sopenharmony_ci // check if buffer has been executed 1398e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 1399e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1400e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Twice Test FAILED"); 1401e5c31af7Sopenharmony_ci 1402e5c31af7Sopenharmony_ci // reset event 1403e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1404e5c31af7Sopenharmony_ci 1405e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1406e5c31af7Sopenharmony_ci 1407e5c31af7Sopenharmony_ci // check if buffer has been executed 1408e5c31af7Sopenharmony_ci result = vk.getEventStatus(vkDevice,*event); 1409e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1410e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Twice Test FAILED"); 1411e5c31af7Sopenharmony_ci else 1412e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Submit Twice Test succeeded"); 1413e5c31af7Sopenharmony_ci} 1414e5c31af7Sopenharmony_ci 1415e5c31af7Sopenharmony_citcu::TestStatus submitSecondaryBufferTwiceTest(Context& context) 1416e5c31af7Sopenharmony_ci{ 1417e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1418e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1419e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1420e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1421e5c31af7Sopenharmony_ci 1422e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 1423e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().commandPoolResetCommandBuffer == VK_FALSE) 1424e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandPoolResetCommandBuffer not supported by this implementation"); 1425e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1426e5c31af7Sopenharmony_ci 1427e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1428e5c31af7Sopenharmony_ci { 1429e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1430e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1431e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1432e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1433e5c31af7Sopenharmony_ci }; 1434e5c31af7Sopenharmony_ci 1435e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1436e5c31af7Sopenharmony_ci const Unique<VkCommandPool> secCmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1437e5c31af7Sopenharmony_ci 1438e5c31af7Sopenharmony_ci // Command buffer 1439e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1440e5c31af7Sopenharmony_ci { 1441e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1442e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1443e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1444e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1445e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1446e5c31af7Sopenharmony_ci }; 1447e5c31af7Sopenharmony_ci 1448e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf1 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1449e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf2 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1450e5c31af7Sopenharmony_ci 1451e5c31af7Sopenharmony_ci // Secondary Command buffer 1452e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 1453e5c31af7Sopenharmony_ci { 1454e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1455e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1456e5c31af7Sopenharmony_ci *secCmdPool, // VkCommandPool pool; 1457e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 1458e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1459e5c31af7Sopenharmony_ci }; 1460e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 1461e5c31af7Sopenharmony_ci 1462e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 1463e5c31af7Sopenharmony_ci { 1464e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 1465e5c31af7Sopenharmony_ci DE_NULL, 1466e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 1467e5c31af7Sopenharmony_ci 0u, // subpass 1468e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 1469e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 1470e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 1471e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 1472e5c31af7Sopenharmony_ci }; 1473e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 1474e5c31af7Sopenharmony_ci { 1475e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 1476e5c31af7Sopenharmony_ci DE_NULL, 1477e5c31af7Sopenharmony_ci 0u, // flags 1478e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 1479e5c31af7Sopenharmony_ci }; 1480e5c31af7Sopenharmony_ci 1481e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1482e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1483e5c31af7Sopenharmony_ci 1484e5c31af7Sopenharmony_ci // reset event 1485e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1486e5c31af7Sopenharmony_ci 1487e5c31af7Sopenharmony_ci // record first primary command buffer 1488e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf1, 0u); 1489e5c31af7Sopenharmony_ci { 1490e5c31af7Sopenharmony_ci // record secondary command buffer 1491e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1492e5c31af7Sopenharmony_ci { 1493e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1494e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1495e5c31af7Sopenharmony_ci 1496e5c31af7Sopenharmony_ci // record setting event 1497e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event,stageMask); 1498e5c31af7Sopenharmony_ci } 1499e5c31af7Sopenharmony_ci 1500e5c31af7Sopenharmony_ci // end recording of secondary buffers 1501e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1502e5c31af7Sopenharmony_ci 1503e5c31af7Sopenharmony_ci // execute secondary buffer 1504e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get()); 1505e5c31af7Sopenharmony_ci } 1506e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf1); 1507e5c31af7Sopenharmony_ci 1508e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf1.get()); 1509e5c31af7Sopenharmony_ci 1510e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 1511e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 1512e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1513e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED"); 1514e5c31af7Sopenharmony_ci 1515e5c31af7Sopenharmony_ci // reset first primary buffer 1516e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandBuffer( *primCmdBuf1, 0u)); 1517e5c31af7Sopenharmony_ci 1518e5c31af7Sopenharmony_ci // reset event to allow receiving it again 1519e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1520e5c31af7Sopenharmony_ci 1521e5c31af7Sopenharmony_ci // record second primary command buffer 1522e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf2, 0u); 1523e5c31af7Sopenharmony_ci { 1524e5c31af7Sopenharmony_ci // execute secondary buffer 1525e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get()); 1526e5c31af7Sopenharmony_ci } 1527e5c31af7Sopenharmony_ci // end recording 1528e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf2); 1529e5c31af7Sopenharmony_ci 1530e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf2.get()); 1531e5c31af7Sopenharmony_ci 1532e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 1533e5c31af7Sopenharmony_ci result = vk.getEventStatus(vkDevice,*event); 1534e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1535e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED"); 1536e5c31af7Sopenharmony_ci else 1537e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Submit Twice Secondary Command Buffer succeeded"); 1538e5c31af7Sopenharmony_ci} 1539e5c31af7Sopenharmony_ci 1540e5c31af7Sopenharmony_citcu::TestStatus oneTimeSubmitFlagPrimaryBufferTest(Context& context) 1541e5c31af7Sopenharmony_ci{ 1542e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1543e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1544e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1545e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1546e5c31af7Sopenharmony_ci 1547e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 1548e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().commandPoolResetCommandBuffer == VK_FALSE) 1549e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandPoolResetCommandBuffer not supported by this implementation"); 1550e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1551e5c31af7Sopenharmony_ci 1552e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1553e5c31af7Sopenharmony_ci { 1554e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1555e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1556e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1557e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1558e5c31af7Sopenharmony_ci }; 1559e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1560e5c31af7Sopenharmony_ci 1561e5c31af7Sopenharmony_ci // Command buffer 1562e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1563e5c31af7Sopenharmony_ci { 1564e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1565e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1566e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1567e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1568e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1569e5c31af7Sopenharmony_ci }; 1570e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1571e5c31af7Sopenharmony_ci 1572e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1573e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1574e5c31af7Sopenharmony_ci 1575e5c31af7Sopenharmony_ci // reset event 1576e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1577e5c31af7Sopenharmony_ci 1578e5c31af7Sopenharmony_ci // record primary command buffer 1579e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf); 1580e5c31af7Sopenharmony_ci { 1581e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1582e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1583e5c31af7Sopenharmony_ci 1584e5c31af7Sopenharmony_ci // record setting event 1585e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 1586e5c31af7Sopenharmony_ci } 1587e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1588e5c31af7Sopenharmony_ci 1589e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1590e5c31af7Sopenharmony_ci 1591e5c31af7Sopenharmony_ci // check if buffer has been executed 1592e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 1593e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1594e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED"); 1595e5c31af7Sopenharmony_ci 1596e5c31af7Sopenharmony_ci // record primary command buffer again - implicit reset because of VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT 1597e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf); 1598e5c31af7Sopenharmony_ci { 1599e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1600e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1601e5c31af7Sopenharmony_ci 1602e5c31af7Sopenharmony_ci // record setting event 1603e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 1604e5c31af7Sopenharmony_ci } 1605e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1606e5c31af7Sopenharmony_ci 1607e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1608e5c31af7Sopenharmony_ci 1609e5c31af7Sopenharmony_ci // check if buffer has been executed 1610e5c31af7Sopenharmony_ci result = vk.getEventStatus(vkDevice,*event); 1611e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1612e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("oneTimeSubmitFlagPrimaryBufferTest FAILED"); 1613e5c31af7Sopenharmony_ci else 1614e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("oneTimeSubmitFlagPrimaryBufferTest succeeded"); 1615e5c31af7Sopenharmony_ci} 1616e5c31af7Sopenharmony_ci 1617e5c31af7Sopenharmony_citcu::TestStatus oneTimeSubmitFlagSecondaryBufferTest(Context& context) 1618e5c31af7Sopenharmony_ci{ 1619e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1620e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1621e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1622e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1623e5c31af7Sopenharmony_ci 1624e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 1625e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().commandPoolResetCommandBuffer == VK_FALSE) 1626e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandPoolResetCommandBuffer not supported by this implementation"); 1627e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 1628e5c31af7Sopenharmony_ci 1629e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1630e5c31af7Sopenharmony_ci { 1631e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1632e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1633e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1634e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1635e5c31af7Sopenharmony_ci }; 1636e5c31af7Sopenharmony_ci 1637e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1638e5c31af7Sopenharmony_ci const Unique<VkCommandPool> secCmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 1639e5c31af7Sopenharmony_ci 1640e5c31af7Sopenharmony_ci // Command buffer 1641e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1642e5c31af7Sopenharmony_ci { 1643e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1644e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1645e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1646e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1647e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1648e5c31af7Sopenharmony_ci }; 1649e5c31af7Sopenharmony_ci 1650e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf1 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1651e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf2 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1652e5c31af7Sopenharmony_ci 1653e5c31af7Sopenharmony_ci // Secondary Command buffer 1654e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 1655e5c31af7Sopenharmony_ci { 1656e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1657e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1658e5c31af7Sopenharmony_ci *secCmdPool, // VkCommandPool pool; 1659e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 1660e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1661e5c31af7Sopenharmony_ci }; 1662e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 1663e5c31af7Sopenharmony_ci 1664e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 1665e5c31af7Sopenharmony_ci { 1666e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 1667e5c31af7Sopenharmony_ci DE_NULL, 1668e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 1669e5c31af7Sopenharmony_ci 0u, // subpass 1670e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 1671e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 1672e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 1673e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 1674e5c31af7Sopenharmony_ci }; 1675e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 1676e5c31af7Sopenharmony_ci { 1677e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 1678e5c31af7Sopenharmony_ci DE_NULL, 1679e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // flags 1680e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 1681e5c31af7Sopenharmony_ci }; 1682e5c31af7Sopenharmony_ci 1683e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 1684e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 1685e5c31af7Sopenharmony_ci 1686e5c31af7Sopenharmony_ci // reset event 1687e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1688e5c31af7Sopenharmony_ci 1689e5c31af7Sopenharmony_ci // record first primary command buffer 1690e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf1, 0u); 1691e5c31af7Sopenharmony_ci { 1692e5c31af7Sopenharmony_ci // record secondary command buffer 1693e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1694e5c31af7Sopenharmony_ci { 1695e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1696e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1697e5c31af7Sopenharmony_ci 1698e5c31af7Sopenharmony_ci // record setting event 1699e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event,stageMask); 1700e5c31af7Sopenharmony_ci } 1701e5c31af7Sopenharmony_ci 1702e5c31af7Sopenharmony_ci // end recording of secondary buffers 1703e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1704e5c31af7Sopenharmony_ci 1705e5c31af7Sopenharmony_ci // execute secondary buffer 1706e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf1, 1, &secCmdBuf.get()); 1707e5c31af7Sopenharmony_ci } 1708e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf1); 1709e5c31af7Sopenharmony_ci 1710e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf1.get()); 1711e5c31af7Sopenharmony_ci 1712e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 1713e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 1714e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1715e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Twice Secondary Command Buffer FAILED"); 1716e5c31af7Sopenharmony_ci 1717e5c31af7Sopenharmony_ci // reset first primary buffer 1718e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandBuffer( *primCmdBuf1, 0u)); 1719e5c31af7Sopenharmony_ci 1720e5c31af7Sopenharmony_ci // reset event to allow receiving it again 1721e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 1722e5c31af7Sopenharmony_ci 1723e5c31af7Sopenharmony_ci // record secondary command buffer again 1724e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1725e5c31af7Sopenharmony_ci { 1726e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 1727e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 1728e5c31af7Sopenharmony_ci 1729e5c31af7Sopenharmony_ci // record setting event 1730e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event,stageMask); 1731e5c31af7Sopenharmony_ci } 1732e5c31af7Sopenharmony_ci // end recording of secondary buffers 1733e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1734e5c31af7Sopenharmony_ci 1735e5c31af7Sopenharmony_ci // record second primary command buffer 1736e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf2, 0u); 1737e5c31af7Sopenharmony_ci { 1738e5c31af7Sopenharmony_ci // execute secondary buffer 1739e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf2, 1, &secCmdBuf.get()); 1740e5c31af7Sopenharmony_ci } 1741e5c31af7Sopenharmony_ci // end recording 1742e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf2); 1743e5c31af7Sopenharmony_ci 1744e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf2.get()); 1745e5c31af7Sopenharmony_ci 1746e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 1747e5c31af7Sopenharmony_ci result = vk.getEventStatus(vkDevice,*event); 1748e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 1749e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("oneTimeSubmitFlagSecondaryBufferTest FAILED"); 1750e5c31af7Sopenharmony_ci else 1751e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("oneTimeSubmitFlagSecondaryBufferTest succeeded"); 1752e5c31af7Sopenharmony_ci} 1753e5c31af7Sopenharmony_ci 1754e5c31af7Sopenharmony_citcu::TestStatus renderPassContinueTest(Context& context, bool framebufferHint) 1755e5c31af7Sopenharmony_ci{ 1756e5c31af7Sopenharmony_ci const DeviceInterface& vkd = context.getDeviceInterface(); 1757e5c31af7Sopenharmony_ci CommandBufferRenderPassTestEnvironment env (context, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); 1758e5c31af7Sopenharmony_ci 1759e5c31af7Sopenharmony_ci VkCommandBuffer primaryCommandBuffer = env.getPrimaryCommandBuffer(); 1760e5c31af7Sopenharmony_ci VkCommandBuffer secondaryCommandBuffer = env.getSecondaryCommandBuffer(); 1761e5c31af7Sopenharmony_ci const deUint32 clearColor[4] = { 2, 47, 131, 211 }; 1762e5c31af7Sopenharmony_ci 1763e5c31af7Sopenharmony_ci const VkClearAttachment clearAttachment = 1764e5c31af7Sopenharmony_ci { 1765e5c31af7Sopenharmony_ci VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask; 1766e5c31af7Sopenharmony_ci 0, // deUint32 colorAttachment; 1767e5c31af7Sopenharmony_ci makeClearValueColorU32(clearColor[0], 1768e5c31af7Sopenharmony_ci clearColor[1], 1769e5c31af7Sopenharmony_ci clearColor[2], 1770e5c31af7Sopenharmony_ci clearColor[3]) // VkClearValue clearValue; 1771e5c31af7Sopenharmony_ci }; 1772e5c31af7Sopenharmony_ci 1773e5c31af7Sopenharmony_ci const VkClearRect clearRect = 1774e5c31af7Sopenharmony_ci { 1775e5c31af7Sopenharmony_ci CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_AREA, // VkRect2D rect; 1776e5c31af7Sopenharmony_ci 0u, // deUint32 baseArrayLayer; 1777e5c31af7Sopenharmony_ci 1u // deUint32 layerCount; 1778e5c31af7Sopenharmony_ci }; 1779e5c31af7Sopenharmony_ci 1780e5c31af7Sopenharmony_ci env.beginSecondaryCommandBuffer(VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT, framebufferHint); 1781e5c31af7Sopenharmony_ci vkd.cmdClearAttachments(secondaryCommandBuffer, 1, &clearAttachment, 1, &clearRect); 1782e5c31af7Sopenharmony_ci endCommandBuffer(vkd, secondaryCommandBuffer); 1783e5c31af7Sopenharmony_ci 1784e5c31af7Sopenharmony_ci 1785e5c31af7Sopenharmony_ci env.beginPrimaryCommandBuffer(0); 1786e5c31af7Sopenharmony_ci env.beginRenderPass(VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); 1787e5c31af7Sopenharmony_ci vkd.cmdExecuteCommands(primaryCommandBuffer, 1, &secondaryCommandBuffer); 1788e5c31af7Sopenharmony_ci endRenderPass(vkd, primaryCommandBuffer); 1789e5c31af7Sopenharmony_ci 1790e5c31af7Sopenharmony_ci endCommandBuffer(vkd, primaryCommandBuffer); 1791e5c31af7Sopenharmony_ci 1792e5c31af7Sopenharmony_ci env.submitPrimaryCommandBuffer(); 1793e5c31af7Sopenharmony_ci context.resetCommandPoolForVKSC(context.getDevice(), env.getCommandPool()); 1794e5c31af7Sopenharmony_ci 1795e5c31af7Sopenharmony_ci de::MovePtr<tcu::TextureLevel> result = env.readColorAttachment(); 1796e5c31af7Sopenharmony_ci tcu::PixelBufferAccess pixelBufferAccess = result->getAccess(); 1797e5c31af7Sopenharmony_ci 1798e5c31af7Sopenharmony_ci for (deUint32 i = 0; i < (CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE.width * CommandBufferRenderPassTestEnvironment::DEFAULT_IMAGE_SIZE.height); ++i) 1799e5c31af7Sopenharmony_ci { 1800e5c31af7Sopenharmony_ci deUint8* colorData = reinterpret_cast<deUint8*>(pixelBufferAccess.getDataPtr()); 1801e5c31af7Sopenharmony_ci for (int colorComponent = 0; colorComponent < 4; ++colorComponent) 1802e5c31af7Sopenharmony_ci if (colorData[i * 4 + colorComponent] != clearColor[colorComponent]) 1803e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("clear value mismatch"); 1804e5c31af7Sopenharmony_ci } 1805e5c31af7Sopenharmony_ci 1806e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("render pass continue test passed"); 1807e5c31af7Sopenharmony_ci} 1808e5c31af7Sopenharmony_ci 1809e5c31af7Sopenharmony_citcu::TestStatus simultaneousUseSecondaryBufferOnePrimaryBufferTest(Context& context) 1810e5c31af7Sopenharmony_ci{ 1811e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 1812e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 1813e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 1814e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1815e5c31af7Sopenharmony_ci Allocator& allocator = context.getDefaultAllocator(); 1816e5c31af7Sopenharmony_ci const ComputeInstanceResultBuffer result(vk, vkDevice, allocator, 0.0f); 1817e5c31af7Sopenharmony_ci 1818e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 1819e5c31af7Sopenharmony_ci { 1820e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 1821e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1822e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 1823e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 1824e5c31af7Sopenharmony_ci }; 1825e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool(createCommandPool(vk, vkDevice, &cmdPoolParams)); 1826e5c31af7Sopenharmony_ci 1827e5c31af7Sopenharmony_ci // Command buffer 1828e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 1829e5c31af7Sopenharmony_ci { 1830e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1831e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1832e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1833e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 1834e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1835e5c31af7Sopenharmony_ci }; 1836e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf(allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 1837e5c31af7Sopenharmony_ci 1838e5c31af7Sopenharmony_ci // Secondary Command buffer params 1839e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 1840e5c31af7Sopenharmony_ci { 1841e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 1842e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 1843e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 1844e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 1845e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 1846e5c31af7Sopenharmony_ci }; 1847e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 1848e5c31af7Sopenharmony_ci 1849e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 1850e5c31af7Sopenharmony_ci { 1851e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 1852e5c31af7Sopenharmony_ci DE_NULL, 1853e5c31af7Sopenharmony_ci (VkRenderPass)0u, 1854e5c31af7Sopenharmony_ci 0u, // subpass 1855e5c31af7Sopenharmony_ci (VkFramebuffer)0u, 1856e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 1857e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, 1858e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, 1859e5c31af7Sopenharmony_ci }; 1860e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 1861e5c31af7Sopenharmony_ci { 1862e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 1863e5c31af7Sopenharmony_ci DE_NULL, 1864e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags 1865e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 1866e5c31af7Sopenharmony_ci }; 1867e5c31af7Sopenharmony_ci 1868e5c31af7Sopenharmony_ci const deUint32 offset = (0u); 1869e5c31af7Sopenharmony_ci const deUint32 addressableSize = 256; 1870e5c31af7Sopenharmony_ci const deUint32 dataSize = 8; 1871e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferMem; 1872e5c31af7Sopenharmony_ci const Unique<VkBuffer> buffer(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem)); 1873e5c31af7Sopenharmony_ci // Secondary command buffer will have a compute shader that does an atomic increment to make sure that all instances of secondary buffers execute 1874e5c31af7Sopenharmony_ci const Unique<VkDescriptorSetLayout> descriptorSetLayout(createDescriptorSetLayout(context)); 1875e5c31af7Sopenharmony_ci const Unique<VkDescriptorPool> descriptorPool(createDescriptorPool(context)); 1876e5c31af7Sopenharmony_ci const Unique<VkDescriptorSet> descriptorSet(createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer())); 1877e5c31af7Sopenharmony_ci const VkDescriptorSet descriptorSets[] = { *descriptorSet }; 1878e5c31af7Sopenharmony_ci const int numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets); 1879e5c31af7Sopenharmony_ci 1880e5c31af7Sopenharmony_ci const VkPipelineLayoutCreateInfo layoutCreateInfo = 1881e5c31af7Sopenharmony_ci { 1882e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType 1883e5c31af7Sopenharmony_ci DE_NULL, // pNext 1884e5c31af7Sopenharmony_ci (VkPipelineLayoutCreateFlags)0, 1885e5c31af7Sopenharmony_ci numDescriptorSets, // setLayoutCount 1886e5c31af7Sopenharmony_ci &descriptorSetLayout.get(), // pSetLayouts 1887e5c31af7Sopenharmony_ci 0u, // pushConstantRangeCount 1888e5c31af7Sopenharmony_ci DE_NULL, // pPushConstantRanges 1889e5c31af7Sopenharmony_ci }; 1890e5c31af7Sopenharmony_ci Unique<VkPipelineLayout> pipelineLayout(createPipelineLayout(vk, vkDevice, &layoutCreateInfo)); 1891e5c31af7Sopenharmony_ci 1892e5c31af7Sopenharmony_ci const Unique<VkShaderModule> computeModule(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("compute_increment"), (VkShaderModuleCreateFlags)0u)); 1893e5c31af7Sopenharmony_ci 1894e5c31af7Sopenharmony_ci const VkPipelineShaderStageCreateInfo shaderCreateInfo = 1895e5c31af7Sopenharmony_ci { 1896e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 1897e5c31af7Sopenharmony_ci DE_NULL, 1898e5c31af7Sopenharmony_ci (VkPipelineShaderStageCreateFlags)0, 1899e5c31af7Sopenharmony_ci VK_SHADER_STAGE_COMPUTE_BIT, // stage 1900e5c31af7Sopenharmony_ci *computeModule, // shader 1901e5c31af7Sopenharmony_ci "main", 1902e5c31af7Sopenharmony_ci DE_NULL, // pSpecializationInfo 1903e5c31af7Sopenharmony_ci }; 1904e5c31af7Sopenharmony_ci 1905e5c31af7Sopenharmony_ci const VkComputePipelineCreateInfo pipelineCreateInfo = 1906e5c31af7Sopenharmony_ci { 1907e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 1908e5c31af7Sopenharmony_ci DE_NULL, 1909e5c31af7Sopenharmony_ci 0u, // flags 1910e5c31af7Sopenharmony_ci shaderCreateInfo, // cs 1911e5c31af7Sopenharmony_ci *pipelineLayout, // layout 1912e5c31af7Sopenharmony_ci (vk::VkPipeline)0, // basePipelineHandle 1913e5c31af7Sopenharmony_ci 0u, // basePipelineIndex 1914e5c31af7Sopenharmony_ci }; 1915e5c31af7Sopenharmony_ci 1916e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier bufferBarrier = 1917e5c31af7Sopenharmony_ci { 1918e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType 1919e5c31af7Sopenharmony_ci DE_NULL, // pNext 1920e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, // srcAccessMask 1921e5c31af7Sopenharmony_ci VK_ACCESS_HOST_READ_BIT, // dstAccessMask 1922e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex 1923e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex 1924e5c31af7Sopenharmony_ci *buffer, // buffer 1925e5c31af7Sopenharmony_ci (VkDeviceSize)0u, // offset 1926e5c31af7Sopenharmony_ci (VkDeviceSize)VK_WHOLE_SIZE, // size 1927e5c31af7Sopenharmony_ci }; 1928e5c31af7Sopenharmony_ci 1929e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline(createComputePipeline(vk, vkDevice, (VkPipelineCache)0u, &pipelineCreateInfo)); 1930e5c31af7Sopenharmony_ci 1931e5c31af7Sopenharmony_ci // record secondary command buffer 1932e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 1933e5c31af7Sopenharmony_ci { 1934e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 1935e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, 0, 0); 1936e5c31af7Sopenharmony_ci vk.cmdDispatch(*secCmdBuf, 1u, 1u, 1u); 1937e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*secCmdBuf, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 1938e5c31af7Sopenharmony_ci 0, (const VkMemoryBarrier*)DE_NULL, 1939e5c31af7Sopenharmony_ci 1, &bufferBarrier, 1940e5c31af7Sopenharmony_ci 0, (const VkImageMemoryBarrier*)DE_NULL); 1941e5c31af7Sopenharmony_ci } 1942e5c31af7Sopenharmony_ci // end recording of secondary buffer 1943e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 1944e5c31af7Sopenharmony_ci 1945e5c31af7Sopenharmony_ci // record primary command buffer 1946e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *primCmdBuf, 0u); 1947e5c31af7Sopenharmony_ci { 1948e5c31af7Sopenharmony_ci // execute secondary buffer twice in same primary 1949e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get()); 1950e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf, 1, &secCmdBuf.get()); 1951e5c31af7Sopenharmony_ci } 1952e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 1953e5c31af7Sopenharmony_ci 1954e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 1955e5c31af7Sopenharmony_ci 1956e5c31af7Sopenharmony_ci deUint32 resultCount; 1957e5c31af7Sopenharmony_ci result.readResultContentsTo(&resultCount); 1958e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 1959e5c31af7Sopenharmony_ci if (resultCount == 2) 1960e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Simultaneous Secondary Command Buffer Execution succeeded"); 1961e5c31af7Sopenharmony_ci else 1962e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Simultaneous Secondary Command Buffer Execution FAILED"); 1963e5c31af7Sopenharmony_ci} 1964e5c31af7Sopenharmony_ci 1965e5c31af7Sopenharmony_cienum class BadInheritanceInfoCase 1966e5c31af7Sopenharmony_ci{ 1967e5c31af7Sopenharmony_ci RANDOM_PTR = 0, 1968e5c31af7Sopenharmony_ci RANDOM_PTR_CONTINUATION, 1969e5c31af7Sopenharmony_ci RANDOM_DATA_PTR, 1970e5c31af7Sopenharmony_ci INVALID_STRUCTURE_TYPE, 1971e5c31af7Sopenharmony_ci VALID_NONSENSE_TYPE, 1972e5c31af7Sopenharmony_ci}; 1973e5c31af7Sopenharmony_ci 1974e5c31af7Sopenharmony_citcu::TestStatus badInheritanceInfoTest (Context& context, BadInheritanceInfoCase testCase) 1975e5c31af7Sopenharmony_ci{ 1976e5c31af7Sopenharmony_ci const auto& vkd = context.getDeviceInterface(); 1977e5c31af7Sopenharmony_ci const auto device = context.getDevice(); 1978e5c31af7Sopenharmony_ci const auto queue = context.getUniversalQueue(); 1979e5c31af7Sopenharmony_ci const auto queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 1980e5c31af7Sopenharmony_ci auto& allocator = context.getDefaultAllocator(); 1981e5c31af7Sopenharmony_ci const ComputeInstanceResultBuffer result (vkd, device, allocator, 0.0f); 1982e5c31af7Sopenharmony_ci 1983e5c31af7Sopenharmony_ci // Command pool and command buffer. 1984e5c31af7Sopenharmony_ci const auto cmdPool = makeCommandPool(vkd, device, queueFamilyIndex); 1985e5c31af7Sopenharmony_ci const auto cmdBufferPtr = allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY); 1986e5c31af7Sopenharmony_ci const auto cmdBuffer = cmdBufferPtr.get(); 1987e5c31af7Sopenharmony_ci 1988e5c31af7Sopenharmony_ci // Buffers, descriptor set layouts and descriptor sets. 1989e5c31af7Sopenharmony_ci const deUint32 offset = 0u; 1990e5c31af7Sopenharmony_ci const deUint32 addressableSize = 256u; 1991e5c31af7Sopenharmony_ci const deUint32 dataSize = 8u; 1992e5c31af7Sopenharmony_ci 1993e5c31af7Sopenharmony_ci // The uniform buffer will not be used by the shader but is needed by auxiliar functions here. 1994e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferMem; 1995e5c31af7Sopenharmony_ci const Unique<VkBuffer> buffer(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem)); 1996e5c31af7Sopenharmony_ci 1997e5c31af7Sopenharmony_ci const Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(context)); 1998e5c31af7Sopenharmony_ci const Unique<VkDescriptorPool> descriptorPool (createDescriptorPool(context)); 1999e5c31af7Sopenharmony_ci const Unique<VkDescriptorSet> descriptorSet (createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer())); 2000e5c31af7Sopenharmony_ci const VkDescriptorSet descriptorSets[] = { *descriptorSet }; 2001e5c31af7Sopenharmony_ci const int numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets); 2002e5c31af7Sopenharmony_ci 2003e5c31af7Sopenharmony_ci // Pipeline layout. 2004e5c31af7Sopenharmony_ci const auto pipelineLayout = makePipelineLayout(vkd, device, descriptorSetLayout.get()); 2005e5c31af7Sopenharmony_ci 2006e5c31af7Sopenharmony_ci // Compute shader module. 2007e5c31af7Sopenharmony_ci const Unique<VkShaderModule> computeModule (createShaderModule(vkd, device, context.getBinaryCollection().get("compute_increment"), (VkShaderModuleCreateFlags)0u)); 2008e5c31af7Sopenharmony_ci 2009e5c31af7Sopenharmony_ci const VkPipelineShaderStageCreateInfo shaderCreateInfo = 2010e5c31af7Sopenharmony_ci { 2011e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 2012e5c31af7Sopenharmony_ci DE_NULL, 2013e5c31af7Sopenharmony_ci (VkPipelineShaderStageCreateFlags)0, 2014e5c31af7Sopenharmony_ci VK_SHADER_STAGE_COMPUTE_BIT, // stage 2015e5c31af7Sopenharmony_ci *computeModule, // shader 2016e5c31af7Sopenharmony_ci "main", 2017e5c31af7Sopenharmony_ci DE_NULL, // pSpecializationInfo 2018e5c31af7Sopenharmony_ci }; 2019e5c31af7Sopenharmony_ci 2020e5c31af7Sopenharmony_ci const VkComputePipelineCreateInfo pipelineCreateInfo = 2021e5c31af7Sopenharmony_ci { 2022e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 2023e5c31af7Sopenharmony_ci DE_NULL, 2024e5c31af7Sopenharmony_ci 0u, // flags 2025e5c31af7Sopenharmony_ci shaderCreateInfo, // cs 2026e5c31af7Sopenharmony_ci *pipelineLayout, // layout 2027e5c31af7Sopenharmony_ci (vk::VkPipeline)0, // basePipelineHandle 2028e5c31af7Sopenharmony_ci 0u, // basePipelineIndex 2029e5c31af7Sopenharmony_ci }; 2030e5c31af7Sopenharmony_ci 2031e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline (createComputePipeline(vkd, device, (VkPipelineCache)0u, &pipelineCreateInfo)); 2032e5c31af7Sopenharmony_ci 2033e5c31af7Sopenharmony_ci // Compute to host barrier to read result. 2034e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier bufferBarrier = 2035e5c31af7Sopenharmony_ci { 2036e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // sType 2037e5c31af7Sopenharmony_ci DE_NULL, // pNext 2038e5c31af7Sopenharmony_ci VK_ACCESS_SHADER_WRITE_BIT, // srcAccessMask 2039e5c31af7Sopenharmony_ci VK_ACCESS_HOST_READ_BIT, // dstAccessMask 2040e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex 2041e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex 2042e5c31af7Sopenharmony_ci *buffer, // buffer 2043e5c31af7Sopenharmony_ci (VkDeviceSize)0u, // offset 2044e5c31af7Sopenharmony_ci (VkDeviceSize)VK_WHOLE_SIZE, // size 2045e5c31af7Sopenharmony_ci }; 2046e5c31af7Sopenharmony_ci 2047e5c31af7Sopenharmony_ci // Record command buffer and submit it. 2048e5c31af7Sopenharmony_ci VkCommandBufferBeginInfo beginInfo = 2049e5c31af7Sopenharmony_ci { 2050e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType; 2051e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 2052e5c31af7Sopenharmony_ci 0u, // VkCommandBufferUsageFlags flags; 2053e5c31af7Sopenharmony_ci nullptr, // const VkCommandBufferInheritanceInfo* pInheritanceInfo; 2054e5c31af7Sopenharmony_ci }; 2055e5c31af7Sopenharmony_ci 2056e5c31af7Sopenharmony_ci // Structures used in different test types. 2057e5c31af7Sopenharmony_ci VkCommandBufferInheritanceInfo inheritanceInfo; 2058e5c31af7Sopenharmony_ci VkBufferCreateInfo validNonsenseStructure; 2059e5c31af7Sopenharmony_ci struct 2060e5c31af7Sopenharmony_ci { 2061e5c31af7Sopenharmony_ci VkStructureType sType; 2062e5c31af7Sopenharmony_ci void* pNext; 2063e5c31af7Sopenharmony_ci } invalidStructure; 2064e5c31af7Sopenharmony_ci 2065e5c31af7Sopenharmony_ci if (testCase == BadInheritanceInfoCase::RANDOM_PTR || testCase == BadInheritanceInfoCase::RANDOM_PTR_CONTINUATION) 2066e5c31af7Sopenharmony_ci { 2067e5c31af7Sopenharmony_ci de::Random rnd (1602600778u); 2068e5c31af7Sopenharmony_ci VkCommandBufferInheritanceInfo* info; 2069e5c31af7Sopenharmony_ci auto ptrData = reinterpret_cast<deUint8*>(&info); 2070e5c31af7Sopenharmony_ci 2071e5c31af7Sopenharmony_ci // Fill pointer value with pseudorandom garbage. 2072e5c31af7Sopenharmony_ci for (size_t i = 0; i < sizeof(info); ++i) 2073e5c31af7Sopenharmony_ci *ptrData++ = rnd.getUint8(); 2074e5c31af7Sopenharmony_ci 2075e5c31af7Sopenharmony_ci beginInfo.pInheritanceInfo = info; 2076e5c31af7Sopenharmony_ci 2077e5c31af7Sopenharmony_ci // Try to trick the implementation into reading pInheritanceInfo one more way. 2078e5c31af7Sopenharmony_ci if (testCase == BadInheritanceInfoCase::RANDOM_PTR_CONTINUATION) 2079e5c31af7Sopenharmony_ci beginInfo.flags |= VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT; 2080e5c31af7Sopenharmony_ci 2081e5c31af7Sopenharmony_ci } 2082e5c31af7Sopenharmony_ci else if (testCase == BadInheritanceInfoCase::RANDOM_DATA_PTR) 2083e5c31af7Sopenharmony_ci { 2084e5c31af7Sopenharmony_ci de::Random rnd (1602601141u); 2085e5c31af7Sopenharmony_ci auto itr = reinterpret_cast<deUint8*>(&inheritanceInfo); 2086e5c31af7Sopenharmony_ci 2087e5c31af7Sopenharmony_ci // Fill inheritance info data structure with random data. 2088e5c31af7Sopenharmony_ci for (size_t i = 0; i < sizeof(inheritanceInfo); ++i) 2089e5c31af7Sopenharmony_ci *itr++ = rnd.getUint8(); 2090e5c31af7Sopenharmony_ci 2091e5c31af7Sopenharmony_ci beginInfo.pInheritanceInfo = &inheritanceInfo; 2092e5c31af7Sopenharmony_ci } 2093e5c31af7Sopenharmony_ci else if (testCase == BadInheritanceInfoCase::INVALID_STRUCTURE_TYPE) 2094e5c31af7Sopenharmony_ci { 2095e5c31af7Sopenharmony_ci de::Random rnd (1602658515u); 2096e5c31af7Sopenharmony_ci auto ptrData = reinterpret_cast<deUint8*>(&(invalidStructure.pNext)); 2097e5c31af7Sopenharmony_ci invalidStructure.sType = VK_STRUCTURE_TYPE_MAX_ENUM; 2098e5c31af7Sopenharmony_ci 2099e5c31af7Sopenharmony_ci // Fill pNext pointer with random data. 2100e5c31af7Sopenharmony_ci for (size_t i = 0; i < sizeof(invalidStructure.pNext); ++i) 2101e5c31af7Sopenharmony_ci *ptrData++ = rnd.getUint8(); 2102e5c31af7Sopenharmony_ci 2103e5c31af7Sopenharmony_ci beginInfo.pInheritanceInfo = reinterpret_cast<VkCommandBufferInheritanceInfo*>(&invalidStructure); 2104e5c31af7Sopenharmony_ci } 2105e5c31af7Sopenharmony_ci else if (testCase == BadInheritanceInfoCase::VALID_NONSENSE_TYPE) 2106e5c31af7Sopenharmony_ci { 2107e5c31af7Sopenharmony_ci validNonsenseStructure.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 2108e5c31af7Sopenharmony_ci validNonsenseStructure.pNext = nullptr; 2109e5c31af7Sopenharmony_ci validNonsenseStructure.flags = 0u; 2110e5c31af7Sopenharmony_ci validNonsenseStructure.size = 1024u; 2111e5c31af7Sopenharmony_ci validNonsenseStructure.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; 2112e5c31af7Sopenharmony_ci validNonsenseStructure.sharingMode = VK_SHARING_MODE_EXCLUSIVE; 2113e5c31af7Sopenharmony_ci validNonsenseStructure.queueFamilyIndexCount = 0u; 2114e5c31af7Sopenharmony_ci validNonsenseStructure.pQueueFamilyIndices = nullptr; 2115e5c31af7Sopenharmony_ci 2116e5c31af7Sopenharmony_ci beginInfo.pInheritanceInfo = reinterpret_cast<VkCommandBufferInheritanceInfo*>(&validNonsenseStructure); 2117e5c31af7Sopenharmony_ci } 2118e5c31af7Sopenharmony_ci else 2119e5c31af7Sopenharmony_ci { 2120e5c31af7Sopenharmony_ci DE_ASSERT(false); 2121e5c31af7Sopenharmony_ci } 2122e5c31af7Sopenharmony_ci 2123e5c31af7Sopenharmony_ci VK_CHECK(vkd.beginCommandBuffer(cmdBuffer, &beginInfo)); 2124e5c31af7Sopenharmony_ci { 2125e5c31af7Sopenharmony_ci vkd.cmdBindPipeline(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 2126e5c31af7Sopenharmony_ci vkd.cmdBindDescriptorSets(cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, 0, 0); 2127e5c31af7Sopenharmony_ci vkd.cmdDispatch(cmdBuffer, 1u, 1u, 1u); 2128e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(cmdBuffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 2129e5c31af7Sopenharmony_ci 0, (const VkMemoryBarrier*)DE_NULL, 2130e5c31af7Sopenharmony_ci 1, &bufferBarrier, 2131e5c31af7Sopenharmony_ci 0, (const VkImageMemoryBarrier*)DE_NULL); 2132e5c31af7Sopenharmony_ci } 2133e5c31af7Sopenharmony_ci endCommandBuffer(vkd, cmdBuffer); 2134e5c31af7Sopenharmony_ci submitCommandsAndWait(vkd, device, queue, cmdBuffer); 2135e5c31af7Sopenharmony_ci 2136e5c31af7Sopenharmony_ci deUint32 resultCount; 2137e5c31af7Sopenharmony_ci result.readResultContentsTo(&resultCount); 2138e5c31af7Sopenharmony_ci 2139e5c31af7Sopenharmony_ci // Make sure the command buffer was run. 2140e5c31af7Sopenharmony_ci if (resultCount != 1u) 2141e5c31af7Sopenharmony_ci { 2142e5c31af7Sopenharmony_ci std::ostringstream msg; 2143e5c31af7Sopenharmony_ci msg << "Invalid value found in results buffer (expected value 1u but found " << resultCount << ")"; 2144e5c31af7Sopenharmony_ci return tcu::TestStatus::fail(msg.str()); 2145e5c31af7Sopenharmony_ci } 2146e5c31af7Sopenharmony_ci 2147e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Pass"); 2148e5c31af7Sopenharmony_ci} 2149e5c31af7Sopenharmony_ci 2150e5c31af7Sopenharmony_citcu::TestStatus simultaneousUseSecondaryBufferTwoPrimaryBuffersTest(Context& context) 2151e5c31af7Sopenharmony_ci{ 2152e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2153e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2154e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 2155e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2156e5c31af7Sopenharmony_ci Allocator& allocator = context.getDefaultAllocator(); 2157e5c31af7Sopenharmony_ci const ComputeInstanceResultBuffer result(vk, vkDevice, allocator, 0.0f); 2158e5c31af7Sopenharmony_ci 2159e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2160e5c31af7Sopenharmony_ci { 2161e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 2162e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2163e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 2164e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 2165e5c31af7Sopenharmony_ci }; 2166e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool(createCommandPool(vk, vkDevice, &cmdPoolParams)); 2167e5c31af7Sopenharmony_ci 2168e5c31af7Sopenharmony_ci // Command buffer 2169e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 2170e5c31af7Sopenharmony_ci { 2171e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 2172e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2173e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 2174e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 2175e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 2176e5c31af7Sopenharmony_ci }; 2177e5c31af7Sopenharmony_ci // Two separate primary cmd buffers that will be executed with the same secondary cmd buffer 2178e5c31af7Sopenharmony_ci const deUint32 numPrimCmdBufs = 2; 2179e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBufOne(allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 2180e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBufTwo(allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 2181e5c31af7Sopenharmony_ci VkCommandBuffer primCmdBufs[numPrimCmdBufs]; 2182e5c31af7Sopenharmony_ci primCmdBufs[0] = primCmdBufOne.get(); 2183e5c31af7Sopenharmony_ci primCmdBufs[1] = primCmdBufTwo.get(); 2184e5c31af7Sopenharmony_ci 2185e5c31af7Sopenharmony_ci // Secondary Command buffer params 2186e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 2187e5c31af7Sopenharmony_ci { 2188e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 2189e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2190e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 2191e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 2192e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 2193e5c31af7Sopenharmony_ci }; 2194e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf(allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 2195e5c31af7Sopenharmony_ci 2196e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primCmdBufBeginInfo = 2197e5c31af7Sopenharmony_ci { 2198e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 2199e5c31af7Sopenharmony_ci DE_NULL, 2200e5c31af7Sopenharmony_ci 0, // flags 2201e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2202e5c31af7Sopenharmony_ci }; 2203e5c31af7Sopenharmony_ci 2204e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 2205e5c31af7Sopenharmony_ci { 2206e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 2207e5c31af7Sopenharmony_ci DE_NULL, 2208e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 2209e5c31af7Sopenharmony_ci 0u, // subpass 2210e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 2211e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 2212e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 2213e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 2214e5c31af7Sopenharmony_ci }; 2215e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 2216e5c31af7Sopenharmony_ci { 2217e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 2218e5c31af7Sopenharmony_ci DE_NULL, 2219e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags 2220e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 2221e5c31af7Sopenharmony_ci }; 2222e5c31af7Sopenharmony_ci 2223e5c31af7Sopenharmony_ci const deUint32 offset = (0u); 2224e5c31af7Sopenharmony_ci const deUint32 addressableSize = 256; 2225e5c31af7Sopenharmony_ci const deUint32 dataSize = 8; 2226e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferMem; 2227e5c31af7Sopenharmony_ci const Unique<VkBuffer> buffer(createDataBuffer(context, offset, addressableSize, 0x00, dataSize, 0x5A, &bufferMem)); 2228e5c31af7Sopenharmony_ci // Secondary command buffer will have a compute shader that does an atomic increment to make sure that all instances of secondary buffers execute 2229e5c31af7Sopenharmony_ci const Unique<VkDescriptorSetLayout> descriptorSetLayout(createDescriptorSetLayout(context)); 2230e5c31af7Sopenharmony_ci const Unique<VkDescriptorPool> descriptorPool(createDescriptorPool(context)); 2231e5c31af7Sopenharmony_ci const Unique<VkDescriptorSet> descriptorSet(createDescriptorSet(context, *descriptorPool, *descriptorSetLayout, *buffer, offset, result.getBuffer())); 2232e5c31af7Sopenharmony_ci const VkDescriptorSet descriptorSets[] = { *descriptorSet }; 2233e5c31af7Sopenharmony_ci const int numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets); 2234e5c31af7Sopenharmony_ci 2235e5c31af7Sopenharmony_ci const VkPipelineLayoutCreateInfo layoutCreateInfo = 2236e5c31af7Sopenharmony_ci { 2237e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType 2238e5c31af7Sopenharmony_ci DE_NULL, // pNext 2239e5c31af7Sopenharmony_ci (VkPipelineLayoutCreateFlags)0, 2240e5c31af7Sopenharmony_ci numDescriptorSets, // setLayoutCount 2241e5c31af7Sopenharmony_ci &descriptorSetLayout.get(), // pSetLayouts 2242e5c31af7Sopenharmony_ci 0u, // pushConstantRangeCount 2243e5c31af7Sopenharmony_ci DE_NULL, // pPushConstantRanges 2244e5c31af7Sopenharmony_ci }; 2245e5c31af7Sopenharmony_ci Unique<VkPipelineLayout> pipelineLayout(createPipelineLayout(vk, vkDevice, &layoutCreateInfo)); 2246e5c31af7Sopenharmony_ci 2247e5c31af7Sopenharmony_ci const Unique<VkShaderModule> computeModule(createShaderModule(vk, vkDevice, context.getBinaryCollection().get("compute_increment"), (VkShaderModuleCreateFlags)0u)); 2248e5c31af7Sopenharmony_ci 2249e5c31af7Sopenharmony_ci const VkPipelineShaderStageCreateInfo shaderCreateInfo = 2250e5c31af7Sopenharmony_ci { 2251e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 2252e5c31af7Sopenharmony_ci DE_NULL, 2253e5c31af7Sopenharmony_ci (VkPipelineShaderStageCreateFlags)0, 2254e5c31af7Sopenharmony_ci VK_SHADER_STAGE_COMPUTE_BIT, // stage 2255e5c31af7Sopenharmony_ci *computeModule, // shader 2256e5c31af7Sopenharmony_ci "main", 2257e5c31af7Sopenharmony_ci DE_NULL, // pSpecializationInfo 2258e5c31af7Sopenharmony_ci }; 2259e5c31af7Sopenharmony_ci 2260e5c31af7Sopenharmony_ci const VkComputePipelineCreateInfo pipelineCreateInfo = 2261e5c31af7Sopenharmony_ci { 2262e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 2263e5c31af7Sopenharmony_ci DE_NULL, 2264e5c31af7Sopenharmony_ci 0u, // flags 2265e5c31af7Sopenharmony_ci shaderCreateInfo, // cs 2266e5c31af7Sopenharmony_ci *pipelineLayout, // layout 2267e5c31af7Sopenharmony_ci (vk::VkPipeline)0, // basePipelineHandle 2268e5c31af7Sopenharmony_ci 0u, // basePipelineIndex 2269e5c31af7Sopenharmony_ci }; 2270e5c31af7Sopenharmony_ci 2271e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipeline(createComputePipeline(vk, vkDevice, (VkPipelineCache)0u, &pipelineCreateInfo)); 2272e5c31af7Sopenharmony_ci 2273e5c31af7Sopenharmony_ci // record secondary command buffer 2274e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 2275e5c31af7Sopenharmony_ci { 2276e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); 2277e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*secCmdBuf, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, 0, 0); 2278e5c31af7Sopenharmony_ci vk.cmdDispatch(*secCmdBuf, 1u, 1u, 1u); 2279e5c31af7Sopenharmony_ci } 2280e5c31af7Sopenharmony_ci // end recording of secondary buffer 2281e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 2282e5c31af7Sopenharmony_ci 2283e5c31af7Sopenharmony_ci // record primary command buffers 2284e5c31af7Sopenharmony_ci // Insert one instance of same secondary command buffer into two separate primary command buffers 2285e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo)); 2286e5c31af7Sopenharmony_ci { 2287e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBufOne, 1, &secCmdBuf.get()); 2288e5c31af7Sopenharmony_ci } 2289e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBufOne); 2290e5c31af7Sopenharmony_ci 2291e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo)); 2292e5c31af7Sopenharmony_ci { 2293e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBufTwo, 1, &secCmdBuf.get()); 2294e5c31af7Sopenharmony_ci } 2295e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBufTwo); 2296e5c31af7Sopenharmony_ci 2297e5c31af7Sopenharmony_ci // create fence to wait for execution of queue 2298e5c31af7Sopenharmony_ci const Unique<VkFence> fence(createFence(vk, vkDevice)); 2299e5c31af7Sopenharmony_ci 2300e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo = 2301e5c31af7Sopenharmony_ci { 2302e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2303e5c31af7Sopenharmony_ci DE_NULL, // pNext 2304e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 2305e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 2306e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 2307e5c31af7Sopenharmony_ci numPrimCmdBufs, // commandBufferCount 2308e5c31af7Sopenharmony_ci primCmdBufs, // pCommandBuffers 2309e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 2310e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 2311e5c31af7Sopenharmony_ci }; 2312e5c31af7Sopenharmony_ci 2313e5c31af7Sopenharmony_ci // submit primary buffers, the secondary should be executed too 2314e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fence)); 2315e5c31af7Sopenharmony_ci 2316e5c31af7Sopenharmony_ci // wait for end of execution of queue 2317e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT)); 2318e5c31af7Sopenharmony_ci 2319e5c31af7Sopenharmony_ci deUint32 resultCount; 2320e5c31af7Sopenharmony_ci result.readResultContentsTo(&resultCount); 2321e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 2322e5c31af7Sopenharmony_ci if (resultCount == 2) 2323e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Simultaneous Secondary Command Buffer Execution succeeded"); 2324e5c31af7Sopenharmony_ci else 2325e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Simultaneous Secondary Command Buffer Execution FAILED"); 2326e5c31af7Sopenharmony_ci} 2327e5c31af7Sopenharmony_ci 2328e5c31af7Sopenharmony_citcu::TestStatus recordBufferQueryPreciseWithFlagTest(Context& context) 2329e5c31af7Sopenharmony_ci{ 2330e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2331e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2332e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2333e5c31af7Sopenharmony_ci 2334e5c31af7Sopenharmony_ci if (!context.getDeviceFeatures().inheritedQueries) 2335e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Inherited queries feature is not supported"); 2336e5c31af7Sopenharmony_ci 2337e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2338e5c31af7Sopenharmony_ci { 2339e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 2340e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2341e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 2342e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 2343e5c31af7Sopenharmony_ci }; 2344e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2345e5c31af7Sopenharmony_ci 2346e5c31af7Sopenharmony_ci // Command buffer 2347e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo primCmdBufParams = 2348e5c31af7Sopenharmony_ci { 2349e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2350e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2351e5c31af7Sopenharmony_ci *cmdPool, // pool; 2352e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 2353e5c31af7Sopenharmony_ci 1u, // flags; 2354e5c31af7Sopenharmony_ci }; 2355e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams)); 2356e5c31af7Sopenharmony_ci 2357e5c31af7Sopenharmony_ci // Secondary Command buffer params 2358e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 2359e5c31af7Sopenharmony_ci { 2360e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2361e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2362e5c31af7Sopenharmony_ci *cmdPool, // pool; 2363e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level; 2364e5c31af7Sopenharmony_ci 1u, // flags; 2365e5c31af7Sopenharmony_ci }; 2366e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 2367e5c31af7Sopenharmony_ci 2368e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primBufferBeginInfo = 2369e5c31af7Sopenharmony_ci { 2370e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2371e5c31af7Sopenharmony_ci DE_NULL, // pNext 2372e5c31af7Sopenharmony_ci 0u, // flags 2373e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2374e5c31af7Sopenharmony_ci }; 2375e5c31af7Sopenharmony_ci 2376e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secBufferInheritInfo = 2377e5c31af7Sopenharmony_ci { 2378e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 2379e5c31af7Sopenharmony_ci DE_NULL, 2380e5c31af7Sopenharmony_ci 0u, // renderPass 2381e5c31af7Sopenharmony_ci 0u, // subpass 2382e5c31af7Sopenharmony_ci 0u, // framebuffer 2383e5c31af7Sopenharmony_ci VK_TRUE, // occlusionQueryEnable 2384e5c31af7Sopenharmony_ci VK_QUERY_CONTROL_PRECISE_BIT, // queryFlags 2385e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 2386e5c31af7Sopenharmony_ci }; 2387e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secBufferBeginInfo = 2388e5c31af7Sopenharmony_ci { 2389e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2390e5c31af7Sopenharmony_ci DE_NULL, // pNext 2391e5c31af7Sopenharmony_ci 0u, // flags 2392e5c31af7Sopenharmony_ci &secBufferInheritInfo, 2393e5c31af7Sopenharmony_ci }; 2394e5c31af7Sopenharmony_ci 2395e5c31af7Sopenharmony_ci const VkQueryPoolCreateInfo queryPoolCreateInfo = 2396e5c31af7Sopenharmony_ci { 2397e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType 2398e5c31af7Sopenharmony_ci DE_NULL, // pNext 2399e5c31af7Sopenharmony_ci (VkQueryPoolCreateFlags)0, // flags 2400e5c31af7Sopenharmony_ci VK_QUERY_TYPE_OCCLUSION, // queryType 2401e5c31af7Sopenharmony_ci 1u, // entryCount 2402e5c31af7Sopenharmony_ci 0u, // pipelineStatistics 2403e5c31af7Sopenharmony_ci }; 2404e5c31af7Sopenharmony_ci Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo)); 2405e5c31af7Sopenharmony_ci 2406e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo)); 2407e5c31af7Sopenharmony_ci endCommandBuffer(vk, secCmdBuf.get()); 2408e5c31af7Sopenharmony_ci 2409e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo)); 2410e5c31af7Sopenharmony_ci { 2411e5c31af7Sopenharmony_ci vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u); 2412e5c31af7Sopenharmony_ci vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, VK_QUERY_CONTROL_PRECISE_BIT); 2413e5c31af7Sopenharmony_ci { 2414e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get()); 2415e5c31af7Sopenharmony_ci } 2416e5c31af7Sopenharmony_ci vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u); 2417e5c31af7Sopenharmony_ci } 2418e5c31af7Sopenharmony_ci endCommandBuffer(vk, primCmdBuf.get()); 2419e5c31af7Sopenharmony_ci 2420e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Successfully recorded a secondary command buffer allowing a precise occlusion query."); 2421e5c31af7Sopenharmony_ci} 2422e5c31af7Sopenharmony_ci 2423e5c31af7Sopenharmony_citcu::TestStatus recordBufferQueryImpreciseWithFlagTest(Context& context) 2424e5c31af7Sopenharmony_ci{ 2425e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2426e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2427e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2428e5c31af7Sopenharmony_ci 2429e5c31af7Sopenharmony_ci if (!context.getDeviceFeatures().inheritedQueries) 2430e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Inherited queries feature is not supported"); 2431e5c31af7Sopenharmony_ci 2432e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2433e5c31af7Sopenharmony_ci { 2434e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 2435e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2436e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 2437e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 2438e5c31af7Sopenharmony_ci }; 2439e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2440e5c31af7Sopenharmony_ci 2441e5c31af7Sopenharmony_ci // Command buffer 2442e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo primCmdBufParams = 2443e5c31af7Sopenharmony_ci { 2444e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2445e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2446e5c31af7Sopenharmony_ci *cmdPool, // pool; 2447e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 2448e5c31af7Sopenharmony_ci 1u, // flags; 2449e5c31af7Sopenharmony_ci }; 2450e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams)); 2451e5c31af7Sopenharmony_ci 2452e5c31af7Sopenharmony_ci // Secondary Command buffer params 2453e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 2454e5c31af7Sopenharmony_ci { 2455e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2456e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2457e5c31af7Sopenharmony_ci *cmdPool, // pool; 2458e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level; 2459e5c31af7Sopenharmony_ci 1u, // flags; 2460e5c31af7Sopenharmony_ci }; 2461e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 2462e5c31af7Sopenharmony_ci 2463e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primBufferBeginInfo = 2464e5c31af7Sopenharmony_ci { 2465e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2466e5c31af7Sopenharmony_ci DE_NULL, // pNext 2467e5c31af7Sopenharmony_ci 0u, // flags 2468e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2469e5c31af7Sopenharmony_ci }; 2470e5c31af7Sopenharmony_ci 2471e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secBufferInheritInfo = 2472e5c31af7Sopenharmony_ci { 2473e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 2474e5c31af7Sopenharmony_ci DE_NULL, 2475e5c31af7Sopenharmony_ci 0u, // renderPass 2476e5c31af7Sopenharmony_ci 0u, // subpass 2477e5c31af7Sopenharmony_ci 0u, // framebuffer 2478e5c31af7Sopenharmony_ci VK_TRUE, // occlusionQueryEnable 2479e5c31af7Sopenharmony_ci VK_QUERY_CONTROL_PRECISE_BIT, // queryFlags 2480e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 2481e5c31af7Sopenharmony_ci }; 2482e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secBufferBeginInfo = 2483e5c31af7Sopenharmony_ci { 2484e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2485e5c31af7Sopenharmony_ci DE_NULL, // pNext 2486e5c31af7Sopenharmony_ci 0u, // flags 2487e5c31af7Sopenharmony_ci &secBufferInheritInfo, 2488e5c31af7Sopenharmony_ci }; 2489e5c31af7Sopenharmony_ci 2490e5c31af7Sopenharmony_ci const VkQueryPoolCreateInfo queryPoolCreateInfo = 2491e5c31af7Sopenharmony_ci { 2492e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType 2493e5c31af7Sopenharmony_ci DE_NULL, // pNext 2494e5c31af7Sopenharmony_ci 0u, // flags 2495e5c31af7Sopenharmony_ci VK_QUERY_TYPE_OCCLUSION, // queryType 2496e5c31af7Sopenharmony_ci 1u, // entryCount 2497e5c31af7Sopenharmony_ci 0u, // pipelineStatistics 2498e5c31af7Sopenharmony_ci }; 2499e5c31af7Sopenharmony_ci Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo)); 2500e5c31af7Sopenharmony_ci 2501e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo)); 2502e5c31af7Sopenharmony_ci endCommandBuffer(vk, secCmdBuf.get()); 2503e5c31af7Sopenharmony_ci 2504e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo)); 2505e5c31af7Sopenharmony_ci { 2506e5c31af7Sopenharmony_ci vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u); 2507e5c31af7Sopenharmony_ci vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, 0u); 2508e5c31af7Sopenharmony_ci { 2509e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get()); 2510e5c31af7Sopenharmony_ci } 2511e5c31af7Sopenharmony_ci vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u); 2512e5c31af7Sopenharmony_ci } 2513e5c31af7Sopenharmony_ci endCommandBuffer(vk, primCmdBuf.get()); 2514e5c31af7Sopenharmony_ci 2515e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Successfully recorded an imprecise query with a secondary command buffer allowing a precise occlusion query."); 2516e5c31af7Sopenharmony_ci} 2517e5c31af7Sopenharmony_ci 2518e5c31af7Sopenharmony_citcu::TestStatus recordBufferQueryImpreciseWithoutFlagTest(Context& context) 2519e5c31af7Sopenharmony_ci{ 2520e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2521e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2522e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2523e5c31af7Sopenharmony_ci 2524e5c31af7Sopenharmony_ci if (!context.getDeviceFeatures().inheritedQueries) 2525e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Inherited queries feature is not supported"); 2526e5c31af7Sopenharmony_ci 2527e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2528e5c31af7Sopenharmony_ci { 2529e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 2530e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2531e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 2532e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 2533e5c31af7Sopenharmony_ci }; 2534e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2535e5c31af7Sopenharmony_ci 2536e5c31af7Sopenharmony_ci // Command buffer 2537e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo primCmdBufParams = 2538e5c31af7Sopenharmony_ci { 2539e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2540e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2541e5c31af7Sopenharmony_ci *cmdPool, // pool; 2542e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 2543e5c31af7Sopenharmony_ci 1u, // flags; 2544e5c31af7Sopenharmony_ci }; 2545e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &primCmdBufParams)); 2546e5c31af7Sopenharmony_ci 2547e5c31af7Sopenharmony_ci // Secondary Command buffer params 2548e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 2549e5c31af7Sopenharmony_ci { 2550e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2551e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2552e5c31af7Sopenharmony_ci *cmdPool, // pool; 2553e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level; 2554e5c31af7Sopenharmony_ci 1u, // flags; 2555e5c31af7Sopenharmony_ci }; 2556e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 2557e5c31af7Sopenharmony_ci 2558e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primBufferBeginInfo = 2559e5c31af7Sopenharmony_ci { 2560e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2561e5c31af7Sopenharmony_ci DE_NULL, // pNext 2562e5c31af7Sopenharmony_ci 0u, // flags 2563e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2564e5c31af7Sopenharmony_ci }; 2565e5c31af7Sopenharmony_ci 2566e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secBufferInheritInfo = 2567e5c31af7Sopenharmony_ci { 2568e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 2569e5c31af7Sopenharmony_ci DE_NULL, 2570e5c31af7Sopenharmony_ci 0u, // renderPass 2571e5c31af7Sopenharmony_ci 0u, // subpass 2572e5c31af7Sopenharmony_ci 0u, // framebuffer 2573e5c31af7Sopenharmony_ci VK_TRUE, // occlusionQueryEnable 2574e5c31af7Sopenharmony_ci 0u, // queryFlags 2575e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 2576e5c31af7Sopenharmony_ci }; 2577e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secBufferBeginInfo = 2578e5c31af7Sopenharmony_ci { 2579e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2580e5c31af7Sopenharmony_ci DE_NULL, // pNext 2581e5c31af7Sopenharmony_ci 0u, // flags 2582e5c31af7Sopenharmony_ci &secBufferInheritInfo, 2583e5c31af7Sopenharmony_ci }; 2584e5c31af7Sopenharmony_ci 2585e5c31af7Sopenharmony_ci const VkQueryPoolCreateInfo queryPoolCreateInfo = 2586e5c31af7Sopenharmony_ci { 2587e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO, // sType 2588e5c31af7Sopenharmony_ci DE_NULL, // pNext 2589e5c31af7Sopenharmony_ci (VkQueryPoolCreateFlags)0, 2590e5c31af7Sopenharmony_ci VK_QUERY_TYPE_OCCLUSION, 2591e5c31af7Sopenharmony_ci 1u, 2592e5c31af7Sopenharmony_ci 0u, 2593e5c31af7Sopenharmony_ci }; 2594e5c31af7Sopenharmony_ci Unique<VkQueryPool> queryPool (createQueryPool(vk, vkDevice, &queryPoolCreateInfo)); 2595e5c31af7Sopenharmony_ci 2596e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(secCmdBuf.get(), &secBufferBeginInfo)); 2597e5c31af7Sopenharmony_ci endCommandBuffer(vk, secCmdBuf.get()); 2598e5c31af7Sopenharmony_ci 2599e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(primCmdBuf.get(), &primBufferBeginInfo)); 2600e5c31af7Sopenharmony_ci { 2601e5c31af7Sopenharmony_ci vk.cmdResetQueryPool(primCmdBuf.get(), queryPool.get(), 0u, 1u); 2602e5c31af7Sopenharmony_ci vk.cmdBeginQuery(primCmdBuf.get(), queryPool.get(), 0u, 0u); 2603e5c31af7Sopenharmony_ci { 2604e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(primCmdBuf.get(), 1u, &secCmdBuf.get()); 2605e5c31af7Sopenharmony_ci } 2606e5c31af7Sopenharmony_ci vk.cmdEndQuery(primCmdBuf.get(), queryPool.get(), 0u); 2607e5c31af7Sopenharmony_ci } 2608e5c31af7Sopenharmony_ci endCommandBuffer(vk, primCmdBuf.get()); 2609e5c31af7Sopenharmony_ci 2610e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Successfully recorded an imprecise query with a secondary command buffer not allowing a precise occlusion query."); 2611e5c31af7Sopenharmony_ci} 2612e5c31af7Sopenharmony_ci 2613e5c31af7Sopenharmony_ci/******** 19.4. Command Buffer Submission (5.4 in VK 1.0 Spec) ****************/ 2614e5c31af7Sopenharmony_citcu::TestStatus submitBufferCountNonZero(Context& context) 2615e5c31af7Sopenharmony_ci{ 2616e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2617e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2618e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 2619e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2620e5c31af7Sopenharmony_ci 2621e5c31af7Sopenharmony_ci const deUint32 BUFFER_COUNT = 5u; 2622e5c31af7Sopenharmony_ci 2623e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2624e5c31af7Sopenharmony_ci { 2625e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 2626e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2627e5c31af7Sopenharmony_ci 0u, // flags; 2628e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 2629e5c31af7Sopenharmony_ci }; 2630e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2631e5c31af7Sopenharmony_ci 2632e5c31af7Sopenharmony_ci // Command buffer 2633e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 2634e5c31af7Sopenharmony_ci { 2635e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2636e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2637e5c31af7Sopenharmony_ci *cmdPool, // pool; 2638e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 2639e5c31af7Sopenharmony_ci BUFFER_COUNT, // bufferCount; 2640e5c31af7Sopenharmony_ci }; 2641e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[BUFFER_COUNT]; 2642e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 2643e5c31af7Sopenharmony_ci 2644e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 2645e5c31af7Sopenharmony_ci { 2646e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2647e5c31af7Sopenharmony_ci DE_NULL, // pNext 2648e5c31af7Sopenharmony_ci 0u, // flags 2649e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2650e5c31af7Sopenharmony_ci }; 2651e5c31af7Sopenharmony_ci 2652e5c31af7Sopenharmony_ci std::vector<VkEventSp> events; 2653e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 2654e5c31af7Sopenharmony_ci { 2655e5c31af7Sopenharmony_ci events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice)))); 2656e5c31af7Sopenharmony_ci } 2657e5c31af7Sopenharmony_ci 2658e5c31af7Sopenharmony_ci VkCommandBuffer cmdBufferHandles[BUFFER_COUNT]; 2659e5c31af7Sopenharmony_ci 2660e5c31af7Sopenharmony_ci // Record the command buffers 2661e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 2662e5c31af7Sopenharmony_ci { 2663e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx].get(), &cmdBufBeginInfo)); 2664e5c31af7Sopenharmony_ci { 2665e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[ndx].get(), events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 2666e5c31af7Sopenharmony_ci } 2667e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffers[ndx].get()); 2668e5c31af7Sopenharmony_ci cmdBufferHandles[ndx] = cmdBuffers[ndx].get(); 2669e5c31af7Sopenharmony_ci } 2670e5c31af7Sopenharmony_ci 2671e5c31af7Sopenharmony_ci // We'll use a fence to wait for the execution of the queue 2672e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 2673e5c31af7Sopenharmony_ci 2674e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo = 2675e5c31af7Sopenharmony_ci { 2676e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2677e5c31af7Sopenharmony_ci DE_NULL, // pNext 2678e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 2679e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 2680e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 2681e5c31af7Sopenharmony_ci BUFFER_COUNT, // commandBufferCount 2682e5c31af7Sopenharmony_ci cmdBufferHandles, // pCommandBuffers 2683e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 2684e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 2685e5c31af7Sopenharmony_ci }; 2686e5c31af7Sopenharmony_ci 2687e5c31af7Sopenharmony_ci // Submit the alpha command buffer to the queue 2688e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, fence.get())); 2689e5c31af7Sopenharmony_ci // Wait for the queue 2690e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT)); 2691e5c31af7Sopenharmony_ci 2692e5c31af7Sopenharmony_ci // Check if the buffers were executed 2693e5c31af7Sopenharmony_ci tcu::TestStatus testResult = tcu::TestStatus::incomplete(); 2694e5c31af7Sopenharmony_ci 2695e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 2696e5c31af7Sopenharmony_ci { 2697e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, events[ndx]->get()) != VK_EVENT_SET) 2698e5c31af7Sopenharmony_ci { 2699e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::fail("Failed to set the event."); 2700e5c31af7Sopenharmony_ci break; 2701e5c31af7Sopenharmony_ci } 2702e5c31af7Sopenharmony_ci } 2703e5c31af7Sopenharmony_ci 2704e5c31af7Sopenharmony_ci if (!testResult.isComplete()) 2705e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::pass("All buffers were submitted and executed correctly."); 2706e5c31af7Sopenharmony_ci 2707e5c31af7Sopenharmony_ci return testResult; 2708e5c31af7Sopenharmony_ci} 2709e5c31af7Sopenharmony_ci 2710e5c31af7Sopenharmony_citcu::TestStatus submitBufferCountEqualZero(Context& context) 2711e5c31af7Sopenharmony_ci{ 2712e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2713e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2714e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 2715e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2716e5c31af7Sopenharmony_ci 2717e5c31af7Sopenharmony_ci const deUint32 BUFFER_COUNT = 2u; 2718e5c31af7Sopenharmony_ci 2719e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2720e5c31af7Sopenharmony_ci { 2721e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 2722e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2723e5c31af7Sopenharmony_ci 0u, // flags; 2724e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 2725e5c31af7Sopenharmony_ci }; 2726e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2727e5c31af7Sopenharmony_ci 2728e5c31af7Sopenharmony_ci // Command buffer 2729e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 2730e5c31af7Sopenharmony_ci { 2731e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 2732e5c31af7Sopenharmony_ci DE_NULL, // pNext; 2733e5c31af7Sopenharmony_ci *cmdPool, // pool; 2734e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 2735e5c31af7Sopenharmony_ci BUFFER_COUNT, // bufferCount; 2736e5c31af7Sopenharmony_ci }; 2737e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[BUFFER_COUNT]; 2738e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 2739e5c31af7Sopenharmony_ci 2740e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 2741e5c31af7Sopenharmony_ci { 2742e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2743e5c31af7Sopenharmony_ci DE_NULL, // pNext 2744e5c31af7Sopenharmony_ci 0u, // flags 2745e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 2746e5c31af7Sopenharmony_ci }; 2747e5c31af7Sopenharmony_ci 2748e5c31af7Sopenharmony_ci std::vector<VkEventSp> events; 2749e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 2750e5c31af7Sopenharmony_ci events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice)))); 2751e5c31af7Sopenharmony_ci 2752e5c31af7Sopenharmony_ci // Record the command buffers 2753e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 2754e5c31af7Sopenharmony_ci { 2755e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx].get(), &cmdBufBeginInfo)); 2756e5c31af7Sopenharmony_ci { 2757e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[ndx].get(), events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 2758e5c31af7Sopenharmony_ci } 2759e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffers[ndx].get()); 2760e5c31af7Sopenharmony_ci } 2761e5c31af7Sopenharmony_ci 2762e5c31af7Sopenharmony_ci // We'll use a fence to wait for the execution of the queue 2763e5c31af7Sopenharmony_ci const Unique<VkFence> fenceZero (createFence(vk, vkDevice)); 2764e5c31af7Sopenharmony_ci const Unique<VkFence> fenceOne (createFence(vk, vkDevice)); 2765e5c31af7Sopenharmony_ci 2766e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf0 = cmdBuffers[0].get(); 2767e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoCountZero = 2768e5c31af7Sopenharmony_ci { 2769e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2770e5c31af7Sopenharmony_ci DE_NULL, // pNext 2771e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 2772e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 2773e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 2774e5c31af7Sopenharmony_ci 1u, // commandBufferCount 2775e5c31af7Sopenharmony_ci &cmdBuf0, // pCommandBuffers 2776e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 2777e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 2778e5c31af7Sopenharmony_ci }; 2779e5c31af7Sopenharmony_ci 2780e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf1 = cmdBuffers[1].get(); 2781e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoCountOne = 2782e5c31af7Sopenharmony_ci { 2783e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2784e5c31af7Sopenharmony_ci DE_NULL, // pNext 2785e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 2786e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 2787e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 2788e5c31af7Sopenharmony_ci 1u, // commandBufferCount 2789e5c31af7Sopenharmony_ci &cmdBuf1, // pCommandBuffers 2790e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 2791e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 2792e5c31af7Sopenharmony_ci }; 2793e5c31af7Sopenharmony_ci 2794e5c31af7Sopenharmony_ci // Submit the command buffers to the queue 2795e5c31af7Sopenharmony_ci // We're performing two submits to make sure that the first one has 2796e5c31af7Sopenharmony_ci // a chance to be processed before we check the event's status 2797e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 0, &submitInfoCountZero, fenceZero.get())); 2798e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1, &submitInfoCountOne, fenceOne.get())); 2799e5c31af7Sopenharmony_ci 2800e5c31af7Sopenharmony_ci const VkFence fences[] = 2801e5c31af7Sopenharmony_ci { 2802e5c31af7Sopenharmony_ci fenceZero.get(), 2803e5c31af7Sopenharmony_ci fenceOne.get(), 2804e5c31af7Sopenharmony_ci }; 2805e5c31af7Sopenharmony_ci 2806e5c31af7Sopenharmony_ci // Wait for the queue 2807e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, (deUint32)DE_LENGTH_OF_ARRAY(fences), fences, VK_TRUE, INFINITE_TIMEOUT)); 2808e5c31af7Sopenharmony_ci 2809e5c31af7Sopenharmony_ci // Check if the first buffer was executed 2810e5c31af7Sopenharmony_ci tcu::TestStatus testResult = tcu::TestStatus::incomplete(); 2811e5c31af7Sopenharmony_ci 2812e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, events[0]->get()) == VK_EVENT_SET) 2813e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::fail("The first event was signaled."); 2814e5c31af7Sopenharmony_ci else 2815e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::pass("The first submission was ignored."); 2816e5c31af7Sopenharmony_ci 2817e5c31af7Sopenharmony_ci return testResult; 2818e5c31af7Sopenharmony_ci} 2819e5c31af7Sopenharmony_ci 2820e5c31af7Sopenharmony_citcu::TestStatus submitBufferWaitSingleSemaphore(Context& context) 2821e5c31af7Sopenharmony_ci{ 2822e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2823e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2824e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 2825e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2826e5c31af7Sopenharmony_ci 2827e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2828e5c31af7Sopenharmony_ci { 2829e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 2830e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2831e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 2832e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 2833e5c31af7Sopenharmony_ci }; 2834e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2835e5c31af7Sopenharmony_ci 2836e5c31af7Sopenharmony_ci // Command buffer 2837e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 2838e5c31af7Sopenharmony_ci { 2839e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 2840e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2841e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 2842e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 2843e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 2844e5c31af7Sopenharmony_ci }; 2845e5c31af7Sopenharmony_ci 2846e5c31af7Sopenharmony_ci // Create two command buffers 2847e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf1 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 2848e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf2 (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 2849e5c31af7Sopenharmony_ci 2850e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primCmdBufBeginInfo = 2851e5c31af7Sopenharmony_ci { 2852e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2853e5c31af7Sopenharmony_ci DE_NULL, // pNext 2854e5c31af7Sopenharmony_ci 0, // flags 2855e5c31af7Sopenharmony_ci DE_NULL // const VkCommandBufferInheritanceInfo* pInheritanceInfo; 2856e5c31af7Sopenharmony_ci }; 2857e5c31af7Sopenharmony_ci 2858e5c31af7Sopenharmony_ci // create two events that will be used to check if command buffers has been executed 2859e5c31af7Sopenharmony_ci const Unique<VkEvent> event1 (createEvent(vk, vkDevice)); 2860e5c31af7Sopenharmony_ci const Unique<VkEvent> event2 (createEvent(vk, vkDevice)); 2861e5c31af7Sopenharmony_ci 2862e5c31af7Sopenharmony_ci // reset events 2863e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event1)); 2864e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event2)); 2865e5c31af7Sopenharmony_ci 2866e5c31af7Sopenharmony_ci // record first command buffer 2867e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBuf1, &primCmdBufBeginInfo)); 2868e5c31af7Sopenharmony_ci { 2869e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 2870e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 2871e5c31af7Sopenharmony_ci 2872e5c31af7Sopenharmony_ci // record setting event 2873e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf1, *event1,stageMask); 2874e5c31af7Sopenharmony_ci } 2875e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf1); 2876e5c31af7Sopenharmony_ci 2877e5c31af7Sopenharmony_ci // record second command buffer 2878e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBuf2, &primCmdBufBeginInfo)); 2879e5c31af7Sopenharmony_ci { 2880e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 2881e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 2882e5c31af7Sopenharmony_ci 2883e5c31af7Sopenharmony_ci // record setting event 2884e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf2, *event2,stageMask); 2885e5c31af7Sopenharmony_ci } 2886e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf2); 2887e5c31af7Sopenharmony_ci 2888e5c31af7Sopenharmony_ci // create fence to wait for execution of queue 2889e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 2890e5c31af7Sopenharmony_ci 2891e5c31af7Sopenharmony_ci // create semaphore for use in this test 2892e5c31af7Sopenharmony_ci const Unique <VkSemaphore> semaphore (createSemaphore(vk, vkDevice)); 2893e5c31af7Sopenharmony_ci 2894e5c31af7Sopenharmony_ci // create submit info for first buffer - signalling semaphore 2895e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo1 = 2896e5c31af7Sopenharmony_ci { 2897e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2898e5c31af7Sopenharmony_ci DE_NULL, // pNext 2899e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 2900e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 2901e5c31af7Sopenharmony_ci DE_NULL, // pWaitDstStageMask 2902e5c31af7Sopenharmony_ci 1, // commandBufferCount 2903e5c31af7Sopenharmony_ci &primCmdBuf1.get(), // pCommandBuffers 2904e5c31af7Sopenharmony_ci 1u, // signalSemaphoreCount 2905e5c31af7Sopenharmony_ci &semaphore.get(), // pSignalSemaphores 2906e5c31af7Sopenharmony_ci }; 2907e5c31af7Sopenharmony_ci 2908e5c31af7Sopenharmony_ci // Submit the command buffer to the queue 2909e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence)); 2910e5c31af7Sopenharmony_ci 2911e5c31af7Sopenharmony_ci // wait for end of execution of queue 2912e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT)); 2913e5c31af7Sopenharmony_ci 2914e5c31af7Sopenharmony_ci // check if buffer has been executed 2915e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event1); 2916e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 2917e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Buffer and Wait for Single Semaphore Test FAILED"); 2918e5c31af7Sopenharmony_ci 2919e5c31af7Sopenharmony_ci const VkPipelineStageFlags waitDstStageFlags = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; 2920e5c31af7Sopenharmony_ci 2921e5c31af7Sopenharmony_ci // create submit info for second buffer - waiting for semaphore 2922e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo2 = 2923e5c31af7Sopenharmony_ci { 2924e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 2925e5c31af7Sopenharmony_ci DE_NULL, // pNext 2926e5c31af7Sopenharmony_ci 1u, // waitSemaphoreCount 2927e5c31af7Sopenharmony_ci &semaphore.get(), // pWaitSemaphores 2928e5c31af7Sopenharmony_ci &waitDstStageFlags, // pWaitDstStageMask 2929e5c31af7Sopenharmony_ci 1, // commandBufferCount 2930e5c31af7Sopenharmony_ci &primCmdBuf2.get(), // pCommandBuffers 2931e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 2932e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 2933e5c31af7Sopenharmony_ci }; 2934e5c31af7Sopenharmony_ci 2935e5c31af7Sopenharmony_ci // reset fence, so it can be used again 2936e5c31af7Sopenharmony_ci VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get())); 2937e5c31af7Sopenharmony_ci 2938e5c31af7Sopenharmony_ci // Submit the second command buffer to the queue 2939e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence)); 2940e5c31af7Sopenharmony_ci 2941e5c31af7Sopenharmony_ci // wait for end of execution of queue 2942e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT)); 2943e5c31af7Sopenharmony_ci 2944e5c31af7Sopenharmony_ci // check if second buffer has been executed 2945e5c31af7Sopenharmony_ci // if it has been executed, it means that the semaphore was signalled - so test if passed 2946e5c31af7Sopenharmony_ci result = vk.getEventStatus(vkDevice,*event1); 2947e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 2948e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Buffer and Wait for Single Semaphore Test FAILED"); 2949e5c31af7Sopenharmony_ci 2950e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Submit Buffer and Wait for Single Semaphore Test succeeded"); 2951e5c31af7Sopenharmony_ci} 2952e5c31af7Sopenharmony_ci 2953e5c31af7Sopenharmony_citcu::TestStatus submitBufferWaitManySemaphores(Context& context) 2954e5c31af7Sopenharmony_ci{ 2955e5c31af7Sopenharmony_ci // This test will create numSemaphores semaphores, and signal them in NUM_SEMAPHORES submits to queue 2956e5c31af7Sopenharmony_ci // After that the numSubmissions queue submissions will wait for each semaphore 2957e5c31af7Sopenharmony_ci 2958e5c31af7Sopenharmony_ci const deUint32 numSemaphores = 10u; // it must be multiply of numSubmission 2959e5c31af7Sopenharmony_ci const deUint32 numSubmissions = 2u; 2960e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 2961e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 2962e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 2963e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 2964e5c31af7Sopenharmony_ci 2965e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 2966e5c31af7Sopenharmony_ci { 2967e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 2968e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2969e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 2970e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 2971e5c31af7Sopenharmony_ci }; 2972e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 2973e5c31af7Sopenharmony_ci 2974e5c31af7Sopenharmony_ci // Command buffer 2975e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 2976e5c31af7Sopenharmony_ci { 2977e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 2978e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 2979e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 2980e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 2981e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 2982e5c31af7Sopenharmony_ci }; 2983e5c31af7Sopenharmony_ci 2984e5c31af7Sopenharmony_ci // Create command buffer 2985e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 2986e5c31af7Sopenharmony_ci 2987e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primCmdBufBeginInfo = 2988e5c31af7Sopenharmony_ci { 2989e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 2990e5c31af7Sopenharmony_ci DE_NULL, // pNext 2991e5c31af7Sopenharmony_ci 0, // flags 2992e5c31af7Sopenharmony_ci DE_NULL // const VkCommandBufferInheritanceInfo* pInheritanceInfo; 2993e5c31af7Sopenharmony_ci }; 2994e5c31af7Sopenharmony_ci 2995e5c31af7Sopenharmony_ci // create event that will be used to check if command buffers has been executed 2996e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 2997e5c31af7Sopenharmony_ci 2998e5c31af7Sopenharmony_ci // reset event - at creation state is undefined 2999e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 3000e5c31af7Sopenharmony_ci 3001e5c31af7Sopenharmony_ci // record command buffer 3002e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo)); 3003e5c31af7Sopenharmony_ci { 3004e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 3005e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 3006e5c31af7Sopenharmony_ci 3007e5c31af7Sopenharmony_ci // record setting event 3008e5c31af7Sopenharmony_ci vk.cmdSetEvent(*primCmdBuf, *event,stageMask); 3009e5c31af7Sopenharmony_ci } 3010e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 3011e5c31af7Sopenharmony_ci 3012e5c31af7Sopenharmony_ci // create fence to wait for execution of queue 3013e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 3014e5c31af7Sopenharmony_ci 3015e5c31af7Sopenharmony_ci // numSemaphores is declared const, so this array can be static 3016e5c31af7Sopenharmony_ci // the semaphores will be destroyed automatically at end of scope 3017e5c31af7Sopenharmony_ci Move <VkSemaphore> semaphoreArray[numSemaphores]; 3018e5c31af7Sopenharmony_ci VkSemaphore semaphores[numSemaphores]; 3019e5c31af7Sopenharmony_ci 3020e5c31af7Sopenharmony_ci for (deUint32 idx = 0; idx < numSemaphores; ++idx) { 3021e5c31af7Sopenharmony_ci // create semaphores for use in this test 3022e5c31af7Sopenharmony_ci semaphoreArray[idx] = createSemaphore(vk, vkDevice); 3023e5c31af7Sopenharmony_ci semaphores[idx] = semaphoreArray[idx].get(); 3024e5c31af7Sopenharmony_ci } 3025e5c31af7Sopenharmony_ci 3026e5c31af7Sopenharmony_ci { 3027e5c31af7Sopenharmony_ci // create submit info for buffer - signal semaphores 3028e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo1 = 3029e5c31af7Sopenharmony_ci { 3030e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3031e5c31af7Sopenharmony_ci DE_NULL, // pNext 3032e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 3033e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 3034e5c31af7Sopenharmony_ci DE_NULL, // pWaitDstStageMask 3035e5c31af7Sopenharmony_ci 1, // commandBufferCount 3036e5c31af7Sopenharmony_ci &primCmdBuf.get(), // pCommandBuffers 3037e5c31af7Sopenharmony_ci numSemaphores, // signalSemaphoreCount 3038e5c31af7Sopenharmony_ci semaphores // pSignalSemaphores 3039e5c31af7Sopenharmony_ci }; 3040e5c31af7Sopenharmony_ci // Submit the command buffer to the queue 3041e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo1, *fence)); 3042e5c31af7Sopenharmony_ci 3043e5c31af7Sopenharmony_ci // wait for end of execution of queue 3044e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, INFINITE_TIMEOUT)); 3045e5c31af7Sopenharmony_ci 3046e5c31af7Sopenharmony_ci // check if buffer has been executed 3047e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 3048e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 3049e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Buffer and Wait for Many Semaphores Test FAILED"); 3050e5c31af7Sopenharmony_ci 3051e5c31af7Sopenharmony_ci // reset event, so next buffers can set it again 3052e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 3053e5c31af7Sopenharmony_ci 3054e5c31af7Sopenharmony_ci // reset fence, so it can be used again 3055e5c31af7Sopenharmony_ci VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get())); 3056e5c31af7Sopenharmony_ci } 3057e5c31af7Sopenharmony_ci 3058e5c31af7Sopenharmony_ci const deUint32 numberOfSemaphoresToBeWaitedByOneSubmission = numSemaphores / numSubmissions; 3059e5c31af7Sopenharmony_ci const std::vector<VkPipelineStageFlags> waitDstStageFlags (numberOfSemaphoresToBeWaitedByOneSubmission, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); 3060e5c31af7Sopenharmony_ci 3061e5c31af7Sopenharmony_ci // the following code waits for the semaphores set above - numSubmissions queues will wait for each semaphore from above 3062e5c31af7Sopenharmony_ci for (deUint32 idxSubmission = 0; idxSubmission < numSubmissions; ++idxSubmission) { 3063e5c31af7Sopenharmony_ci 3064e5c31af7Sopenharmony_ci // create submit info for buffer - waiting for semaphore 3065e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo2 = 3066e5c31af7Sopenharmony_ci { 3067e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3068e5c31af7Sopenharmony_ci DE_NULL, // pNext 3069e5c31af7Sopenharmony_ci numberOfSemaphoresToBeWaitedByOneSubmission, // waitSemaphoreCount 3070e5c31af7Sopenharmony_ci semaphores + (numberOfSemaphoresToBeWaitedByOneSubmission * idxSubmission), // pWaitSemaphores 3071e5c31af7Sopenharmony_ci waitDstStageFlags.data(), // pWaitDstStageMask 3072e5c31af7Sopenharmony_ci 1, // commandBufferCount 3073e5c31af7Sopenharmony_ci &primCmdBuf.get(), // pCommandBuffers 3074e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 3075e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 3076e5c31af7Sopenharmony_ci }; 3077e5c31af7Sopenharmony_ci 3078e5c31af7Sopenharmony_ci // Submit the second command buffer to the queue 3079e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fence)); 3080e5c31af7Sopenharmony_ci 3081e5c31af7Sopenharmony_ci // wait for 1 second. 3082e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), 0u, 1000 * 1000 * 1000)); 3083e5c31af7Sopenharmony_ci 3084e5c31af7Sopenharmony_ci // check if second buffer has been executed 3085e5c31af7Sopenharmony_ci // if it has been executed, it means that the semaphore was signalled - so test if passed 3086e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice,*event); 3087e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 3088e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit Buffer and Wait for Many Semaphores Test FAILED"); 3089e5c31af7Sopenharmony_ci 3090e5c31af7Sopenharmony_ci // reset fence, so it can be used again 3091e5c31af7Sopenharmony_ci VK_CHECK(vk.resetFences(vkDevice, 1u, &fence.get())); 3092e5c31af7Sopenharmony_ci 3093e5c31af7Sopenharmony_ci // reset event, so next buffers can set it again 3094e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 3095e5c31af7Sopenharmony_ci } 3096e5c31af7Sopenharmony_ci 3097e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Submit Buffer and Wait for Many Semaphores Test succeeded"); 3098e5c31af7Sopenharmony_ci} 3099e5c31af7Sopenharmony_ci 3100e5c31af7Sopenharmony_citcu::TestStatus submitBufferNullFence(Context& context) 3101e5c31af7Sopenharmony_ci{ 3102e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 3103e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3104e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3105e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3106e5c31af7Sopenharmony_ci 3107e5c31af7Sopenharmony_ci const short BUFFER_COUNT = 2; 3108e5c31af7Sopenharmony_ci 3109e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 3110e5c31af7Sopenharmony_ci { 3111e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 3112e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3113e5c31af7Sopenharmony_ci 0u, // flags; 3114e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 3115e5c31af7Sopenharmony_ci }; 3116e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 3117e5c31af7Sopenharmony_ci 3118e5c31af7Sopenharmony_ci // Command buffer 3119e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 3120e5c31af7Sopenharmony_ci { 3121e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 3122e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3123e5c31af7Sopenharmony_ci *cmdPool, // pool; 3124e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 3125e5c31af7Sopenharmony_ci BUFFER_COUNT, // bufferCount; 3126e5c31af7Sopenharmony_ci }; 3127e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[BUFFER_COUNT]; 3128e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 3129e5c31af7Sopenharmony_ci 3130e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 3131e5c31af7Sopenharmony_ci { 3132e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 3133e5c31af7Sopenharmony_ci DE_NULL, // pNext 3134e5c31af7Sopenharmony_ci 0u, // flags 3135e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 3136e5c31af7Sopenharmony_ci }; 3137e5c31af7Sopenharmony_ci 3138e5c31af7Sopenharmony_ci std::vector<VkEventSp> events; 3139e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 3140e5c31af7Sopenharmony_ci events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice)))); 3141e5c31af7Sopenharmony_ci 3142e5c31af7Sopenharmony_ci // Record the command buffers 3143e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 3144e5c31af7Sopenharmony_ci { 3145e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx].get(), &cmdBufBeginInfo)); 3146e5c31af7Sopenharmony_ci { 3147e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[ndx].get(), events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3148e5c31af7Sopenharmony_ci } 3149e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffers[ndx].get()); 3150e5c31af7Sopenharmony_ci } 3151e5c31af7Sopenharmony_ci 3152e5c31af7Sopenharmony_ci // We'll use a fence to wait for the execution of the queue 3153e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 3154e5c31af7Sopenharmony_ci 3155e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf0 = cmdBuffers[0].get(); 3156e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoNullFence = 3157e5c31af7Sopenharmony_ci { 3158e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3159e5c31af7Sopenharmony_ci DE_NULL, // pNext 3160e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 3161e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 3162e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 3163e5c31af7Sopenharmony_ci 1u, // commandBufferCount 3164e5c31af7Sopenharmony_ci &cmdBuf0, // pCommandBuffers 3165e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 3166e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 3167e5c31af7Sopenharmony_ci }; 3168e5c31af7Sopenharmony_ci 3169e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf1 = cmdBuffers[1].get(); 3170e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoNonNullFence = 3171e5c31af7Sopenharmony_ci { 3172e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3173e5c31af7Sopenharmony_ci DE_NULL, // pNext 3174e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 3175e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 3176e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 3177e5c31af7Sopenharmony_ci 1u, // commandBufferCount 3178e5c31af7Sopenharmony_ci &cmdBuf1, // pCommandBuffers 3179e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 3180e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 3181e5c31af7Sopenharmony_ci }; 3182e5c31af7Sopenharmony_ci 3183e5c31af7Sopenharmony_ci // Perform two submissions - one with no fence, the other one with a valid 3184e5c31af7Sopenharmony_ci // fence Hoping submitting the other buffer will give the first one time to 3185e5c31af7Sopenharmony_ci // execute 3186e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNullFence, DE_NULL)); 3187e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullFence, fence.get())); 3188e5c31af7Sopenharmony_ci 3189e5c31af7Sopenharmony_ci // Wait for the queue 3190e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT)); 3191e5c31af7Sopenharmony_ci 3192e5c31af7Sopenharmony_ci 3193e5c31af7Sopenharmony_ci tcu::TestStatus testResult = tcu::TestStatus::incomplete(); 3194e5c31af7Sopenharmony_ci 3195e5c31af7Sopenharmony_ci //Fence guaranteed that all buffers submited before fence were executed 3196e5c31af7Sopenharmony_ci if (vk.getEventStatus(vkDevice, events[0]->get()) != VK_EVENT_SET || vk.getEventStatus(vkDevice, events[1]->get()) != VK_EVENT_SET) 3197e5c31af7Sopenharmony_ci { 3198e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::fail("One of the buffers was not executed."); 3199e5c31af7Sopenharmony_ci } 3200e5c31af7Sopenharmony_ci else 3201e5c31af7Sopenharmony_ci { 3202e5c31af7Sopenharmony_ci testResult = tcu::TestStatus::pass("Buffers have been submitted and executed correctly."); 3203e5c31af7Sopenharmony_ci } 3204e5c31af7Sopenharmony_ci 3205e5c31af7Sopenharmony_ci vk.queueWaitIdle(queue); 3206e5c31af7Sopenharmony_ci return testResult; 3207e5c31af7Sopenharmony_ci} 3208e5c31af7Sopenharmony_ci 3209e5c31af7Sopenharmony_citcu::TestStatus submitTwoBuffersOneBufferNullWithFence(Context& context) 3210e5c31af7Sopenharmony_ci{ 3211e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 3212e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3213e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3214e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3215e5c31af7Sopenharmony_ci const deUint32 BUFFER_COUNT = 2u; 3216e5c31af7Sopenharmony_ci 3217e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 3218e5c31af7Sopenharmony_ci { 3219e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 3220e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3221e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 3222e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 3223e5c31af7Sopenharmony_ci }; 3224e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 3225e5c31af7Sopenharmony_ci 3226e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 3227e5c31af7Sopenharmony_ci { 3228e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 3229e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3230e5c31af7Sopenharmony_ci *cmdPool, // pool; 3231e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 3232e5c31af7Sopenharmony_ci BUFFER_COUNT, // bufferCount; 3233e5c31af7Sopenharmony_ci }; 3234e5c31af7Sopenharmony_ci 3235e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[BUFFER_COUNT]; 3236e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &cmdBufParams, cmdBuffers); 3237e5c31af7Sopenharmony_ci 3238e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 3239e5c31af7Sopenharmony_ci { 3240e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 3241e5c31af7Sopenharmony_ci DE_NULL, // pNext 3242e5c31af7Sopenharmony_ci 0u, // flags 3243e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, // pInheritanceInfo 3244e5c31af7Sopenharmony_ci }; 3245e5c31af7Sopenharmony_ci 3246e5c31af7Sopenharmony_ci std::vector<VkEventSp> events; 3247e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 3248e5c31af7Sopenharmony_ci events.push_back(VkEventSp(new vk::Unique<VkEvent>(createEvent(vk, vkDevice)))); 3249e5c31af7Sopenharmony_ci 3250e5c31af7Sopenharmony_ci // Record the command buffers 3251e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 3252e5c31af7Sopenharmony_ci { 3253e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx].get(), &cmdBufBeginInfo)); 3254e5c31af7Sopenharmony_ci { 3255e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[ndx].get(), events[ndx]->get(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3256e5c31af7Sopenharmony_ci } 3257e5c31af7Sopenharmony_ci VK_CHECK(vk.endCommandBuffer(cmdBuffers[ndx].get())); 3258e5c31af7Sopenharmony_ci } 3259e5c31af7Sopenharmony_ci 3260e5c31af7Sopenharmony_ci // First command buffer 3261e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf0 = cmdBuffers[0].get(); 3262e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoNonNullFirst = 3263e5c31af7Sopenharmony_ci { 3264e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3265e5c31af7Sopenharmony_ci DE_NULL, // pNext 3266e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 3267e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 3268e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 3269e5c31af7Sopenharmony_ci 1u, // commandBufferCount 3270e5c31af7Sopenharmony_ci &cmdBuf0, // pCommandBuffers 3271e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 3272e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 3273e5c31af7Sopenharmony_ci }; 3274e5c31af7Sopenharmony_ci 3275e5c31af7Sopenharmony_ci // Second command buffer 3276e5c31af7Sopenharmony_ci VkCommandBuffer cmdBuf1 = cmdBuffers[1].get(); 3277e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfoNonNullSecond = 3278e5c31af7Sopenharmony_ci { 3279e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType 3280e5c31af7Sopenharmony_ci DE_NULL, // pNext 3281e5c31af7Sopenharmony_ci 0u, // waitSemaphoreCount 3282e5c31af7Sopenharmony_ci DE_NULL, // pWaitSemaphores 3283e5c31af7Sopenharmony_ci (const VkPipelineStageFlags*)DE_NULL, // pWaitDstStageMask 3284e5c31af7Sopenharmony_ci 1u, // commandBufferCount 3285e5c31af7Sopenharmony_ci &cmdBuf1, // pCommandBuffers 3286e5c31af7Sopenharmony_ci 0u, // signalSemaphoreCount 3287e5c31af7Sopenharmony_ci DE_NULL, // pSignalSemaphores 3288e5c31af7Sopenharmony_ci }; 3289e5c31af7Sopenharmony_ci 3290e5c31af7Sopenharmony_ci // Fence will be submitted with the null queue 3291e5c31af7Sopenharmony_ci const Unique<VkFence> fence (createFence(vk, vkDevice)); 3292e5c31af7Sopenharmony_ci 3293e5c31af7Sopenharmony_ci // Perform two separate queueSubmit calls on the same queue followed 3294e5c31af7Sopenharmony_ci // by a third call with no submitInfos and with a valid fence 3295e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullFirst, DE_NULL)); 3296e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfoNonNullSecond, DE_NULL)); 3297e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 0u, DE_NULL, fence.get())); 3298e5c31af7Sopenharmony_ci 3299e5c31af7Sopenharmony_ci // Wait for the queue 3300e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1u, &fence.get(), VK_TRUE, INFINITE_TIMEOUT)); 3301e5c31af7Sopenharmony_ci 3302e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Buffers have been submitted correctly"); 3303e5c31af7Sopenharmony_ci} 3304e5c31af7Sopenharmony_ci 3305e5c31af7Sopenharmony_ci/******** 19.5. Secondary Command Buffer Execution (5.6 in VK 1.0 Spec) *******/ 3306e5c31af7Sopenharmony_citcu::TestStatus executeSecondaryBufferTest(Context& context) 3307e5c31af7Sopenharmony_ci{ 3308e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 3309e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3310e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3311e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3312e5c31af7Sopenharmony_ci 3313e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 3314e5c31af7Sopenharmony_ci { 3315e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 3316e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3317e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // flags; 3318e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex; 3319e5c31af7Sopenharmony_ci }; 3320e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 3321e5c31af7Sopenharmony_ci 3322e5c31af7Sopenharmony_ci // Command buffer 3323e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 3324e5c31af7Sopenharmony_ci { 3325e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 3326e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3327e5c31af7Sopenharmony_ci *cmdPool, // commandPool; 3328e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level; 3329e5c31af7Sopenharmony_ci 1u, // bufferCount; 3330e5c31af7Sopenharmony_ci }; 3331e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBuf (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 3332e5c31af7Sopenharmony_ci 3333e5c31af7Sopenharmony_ci // Secondary Command buffer 3334e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 3335e5c31af7Sopenharmony_ci { 3336e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType; 3337e5c31af7Sopenharmony_ci DE_NULL, // pNext; 3338e5c31af7Sopenharmony_ci *cmdPool, // commandPool; 3339e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // level; 3340e5c31af7Sopenharmony_ci 1u, // bufferCount; 3341e5c31af7Sopenharmony_ci }; 3342e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> secCmdBuf (allocateCommandBuffer(vk, vkDevice, &secCmdBufParams)); 3343e5c31af7Sopenharmony_ci 3344e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primCmdBufBeginInfo = 3345e5c31af7Sopenharmony_ci { 3346e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 3347e5c31af7Sopenharmony_ci DE_NULL, // pNext 3348e5c31af7Sopenharmony_ci 0u, // flags 3349e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 3350e5c31af7Sopenharmony_ci }; 3351e5c31af7Sopenharmony_ci 3352e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 3353e5c31af7Sopenharmony_ci { 3354e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 3355e5c31af7Sopenharmony_ci DE_NULL, 3356e5c31af7Sopenharmony_ci DE_NULL, // renderPass 3357e5c31af7Sopenharmony_ci 0u, // subpass 3358e5c31af7Sopenharmony_ci DE_NULL, // framebuffer 3359e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 3360e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 3361e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 3362e5c31af7Sopenharmony_ci }; 3363e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 3364e5c31af7Sopenharmony_ci { 3365e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 3366e5c31af7Sopenharmony_ci DE_NULL, // pNext 3367e5c31af7Sopenharmony_ci 0u, // flags 3368e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 3369e5c31af7Sopenharmony_ci }; 3370e5c31af7Sopenharmony_ci 3371e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 3372e5c31af7Sopenharmony_ci const Unique<VkEvent> event (createEvent(vk, vkDevice)); 3373e5c31af7Sopenharmony_ci 3374e5c31af7Sopenharmony_ci // reset event 3375e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *event)); 3376e5c31af7Sopenharmony_ci 3377e5c31af7Sopenharmony_ci // record secondary command buffer 3378e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*secCmdBuf, &secCmdBufBeginInfo)); 3379e5c31af7Sopenharmony_ci { 3380e5c31af7Sopenharmony_ci // allow execution of event during every stage of pipeline 3381e5c31af7Sopenharmony_ci VkPipelineStageFlags stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; 3382e5c31af7Sopenharmony_ci // record setting event 3383e5c31af7Sopenharmony_ci vk.cmdSetEvent(*secCmdBuf, *event, stageMask); 3384e5c31af7Sopenharmony_ci } 3385e5c31af7Sopenharmony_ci // end recording of the secondary buffer 3386e5c31af7Sopenharmony_ci endCommandBuffer(vk, *secCmdBuf); 3387e5c31af7Sopenharmony_ci 3388e5c31af7Sopenharmony_ci // record primary command buffer 3389e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBuf, &primCmdBufBeginInfo)); 3390e5c31af7Sopenharmony_ci { 3391e5c31af7Sopenharmony_ci // execute secondary buffer 3392e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBuf, 1u, &secCmdBuf.get()); 3393e5c31af7Sopenharmony_ci } 3394e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBuf); 3395e5c31af7Sopenharmony_ci 3396e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, primCmdBuf.get()); 3397e5c31af7Sopenharmony_ci 3398e5c31af7Sopenharmony_ci // check if secondary buffer has been executed 3399e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice, *event); 3400e5c31af7Sopenharmony_ci if (result == VK_EVENT_SET) 3401e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("executeSecondaryBufferTest succeeded"); 3402e5c31af7Sopenharmony_ci 3403e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("executeSecondaryBufferTest FAILED"); 3404e5c31af7Sopenharmony_ci} 3405e5c31af7Sopenharmony_ci 3406e5c31af7Sopenharmony_citcu::TestStatus executeSecondaryBufferTwiceTest(Context& context) 3407e5c31af7Sopenharmony_ci{ 3408e5c31af7Sopenharmony_ci const deUint32 BUFFER_COUNT = 10u; 3409e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 3410e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3411e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3412e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3413e5c31af7Sopenharmony_ci 3414e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolParams = 3415e5c31af7Sopenharmony_ci { 3416e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType; 3417e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 3418e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // VkCommandPoolCreateFlags flags; 3419e5c31af7Sopenharmony_ci queueFamilyIndex, // deUint32 queueFamilyIndex; 3420e5c31af7Sopenharmony_ci }; 3421e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, &cmdPoolParams)); 3422e5c31af7Sopenharmony_ci 3423e5c31af7Sopenharmony_ci // Command buffer 3424e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufParams = 3425e5c31af7Sopenharmony_ci { 3426e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 3427e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 3428e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 3429e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level; 3430e5c31af7Sopenharmony_ci 1u, // uint32_t bufferCount; 3431e5c31af7Sopenharmony_ci }; 3432e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBufOne (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 3433e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> primCmdBufTwo (allocateCommandBuffer(vk, vkDevice, &cmdBufParams)); 3434e5c31af7Sopenharmony_ci 3435e5c31af7Sopenharmony_ci // Secondary Command buffers params 3436e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo secCmdBufParams = 3437e5c31af7Sopenharmony_ci { 3438e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType; 3439e5c31af7Sopenharmony_ci DE_NULL, // const void* pNext; 3440e5c31af7Sopenharmony_ci *cmdPool, // VkCommandPool pool; 3441e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_SECONDARY, // VkCommandBufferLevel level; 3442e5c31af7Sopenharmony_ci BUFFER_COUNT, // uint32_t bufferCount; 3443e5c31af7Sopenharmony_ci }; 3444e5c31af7Sopenharmony_ci Move<VkCommandBuffer> cmdBuffers[BUFFER_COUNT]; 3445e5c31af7Sopenharmony_ci allocateCommandBuffers(vk, vkDevice, &secCmdBufParams, cmdBuffers); 3446e5c31af7Sopenharmony_ci 3447e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo primCmdBufBeginInfo = 3448e5c31af7Sopenharmony_ci { 3449e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 3450e5c31af7Sopenharmony_ci DE_NULL, 3451e5c31af7Sopenharmony_ci 0, // flags 3452e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 3453e5c31af7Sopenharmony_ci }; 3454e5c31af7Sopenharmony_ci 3455e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo secCmdBufInheritInfo = 3456e5c31af7Sopenharmony_ci { 3457e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 3458e5c31af7Sopenharmony_ci DE_NULL, 3459e5c31af7Sopenharmony_ci (VkRenderPass)0u, // renderPass 3460e5c31af7Sopenharmony_ci 0u, // subpass 3461e5c31af7Sopenharmony_ci (VkFramebuffer)0u, // framebuffer 3462e5c31af7Sopenharmony_ci VK_FALSE, // occlusionQueryEnable 3463e5c31af7Sopenharmony_ci (VkQueryControlFlags)0u, // queryFlags 3464e5c31af7Sopenharmony_ci (VkQueryPipelineStatisticFlags)0u, // pipelineStatistics 3465e5c31af7Sopenharmony_ci }; 3466e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo secCmdBufBeginInfo = 3467e5c31af7Sopenharmony_ci { 3468e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 3469e5c31af7Sopenharmony_ci DE_NULL, 3470e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, // flags 3471e5c31af7Sopenharmony_ci &secCmdBufInheritInfo, 3472e5c31af7Sopenharmony_ci }; 3473e5c31af7Sopenharmony_ci 3474e5c31af7Sopenharmony_ci // create event that will be used to check if secondary command buffer has been executed 3475e5c31af7Sopenharmony_ci const Unique<VkEvent> eventOne (createEvent(vk, vkDevice)); 3476e5c31af7Sopenharmony_ci 3477e5c31af7Sopenharmony_ci // reset event 3478e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *eventOne)); 3479e5c31af7Sopenharmony_ci 3480e5c31af7Sopenharmony_ci VkCommandBuffer cmdBufferHandles[BUFFER_COUNT]; 3481e5c31af7Sopenharmony_ci 3482e5c31af7Sopenharmony_ci for (deUint32 ndx = 0; ndx < BUFFER_COUNT; ++ndx) 3483e5c31af7Sopenharmony_ci { 3484e5c31af7Sopenharmony_ci // record secondary command buffer 3485e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(cmdBuffers[ndx].get(), &secCmdBufBeginInfo)); 3486e5c31af7Sopenharmony_ci { 3487e5c31af7Sopenharmony_ci // set event 3488e5c31af7Sopenharmony_ci vk.cmdSetEvent(cmdBuffers[ndx].get(), *eventOne, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); 3489e5c31af7Sopenharmony_ci } 3490e5c31af7Sopenharmony_ci // end recording of secondary buffers 3491e5c31af7Sopenharmony_ci endCommandBuffer(vk, cmdBuffers[ndx].get()); 3492e5c31af7Sopenharmony_ci cmdBufferHandles[ndx] = cmdBuffers[ndx].get(); 3493e5c31af7Sopenharmony_ci } 3494e5c31af7Sopenharmony_ci 3495e5c31af7Sopenharmony_ci // record primary command buffer one 3496e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBufOne, &primCmdBufBeginInfo)); 3497e5c31af7Sopenharmony_ci { 3498e5c31af7Sopenharmony_ci // execute one secondary buffer 3499e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBufOne, 1, cmdBufferHandles); 3500e5c31af7Sopenharmony_ci } 3501e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBufOne); 3502e5c31af7Sopenharmony_ci 3503e5c31af7Sopenharmony_ci // record primary command buffer two 3504e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*primCmdBufTwo, &primCmdBufBeginInfo)); 3505e5c31af7Sopenharmony_ci { 3506e5c31af7Sopenharmony_ci // execute one secondary buffer with all buffers 3507e5c31af7Sopenharmony_ci vk.cmdExecuteCommands(*primCmdBufTwo, BUFFER_COUNT, cmdBufferHandles); 3508e5c31af7Sopenharmony_ci } 3509e5c31af7Sopenharmony_ci endCommandBuffer(vk, *primCmdBufTwo); 3510e5c31af7Sopenharmony_ci 3511e5c31af7Sopenharmony_ci // create fence to wait for execution of queue 3512e5c31af7Sopenharmony_ci const Unique<VkFence> fenceOne (createFence(vk, vkDevice)); 3513e5c31af7Sopenharmony_ci const Unique<VkFence> fenceTwo (createFence(vk, vkDevice)); 3514e5c31af7Sopenharmony_ci 3515e5c31af7Sopenharmony_ci const uint64_t semaphoreWaitValue = 1ull; 3516e5c31af7Sopenharmony_ci const VkPipelineStageFlags semaphoreWaitStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; 3517e5c31af7Sopenharmony_ci const auto semaphore = createSemaphoreType(vk, vkDevice, VK_SEMAPHORE_TYPE_TIMELINE); 3518e5c31af7Sopenharmony_ci 3519e5c31af7Sopenharmony_ci // Use timeline semaphore to wait for signal from the host. 3520e5c31af7Sopenharmony_ci const VkTimelineSemaphoreSubmitInfo timelineWaitSubmitInfo = 3521e5c31af7Sopenharmony_ci { 3522e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, // VkStructureType sType; 3523e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 3524e5c31af7Sopenharmony_ci 1u, // uint32_t waitSemaphoreValueCount; 3525e5c31af7Sopenharmony_ci &semaphoreWaitValue, // const uint64_t* pWaitSemaphoreValues; 3526e5c31af7Sopenharmony_ci 0u, // uint32_t signalSemaphoreValueCount; 3527e5c31af7Sopenharmony_ci nullptr, // const uint64_t* pSignalSemaphoreValues; 3528e5c31af7Sopenharmony_ci }; 3529e5c31af7Sopenharmony_ci 3530e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo = 3531e5c31af7Sopenharmony_ci { 3532e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType; 3533e5c31af7Sopenharmony_ci &timelineWaitSubmitInfo, // const void* pNext; 3534e5c31af7Sopenharmony_ci 1u, // uint32_t waitSemaphoreCount; 3535e5c31af7Sopenharmony_ci &semaphore.get(), // const VkSemaphore* pWaitSemaphores; 3536e5c31af7Sopenharmony_ci &semaphoreWaitStage, // const VkPipelineStageFlags* pWaitDstStageMask; 3537e5c31af7Sopenharmony_ci 1u, // uint32_t commandBufferCount; 3538e5c31af7Sopenharmony_ci &primCmdBufOne.get(), // const VkCommandBuffer* pCommandBuffers; 3539e5c31af7Sopenharmony_ci 0u, // uint32_t signalSemaphoreCount; 3540e5c31af7Sopenharmony_ci nullptr, // const VkSemaphore* pSignalSemaphores; 3541e5c31af7Sopenharmony_ci }; 3542e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo, *fenceOne)); 3543e5c31af7Sopenharmony_ci 3544e5c31af7Sopenharmony_ci const VkSubmitInfo submitInfo2 = 3545e5c31af7Sopenharmony_ci { 3546e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType; 3547e5c31af7Sopenharmony_ci &timelineWaitSubmitInfo, // const void* pNext; 3548e5c31af7Sopenharmony_ci 1u, // uint32_t waitSemaphoreCount; 3549e5c31af7Sopenharmony_ci &semaphore.get(), // const VkSemaphore* pWaitSemaphores; 3550e5c31af7Sopenharmony_ci &semaphoreWaitStage, // const VkPipelineStageFlags* pWaitDstStageMask; 3551e5c31af7Sopenharmony_ci 1u, // uint32_t commandBufferCount; 3552e5c31af7Sopenharmony_ci &primCmdBufTwo.get(), // const VkCommandBuffer* pCommandBuffers; 3553e5c31af7Sopenharmony_ci 0u, // uint32_t signalSemaphoreCount; 3554e5c31af7Sopenharmony_ci nullptr, // const VkSemaphore* pSignalSemaphores; 3555e5c31af7Sopenharmony_ci }; 3556e5c31af7Sopenharmony_ci 3557e5c31af7Sopenharmony_ci VK_CHECK(vk.queueSubmit(queue, 1u, &submitInfo2, *fenceTwo)); 3558e5c31af7Sopenharmony_ci 3559e5c31af7Sopenharmony_ci // Signal from host 3560e5c31af7Sopenharmony_ci const vk::VkSemaphoreSignalInfo signalInfo = 3561e5c31af7Sopenharmony_ci { 3562e5c31af7Sopenharmony_ci vk::VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO, // VkStructureType sType; 3563e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 3564e5c31af7Sopenharmony_ci semaphore.get(), // VkSemaphore semaphore; 3565e5c31af7Sopenharmony_ci semaphoreWaitValue, // uint64_t value; 3566e5c31af7Sopenharmony_ci }; 3567e5c31af7Sopenharmony_ci 3568e5c31af7Sopenharmony_ci VK_CHECK(vk.signalSemaphore(vkDevice, &signalInfo)); 3569e5c31af7Sopenharmony_ci 3570e5c31af7Sopenharmony_ci // wait for end of execution of fenceOne 3571e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceOne.get(), 0u, INFINITE_TIMEOUT)); 3572e5c31af7Sopenharmony_ci 3573e5c31af7Sopenharmony_ci // wait for end of execution of fenceTwo 3574e5c31af7Sopenharmony_ci VK_CHECK(vk.waitForFences(vkDevice, 1, &fenceTwo.get(), 0u, INFINITE_TIMEOUT)); 3575e5c31af7Sopenharmony_ci 3576e5c31af7Sopenharmony_ci TCU_CHECK(vk.getEventStatus(vkDevice, *eventOne) == vk::VK_EVENT_SET); 3577e5c31af7Sopenharmony_ci 3578e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("executeSecondaryBufferTwiceTest succeeded"); 3579e5c31af7Sopenharmony_ci} 3580e5c31af7Sopenharmony_ci 3581e5c31af7Sopenharmony_ci/******** 19.6. Commands Allowed Inside Command Buffers (? in VK 1.0 Spec) **/ 3582e5c31af7Sopenharmony_citcu::TestStatus orderBindPipelineTest(Context& context) 3583e5c31af7Sopenharmony_ci{ 3584e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3585e5c31af7Sopenharmony_ci const VkDevice device = context.getDevice(); 3586e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3587e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3588e5c31af7Sopenharmony_ci Allocator& allocator = context.getDefaultAllocator(); 3589e5c31af7Sopenharmony_ci const ComputeInstanceResultBuffer result (vk, device, allocator); 3590e5c31af7Sopenharmony_ci 3591e5c31af7Sopenharmony_ci enum 3592e5c31af7Sopenharmony_ci { 3593e5c31af7Sopenharmony_ci ADDRESSABLE_SIZE = 256, // allocate a lot more than required 3594e5c31af7Sopenharmony_ci }; 3595e5c31af7Sopenharmony_ci 3596e5c31af7Sopenharmony_ci const tcu::Vec4 colorA1 = tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0f); 3597e5c31af7Sopenharmony_ci const tcu::Vec4 colorA2 = tcu::Vec4(1.0f, 1.0f, 0.0f, 1.0f); 3598e5c31af7Sopenharmony_ci const tcu::Vec4 colorB1 = tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f); 3599e5c31af7Sopenharmony_ci const tcu::Vec4 colorB2 = tcu::Vec4(0.0f, 0.0f, 1.0f, 1.0f); 3600e5c31af7Sopenharmony_ci 3601e5c31af7Sopenharmony_ci const deUint32 dataOffsetA = (0u); 3602e5c31af7Sopenharmony_ci const deUint32 dataOffsetB = (0u); 3603e5c31af7Sopenharmony_ci const deUint32 viewOffsetA = (0u); 3604e5c31af7Sopenharmony_ci const deUint32 viewOffsetB = (0u); 3605e5c31af7Sopenharmony_ci const deUint32 bufferSizeA = dataOffsetA + ADDRESSABLE_SIZE; 3606e5c31af7Sopenharmony_ci const deUint32 bufferSizeB = dataOffsetB + ADDRESSABLE_SIZE; 3607e5c31af7Sopenharmony_ci 3608e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferMemA; 3609e5c31af7Sopenharmony_ci const Unique<VkBuffer> bufferA (createColorDataBuffer(dataOffsetA, bufferSizeA, colorA1, colorA2, &bufferMemA, context)); 3610e5c31af7Sopenharmony_ci 3611e5c31af7Sopenharmony_ci de::MovePtr<Allocation> bufferMemB; 3612e5c31af7Sopenharmony_ci const Unique<VkBuffer> bufferB (createColorDataBuffer(dataOffsetB, bufferSizeB, colorB1, colorB2, &bufferMemB, context)); 3613e5c31af7Sopenharmony_ci 3614e5c31af7Sopenharmony_ci const Unique<VkDescriptorSetLayout> descriptorSetLayout (createDescriptorSetLayout(context)); 3615e5c31af7Sopenharmony_ci const Unique<VkDescriptorPool> descriptorPool (createDescriptorPool(context)); 3616e5c31af7Sopenharmony_ci const Unique<VkDescriptorSet> descriptorSet (createDescriptorSet(*descriptorPool, *descriptorSetLayout, *bufferA, viewOffsetA, *bufferB, viewOffsetB, result.getBuffer(), context)); 3617e5c31af7Sopenharmony_ci const VkDescriptorSet descriptorSets[] = { *descriptorSet }; 3618e5c31af7Sopenharmony_ci const int numDescriptorSets = DE_LENGTH_OF_ARRAY(descriptorSets); 3619e5c31af7Sopenharmony_ci 3620e5c31af7Sopenharmony_ci const VkPipelineLayoutCreateInfo layoutCreateInfo = 3621e5c31af7Sopenharmony_ci { 3622e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // sType 3623e5c31af7Sopenharmony_ci DE_NULL, // pNext 3624e5c31af7Sopenharmony_ci (VkPipelineLayoutCreateFlags)0, 3625e5c31af7Sopenharmony_ci numDescriptorSets, // setLayoutCount 3626e5c31af7Sopenharmony_ci &descriptorSetLayout.get(), // pSetLayouts 3627e5c31af7Sopenharmony_ci 0u, // pushConstantRangeCount 3628e5c31af7Sopenharmony_ci DE_NULL, // pPushConstantRanges 3629e5c31af7Sopenharmony_ci }; 3630e5c31af7Sopenharmony_ci Unique<VkPipelineLayout> pipelineLayout (createPipelineLayout(vk, device, &layoutCreateInfo)); 3631e5c31af7Sopenharmony_ci 3632e5c31af7Sopenharmony_ci const Unique<VkShaderModule> computeModuleGood (createShaderModule(vk, device, context.getBinaryCollection().get("compute_good"), (VkShaderModuleCreateFlags)0u)); 3633e5c31af7Sopenharmony_ci const Unique<VkShaderModule> computeModuleBad (createShaderModule(vk, device, context.getBinaryCollection().get("compute_bad"), (VkShaderModuleCreateFlags)0u)); 3634e5c31af7Sopenharmony_ci 3635e5c31af7Sopenharmony_ci const VkPipelineShaderStageCreateInfo shaderCreateInfoGood = 3636e5c31af7Sopenharmony_ci { 3637e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 3638e5c31af7Sopenharmony_ci DE_NULL, 3639e5c31af7Sopenharmony_ci (VkPipelineShaderStageCreateFlags)0, 3640e5c31af7Sopenharmony_ci VK_SHADER_STAGE_COMPUTE_BIT, // stage 3641e5c31af7Sopenharmony_ci *computeModuleGood, // shader 3642e5c31af7Sopenharmony_ci "main", 3643e5c31af7Sopenharmony_ci DE_NULL, // pSpecializationInfo 3644e5c31af7Sopenharmony_ci }; 3645e5c31af7Sopenharmony_ci 3646e5c31af7Sopenharmony_ci const VkPipelineShaderStageCreateInfo shaderCreateInfoBad = 3647e5c31af7Sopenharmony_ci { 3648e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, 3649e5c31af7Sopenharmony_ci DE_NULL, 3650e5c31af7Sopenharmony_ci (vk::VkPipelineShaderStageCreateFlags)0, 3651e5c31af7Sopenharmony_ci vk::VK_SHADER_STAGE_COMPUTE_BIT, // stage 3652e5c31af7Sopenharmony_ci *computeModuleBad, // shader 3653e5c31af7Sopenharmony_ci "main", 3654e5c31af7Sopenharmony_ci DE_NULL, // pSpecializationInfo 3655e5c31af7Sopenharmony_ci }; 3656e5c31af7Sopenharmony_ci 3657e5c31af7Sopenharmony_ci const VkComputePipelineCreateInfo createInfoGood = 3658e5c31af7Sopenharmony_ci { 3659e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 3660e5c31af7Sopenharmony_ci DE_NULL, 3661e5c31af7Sopenharmony_ci 0u, // flags 3662e5c31af7Sopenharmony_ci shaderCreateInfoGood, // cs 3663e5c31af7Sopenharmony_ci *pipelineLayout, // layout 3664e5c31af7Sopenharmony_ci (vk::VkPipeline)0, // basePipelineHandle 3665e5c31af7Sopenharmony_ci 0u, // basePipelineIndex 3666e5c31af7Sopenharmony_ci }; 3667e5c31af7Sopenharmony_ci 3668e5c31af7Sopenharmony_ci const VkComputePipelineCreateInfo createInfoBad = 3669e5c31af7Sopenharmony_ci { 3670e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, 3671e5c31af7Sopenharmony_ci DE_NULL, 3672e5c31af7Sopenharmony_ci 0u, // flags 3673e5c31af7Sopenharmony_ci shaderCreateInfoBad, // cs 3674e5c31af7Sopenharmony_ci *pipelineLayout, // descriptorSetLayout.get() 3675e5c31af7Sopenharmony_ci (VkPipeline)0, // basePipelineHandle 3676e5c31af7Sopenharmony_ci 0u, // basePipelineIndex 3677e5c31af7Sopenharmony_ci }; 3678e5c31af7Sopenharmony_ci 3679e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipelineGood (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoGood)); 3680e5c31af7Sopenharmony_ci const Unique<VkPipeline> pipelineBad (createComputePipeline(vk, device, (VkPipelineCache)0u, &createInfoBad)); 3681e5c31af7Sopenharmony_ci 3682e5c31af7Sopenharmony_ci const VkAccessFlags inputBit = (VK_ACCESS_UNIFORM_READ_BIT); 3683e5c31af7Sopenharmony_ci const VkBufferMemoryBarrier bufferBarriers[] = 3684e5c31af7Sopenharmony_ci { 3685e5c31af7Sopenharmony_ci { 3686e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, 3687e5c31af7Sopenharmony_ci DE_NULL, 3688e5c31af7Sopenharmony_ci VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask 3689e5c31af7Sopenharmony_ci inputBit, // dstAccessMask 3690e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex 3691e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex 3692e5c31af7Sopenharmony_ci *bufferA, // buffer 3693e5c31af7Sopenharmony_ci (VkDeviceSize)0u, // offset 3694e5c31af7Sopenharmony_ci (VkDeviceSize)bufferSizeA, // size 3695e5c31af7Sopenharmony_ci }, 3696e5c31af7Sopenharmony_ci { 3697e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, 3698e5c31af7Sopenharmony_ci DE_NULL, 3699e5c31af7Sopenharmony_ci VK_ACCESS_HOST_WRITE_BIT, // srcAccessMask 3700e5c31af7Sopenharmony_ci inputBit, // dstAccessMask 3701e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex 3702e5c31af7Sopenharmony_ci VK_QUEUE_FAMILY_IGNORED, // destQueueFamilyIndex 3703e5c31af7Sopenharmony_ci *bufferB, // buffer 3704e5c31af7Sopenharmony_ci (VkDeviceSize)0u, // offset 3705e5c31af7Sopenharmony_ci (VkDeviceSize)bufferSizeB, // size 3706e5c31af7Sopenharmony_ci } 3707e5c31af7Sopenharmony_ci }; 3708e5c31af7Sopenharmony_ci 3709e5c31af7Sopenharmony_ci const deUint32 numSrcBuffers = 1u; 3710e5c31af7Sopenharmony_ci 3711e5c31af7Sopenharmony_ci const deUint32* const dynamicOffsets = (DE_NULL); 3712e5c31af7Sopenharmony_ci const deUint32 numDynamicOffsets = (0); 3713e5c31af7Sopenharmony_ci const int numPreBarriers = numSrcBuffers; 3714e5c31af7Sopenharmony_ci const vk::VkBufferMemoryBarrier* const postBarriers = result.getResultReadBarrier(); 3715e5c31af7Sopenharmony_ci const int numPostBarriers = 1; 3716e5c31af7Sopenharmony_ci const tcu::Vec4 refQuadrantValue14 = (colorA2); 3717e5c31af7Sopenharmony_ci const tcu::Vec4 refQuadrantValue23 = (colorA1); 3718e5c31af7Sopenharmony_ci const tcu::Vec4 references[4] = 3719e5c31af7Sopenharmony_ci { 3720e5c31af7Sopenharmony_ci refQuadrantValue14, 3721e5c31af7Sopenharmony_ci refQuadrantValue23, 3722e5c31af7Sopenharmony_ci refQuadrantValue23, 3723e5c31af7Sopenharmony_ci refQuadrantValue14, 3724e5c31af7Sopenharmony_ci }; 3725e5c31af7Sopenharmony_ci tcu::Vec4 results[4]; 3726e5c31af7Sopenharmony_ci 3727e5c31af7Sopenharmony_ci // submit and wait begin 3728e5c31af7Sopenharmony_ci 3729e5c31af7Sopenharmony_ci const tcu::UVec3 numWorkGroups = tcu::UVec3(4, 1u, 1); 3730e5c31af7Sopenharmony_ci 3731e5c31af7Sopenharmony_ci const VkCommandPoolCreateInfo cmdPoolCreateInfo = 3732e5c31af7Sopenharmony_ci { 3733e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // sType; 3734e5c31af7Sopenharmony_ci DE_NULL, // pNext 3735e5c31af7Sopenharmony_ci VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // flags 3736e5c31af7Sopenharmony_ci queueFamilyIndex, // queueFamilyIndex 3737e5c31af7Sopenharmony_ci }; 3738e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, device, &cmdPoolCreateInfo)); 3739e5c31af7Sopenharmony_ci const VkCommandBufferAllocateInfo cmdBufCreateInfo = 3740e5c31af7Sopenharmony_ci { 3741e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // sType 3742e5c31af7Sopenharmony_ci DE_NULL, // pNext 3743e5c31af7Sopenharmony_ci *cmdPool, // commandPool 3744e5c31af7Sopenharmony_ci VK_COMMAND_BUFFER_LEVEL_PRIMARY, // level 3745e5c31af7Sopenharmony_ci 1u, // bufferCount; 3746e5c31af7Sopenharmony_ci }; 3747e5c31af7Sopenharmony_ci 3748e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo cmdBufBeginInfo = 3749e5c31af7Sopenharmony_ci { 3750e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // sType 3751e5c31af7Sopenharmony_ci DE_NULL, // pNext 3752e5c31af7Sopenharmony_ci 0u, // flags 3753e5c31af7Sopenharmony_ci (const VkCommandBufferInheritanceInfo*)DE_NULL, 3754e5c31af7Sopenharmony_ci }; 3755e5c31af7Sopenharmony_ci 3756e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmd (allocateCommandBuffer(vk, device, &cmdBufCreateInfo)); 3757e5c31af7Sopenharmony_ci 3758e5c31af7Sopenharmony_ci VK_CHECK(vk.beginCommandBuffer(*cmd, &cmdBufBeginInfo)); 3759e5c31af7Sopenharmony_ci 3760e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineBad); 3761e5c31af7Sopenharmony_ci vk.cmdBindPipeline(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineGood); 3762e5c31af7Sopenharmony_ci vk.cmdBindDescriptorSets(*cmd, VK_PIPELINE_BIND_POINT_COMPUTE, *pipelineLayout, 0, numDescriptorSets, descriptorSets, numDynamicOffsets, dynamicOffsets); 3763e5c31af7Sopenharmony_ci 3764e5c31af7Sopenharmony_ci if (numPreBarriers) 3765e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmd, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, (VkDependencyFlags)0, 3766e5c31af7Sopenharmony_ci 0, (const VkMemoryBarrier*)DE_NULL, 3767e5c31af7Sopenharmony_ci numPreBarriers, bufferBarriers, 3768e5c31af7Sopenharmony_ci 0, (const VkImageMemoryBarrier*)DE_NULL); 3769e5c31af7Sopenharmony_ci 3770e5c31af7Sopenharmony_ci vk.cmdDispatch(*cmd, numWorkGroups.x(), numWorkGroups.y(), numWorkGroups.z()); 3771e5c31af7Sopenharmony_ci vk.cmdPipelineBarrier(*cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 3772e5c31af7Sopenharmony_ci 0, (const VkMemoryBarrier*)DE_NULL, 3773e5c31af7Sopenharmony_ci numPostBarriers, postBarriers, 3774e5c31af7Sopenharmony_ci 0, (const VkImageMemoryBarrier*)DE_NULL); 3775e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmd); 3776e5c31af7Sopenharmony_ci 3777e5c31af7Sopenharmony_ci // run 3778e5c31af7Sopenharmony_ci // submit second primary buffer, the secondary should be executed too 3779e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, device, queue, cmd.get()); 3780e5c31af7Sopenharmony_ci 3781e5c31af7Sopenharmony_ci // submit and wait end 3782e5c31af7Sopenharmony_ci result.readResultContentsTo(&results); 3783e5c31af7Sopenharmony_ci 3784e5c31af7Sopenharmony_ci // verify 3785e5c31af7Sopenharmony_ci if (results[0] == references[0] && 3786e5c31af7Sopenharmony_ci results[1] == references[1] && 3787e5c31af7Sopenharmony_ci results[2] == references[2] && 3788e5c31af7Sopenharmony_ci results[3] == references[3]) 3789e5c31af7Sopenharmony_ci { 3790e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Pass"); 3791e5c31af7Sopenharmony_ci } 3792e5c31af7Sopenharmony_ci else if (results[0] == tcu::Vec4(-1.0f) && 3793e5c31af7Sopenharmony_ci results[1] == tcu::Vec4(-1.0f) && 3794e5c31af7Sopenharmony_ci results[2] == tcu::Vec4(-1.0f) && 3795e5c31af7Sopenharmony_ci results[3] == tcu::Vec4(-1.0f)) 3796e5c31af7Sopenharmony_ci { 3797e5c31af7Sopenharmony_ci context.getTestContext().getLog() 3798e5c31af7Sopenharmony_ci << tcu::TestLog::Message 3799e5c31af7Sopenharmony_ci << "Result buffer was not written to." 3800e5c31af7Sopenharmony_ci << tcu::TestLog::EndMessage; 3801e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Result buffer was not written to"); 3802e5c31af7Sopenharmony_ci } 3803e5c31af7Sopenharmony_ci else 3804e5c31af7Sopenharmony_ci { 3805e5c31af7Sopenharmony_ci context.getTestContext().getLog() 3806e5c31af7Sopenharmony_ci << tcu::TestLog::Message 3807e5c31af7Sopenharmony_ci << "Error expected [" 3808e5c31af7Sopenharmony_ci << references[0] << ", " 3809e5c31af7Sopenharmony_ci << references[1] << ", " 3810e5c31af7Sopenharmony_ci << references[2] << ", " 3811e5c31af7Sopenharmony_ci << references[3] << "], got [" 3812e5c31af7Sopenharmony_ci << results[0] << ", " 3813e5c31af7Sopenharmony_ci << results[1] << ", " 3814e5c31af7Sopenharmony_ci << results[2] << ", " 3815e5c31af7Sopenharmony_ci << results[3] << "]" 3816e5c31af7Sopenharmony_ci << tcu::TestLog::EndMessage; 3817e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Invalid result values"); 3818e5c31af7Sopenharmony_ci } 3819e5c31af7Sopenharmony_ci} 3820e5c31af7Sopenharmony_ci 3821e5c31af7Sopenharmony_cienum StateTransitionTest 3822e5c31af7Sopenharmony_ci{ 3823e5c31af7Sopenharmony_ci STT_RECORDING_TO_INITIAL = 0, 3824e5c31af7Sopenharmony_ci STT_EXECUTABLE_TO_INITIAL, 3825e5c31af7Sopenharmony_ci STT_RECORDING_TO_INVALID, 3826e5c31af7Sopenharmony_ci STT_EXECUTABLE_TO_INVALID, 3827e5c31af7Sopenharmony_ci}; 3828e5c31af7Sopenharmony_ci 3829e5c31af7Sopenharmony_citcu::TestStatus executeStateTransitionTest(Context& context, StateTransitionTest type) 3830e5c31af7Sopenharmony_ci{ 3831e5c31af7Sopenharmony_ci const VkDevice vkDevice = context.getDevice(); 3832e5c31af7Sopenharmony_ci const DeviceInterface& vk = context.getDeviceInterface(); 3833e5c31af7Sopenharmony_ci const VkQueue queue = context.getUniversalQueue(); 3834e5c31af7Sopenharmony_ci const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex(); 3835e5c31af7Sopenharmony_ci 3836e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 3837e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().commandPoolResetCommandBuffer == VK_FALSE) 3838e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandPoolResetCommandBuffer not supported by this implementation"); 3839e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 3840e5c31af7Sopenharmony_ci 3841e5c31af7Sopenharmony_ci const Unique<VkCommandPool> cmdPool (createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex)); 3842e5c31af7Sopenharmony_ci const Unique<VkCommandBuffer> cmdBuffer (allocateCommandBuffer(vk, vkDevice, *cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY)); 3843e5c31af7Sopenharmony_ci const Unique<VkEvent> globalEvent (createEvent(vk, vkDevice)); 3844e5c31af7Sopenharmony_ci 3845e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *globalEvent)); 3846e5c31af7Sopenharmony_ci 3847e5c31af7Sopenharmony_ci switch (type) 3848e5c31af7Sopenharmony_ci { 3849e5c31af7Sopenharmony_ci case STT_RECORDING_TO_INITIAL: 3850e5c31af7Sopenharmony_ci { 3851e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer, 0u); 3852e5c31af7Sopenharmony_ci vk.cmdSetEvent(*cmdBuffer, *globalEvent, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3853e5c31af7Sopenharmony_ci break; 3854e5c31af7Sopenharmony_ci // command buffer is still in recording state 3855e5c31af7Sopenharmony_ci } 3856e5c31af7Sopenharmony_ci case STT_EXECUTABLE_TO_INITIAL: 3857e5c31af7Sopenharmony_ci { 3858e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer, 0u); 3859e5c31af7Sopenharmony_ci vk.cmdSetEvent(*cmdBuffer, *globalEvent, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3860e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 3861e5c31af7Sopenharmony_ci break; 3862e5c31af7Sopenharmony_ci // command buffer is still in executable state 3863e5c31af7Sopenharmony_ci } 3864e5c31af7Sopenharmony_ci case STT_RECORDING_TO_INVALID: 3865e5c31af7Sopenharmony_ci { 3866e5c31af7Sopenharmony_ci VkSubpassDescription subpassDescription; 3867e5c31af7Sopenharmony_ci deMemset(&subpassDescription, 0, sizeof(VkSubpassDescription)); 3868e5c31af7Sopenharmony_ci subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 3869e5c31af7Sopenharmony_ci 3870e5c31af7Sopenharmony_ci VkRenderPassCreateInfo renderPassCreateInfo 3871e5c31af7Sopenharmony_ci { 3872e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, 3873e5c31af7Sopenharmony_ci DE_NULL, 0, 0, DE_NULL, 3874e5c31af7Sopenharmony_ci 1, &subpassDescription, 0, DE_NULL 3875e5c31af7Sopenharmony_ci }; 3876e5c31af7Sopenharmony_ci 3877e5c31af7Sopenharmony_ci // Error here - renderpass and framebuffer were created localy 3878e5c31af7Sopenharmony_ci Move <VkRenderPass> renderPass = createRenderPass(vk, vkDevice, &renderPassCreateInfo); 3879e5c31af7Sopenharmony_ci 3880e5c31af7Sopenharmony_ci VkFramebufferCreateInfo framebufferCreateInfo 3881e5c31af7Sopenharmony_ci { 3882e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, DE_NULL, 3883e5c31af7Sopenharmony_ci 0, *renderPass, 0, DE_NULL, 16, 16, 1 3884e5c31af7Sopenharmony_ci }; 3885e5c31af7Sopenharmony_ci Move <VkFramebuffer> framebuffer = createFramebuffer(vk, vkDevice, &framebufferCreateInfo); 3886e5c31af7Sopenharmony_ci 3887e5c31af7Sopenharmony_ci VkRenderPassBeginInfo renderPassBeginInfo = 3888e5c31af7Sopenharmony_ci { 3889e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, 3890e5c31af7Sopenharmony_ci DE_NULL, *renderPass, *framebuffer, { { 0, 0 }, { 16, 16 } }, 3891e5c31af7Sopenharmony_ci 0, DE_NULL 3892e5c31af7Sopenharmony_ci }; 3893e5c31af7Sopenharmony_ci 3894e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer, 0u); 3895e5c31af7Sopenharmony_ci vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); 3896e5c31af7Sopenharmony_ci vk.cmdEndRenderPass(*cmdBuffer); 3897e5c31af7Sopenharmony_ci 3898e5c31af7Sopenharmony_ci // not executing endCommandBuffer(vk, *cmdBuffer); 3899e5c31af7Sopenharmony_ci // command buffer is still in recording state 3900e5c31af7Sopenharmony_ci break; 3901e5c31af7Sopenharmony_ci // renderpass and framebuffer are destroyed; command buffer should be now in invalid state 3902e5c31af7Sopenharmony_ci } 3903e5c31af7Sopenharmony_ci case STT_EXECUTABLE_TO_INVALID: 3904e5c31af7Sopenharmony_ci { 3905e5c31af7Sopenharmony_ci // create event that will be used to check if command buffer has been executed 3906e5c31af7Sopenharmony_ci const Unique<VkEvent> localEvent(createEvent(vk, vkDevice)); 3907e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *localEvent)); 3908e5c31af7Sopenharmony_ci 3909e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer, 0u); 3910e5c31af7Sopenharmony_ci vk.cmdSetEvent(*cmdBuffer, *localEvent, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3911e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 3912e5c31af7Sopenharmony_ci // command buffer is in executable state 3913e5c31af7Sopenharmony_ci break; 3914e5c31af7Sopenharmony_ci // localEvent is destroyed; command buffer should be now in invalid state 3915e5c31af7Sopenharmony_ci } 3916e5c31af7Sopenharmony_ci } 3917e5c31af7Sopenharmony_ci 3918e5c31af7Sopenharmony_ci VK_CHECK(vk.resetEvent(vkDevice, *globalEvent)); 3919e5c31af7Sopenharmony_ci 3920e5c31af7Sopenharmony_ci VK_CHECK(vk.resetCommandBuffer(*cmdBuffer, 0u)); 3921e5c31af7Sopenharmony_ci // command buffer should now be back in initial state 3922e5c31af7Sopenharmony_ci 3923e5c31af7Sopenharmony_ci // verify commandBuffer 3924e5c31af7Sopenharmony_ci beginCommandBuffer(vk, *cmdBuffer, 0u); 3925e5c31af7Sopenharmony_ci vk.cmdSetEvent(*cmdBuffer, *globalEvent, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 3926e5c31af7Sopenharmony_ci endCommandBuffer(vk, *cmdBuffer); 3927e5c31af7Sopenharmony_ci submitCommandsAndWait(vk, vkDevice, queue, *cmdBuffer); 3928e5c31af7Sopenharmony_ci 3929e5c31af7Sopenharmony_ci // check if buffer has been executed 3930e5c31af7Sopenharmony_ci VkResult result = vk.getEventStatus(vkDevice, *globalEvent); 3931e5c31af7Sopenharmony_ci if (result != VK_EVENT_SET) 3932e5c31af7Sopenharmony_ci return tcu::TestStatus::fail("Submit failed"); 3933e5c31af7Sopenharmony_ci 3934e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Pass"); 3935e5c31af7Sopenharmony_ci} 3936e5c31af7Sopenharmony_ci 3937e5c31af7Sopenharmony_ci// Shaders 3938e5c31af7Sopenharmony_civoid genComputeSource (SourceCollections& programCollection) 3939e5c31af7Sopenharmony_ci{ 3940e5c31af7Sopenharmony_ci const char* const versionDecl = glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES); 3941e5c31af7Sopenharmony_ci std::ostringstream bufGood; 3942e5c31af7Sopenharmony_ci 3943e5c31af7Sopenharmony_ci bufGood << versionDecl << "\n" 3944e5c31af7Sopenharmony_ci << "" 3945e5c31af7Sopenharmony_ci << "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n" 3946e5c31af7Sopenharmony_ci << "layout(set = 0, binding = 1u, std140) uniform BufferName\n" 3947e5c31af7Sopenharmony_ci << "{\n" 3948e5c31af7Sopenharmony_ci << " highp vec4 colorA;\n" 3949e5c31af7Sopenharmony_ci << " highp vec4 colorB;\n" 3950e5c31af7Sopenharmony_ci << "} b_instance;\n" 3951e5c31af7Sopenharmony_ci << "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n" 3952e5c31af7Sopenharmony_ci << "{\n" 3953e5c31af7Sopenharmony_ci << " highp vec4 read_colors[4];\n" 3954e5c31af7Sopenharmony_ci << "} b_out;\n" 3955e5c31af7Sopenharmony_ci << "void main(void)\n" 3956e5c31af7Sopenharmony_ci << "{\n" 3957e5c31af7Sopenharmony_ci << " highp int quadrant_id = int(gl_WorkGroupID.x);\n" 3958e5c31af7Sopenharmony_ci << " highp vec4 result_color;\n" 3959e5c31af7Sopenharmony_ci << " if (quadrant_id == 1 || quadrant_id == 2)\n" 3960e5c31af7Sopenharmony_ci << " result_color = b_instance.colorA;\n" 3961e5c31af7Sopenharmony_ci << " else\n" 3962e5c31af7Sopenharmony_ci << " result_color = b_instance.colorB;\n" 3963e5c31af7Sopenharmony_ci << " b_out.read_colors[gl_WorkGroupID.x] = result_color;\n" 3964e5c31af7Sopenharmony_ci << "}\n"; 3965e5c31af7Sopenharmony_ci 3966e5c31af7Sopenharmony_ci programCollection.glslSources.add("compute_good") << glu::ComputeSource(bufGood.str()); 3967e5c31af7Sopenharmony_ci 3968e5c31af7Sopenharmony_ci std::ostringstream bufBad; 3969e5c31af7Sopenharmony_ci 3970e5c31af7Sopenharmony_ci bufBad << versionDecl << "\n" 3971e5c31af7Sopenharmony_ci << "" 3972e5c31af7Sopenharmony_ci << "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n" 3973e5c31af7Sopenharmony_ci << "layout(set = 0, binding = 1u, std140) uniform BufferName\n" 3974e5c31af7Sopenharmony_ci << "{\n" 3975e5c31af7Sopenharmony_ci << " highp vec4 colorA;\n" 3976e5c31af7Sopenharmony_ci << " highp vec4 colorB;\n" 3977e5c31af7Sopenharmony_ci << "} b_instance;\n" 3978e5c31af7Sopenharmony_ci << "layout(set = 0, binding = 0, std140) writeonly buffer OutBuf\n" 3979e5c31af7Sopenharmony_ci << "{\n" 3980e5c31af7Sopenharmony_ci << " highp vec4 read_colors[4];\n" 3981e5c31af7Sopenharmony_ci << "} b_out;\n" 3982e5c31af7Sopenharmony_ci << "void main(void)\n" 3983e5c31af7Sopenharmony_ci << "{\n" 3984e5c31af7Sopenharmony_ci << " highp int quadrant_id = int(gl_WorkGroupID.x);\n" 3985e5c31af7Sopenharmony_ci << " highp vec4 result_color;\n" 3986e5c31af7Sopenharmony_ci << " if (quadrant_id == 1 || quadrant_id == 2)\n" 3987e5c31af7Sopenharmony_ci << " result_color = b_instance.colorA;\n" 3988e5c31af7Sopenharmony_ci << " else\n" 3989e5c31af7Sopenharmony_ci << " result_color = b_instance.colorB;\n" 3990e5c31af7Sopenharmony_ci << " b_out.read_colors[gl_WorkGroupID.x] = vec4(0.0, 0.0, 0.0, 0.0);\n" 3991e5c31af7Sopenharmony_ci << "}\n"; 3992e5c31af7Sopenharmony_ci 3993e5c31af7Sopenharmony_ci programCollection.glslSources.add("compute_bad") << glu::ComputeSource(bufBad.str()); 3994e5c31af7Sopenharmony_ci} 3995e5c31af7Sopenharmony_ci 3996e5c31af7Sopenharmony_civoid genComputeIncrementSource (SourceCollections& programCollection) 3997e5c31af7Sopenharmony_ci{ 3998e5c31af7Sopenharmony_ci const char* const versionDecl = glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES); 3999e5c31af7Sopenharmony_ci std::ostringstream bufIncrement; 4000e5c31af7Sopenharmony_ci 4001e5c31af7Sopenharmony_ci bufIncrement << versionDecl << "\n" 4002e5c31af7Sopenharmony_ci << "" 4003e5c31af7Sopenharmony_ci << "layout(local_size_x = 1u, local_size_y = 1u, local_size_z = 1u) in;\n" 4004e5c31af7Sopenharmony_ci << "layout(set = 0, binding = 0, std140) buffer InOutBuf\n" 4005e5c31af7Sopenharmony_ci << "{\n" 4006e5c31af7Sopenharmony_ci << " coherent uint count;\n" 4007e5c31af7Sopenharmony_ci << "} b_in_out;\n" 4008e5c31af7Sopenharmony_ci << "void main(void)\n" 4009e5c31af7Sopenharmony_ci << "{\n" 4010e5c31af7Sopenharmony_ci << " atomicAdd(b_in_out.count, 1u);\n" 4011e5c31af7Sopenharmony_ci << "}\n"; 4012e5c31af7Sopenharmony_ci 4013e5c31af7Sopenharmony_ci programCollection.glslSources.add("compute_increment") << glu::ComputeSource(bufIncrement.str()); 4014e5c31af7Sopenharmony_ci} 4015e5c31af7Sopenharmony_ci 4016e5c31af7Sopenharmony_civoid genComputeIncrementSourceBadInheritance(SourceCollections& programCollection, BadInheritanceInfoCase testCase) 4017e5c31af7Sopenharmony_ci{ 4018e5c31af7Sopenharmony_ci DE_UNREF(testCase); 4019e5c31af7Sopenharmony_ci return genComputeIncrementSource(programCollection); 4020e5c31af7Sopenharmony_ci} 4021e5c31af7Sopenharmony_ci 4022e5c31af7Sopenharmony_civoid checkEventSupport (Context& context) 4023e5c31af7Sopenharmony_ci{ 4024e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4025e5c31af7Sopenharmony_ci if (context.isDeviceFunctionalitySupported("VK_KHR_portability_subset") && !context.getPortabilitySubsetFeatures().events) 4026e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "VK_KHR_portability_subset: Events are not supported by this implementation"); 4027e5c31af7Sopenharmony_ci#else 4028e5c31af7Sopenharmony_ci DE_UNREF(context); 4029e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4030e5c31af7Sopenharmony_ci} 4031e5c31af7Sopenharmony_ci 4032e5c31af7Sopenharmony_civoid checkCommandBufferSimultaneousUseSupport(Context& context) 4033e5c31af7Sopenharmony_ci{ 4034e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 4035e5c31af7Sopenharmony_ci if(context.getDeviceVulkanSC10Properties().commandBufferSimultaneousUse == VK_FALSE) 4036e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "commandBufferSimultaneousUse is not supported"); 4037e5c31af7Sopenharmony_ci#else 4038e5c31af7Sopenharmony_ci DE_UNREF(context); 4039e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4040e5c31af7Sopenharmony_ci} 4041e5c31af7Sopenharmony_ci 4042e5c31af7Sopenharmony_civoid checkSecondaryCommandBufferNullOrImagelessFramebufferSupport(Context& context) 4043e5c31af7Sopenharmony_ci{ 4044e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 4045e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().secondaryCommandBufferNullOrImagelessFramebuffer == VK_FALSE) 4046e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "secondaryCommandBufferNullFramebuffer is not supported"); 4047e5c31af7Sopenharmony_ci#else 4048e5c31af7Sopenharmony_ci DE_UNREF(context); 4049e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4050e5c31af7Sopenharmony_ci} 4051e5c31af7Sopenharmony_ci 4052e5c31af7Sopenharmony_civoid checkSecondaryCommandBufferNullOrImagelessFramebufferSupport1(Context& context, bool value) 4053e5c31af7Sopenharmony_ci{ 4054e5c31af7Sopenharmony_ci DE_UNREF(value); 4055e5c31af7Sopenharmony_ci#ifdef CTS_USES_VULKANSC 4056e5c31af7Sopenharmony_ci if (context.getDeviceVulkanSC10Properties().secondaryCommandBufferNullOrImagelessFramebuffer == VK_FALSE) 4057e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "secondaryCommandBufferNullFramebuffer is not supported"); 4058e5c31af7Sopenharmony_ci#else 4059e5c31af7Sopenharmony_ci DE_UNREF(context); 4060e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4061e5c31af7Sopenharmony_ci} 4062e5c31af7Sopenharmony_ci 4063e5c31af7Sopenharmony_civoid checkEventAndSecondaryCommandBufferNullFramebufferSupport(Context& context) 4064e5c31af7Sopenharmony_ci{ 4065e5c31af7Sopenharmony_ci checkEventSupport(context); 4066e5c31af7Sopenharmony_ci checkSecondaryCommandBufferNullOrImagelessFramebufferSupport(context); 4067e5c31af7Sopenharmony_ci} 4068e5c31af7Sopenharmony_ci 4069e5c31af7Sopenharmony_civoid checkSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport(Context& context) 4070e5c31af7Sopenharmony_ci{ 4071e5c31af7Sopenharmony_ci checkCommandBufferSimultaneousUseSupport(context); 4072e5c31af7Sopenharmony_ci checkSecondaryCommandBufferNullOrImagelessFramebufferSupport(context); 4073e5c31af7Sopenharmony_ci} 4074e5c31af7Sopenharmony_ci 4075e5c31af7Sopenharmony_civoid checkEventAndTimelineSemaphoreAndSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport(Context& context) 4076e5c31af7Sopenharmony_ci{ 4077e5c31af7Sopenharmony_ci checkEventSupport(context); 4078e5c31af7Sopenharmony_ci context.requireDeviceFunctionality("VK_KHR_timeline_semaphore"); 4079e5c31af7Sopenharmony_ci 4080e5c31af7Sopenharmony_ci checkSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport(context); 4081e5c31af7Sopenharmony_ci} 4082e5c31af7Sopenharmony_ci 4083e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4084e5c31af7Sopenharmony_civoid checkEventSupport (Context& context, const VkCommandBufferLevel) 4085e5c31af7Sopenharmony_ci{ 4086e5c31af7Sopenharmony_ci checkEventSupport(context); 4087e5c31af7Sopenharmony_ci} 4088e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4089e5c31af7Sopenharmony_ci 4090e5c31af7Sopenharmony_cistruct ManyDrawsParams 4091e5c31af7Sopenharmony_ci{ 4092e5c31af7Sopenharmony_ci VkCommandBufferLevel level; 4093e5c31af7Sopenharmony_ci VkExtent3D imageExtent; 4094e5c31af7Sopenharmony_ci deUint32 seed; 4095e5c31af7Sopenharmony_ci 4096e5c31af7Sopenharmony_ci ManyDrawsParams(VkCommandBufferLevel level_, const VkExtent3D& extent_, deUint32 seed_) 4097e5c31af7Sopenharmony_ci : level (level_) 4098e5c31af7Sopenharmony_ci , imageExtent (extent_) 4099e5c31af7Sopenharmony_ci , seed (seed_) 4100e5c31af7Sopenharmony_ci {} 4101e5c31af7Sopenharmony_ci}; 4102e5c31af7Sopenharmony_ci 4103e5c31af7Sopenharmony_cistruct ManyDrawsVertex 4104e5c31af7Sopenharmony_ci{ 4105e5c31af7Sopenharmony_ci using Color = tcu::Vector<deUint8, 4>; 4106e5c31af7Sopenharmony_ci 4107e5c31af7Sopenharmony_ci tcu::Vec2 coords; 4108e5c31af7Sopenharmony_ci Color color; 4109e5c31af7Sopenharmony_ci 4110e5c31af7Sopenharmony_ci ManyDrawsVertex (const tcu::Vec2& coords_, const Color& color_) : coords(coords_), color(color_) {} 4111e5c31af7Sopenharmony_ci}; 4112e5c31af7Sopenharmony_ci 4113e5c31af7Sopenharmony_ciVkFormat getSupportedDepthStencilFormat (const InstanceInterface& vki, VkPhysicalDevice physDev) 4114e5c31af7Sopenharmony_ci{ 4115e5c31af7Sopenharmony_ci const VkFormat formatList[] = { VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT }; 4116e5c31af7Sopenharmony_ci const VkFormatFeatureFlags requirements = (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT); 4117e5c31af7Sopenharmony_ci 4118e5c31af7Sopenharmony_ci for (int i = 0; i < DE_LENGTH_OF_ARRAY(formatList); ++i) 4119e5c31af7Sopenharmony_ci { 4120e5c31af7Sopenharmony_ci const auto properties = getPhysicalDeviceFormatProperties(vki, physDev, formatList[i]); 4121e5c31af7Sopenharmony_ci if ((properties.optimalTilingFeatures & requirements) == requirements) 4122e5c31af7Sopenharmony_ci return formatList[i]; 4123e5c31af7Sopenharmony_ci } 4124e5c31af7Sopenharmony_ci 4125e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "No suitable depth/stencil format support"); 4126e5c31af7Sopenharmony_ci return VK_FORMAT_UNDEFINED; 4127e5c31af7Sopenharmony_ci} 4128e5c31af7Sopenharmony_ci 4129e5c31af7Sopenharmony_ciclass ManyDrawsCase : public TestCase 4130e5c31af7Sopenharmony_ci{ 4131e5c31af7Sopenharmony_cipublic: 4132e5c31af7Sopenharmony_ci ManyDrawsCase (tcu::TestContext& testCtx, const std::string& name, const ManyDrawsParams& params); 4133e5c31af7Sopenharmony_ci virtual ~ManyDrawsCase (void) {} 4134e5c31af7Sopenharmony_ci 4135e5c31af7Sopenharmony_ci virtual void checkSupport (Context& context) const; 4136e5c31af7Sopenharmony_ci virtual void initPrograms (vk::SourceCollections& programCollection) const; 4137e5c31af7Sopenharmony_ci virtual TestInstance* createInstance (Context& context) const; 4138e5c31af7Sopenharmony_ci 4139e5c31af7Sopenharmony_ci static VkFormat getColorFormat (void) { return VK_FORMAT_R8G8B8A8_UINT; } 4140e5c31af7Sopenharmony_ci 4141e5c31af7Sopenharmony_ciprotected: 4142e5c31af7Sopenharmony_ci ManyDrawsParams m_params; 4143e5c31af7Sopenharmony_ci}; 4144e5c31af7Sopenharmony_ci 4145e5c31af7Sopenharmony_ciclass ManyDrawsInstance : public TestInstance 4146e5c31af7Sopenharmony_ci{ 4147e5c31af7Sopenharmony_cipublic: 4148e5c31af7Sopenharmony_ci ManyDrawsInstance (Context& context, const ManyDrawsParams& params); 4149e5c31af7Sopenharmony_ci virtual ~ManyDrawsInstance (void) {} 4150e5c31af7Sopenharmony_ci 4151e5c31af7Sopenharmony_ci virtual tcu::TestStatus iterate (void); 4152e5c31af7Sopenharmony_ci 4153e5c31af7Sopenharmony_ciprotected: 4154e5c31af7Sopenharmony_ci ManyDrawsParams m_params; 4155e5c31af7Sopenharmony_ci}; 4156e5c31af7Sopenharmony_ci 4157e5c31af7Sopenharmony_ciusing BufferPtr = de::MovePtr<BufferWithMemory>; 4158e5c31af7Sopenharmony_ciusing ImagePtr = de::MovePtr<ImageWithMemory>; 4159e5c31af7Sopenharmony_ci 4160e5c31af7Sopenharmony_cistruct ManyDrawsVertexBuffers 4161e5c31af7Sopenharmony_ci{ 4162e5c31af7Sopenharmony_ci BufferPtr stagingBuffer; 4163e5c31af7Sopenharmony_ci BufferPtr vertexBuffer; 4164e5c31af7Sopenharmony_ci}; 4165e5c31af7Sopenharmony_ci 4166e5c31af7Sopenharmony_cistruct ManyDrawsAllocatedData 4167e5c31af7Sopenharmony_ci{ 4168e5c31af7Sopenharmony_ci ManyDrawsVertexBuffers frontBuffers; 4169e5c31af7Sopenharmony_ci ManyDrawsVertexBuffers backBuffers; 4170e5c31af7Sopenharmony_ci ImagePtr colorAttachment; 4171e5c31af7Sopenharmony_ci ImagePtr dsAttachment; 4172e5c31af7Sopenharmony_ci BufferPtr colorCheckBuffer; 4173e5c31af7Sopenharmony_ci BufferPtr stencilCheckBuffer; 4174e5c31af7Sopenharmony_ci 4175e5c31af7Sopenharmony_ci static deUint32 calcNumPixels (const VkExtent3D& extent) 4176e5c31af7Sopenharmony_ci { 4177e5c31af7Sopenharmony_ci DE_ASSERT(extent.depth == 1u); 4178e5c31af7Sopenharmony_ci return (extent.width * extent.height); 4179e5c31af7Sopenharmony_ci } 4180e5c31af7Sopenharmony_ci static deUint32 calcNumVertices (const VkExtent3D& extent) 4181e5c31af7Sopenharmony_ci { 4182e5c31af7Sopenharmony_ci // One triangle (3 vertices) per output image pixel. 4183e5c31af7Sopenharmony_ci return (calcNumPixels(extent) * 3u); 4184e5c31af7Sopenharmony_ci } 4185e5c31af7Sopenharmony_ci 4186e5c31af7Sopenharmony_ci static VkDeviceSize calcVertexBufferSize (const VkExtent3D& extent) 4187e5c31af7Sopenharmony_ci { 4188e5c31af7Sopenharmony_ci return calcNumVertices(extent) * sizeof(ManyDrawsVertex); 4189e5c31af7Sopenharmony_ci } 4190e5c31af7Sopenharmony_ci 4191e5c31af7Sopenharmony_ci static void makeVertexBuffers (const DeviceInterface& vkd, VkDevice device, Allocator& alloc, VkDeviceSize size, ManyDrawsVertexBuffers& buffers) 4192e5c31af7Sopenharmony_ci { 4193e5c31af7Sopenharmony_ci const auto stagingBufferInfo = makeBufferCreateInfo(size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT); 4194e5c31af7Sopenharmony_ci const auto vertexBufferInfo = makeBufferCreateInfo(size, (VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)); 4195e5c31af7Sopenharmony_ci 4196e5c31af7Sopenharmony_ci buffers.stagingBuffer = BufferPtr(new BufferWithMemory(vkd, device, alloc, stagingBufferInfo, MemoryRequirement::HostVisible)); 4197e5c31af7Sopenharmony_ci buffers.vertexBuffer = BufferPtr(new BufferWithMemory(vkd, device, alloc, vertexBufferInfo, MemoryRequirement::Any)); 4198e5c31af7Sopenharmony_ci } 4199e5c31af7Sopenharmony_ci 4200e5c31af7Sopenharmony_ci ManyDrawsAllocatedData (const DeviceInterface &vkd, VkDevice device, Allocator &alloc, const VkExtent3D& imageExtent, VkFormat colorFormat, VkFormat dsFormat) 4201e5c31af7Sopenharmony_ci { 4202e5c31af7Sopenharmony_ci const auto numPixels = calcNumPixels(imageExtent); 4203e5c31af7Sopenharmony_ci const auto vertexBufferSize = calcVertexBufferSize(imageExtent); 4204e5c31af7Sopenharmony_ci 4205e5c31af7Sopenharmony_ci makeVertexBuffers(vkd, device, alloc, vertexBufferSize, frontBuffers); 4206e5c31af7Sopenharmony_ci makeVertexBuffers(vkd, device, alloc, vertexBufferSize, backBuffers); 4207e5c31af7Sopenharmony_ci 4208e5c31af7Sopenharmony_ci const auto colorUsage = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT); 4209e5c31af7Sopenharmony_ci const auto dsUsage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 4210e5c31af7Sopenharmony_ci 4211e5c31af7Sopenharmony_ci const VkImageCreateInfo colorAttachmentInfo = 4212e5c31af7Sopenharmony_ci { 4213e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 4214e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 4215e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 4216e5c31af7Sopenharmony_ci VK_IMAGE_TYPE_2D, // VkImageType imageType; 4217e5c31af7Sopenharmony_ci colorFormat, // VkFormat format; 4218e5c31af7Sopenharmony_ci imageExtent, // VkExtent3D extent; 4219e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 4220e5c31af7Sopenharmony_ci 1u, // deUint32 arrayLayers; 4221e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 4222e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 4223e5c31af7Sopenharmony_ci colorUsage, // VkImageUsageFlags usage; 4224e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 4225e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 4226e5c31af7Sopenharmony_ci nullptr, // const deUint32* pQueueFamilyIndices; 4227e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 4228e5c31af7Sopenharmony_ci }; 4229e5c31af7Sopenharmony_ci colorAttachment = ImagePtr(new ImageWithMemory(vkd, device, alloc, colorAttachmentInfo, MemoryRequirement::Any)); 4230e5c31af7Sopenharmony_ci 4231e5c31af7Sopenharmony_ci const VkImageCreateInfo dsAttachmentInfo = 4232e5c31af7Sopenharmony_ci { 4233e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType; 4234e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 4235e5c31af7Sopenharmony_ci 0u, // VkImageCreateFlags flags; 4236e5c31af7Sopenharmony_ci VK_IMAGE_TYPE_2D, // VkImageType imageType; 4237e5c31af7Sopenharmony_ci dsFormat, // VkFormat format; 4238e5c31af7Sopenharmony_ci imageExtent, // VkExtent3D extent; 4239e5c31af7Sopenharmony_ci 1u, // deUint32 mipLevels; 4240e5c31af7Sopenharmony_ci 1u, // deUint32 arrayLayers; 4241e5c31af7Sopenharmony_ci VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples; 4242e5c31af7Sopenharmony_ci VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling; 4243e5c31af7Sopenharmony_ci dsUsage, // VkImageUsageFlags usage; 4244e5c31af7Sopenharmony_ci VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode; 4245e5c31af7Sopenharmony_ci 0u, // deUint32 queueFamilyIndexCount; 4246e5c31af7Sopenharmony_ci nullptr, // const deUint32* pQueueFamilyIndices; 4247e5c31af7Sopenharmony_ci VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout; 4248e5c31af7Sopenharmony_ci }; 4249e5c31af7Sopenharmony_ci dsAttachment = ImagePtr(new ImageWithMemory(vkd, device, alloc, dsAttachmentInfo, MemoryRequirement::Any)); 4250e5c31af7Sopenharmony_ci 4251e5c31af7Sopenharmony_ci const auto colorCheckBufferSize = static_cast<VkDeviceSize>(numPixels * tcu::getPixelSize(mapVkFormat(colorFormat))); 4252e5c31af7Sopenharmony_ci const auto colorCheckBufferInfo = makeBufferCreateInfo(colorCheckBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 4253e5c31af7Sopenharmony_ci 4254e5c31af7Sopenharmony_ci colorCheckBuffer = BufferPtr(new BufferWithMemory(vkd, device, alloc, colorCheckBufferInfo, MemoryRequirement::HostVisible)); 4255e5c31af7Sopenharmony_ci 4256e5c31af7Sopenharmony_ci const auto stencilFormat = tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8); 4257e5c31af7Sopenharmony_ci const auto stencilCheckBufferSize = static_cast<VkDeviceSize>(numPixels * tcu::getPixelSize(stencilFormat)); 4258e5c31af7Sopenharmony_ci const auto stencilCheckBufferInfo = makeBufferCreateInfo(stencilCheckBufferSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT); 4259e5c31af7Sopenharmony_ci 4260e5c31af7Sopenharmony_ci stencilCheckBuffer = BufferPtr(new BufferWithMemory(vkd, device, alloc, stencilCheckBufferInfo, MemoryRequirement::HostVisible)); 4261e5c31af7Sopenharmony_ci } 4262e5c31af7Sopenharmony_ci}; 4263e5c31af7Sopenharmony_ci 4264e5c31af7Sopenharmony_ciManyDrawsCase::ManyDrawsCase (tcu::TestContext& testCtx, const std::string& name, const ManyDrawsParams& params) 4265e5c31af7Sopenharmony_ci : TestCase (testCtx, name) 4266e5c31af7Sopenharmony_ci , m_params (params) 4267e5c31af7Sopenharmony_ci{} 4268e5c31af7Sopenharmony_ci 4269e5c31af7Sopenharmony_civoid ManyDrawsCase::checkSupport (Context& context) const 4270e5c31af7Sopenharmony_ci{ 4271e5c31af7Sopenharmony_ci const auto& vki = context.getInstanceInterface(); 4272e5c31af7Sopenharmony_ci const auto physDev = context.getPhysicalDevice(); 4273e5c31af7Sopenharmony_ci const auto& vkd = context.getDeviceInterface(); 4274e5c31af7Sopenharmony_ci const auto device = context.getDevice(); 4275e5c31af7Sopenharmony_ci auto& alloc = context.getDefaultAllocator(); 4276e5c31af7Sopenharmony_ci const auto dsFormat = getSupportedDepthStencilFormat(vki, physDev); 4277e5c31af7Sopenharmony_ci 4278e5c31af7Sopenharmony_ci try 4279e5c31af7Sopenharmony_ci { 4280e5c31af7Sopenharmony_ci ManyDrawsAllocatedData allocatedData(vkd, device, alloc, m_params.imageExtent, getColorFormat(), dsFormat); 4281e5c31af7Sopenharmony_ci } 4282e5c31af7Sopenharmony_ci catch (const vk::Error& err) 4283e5c31af7Sopenharmony_ci { 4284e5c31af7Sopenharmony_ci const auto result = err.getError(); 4285e5c31af7Sopenharmony_ci if (result == VK_ERROR_OUT_OF_HOST_MEMORY || result == VK_ERROR_OUT_OF_DEVICE_MEMORY) 4286e5c31af7Sopenharmony_ci TCU_THROW(NotSupportedError, "Not enough memory to run this test"); 4287e5c31af7Sopenharmony_ci throw; 4288e5c31af7Sopenharmony_ci } 4289e5c31af7Sopenharmony_ci} 4290e5c31af7Sopenharmony_ci 4291e5c31af7Sopenharmony_civoid ManyDrawsCase::initPrograms (vk::SourceCollections& programCollection) const 4292e5c31af7Sopenharmony_ci{ 4293e5c31af7Sopenharmony_ci std::ostringstream vert; 4294e5c31af7Sopenharmony_ci vert 4295e5c31af7Sopenharmony_ci << "#version 450\n" 4296e5c31af7Sopenharmony_ci << "\n" 4297e5c31af7Sopenharmony_ci << "layout(location=0) in vec2 inCoords;\n" 4298e5c31af7Sopenharmony_ci << "layout(location=1) in uvec4 inColor;\n" 4299e5c31af7Sopenharmony_ci << "\n" 4300e5c31af7Sopenharmony_ci << "layout(location=0) out flat uvec4 outColor;\n" 4301e5c31af7Sopenharmony_ci << "\n" 4302e5c31af7Sopenharmony_ci << "void main()\n" 4303e5c31af7Sopenharmony_ci << "{\n" 4304e5c31af7Sopenharmony_ci << " gl_Position = vec4(inCoords, 0.0, 1.0);\n" 4305e5c31af7Sopenharmony_ci << " outColor = inColor;\n" 4306e5c31af7Sopenharmony_ci << "}\n" 4307e5c31af7Sopenharmony_ci ; 4308e5c31af7Sopenharmony_ci 4309e5c31af7Sopenharmony_ci std::ostringstream frag; 4310e5c31af7Sopenharmony_ci frag 4311e5c31af7Sopenharmony_ci << "#version 450\n" 4312e5c31af7Sopenharmony_ci << "\n" 4313e5c31af7Sopenharmony_ci << "layout(location=0) in flat uvec4 inColor;\n" 4314e5c31af7Sopenharmony_ci << "layout(location=0) out uvec4 outColor;\n" 4315e5c31af7Sopenharmony_ci << "\n" 4316e5c31af7Sopenharmony_ci << "void main()\n" 4317e5c31af7Sopenharmony_ci << "{\n" 4318e5c31af7Sopenharmony_ci << " outColor = inColor;\n" 4319e5c31af7Sopenharmony_ci << "}\n" 4320e5c31af7Sopenharmony_ci ; 4321e5c31af7Sopenharmony_ci 4322e5c31af7Sopenharmony_ci programCollection.glslSources.add("vert") << glu::VertexSource(vert.str()); 4323e5c31af7Sopenharmony_ci programCollection.glslSources.add("frag") << glu::FragmentSource(frag.str()); 4324e5c31af7Sopenharmony_ci} 4325e5c31af7Sopenharmony_ci 4326e5c31af7Sopenharmony_ciTestInstance* ManyDrawsCase::createInstance (Context& context) const 4327e5c31af7Sopenharmony_ci{ 4328e5c31af7Sopenharmony_ci return new ManyDrawsInstance(context, m_params); 4329e5c31af7Sopenharmony_ci} 4330e5c31af7Sopenharmony_ci 4331e5c31af7Sopenharmony_ciManyDrawsInstance::ManyDrawsInstance (Context& context, const ManyDrawsParams& params) 4332e5c31af7Sopenharmony_ci : TestInstance (context) 4333e5c31af7Sopenharmony_ci , m_params (params) 4334e5c31af7Sopenharmony_ci{} 4335e5c31af7Sopenharmony_ci 4336e5c31af7Sopenharmony_civoid copyAndFlush (const DeviceInterface& vkd, VkDevice device, BufferWithMemory& buffer, const std::vector<ManyDrawsVertex>& vertices) 4337e5c31af7Sopenharmony_ci{ 4338e5c31af7Sopenharmony_ci auto& alloc = buffer.getAllocation(); 4339e5c31af7Sopenharmony_ci void* hostPtr = alloc.getHostPtr(); 4340e5c31af7Sopenharmony_ci 4341e5c31af7Sopenharmony_ci deMemcpy(hostPtr, vertices.data(), de::dataSize(vertices)); 4342e5c31af7Sopenharmony_ci flushAlloc(vkd, device, alloc); 4343e5c31af7Sopenharmony_ci} 4344e5c31af7Sopenharmony_ci 4345e5c31af7Sopenharmony_citcu::TestStatus ManyDrawsInstance::iterate (void) 4346e5c31af7Sopenharmony_ci{ 4347e5c31af7Sopenharmony_ci const auto& vki = m_context.getInstanceInterface(); 4348e5c31af7Sopenharmony_ci const auto physDev = m_context.getPhysicalDevice(); 4349e5c31af7Sopenharmony_ci const auto& vkd = m_context.getDeviceInterface(); 4350e5c31af7Sopenharmony_ci const auto device = m_context.getDevice(); 4351e5c31af7Sopenharmony_ci auto& alloc = m_context.getDefaultAllocator(); 4352e5c31af7Sopenharmony_ci const auto qIndex = m_context.getUniversalQueueFamilyIndex(); 4353e5c31af7Sopenharmony_ci const auto queue = m_context.getUniversalQueue(); 4354e5c31af7Sopenharmony_ci 4355e5c31af7Sopenharmony_ci const auto colorFormat = ManyDrawsCase::getColorFormat(); 4356e5c31af7Sopenharmony_ci const auto dsFormat = getSupportedDepthStencilFormat(vki, physDev); 4357e5c31af7Sopenharmony_ci const auto vertexBufferSize = ManyDrawsAllocatedData::calcVertexBufferSize(m_params.imageExtent); 4358e5c31af7Sopenharmony_ci const auto vertexBufferOffset = static_cast<VkDeviceSize>(0); 4359e5c31af7Sopenharmony_ci const auto numPixels = ManyDrawsAllocatedData::calcNumPixels(m_params.imageExtent); 4360e5c31af7Sopenharmony_ci const auto numVertices = ManyDrawsAllocatedData::calcNumVertices(m_params.imageExtent); 4361e5c31af7Sopenharmony_ci const auto alphaValue = std::numeric_limits<deUint8>::max(); 4362e5c31af7Sopenharmony_ci const auto pixelWidth = 2.0f / static_cast<float>(m_params.imageExtent.width); // Normalized size. 4363e5c31af7Sopenharmony_ci const auto pixelWidthHalf = pixelWidth / 2.0f; // Normalized size. 4364e5c31af7Sopenharmony_ci const auto pixelHeight = 2.0f / static_cast<float>(m_params.imageExtent.height); // Normalized size. 4365e5c31af7Sopenharmony_ci const auto useSecondary = (m_params.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY); 4366e5c31af7Sopenharmony_ci 4367e5c31af7Sopenharmony_ci // Allocate all needed data up front. 4368e5c31af7Sopenharmony_ci ManyDrawsAllocatedData testData(vkd, device, alloc, m_params.imageExtent, colorFormat, dsFormat); 4369e5c31af7Sopenharmony_ci 4370e5c31af7Sopenharmony_ci // Generate random colors. 4371e5c31af7Sopenharmony_ci de::Random rnd(m_params.seed); 4372e5c31af7Sopenharmony_ci std::vector<ManyDrawsVertex::Color> colors; 4373e5c31af7Sopenharmony_ci 4374e5c31af7Sopenharmony_ci colors.reserve(numPixels); 4375e5c31af7Sopenharmony_ci for (deUint32 i = 0; i < numPixels; ++i) 4376e5c31af7Sopenharmony_ci { 4377e5c31af7Sopenharmony_ci#if 0 4378e5c31af7Sopenharmony_ci const deUint8 red = ((i ) & 0xFFu); 4379e5c31af7Sopenharmony_ci const deUint8 green = ((i >> 8) & 0xFFu); 4380e5c31af7Sopenharmony_ci const deUint8 blue = ((i >> 16) & 0xFFu); 4381e5c31af7Sopenharmony_ci colors.push_back(ManyDrawsVertex::Color(red, green, blue, alphaValue)); 4382e5c31af7Sopenharmony_ci#else 4383e5c31af7Sopenharmony_ci colors.push_back(ManyDrawsVertex::Color(rnd.getUint8(), rnd.getUint8(), rnd.getUint8(), alphaValue)); 4384e5c31af7Sopenharmony_ci#endif 4385e5c31af7Sopenharmony_ci } 4386e5c31af7Sopenharmony_ci 4387e5c31af7Sopenharmony_ci // Fill vertex data. One triangle per pixel, front and back. 4388e5c31af7Sopenharmony_ci std::vector<ManyDrawsVertex> frontVector; 4389e5c31af7Sopenharmony_ci std::vector<ManyDrawsVertex> backVector; 4390e5c31af7Sopenharmony_ci frontVector.reserve(numVertices); 4391e5c31af7Sopenharmony_ci backVector.reserve(numVertices); 4392e5c31af7Sopenharmony_ci 4393e5c31af7Sopenharmony_ci for (deUint32 y = 0; y < m_params.imageExtent.height; ++y) 4394e5c31af7Sopenharmony_ci for (deUint32 x = 0; x < m_params.imageExtent.width; ++x) 4395e5c31af7Sopenharmony_ci { 4396e5c31af7Sopenharmony_ci float x_left = static_cast<float>(x) * pixelWidth - 1.0f; 4397e5c31af7Sopenharmony_ci float x_mid = x_left + pixelWidthHalf; 4398e5c31af7Sopenharmony_ci float x_right = x_left + pixelWidth; 4399e5c31af7Sopenharmony_ci float y_top = static_cast<float>(y) * pixelHeight - 1.0f; 4400e5c31af7Sopenharmony_ci float y_bottom = y_top + pixelHeight; 4401e5c31af7Sopenharmony_ci 4402e5c31af7Sopenharmony_ci // Triangles in the "back" mesh will have different colors. 4403e5c31af7Sopenharmony_ci const auto colorIdx = y * m_params.imageExtent.width + x; 4404e5c31af7Sopenharmony_ci const auto& frontColor = colors[colorIdx]; 4405e5c31af7Sopenharmony_ci const auto& backColor = colors[colors.size() - 1u - colorIdx]; 4406e5c31af7Sopenharmony_ci 4407e5c31af7Sopenharmony_ci const tcu::Vec2 triangle[3u] = 4408e5c31af7Sopenharmony_ci { 4409e5c31af7Sopenharmony_ci tcu::Vec2(x_left, y_top), 4410e5c31af7Sopenharmony_ci tcu::Vec2(x_right, y_top), 4411e5c31af7Sopenharmony_ci tcu::Vec2(x_mid, y_bottom), 4412e5c31af7Sopenharmony_ci }; 4413e5c31af7Sopenharmony_ci 4414e5c31af7Sopenharmony_ci frontVector.emplace_back(triangle[0], frontColor); 4415e5c31af7Sopenharmony_ci frontVector.emplace_back(triangle[1], frontColor); 4416e5c31af7Sopenharmony_ci frontVector.emplace_back(triangle[2], frontColor); 4417e5c31af7Sopenharmony_ci 4418e5c31af7Sopenharmony_ci backVector.emplace_back(triangle[0], backColor); 4419e5c31af7Sopenharmony_ci backVector.emplace_back(triangle[1], backColor); 4420e5c31af7Sopenharmony_ci backVector.emplace_back(triangle[2], backColor); 4421e5c31af7Sopenharmony_ci } 4422e5c31af7Sopenharmony_ci 4423e5c31af7Sopenharmony_ci // Copy vertex data to staging buffers. 4424e5c31af7Sopenharmony_ci copyAndFlush(vkd, device, *testData.frontBuffers.stagingBuffer, frontVector); 4425e5c31af7Sopenharmony_ci copyAndFlush(vkd, device, *testData.backBuffers.stagingBuffer, backVector); 4426e5c31af7Sopenharmony_ci 4427e5c31af7Sopenharmony_ci // Color attachment view. 4428e5c31af7Sopenharmony_ci const auto colorResourceRange = makeImageSubresourceRange(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u); 4429e5c31af7Sopenharmony_ci const auto colorAttachmentView = makeImageView(vkd, device, testData.colorAttachment->get(), VK_IMAGE_VIEW_TYPE_2D, colorFormat, colorResourceRange); 4430e5c31af7Sopenharmony_ci 4431e5c31af7Sopenharmony_ci // Depth/stencil attachment view. 4432e5c31af7Sopenharmony_ci const auto dsResourceRange = makeImageSubresourceRange((VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT), 0u, 1u, 0u, 1u); 4433e5c31af7Sopenharmony_ci const auto dsAttachmentView = makeImageView(vkd, device, testData.dsAttachment->get(), VK_IMAGE_VIEW_TYPE_2D, dsFormat, dsResourceRange); 4434e5c31af7Sopenharmony_ci 4435e5c31af7Sopenharmony_ci const VkImageView attachmentArray[] = { colorAttachmentView.get(), dsAttachmentView.get() }; 4436e5c31af7Sopenharmony_ci const auto numAttachments = static_cast<deUint32>(DE_LENGTH_OF_ARRAY(attachmentArray)); 4437e5c31af7Sopenharmony_ci 4438e5c31af7Sopenharmony_ci const auto renderPass = makeRenderPass(vkd, device, colorFormat, dsFormat); 4439e5c31af7Sopenharmony_ci const auto framebuffer = makeFramebuffer(vkd, device, renderPass.get(), numAttachments, attachmentArray, m_params.imageExtent.width, m_params.imageExtent.height); 4440e5c31af7Sopenharmony_ci 4441e5c31af7Sopenharmony_ci const auto vertModule = createShaderModule(vkd, device, m_context.getBinaryCollection().get("vert"), 0u); 4442e5c31af7Sopenharmony_ci const auto fragModule = createShaderModule(vkd, device, m_context.getBinaryCollection().get("frag"), 0u); 4443e5c31af7Sopenharmony_ci 4444e5c31af7Sopenharmony_ci const std::vector<VkViewport> viewports (1u, makeViewport(m_params.imageExtent)); 4445e5c31af7Sopenharmony_ci const std::vector<VkRect2D> scissors (1u, makeRect2D(m_params.imageExtent)); 4446e5c31af7Sopenharmony_ci 4447e5c31af7Sopenharmony_ci const auto descriptorSetLayout = DescriptorSetLayoutBuilder().build(vkd, device); 4448e5c31af7Sopenharmony_ci const auto pipelineLayout = makePipelineLayout(vkd, device, descriptorSetLayout.get()); 4449e5c31af7Sopenharmony_ci 4450e5c31af7Sopenharmony_ci const VkVertexInputBindingDescription bindings[] = 4451e5c31af7Sopenharmony_ci { 4452e5c31af7Sopenharmony_ci makeVertexInputBindingDescription(0u, static_cast<deUint32>(sizeof(ManyDrawsVertex)), VK_VERTEX_INPUT_RATE_VERTEX), 4453e5c31af7Sopenharmony_ci }; 4454e5c31af7Sopenharmony_ci 4455e5c31af7Sopenharmony_ci const VkVertexInputAttributeDescription attributes[] = 4456e5c31af7Sopenharmony_ci { 4457e5c31af7Sopenharmony_ci makeVertexInputAttributeDescription(0u, 0u, VK_FORMAT_R32G32_SFLOAT, static_cast<deUint32>(offsetof(ManyDrawsVertex, coords))), 4458e5c31af7Sopenharmony_ci makeVertexInputAttributeDescription(1u, 0u, VK_FORMAT_R8G8B8A8_UINT, static_cast<deUint32>(offsetof(ManyDrawsVertex, color))), 4459e5c31af7Sopenharmony_ci }; 4460e5c31af7Sopenharmony_ci 4461e5c31af7Sopenharmony_ci const VkPipelineVertexInputStateCreateInfo inputState = 4462e5c31af7Sopenharmony_ci { 4463e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType; 4464e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 4465e5c31af7Sopenharmony_ci 0u, // VkPipelineVertexInputStateCreateFlags flags; 4466e5c31af7Sopenharmony_ci static_cast<deUint32>(DE_LENGTH_OF_ARRAY(bindings)), // deUint32 vertexBindingDescriptionCount; 4467e5c31af7Sopenharmony_ci bindings, // const VkVertexInputBindingDescription* pVertexBindingDescriptions; 4468e5c31af7Sopenharmony_ci static_cast<deUint32>(DE_LENGTH_OF_ARRAY(attributes)), // deUint32 vertexAttributeDescriptionCount; 4469e5c31af7Sopenharmony_ci attributes, // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions; 4470e5c31af7Sopenharmony_ci }; 4471e5c31af7Sopenharmony_ci 4472e5c31af7Sopenharmony_ci // Stencil state: this is key for checking and obtaining the right results. The stencil buffer will be cleared to 0. The first 4473e5c31af7Sopenharmony_ci // set of draws ("front" set of triangles) will pass the test and increment the stencil value to 1. The second set of draws 4474e5c31af7Sopenharmony_ci // ("back" set of triangles, not really in the back because all of them have depth 0.0) will not pass the stencil test then, but 4475e5c31af7Sopenharmony_ci // still increment the stencil value to 2. 4476e5c31af7Sopenharmony_ci // 4477e5c31af7Sopenharmony_ci // At the end of the test, if every draw command was executed correctly in the expected order, the color buffer will have the 4478e5c31af7Sopenharmony_ci // colors of the front set, and the stencil buffer will be full of 2s. 4479e5c31af7Sopenharmony_ci const auto stencilOpState = makeStencilOpState(VK_STENCIL_OP_INCREMENT_AND_CLAMP, VK_STENCIL_OP_INCREMENT_AND_CLAMP, VK_STENCIL_OP_KEEP, 4480e5c31af7Sopenharmony_ci VK_COMPARE_OP_EQUAL, 0xFFu, 0xFFu, 0u); 4481e5c31af7Sopenharmony_ci 4482e5c31af7Sopenharmony_ci const VkPipelineDepthStencilStateCreateInfo dsState = 4483e5c31af7Sopenharmony_ci { 4484e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType 4485e5c31af7Sopenharmony_ci nullptr, // const void* pNext 4486e5c31af7Sopenharmony_ci 0u, // VkPipelineDepthStencilStateCreateFlags flags 4487e5c31af7Sopenharmony_ci VK_FALSE, // VkBool32 depthTestEnable 4488e5c31af7Sopenharmony_ci VK_FALSE, // VkBool32 depthWriteEnable 4489e5c31af7Sopenharmony_ci VK_COMPARE_OP_NEVER, // VkCompareOp depthCompareOp 4490e5c31af7Sopenharmony_ci VK_FALSE, // VkBool32 depthBoundsTestEnable 4491e5c31af7Sopenharmony_ci VK_TRUE, // VkBool32 stencilTestEnable 4492e5c31af7Sopenharmony_ci stencilOpState, // VkStencilOpState front 4493e5c31af7Sopenharmony_ci stencilOpState, // VkStencilOpState back 4494e5c31af7Sopenharmony_ci 0.0f, // float minDepthBounds 4495e5c31af7Sopenharmony_ci 1.0f, // float maxDepthBounds 4496e5c31af7Sopenharmony_ci }; 4497e5c31af7Sopenharmony_ci 4498e5c31af7Sopenharmony_ci const auto pipeline = makeGraphicsPipeline(vkd, device, pipelineLayout.get(), 4499e5c31af7Sopenharmony_ci vertModule.get(), DE_NULL, DE_NULL, DE_NULL, fragModule.get(), 4500e5c31af7Sopenharmony_ci renderPass.get(), viewports, scissors, VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, 0u, 0u, 4501e5c31af7Sopenharmony_ci &inputState, nullptr, nullptr, &dsState); 4502e5c31af7Sopenharmony_ci 4503e5c31af7Sopenharmony_ci // Command pool and buffers. 4504e5c31af7Sopenharmony_ci using CmdBufferPtr = Move<VkCommandBuffer>; 4505e5c31af7Sopenharmony_ci const auto cmdPool = makeCommandPool(vkd, device, qIndex); 4506e5c31af7Sopenharmony_ci const auto secCmdPool = makeCommandPool(vkd, device, qIndex); 4507e5c31af7Sopenharmony_ci 4508e5c31af7Sopenharmony_ci CmdBufferPtr primaryCmdBufferPtr; 4509e5c31af7Sopenharmony_ci CmdBufferPtr secondaryCmdBufferPtr; 4510e5c31af7Sopenharmony_ci VkCommandBuffer primaryCmdBuffer; 4511e5c31af7Sopenharmony_ci VkCommandBuffer secondaryCmdBuffer; 4512e5c31af7Sopenharmony_ci VkCommandBuffer drawsCmdBuffer; 4513e5c31af7Sopenharmony_ci 4514e5c31af7Sopenharmony_ci primaryCmdBufferPtr = allocateCommandBuffer(vkd, device, cmdPool.get(), VK_COMMAND_BUFFER_LEVEL_PRIMARY); 4515e5c31af7Sopenharmony_ci primaryCmdBuffer = primaryCmdBufferPtr.get(); 4516e5c31af7Sopenharmony_ci drawsCmdBuffer = primaryCmdBuffer; 4517e5c31af7Sopenharmony_ci beginCommandBuffer(vkd, primaryCmdBuffer); 4518e5c31af7Sopenharmony_ci 4519e5c31af7Sopenharmony_ci // Clear values. 4520e5c31af7Sopenharmony_ci std::vector<VkClearValue> clearValues(2u); 4521e5c31af7Sopenharmony_ci clearValues[0] = makeClearValueColorU32(0u, 0u, 0u, 0u); 4522e5c31af7Sopenharmony_ci clearValues[1] = makeClearValueDepthStencil(1.0f, 0u); 4523e5c31af7Sopenharmony_ci 4524e5c31af7Sopenharmony_ci // Copy staging buffers to vertex buffers. 4525e5c31af7Sopenharmony_ci const auto copyRegion = makeBufferCopy(0ull, 0ull, vertexBufferSize); 4526e5c31af7Sopenharmony_ci vkd.cmdCopyBuffer(primaryCmdBuffer, testData.frontBuffers.stagingBuffer->get(), testData.frontBuffers.vertexBuffer->get(), 1u, ©Region); 4527e5c31af7Sopenharmony_ci vkd.cmdCopyBuffer(primaryCmdBuffer, testData.backBuffers.stagingBuffer->get(), testData.backBuffers.vertexBuffer->get(), 1u, ©Region); 4528e5c31af7Sopenharmony_ci 4529e5c31af7Sopenharmony_ci // Use barrier for vertex reads. 4530e5c31af7Sopenharmony_ci const auto vertexBarier = makeMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT); 4531e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(primaryCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, 0u, 1u, &vertexBarier, 0u, nullptr, 0u, nullptr); 4532e5c31af7Sopenharmony_ci 4533e5c31af7Sopenharmony_ci // Change depth/stencil attachment layout. 4534e5c31af7Sopenharmony_ci const auto dsBarrier = makeImageMemoryBarrier(0, (VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, testData.dsAttachment->get(), dsResourceRange); 4535e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(primaryCmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT), 0u, 0u, nullptr, 0u, nullptr, 1u, &dsBarrier); 4536e5c31af7Sopenharmony_ci 4537e5c31af7Sopenharmony_ci beginRenderPass(vkd, primaryCmdBuffer, renderPass.get(), framebuffer.get(), 4538e5c31af7Sopenharmony_ci scissors[0], static_cast<deUint32>(clearValues.size()), clearValues.data(), 4539e5c31af7Sopenharmony_ci (useSecondary ? VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS : VK_SUBPASS_CONTENTS_INLINE)); 4540e5c31af7Sopenharmony_ci 4541e5c31af7Sopenharmony_ci if (useSecondary) 4542e5c31af7Sopenharmony_ci { 4543e5c31af7Sopenharmony_ci secondaryCmdBufferPtr = allocateCommandBuffer(vkd, device, secCmdPool.get(), VK_COMMAND_BUFFER_LEVEL_SECONDARY); 4544e5c31af7Sopenharmony_ci secondaryCmdBuffer = secondaryCmdBufferPtr.get(); 4545e5c31af7Sopenharmony_ci drawsCmdBuffer = secondaryCmdBuffer; 4546e5c31af7Sopenharmony_ci 4547e5c31af7Sopenharmony_ci const VkCommandBufferInheritanceInfo inheritanceInfo = 4548e5c31af7Sopenharmony_ci { 4549e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, // VkStructureType sType; 4550e5c31af7Sopenharmony_ci nullptr, // const void* pNext; 4551e5c31af7Sopenharmony_ci renderPass.get(), // VkRenderPass renderPass; 4552e5c31af7Sopenharmony_ci 0u, // deUint32 subpass; 4553e5c31af7Sopenharmony_ci framebuffer.get(), // VkFramebuffer framebuffer; 4554e5c31af7Sopenharmony_ci 0u, // VkBool32 occlusionQueryEnable; 4555e5c31af7Sopenharmony_ci 0u, // VkQueryControlFlags queryFlags; 4556e5c31af7Sopenharmony_ci 0u, // VkQueryPipelineStatisticFlags pipelineStatistics; 4557e5c31af7Sopenharmony_ci }; 4558e5c31af7Sopenharmony_ci 4559e5c31af7Sopenharmony_ci const VkCommandBufferUsageFlags usageFlags = (VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT); 4560e5c31af7Sopenharmony_ci const VkCommandBufferBeginInfo beginInfo = 4561e5c31af7Sopenharmony_ci { 4562e5c31af7Sopenharmony_ci VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 4563e5c31af7Sopenharmony_ci nullptr, 4564e5c31af7Sopenharmony_ci usageFlags, // VkCommandBufferUsageFlags flags; 4565e5c31af7Sopenharmony_ci &inheritanceInfo, // const VkCommandBufferInheritanceInfo* pInheritanceInfo; 4566e5c31af7Sopenharmony_ci }; 4567e5c31af7Sopenharmony_ci 4568e5c31af7Sopenharmony_ci VK_CHECK(vkd.beginCommandBuffer(secondaryCmdBuffer, &beginInfo)); 4569e5c31af7Sopenharmony_ci } 4570e5c31af7Sopenharmony_ci 4571e5c31af7Sopenharmony_ci // Bind pipeline. 4572e5c31af7Sopenharmony_ci vkd.cmdBindPipeline(drawsCmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.get()); 4573e5c31af7Sopenharmony_ci 4574e5c31af7Sopenharmony_ci // Draw triangles in front. 4575e5c31af7Sopenharmony_ci vkd.cmdBindVertexBuffers(drawsCmdBuffer, 0u, 1u, &testData.frontBuffers.vertexBuffer->get(), &vertexBufferOffset); 4576e5c31af7Sopenharmony_ci for (deUint32 i = 0; i < numPixels; ++i) 4577e5c31af7Sopenharmony_ci vkd.cmdDraw(drawsCmdBuffer, 3u, 1u, i*3u, 0u); 4578e5c31af7Sopenharmony_ci 4579e5c31af7Sopenharmony_ci // Draw triangles in the "back". This should have no effect due to the stencil test. 4580e5c31af7Sopenharmony_ci vkd.cmdBindVertexBuffers(drawsCmdBuffer, 0u, 1u, &testData.backBuffers.vertexBuffer->get(), &vertexBufferOffset); 4581e5c31af7Sopenharmony_ci for (deUint32 i = 0; i < numPixels; ++i) 4582e5c31af7Sopenharmony_ci vkd.cmdDraw(drawsCmdBuffer, 3u, 1u, i*3u, 0u); 4583e5c31af7Sopenharmony_ci 4584e5c31af7Sopenharmony_ci if (useSecondary) 4585e5c31af7Sopenharmony_ci { 4586e5c31af7Sopenharmony_ci endCommandBuffer(vkd, secondaryCmdBuffer); 4587e5c31af7Sopenharmony_ci vkd.cmdExecuteCommands(primaryCmdBuffer, 1u, &secondaryCmdBuffer); 4588e5c31af7Sopenharmony_ci } 4589e5c31af7Sopenharmony_ci 4590e5c31af7Sopenharmony_ci endRenderPass(vkd, primaryCmdBuffer); 4591e5c31af7Sopenharmony_ci 4592e5c31af7Sopenharmony_ci // Copy color and depth/stencil attachments to verification buffers. 4593e5c31af7Sopenharmony_ci const auto colorAttachmentBarrier = makeImageMemoryBarrier(VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, testData.colorAttachment->get(), colorResourceRange); 4594e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(primaryCmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, nullptr, 0u, nullptr, 1u, &colorAttachmentBarrier); 4595e5c31af7Sopenharmony_ci 4596e5c31af7Sopenharmony_ci const auto colorResourceLayers = makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u); 4597e5c31af7Sopenharmony_ci const auto colorCopyRegion = makeBufferImageCopy(m_params.imageExtent, colorResourceLayers); 4598e5c31af7Sopenharmony_ci vkd.cmdCopyImageToBuffer(primaryCmdBuffer, testData.colorAttachment->get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, testData.colorCheckBuffer->get(), 1u, &colorCopyRegion); 4599e5c31af7Sopenharmony_ci 4600e5c31af7Sopenharmony_ci const auto stencilAttachmentBarrier = makeImageMemoryBarrier(VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, testData.dsAttachment->get(), dsResourceRange); 4601e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(primaryCmdBuffer, (VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT), VK_PIPELINE_STAGE_TRANSFER_BIT, 0u, 0u, nullptr, 0u, nullptr, 1u, &stencilAttachmentBarrier); 4602e5c31af7Sopenharmony_ci 4603e5c31af7Sopenharmony_ci const auto stencilResourceLayers = makeImageSubresourceLayers(VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u); 4604e5c31af7Sopenharmony_ci const auto stencilCopyRegion = makeBufferImageCopy(m_params.imageExtent, stencilResourceLayers); 4605e5c31af7Sopenharmony_ci vkd.cmdCopyImageToBuffer(primaryCmdBuffer, testData.dsAttachment->get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, testData.stencilCheckBuffer->get(), 1u, &stencilCopyRegion); 4606e5c31af7Sopenharmony_ci 4607e5c31af7Sopenharmony_ci const auto verificationBuffersBarrier = makeMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_HOST_READ_BIT); 4608e5c31af7Sopenharmony_ci vkd.cmdPipelineBarrier(primaryCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0u, 1u, &verificationBuffersBarrier, 0u, nullptr, 0u, nullptr); 4609e5c31af7Sopenharmony_ci 4610e5c31af7Sopenharmony_ci endCommandBuffer(vkd, primaryCmdBuffer); 4611e5c31af7Sopenharmony_ci submitCommandsAndWait(vkd, device, queue, primaryCmdBuffer); 4612e5c31af7Sopenharmony_ci 4613e5c31af7Sopenharmony_ci // Check buffer contents. 4614e5c31af7Sopenharmony_ci auto& colorCheckBufferAlloc = testData.colorCheckBuffer->getAllocation(); 4615e5c31af7Sopenharmony_ci void* colorCheckBufferData = colorCheckBufferAlloc.getHostPtr(); 4616e5c31af7Sopenharmony_ci invalidateAlloc(vkd, device, colorCheckBufferAlloc); 4617e5c31af7Sopenharmony_ci 4618e5c31af7Sopenharmony_ci auto& stencilCheckBufferAlloc = testData.stencilCheckBuffer->getAllocation(); 4619e5c31af7Sopenharmony_ci void* stencilCheckBufferData = stencilCheckBufferAlloc.getHostPtr(); 4620e5c31af7Sopenharmony_ci invalidateAlloc(vkd, device, stencilCheckBufferAlloc); 4621e5c31af7Sopenharmony_ci 4622e5c31af7Sopenharmony_ci const auto iWidth = static_cast<int>(m_params.imageExtent.width); 4623e5c31af7Sopenharmony_ci const auto iHeight = static_cast<int>(m_params.imageExtent.height); 4624e5c31af7Sopenharmony_ci const auto colorTcuFormat = mapVkFormat(colorFormat); 4625e5c31af7Sopenharmony_ci const auto stencilTcuFormat = tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8); 4626e5c31af7Sopenharmony_ci 4627e5c31af7Sopenharmony_ci tcu::TextureLevel referenceLevel (colorTcuFormat, iWidth, iHeight); 4628e5c31af7Sopenharmony_ci tcu::PixelBufferAccess referenceAccess = referenceLevel.getAccess(); 4629e5c31af7Sopenharmony_ci tcu::TextureLevel colorErrorLevel (mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), iWidth, iHeight); 4630e5c31af7Sopenharmony_ci tcu::PixelBufferAccess colorErrorAccess = colorErrorLevel.getAccess(); 4631e5c31af7Sopenharmony_ci tcu::TextureLevel stencilErrorLevel (mapVkFormat(VK_FORMAT_R8G8B8A8_UNORM), iWidth, iHeight); 4632e5c31af7Sopenharmony_ci tcu::PixelBufferAccess stencilErrorAccess = stencilErrorLevel.getAccess(); 4633e5c31af7Sopenharmony_ci tcu::ConstPixelBufferAccess colorAccess (colorTcuFormat, iWidth, iHeight, 1, colorCheckBufferData); 4634e5c31af7Sopenharmony_ci tcu::ConstPixelBufferAccess stencilAccess (stencilTcuFormat, iWidth, iHeight, 1, stencilCheckBufferData); 4635e5c31af7Sopenharmony_ci const tcu::Vec4 green (0.0f, 1.0f, 0.0f, 1.0f); 4636e5c31af7Sopenharmony_ci const tcu::Vec4 red (1.0f, 0.0f, 0.0f, 1.0f); 4637e5c31af7Sopenharmony_ci const int expectedStencil = 2; 4638e5c31af7Sopenharmony_ci bool colorFail = false; 4639e5c31af7Sopenharmony_ci bool stencilFail = false; 4640e5c31af7Sopenharmony_ci 4641e5c31af7Sopenharmony_ci for (int y = 0; y < iHeight; ++y) 4642e5c31af7Sopenharmony_ci for (int x = 0; x < iWidth; ++x) 4643e5c31af7Sopenharmony_ci { 4644e5c31af7Sopenharmony_ci const tcu::UVec4 colorValue = colorAccess.getPixelUint(x, y); 4645e5c31af7Sopenharmony_ci const auto expectedPixel = colors[y * iWidth + x]; 4646e5c31af7Sopenharmony_ci const tcu::UVec4 expectedValue (expectedPixel.x(), expectedPixel.y(), expectedPixel.z(), expectedPixel.w()); 4647e5c31af7Sopenharmony_ci const bool colorMismatch = (colorValue != expectedValue); 4648e5c31af7Sopenharmony_ci 4649e5c31af7Sopenharmony_ci const auto stencilValue = stencilAccess.getPixStencil(x, y); 4650e5c31af7Sopenharmony_ci const bool stencilMismatch = (stencilValue != expectedStencil); 4651e5c31af7Sopenharmony_ci 4652e5c31af7Sopenharmony_ci referenceAccess.setPixel(expectedValue, x, y); 4653e5c31af7Sopenharmony_ci colorErrorAccess.setPixel((colorMismatch ? red : green), x, y); 4654e5c31af7Sopenharmony_ci stencilErrorAccess.setPixel((stencilMismatch ? red : green), x, y); 4655e5c31af7Sopenharmony_ci 4656e5c31af7Sopenharmony_ci if (stencilMismatch) 4657e5c31af7Sopenharmony_ci stencilFail = true; 4658e5c31af7Sopenharmony_ci 4659e5c31af7Sopenharmony_ci if (colorMismatch) 4660e5c31af7Sopenharmony_ci colorFail = true; 4661e5c31af7Sopenharmony_ci } 4662e5c31af7Sopenharmony_ci 4663e5c31af7Sopenharmony_ci if (colorFail || stencilFail) 4664e5c31af7Sopenharmony_ci { 4665e5c31af7Sopenharmony_ci auto& log = m_context.getTestContext().getLog(); 4666e5c31af7Sopenharmony_ci log 4667e5c31af7Sopenharmony_ci << tcu::TestLog::ImageSet("Result", "") 4668e5c31af7Sopenharmony_ci << tcu::TestLog::Image("ColorOutput", "", colorAccess) 4669e5c31af7Sopenharmony_ci << tcu::TestLog::Image("ColorReference", "", referenceAccess) 4670e5c31af7Sopenharmony_ci << tcu::TestLog::Image("ColorError", "", colorErrorAccess) 4671e5c31af7Sopenharmony_ci << tcu::TestLog::Image("StencilError", "", stencilErrorAccess) 4672e5c31af7Sopenharmony_ci << tcu::TestLog::EndImageSet 4673e5c31af7Sopenharmony_ci ; 4674e5c31af7Sopenharmony_ci TCU_FAIL("Mismatched output and reference color or stencil; please check test log --"); 4675e5c31af7Sopenharmony_ci } 4676e5c31af7Sopenharmony_ci 4677e5c31af7Sopenharmony_ci return tcu::TestStatus::pass("Pass"); 4678e5c31af7Sopenharmony_ci} 4679e5c31af7Sopenharmony_ci 4680e5c31af7Sopenharmony_ci} // anonymous 4681e5c31af7Sopenharmony_ci 4682e5c31af7Sopenharmony_citcu::TestCaseGroup* createCommandBuffersTests (tcu::TestContext& testCtx) 4683e5c31af7Sopenharmony_ci{ 4684e5c31af7Sopenharmony_ci de::MovePtr<tcu::TestCaseGroup> commandBuffersTests (new tcu::TestCaseGroup(testCtx, "command_buffers")); 4685e5c31af7Sopenharmony_ci 4686e5c31af7Sopenharmony_ci /* 19.1. Command Pools (5.1 in VK 1.0 Spec) */ 4687e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_create_null_params", createPoolNullParamsTest); 4688e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4689e5c31af7Sopenharmony_ci // VkAllocationCallbacks must be NULL in Vulkan SC 4690e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_create_non_null_allocator", createPoolNonNullAllocatorTest); 4691e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4692e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_create_transient_bit", createPoolTransientBitTest); 4693e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_create_reset_bit", createPoolResetBitTest); 4694e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4695e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_reset_release_res", resetPoolReleaseResourcesBitTest); 4696e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4697e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_reset_no_flags_res", resetPoolNoFlagsTest); 4698e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4699e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "pool_reset_reuse", checkEventSupport, resetPoolReuseTest); 4700e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4701e5c31af7Sopenharmony_ci /* 19.2. Command Buffer Lifetime (5.2 in VK 1.0 Spec) */ 4702e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "allocate_single_primary", allocatePrimaryBufferTest); 4703e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "allocate_many_primary", allocateManyPrimaryBuffersTest); 4704e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "allocate_single_secondary", allocateSecondaryBufferTest); 4705e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "allocate_many_secondary", allocateManySecondaryBuffersTest); 4706e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "execute_small_primary", checkEventSupport, executePrimaryBufferTest); 4707e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "execute_large_primary", checkEventSupport, executeLargePrimaryBufferTest); 4708e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "reset_implicit", checkEventSupport, resetBufferImplicitlyTest); 4709e5c31af7Sopenharmony_ci#ifndef CTS_USES_VULKANSC 4710e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "trim_command_pool", checkEventSupport, trimCommandPoolTest, VK_COMMAND_BUFFER_LEVEL_PRIMARY); 4711e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "trim_command_pool_secondary", checkEventSupport, trimCommandPoolTest, VK_COMMAND_BUFFER_LEVEL_SECONDARY); 4712e5c31af7Sopenharmony_ci#endif // CTS_USES_VULKANSC 4713e5c31af7Sopenharmony_ci /* 19.3. Command Buffer Recording (5.3 in VK 1.0 Spec) */ 4714e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_single_primary", checkEventSupport, recordSinglePrimaryBufferTest); 4715e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_many_primary", checkEventSupport, recordLargePrimaryBufferTest); 4716e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_single_secondary", checkEventAndSecondaryCommandBufferNullFramebufferSupport, recordSingleSecondaryBufferTest); 4717e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_many_secondary", checkEventAndSecondaryCommandBufferNullFramebufferSupport, recordLargeSecondaryBufferTest); 4718e5c31af7Sopenharmony_ci { 4719e5c31af7Sopenharmony_ci deUint32 seed = 1614182419u; 4720e5c31af7Sopenharmony_ci const auto smallExtent = makeExtent3D(128u, 128u, 1u); 4721e5c31af7Sopenharmony_ci const auto largeExtent = makeExtent3D(512u, 256u, 1u); 4722e5c31af7Sopenharmony_ci 4723e5c31af7Sopenharmony_ci commandBuffersTests->addChild(new ManyDrawsCase(testCtx, "record_many_draws_primary_1", ManyDrawsParams(VK_COMMAND_BUFFER_LEVEL_PRIMARY, smallExtent, seed++))); 4724e5c31af7Sopenharmony_ci commandBuffersTests->addChild(new ManyDrawsCase(testCtx, "record_many_draws_primary_2", ManyDrawsParams(VK_COMMAND_BUFFER_LEVEL_PRIMARY, largeExtent, seed++))); 4725e5c31af7Sopenharmony_ci commandBuffersTests->addChild(new ManyDrawsCase(testCtx, "record_many_draws_secondary_1", ManyDrawsParams(VK_COMMAND_BUFFER_LEVEL_SECONDARY, smallExtent, seed++))); 4726e5c31af7Sopenharmony_ci commandBuffersTests->addChild(new ManyDrawsCase(testCtx, "record_many_draws_secondary_2", ManyDrawsParams(VK_COMMAND_BUFFER_LEVEL_SECONDARY, largeExtent, seed++))); 4727e5c31af7Sopenharmony_ci } 4728e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_twice_primary", checkEventSupport, submitPrimaryBufferTwiceTest); 4729e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_twice_secondary", checkEventAndSecondaryCommandBufferNullFramebufferSupport, submitSecondaryBufferTwiceTest); 4730e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_one_time_submit_primary", checkEventSupport, oneTimeSubmitFlagPrimaryBufferTest); 4731e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_one_time_submit_secondary", checkEventAndSecondaryCommandBufferNullFramebufferSupport, oneTimeSubmitFlagSecondaryBufferTest); 4732e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "render_pass_continue", renderPassContinueTest, true); 4733e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "render_pass_continue_no_fb", checkSecondaryCommandBufferNullOrImagelessFramebufferSupport1, renderPassContinueTest, false); 4734e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "record_simul_use_secondary_one_primary", checkSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport, genComputeIncrementSource, simultaneousUseSecondaryBufferOnePrimaryBufferTest); 4735e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "record_simul_use_secondary_two_primary", checkSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport, genComputeIncrementSource, simultaneousUseSecondaryBufferTwoPrimaryBuffersTest); 4736e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_query_precise_w_flag", checkSecondaryCommandBufferNullOrImagelessFramebufferSupport, recordBufferQueryPreciseWithFlagTest); 4737e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_query_imprecise_w_flag", checkSecondaryCommandBufferNullOrImagelessFramebufferSupport, recordBufferQueryImpreciseWithFlagTest); 4738e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "record_query_imprecise_wo_flag", checkSecondaryCommandBufferNullOrImagelessFramebufferSupport, recordBufferQueryImpreciseWithoutFlagTest); 4739e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "bad_inheritance_info_random", genComputeIncrementSourceBadInheritance, badInheritanceInfoTest, BadInheritanceInfoCase::RANDOM_PTR); 4740e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "bad_inheritance_info_random_cont", genComputeIncrementSourceBadInheritance, badInheritanceInfoTest, BadInheritanceInfoCase::RANDOM_PTR_CONTINUATION); 4741e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "bad_inheritance_info_random_data", genComputeIncrementSourceBadInheritance, badInheritanceInfoTest, BadInheritanceInfoCase::RANDOM_DATA_PTR); 4742e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "bad_inheritance_info_invalid_type", genComputeIncrementSourceBadInheritance, badInheritanceInfoTest, BadInheritanceInfoCase::INVALID_STRUCTURE_TYPE); 4743e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "bad_inheritance_info_valid_nonsense_type", genComputeIncrementSourceBadInheritance, badInheritanceInfoTest, BadInheritanceInfoCase::VALID_NONSENSE_TYPE); 4744e5c31af7Sopenharmony_ci /* 19.4. Command Buffer Submission (5.4 in VK 1.0 Spec) */ 4745e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_count_non_zero", checkEventSupport, submitBufferCountNonZero); 4746e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_count_equal_zero", checkEventSupport, submitBufferCountEqualZero); 4747e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_wait_single_semaphore", checkEventSupport, submitBufferWaitSingleSemaphore); 4748e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_wait_many_semaphores", checkEventSupport, submitBufferWaitManySemaphores); 4749e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_null_fence", checkEventSupport, submitBufferNullFence); 4750e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "submit_two_buffers_one_buffer_null_with_fence", checkEventSupport, submitTwoBuffersOneBufferNullWithFence); 4751e5c31af7Sopenharmony_ci /* 19.5. Secondary Command Buffer Execution (5.6 in VK 1.0 Spec) */ 4752e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "secondary_execute", checkEventAndSecondaryCommandBufferNullFramebufferSupport, executeSecondaryBufferTest); 4753e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "secondary_execute_twice", checkEventAndTimelineSemaphoreAndSimultaneousUseAndSecondaryCommandBufferNullFramebufferSupport, executeSecondaryBufferTwiceTest); 4754e5c31af7Sopenharmony_ci /* 19.6. Commands Allowed Inside Command Buffers (? in VK 1.0 Spec) */ 4755e5c31af7Sopenharmony_ci addFunctionCaseWithPrograms (commandBuffersTests.get(), "order_bind_pipeline", genComputeSource, orderBindPipelineTest); 4756e5c31af7Sopenharmony_ci /* Verify untested transitions between command buffer states */ 4757e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "recording_to_ininitial", executeStateTransitionTest, STT_RECORDING_TO_INITIAL); 4758e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "executable_to_ininitial", executeStateTransitionTest, STT_EXECUTABLE_TO_INITIAL); 4759e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "recording_to_invalid", executeStateTransitionTest, STT_RECORDING_TO_INVALID); 4760e5c31af7Sopenharmony_ci addFunctionCase (commandBuffersTests.get(), "executable_to_invalid", executeStateTransitionTest, STT_EXECUTABLE_TO_INVALID); 4761e5c31af7Sopenharmony_ci 4762e5c31af7Sopenharmony_ci return commandBuffersTests.release(); 4763e5c31af7Sopenharmony_ci} 4764e5c31af7Sopenharmony_ci 4765e5c31af7Sopenharmony_ci} // api 4766e5c31af7Sopenharmony_ci} // vkt 4767