1 #ifndef _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP
2 #define _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 Google 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 Compute Shader Based Test Case Utility Structs/Functions
24 *//*--------------------------------------------------------------------*/
27 #include "deFloat16.h"
28 #include "deSharedPtr.hpp"
29 #include "tcuTestLog.hpp"
30 #include "tcuVector.hpp"
31 #include "vkMemUtil.hpp"
32 #include "vktSpvAsmUtils.hpp"
42 namespace SpirVAssembly
45 typedef de::MovePtr<vk::Allocation> AllocationMp;
46 typedef de::SharedPtr<vk::Allocation> AllocationSp;
48 /*--------------------------------------------------------------------*//*!
49 * \brief Abstract class for an input/output storage buffer object
50 *//*--------------------------------------------------------------------*/
54 virtual ~BufferInterface (void) {}
56 virtual size_t getNumBytes (void) const = 0;
57 virtual const void* data (void) const = 0;
60 typedef de::SharedPtr<BufferInterface> BufferSp;
62 /*--------------------------------------------------------------------*//*!
63 * \brief Concrete class for an input/output storage buffer object
64 *//*--------------------------------------------------------------------*/
66 class Buffer : public BufferInterface
69 Buffer (const std::vector<E>& elements)
70 : m_elements(elements)
73 size_t getNumBytes (void) const { return m_elements.size() * sizeof(E); }
74 const void* data (void) const { return &m_elements.front(); }
77 std::vector<E> m_elements;
80 DE_STATIC_ASSERT(sizeof(tcu::Vec4) == 4 * sizeof(float));
82 typedef Buffer<float> Float32Buffer;
83 typedef Buffer<deInt32> Int32Buffer;
84 typedef Buffer<tcu::Vec4> Vec4Buffer;
86 typedef bool (*ComputeVerifyIOFunc) (const std::vector<BufferSp>& inputs,
87 const std::vector<AllocationSp>& outputAllocations,
88 const std::vector<BufferSp>& expectedOutputs,
91 /*--------------------------------------------------------------------*//*!
92 * \brief Specification for a compute shader.
94 * This struct bundles SPIR-V assembly code, input and expected output
96 *//*--------------------------------------------------------------------*/
97 struct ComputeShaderSpec
100 std::string entryPoint;
101 std::vector<BufferSp> inputs;
102 // Mapping from input index (in the inputs field) to the descriptor type.
103 std::map<deUint32, VkDescriptorType> inputTypes;
104 std::vector<BufferSp> outputs;
105 tcu::IVec3 numWorkGroups;
106 std::vector<deUint32> specConstants;
107 BufferSp pushConstants;
108 std::vector<std::string> extensions;
109 ExtensionFeatures requestedExtensionFeatures;
110 qpTestResult failResult;
111 std::string failMessage;
112 // If null, a default verification will be performed by comparing the memory pointed to by outputAllocations
113 // and the contents of expectedOutputs. Otherwise the function pointed to by verifyIO will be called.
114 // If true is returned, then the test case is assumed to have passed, if false is returned, then the test
115 // case is assumed to have failed. Exact meaning of failure can be customized with failResult.
116 ComputeVerifyIOFunc verifyIO;
118 ComputeShaderSpec (void)
119 : entryPoint ("main")
120 , pushConstants (DE_NULL)
121 , requestedExtensionFeatures ()
122 , failResult (QP_TEST_RESULT_FAIL)
123 , failMessage ("Output doesn't match with expected")
128 /*--------------------------------------------------------------------*//*!
129 * \brief Helper functions for SPIR-V assembly shared by various tests
130 *//*--------------------------------------------------------------------*/
132 const char* getComputeAsmShaderPreamble (void);
133 const char* getComputeAsmCommonTypes (void);
135 /*--------------------------------------------------------------------*//*!
136 * Declares two uniform variables (indata, outdata) of type
137 * "struct { float[] }". Depends on type "f32arr" (for "float[]").
138 *//*--------------------------------------------------------------------*/
139 const char* getComputeAsmInputOutputBuffer (void);
140 /*--------------------------------------------------------------------*//*!
141 * Declares buffer type and layout for uniform variables indata and
142 * outdata. Both of them are SSBO bounded to descriptor set 0.
143 * indata is at binding point 0, while outdata is at 1.
144 *//*--------------------------------------------------------------------*/
145 const char* getComputeAsmInputOutputBufferTraits (void);
150 #endif // _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP