1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2016 The Khronos Group Inc.
6 * Copyright (c) 2016 Imagination Technologies Ltd.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 * \brief Robustness Utilities
23 *//*--------------------------------------------------------------------*/
25 #include "vktRobustnessUtil.hpp"
27 #include "vkImageUtil.hpp"
28 #include "vkPrograms.hpp"
29 #include "vkQueryUtil.hpp"
30 #include "vkRefUtil.hpp"
43 Move<VkDevice> createRobustBufferAccessDevice (Context& context)
45 const float queuePriority = 1.0f;
47 // Create a universal queue that supports graphics and compute
48 const VkDeviceQueueCreateInfo queueParams =
50 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // VkStructureType sType;
51 DE_NULL, // const void* pNext;
52 0u, // VkDeviceQueueCreateFlags flags;
53 context.getUniversalQueueFamilyIndex(), // deUint32 queueFamilyIndex;
54 1u, // deUint32 queueCount;
55 &queuePriority // const float* pQueuePriorities;
58 VkPhysicalDeviceFeatures enabledFeatures = context.getDeviceFeatures();
59 enabledFeatures.robustBufferAccess = true;
61 const VkDeviceCreateInfo deviceParams =
63 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // VkStructureType sType;
64 DE_NULL, // const void* pNext;
65 0u, // VkDeviceCreateFlags flags;
66 1u, // deUint32 queueCreateInfoCount;
67 &queueParams, // const VkDeviceQueueCreateInfo* pQueueCreateInfos;
68 0u, // deUint32 enabledLayerCount;
69 DE_NULL, // const char* const* ppEnabledLayerNames;
70 0u, // deUint32 enabledExtensionCount;
71 DE_NULL, // const char* const* ppEnabledExtensionNames;
72 &enabledFeatures // const VkPhysicalDeviceFeatures* pEnabledFeatures;
75 return createDevice(context.getInstanceInterface(), context.getPhysicalDevice(), &deviceParams);
78 bool areEqual (float a, float b)
80 return deFloatAbs(a - b) <= 0.001f;
83 bool isValueZero (const void* valuePtr, size_t valueSizeInBytes)
85 const deUint8* bytePtr = reinterpret_cast<const deUint8*>(valuePtr);
87 for (size_t i = 0; i < valueSizeInBytes; i++)
96 bool isValueWithinBuffer (const void* buffer, VkDeviceSize bufferSize, const void* valuePtr, size_t valueSizeInBytes)
98 const deUint8* byteBuffer = reinterpret_cast<const deUint8*>(buffer);
100 if (bufferSize < ((VkDeviceSize)valueSizeInBytes))
103 for (VkDeviceSize i = 0; i <= (bufferSize - valueSizeInBytes); i++)
105 if (!deMemCmp(&byteBuffer[i], valuePtr, valueSizeInBytes))
112 bool isValueWithinBufferOrZero (const void* buffer, VkDeviceSize bufferSize, const void* valuePtr, size_t valueSizeInBytes)
114 return isValueWithinBuffer(buffer, bufferSize, valuePtr, valueSizeInBytes) || isValueZero(valuePtr, valueSizeInBytes);
117 bool verifyOutOfBoundsVec4 (const void* vecPtr, VkFormat bufferFormat)
119 if (isUintFormat(bufferFormat))
121 const deUint32* data = (deUint32*)vecPtr;
126 && (data[3] == 0u || data[3] == 1u || data[3] == std::numeric_limits<deUint32>::max());
128 else if (isIntFormat(bufferFormat))
130 const deInt32* data = (deInt32*)vecPtr;
135 && (data[3] == 0 || data[3] == 1 || data[3] == std::numeric_limits<deInt32>::max());
137 else if (isFloatFormat(bufferFormat))
139 const float* data = (float*)vecPtr;
141 return areEqual(data[0], 0.0f)
142 && areEqual(data[1], 0.0f)
143 && areEqual(data[2], 0.0f)
144 && (areEqual(data[3], 0.0f) || areEqual(data[3], 1.0f));
146 else if (bufferFormat == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
148 return *((deUint32*)vecPtr) == 0xc0000000u;
155 void populateBufferWithTestValues (void* buffer, VkDeviceSize size, VkFormat format)
157 // Assign a sequence of 32-bit values
158 for (VkDeviceSize scalarNdx = 0; scalarNdx < size / 4; scalarNdx++)
160 const deUint32 valueIndex = (deUint32)(2 + scalarNdx); // Do not use 0 or 1
162 if (isUintFormat(format))
164 reinterpret_cast<deUint32*>(buffer)[scalarNdx] = valueIndex;
166 else if (isIntFormat(format))
168 reinterpret_cast<deInt32*>(buffer)[scalarNdx] = -deInt32(valueIndex);
170 else if (isFloatFormat(format))
172 reinterpret_cast<float*>(buffer)[scalarNdx] = float(valueIndex);
174 else if (format == VK_FORMAT_A2B10G10R10_UNORM_PACK32)
176 const deUint32 r = ((valueIndex + 0) & ((2u << 10) - 1u));
177 const deUint32 g = ((valueIndex + 1) & ((2u << 10) - 1u));
178 const deUint32 b = ((valueIndex + 2) & ((2u << 10) - 1u));
179 const deUint32 a = ((valueIndex + 0) & ((2u << 2) - 1u));
181 reinterpret_cast<deUint32*>(buffer)[scalarNdx] = (a << 30) | (b << 20) | (g << 10) | r;
190 void logValue (std::ostringstream& logMsg, const void* valuePtr, VkFormat valueFormat, size_t valueSize)
192 if (isUintFormat(valueFormat))
194 logMsg << *reinterpret_cast<const deUint32*>(valuePtr);
196 else if (isIntFormat(valueFormat))
198 logMsg << *reinterpret_cast<const deInt32*>(valuePtr);
200 else if (isFloatFormat(valueFormat))
202 logMsg << *reinterpret_cast<const float*>(valuePtr);
206 const deUint8* bytePtr = reinterpret_cast<const deUint8*>(valuePtr);
207 const std::ios::fmtflags streamFlags = logMsg.flags();
210 for (size_t i = 0; i < valueSize; i++)
212 logMsg << " " << (deUint32)bytePtr[i];
214 logMsg.flags(streamFlags);
220 TestEnvironment::TestEnvironment (Context& context,
222 VkDescriptorSetLayout descriptorSetLayout,
223 VkDescriptorSet descriptorSet)
224 : m_context (context)
226 , m_descriptorSetLayout (descriptorSetLayout)
227 , m_descriptorSet (descriptorSet)
229 const DeviceInterface& vk = context.getDeviceInterface();
231 // Create command pool
233 const VkCommandPoolCreateInfo commandPoolParams =
235 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
236 DE_NULL, // const void* pNext;
237 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
238 context.getUniversalQueueFamilyIndex() // deUint32 queueFamilyIndex;
241 m_commandPool = createCommandPool(vk, m_device, &commandPoolParams);
244 // Create command buffer
246 const VkCommandBufferAllocateInfo commandBufferAllocateInfo =
248 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
249 DE_NULL, // const void* pNext;
250 *m_commandPool, // VkCommandPool commandPool;
251 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
252 1u, // deUint32 bufferCount;
255 m_commandBuffer = allocateCommandBuffer(vk, m_device, &commandBufferAllocateInfo);
259 VkCommandBuffer TestEnvironment::getCommandBuffer (void)
261 return *m_commandBuffer;
264 // GraphicsEnvironment
266 GraphicsEnvironment::GraphicsEnvironment (Context& context,
268 VkDescriptorSetLayout descriptorSetLayout,
269 VkDescriptorSet descriptorSet,
270 const VertexBindings& vertexBindings,
271 const VertexAttributes& vertexAttributes,
272 const DrawConfig& drawConfig)
274 : TestEnvironment (context, device, descriptorSetLayout, descriptorSet)
275 , m_renderSize (16, 16)
276 , m_colorFormat (VK_FORMAT_R8G8B8A8_UNORM)
278 const DeviceInterface& vk = context.getDeviceInterface();
279 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
280 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
281 SimpleAllocator memAlloc (vk, m_device, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
283 // Create color image and view
285 const VkImageCreateInfo colorImageParams =
287 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
288 DE_NULL, // const void* pNext;
289 0u, // VkImageCreateFlags flags;
290 VK_IMAGE_TYPE_2D, // VkImageType imageType;
291 m_colorFormat, // VkFormat format;
292 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u }, // VkExtent3D extent;
293 1u, // deUint32 mipLevels;
294 1u, // deUint32 arrayLayers;
295 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
296 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
297 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
298 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
299 1u, // deUint32 queueFamilyIndexCount;
300 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
301 VK_IMAGE_LAYOUT_UNDEFINED // VkImageLayout initialLayout;
304 m_colorImage = createImage(vk, m_device, &colorImageParams);
305 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, m_device, *m_colorImage), MemoryRequirement::Any);
306 VK_CHECK(vk.bindImageMemory(m_device, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
308 const VkImageViewCreateInfo colorAttachmentViewParams =
310 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
311 DE_NULL, // const void* pNext;
312 0u, // VkImageViewCreateFlags flags;
313 *m_colorImage, // VkImage image;
314 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
315 m_colorFormat, // VkFormat format;
316 componentMappingRGBA, // VkComponentMapping components;
317 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
320 m_colorAttachmentView = createImageView(vk, m_device, &colorAttachmentViewParams);
323 // Create render pass
325 const VkAttachmentDescription colorAttachmentDescription =
327 0u, // VkAttachmentDescriptionFlags flags;
328 m_colorFormat, // VkFormat format;
329 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits samples;
330 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
331 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
332 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
333 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
334 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
335 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
338 const VkAttachmentReference colorAttachmentReference =
340 0u, // deUint32 attachment;
341 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
344 const VkSubpassDescription subpassDescription =
346 0u, // VkSubpassDescriptionFlags flags;
347 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
348 0u, // deUint32 inputAttachmentCount;
349 DE_NULL, // const VkAttachmentReference* pInputAttachments;
350 1u, // deUint32 colorAttachmentCount;
351 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
352 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
353 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
354 0u, // deUint32 preserveAttachmentCount;
355 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
358 const VkRenderPassCreateInfo renderPassParams =
360 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
361 DE_NULL, // const void* pNext;
362 0u, // VkRenderPassCreateFlags flags;
363 1u, // deUint32 attachmentCount;
364 &colorAttachmentDescription, // const VkAttachmentDescription* pAttachments;
365 1u, // deUint32 subpassCount;
366 &subpassDescription, // const VkSubpassDescription* pSubpasses;
367 0u, // deUint32 dependencyCount;
368 DE_NULL // const VkSubpassDependency* pDependencies;
371 m_renderPass = createRenderPass(vk, m_device, &renderPassParams);
374 // Create framebuffer
376 const VkFramebufferCreateInfo framebufferParams =
378 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
379 DE_NULL, // const void* pNext;
380 0u, // VkFramebufferCreateFlags flags;
381 *m_renderPass, // VkRenderPass renderPass;
382 1u, // deUint32 attachmentCount;
383 &m_colorAttachmentView.get(), // const VkImageView* pAttachments;
384 (deUint32)m_renderSize.x(), // deUint32 width;
385 (deUint32)m_renderSize.y(), // deUint32 height;
386 1u // deUint32 layers;
389 m_framebuffer = createFramebuffer(vk, m_device, &framebufferParams);
392 // Create pipeline layout
394 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
396 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
397 DE_NULL, // const void* pNext;
398 0u, // VkPipelineLayoutCreateFlags flags;
399 1u, // deUint32 setLayoutCount;
400 &m_descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
401 0u, // deUint32 pushConstantRangeCount;
402 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
405 m_pipelineLayout = createPipelineLayout(vk, m_device, &pipelineLayoutParams);
408 m_vertexShaderModule = createShaderModule(vk, m_device, m_context.getBinaryCollection().get("vertex"), 0);
409 m_fragmentShaderModule = createShaderModule(vk, m_device, m_context.getBinaryCollection().get("fragment"), 0);
413 const VkPipelineShaderStageCreateInfo renderShaderStages[2] =
416 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
417 DE_NULL, // const void* pNext;
418 0u, // VkPipelineShaderStageCreateFlags flags;
419 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
420 *m_vertexShaderModule, // VkShaderModule module;
421 "main", // const char* pName;
422 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
425 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
426 DE_NULL, // const void* pNext;
427 0u, // VkPipelineShaderStageCreateFlags flags;
428 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
429 *m_fragmentShaderModule, // VkShaderModule module;
430 "main", // const char* pName;
431 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
435 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
437 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
438 DE_NULL, // const void* pNext;
439 0u, // VkPipelineVertexInputStateCreateFlags flags;
440 (deUint32)vertexBindings.size(), // deUint32 vertexBindingDescriptionCount;
441 vertexBindings.data(), // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
442 (deUint32)vertexAttributes.size(), // deUint32 vertexAttributeDescriptionCount;
443 vertexAttributes.data() // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
446 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
448 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
449 DE_NULL, // const void* pNext;
450 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
451 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, // VkPrimitiveTopology topology;
452 false // VkBool32 primitiveRestartEnable;
455 const VkViewport viewport =
459 (float)m_renderSize.x(), // float width;
460 (float)m_renderSize.y(), // float height;
461 0.0f, // float minDepth;
462 1.0f // float maxDepth;
465 const VkRect2D scissor = { { 0, 0 }, { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } };
467 const VkPipelineViewportStateCreateInfo viewportStateParams =
469 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
470 DE_NULL, // const void* pNext;
471 0u, // VkPipelineViewportStateCreateFlags flags;
472 1u, // deUint32 viewportCount;
473 &viewport, // const VkViewport* pViewports;
474 1u, // deUint32 scissorCount;
475 &scissor // const VkRect2D* pScissors;
478 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
480 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
481 DE_NULL, // const void* pNext;
482 0u, // VkPipelineRasterizationStateCreateFlags flags;
483 false, // VkBool32 depthClampEnable;
484 false, // VkBool32 rasterizerDiscardEnable;
485 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
486 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
487 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
488 false, // VkBool32 depthBiasEnable;
489 0.0f, // float depthBiasConstantFactor;
490 0.0f, // float depthBiasClamp;
491 0.0f, // float depthBiasSlopeFactor;
492 1.0f // float lineWidth;
495 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
497 false, // VkBool32 blendEnable;
498 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcColorBlendFactor;
499 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstColorBlendFactor;
500 VK_BLEND_OP_ADD, // VkBlendOp colorBlendOp;
501 VK_BLEND_FACTOR_ONE, // VkBlendFactor srcAlphaBlendFactor;
502 VK_BLEND_FACTOR_ZERO, // VkBlendFactor dstAlphaBlendFactor;
503 VK_BLEND_OP_ADD, // VkBlendOp alphaBlendOp;
504 VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | // VkColorComponentFlags colorWriteMask;
505 VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT
508 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
510 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
511 DE_NULL, // const void* pNext;
512 0u, // VkPipelineColorBlendStateCreateFlags flags;
513 false, // VkBool32 logicOpEnable;
514 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
515 1u, // deUint32 attachmentCount;
516 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
517 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
520 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
522 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
523 DE_NULL, // const void* pNext;
524 0u, // VkPipelineMultisampleStateCreateFlags flags;
525 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
526 false, // VkBool32 sampleShadingEnable;
527 0.0f, // float minSampleShading;
528 DE_NULL, // const VkSampleMask* pSampleMask;
529 false, // VkBool32 alphaToCoverageEnable;
530 false // VkBool32 alphaToOneEnable;
533 VkPipelineDepthStencilStateCreateInfo depthStencilStateParams =
535 VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, // VkStructureType sType;
536 DE_NULL, // const void* pNext;
537 0u, // VkPipelineDepthStencilStateCreateFlags flags;
538 false, // VkBool32 depthTestEnable;
539 false, // VkBool32 depthWriteEnable;
540 VK_COMPARE_OP_LESS, // VkCompareOp depthCompareOp;
541 false, // VkBool32 depthBoundsTestEnable;
542 false, // VkBool32 stencilTestEnable;
543 { // VkStencilOpState front;
544 VK_STENCIL_OP_ZERO, // VkStencilOp failOp;
545 VK_STENCIL_OP_ZERO, // VkStencilOp passOp;
546 VK_STENCIL_OP_ZERO, // VkStencilOp depthFailOp;
547 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
548 0u, // deUint32 compareMask;
549 0u, // deUint32 writeMask;
550 0u // deUint32 reference;
552 { // VkStencilOpState back;
553 VK_STENCIL_OP_ZERO, // VkStencilOp failOp;
554 VK_STENCIL_OP_ZERO, // VkStencilOp passOp;
555 VK_STENCIL_OP_ZERO, // VkStencilOp depthFailOp;
556 VK_COMPARE_OP_NEVER, // VkCompareOp compareOp;
557 0u, // deUint32 compareMask;
558 0u, // deUint32 writeMask;
559 0u // deUint32 reference;
561 -1.0f, // float minDepthBounds;
562 +1.0f // float maxDepthBounds;
565 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
567 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
568 DE_NULL, // const void* pNext;
569 0u, // VkPipelineCreateFlags flags;
570 2u, // deUint32 stageCount;
571 renderShaderStages, // const VkPipelineShaderStageCreateInfo* pStages;
572 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
573 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
574 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
575 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
576 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
577 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
578 &depthStencilStateParams, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
579 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
580 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
581 *m_pipelineLayout, // VkPipelineLayout layout;
582 *m_renderPass, // VkRenderPass renderPass;
583 0u, // deUint32 subpass;
584 0u, // VkPipeline basePipelineHandle;
585 0u // deInt32 basePipelineIndex;
588 m_graphicsPipeline = createGraphicsPipeline(vk, m_device, DE_NULL, &graphicsPipelineParams);
593 const VkCommandBufferBeginInfo commandBufferBeginInfo =
595 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
596 DE_NULL, // const void* pNext;
597 0u, // VkCommandBufferUsageFlags flags;
598 (const VkCommandBufferInheritanceInfo*)DE_NULL, // const VkCommandBufferInheritanceInfo *pInheritanceInfo;
601 VkClearValue attachmentClearValue;
602 attachmentClearValue.color.float32[0] = 0.0f;
603 attachmentClearValue.color.float32[1] = 0.0f;
604 attachmentClearValue.color.float32[2] = 0.0f;
605 attachmentClearValue.color.float32[3] = 0.0f;
607 const VkRenderPassBeginInfo renderPassBeginInfo =
609 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
610 DE_NULL, // const void* pNext;
611 *m_renderPass, // VkRenderPass renderPass;
612 *m_framebuffer, // VkFramebuffer framebuffer;
615 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
616 }, // VkRect2D renderArea;
617 1, // deUint32 clearValueCount;
618 &attachmentClearValue // const VkClearValue* pClearValues;
621 const VkImageMemoryBarrier imageLayoutBarrier =
623 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
624 DE_NULL, // const void* pNext;
625 (VkAccessFlags)0, // VkAccessFlags srcAccessMask;
626 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
627 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
628 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
629 VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex;
630 VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex;
631 *m_colorImage, // VkImage image;
632 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
635 VK_CHECK(vk.beginCommandBuffer(*m_commandBuffer, &commandBufferBeginInfo));
637 vk.cmdPipelineBarrier(*m_commandBuffer,
638 VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
639 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
640 (VkDependencyFlags)0,
643 1u, &imageLayoutBarrier);
645 vk.cmdBeginRenderPass(*m_commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
647 const std::vector<VkDeviceSize> vertexBufferOffsets(drawConfig.vertexBuffers.size(), 0ull);
649 vk.cmdBindPipeline(*m_commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipeline);
650 vk.cmdBindDescriptorSets(*m_commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0, 1, &m_descriptorSet, 0, DE_NULL);
651 vk.cmdBindVertexBuffers(*m_commandBuffer, 0, (deUint32)drawConfig.vertexBuffers.size(), drawConfig.vertexBuffers.data(), vertexBufferOffsets.data());
653 if (drawConfig.indexBuffer == DE_NULL || drawConfig.indexCount == 0)
655 vk.cmdDraw(*m_commandBuffer, drawConfig.vertexCount, drawConfig.instanceCount, 0, 0);
659 vk.cmdBindIndexBuffer(*m_commandBuffer, drawConfig.indexBuffer, 0, VK_INDEX_TYPE_UINT32);
660 vk.cmdDrawIndexed(*m_commandBuffer, drawConfig.indexCount, drawConfig.instanceCount, 0, 0, 0);
663 vk.cmdEndRenderPass(*m_commandBuffer);
665 VK_CHECK(vk.endCommandBuffer(*m_commandBuffer));
669 // ComputeEnvironment
671 ComputeEnvironment::ComputeEnvironment (Context& context,
673 VkDescriptorSetLayout descriptorSetLayout,
674 VkDescriptorSet descriptorSet)
676 : TestEnvironment (context, device, descriptorSetLayout, descriptorSet)
678 const DeviceInterface& vk = context.getDeviceInterface();
680 // Create pipeline layout
682 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
684 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
685 DE_NULL, // const void* pNext;
686 0u, // VkPipelineLayoutCreateFlags flags;
687 1u, // deUint32 setLayoutCount;
688 &m_descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
689 0u, // deUint32 pushConstantRangeCount;
690 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
693 m_pipelineLayout = createPipelineLayout(vk, m_device, &pipelineLayoutParams);
696 // Create compute pipeline
698 m_computeShaderModule = createShaderModule(vk, m_device, m_context.getBinaryCollection().get("compute"), 0);
700 const VkPipelineShaderStageCreateInfo computeStageParams =
702 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
703 DE_NULL, // const void* pNext;
704 0u, // VkPipelineShaderStageCreateFlags flags;
705 VK_SHADER_STAGE_COMPUTE_BIT, // VkShaderStageFlagBits stage;
706 *m_computeShaderModule, // VkShaderModule module;
707 "main", // const char* pName;
708 DE_NULL, // const VkSpecializationInfo* pSpecializationInfo;
711 const VkComputePipelineCreateInfo computePipelineParams =
713 VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, // VkStructureType sType;
714 DE_NULL, // const void* pNext;
715 0u, // VkPipelineCreateFlags flags;
716 computeStageParams, // VkPipelineShaderStageCreateInfo stage;
717 *m_pipelineLayout, // VkPipelineLayout layout;
718 DE_NULL, // VkPipeline basePipelineHandle;
719 0u // deInt32 basePipelineIndex;
722 m_computePipeline = createComputePipeline(vk, m_device, DE_NULL, &computePipelineParams);
727 const VkCommandBufferBeginInfo commandBufferBeginInfo =
729 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
730 DE_NULL, // const void* pNext;
731 0u, // VkCommandBufferUsageFlags flags;
732 (const VkCommandBufferInheritanceInfo*)DE_NULL, // const VkCommandBufferInheritanceInfo *pInheritanceInfo;
735 VK_CHECK(vk.beginCommandBuffer(*m_commandBuffer, &commandBufferBeginInfo));
736 vk.cmdBindPipeline(*m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_computePipeline);
737 vk.cmdBindDescriptorSets(*m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, *m_pipelineLayout, 0, 1, &m_descriptorSet, 0, DE_NULL);
738 vk.cmdDispatch(*m_commandBuffer, 32, 32, 1);
739 VK_CHECK(vk.endCommandBuffer(*m_commandBuffer));