• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Compute tests utility classes
22  *//*--------------------------------------------------------------------*/
23 
24 #include "vktComputeTestsUtil.hpp"
25 #include "vkQueryUtil.hpp"
26 #include "vkTypeUtil.hpp"
27 
28 using namespace vk;
29 
30 namespace vkt
31 {
32 namespace compute
33 {
34 
Buffer(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkBufferCreateInfo & bufferCreateInfo,const MemoryRequirement memoryRequirement)35 Buffer::Buffer (const DeviceInterface&		vk,
36 				const VkDevice				device,
37 				Allocator&					allocator,
38 				const VkBufferCreateInfo&	bufferCreateInfo,
39 				const MemoryRequirement		memoryRequirement)
40 {
41 	m_buffer = createBuffer(vk, device, &bufferCreateInfo);
42 	m_allocation = allocator.allocate(getBufferMemoryRequirements(vk, device, *m_buffer), memoryRequirement);
43 	VK_CHECK(vk.bindBufferMemory(device, *m_buffer, m_allocation->getMemory(), m_allocation->getOffset()));
44 }
45 
Image(const DeviceInterface & vk,const VkDevice device,Allocator & allocator,const VkImageCreateInfo & imageCreateInfo,const MemoryRequirement memoryRequirement)46 Image::Image (const DeviceInterface&	vk,
47 			  const VkDevice			device,
48 			  Allocator&				allocator,
49 			  const VkImageCreateInfo&	imageCreateInfo,
50 			  const MemoryRequirement	memoryRequirement)
51 {
52 	m_image = createImage(vk, device, &imageCreateInfo);
53 	m_allocation = allocator.allocate(getImageMemoryRequirements(vk, device, *m_image), memoryRequirement);
54 	VK_CHECK(vk.bindImageMemory(device, *m_image, m_allocation->getMemory(), m_allocation->getOffset()));
55 }
56 
makeBufferImageCopy(const VkExtent3D extent,const deUint32 arraySize)57 VkBufferImageCopy makeBufferImageCopy (const VkExtent3D extent,
58 									   const deUint32	arraySize)
59 {
60 	const VkBufferImageCopy copyParams =
61 	{
62 		0ull,																		//	VkDeviceSize				bufferOffset;
63 		0u,																			//	deUint32					bufferRowLength;
64 		0u,																			//	deUint32					bufferImageHeight;
65 		makeImageSubresourceLayers(VK_IMAGE_ASPECT_COLOR_BIT, 0u, 0u, arraySize),	//	VkImageSubresourceLayers	imageSubresource;
66 		makeOffset3D(0, 0, 0),														//	VkOffset3D					imageOffset;
67 		extent,																		//	VkExtent3D					imageExtent;
68 	};
69 	return copyParams;
70 }
71 
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkPipelineCreateFlags pipelineFlags,const VkShaderModule shaderModule,const VkPipelineShaderStageCreateFlags shaderFlags)72 Move<VkPipeline> makeComputePipeline (const DeviceInterface&					vk,
73 									  const VkDevice							device,
74 									  const VkPipelineLayout					pipelineLayout,
75 									  const VkPipelineCreateFlags				pipelineFlags,
76 									  const VkShaderModule						shaderModule,
77 									  const VkPipelineShaderStageCreateFlags	shaderFlags)
78 {
79 	const VkPipelineShaderStageCreateInfo pipelineShaderStageParams =
80 	{
81 		VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,	// VkStructureType						sType;
82 		DE_NULL,												// const void*							pNext;
83 		shaderFlags,											// VkPipelineShaderStageCreateFlags		flags;
84 		VK_SHADER_STAGE_COMPUTE_BIT,							// VkShaderStageFlagBits				stage;
85 		shaderModule,											// VkShaderModule						module;
86 		"main",													// const char*							pName;
87 		DE_NULL,												// const VkSpecializationInfo*			pSpecializationInfo;
88 	};
89 	const VkComputePipelineCreateInfo pipelineCreateInfo =
90 	{
91 		VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,		// VkStructureType					sType;
92 		DE_NULL,											// const void*						pNext;
93 		pipelineFlags,										// VkPipelineCreateFlags			flags;
94 		pipelineShaderStageParams,							// VkPipelineShaderStageCreateInfo	stage;
95 		pipelineLayout,										// VkPipelineLayout					layout;
96 		DE_NULL,											// VkPipeline						basePipelineHandle;
97 		0,													// deInt32							basePipelineIndex;
98 	};
99 	return createComputePipeline(vk, device, DE_NULL , &pipelineCreateInfo);
100 }
101 
makeComputePipeline(const DeviceInterface & vk,const VkDevice device,const VkPipelineLayout pipelineLayout,const VkShaderModule shaderModule)102 Move<VkPipeline> makeComputePipeline (const DeviceInterface&	vk,
103 									  const VkDevice			device,
104 									  const VkPipelineLayout	pipelineLayout,
105 									  const VkShaderModule		shaderModule)
106 {
107 	return makeComputePipeline(vk, device, pipelineLayout, static_cast<VkPipelineCreateFlags>(0u), shaderModule, static_cast<VkPipelineShaderStageCreateFlags>(0u));
108 }
109 } // compute
110 } // vkt
111