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<deFloat16> Float16Buffer;
84 typedef Buffer<deInt64> Int64Buffer;
85 typedef Buffer<deInt32> Int32Buffer;
86 typedef Buffer<deInt16> Int16Buffer;
87 typedef Buffer<tcu::Vec4> Vec4Buffer;
89 typedef bool (*ComputeVerifyIOFunc) (const std::vector<BufferSp>& inputs,
90 const std::vector<AllocationSp>& outputAllocations,
91 const std::vector<BufferSp>& expectedOutputs,
94 /*--------------------------------------------------------------------*//*!
95 * \brief Specification for a compute shader.
97 * This struct bundles SPIR-V assembly code, input and expected output
99 *//*--------------------------------------------------------------------*/
100 struct ComputeShaderSpec
102 std::string assembly;
103 std::string entryPoint;
104 std::vector<BufferSp> inputs;
105 // Mapping from input index (in the inputs field) to the descriptor type.
106 std::map<deUint32, VkDescriptorType> inputTypes;
107 std::vector<BufferSp> outputs;
108 tcu::IVec3 numWorkGroups;
109 std::vector<deUint32> specConstants;
110 BufferSp pushConstants;
111 std::vector<std::string> extensions;
112 VulkanFeatures requestedVulkanFeatures;
113 qpTestResult failResult;
114 std::string failMessage;
115 // If null, a default verification will be performed by comparing the memory pointed to by outputAllocations
116 // and the contents of expectedOutputs. Otherwise the function pointed to by verifyIO will be called.
117 // If true is returned, then the test case is assumed to have passed, if false is returned, then the test
118 // case is assumed to have failed. Exact meaning of failure can be customized with failResult.
119 ComputeVerifyIOFunc verifyIO;
121 ComputeShaderSpec (void)
122 : entryPoint ("main")
123 , pushConstants (DE_NULL)
124 , requestedVulkanFeatures ()
125 , failResult (QP_TEST_RESULT_FAIL)
126 , failMessage ("Output doesn't match with expected")
131 /*--------------------------------------------------------------------*//*!
132 * \brief Helper functions for SPIR-V assembly shared by various tests
133 *//*--------------------------------------------------------------------*/
135 const char* getComputeAsmShaderPreamble (void);
136 const char* getComputeAsmCommonTypes (void);
137 const char* getComputeAsmCommonInt64Types (void);
139 /*--------------------------------------------------------------------*//*!
140 * Declares two uniform variables (indata, outdata) of type
141 * "struct { float[] }". Depends on type "f32arr" (for "float[]").
142 *//*--------------------------------------------------------------------*/
143 const char* getComputeAsmInputOutputBuffer (void);
144 /*--------------------------------------------------------------------*//*!
145 * Declares buffer type and layout for uniform variables indata and
146 * outdata. Both of them are SSBO bounded to descriptor set 0.
147 * indata is at binding point 0, while outdata is at 1.
148 *//*--------------------------------------------------------------------*/
149 const char* getComputeAsmInputOutputBufferTraits (void);
154 #endif // _VKTSPVASMCOMPUTESHADERTESTUTIL_HPP