1 /*-------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015 Google Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Compute Shader Based Test Case Utility Structs/Functions
22 *//*--------------------------------------------------------------------*/
24 #include "vktSpvAsmComputeShaderTestUtil.hpp"
28 namespace SpirVAssembly
32 bool verifyOutputWithEpsilon (const std::vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, tcu::TestLog& log, const float epsilon)
34 DE_ASSERT(outputAllocs.size() != 0);
35 DE_ASSERT(outputAllocs.size() == expectedOutputs.size());
37 for (size_t outputNdx = 0; outputNdx < outputAllocs.size(); ++outputNdx)
39 std::vector<deUint8> expectedBytes;
40 expectedOutputs[outputNdx].getBytes(expectedBytes);
42 std::vector<float> expectedFloats (expectedBytes.size() / sizeof (float));
43 std::vector<float> actualFloats (expectedBytes.size() / sizeof (float));
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)
49 // Use custom epsilon because of the float->string conversion
50 if (fabs(expectedFloats[floatNdx] - actualFloats[floatNdx]) > epsilon)
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;
62 const char* getComputeAsmShaderPreamble (void)
65 "OpCapability Shader\n"
66 "OpMemoryModel Logical GLSL450\n"
67 "OpEntryPoint GLCompute %main \"main\" %id\n"
68 "OpExecutionMode %main LocalSize 1 1 1\n";
71 const char* getComputeAsmShaderPreambleWithoutLocalSize (void)
74 "OpCapability Shader\n"
75 "OpMemoryModel Logical GLSL450\n"
76 "OpEntryPoint GLCompute %main \"main\" %id\n";
79 std::string getComputeAsmCommonTypes (std::string blockStorageClass)
82 "%bool = OpTypeBool\n"
83 "%void = OpTypeVoid\n"
84 "%voidf = OpTypeFunction %void\n"
85 "%u32 = OpTypeInt 32 0\n"
86 "%i32 = OpTypeInt 32 1\n"
87 "%f32 = OpTypeFloat 32\n"
88 "%uvec3 = OpTypeVector %u32 3\n"
89 "%fvec3 = OpTypeVector %f32 3\n"
90 "%uvec3ptr = OpTypePointer Input %uvec3\n") +
91 "%i32ptr = OpTypePointer " + blockStorageClass + " %i32\n"
92 "%f32ptr = OpTypePointer " + blockStorageClass + " %f32\n"
93 "%i32arr = OpTypeRuntimeArray %i32\n"
94 "%f32arr = OpTypeRuntimeArray %f32\n";
97 const char* getComputeAsmCommonInt64Types (void)
100 "%i64 = OpTypeInt 64 1\n"
101 "%i64ptr = OpTypePointer Uniform %i64\n"
102 "%i64arr = OpTypeRuntimeArray %i64\n";
105 const char* getComputeAsmInputOutputBuffer (void)
108 "%buf = OpTypeStruct %f32arr\n"
109 "%bufptr = OpTypePointer Uniform %buf\n"
110 "%indata = OpVariable %bufptr Uniform\n"
111 "%outdata = OpVariable %bufptr Uniform\n";
114 const char* getComputeAsmInputOutputBufferTraits (void)
117 "OpDecorate %buf BufferBlock\n"
118 "OpDecorate %indata DescriptorSet 0\n"
119 "OpDecorate %indata Binding 0\n"
120 "OpDecorate %outdata DescriptorSet 0\n"
121 "OpDecorate %outdata Binding 1\n"
122 "OpDecorate %f32arr ArrayStride 4\n"
123 "OpMemberDecorate %buf 0 Offset 0\n";
126 bool verifyOutput (const std::vector<Resource>&, const std::vector<AllocationSp>& outputAllocs, const std::vector<Resource>& expectedOutputs, tcu::TestLog& log)
128 const float epsilon = 0.001f;
129 return verifyOutputWithEpsilon(outputAllocs, expectedOutputs, log, epsilon);