1 /*------------------------------------------------------------------------- 2 * Vulkan Conformance Tests 3 * ------------------------ 4 * 5 * Copyright (c) 2015 Google 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 Shader Based Test Case Utility Structs/Functions 22 *//*--------------------------------------------------------------------*/ 23 24 #include "vktSpvAsmComputeShaderTestUtil.hpp" 25 26 namespace vkt 27 { 28 namespace SpirVAssembly 29 { 30 namespace 31 { 32 bool verifyOutputWithEpsilon (const std::vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, tcu::TestLog& log, const float epsilon) 33 { 34 DE_ASSERT(outputAllocs.size() != 0); 35 DE_ASSERT(outputAllocs.size() == expectedOutputs.size()); 36 37 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx) 38 { 39 std::vector<deUint8> expectedBytes; 40 expectedOutputs[outputNdx]->getBytes(expectedBytes); 41 42 std::vector<float> expectedFloats (expectedBytes.size() / sizeof (float)); 43 std::vector<float> actualFloats (expectedBytes.size() / sizeof (float)); 44 45 memcpy(&expectedFloats[0], &expectedBytes.front(), expectedBytes.size()); 46 memcpy(&actualFloats[0], outputAllocs[outputNdx]->getHostPtr(), expectedBytes.size()); 47 for (size_t floatNdx = 0; floatNdx < actualFloats.size(); ++floatNdx) 48 { 49 // Use custom epsilon because of the float->string conversion 50 if (fabs(expectedFloats[floatNdx] - actualFloats[floatNdx]) > epsilon) 51 { 52 log << tcu::TestLog::Message << "Error: The actual and expected values not matching." 53 << " Expected: " << expectedFloats[floatNdx] << " Actual: " << actualFloats[floatNdx] << " Epsilon: " << epsilon << tcu::TestLog::EndMessage; 54 return false; 55 } 56 } 57 } 58 return true; 59 } 60 } 61 62 const char* getComputeAsmShaderPreamble (void) 63 { 64 return 65 "OpCapability Shader\n" 66 "OpMemoryModel Logical GLSL450\n" 67 "OpEntryPoint GLCompute %main \"main\" %id\n" 68 "OpExecutionMode %main LocalSize 1 1 1\n"; 69 } 70 71 std::string getComputeAsmCommonTypes (std::string blockStorageClass) 72 { 73 return std::string( 74 "%bool = OpTypeBool\n" 75 "%void = OpTypeVoid\n" 76 "%voidf = OpTypeFunction %void\n" 77 "%u32 = OpTypeInt 32 0\n" 78 "%i32 = OpTypeInt 32 1\n" 79 "%f32 = OpTypeFloat 32\n" 80 "%uvec3 = OpTypeVector %u32 3\n" 81 "%fvec3 = OpTypeVector %f32 3\n" 82 "%uvec3ptr = OpTypePointer Input %uvec3\n") + 83 "%i32ptr = OpTypePointer " + blockStorageClass + " %i32\n" 84 "%f32ptr = OpTypePointer " + blockStorageClass + " %f32\n" 85 "%i32arr = OpTypeRuntimeArray %i32\n" 86 "%f32arr = OpTypeRuntimeArray %f32\n"; 87 } 88 89 const char* getComputeAsmCommonInt64Types (void) 90 { 91 return 92 "%i64 = OpTypeInt 64 1\n" 93 "%i64ptr = OpTypePointer Uniform %i64\n" 94 "%i64arr = OpTypeRuntimeArray %i64\n"; 95 } 96 97 const char* getComputeAsmInputOutputBuffer (void) 98 { 99 return 100 "%buf = OpTypeStruct %f32arr\n" 101 "%bufptr = OpTypePointer Uniform %buf\n" 102 "%indata = OpVariable %bufptr Uniform\n" 103 "%outdata = OpVariable %bufptr Uniform\n"; 104 } 105 106 const char* getComputeAsmInputOutputBufferTraits (void) 107 { 108 return 109 "OpDecorate %buf BufferBlock\n" 110 "OpDecorate %indata DescriptorSet 0\n" 111 "OpDecorate %indata Binding 0\n" 112 "OpDecorate %outdata DescriptorSet 0\n" 113 "OpDecorate %outdata Binding 1\n" 114 "OpDecorate %f32arr ArrayStride 4\n" 115 "OpMemberDecorate %buf 0 Offset 0\n"; 116 } 117 118 bool verifyOutput (const std::vector<BufferSp>&, const std::vector<AllocationSp>& outputAllocs, const std::vector<BufferSp>& expectedOutputs, tcu::TestLog& log) 119 { 120 const float epsilon = 0.001f; 121 return verifyOutputWithEpsilon(outputAllocs, expectedOutputs, log, epsilon); 122 } 123 124 } // SpirVAssembly 125 } // vkt 126