1 #ifndef _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP
2 #define _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan Conformance Tests
5  * ------------------------
6  *
7  * Copyright (c) 2015 Google 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 Compute Shader Based Test Case Utility Structs/Functions
24  *//*--------------------------------------------------------------------*/
25 
26 #include "deDefs.h"
27 #include "deSharedPtr.hpp"
28 #include "tcuTestLog.hpp"
29 #include "tcuVector.hpp"
30 #include "vkMemUtil.hpp"
31 
32 #include <string>
33 #include <vector>
34 
35 using namespace vk;
36 
37 namespace vkt
38 {
39 namespace SpirVAssembly
40 {
41 
42 typedef de::MovePtr<vk::Allocation>			AllocationMp;
43 typedef de::SharedPtr<vk::Allocation>		AllocationSp;
44 
45 /*--------------------------------------------------------------------*//*!
46  * \brief Abstract class for an input/output storage buffer object
47  *//*--------------------------------------------------------------------*/
48 class BufferInterface
49 {
50 public:
~BufferInterface(void)51 	virtual				~BufferInterface	(void)				{}
52 
53 	virtual size_t		getNumBytes			(void) const = 0;
54 	virtual const void*	data				(void) const = 0;
55 };
56 
57 typedef de::SharedPtr<BufferInterface>		BufferSp;
58 
59 /*--------------------------------------------------------------------*//*!
60  * \brief Concrete class for an input/output storage buffer object
61  *//*--------------------------------------------------------------------*/
62 template<typename E>
63 class Buffer : public BufferInterface
64 {
65 public:
Buffer(const std::vector<E> & elements)66 						Buffer				(const std::vector<E>& elements)
67 							: m_elements(elements)
68 						{}
69 
getNumBytes(void) const70 	size_t				getNumBytes			(void) const		{ return m_elements.size() * sizeof(E); }
data(void) const71 	const void*			data				(void) const		{ return &m_elements.front(); }
72 
73 private:
74 	std::vector<E>		m_elements;
75 };
76 
77 DE_STATIC_ASSERT(sizeof(tcu::Vec4) == 4 * sizeof(float));
78 
79 typedef Buffer<float>		Float32Buffer;
80 typedef Buffer<deInt32>		Int32Buffer;
81 typedef Buffer<tcu::Vec4>	Vec4Buffer;
82 
83 
84 /*--------------------------------------------------------------------*//*!
85  * \brief Specification for a compute shader.
86  *
87  * This struct bundles SPIR-V assembly code, input and expected output
88  * together.
89  *//*--------------------------------------------------------------------*/
90 struct ComputeShaderSpec
91 {
92 	std::string				assembly;
93 	std::string				entryPoint;
94 	std::vector<BufferSp>	inputs;
95 	std::vector<BufferSp>	outputs;
96 	tcu::IVec3				numWorkGroups;
97 	std::vector<deUint32>	specConstants;
98 	// If null, a default verification will be performed by comparing the memory pointed to by outputAllocations
99 	// and the contents of expectedOutputs. Otherwise the function pointed to by verifyIO will be called.
100 	// If true is returned, then the test case is assumed to have passed, if false is returned, then the test
101 	// case is assumed to have failed.
102 	bool					(*verifyIO)(const std::vector<BufferSp>& inputs, const std::vector<AllocationSp>& outputAllocations, const std::vector<BufferSp>& expectedOutputs, tcu::TestLog& log);
ComputeShaderSpecvkt::SpirVAssembly::ComputeShaderSpec103 							ComputeShaderSpec()
104 								: entryPoint	("main")
105 								, verifyIO		(DE_NULL)
106 							{}
107 
108 };
109 
110 } // SpirVAssembly
111 } // vkt
112 
113 #endif // _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP
114