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