1 #ifndef _VKTPIPELINESPECCONSTANTUTIL_HPP
2 #define _VKTPIPELINESPECCONSTANTUTIL_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2016 The Khronos Group Inc.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Pipeline specialization constants test utilities
24 *//*--------------------------------------------------------------------*/
28 #include "vkPrograms.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkRefUtil.hpp"
31 #include "vkQueryUtil.hpp"
41 Buffer (const vk::DeviceInterface& vk,
42 const vk::VkDevice device,
43 vk::Allocator& allocator,
44 const vk::VkBufferCreateInfo& bufferCreateInfo,
45 const vk::MemoryRequirement memoryRequirement)
47 : m_buffer (createBuffer(vk, device, &bufferCreateInfo))
48 , m_allocation (allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement))
50 VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
53 const vk::VkBuffer& get (void) const { return *m_buffer; }
54 const vk::VkBuffer& operator* (void) const { return get(); }
55 vk::Allocation& getAllocation (void) const { return *m_allocation; }
58 const vk::Unique<vk::VkBuffer> m_buffer;
59 const de::UniquePtr<vk::Allocation> m_allocation;
62 Buffer (const Buffer&);
63 Buffer& operator= (const Buffer&);
69 Image (const vk::DeviceInterface& vk,
70 const vk::VkDevice device,
71 vk::Allocator& allocator,
72 const vk::VkImageCreateInfo& imageCreateInfo,
73 const vk::MemoryRequirement memoryRequirement)
75 : m_image (createImage(vk, device, &imageCreateInfo))
76 , m_allocation (allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement))
78 VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
81 const vk::VkImage& get (void) const { return *m_image; }
82 const vk::VkImage& operator* (void) const { return get(); }
83 vk::Allocation& getAllocation (void) const { return *m_allocation; }
86 const vk::Unique<vk::VkImage> m_image;
87 const de::UniquePtr<vk::Allocation> m_allocation;
91 Image& operator= (const Image&);
94 class GraphicsPipelineBuilder
97 GraphicsPipelineBuilder (void) : m_renderSize (16, 16)
98 , m_shaderStageFlags (0u) {}
100 GraphicsPipelineBuilder& setRenderSize (const tcu::IVec2& size) { m_renderSize = size; return *this; }
101 GraphicsPipelineBuilder& setShader (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo);
102 vk::Move<vk::VkPipeline> build (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
105 tcu::IVec2 m_renderSize;
106 vk::Move<vk::VkShaderModule> m_vertexShaderModule;
107 vk::Move<vk::VkShaderModule> m_fragmentShaderModule;
108 vk::Move<vk::VkShaderModule> m_geometryShaderModule;
109 vk::Move<vk::VkShaderModule> m_tessControlShaderModule;
110 vk::Move<vk::VkShaderModule> m_tessEvaluationShaderModule;
111 std::vector<vk::VkPipelineShaderStageCreateInfo> m_shaderStages;
112 vk::VkShaderStageFlags m_shaderStageFlags;
114 GraphicsPipelineBuilder (const GraphicsPipelineBuilder&); // "deleted"
115 GraphicsPipelineBuilder& operator= (const GraphicsPipelineBuilder&);
120 FEATURE_TESSELLATION_SHADER = 1u << 0,
121 FEATURE_GEOMETRY_SHADER = 1u << 1,
122 FEATURE_SHADER_FLOAT_64 = 1u << 2,
123 FEATURE_VERTEX_PIPELINE_STORES_AND_ATOMICS = 1u << 3,
124 FEATURE_FRAGMENT_STORES_AND_ATOMICS = 1u << 4,
126 typedef deUint32 FeatureFlags;
128 vk::VkBufferCreateInfo makeBufferCreateInfo (const vk::VkDeviceSize bufferSize, const vk::VkBufferUsageFlags usage);
129 vk::VkImageCreateInfo makeImageCreateInfo (const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage);
130 vk::Move<vk::VkCommandPool> makeCommandPool (const vk::DeviceInterface& vk, const vk::VkDevice device, const deUint32 queueFamilyIndex);
131 vk::Move<vk::VkCommandBuffer> makeCommandBuffer (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkCommandPool commandPool);
132 vk::Move<vk::VkDescriptorSet> makeDescriptorSet (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorPool descriptorPool, const vk::VkDescriptorSetLayout setLayout);
133 vk::Move<vk::VkPipelineLayout> makePipelineLayout (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkDescriptorSetLayout descriptorSetLayout);
134 vk::Move<vk::VkPipeline> makeComputePipeline (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkShaderModule shaderModule, const vk::VkSpecializationInfo* specInfo);
135 vk::Move<vk::VkRenderPass> makeRenderPass (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkFormat colorFormat);
136 vk::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);
137 vk::Move<vk::VkImageView> makeImageView (const vk::DeviceInterface& vk, const vk::VkDevice vkDevice, const vk::VkImage image, const vk::VkImageViewType viewType, const vk::VkFormat format);
138 vk::VkBufferMemoryBarrier makeBufferMemoryBarrier (const vk::VkAccessFlags srcAccessMask, const vk::VkAccessFlags dstAccessMask, const vk::VkBuffer buffer, const vk::VkDeviceSize offset, const vk::VkDeviceSize bufferSizeBytes);
139 vk::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);
140 void beginCommandBuffer (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
141 void endCommandBuffer (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
142 void submitCommandsAndWait (const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkQueue queue, const vk::VkCommandBuffer commandBuffer);
143 void 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);
144 void endRenderPass (const vk::DeviceInterface& vk, const vk::VkCommandBuffer commandBuffer);
145 void requireFeatures (const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice, const FeatureFlags flags);
147 // Ugly, brute-force replacement for the initializer list
150 std::vector<T> makeVector (const T& o1)
159 std::vector<T> makeVector (const T& o1, const T& o2)
169 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3)
180 std::vector<T> makeVector (const T& o1, const T& o2, const T& o3, const T& o4)
194 #endif // _VKTPIPELINESPECCONSTANTUTIL_HPP