• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "vkObjUtil.hpp"
29 #include "vkMemUtil.hpp"
30 #include "vkRef.hpp"
31 #include "vkPrograms.hpp"
32 #include "vkRefUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vktTestCase.hpp"
35 
36 #include "tcuVector.hpp"
37 #include "tcuTexture.hpp"
38 
39 #include "deStringUtil.hpp"
40 #include "deUniquePtr.hpp"
41 
42 namespace vkt
43 {
44 namespace geometry
45 {
46 
47 struct PrimitiveTestSpec
48 {
49 	vk::VkPrimitiveTopology		primitiveType;
50 	const char*					name;
51 	vk::VkPrimitiveTopology		outputType;
52 };
53 
54 class GraphicsPipelineBuilder
55 {
56 public:
GraphicsPipelineBuilder(void)57 								GraphicsPipelineBuilder	(void) : m_renderSize			(0, 0)
58 															   , m_shaderStageFlags		(0u)
59 															   , m_cullModeFlags		(vk::VK_CULL_MODE_NONE)
60 															   , m_frontFace			(vk::VK_FRONT_FACE_COUNTER_CLOCKWISE)
61 															   , m_patchControlPoints	(1u)
62 															   , m_blendEnable			(false)
63 															   , m_primitiveTopology	(vk::VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) {}
64 
setRenderSize(const tcu::IVec2 & size)65 	GraphicsPipelineBuilder&	setRenderSize					(const tcu::IVec2& size) { m_renderSize = size; return *this; }
66 	GraphicsPipelineBuilder&	setShader						(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkShaderStageFlagBits stage, const vk::ProgramBinary& binary, const vk::VkSpecializationInfo* specInfo);
setPatchControlPoints(const deUint32 controlPoints)67 	GraphicsPipelineBuilder&	setPatchControlPoints			(const deUint32 controlPoints) { m_patchControlPoints = controlPoints; return *this; }
setCullModeFlags(const vk::VkCullModeFlags cullModeFlags)68 	GraphicsPipelineBuilder&	setCullModeFlags				(const vk::VkCullModeFlags cullModeFlags) { m_cullModeFlags = cullModeFlags; return *this; }
setFrontFace(const vk::VkFrontFace frontFace)69 	GraphicsPipelineBuilder&	setFrontFace					(const vk::VkFrontFace frontFace) { m_frontFace = frontFace; return *this; }
setBlend(const bool enable)70 	GraphicsPipelineBuilder&	setBlend						(const bool enable) { m_blendEnable = enable; return *this; }
71 
72 	//! Applies only to pipelines without tessellation shaders.
setPrimitiveTopology(const vk::VkPrimitiveTopology topology)73 	GraphicsPipelineBuilder&	setPrimitiveTopology			(const vk::VkPrimitiveTopology topology) { m_primitiveTopology = topology; return *this; }
74 
addVertexBinding(const vk::VkVertexInputBindingDescription vertexBinding)75 	GraphicsPipelineBuilder&	addVertexBinding				(const vk::VkVertexInputBindingDescription vertexBinding) { m_vertexInputBindings.push_back(vertexBinding); return *this; }
addVertexAttribute(const vk::VkVertexInputAttributeDescription vertexAttribute)76 	GraphicsPipelineBuilder&	addVertexAttribute				(const vk::VkVertexInputAttributeDescription vertexAttribute) { m_vertexInputAttributes.push_back(vertexAttribute); return *this; }
77 
78 	//! Basic vertex input configuration (uses biding 0, location 0, etc.)
79 	GraphicsPipelineBuilder&	setVertexInputSingleAttribute	(const vk::VkFormat vertexFormat, const deUint32 stride);
80 
81 	vk::Move<vk::VkPipeline>	build							(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::VkPipelineLayout pipelineLayout, const vk::VkRenderPass renderPass);
82 
83 private:
84 	tcu::IVec2											m_renderSize;
85 	vk::Move<vk::VkShaderModule>						m_vertexShaderModule;
86 	vk::Move<vk::VkShaderModule>						m_fragmentShaderModule;
87 	vk::Move<vk::VkShaderModule>						m_geometryShaderModule;
88 	vk::Move<vk::VkShaderModule>						m_tessControlShaderModule;
89 	vk::Move<vk::VkShaderModule>						m_tessEvaluationShaderModule;
90 	std::vector<vk::VkPipelineShaderStageCreateInfo>	m_shaderStages;
91 	std::vector<vk::VkVertexInputBindingDescription>	m_vertexInputBindings;
92 	std::vector<vk::VkVertexInputAttributeDescription>	m_vertexInputAttributes;
93 	vk::VkShaderStageFlags								m_shaderStageFlags;
94 	vk::VkCullModeFlags									m_cullModeFlags;
95 	vk::VkFrontFace										m_frontFace;
96 	deUint32											m_patchControlPoints;
97 	bool												m_blendEnable;
98 	vk::VkPrimitiveTopology								m_primitiveTopology;
99 
100 	GraphicsPipelineBuilder (const GraphicsPipelineBuilder&); // "deleted"
101 	GraphicsPipelineBuilder& operator= (const GraphicsPipelineBuilder&);
102 };
103 
104 template<typename T>
sizeInBytes(const std::vector<T> & vec)105 inline std::size_t sizeInBytes (const std::vector<T>& vec)
106 {
107 	return vec.size() * sizeof(vec[0]);
108 }
109 
110 std::string						inputTypeToGLString			(const vk::VkPrimitiveTopology& inputType);
111 std::string						outputTypeToGLString		(const vk::VkPrimitiveTopology& outputType);
112 std::size_t						calcOutputVertices			(const vk::VkPrimitiveTopology& inputType);
113 
114 vk::VkImageCreateInfo			makeImageCreateInfo			(const tcu::IVec2& size, const vk::VkFormat format, const vk::VkImageUsageFlags usage, const deUint32 numArrayLayers = 1u);
115 vk::VkBufferImageCopy			makeBufferImageCopy			(const vk::VkDeviceSize& bufferOffset, const vk::VkImageSubresourceLayers& imageSubresource, const vk::VkOffset3D& imageOffset, const vk::VkExtent3D& imageExtent);
116 
117 bool							compareWithFileImage		(Context& context, const tcu::ConstPixelBufferAccess& resultImage, std::string name);
118 
119 void							fillBuffer					(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::Allocation& alloc, const vk::VkDeviceSize size, const vk::VkDeviceSize offset, const vk::VkFormat format, const tcu::Vec4& color);
120 void							fillBuffer					(const vk::DeviceInterface& vk, const vk::VkDevice device, const vk::Allocation& alloc, const vk::VkDeviceSize size, const vk::VkDeviceSize offset, const vk::VkFormat format, const float depth);
121 vk::VkBool32					checkPointSize				(const vk::InstanceInterface& vki, const vk::VkPhysicalDevice physDevice);
122 
123 } //vkt
124 } //geometry
125 
126 #endif // _VKTGEOMETRYTESTSUTIL_HPP
127