1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., 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 Vulkan Buffer View Memory Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktApiBufferViewAccessTests.hpp"
26 #include "vktApiBufferAndImageAllocationUtil.hpp"
28 #include "deStringUtil.hpp"
29 #include "deUniquePtr.hpp"
30 #include "vktTestCase.hpp"
31 #include "vktTestCaseUtil.hpp"
32 #include "vkImageUtil.hpp"
33 #include "vkMemUtil.hpp"
34 #include "vkPrograms.hpp"
35 #include "vkQueryUtil.hpp"
37 #include "vkRefUtil.hpp"
38 #include "vkTypeUtil.hpp"
39 #include "tcuImageCompare.hpp"
40 #include "tcuTexture.hpp"
41 #include "tcuTextureUtil.hpp"
42 #include "deSharedPtr.hpp"
57 ALLOCATION_KIND_SUBALLOCATION = 0,
58 ALLOCATION_KIND_DEDICATED = 1,
62 struct BufferViewCaseParams
65 deUint32 bufferViewSize;
66 deUint32 elementOffset;
67 AllocationKind bufferAllocationKind;
68 AllocationKind imageAllocationKind;
71 class BufferViewTestInstance : public vkt::TestInstance
74 BufferViewTestInstance (Context& context,
75 BufferViewCaseParams testCase);
76 virtual ~BufferViewTestInstance (void);
77 virtual tcu::TestStatus iterate (void);
80 void createQuad (void);
81 tcu::TestStatus checkResult (deInt8 factor);
84 BufferViewCaseParams m_testCase;
86 const tcu::IVec2 m_renderSize;
87 const VkFormat m_colorFormat;
89 const VkDeviceSize m_pixelDataSize;
91 Move<VkImage> m_colorImage;
92 de::MovePtr<Allocation> m_colorImageAlloc;
93 Move<VkImageView> m_colorAttachmentView;
94 Move<VkRenderPass> m_renderPass;
95 Move<VkFramebuffer> m_framebuffer;
97 Move<VkDescriptorSetLayout> m_descriptorSetLayout;
98 Move<VkDescriptorPool> m_descriptorPool;
99 Move<VkDescriptorSet> m_descriptorSet;
101 Move<VkBuffer> m_uniformBuffer;
102 de::MovePtr<vk::Allocation> m_uniformBufferAlloc;
103 Move<VkBufferView> m_uniformBufferView;
105 Move<VkShaderModule> m_vertexShaderModule;
106 Move<VkShaderModule> m_fragmentShaderModule;
108 Move<VkBuffer> m_vertexBuffer;
109 std::vector<tcu::Vec4> m_vertices;
110 de::MovePtr<Allocation> m_vertexBufferAlloc;
112 Move<VkPipelineLayout> m_pipelineLayout;
113 Move<VkPipeline> m_graphicsPipelines;
115 Move<VkCommandPool> m_cmdPool;
116 Move<VkCommandBuffer> m_cmdBuffer;
118 Move<VkBuffer> m_resultBuffer;
119 de::MovePtr<Allocation> m_resultBufferAlloc;
121 Move<VkFence> m_fence;
124 static void generateBuffer (std::vector<deUint32>& uniformData,
128 for (deUint32 i = 0; i < bufferSize; ++i)
129 uniformData.push_back(factor * i);
132 void BufferViewTestInstance::createQuad (void)
134 tcu::Vec4 a(-1.0, -1.0, 0.0, 1.0);
135 tcu::Vec4 b(1.0, -1.0, 0.0, 1.0);
136 tcu::Vec4 c(1.0, 1.0, 0.0, 1.0);
137 tcu::Vec4 d(-1.0, 1.0, 0.0, 1.0);
140 m_vertices.push_back(a);
141 m_vertices.push_back(c);
142 m_vertices.push_back(b);
145 m_vertices.push_back(c);
146 m_vertices.push_back(a);
147 m_vertices.push_back(d);
150 BufferViewTestInstance::~BufferViewTestInstance (void)
154 BufferViewTestInstance::BufferViewTestInstance (Context& context,
155 BufferViewCaseParams testCase)
156 : vkt::TestInstance (context)
157 , m_testCase (testCase)
158 , m_renderSize (testCase.bufferViewSize, testCase.bufferViewSize)
159 , m_colorFormat (VK_FORMAT_R32_UINT)
160 , m_pixelDataSize (m_renderSize.x() * m_renderSize.y() * mapVkFormat(m_colorFormat).getPixelSize())
162 const DeviceInterface& vk = context.getDeviceInterface();
163 const VkDevice vkDevice = context.getDevice();
164 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
165 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
166 const VkComponentMapping channelMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
168 // Create color image
169 if (m_testCase.imageAllocationKind == ALLOCATION_KIND_DEDICATED)
171 ImageDedicatedAllocation().createTestImage(m_renderSize, m_colorFormat, context, memAlloc, m_colorImage, MemoryRequirement::Any, m_colorImageAlloc);
175 ImageSuballocation().createTestImage(m_renderSize, m_colorFormat, context, memAlloc, m_colorImage, MemoryRequirement::Any, m_colorImageAlloc);
178 // Create destination buffer
179 if (m_testCase.bufferAllocationKind == ALLOCATION_KIND_DEDICATED)
181 BufferDedicatedAllocation().createTestBuffer(m_pixelDataSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, m_context, memAlloc, m_resultBuffer, MemoryRequirement::HostVisible, m_resultBufferAlloc);
185 BufferSuballocation().createTestBuffer(m_pixelDataSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, m_context, memAlloc, m_resultBuffer, MemoryRequirement::HostVisible, m_resultBufferAlloc);
188 // Create color attachment view
190 const VkImageViewCreateInfo colorAttachmentViewParams =
192 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
193 DE_NULL, // const void* pNext;
194 0u, // VkImageViewCreateFlags flags;
195 *m_colorImage, // VkImage image;
196 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
197 m_colorFormat, // VkFormat format;
198 channelMappingRGBA, // VkChannelMapping channels;
199 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
202 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
205 // Create render pass
207 const VkAttachmentDescription colorAttachmentDescription =
209 0u, // VkAttachmentDescriptionFlags flags;
210 m_colorFormat, // VkFormat format;
211 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
212 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
213 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
214 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
215 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
216 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
217 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
220 const VkAttachmentReference colorAttachmentReference =
222 0u, // deUint32 attachment;
223 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
226 const VkSubpassDescription subpassDescription =
228 0u, // VkSubpassDescriptionFlags flags;
229 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
230 0u, // deUint32 inputCount;
231 DE_NULL, // const VkAttachmentReference* pInputAttachments;
232 1u, // deUint32 colorCount;
233 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
234 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
235 DE_NULL, // VkAttachmentReference depthStencilAttachment;
236 0u, // deUint32 preserveCount;
237 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
240 const VkRenderPassCreateInfo renderPassParams =
242 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
243 DE_NULL, // const void* pNext;
244 (VkRenderPassCreateFlags)0,
245 1u, // deUint32 attachmentCount;
246 &colorAttachmentDescription, // const VkAttachmentDescription* pAttachments;
247 1u, // deUint32 subpassCount;
248 &subpassDescription, // const VkSubpassDescription* pSubpasses;
249 0u, // deUint32 dependencyCount;
250 DE_NULL // const VkSubpassDependency* pDependencies;
253 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
256 // Create framebuffer
258 const VkImageView attachmentBindInfos[1] =
260 *m_colorAttachmentView,
263 const VkFramebufferCreateInfo framebufferParams =
265 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
266 DE_NULL, // const void* pNext;
267 (VkFramebufferCreateFlags)0,
268 *m_renderPass, // VkRenderPass renderPass;
269 1u, // deUint32 attachmentCount;
270 attachmentBindInfos, // const VkImageView* pAttachments;
271 (deUint32)m_renderSize.x(), // deUint32 width;
272 (deUint32)m_renderSize.y(), // deUint32 height;
273 1u // deUint32 layers;
276 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
279 // Create descriptors
281 const VkDescriptorSetLayoutBinding
285 0u, // deUint32 binding;
286 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType descriptorType;
287 1u, // deUint32 arraySize;
288 VK_SHADER_STAGE_ALL, // VkShaderStageFlags stageFlags;
289 DE_NULL // const VkSampler* pImmutableSamplers;
293 const VkDescriptorSetLayoutCreateInfo
294 descriptorLayoutParams =
296 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
297 DE_NULL, // cost void* pNexŧ;
298 (VkDescriptorSetLayoutCreateFlags)0,
299 DE_LENGTH_OF_ARRAY(layoutBindings), // deUint32 count;
300 layoutBindings // const VkDescriptorSetLayoutBinding pBinding;
303 m_descriptorSetLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorLayoutParams);
306 std::vector<deUint32> uniformData;
307 generateBuffer(uniformData, testCase.bufferSize, 1);
309 const VkDeviceSize uniformSize = testCase.bufferSize * sizeof(deUint32);
311 BufferSuballocation().createTestBuffer(uniformSize, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, m_context, memAlloc, m_uniformBuffer, MemoryRequirement::HostVisible, m_uniformBufferAlloc);
312 deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
313 flushMappedMemoryRange(vk, vkDevice, m_uniformBufferAlloc->getMemory(), m_uniformBufferAlloc->getOffset(), uniformSize);
315 const VkBufferViewCreateInfo viewInfo =
317 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
318 DE_NULL, // void* pNext;
319 (VkBufferViewCreateFlags)0,
320 *m_uniformBuffer, // VkBuffer buffer;
321 m_colorFormat, // VkFormat format;
322 m_testCase.elementOffset * sizeof(deUint32), // VkDeviceSize offset;
323 m_testCase.bufferViewSize * sizeof(deUint32) // VkDeviceSize range;
326 m_uniformBufferView = createBufferView(vk, vkDevice, &viewInfo);
328 const VkDescriptorPoolSize descriptorTypes[1] =
331 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType type;
336 const VkDescriptorPoolCreateInfo
337 descriptorPoolParams =
339 VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
340 DE_NULL, // void* pNext;
341 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, // VkDescriptorPoolCreateFlags flags;
342 1u, // uint32_t maxSets;
343 DE_LENGTH_OF_ARRAY(descriptorTypes), // deUint32 count;
344 descriptorTypes // const VkDescriptorTypeCount* pTypeCount
347 m_descriptorPool = createDescriptorPool(vk, vkDevice, &descriptorPoolParams);
349 const VkDescriptorSetAllocateInfo
350 descriptorSetParams =
352 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
356 &m_descriptorSetLayout.get(),
358 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetParams);
360 const VkWriteDescriptorSet writeDescritporSets[] =
363 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
364 DE_NULL, // const void* pNext;
365 *m_descriptorSet, // VkDescriptorSet destSet;
366 0, // deUint32 destBinding;
367 0, // deUint32 destArrayElement;
368 1u, // deUint32 count;
369 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType descriptorType;
370 (const VkDescriptorImageInfo*)DE_NULL,
371 (const VkDescriptorBufferInfo*)DE_NULL,
372 &m_uniformBufferView.get(),
376 vk.updateDescriptorSets(vkDevice, DE_LENGTH_OF_ARRAY(writeDescritporSets), writeDescritporSets, 0u, DE_NULL);
379 // Create pipeline layout
381 const VkPipelineLayoutCreateInfo
382 pipelineLayoutParams =
384 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
385 DE_NULL, // const void* pNext;
386 (VkPipelineLayoutCreateFlags)0,
387 1u, // deUint32 descriptorSetCount;
388 &*m_descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
389 0u, // deUint32 pushConstantRangeCount;
390 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
393 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
398 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
399 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
405 const VkPipelineShaderStageCreateInfo
406 shaderStageParams[2] =
409 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
410 DE_NULL, // const void* pNext;
411 (VkPipelineShaderStageCreateFlags)0,
412 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStage stage;
413 *m_vertexShaderModule, // VkShader shader;
415 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
418 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
419 DE_NULL, // const void* pNext;
420 (VkPipelineShaderStageCreateFlags)0,
421 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStage stage;
422 *m_fragmentShaderModule, // VkShader shader;
424 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
428 const VkVertexInputBindingDescription
429 vertexInputBindingDescription =
431 0u, // deUint32 binding;
432 sizeof(tcu::Vec4), // deUint32 strideInBytes;
433 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate;
436 const VkVertexInputAttributeDescription
437 vertexInputAttributeDescriptions[1]
441 0u, // deUint32 location;
442 0u, // deUint32 binding;
443 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
444 0u // deUint32 offsetInBytes;
448 const VkPipelineVertexInputStateCreateInfo
449 vertexInputStateParams =
451 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
452 DE_NULL, // const void* pNext;
453 (VkPipelineVertexInputStateCreateFlags)0,
454 1u, // deUint32 bindingCount;
455 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
456 1u, // deUint32 attributeCount;
457 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
460 const VkPipelineInputAssemblyStateCreateInfo
461 inputAssemblyStateParams =
463 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
464 DE_NULL, // const void* pNext;
465 (VkPipelineInputAssemblyStateCreateFlags)0,
466 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
467 false // VkBool32 primitiveRestartEnable;
470 const VkViewport viewport =
472 0.0f, // float originX;
473 0.0f, // float originY;
474 (float)m_renderSize.x(), // float width;
475 (float)m_renderSize.y(), // float height;
476 0.0f, // float minDepth;
477 1.0f // float maxDepth;
479 const VkRect2D scissor =
481 { 0, 0 }, // VkOffset2D offset;
482 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } // VkExtent2D extent;
484 const VkPipelineViewportStateCreateInfo
485 viewportStateParams =
487 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
488 DE_NULL, // const void* pNext;
489 (VkPipelineViewportStateCreateFlags)0,
490 1u, // deUint32 viewportCount;
491 &viewport, // const VkViewport* pViewports;
492 1u, // deUint32 scissorCount;
493 &scissor // const VkRect2D* pScissors;
496 const VkPipelineRasterizationStateCreateInfo
499 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
500 DE_NULL, // const void* pNext;
501 (VkPipelineRasterizationStateCreateFlags)0,
502 false, // VkBool32 depthClipEnable;
503 false, // VkBool32 rasterizerDiscardEnable;
504 VK_POLYGON_MODE_FILL, // VkFillMode fillMode;
505 VK_CULL_MODE_NONE, // VkCullMode cullMode;
506 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
507 VK_FALSE, // VkBool32 depthBiasEnable;
508 0.0f, // float depthBias;
509 0.0f, // float depthBiasClamp;
510 0.0f, // float slopeScaledDepthBias;
511 1.0f, // float lineWidth;
514 const VkPipelineMultisampleStateCreateInfo
515 multisampleStateParams =
517 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
518 DE_NULL, // const void* pNext;
519 0u, // VkPipelineMultisampleStateCreateFlags flags;
520 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
521 VK_FALSE, // VkBool32 sampleShadingEnable;
522 0.0f, // float minSampleShading;
523 DE_NULL, // const VkSampleMask* pSampleMask;
524 VK_FALSE, // VkBool32 alphaToCoverageEnable;
525 VK_FALSE // VkBool32 alphaToOneEnable;
528 const VkPipelineColorBlendAttachmentState
529 colorBlendAttachmentState =
531 false, // VkBool32 blendEnable;
532 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
533 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
534 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
535 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
536 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
537 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
538 (VK_COLOR_COMPONENT_R_BIT |
539 VK_COLOR_COMPONENT_G_BIT |
540 VK_COLOR_COMPONENT_B_BIT |
541 VK_COLOR_COMPONENT_A_BIT) // VkChannelFlags channelWriteMask;
544 const VkPipelineColorBlendStateCreateInfo
545 colorBlendStateParams =
547 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
548 DE_NULL, // const void* pNext;
549 (VkPipelineColorBlendStateCreateFlags)0,
550 false, // VkBool32 logicOpEnable;
551 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
552 1u, // deUint32 attachmentCount;
553 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
554 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
557 const VkGraphicsPipelineCreateInfo
558 graphicsPipelineParams =
560 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
561 DE_NULL, // const void* pNext;
562 0u, // VkPipelineCreateFlags flags;
563 2u, // deUint32 stageCount;
564 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
565 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
566 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
567 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
568 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
569 &rasterStateParams, // const VkPipelineRasterStateCreateInfo* pRasterState;
570 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
571 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
572 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
573 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
574 *m_pipelineLayout, // VkPipelineLayout layout;
575 *m_renderPass, // VkRenderPass renderPass;
576 0u, // deUint32 subpass;
577 0u, // VkPipeline basePipelineHandle;
578 0u // deInt32 basePipelineIndex;
581 m_graphicsPipelines = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
584 // Create vertex buffer
587 const VkDeviceSize vertexDataSize = m_vertices.size() * sizeof(tcu::Vec4);
589 BufferSuballocation().createTestBuffer(vertexDataSize, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, m_context, memAlloc, m_vertexBuffer, MemoryRequirement::HostVisible, m_vertexBufferAlloc);
591 // Load vertices into vertex buffer
592 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), (size_t)vertexDataSize);
593 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexDataSize);
596 // Create command pool
597 m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, queueFamilyIndex);
599 // Create command buffer
601 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
603 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
604 DE_NULL, // const void* pNext;
605 0u, // VkCmdBufferOptimizeFlags flags;
606 (const VkCommandBufferInheritanceInfo*)DE_NULL,
609 const VkClearValue clearValue = makeClearValueColorF32(0.0, 0.0, 0.0, 0.0);
611 const VkClearValue attachmentClearValues[1] =
616 const VkRenderPassBeginInfo renderPassBeginInfo =
618 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
619 DE_NULL, // const void* pNext;
620 *m_renderPass, // VkRenderPass renderPass;
621 *m_framebuffer, // VkFramebuffer framebuffer;
624 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
625 }, // VkRect2D renderArea;
626 1u, // deUint32 clearValueCount;
627 attachmentClearValues // const VkClearValue* pClearValues;
630 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
632 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
634 const VkImageMemoryBarrier initialImageBarrier =
636 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
637 DE_NULL, // const void* pNext;
638 0, // VkMemoryOutputFlags outputMask;
639 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryInputFlags inputMask;
640 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
641 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
642 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
643 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
644 *m_colorImage, // VkImage image;
645 { // VkImageSubresourceRange subresourceRange;
646 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
647 0u, // deUint32 baseMipLevel;
648 1u, // deUint32 mipLevels;
649 0u, // deUint32 baseArraySlice;
650 1u // deUint32 arraySize;
654 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &initialImageBarrier);
656 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
658 const VkDeviceSize vertexBufferOffset[1] = { 0 };
660 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
661 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1, &*m_descriptorSet, 0u, DE_NULL);
662 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), vertexBufferOffset);
663 vk.cmdDraw(*m_cmdBuffer, (deUint32)m_vertices.size(), 1, 0, 0);
664 vk.cmdEndRenderPass(*m_cmdBuffer);
666 const VkImageMemoryBarrier imageBarrier =
668 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
669 DE_NULL, // const void* pNext;
670 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryOutputFlags outputMask;
671 VK_ACCESS_TRANSFER_READ_BIT, // VkMemoryInputFlags inputMask;
672 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
673 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
674 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
675 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
676 *m_colorImage, // VkImage image;
677 { // VkImageSubresourceRange subresourceRange;
678 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
679 0u, // deUint32 baseMipLevel;
680 1u, // deUint32 mipLevels;
681 0u, // deUint32 baseArraySlice;
682 1u // deUint32 arraySize;
686 const VkBufferMemoryBarrier bufferBarrier =
688 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
689 DE_NULL, // const void* pNext;
690 VK_ACCESS_TRANSFER_WRITE_BIT, // VkMemoryOutputFlags outputMask;
691 VK_ACCESS_HOST_READ_BIT, // VkMemoryInputFlags inputMask;
692 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
693 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
694 *m_resultBuffer, // VkBuffer buffer;
695 0u, // VkDeviceSize offset;
696 m_pixelDataSize // VkDeviceSize size;
699 const VkBufferImageCopy copyRegion =
701 0u, // VkDeviceSize bufferOffset;
702 (deUint32)m_renderSize.x(), // deUint32 bufferRowLength;
703 (deUint32)m_renderSize.y(), // deUint32 bufferImageHeight;
704 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u }, // VkImageSubresourceCopy imageSubresource;
705 { 0, 0, 0 }, // VkOffset3D imageOffset;
707 (deUint32)m_renderSize.x(),
708 (deUint32)m_renderSize.y(),
710 } // VkExtent3D imageExtent;
713 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
714 vk.cmdCopyImageToBuffer(*m_cmdBuffer, *m_colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *m_resultBuffer, 1, ©Region);
715 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
717 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
721 m_fence = createFence(vk, vkDevice);
724 tcu::TestStatus BufferViewTestInstance::checkResult (deInt8 factor)
726 const DeviceInterface& vk = m_context.getDeviceInterface();
727 const VkDevice vkDevice = m_context.getDevice();
728 const tcu::TextureFormat tcuFormat = mapVkFormat(m_colorFormat);
729 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(tcuFormat, m_renderSize.x(), m_renderSize.y()));
731 invalidateMappedMemoryRange(vk, vkDevice, m_resultBufferAlloc->getMemory(), m_resultBufferAlloc->getOffset(), m_pixelDataSize);
732 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_resultBufferAlloc->getHostPtr()));
734 tcu::ConstPixelBufferAccess pixelBuffer = resultLevel->getAccess();
735 for (deInt32 i = 0; i < (deInt32) m_renderSize.x(); ++i)
737 tcu::IVec4 pixel = pixelBuffer.getPixelInt(i, i);
738 deInt32 expected = factor * (m_testCase.elementOffset + i);
739 deInt32 actual = pixel[0];
740 if (expected != actual)
742 std::ostringstream errorMessage;
743 errorMessage << "BufferView test failed. expected: " << expected << " actual: " << actual;
744 return tcu::TestStatus::fail(errorMessage.str());
748 return tcu::TestStatus::pass("BufferView test");
751 tcu::TestStatus BufferViewTestInstance::iterate (void)
753 const DeviceInterface& vk = m_context.getDeviceInterface();
754 const VkDevice vkDevice = m_context.getDevice();
755 const VkQueue queue = m_context.getUniversalQueue();
756 const VkSubmitInfo submitInfo =
758 VK_STRUCTURE_TYPE_SUBMIT_INFO,
761 (const VkSemaphore*)DE_NULL,
762 (const VkPipelineStageFlags*)DE_NULL,
766 (const VkSemaphore*)DE_NULL,
769 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
770 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
771 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
773 tcu::TestStatus testStatus = checkResult(1);
774 if (testStatus.getCode() != QP_TEST_RESULT_PASS)
777 // Generate and bind another buffer
778 std::vector<deUint32> uniformData;
779 const VkDeviceSize uniformSize = m_testCase.bufferSize * sizeof(deUint32);
780 const deInt8 factor = 2;
782 generateBuffer(uniformData, m_testCase.bufferSize, factor);
783 deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
784 flushMappedMemoryRange(vk, vkDevice, m_uniformBufferAlloc->getMemory(), m_uniformBufferAlloc->getOffset(), uniformSize);
786 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
787 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
788 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
790 return checkResult(factor);
793 class BufferViewTestCase : public vkt::TestCase
796 BufferViewTestCase (tcu::TestContext& testCtx,
797 const std::string& name,
798 const std::string& description,
799 BufferViewCaseParams bufferViewTestInfo)
800 : vkt::TestCase (testCtx, name, description)
801 , m_bufferViewTestInfo (bufferViewTestInfo)
804 virtual ~BufferViewTestCase (void)
806 virtual void initPrograms (SourceCollections& programCollection) const;
808 virtual TestInstance* createInstance (Context& context) const
810 return new BufferViewTestInstance(context, m_bufferViewTestInfo);
813 BufferViewCaseParams m_bufferViewTestInfo;
816 void BufferViewTestCase::initPrograms (SourceCollections& programCollection) const
818 programCollection.glslSources.add("vert") << glu::VertexSource(
820 "layout (location = 0) in highp vec4 a_position;\n"
823 " gl_Position = a_position;\n"
827 programCollection.glslSources.add("frag") << glu::FragmentSource(
829 "#extension GL_EXT_texture_buffer : enable\n"
830 "layout (set=0, binding=0) uniform highp usamplerBuffer u_buffer;\n"
831 "layout (location = 0) out highp uint o_color;\n"
834 " o_color = texelFetch(u_buffer, int(gl_FragCoord.x)).x;\n"
840 tcu::TestCaseGroup* createBufferViewAccessTests (tcu::TestContext& testCtx)
842 const char* const bufferTexts[ALLOCATION_KIND_LAST] =
844 "buffer_suballocated",
845 "buffer_dedicated_alloc"
848 const char* const imageTexts[ALLOCATION_KIND_LAST] =
850 "image_suballocated",
851 "image_dedicated_alloc"
854 de::MovePtr<tcu::TestCaseGroup> bufferViewTests (new tcu::TestCaseGroup(testCtx, "access", "BufferView Access Tests"));
855 de::MovePtr<tcu::TestCaseGroup> bufferViewAllocationGroupTests[] =
857 de::MovePtr<tcu::TestCaseGroup>(new tcu::TestCaseGroup(testCtx, "suballocation", "BufferView Access Tests for Suballocated Objects")),
858 de::MovePtr<tcu::TestCaseGroup>(new tcu::TestCaseGroup(testCtx, "dedicated_alloc", "BufferView Access Tests for Dedicatedly Allocated Objects"))
861 for (deUint32 buffersAllocationNdx = 0u; buffersAllocationNdx < ALLOCATION_KIND_LAST; ++buffersAllocationNdx)
862 for (deUint32 imageAllocationNdx = 0u; imageAllocationNdx < ALLOCATION_KIND_LAST; ++imageAllocationNdx)
864 const deUint32 testCaseGroupNdx = (buffersAllocationNdx == 0u && imageAllocationNdx == 0u) ? 0u : 1u;
865 de::MovePtr<tcu::TestCaseGroup>&
866 currentTestsGroup = bufferViewAllocationGroupTests[testCaseGroupNdx];
868 const BufferViewCaseParams info =
870 512, // deUint32 bufferSize
871 512, // deUint32 bufferViewSize
872 0, // deUint32 elementOffset
873 static_cast<AllocationKind>(buffersAllocationNdx),
874 static_cast<AllocationKind>(imageAllocationNdx)
876 std::ostringstream name;
877 name << "buffer_view_memory_test_complete";
878 if (testCaseGroupNdx != 0)
879 name << "_with_" << bufferTexts[buffersAllocationNdx] << "_" << imageTexts[imageAllocationNdx];
880 std::ostringstream description;
881 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
882 currentTestsGroup->addChild(new BufferViewTestCase(testCtx, name.str(), description.str(), info));
886 const BufferViewCaseParams info =
888 4096, // deUint32 bufferSize
889 512, // deUint32 bufferViewSize
890 0, // deUint32 elementOffset
891 static_cast<AllocationKind>(buffersAllocationNdx),
892 static_cast<AllocationKind>(imageAllocationNdx)
894 std::ostringstream name;
895 name << "buffer_view_memory_test_partial_offset0";
896 if (testCaseGroupNdx != 0)
897 name << "_with_" << bufferTexts[buffersAllocationNdx] << "_" << imageTexts[imageAllocationNdx];
898 std::ostringstream description;
899 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
900 currentTestsGroup->addChild(new BufferViewTestCase(testCtx, name.str(), description.str(), info));
904 const BufferViewCaseParams info =
906 4096, // deUint32 bufferSize
907 512, // deUint32 bufferViewSize
908 128, // deUint32 elementOffset
909 static_cast<AllocationKind>(buffersAllocationNdx),
910 static_cast<AllocationKind>(imageAllocationNdx)
912 std::ostringstream name;
913 name << "buffer_view_memory_test_partial_offset1";
914 if (testCaseGroupNdx != 0)
915 name << "_with_" << bufferTexts[buffersAllocationNdx] << "_" << imageTexts[imageAllocationNdx];
916 std::ostringstream description;
917 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
918 currentTestsGroup->addChild(new BufferViewTestCase(testCtx, name.str(), description.str(), info));
922 for (deUint32 subgroupNdx = 0u; subgroupNdx < DE_LENGTH_OF_ARRAY(bufferViewAllocationGroupTests); ++subgroupNdx)
924 bufferViewTests->addChild(bufferViewAllocationGroupTests[subgroupNdx].release());
926 return bufferViewTests.release();