1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 The Khronos Group Inc.
6 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and/or associated documentation files (the
10 * "Materials"), to deal in the Materials without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Materials, and to
13 * permit persons to whom the Materials are furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice(s) and this permission notice shall be included
17 * in all copies or substantial portions of the Materials.
19 * The Materials are Confidential Information as defined by the
20 * Khronos Membership Agreement until designated non-confidential by Khronos,
21 * at which point this condition clause shall be removed.
23 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
33 * \brief Vulkan Buffer View Memory Tests
34 *//*--------------------------------------------------------------------*/
36 #include "vktApiBufferViewAccessTests.hpp"
38 #include "deStringUtil.hpp"
39 #include "deUniquePtr.hpp"
40 #include "vktTestCase.hpp"
41 #include "vktTestCaseUtil.hpp"
42 #include "vkImageUtil.hpp"
43 #include "vkMemUtil.hpp"
44 #include "vkPrograms.hpp"
45 #include "vkQueryUtil.hpp"
47 #include "vkRefUtil.hpp"
48 #include "vkTypeUtil.hpp"
49 #include "tcuImageCompare.hpp"
50 #include "tcuTexture.hpp"
51 #include "tcuTextureUtil.hpp"
64 struct BufferViewCaseParams
67 deUint32 bufferViewSize;
68 deUint32 elementOffset;
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 = 1);
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, deUint32 bufferSize, deInt8 factor = 1)
126 for (deUint32 i = 0; i < bufferSize; ++i)
127 uniformData.push_back(factor * i);
130 void BufferViewTestInstance::createQuad (void)
132 tcu::Vec4 a(-1.0, -1.0, 0.0, 1.0);
133 tcu::Vec4 b(1.0, -1.0, 0.0, 1.0);
134 tcu::Vec4 c(1.0, 1.0, 0.0, 1.0);
135 tcu::Vec4 d(-1.0, 1.0, 0.0, 1.0);
138 m_vertices.push_back(a);
139 m_vertices.push_back(c);
140 m_vertices.push_back(b);
143 m_vertices.push_back(c);
144 m_vertices.push_back(a);
145 m_vertices.push_back(d);
148 BufferViewTestInstance::~BufferViewTestInstance (void)
152 BufferViewTestInstance::BufferViewTestInstance (Context& context, BufferViewCaseParams testCase)
153 : vkt::TestInstance (context)
154 , m_testCase (testCase)
155 , m_renderSize (testCase.bufferViewSize, testCase.bufferViewSize)
156 , m_colorFormat (VK_FORMAT_R32_UINT)
157 , m_pixelDataSize (m_renderSize.x() * m_renderSize.y() * mapVkFormat(m_colorFormat).getPixelSize())
159 const DeviceInterface& vk = context.getDeviceInterface();
160 const VkDevice vkDevice = context.getDevice();
161 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
162 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(context.getInstanceInterface(), context.getPhysicalDevice()));
163 const VkComponentMapping channelMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
165 // Create color image
167 const VkImageCreateInfo colorImageParams =
169 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
170 DE_NULL, // const void* pNext;
171 0u, // VkImageCreateFlags flags;
172 VK_IMAGE_TYPE_2D, // VkImageType imageType;
173 m_colorFormat, // VkFormat format;
174 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y(), 1u }, // VkExtent3D extent;
175 1u, // deUint32 mipLevels;
176 1u, // deUint32 arraySize;
177 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
178 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
179 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
180 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
181 1u, // deUint32 queueFamilyCount;
182 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
183 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
186 m_colorImage = createImage(vk, vkDevice, &colorImageParams);
188 // Allocate and bind color image memory
189 m_colorImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_colorImage), MemoryRequirement::Any);
190 VK_CHECK(vk.bindImageMemory(vkDevice, *m_colorImage, m_colorImageAlloc->getMemory(), m_colorImageAlloc->getOffset()));
193 // Create destination buffer
195 const VkBufferCreateInfo bufferParams =
197 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
198 DE_NULL, // const void* pNext;
199 0u, // VkBufferCreateFlags flags;
200 m_pixelDataSize, // VkDeviceSize size;
201 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
202 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
203 0u, // deUint32 queueFamilyCount;
204 DE_NULL, // const deUint32* pQueueFamilyIndices;
207 m_resultBuffer = createBuffer(vk, vkDevice, &bufferParams);
208 m_resultBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_resultBuffer), MemoryRequirement::HostVisible);
210 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_resultBuffer, m_resultBufferAlloc->getMemory(), m_resultBufferAlloc->getOffset()));
213 // Create color attachment view
215 const VkImageViewCreateInfo colorAttachmentViewParams =
217 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
218 DE_NULL, // const void* pNext;
219 0u, // VkImageViewCreateFlags flags;
220 *m_colorImage, // VkImage image;
221 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
222 m_colorFormat, // VkFormat format;
223 channelMappingRGBA, // VkChannelMapping channels;
224 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }, // VkImageSubresourceRange subresourceRange;
227 m_colorAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
230 // Create render pass
232 const VkAttachmentDescription colorAttachmentDescription =
234 0u, // VkAttachmentDescriptionFlags flags;
235 m_colorFormat, // VkFormat format;
236 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
237 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
238 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
239 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
240 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
241 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
242 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout finalLayout;
245 const VkAttachmentReference colorAttachmentReference =
247 0u, // deUint32 attachment;
248 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
251 const VkSubpassDescription subpassDescription =
253 0u, // VkSubpassDescriptionFlags flags;
254 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
255 0u, // deUint32 inputCount;
256 DE_NULL, // const VkAttachmentReference* pInputAttachments;
257 1u, // deUint32 colorCount;
258 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
259 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
260 DE_NULL, // VkAttachmentReference depthStencilAttachment;
261 0u, // deUint32 preserveCount;
262 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
265 const VkRenderPassCreateInfo renderPassParams =
267 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
268 DE_NULL, // const void* pNext;
269 (VkRenderPassCreateFlags)0,
270 1u, // deUint32 attachmentCount;
271 &colorAttachmentDescription, // const VkAttachmentDescription* pAttachments;
272 1u, // deUint32 subpassCount;
273 &subpassDescription, // const VkSubpassDescription* pSubpasses;
274 0u, // deUint32 dependencyCount;
275 DE_NULL // const VkSubpassDependency* pDependencies;
278 m_renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
281 // Create framebuffer
283 const VkImageView attachmentBindInfos[1] =
285 *m_colorAttachmentView,
288 const VkFramebufferCreateInfo framebufferParams =
290 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
291 DE_NULL, // const void* pNext;
292 (VkFramebufferCreateFlags)0,
293 *m_renderPass, // VkRenderPass renderPass;
294 1u, // deUint32 attachmentCount;
295 attachmentBindInfos, // const VkImageView* pAttachments;
296 (deUint32)m_renderSize.x(), // deUint32 width;
297 (deUint32)m_renderSize.y(), // deUint32 height;
298 1u // deUint32 layers;
301 m_framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
304 // Create descriptors
306 const VkDescriptorSetLayoutBinding layoutBindings[1] =
309 0u, // deUint32 binding;
310 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType descriptorType;
311 1u, // deUint32 arraySize;
312 VK_SHADER_STAGE_ALL, // VkShaderStageFlags stageFlags;
313 DE_NULL // const VkSampler* pImmutableSamplers;
317 const VkDescriptorSetLayoutCreateInfo descriptorLayoutParams =
319 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, // VkStructureType sType;
320 DE_NULL, // cost void* pNexŧ;
321 (VkDescriptorSetLayoutCreateFlags)0,
322 DE_LENGTH_OF_ARRAY(layoutBindings), // deUint32 count;
323 layoutBindings // const VkDescriptorSetLayoutBinding pBinding;
326 m_descriptorSetLayout = createDescriptorSetLayout(vk, vkDevice, &descriptorLayoutParams);
329 std::vector<deUint32> uniformData;
330 generateBuffer(uniformData, testCase.bufferSize);
332 const VkDeviceSize uniformSize = testCase.bufferSize * sizeof(deUint32);
333 const VkBufferCreateInfo uniformBufferParams =
335 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
336 DE_NULL, // const void* pNext;
337 0u, // VkBufferCreateFlags flags; <-- TODO: 0u?
338 uniformSize, // VkDeviceSize size;
339 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, // VkBufferUsageFlags usage;
340 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
341 1u, // deUint32 queueFamilyIndexCount;
342 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
345 m_uniformBuffer = createBuffer(vk, vkDevice, &uniformBufferParams);
346 m_uniformBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_uniformBuffer), MemoryRequirement::HostVisible);
348 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_uniformBuffer, m_uniformBufferAlloc->getMemory(), 0));
349 deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
351 const VkBufferViewCreateInfo viewInfo =
353 VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType;
354 DE_NULL, // void* pNext;
355 (VkBufferViewCreateFlags)0,
356 *m_uniformBuffer, // VkBuffer buffer;
357 m_colorFormat, // VkFormat format;
358 m_testCase.elementOffset * sizeof(deUint32), // VkDeviceSize offset;
359 m_testCase.bufferViewSize * sizeof(deUint32) // VkDeviceSize range;
362 m_uniformBufferView = createBufferView(vk, vkDevice, &viewInfo);
364 const VkDescriptorPoolSize descriptorTypes[1] =
367 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType type;
372 const VkDescriptorPoolCreateInfo descriptorPoolParams =
374 VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // VkStructureType sType;
375 DE_NULL, // void* pNext;
376 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, // VkDescriptorPoolCreateFlags flags;
377 1u, // uint32_t maxSets;
378 DE_LENGTH_OF_ARRAY(descriptorTypes), // deUint32 count;
379 descriptorTypes // const VkDescriptorTypeCount* pTypeCount
382 m_descriptorPool = createDescriptorPool(vk, vkDevice, &descriptorPoolParams);
384 const VkDescriptorSetAllocateInfo descriptorSetParams =
386 VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
390 &m_descriptorSetLayout.get(),
392 m_descriptorSet = allocateDescriptorSet(vk, vkDevice, &descriptorSetParams);
394 const VkWriteDescriptorSet writeDescritporSets[] =
397 VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, // VkStructureType sType;
398 DE_NULL, // const void* pNext;
399 *m_descriptorSet, // VkDescriptorSet destSet;
400 0, // deUint32 destBinding;
401 0, // deUint32 destArrayElement;
402 1u, // deUint32 count;
403 VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, // VkDescriptorType descriptorType;
404 (const VkDescriptorImageInfo*)DE_NULL,
405 (const VkDescriptorBufferInfo*)DE_NULL,
406 &m_uniformBufferView.get(),
410 vk.updateDescriptorSets(vkDevice, DE_LENGTH_OF_ARRAY(writeDescritporSets), writeDescritporSets, 0u, DE_NULL);
413 // Create pipeline layout
415 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
417 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
418 DE_NULL, // const void* pNext;
419 (VkPipelineLayoutCreateFlags)0,
420 1u, // deUint32 descriptorSetCount;
421 &*m_descriptorSetLayout, // const VkDescriptorSetLayout* pSetLayouts;
422 0u, // deUint32 pushConstantRangeCount;
423 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
426 m_pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
431 m_vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
432 m_fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
438 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
441 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
442 DE_NULL, // const void* pNext;
443 (VkPipelineShaderStageCreateFlags)0,
444 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStage stage;
445 *m_vertexShaderModule, // VkShader shader;
447 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
450 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
451 DE_NULL, // const void* pNext;
452 (VkPipelineShaderStageCreateFlags)0,
453 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStage stage;
454 *m_fragmentShaderModule, // VkShader shader;
456 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
460 const VkVertexInputBindingDescription vertexInputBindingDescription =
462 0u, // deUint32 binding;
463 sizeof(tcu::Vec4), // deUint32 strideInBytes;
464 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputStepRate stepRate;
467 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[1] =
470 0u, // deUint32 location;
471 0u, // deUint32 binding;
472 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
473 0u // deUint32 offsetInBytes;
477 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
479 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
480 DE_NULL, // const void* pNext;
481 (VkPipelineVertexInputStateCreateFlags)0,
482 1u, // deUint32 bindingCount;
483 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
484 1u, // deUint32 attributeCount;
485 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
488 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
490 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
491 DE_NULL, // const void* pNext;
492 (VkPipelineInputAssemblyStateCreateFlags)0,
493 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
494 false // VkBool32 primitiveRestartEnable;
497 const VkViewport viewport =
499 0.0f, // float originX;
500 0.0f, // float originY;
501 (float)m_renderSize.x(), // float width;
502 (float)m_renderSize.y(), // float height;
503 0.0f, // float minDepth;
504 1.0f // float maxDepth;
506 const VkRect2D scissor =
508 { 0, 0 }, // VkOffset2D offset;
509 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() } // VkExtent2D extent;
511 const VkPipelineViewportStateCreateInfo viewportStateParams =
513 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
514 DE_NULL, // const void* pNext;
515 (VkPipelineViewportStateCreateFlags)0,
516 1u, // deUint32 viewportCount;
517 &viewport, // const VkViewport* pViewports;
518 1u, // deUint32 scissorCount;
519 &scissor // const VkRect2D* pScissors;
522 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
524 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
525 DE_NULL, // const void* pNext;
526 (VkPipelineRasterizationStateCreateFlags)0,
527 false, // VkBool32 depthClipEnable;
528 false, // VkBool32 rasterizerDiscardEnable;
529 VK_POLYGON_MODE_FILL, // VkFillMode fillMode;
530 VK_CULL_MODE_NONE, // VkCullMode cullMode;
531 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
532 VK_FALSE, // VkBool32 depthBiasEnable;
533 0.0f, // float depthBias;
534 0.0f, // float depthBiasClamp;
535 0.0f, // float slopeScaledDepthBias;
536 1.0f, // float lineWidth;
539 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
541 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
542 DE_NULL, // const void* pNext;
543 0u, // VkPipelineMultisampleStateCreateFlags flags;
544 VK_SAMPLE_COUNT_1_BIT, // VkSampleCountFlagBits rasterizationSamples;
545 VK_FALSE, // VkBool32 sampleShadingEnable;
546 0.0f, // float minSampleShading;
547 DE_NULL, // const VkSampleMask* pSampleMask;
548 VK_FALSE, // VkBool32 alphaToCoverageEnable;
549 VK_FALSE // VkBool32 alphaToOneEnable;
552 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
554 false, // VkBool32 blendEnable;
555 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
556 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
557 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
558 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
559 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
560 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
561 (VK_COLOR_COMPONENT_R_BIT |
562 VK_COLOR_COMPONENT_G_BIT |
563 VK_COLOR_COMPONENT_B_BIT |
564 VK_COLOR_COMPONENT_A_BIT) // VkChannelFlags channelWriteMask;
567 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
569 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
570 DE_NULL, // const void* pNext;
571 (VkPipelineColorBlendStateCreateFlags)0,
572 false, // VkBool32 logicOpEnable;
573 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
574 1u, // deUint32 attachmentCount;
575 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
576 { 0.0f, 0.0f, 0.0f, 0.0f }, // float blendConst[4];
579 const VkPipelineDynamicStateCreateInfo dynamicStateParams =
581 VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, // VkStructureType sType;
582 DE_NULL, // const void* pNext;
583 (VkPipelineDynamicStateCreateFlags)0,
584 0u, // deUint32 dynamicStateCount;
585 DE_NULL // const VkDynamicState* pDynamicStates;
588 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
590 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
591 DE_NULL, // const void* pNext;
592 0u, // VkPipelineCreateFlags flags;
593 2u, // deUint32 stageCount;
594 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
595 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
596 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
597 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
598 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
599 &rasterStateParams, // const VkPipelineRasterStateCreateInfo* pRasterState;
600 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
601 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
602 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
603 &dynamicStateParams, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
604 *m_pipelineLayout, // VkPipelineLayout layout;
605 *m_renderPass, // VkRenderPass renderPass;
606 0u, // deUint32 subpass;
607 0u, // VkPipeline basePipelineHandle;
608 0u // deInt32 basePipelineIndex;
611 m_graphicsPipelines = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
614 // Create vertex buffer
617 const VkDeviceSize vertexDataSize = m_vertices.size() * sizeof(tcu::Vec4);
618 const VkBufferCreateInfo vertexBufferParams =
620 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
621 DE_NULL, // const void* pNext;
622 0u, // VkBufferCreateFlags flags;
623 vertexDataSize, // VkDeviceSize size;
624 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
625 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
626 1u, // deUint32 queueFamilyCount;
627 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
630 m_vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
631 m_vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_vertexBuffer), MemoryRequirement::HostVisible);
633 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_vertexBuffer, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset()));
635 // Load vertices into vertex buffer
636 deMemcpy(m_vertexBufferAlloc->getHostPtr(), m_vertices.data(), (size_t)vertexDataSize);
637 flushMappedMemoryRange(vk, vkDevice, m_vertexBufferAlloc->getMemory(), m_vertexBufferAlloc->getOffset(), vertexDataSize);
640 // Create command pool
642 const VkCommandPoolCreateInfo cmdPoolParams =
644 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
645 DE_NULL, // const void* pNext;
646 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
647 queueFamilyIndex, // deUint32 queueFamilyIndex;
650 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
653 // Create command buffer
655 const VkCommandBufferAllocateInfo cmdBufferParams =
657 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
658 DE_NULL, // const void* pNext;
659 *m_cmdPool, // VkCmdPool cmdPool;
660 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCmdBufferLevel level;
661 1u // deUint32 count;
664 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
666 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
667 DE_NULL, // const void* pNext;
668 0u, // VkCmdBufferOptimizeFlags flags;
669 (const VkCommandBufferInheritanceInfo*)DE_NULL,
672 const VkClearValue clearValue = makeClearValueColorF32(0.0, 0.0, 0.0, 0.0);
674 const VkClearValue attachmentClearValues[1] =
679 const VkRenderPassBeginInfo renderPassBeginInfo =
681 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
682 DE_NULL, // const void* pNext;
683 *m_renderPass, // VkRenderPass renderPass;
684 *m_framebuffer, // VkFramebuffer framebuffer;
687 { (deUint32)m_renderSize.x(), (deUint32)m_renderSize.y() }
688 }, // VkRect2D renderArea;
689 1u, // deUint32 clearValueCount;
690 attachmentClearValues // const VkClearValue* pClearValues;
693 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferParams);
695 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
697 const VkImageMemoryBarrier initialImageBarrier =
699 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
700 DE_NULL, // const void* pNext;
701 0, // VkMemoryOutputFlags outputMask;
702 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryInputFlags inputMask;
703 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
704 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
705 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
706 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
707 *m_colorImage, // VkImage image;
708 { // VkImageSubresourceRange subresourceRange;
709 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
710 0u, // deUint32 baseMipLevel;
711 1u, // deUint32 mipLevels;
712 0u, // deUint32 baseArraySlice;
713 1u // deUint32 arraySize;
717 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);
719 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
721 const VkDeviceSize vertexBufferOffset[1] = { 0 };
723 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_graphicsPipelines);
724 vk.cmdBindDescriptorSets(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *m_pipelineLayout, 0u, 1, &*m_descriptorSet, 0u, DE_NULL);
725 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &m_vertexBuffer.get(), vertexBufferOffset);
726 vk.cmdDraw(*m_cmdBuffer, (deUint32)m_vertices.size(), 1, 0, 0);
727 vk.cmdEndRenderPass(*m_cmdBuffer);
729 const VkImageMemoryBarrier imageBarrier =
731 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
732 DE_NULL, // const void* pNext;
733 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkMemoryOutputFlags outputMask;
734 VK_ACCESS_TRANSFER_READ_BIT, // VkMemoryInputFlags inputMask;
735 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
736 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
737 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
738 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
739 *m_colorImage, // VkImage image;
740 { // VkImageSubresourceRange subresourceRange;
741 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
742 0u, // deUint32 baseMipLevel;
743 1u, // deUint32 mipLevels;
744 0u, // deUint32 baseArraySlice;
745 1u // deUint32 arraySize;
749 const VkBufferMemoryBarrier bufferBarrier =
751 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
752 DE_NULL, // const void* pNext;
753 VK_ACCESS_TRANSFER_WRITE_BIT, // VkMemoryOutputFlags outputMask;
754 VK_ACCESS_HOST_READ_BIT, // VkMemoryInputFlags inputMask;
755 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
756 VK_QUEUE_FAMILY_IGNORED, // deUint32 destQueueFamilyIndex;
757 *m_resultBuffer, // VkBuffer buffer;
758 0u, // VkDeviceSize offset;
759 m_pixelDataSize // VkDeviceSize size;
762 const VkBufferImageCopy copyRegion =
764 0u, // VkDeviceSize bufferOffset;
765 (deUint32)m_renderSize.x(), // deUint32 bufferRowLength;
766 (deUint32)m_renderSize.y(), // deUint32 bufferImageHeight;
767 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, 1u }, // VkImageSubresourceCopy imageSubresource;
768 { 0, 0, 0 }, // VkOffset3D imageOffset;
770 (deUint32)m_renderSize.x(),
771 (deUint32)m_renderSize.y(),
773 } // VkExtent3D imageExtent;
776 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);
777 vk.cmdCopyImageToBuffer(*m_cmdBuffer, *m_colorImage, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *m_resultBuffer, 1, ©Region);
778 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);
780 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
785 const VkFenceCreateInfo fenceParams =
787 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
788 DE_NULL, // const void* pNext;
789 0u // VkFenceCreateFlags flags;
792 m_fence = createFence(vk, vkDevice, &fenceParams);
796 tcu::TestStatus BufferViewTestInstance::checkResult (deInt8 factor)
798 const DeviceInterface& vk = m_context.getDeviceInterface();
799 const VkDevice vkDevice = m_context.getDevice();
800 const tcu::TextureFormat tcuFormat = mapVkFormat(m_colorFormat);
801 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(tcuFormat, m_renderSize.x(), m_renderSize.y()));
803 invalidateMappedMemoryRange(vk, vkDevice, m_resultBufferAlloc->getMemory(), m_resultBufferAlloc->getOffset(), m_pixelDataSize);
804 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_resultBufferAlloc->getHostPtr()));
806 tcu::ConstPixelBufferAccess pixelBuffer = resultLevel->getAccess();
807 for (deInt32 i = 0; i < (deInt32) m_renderSize.x(); ++i)
809 tcu::IVec4 pixel = pixelBuffer.getPixelInt(i, i);
810 deInt32 expected = factor * (m_testCase.elementOffset + i);
811 deInt32 actual = pixel[0];
812 if (expected != actual)
814 std::ostringstream errorMessage;
815 errorMessage << "BufferView test failed. expected: " << expected << " actual: " << actual;
816 return tcu::TestStatus::fail(errorMessage.str());
820 return tcu::TestStatus::pass("BufferView test");
823 tcu::TestStatus BufferViewTestInstance::iterate (void)
825 const DeviceInterface& vk = m_context.getDeviceInterface();
826 const VkDevice vkDevice = m_context.getDevice();
827 const VkQueue queue = m_context.getUniversalQueue();
828 const VkSubmitInfo submitInfo =
830 VK_STRUCTURE_TYPE_SUBMIT_INFO,
833 (const VkSemaphore*)DE_NULL,
834 (const VkPipelineStageFlags*)DE_NULL,
838 (const VkSemaphore*)DE_NULL,
841 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
842 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
843 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
845 tcu::TestStatus testStatus = checkResult();
846 if (testStatus.getCode() != QP_TEST_RESULT_PASS)
851 // Generate and bind another buffer
852 std::vector<deUint32> uniformData;
853 const VkDeviceSize uniformSize = m_testCase.bufferSize * sizeof(deUint32);
854 const deInt8 factor = 2;
856 generateBuffer(uniformData, m_testCase.bufferSize, factor);
857 deMemcpy(m_uniformBufferAlloc->getHostPtr(), uniformData.data(), (size_t)uniformSize);
859 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
860 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
861 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
863 return checkResult(factor);
866 class BufferViewTestCase : public vkt::TestCase
869 BufferViewTestCase (tcu::TestContext& testCtx,
870 const std::string& name,
871 const std::string& description,
872 BufferViewCaseParams bufferViewTestInfo)
873 : vkt::TestCase (testCtx, name, description)
874 , m_bufferViewTestInfo (bufferViewTestInfo)
877 virtual ~BufferViewTestCase (void) {}
878 virtual void initPrograms (SourceCollections& programCollection) const;
880 virtual TestInstance* createInstance (Context& context) const
882 return new BufferViewTestInstance(context, m_bufferViewTestInfo);
885 BufferViewCaseParams m_bufferViewTestInfo;
888 void BufferViewTestCase::initPrograms (SourceCollections& programCollection) const
890 programCollection.glslSources.add("vert") << glu::VertexSource(
892 "layout (location = 0) in highp vec4 a_position;\n"
895 " gl_Position = a_position;\n"
899 programCollection.glslSources.add("frag") << glu::FragmentSource(
901 "#extension GL_EXT_texture_buffer : enable\n"
902 "layout (set=0, binding=0) uniform highp usamplerBuffer u_buffer;\n"
903 "layout (location = 0) out highp uint o_color;\n"
906 " o_color = texelFetch(u_buffer, int(gl_FragCoord.x)).x;\n"
912 tcu::TestCaseGroup* createBufferViewAccessTests (tcu::TestContext& testCtx)
914 de::MovePtr<tcu::TestCaseGroup> bufferViewTests (new tcu::TestCaseGroup(testCtx, "access", "BufferView Access Tests"));
917 BufferViewCaseParams info =
919 512, // deUint32 bufferSize
920 512, // deUint32 bufferViewSize
921 0, // deUint32 elementOffset
923 std::ostringstream description;
924 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
925 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_complete", description.str(), info));
929 BufferViewCaseParams info =
931 4096, // deUint32 bufferSize
932 512, // deUint32 bufferViewSize
933 0, // deUint32 elementOffset
935 std::ostringstream description;
936 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
937 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_partial_offset0", description.str(), info));
941 BufferViewCaseParams info =
943 4096, // deUint32 bufferSize
944 512, // deUint32 bufferViewSize
945 128, // deUint32 elementOffset
947 std::ostringstream description;
948 description << "bufferSize: " << info.bufferSize << " bufferViewSize: " << info.bufferViewSize << " bufferView element offset: " << info.elementOffset;
949 bufferViewTests->addChild(new BufferViewTestCase(testCtx, "buffer_view_memory_test_partial_offset1", description.str(), info));
952 return bufferViewTests.release();