• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _VKTSYNCHRONIZATIONOPERATION_HPP
2 #define _VKTSYNCHRONIZATIONOPERATION_HPP
3 /*------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2016 The Khronos Group Inc.
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file
23  * \brief Synchronization operation abstraction
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "vkDefs.hpp"
28 #include "vkPrograms.hpp"
29 #include "vktTestCase.hpp"
30 #include "vktSynchronizationUtil.hpp"
31 #include "tcuVector.hpp"
32 #include "deUniquePtr.hpp"
33 #include <string>
34 
35 namespace vkt
36 {
37 namespace synchronization
38 {
39 
40 enum OperationName
41 {
42 	// Write operations
43 	OPERATION_NAME_WRITE_FILL_BUFFER,
44 	OPERATION_NAME_WRITE_UPDATE_BUFFER,
45 	OPERATION_NAME_WRITE_COPY_BUFFER,
46 	OPERATION_NAME_WRITE_COPY_BUFFER_TO_IMAGE,
47 	OPERATION_NAME_WRITE_COPY_IMAGE_TO_BUFFER,
48 	OPERATION_NAME_WRITE_COPY_IMAGE,
49 	OPERATION_NAME_WRITE_BLIT_IMAGE,
50 	OPERATION_NAME_WRITE_SSBO_VERTEX,
51 	OPERATION_NAME_WRITE_SSBO_TESSELLATION_CONTROL,
52 	OPERATION_NAME_WRITE_SSBO_TESSELLATION_EVALUATION,
53 	OPERATION_NAME_WRITE_SSBO_GEOMETRY,
54 	OPERATION_NAME_WRITE_SSBO_FRAGMENT,
55 	OPERATION_NAME_WRITE_SSBO_COMPUTE,
56 	OPERATION_NAME_WRITE_SSBO_COMPUTE_INDIRECT,
57 	OPERATION_NAME_WRITE_IMAGE_VERTEX,
58 	OPERATION_NAME_WRITE_IMAGE_TESSELLATION_CONTROL,
59 	OPERATION_NAME_WRITE_IMAGE_TESSELLATION_EVALUATION,
60 	OPERATION_NAME_WRITE_IMAGE_GEOMETRY,
61 	OPERATION_NAME_WRITE_IMAGE_FRAGMENT,
62 	OPERATION_NAME_WRITE_IMAGE_COMPUTE,
63 	OPERATION_NAME_WRITE_IMAGE_COMPUTE_INDIRECT,
64 	OPERATION_NAME_WRITE_CLEAR_COLOR_IMAGE,
65 	OPERATION_NAME_WRITE_CLEAR_DEPTH_STENCIL_IMAGE,
66 	OPERATION_NAME_WRITE_DRAW,
67 	OPERATION_NAME_WRITE_DRAW_INDEXED,
68 	OPERATION_NAME_WRITE_DRAW_INDIRECT,
69 	OPERATION_NAME_WRITE_DRAW_INDEXED_INDIRECT,
70 	OPERATION_NAME_WRITE_CLEAR_ATTACHMENTS,
71 	OPERATION_NAME_WRITE_INDIRECT_BUFFER_DRAW,
72 	OPERATION_NAME_WRITE_INDIRECT_BUFFER_DRAW_INDEXED,
73 	OPERATION_NAME_WRITE_INDIRECT_BUFFER_DISPATCH,
74 
75 	// Read operations
76 	OPERATION_NAME_READ_COPY_BUFFER,
77 	OPERATION_NAME_READ_COPY_BUFFER_TO_IMAGE,
78 	OPERATION_NAME_READ_COPY_IMAGE_TO_BUFFER,
79 	OPERATION_NAME_READ_COPY_IMAGE,
80 	OPERATION_NAME_READ_BLIT_IMAGE,
81 	OPERATION_NAME_READ_UBO_VERTEX,
82 	OPERATION_NAME_READ_UBO_TESSELLATION_CONTROL,
83 	OPERATION_NAME_READ_UBO_TESSELLATION_EVALUATION,
84 	OPERATION_NAME_READ_UBO_GEOMETRY,
85 	OPERATION_NAME_READ_UBO_FRAGMENT,
86 	OPERATION_NAME_READ_UBO_COMPUTE,
87 	OPERATION_NAME_READ_UBO_COMPUTE_INDIRECT,
88 	OPERATION_NAME_READ_SSBO_VERTEX,
89 	OPERATION_NAME_READ_SSBO_TESSELLATION_CONTROL,
90 	OPERATION_NAME_READ_SSBO_TESSELLATION_EVALUATION,
91 	OPERATION_NAME_READ_SSBO_GEOMETRY,
92 	OPERATION_NAME_READ_SSBO_FRAGMENT,
93 	OPERATION_NAME_READ_SSBO_COMPUTE,
94 	OPERATION_NAME_READ_SSBO_COMPUTE_INDIRECT,
95 	OPERATION_NAME_READ_IMAGE_VERTEX,
96 	OPERATION_NAME_READ_IMAGE_TESSELLATION_CONTROL,
97 	OPERATION_NAME_READ_IMAGE_TESSELLATION_EVALUATION,
98 	OPERATION_NAME_READ_IMAGE_GEOMETRY,
99 	OPERATION_NAME_READ_IMAGE_FRAGMENT,
100 	OPERATION_NAME_READ_IMAGE_COMPUTE,
101 	OPERATION_NAME_READ_IMAGE_COMPUTE_INDIRECT,
102 	OPERATION_NAME_READ_INDIRECT_BUFFER_DRAW,
103 	OPERATION_NAME_READ_INDIRECT_BUFFER_DRAW_INDEXED,
104 	OPERATION_NAME_READ_INDIRECT_BUFFER_DISPATCH,
105 	OPERATION_NAME_READ_VERTEX_INPUT,
106 };
107 
108 //! Similar to Context, but allows test instance to decide which resources are used by the operation.
109 //! E.g. this is needed when we want operation to work on a particular queue instead of the universal queue.
110 class OperationContext
111 {
112 public:
getInstanceInterface(void) const113 	const vk::InstanceInterface&				getInstanceInterface	(void) const { return m_vki; }
getDeviceInterface(void) const114 	const vk::DeviceInterface&					getDeviceInterface		(void) const { return m_vk; }
getPhysicalDevice(void) const115 	vk::VkPhysicalDevice						getPhysicalDevice		(void) const { return m_physicalDevice; }
getDevice(void) const116 	vk::VkDevice								getDevice				(void) const { return m_device; }
getAllocator(void) const117 	vk::Allocator&								getAllocator			(void) const { return m_allocator; }
getBinaryCollection(void) const118 	vk::ProgramCollection<vk::ProgramBinary>&	getBinaryCollection		(void) const { return m_progCollection; }
getPipelineCacheData(void) const119 	PipelineCacheData&							getPipelineCacheData	(void) const { return m_pipelineCacheData; }
getDeviceExtensions(void) const120 	const std::vector<std::string>&				getDeviceExtensions		(void) const { return m_deviceExtensions;}
121 
122 	OperationContext (Context& context, PipelineCacheData& pipelineCacheData);
123 	OperationContext (Context& context, PipelineCacheData& pipelineCacheData, const vk::DeviceInterface& vk, const vk::VkDevice device, vk::Allocator& allocator);
124 
125 private:
126 	const vk::InstanceInterface&				m_vki;
127 	const vk::DeviceInterface&					m_vk;
128 	const vk::VkPhysicalDevice					m_physicalDevice;
129 	const vk::VkDevice							m_device;
130 	vk::Allocator&								m_allocator;
131 	vk::ProgramCollection<vk::ProgramBinary>&	m_progCollection;
132 	PipelineCacheData&							m_pipelineCacheData;
133 	const std::vector<std::string>&				m_deviceExtensions;
134 
135 	OperationContext (const OperationContext&);	// "deleted"
136 	OperationContext& operator= (const OperationContext&);
137 };
138 
139 //! Common interface to images and buffers used by operations.
140 class Resource
141 {
142 public:
143 									Resource			(OperationContext& context, const ResourceDescription& desc, const deUint32 usage,
144 														 const vk::VkSharingMode sharingMode = vk::VK_SHARING_MODE_EXCLUSIVE, const std::vector<deUint32>& queueFamilyIndex = std::vector<deUint32>());
145 
getType(void) const146 	ResourceType					getType				(void) const { return m_type; }
getBuffer(void) const147 	const BufferResource&			getBuffer			(void) const { return m_bufferData; }
getImage(void) const148 	const ImageResource&			getImage			(void) const { return m_imageData; }
149 
150 private:
151 	const ResourceType				m_type;
152 	de::MovePtr<Buffer>				m_buffer;
153 	BufferResource					m_bufferData;
154 	de::MovePtr<Image>				m_image;
155 	ImageResource					m_imageData;
156 };
157 
158 //! \note Meaning of image layout is different for read and write types of operations:
159 //!       read  - the layout image must be in before being passed to the read operation
160 //!       write - the layout image will be in after the write operation has finished
161 struct SyncInfo
162 {
163 	vk::VkPipelineStageFlags	stageMask;		//!< pipeline stage where read/write takes place
164 	vk::VkAccessFlags			accessMask;		//!< type of access that is performed
165 	vk::VkImageLayout			imageLayout;	//!< src (for reads) or dst (for writes) image layout
166 };
167 
168 struct Data
169 {
170 	std::size_t					size;
171 	const deUint8*				data;
172 };
173 
174 //! Abstract operation on a resource
175 //! \note Meaning of getData is different for read and write operations:
176 //!       read  - data actually read by the operation
177 //!       write - expected data that operation was supposed to write
178 //! \note It's assumed that recordCommands is called only once (i.e. no multiple command buffers are using these commands).
179 class Operation
180 {
181 public:
Operation(void)182 							Operation		(void) {}
~Operation(void)183 	virtual					~Operation		(void) {}
184 
185 	virtual void			recordCommands	(const vk::VkCommandBuffer cmdBuffer) = 0;	//!< commands that carry out this operation
186 	virtual SyncInfo		getSyncInfo		(void) const = 0;							//!< data required to properly synchronize this operation
187 	virtual Data			getData			(void) const = 0;							//!< get raw data that was written to or read from actual resource
188 
189 private:
190 							Operation		(const Operation& rhs);
191 	Operation&				operator=		(const Operation& rhs);
192 };
193 
194 //! A helper class to init programs and create the operation when context becomes available.
195 //! Throws OperationInvalidResourceError when resource and operation combination is not possible (e.g. buffer-specific op on an image).
196 class OperationSupport
197 {
198 public:
OperationSupport(void)199 									OperationSupport		(void) {}
~OperationSupport(void)200 	virtual							~OperationSupport		(void) {}
201 
202 	virtual deUint32				getResourceUsageFlags	(void) const = 0;
203 	virtual vk::VkQueueFlags		getQueueFlags			(const OperationContext& context) const = 0;
initPrograms(vk::SourceCollections &) const204 	virtual void					initPrograms			(vk::SourceCollections&) const {}	//!< empty by default
205 
206 	virtual de::MovePtr<Operation>	build					(OperationContext& context, Resource& resource) const = 0;
207 
208 private:
209 									OperationSupport		(const OperationSupport& rhs);
210 	OperationSupport&				operator=				(const OperationSupport& rhs);
211 };
212 
213 bool							isResourceSupported		(const OperationName opName, const ResourceDescription& resourceDesc);
214 de::MovePtr<OperationSupport>	makeOperationSupport	(const OperationName opName, const ResourceDescription& resourceDesc);
215 std::string						getOperationName		(const OperationName opName);
216 
217 } // synchronization
218 } // vkt
219 
220 #endif // _VKTSYNCHRONIZATIONOPERATION_HPP
221