1#ifndef _VKTGEOMETRYTESTSUTIL_HPP 2#define _VKTGEOMETRYTESTSUTIL_HPP 3/*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2014 The Android Open Source Project 8 * Copyright (c) 2016 The Khronos Group Inc. 9 * 10 * Licensed under the Apache License, Version 2.0 (the "License"); 11 * you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software 17 * distributed under the License is distributed on an "AS IS" BASIS, 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 * See the License for the specific language governing permissions and 20 * limitations under the License. 21 * 22 *//*! 23 * \file 24 * \brief Geometry Utilities 25 *//*--------------------------------------------------------------------*/ 26 27#include "vkDefs.hpp" 28#include "vkMemUtil.hpp" 29#include "vkRef.hpp" 30#include "vkPrograms.hpp" 31#include "vkRefUtil.hpp" 32#include "vkQueryUtil.hpp" 33#include "vktTestCase.hpp" 34 35#include "tcuVector.hpp" 36 37#include "deStringUtil.hpp" 38#include "deUniquePtr.hpp" 39 40namespace vkt 41{ 42namespace geometry 43{ 44 45struct PrimitiveTestSpec 46{ 47 vk::VkPrimitiveTopology primitiveType; 48 const char* name; 49 vk::VkPrimitiveTopology outputType; 50}; 51 52class Buffer 53{ 54public: 55 Buffer (const vk::DeviceInterface& vk, 56 const vk::VkDevice device, 57 vk::Allocator& allocator, 58 const vk::VkBufferCreateInfo& bufferCreateInfo, 59 const vk::MemoryRequirement memoryRequirement) 60 61 : m_buffer (createBuffer(vk, device, &bufferCreateInfo)) 62 , m_allocation (allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement)) 63 { 64 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset())); 65 } 66 67 const vk::VkBuffer& get (void) const { return *m_buffer; } 68 const vk::VkBuffer& operator* (void) const { return get(); } 69 vk::Allocation& getAllocation (void) const { return *m_allocation; } 70 71private: 72 const vk::Unique<vk::VkBuffer> m_buffer; 73 const de::UniquePtr<vk::Allocation> m_allocation; 74 75 // "deleted" 76 Buffer (const Buffer&); 77 Buffer& operator= (const Buffer&); 78}; 79 80class Image 81{ 82public: 83 Image (const vk::DeviceInterface& vk, 84 const vk::VkDevice device, 85 vk::Allocator& allocator, 86 const vk::VkImageCreateInfo& imageCreateInfo, 87 const vk::MemoryRequirement memoryRequirement) 88 89 : m_image (createImage(vk, device, &imageCreateInfo)) 90 , m_allocation (allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement)) 91 { 92 VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset())); 93 } 94 95 const vk::VkImage& get (void) const { return *m_image; } 96 const vk::VkImage& operator* (void) const { return get(); } 97 vk::Allocation& getAllocation (void) const { return *m_allocation; } 98 99private: 100 const vk::Unique<vk::VkImage> m_image; 101 const de::UniquePtr<vk::Allocation> m_allocation; 102 103 // "deleted" 104 Image (const Image&); 105 Image& operator= (const Image&); 106}; 107 108class GraphicsPipelineBuilder 109{ 110public: 111 GraphicsPipelineBuilder (void) : m_renderSize (0, 0) 112 , m_shaderStageFlags (0u) 113 , m_cullModeFlags (vk::VK_CULL_MODE_NONE) 114 , m_frontFace (vk::VK_FRONT_FACE_COUNTER_CLOCKWISE) 115 , m_patchControlPoints (1u) 116 , m_blendEnable (false) 117 , m_primitiveTopology (vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) {} 118 119 GraphicsPipelineBuilder& setRenderSize (const tcu::IVec2& size) { m_renderSize = size; return *this; } 120 GraphicsPipelineBuilder& setShader (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo); 121 GraphicsPipelineBuilder& setPatchControlPoints (const deUint32 controlPoints) { m_patchControlPoints = controlPoints; return *this; } 122 GraphicsPipelineBuilder& setCullModeFlags (const vk::VkCullModeFlags cullModeFlags) { m_cullModeFlags = cullModeFlags; return *this; } 123 GraphicsPipelineBuilder& setFrontFace (const vk::VkFrontFace frontFace) { m_frontFace = frontFace; return *this; } 124 GraphicsPipelineBuilder& setBlend (const bool enable) { m_blendEnable = enable; return *this; } 125 126 //! Applies only to pipelines without tessellation shaders. 127 GraphicsPipelineBuilder& setPrimitiveTopology (const vk::VkPrimitiveTopology topology) { m_primitiveTopology = topology; return *this; } 128 129 GraphicsPipelineBuilder& addVertexBinding (const vk::VkVertexInputBindingDescription vertexBinding) { m_vertexInputBindings.push_back(vertexBinding); return *this; } 130 GraphicsPipelineBuilder& addVertexAttribute (const vk::VkVertexInputAttributeDescription vertexAttribute) { m_vertexInputAttributes.push_back(vertexAttribute); return *this; } 131 132 //! Basic vertex input configuration (uses biding 0, location 0, etc.) 133 GraphicsPipelineBuilder& setVertexInputSingleAttribute (const vk::VkFormat vertexFormat, const deUint32 stride); 134 135 vk::Move<vk::VkPipeline> build (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass); 136 137private: 138 tcu::IVec2 m_renderSize; 139 vk::Move<vk::VkShaderModule> m_vertexShaderModule; 140 vk::Move<vk::VkShaderModule> m_fragmentShaderModule; 141 vk::Move<vk::VkShaderModule> m_geometryShaderModule; 142 vk::Move<vk::VkShaderModule> m_tessControlShaderModule; 143 vk::Move<vk::VkShaderModule> m_tessEvaluationShaderModule; 144 std::vector<vk::VkPipelineShaderStageCreateInfo> m_shaderStages; 145 std::vector<vk::VkVertexInputBindingDescription> m_vertexInputBindings; 146 std::vector<vk::VkVertexInputAttributeDescription> m_vertexInputAttributes; 147 vk::VkShaderStageFlags m_shaderStageFlags; 148 vk::VkCullModeFlags m_cullModeFlags; 149 vk::VkFrontFace m_frontFace; 150 deUint32 m_patchControlPoints; 151 bool m_blendEnable; 152 vk::VkPrimitiveTopology m_primitiveTopology; 153 154 GraphicsPipelineBuilder (const GraphicsPipelineBuilder&); // "deleted" 155 GraphicsPipelineBuilder& operator= (const GraphicsPipelineBuilder&); 156}; 157 158template<typename T> 159inline std::size_t sizeInBytes (const std::vector<T>& vec) 160{ 161 return vec.size() * sizeof(vec[0]); 162} 163 164std::string inputTypeToGLString (const vk::VkPrimitiveTopology& inputType); 165std::string outputTypeToGLString (const vk::VkPrimitiveTopology& outputType); 166std::size_t calcOutputVertices (const vk::VkPrimitiveTopology& inputType); 167 168vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize, const vk::VkBufferUsageFlags usage); 169vk::VkImageCreateInfo makeImageCreateInfo (const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage, const deUint32 numArrayLayers = 1u); 170vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout); 171vk::Move<vk::VkRenderPass> makeRenderPass (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkFormat colorFormat); 172vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk, const vk::VkDevice vkDevice, const vk::VkImage image, const vk::VkImageViewType viewType, const vk::VkFormat format, const vk::VkImageSubresourceRange subresourceRange); 173vk::VkBufferImageCopy makeBufferImageCopy (const vk::VkExtent3D extent, const vk::VkImageSubresourceLayers subresourceLayers); 174vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorSetLayout descriptorSetLayout = DE_NULL); 175vk::Move<vk::VkFramebuffer> makeFramebuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkRenderPass renderPass, const vk::VkImageView colorAttachment, const deUint32 width, const deUint32 height, const deUint32 layers); 176vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk, const vk::VkDevice device, const deUint32 queueFamilyIndex); 177vk::Move<vk::VkCommandBuffer> makeCommandBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkCommandPool commandPool); 178vk::VkImageMemoryBarrier makeImageMemoryBarrier (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkImageLayout oldLayout, const vk::VkImageLayout newLayout, const vk::VkImage image, const vk::VkImageSubresourceRange subresourceRange); 179vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkBuffer buffer, const vk::VkDeviceSize offset, const vk::VkDeviceSize bufferSizeBytes); 180de::MovePtr<vk::Allocation> bindImage (const vk::DeviceInterface& vk, const vk::VkDevice device, vk::Allocator& allocator, const vk::VkImage image, const vk::MemoryRequirement requirement); 181de::MovePtr<vk::Allocation> bindBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, vk::Allocator& allocator, const vk::VkBuffer buffer, const vk::MemoryRequirement requirement); 182 183void beginRenderPass (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer, const vk::VkRenderPass renderPass, const vk::VkFramebuffer framebuffer, const vk::VkRect2D& renderArea, const tcu::Vec4& clearColor); 184void endRenderPass (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer); 185void beginCommandBuffer (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer); 186void endCommandBuffer (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer); 187void submitCommandsAndWait (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkQueue queue, const vk::VkCommandBuffer commandBuffer); 188 189bool compareWithFileImage (Context& context, const tcu::ConstPixelBufferAccess& resultImage, std::string name); 190 191void zeroBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::Allocation& alloc, const vk::VkDeviceSize size); 192 193void checkGeometryShaderSupport (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice, const int numGeometryShaderInvocations = 0); 194vk::VkBool32 checkPointSize (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice); 195 196inline vk::Move<vk::VkBuffer> makeBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkBufferCreateInfo& createInfo) 197{ 198 return createBuffer(vk, device, &createInfo); 199} 200 201inline vk::Move<vk::VkImage> makeImage (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkImageCreateInfo& createInfo) 202{ 203 return createImage(vk, device, &createInfo); 204} 205 206} //vkt 207} //geometry 208 209#endif // _VKTGEOMETRYTESTSUTIL_HPP 210