Codebase list glslang / 414eb60
Link in Google Test framework. The existing test harness is a homemade shell script. All the tests and the expected results are written in plain text files. The harness just reads in a test, invoke the glslangValidator binary on it, and compare the result with the golden file. All tests are kinda integration tests. This patch add Google Test as an external project, which provides a new harness for reading shader source files, compile to SPIR-V, and then compare with the expected output. Lei Zhang 8 years ago
23 changed file(s) with 1618 addition(s) and 106 deletion(s). Raw diff Collapse all Expand all
66 Test/localResults/
77 Test/multiThread.out
88 Test/singleThread.out
9 External/googletest
00 cmake_minimum_required(VERSION 2.8)
1
2 enable_testing()
13
24 set(CMAKE_INSTALL_PREFIX "install" CACHE STRING "prefix")
35
1921 add_definitions(-std=c++11)
2022 endif()
2123
24 # We depend on these for later projects, so they should come first.
25 add_subdirectory(External)
26
2227 add_subdirectory(glslang)
2328 add_subdirectory(OGLCompilersDLL)
2429 add_subdirectory(StandAlone)
2530 add_subdirectory(SPIRV)
31
32 add_subdirectory(gtests)
0 # Suppress all warnings from external projects.
1 set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -w)
2
3 if (TARGET gmock)
4 message(STATUS "Google Mock already configured - use it")
5 elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
6 # We need to make sure Google Test does not mess up with the
7 # global CRT settings on Windows.
8 if(WIN32)
9 set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
10 endif(WIN32)
11 add_subdirectory(googletest)
12 else()
13 message(STATUS
14 "Google Mock was not found - tests based on that will not build")
15 endif()
6060 -o MachineIndependent/glslang_tab.cpp
6161 ```
6262
63 Glslang is adding the ability to test with
64 [Google Test](https://github.com/google/googletest) framework. If you want to
65 build and run those tests, please make sure you have a copy of Google Tests
66 checked out in the `External/` directory:
67 `git clone https://github.com/google/googletest.git`.
68
6369 Programmatic Interfaces
6470 -----------------------
6571
117123 -------
118124
119125 Test results should always be included with a pull request that modifies
120 functionality. There is a simple process for doing this, described here:
126 functionality. And since glslang is adding the ability to test with
127 [Google Test](https://github.com/google/googletest) framework,
128 please write your new tests using Google Test.
129
130 The old (deprecated) testing process is:
121131
122132 `Test` is an active test directory that contains test input and a
123133 subdirectory `baseResults` that contains the expected results of the
00 cmake_minimum_required(VERSION 2.8)
1
2 add_library(glslang-default-resource-limits
3 ${CMAKE_CURRENT_SOURCE_DIR}/DefaultResourceLimits.cpp
4 )
5 target_include_directories(glslang-default-resource-limits
6 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
7 PUBLIC ${PROJECT_SOURCE_DIR}
8 )
19
210 set(SOURCES StandAlone.cpp)
311 set(REMAPPER_SOURCES spirv-remap.cpp)
917 glslang
1018 OGLCompiler
1119 OSDependent
12 SPIRV)
20 SPIRV
21 glslang-default-resource-limits)
1322
1423 if(WIN32)
1524 set(LIBRARIES ${LIBRARIES} psapi)
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <sstream>
35
36 #include "DefaultResourceLimits.h"
37
38 namespace glslang {
39
40 const TBuiltInResource DefaultTBuiltInResource = {
41 /* .MaxLights = */ 32,
42 /* .MaxClipPlanes = */ 6,
43 /* .MaxTextureUnits = */ 32,
44 /* .MaxTextureCoords = */ 32,
45 /* .MaxVertexAttribs = */ 64,
46 /* .MaxVertexUniformComponents = */ 4096,
47 /* .MaxVaryingFloats = */ 64,
48 /* .MaxVertexTextureImageUnits = */ 32,
49 /* .MaxCombinedTextureImageUnits = */ 80,
50 /* .MaxTextureImageUnits = */ 32,
51 /* .MaxFragmentUniformComponents = */ 4096,
52 /* .MaxDrawBuffers = */ 32,
53 /* .MaxVertexUniformVectors = */ 128,
54 /* .MaxVaryingVectors = */ 8,
55 /* .MaxFragmentUniformVectors = */ 16,
56 /* .MaxVertexOutputVectors = */ 16,
57 /* .MaxFragmentInputVectors = */ 15,
58 /* .MinProgramTexelOffset = */ -8,
59 /* .MaxProgramTexelOffset = */ 7,
60 /* .MaxClipDistances = */ 8,
61 /* .MaxComputeWorkGroupCountX = */ 65535,
62 /* .MaxComputeWorkGroupCountY = */ 65535,
63 /* .MaxComputeWorkGroupCountZ = */ 65535,
64 /* .MaxComputeWorkGroupSizeX = */ 1024,
65 /* .MaxComputeWorkGroupSizeY = */ 1024,
66 /* .MaxComputeWorkGroupSizeZ = */ 64,
67 /* .MaxComputeUniformComponents = */ 1024,
68 /* .MaxComputeTextureImageUnits = */ 16,
69 /* .MaxComputeImageUniforms = */ 8,
70 /* .MaxComputeAtomicCounters = */ 8,
71 /* .MaxComputeAtomicCounterBuffers = */ 1,
72 /* .MaxVaryingComponents = */ 60,
73 /* .MaxVertexOutputComponents = */ 64,
74 /* .MaxGeometryInputComponents = */ 64,
75 /* .MaxGeometryOutputComponents = */ 128,
76 /* .MaxFragmentInputComponents = */ 128,
77 /* .MaxImageUnits = */ 8,
78 /* .MaxCombinedImageUnitsAndFragmentOutputs = */ 8,
79 /* .MaxCombinedShaderOutputResources = */ 8,
80 /* .MaxImageSamples = */ 0,
81 /* .MaxVertexImageUniforms = */ 0,
82 /* .MaxTessControlImageUniforms = */ 0,
83 /* .MaxTessEvaluationImageUniforms = */ 0,
84 /* .MaxGeometryImageUniforms = */ 0,
85 /* .MaxFragmentImageUniforms = */ 8,
86 /* .MaxCombinedImageUniforms = */ 8,
87 /* .MaxGeometryTextureImageUnits = */ 16,
88 /* .MaxGeometryOutputVertices = */ 256,
89 /* .MaxGeometryTotalOutputComponents = */ 1024,
90 /* .MaxGeometryUniformComponents = */ 1024,
91 /* .MaxGeometryVaryingComponents = */ 64,
92 /* .MaxTessControlInputComponents = */ 128,
93 /* .MaxTessControlOutputComponents = */ 128,
94 /* .MaxTessControlTextureImageUnits = */ 16,
95 /* .MaxTessControlUniformComponents = */ 1024,
96 /* .MaxTessControlTotalOutputComponents = */ 4096,
97 /* .MaxTessEvaluationInputComponents = */ 128,
98 /* .MaxTessEvaluationOutputComponents = */ 128,
99 /* .MaxTessEvaluationTextureImageUnits = */ 16,
100 /* .MaxTessEvaluationUniformComponents = */ 1024,
101 /* .MaxTessPatchComponents = */ 120,
102 /* .MaxPatchVertices = */ 32,
103 /* .MaxTessGenLevel = */ 64,
104 /* .MaxViewports = */ 16,
105 /* .MaxVertexAtomicCounters = */ 0,
106 /* .MaxTessControlAtomicCounters = */ 0,
107 /* .MaxTessEvaluationAtomicCounters = */ 0,
108 /* .MaxGeometryAtomicCounters = */ 0,
109 /* .MaxFragmentAtomicCounters = */ 8,
110 /* .MaxCombinedAtomicCounters = */ 8,
111 /* .MaxAtomicCounterBindings = */ 1,
112 /* .MaxVertexAtomicCounterBuffers = */ 0,
113 /* .MaxTessControlAtomicCounterBuffers = */ 0,
114 /* .MaxTessEvaluationAtomicCounterBuffers = */ 0,
115 /* .MaxGeometryAtomicCounterBuffers = */ 0,
116 /* .MaxFragmentAtomicCounterBuffers = */ 1,
117 /* .MaxCombinedAtomicCounterBuffers = */ 1,
118 /* .MaxAtomicCounterBufferSize = */ 16384,
119 /* .MaxTransformFeedbackBuffers = */ 4,
120 /* .MaxTransformFeedbackInterleavedComponents = */ 64,
121 /* .MaxCullDistances = */ 8,
122 /* .MaxCombinedClipAndCullDistances = */ 8,
123 /* .MaxSamples = */ 4,
124 /* .limits = */ {
125 /* .nonInductiveForLoops = */ 1,
126 /* .whileLoops = */ 1,
127 /* .doWhileLoops = */ 1,
128 /* .generalUniformIndexing = */ 1,
129 /* .generalAttributeMatrixVectorIndexing = */ 1,
130 /* .generalVaryingIndexing = */ 1,
131 /* .generalSamplerIndexing = */ 1,
132 /* .generalVariableIndexing = */ 1,
133 /* .generalConstantMatrixVectorIndexing = */ 1,
134 }};
135
136 std::string GetDefaultTBuiltInResourceString()
137 {
138 std::ostringstream ostream;
139
140 ostream << "MaxLights " << DefaultTBuiltInResource.maxLights << "\n"
141 << "MaxClipPlanes " << DefaultTBuiltInResource.maxClipPlanes << "\n"
142 << "MaxTextureUnits " << DefaultTBuiltInResource.maxTextureUnits << "\n"
143 << "MaxTextureCoords " << DefaultTBuiltInResource.maxTextureCoords << "\n"
144 << "MaxVertexAttribs " << DefaultTBuiltInResource.maxVertexAttribs << "\n"
145 << "MaxVertexUniformComponents " << DefaultTBuiltInResource.maxVertexUniformComponents << "\n"
146 << "MaxVaryingFloats " << DefaultTBuiltInResource.maxVaryingFloats << "\n"
147 << "MaxVertexTextureImageUnits " << DefaultTBuiltInResource.maxVertexTextureImageUnits << "\n"
148 << "MaxCombinedTextureImageUnits " << DefaultTBuiltInResource.maxCombinedTextureImageUnits << "\n"
149 << "MaxTextureImageUnits " << DefaultTBuiltInResource.maxTextureImageUnits << "\n"
150 << "MaxFragmentUniformComponents " << DefaultTBuiltInResource.maxFragmentUniformComponents << "\n"
151 << "MaxDrawBuffers " << DefaultTBuiltInResource.maxDrawBuffers << "\n"
152 << "MaxVertexUniformVectors " << DefaultTBuiltInResource.maxVertexUniformVectors << "\n"
153 << "MaxVaryingVectors " << DefaultTBuiltInResource.maxVaryingVectors << "\n"
154 << "MaxFragmentUniformVectors " << DefaultTBuiltInResource.maxFragmentUniformVectors << "\n"
155 << "MaxVertexOutputVectors " << DefaultTBuiltInResource.maxVertexOutputVectors << "\n"
156 << "MaxFragmentInputVectors " << DefaultTBuiltInResource.maxFragmentInputVectors << "\n"
157 << "MinProgramTexelOffset " << DefaultTBuiltInResource.minProgramTexelOffset << "\n"
158 << "MaxProgramTexelOffset " << DefaultTBuiltInResource.maxProgramTexelOffset << "\n"
159 << "MaxClipDistances " << DefaultTBuiltInResource.maxClipDistances << "\n"
160 << "MaxComputeWorkGroupCountX " << DefaultTBuiltInResource.maxComputeWorkGroupCountX << "\n"
161 << "MaxComputeWorkGroupCountY " << DefaultTBuiltInResource.maxComputeWorkGroupCountY << "\n"
162 << "MaxComputeWorkGroupCountZ " << DefaultTBuiltInResource.maxComputeWorkGroupCountZ << "\n"
163 << "MaxComputeWorkGroupSizeX " << DefaultTBuiltInResource.maxComputeWorkGroupSizeX << "\n"
164 << "MaxComputeWorkGroupSizeY " << DefaultTBuiltInResource.maxComputeWorkGroupSizeY << "\n"
165 << "MaxComputeWorkGroupSizeZ " << DefaultTBuiltInResource.maxComputeWorkGroupSizeZ << "\n"
166 << "MaxComputeUniformComponents " << DefaultTBuiltInResource.maxComputeUniformComponents << "\n"
167 << "MaxComputeTextureImageUnits " << DefaultTBuiltInResource.maxComputeTextureImageUnits << "\n"
168 << "MaxComputeImageUniforms " << DefaultTBuiltInResource.maxComputeImageUniforms << "\n"
169 << "MaxComputeAtomicCounters " << DefaultTBuiltInResource.maxComputeAtomicCounters << "\n"
170 << "MaxComputeAtomicCounterBuffers " << DefaultTBuiltInResource.maxComputeAtomicCounterBuffers << "\n"
171 << "MaxVaryingComponents " << DefaultTBuiltInResource.maxVaryingComponents << "\n"
172 << "MaxVertexOutputComponents " << DefaultTBuiltInResource.maxVertexOutputComponents << "\n"
173 << "MaxGeometryInputComponents " << DefaultTBuiltInResource.maxGeometryInputComponents << "\n"
174 << "MaxGeometryOutputComponents " << DefaultTBuiltInResource.maxGeometryOutputComponents << "\n"
175 << "MaxFragmentInputComponents " << DefaultTBuiltInResource.maxFragmentInputComponents << "\n"
176 << "MaxImageUnits " << DefaultTBuiltInResource.maxImageUnits << "\n"
177 << "MaxCombinedImageUnitsAndFragmentOutputs " << DefaultTBuiltInResource.maxCombinedImageUnitsAndFragmentOutputs << "\n"
178 << "MaxCombinedShaderOutputResources " << DefaultTBuiltInResource.maxCombinedShaderOutputResources << "\n"
179 << "MaxImageSamples " << DefaultTBuiltInResource.maxImageSamples << "\n"
180 << "MaxVertexImageUniforms " << DefaultTBuiltInResource.maxVertexImageUniforms << "\n"
181 << "MaxTessControlImageUniforms " << DefaultTBuiltInResource.maxTessControlImageUniforms << "\n"
182 << "MaxTessEvaluationImageUniforms " << DefaultTBuiltInResource.maxTessEvaluationImageUniforms << "\n"
183 << "MaxGeometryImageUniforms " << DefaultTBuiltInResource.maxGeometryImageUniforms << "\n"
184 << "MaxFragmentImageUniforms " << DefaultTBuiltInResource.maxFragmentImageUniforms << "\n"
185 << "MaxCombinedImageUniforms " << DefaultTBuiltInResource.maxCombinedImageUniforms << "\n"
186 << "MaxGeometryTextureImageUnits " << DefaultTBuiltInResource.maxGeometryTextureImageUnits << "\n"
187 << "MaxGeometryOutputVertices " << DefaultTBuiltInResource.maxGeometryOutputVertices << "\n"
188 << "MaxGeometryTotalOutputComponents " << DefaultTBuiltInResource.maxGeometryTotalOutputComponents << "\n"
189 << "MaxGeometryUniformComponents " << DefaultTBuiltInResource.maxGeometryUniformComponents << "\n"
190 << "MaxGeometryVaryingComponents " << DefaultTBuiltInResource.maxGeometryVaryingComponents << "\n"
191 << "MaxTessControlInputComponents " << DefaultTBuiltInResource.maxTessControlInputComponents << "\n"
192 << "MaxTessControlOutputComponents " << DefaultTBuiltInResource.maxTessControlOutputComponents << "\n"
193 << "MaxTessControlTextureImageUnits " << DefaultTBuiltInResource.maxTessControlTextureImageUnits << "\n"
194 << "MaxTessControlUniformComponents " << DefaultTBuiltInResource.maxTessControlUniformComponents << "\n"
195 << "MaxTessControlTotalOutputComponents " << DefaultTBuiltInResource.maxTessControlTotalOutputComponents << "\n"
196 << "MaxTessEvaluationInputComponents " << DefaultTBuiltInResource.maxTessEvaluationInputComponents << "\n"
197 << "MaxTessEvaluationOutputComponents " << DefaultTBuiltInResource.maxTessEvaluationOutputComponents << "\n"
198 << "MaxTessEvaluationTextureImageUnits " << DefaultTBuiltInResource.maxTessEvaluationTextureImageUnits << "\n"
199 << "MaxTessEvaluationUniformComponents " << DefaultTBuiltInResource.maxTessEvaluationUniformComponents << "\n"
200 << "MaxTessPatchComponents " << DefaultTBuiltInResource.maxTessPatchComponents << "\n"
201 << "MaxPatchVertices " << DefaultTBuiltInResource.maxPatchVertices << "\n"
202 << "MaxTessGenLevel " << DefaultTBuiltInResource.maxTessGenLevel << "\n"
203 << "MaxViewports " << DefaultTBuiltInResource.maxViewports << "\n"
204 << "MaxVertexAtomicCounters " << DefaultTBuiltInResource.maxVertexAtomicCounters << "\n"
205 << "MaxTessControlAtomicCounters " << DefaultTBuiltInResource.maxTessControlAtomicCounters << "\n"
206 << "MaxTessEvaluationAtomicCounters " << DefaultTBuiltInResource.maxTessEvaluationAtomicCounters << "\n"
207 << "MaxGeometryAtomicCounters " << DefaultTBuiltInResource.maxGeometryAtomicCounters << "\n"
208 << "MaxFragmentAtomicCounters " << DefaultTBuiltInResource.maxFragmentAtomicCounters << "\n"
209 << "MaxCombinedAtomicCounters " << DefaultTBuiltInResource.maxCombinedAtomicCounters << "\n"
210 << "MaxAtomicCounterBindings " << DefaultTBuiltInResource.maxAtomicCounterBindings << "\n"
211 << "MaxVertexAtomicCounterBuffers " << DefaultTBuiltInResource.maxVertexAtomicCounterBuffers << "\n"
212 << "MaxTessControlAtomicCounterBuffers " << DefaultTBuiltInResource.maxTessControlAtomicCounterBuffers << "\n"
213 << "MaxTessEvaluationAtomicCounterBuffers " << DefaultTBuiltInResource.maxTessEvaluationAtomicCounterBuffers << "\n"
214 << "MaxGeometryAtomicCounterBuffers " << DefaultTBuiltInResource.maxGeometryAtomicCounterBuffers << "\n"
215 << "MaxFragmentAtomicCounterBuffers " << DefaultTBuiltInResource.maxFragmentAtomicCounterBuffers << "\n"
216 << "MaxCombinedAtomicCounterBuffers " << DefaultTBuiltInResource.maxCombinedAtomicCounterBuffers << "\n"
217 << "MaxAtomicCounterBufferSize " << DefaultTBuiltInResource.maxAtomicCounterBufferSize << "\n"
218 << "MaxTransformFeedbackBuffers " << DefaultTBuiltInResource.maxTransformFeedbackBuffers << "\n"
219 << "MaxTransformFeedbackInterleavedComponents " << DefaultTBuiltInResource.maxTransformFeedbackInterleavedComponents << "\n"
220 << "MaxCullDistances " << DefaultTBuiltInResource.maxCullDistances << "\n"
221 << "MaxCombinedClipAndCullDistances " << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n"
222 << "MaxSamples " << DefaultTBuiltInResource.maxSamples << "\n"
223
224 << "nonInductiveForLoops " << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n"
225 << "whileLoops " << DefaultTBuiltInResource.limits.whileLoops << "\n"
226 << "doWhileLoops " << DefaultTBuiltInResource.limits.doWhileLoops << "\n"
227 << "generalUniformIndexing " << DefaultTBuiltInResource.limits.generalUniformIndexing << "\n"
228 << "generalAttributeMatrixVectorIndexing " << DefaultTBuiltInResource.limits.generalAttributeMatrixVectorIndexing << "\n"
229 << "generalVaryingIndexing " << DefaultTBuiltInResource.limits.generalVaryingIndexing << "\n"
230 << "generalSamplerIndexing " << DefaultTBuiltInResource.limits.generalSamplerIndexing << "\n"
231 << "generalVariableIndexing " << DefaultTBuiltInResource.limits.generalVariableIndexing << "\n"
232 << "generalConstantMatrixVectorIndexing " << DefaultTBuiltInResource.limits.generalConstantMatrixVectorIndexing << "\n"
233 ;
234
235 return ostream.str();
236 }
237
238 } // end namespace glslang
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #ifndef _DEFAULT_RESOURCE_LIMITS_INCLUDED_
35 #define _DEFAULT_RESOURCE_LIMITS_INCLUDED_
36
37 #include <string>
38
39 #include "glslang/Include/ResourceLimits.h"
40
41 namespace glslang {
42
43 // These are the default resources for TBuiltInResources, used for both
44 // - parsing this string for the case where the user didn't supply one,
45 // - dumping out a template for user construction of a config file.
46 extern const TBuiltInResource DefaultTBuiltInResource;
47
48 // Returns the DefaultTBuiltInResource as a human-readable string.
49 std::string GetDefaultTBuiltInResourceString();
50
51 } // end namespace glslang
52
53 #endif // _DEFAULT_RESOURCE_LIMITS_INCLUDED_
3636 // this only applies to the standalone wrapper, not the front end in general
3737 #define _CRT_SECURE_NO_WARNINGS
3838
39 #include "DefaultResourceLimits.h"
3940 #include "Worklist.h"
4041 #include "./../glslang/Include/ShHandle.h"
4142 #include "./../glslang/Include/revision.h"
110111 std::string ConfigFile;
111112
112113 //
113 // These are the default resources for TBuiltInResources, used for both
114 // - parsing this string for the case where the user didn't supply one
115 // - dumping out a template for user construction of a config file
116 //
117 const char* DefaultConfig =
118 "MaxLights 32\n"
119 "MaxClipPlanes 6\n"
120 "MaxTextureUnits 32\n"
121 "MaxTextureCoords 32\n"
122 "MaxVertexAttribs 64\n"
123 "MaxVertexUniformComponents 4096\n"
124 "MaxVaryingFloats 64\n"
125 "MaxVertexTextureImageUnits 32\n"
126 "MaxCombinedTextureImageUnits 80\n"
127 "MaxTextureImageUnits 32\n"
128 "MaxFragmentUniformComponents 4096\n"
129 "MaxDrawBuffers 32\n"
130 "MaxVertexUniformVectors 128\n"
131 "MaxVaryingVectors 8\n"
132 "MaxFragmentUniformVectors 16\n"
133 "MaxVertexOutputVectors 16\n"
134 "MaxFragmentInputVectors 15\n"
135 "MinProgramTexelOffset -8\n"
136 "MaxProgramTexelOffset 7\n"
137 "MaxClipDistances 8\n"
138 "MaxComputeWorkGroupCountX 65535\n"
139 "MaxComputeWorkGroupCountY 65535\n"
140 "MaxComputeWorkGroupCountZ 65535\n"
141 "MaxComputeWorkGroupSizeX 1024\n"
142 "MaxComputeWorkGroupSizeY 1024\n"
143 "MaxComputeWorkGroupSizeZ 64\n"
144 "MaxComputeUniformComponents 1024\n"
145 "MaxComputeTextureImageUnits 16\n"
146 "MaxComputeImageUniforms 8\n"
147 "MaxComputeAtomicCounters 8\n"
148 "MaxComputeAtomicCounterBuffers 1\n"
149 "MaxVaryingComponents 60\n"
150 "MaxVertexOutputComponents 64\n"
151 "MaxGeometryInputComponents 64\n"
152 "MaxGeometryOutputComponents 128\n"
153 "MaxFragmentInputComponents 128\n"
154 "MaxImageUnits 8\n"
155 "MaxCombinedImageUnitsAndFragmentOutputs 8\n"
156 "MaxCombinedShaderOutputResources 8\n"
157 "MaxImageSamples 0\n"
158 "MaxVertexImageUniforms 0\n"
159 "MaxTessControlImageUniforms 0\n"
160 "MaxTessEvaluationImageUniforms 0\n"
161 "MaxGeometryImageUniforms 0\n"
162 "MaxFragmentImageUniforms 8\n"
163 "MaxCombinedImageUniforms 8\n"
164 "MaxGeometryTextureImageUnits 16\n"
165 "MaxGeometryOutputVertices 256\n"
166 "MaxGeometryTotalOutputComponents 1024\n"
167 "MaxGeometryUniformComponents 1024\n"
168 "MaxGeometryVaryingComponents 64\n"
169 "MaxTessControlInputComponents 128\n"
170 "MaxTessControlOutputComponents 128\n"
171 "MaxTessControlTextureImageUnits 16\n"
172 "MaxTessControlUniformComponents 1024\n"
173 "MaxTessControlTotalOutputComponents 4096\n"
174 "MaxTessEvaluationInputComponents 128\n"
175 "MaxTessEvaluationOutputComponents 128\n"
176 "MaxTessEvaluationTextureImageUnits 16\n"
177 "MaxTessEvaluationUniformComponents 1024\n"
178 "MaxTessPatchComponents 120\n"
179 "MaxPatchVertices 32\n"
180 "MaxTessGenLevel 64\n"
181 "MaxViewports 16\n"
182 "MaxVertexAtomicCounters 0\n"
183 "MaxTessControlAtomicCounters 0\n"
184 "MaxTessEvaluationAtomicCounters 0\n"
185 "MaxGeometryAtomicCounters 0\n"
186 "MaxFragmentAtomicCounters 8\n"
187 "MaxCombinedAtomicCounters 8\n"
188 "MaxAtomicCounterBindings 1\n"
189 "MaxVertexAtomicCounterBuffers 0\n"
190 "MaxTessControlAtomicCounterBuffers 0\n"
191 "MaxTessEvaluationAtomicCounterBuffers 0\n"
192 "MaxGeometryAtomicCounterBuffers 0\n"
193 "MaxFragmentAtomicCounterBuffers 1\n"
194 "MaxCombinedAtomicCounterBuffers 1\n"
195 "MaxAtomicCounterBufferSize 16384\n"
196 "MaxTransformFeedbackBuffers 4\n"
197 "MaxTransformFeedbackInterleavedComponents 64\n"
198 "MaxCullDistances 8\n"
199 "MaxCombinedClipAndCullDistances 8\n"
200 "MaxSamples 4\n"
201
202 "nonInductiveForLoops 1\n"
203 "whileLoops 1\n"
204 "doWhileLoops 1\n"
205 "generalUniformIndexing 1\n"
206 "generalAttributeMatrixVectorIndexing 1\n"
207 "generalVaryingIndexing 1\n"
208 "generalSamplerIndexing 1\n"
209 "generalVariableIndexing 1\n"
210 "generalConstantMatrixVectorIndexing 1\n"
211 ;
212
213 //
214114 // Parse either a .conf file provided by the user or the default string above.
215115 //
216116 void ProcessConfigFile()
228128 }
229129
230130 if (config == 0) {
231 config = new char[strlen(DefaultConfig) + 1];
232 strcpy(config, DefaultConfig);
131 Resources = glslang::DefaultTBuiltInResource;
132 return;
233133 }
234134
235135 const char* delims = " \t\n\r";
831731 ProcessArguments(argc, argv);
832732
833733 if (Options & EOptionDumpConfig) {
834 printf("%s", DefaultConfig);
734 printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str());
835735 if (Worklist.empty())
836736 return ESuccess;
837737 }
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <gtest/gtest.h>
35
36 #include "TestFixture.h"
37
38 namespace glslangtest {
39 namespace {
40
41 using CompileToAstTest = GlslangTest<::testing::TestWithParam<std::string>>;
42
43 TEST_P(CompileToAstTest, FromFile)
44 {
45 loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
46 Semantics::OpenGL, Target::AST);
47 }
48
49 // clang-format off
50 INSTANTIATE_TEST_CASE_P(
51 Glsl, CompileToAstTest,
52 ::testing::ValuesIn(std::vector<std::string>({
53 "sample.frag",
54 "sample.vert",
55 "decls.frag",
56 "specExamples.frag",
57 "specExamples.vert",
58 "versionsClean.frag",
59 "versionsClean.vert",
60 "versionsErrors.frag",
61 "versionsErrors.vert",
62 "100.frag",
63 "120.vert",
64 "120.frag",
65 "130.vert",
66 "130.frag",
67 "140.vert",
68 "140.frag",
69 "150.vert",
70 "150.geom",
71 "150.frag",
72 "precision.frag",
73 "precision.vert",
74 "nonSquare.vert",
75 "matrixError.vert",
76 "cppSimple.vert",
77 "cppIndent.vert",
78 "cppNest.vert",
79 "cppComplexExpr.vert",
80 "badChars.frag",
81 "pointCoord.frag",
82 "array.frag",
83 "array100.frag",
84 "comment.frag",
85 "300.vert",
86 "300.frag",
87 "300BuiltIns.frag",
88 "300layout.vert",
89 "300layout.frag",
90 "300operations.frag",
91 "300block.frag",
92 "310.comp",
93 "310.vert",
94 "310.geom",
95 "310.frag",
96 "310.tesc",
97 "310.tese",
98 "310implicitSizeArrayError.vert",
99 "310AofA.vert",
100 "330.frag",
101 "330comp.frag",
102 "constErrors.frag",
103 "constFold.frag",
104 "errors.frag",
105 "forwardRef.frag",
106 "uint.frag",
107 "switch.frag",
108 "tokenLength.vert",
109 "100Limits.vert",
110 "100scope.vert",
111 "110scope.vert",
112 "300scope.vert",
113 "400.frag",
114 "420.frag",
115 "420.vert",
116 "420.geom",
117 "420_size_gl_in.geom",
118 "430scope.vert",
119 "lineContinuation100.vert",
120 "lineContinuation.vert",
121 "numeral.frag",
122 "400.geom",
123 "400.tesc",
124 "400.tese",
125 "410.tesc",
126 "420.tesc",
127 "420.tese",
128 "410.geom",
129 "430.vert",
130 "430.comp",
131 "430AofA.frag",
132 "440.vert",
133 "440.frag",
134 "450.vert",
135 "450.geom",
136 "450.tesc",
137 "450.tese",
138 "450.frag",
139 "450.comp",
140 "dce.frag",
141 "atomic_uint.frag",
142 "aggOps.frag",
143 "always-discard.frag",
144 "always-discard2.frag",
145 "conditionalDiscard.frag",
146 "conversion.frag",
147 "dataOut.frag",
148 "dataOutIndirect.frag",
149 "deepRvalue.frag",
150 "depthOut.frag",
151 "discard-dce.frag",
152 "doWhileLoop.frag",
153 "earlyReturnDiscard.frag",
154 "flowControl.frag",
155 "forLoop.frag",
156 "functionCall.frag",
157 "functionSemantics.frag",
158 "length.frag",
159 "localAggregates.frag",
160 "loops.frag",
161 "loopsArtificial.frag",
162 "matrix.frag",
163 "matrix2.frag",
164 "newTexture.frag",
165 "Operations.frag",
166 "prepost.frag",
167 "simpleFunctionCall.frag",
168 "structAssignment.frag",
169 "structDeref.frag",
170 "structure.frag",
171 "swizzle.frag",
172 "syntaxError.frag",
173 "test.frag",
174 "texture.frag",
175 "types.frag",
176 "uniformArray.frag",
177 "variableArrayIndex.frag",
178 "varyingArray.frag",
179 "varyingArrayIndirect.frag",
180 "voidFunction.frag",
181 "whileLoop.frag",
182 "nonVulkan.frag",
183 "spv.atomic.comp",
184 })),
185 FileNameAsCustomTestName
186 );
187 // clang-format on
188
189 } // anonymous namespace
190 } // namespace glslangtest
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <algorithm>
35
36 #include <gtest/gtest.h>
37
38 #include "StandAlone/DefaultResourceLimits.h"
39 #include "TestFixture.h"
40
41 namespace glslangtest {
42 namespace {
43
44 using DefaultResourceTest = GlslangTest<::testing::Test>;
45
46 TEST_F(DefaultResourceTest, FromFile)
47 {
48 const std::string path = GLSLANG_TEST_DIRECTORY "/baseResults/test.conf";
49 std::string expectedConfig;
50 tryLoadFile(path, "expected resource limit", &expectedConfig);
51 const std::string realConfig = glslang::GetDefaultTBuiltInResourceString();
52 ASSERT_EQ(expectedConfig, realConfig);
53 }
54
55 } // anonymous namespace
56 } // namespace glslangtest
0 if (TARGET gmock)
1 message(STATUS "Google Mock found - building tests")
2
3 set(TEST_SOURCES
4 # Framework related source files
5 ${CMAKE_CURRENT_SOURCE_DIR}/Initializer.h
6 ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
7 ${CMAKE_CURRENT_SOURCE_DIR}/Settings.cpp
8 ${CMAKE_CURRENT_SOURCE_DIR}/Settings.h
9 ${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.cpp
10 ${CMAKE_CURRENT_SOURCE_DIR}/TestFixture.h
11
12 # Test related source files
13 ${CMAKE_CURRENT_SOURCE_DIR}/AST.FromFile.cpp
14 ${CMAKE_CURRENT_SOURCE_DIR}/BuiltInResource.FromFile.cpp
15 ${CMAKE_CURRENT_SOURCE_DIR}/Pp.FromFile.cpp
16 ${CMAKE_CURRENT_SOURCE_DIR}/Spv.FromFile.cpp
17 )
18
19 add_executable(glslangtests ${TEST_SOURCES})
20 target_compile_definitions(glslangtests
21 PRIVATE GLSLANG_TEST_DIRECTORY="${CMAKE_CURRENT_SOURCE_DIR}/../Test")
22 target_include_directories(glslangtests PRIVATE
23 ${CMAKE_CURRENT_SOURCE_DIR}
24 ${PROJECT_SOURCE_DIR}
25 ${gmock_SOURCE_DIR}/include
26 ${gtest_SOURCE_DIR}/include)
27 target_link_libraries(glslangtests PRIVATE
28 glslang OSDependent OGLCompiler glslang
29 SPIRV glslang-default-resource-limits gmock)
30 add_test(NAME glslang-gtests COMMAND glslangtests)
31 endif()
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #ifndef GLSLANG_GTESTS_INITIALIZER_H
35 #define GLSLANG_GTESTS_INITIALIZER_H
36
37 #include <mutex>
38
39 #include "glslang/Public/ShaderLang.h"
40
41 namespace glslangtest {
42
43 // Initializes glslang on creation, and destroys it on completion.
44 // And provides .Acquire() as a way to reinitialize glslang if semantics change.
45 // This object is expected to be a singleton, so that internal glslang state
46 // can be correctly handled.
47 //
48 // TODO(antiagainst): It's a known bug that some of the internal states need to
49 // be reset if semantics change:
50 // https://github.com/KhronosGroup/glslang/issues/166
51 // Therefore, the following mechanism is needed. Remove this once the above bug
52 // gets fixed.
53 class GlslangInitializer {
54 public:
55 GlslangInitializer() : lastMessages(EShMsgDefault)
56 {
57 glslang::InitializeProcess();
58 }
59
60 ~GlslangInitializer() { glslang::FinalizeProcess(); }
61
62 // A token indicates that the glslang is reinitialized (if necessary) to the
63 // required semantics. And that won't change until the token is destroyed.
64 class InitializationToken {
65 public:
66 InitializationToken() : initializer(nullptr) {}
67 ~InitializationToken()
68 {
69 if (initializer) {
70 initializer->release();
71 }
72 }
73
74 InitializationToken(InitializationToken&& other)
75 : initializer(other.initializer)
76 {
77 other.initializer = nullptr;
78 }
79
80 InitializationToken(const InitializationToken&) = delete;
81
82 private:
83 InitializationToken(GlslangInitializer* initializer)
84 : initializer(initializer) {}
85
86 friend class GlslangInitializer;
87 GlslangInitializer* initializer;
88 };
89
90 // Obtains exclusive access to the glslang state. The state remains
91 // exclusive until the Initialization Token has been destroyed.
92 // Re-initializes glsl state iff the previous messages and the current
93 // messages are incompatible.
94 InitializationToken acquire(EShMessages new_messages)
95 {
96 stateLock.lock();
97
98 if ((lastMessages ^ new_messages) &
99 (EShMsgVulkanRules | EShMsgSpvRules)) {
100 glslang::FinalizeProcess();
101 glslang::InitializeProcess();
102 }
103 lastMessages = new_messages;
104 return InitializationToken(this);
105 }
106
107 private:
108 void release() { stateLock.unlock(); }
109
110 friend class InitializationToken;
111
112 EShMessages lastMessages;
113 std::mutex stateLock;
114 };
115
116 } // namespace glslangtest
117
118 #endif // GLSLANG_GTESTS_INITIALIZER_H
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <gtest/gtest.h>
35
36 #include "TestFixture.h"
37
38 namespace glslangtest {
39 namespace {
40
41 using PreprocessingTest = GlslangTest<::testing::TestWithParam<std::string>>;
42
43 TEST_P(PreprocessingTest, FromFile)
44 {
45 loadFilePreprocessAndCheck(GLSLANG_TEST_DIRECTORY, GetParam());
46 }
47
48 // clang-format off
49 INSTANTIATE_TEST_CASE_P(
50 Glsl, PreprocessingTest,
51 ::testing::ValuesIn(std::vector<std::string>({
52 "preprocessor.cpp_style_line_directive.vert",
53 "preprocessor.cpp_style___FILE__.vert",
54 "preprocessor.edge_cases.vert",
55 "preprocessor.errors.vert",
56 "preprocessor.extensions.vert",
57 "preprocessor.function_macro.vert",
58 "preprocessor.include.enabled.vert",
59 "preprocessor.include.disabled.vert",
60 "preprocessor.line.vert",
61 "preprocessor.line.frag",
62 "preprocessor.pragma.vert",
63 "preprocessor.simple.vert",
64 "preprocessor.success_if_parse_would_fail.vert",
65 "preprocessor.defined.vert",
66 "preprocessor.many.endif.vert",
67 })),
68 FileNameAsCustomTestName
69 );
70 // clang-format on
71
72 } // anonymous namespace
73 } // namespace glslangtest
0 Glslang Tests based on the Google Test Framework
1 ================================================
2
3 This directory contains [Google Test][gtest] based test fixture and test
4 cases for glslang.
5
6 Apart from typical unit tests, necessary utility methods are added into
7 the [`GlslangTests`](TestFixture.h) fixture to provide the ability to do
8 file-based integration tests. Various `*.FromFile.cpp` files lists names
9 of files containing input shader code in the `Test/` directory. Utility
10 methods will load the input shader source, compile them, and compare with
11 the corresponding expected output in the `Test/baseResults/` directory.
12
13 How to run the tests
14 --------------------
15
16 Please make sure you have a copy of [Google Test][gtest] checked out under
17 the `External` directory before building. After building, just run the
18 `ctest` command or the `gtests/glslangtests` binary in your build directory.
19
20 The `gtests/glslangtests` binary also provides an `--update-mode` command
21 line option, which, if supplied, will overwrite the golden files under
22 the `Test/baseResults/` directory with real output from that invocation.
23 This serves as an easy way to update golden files.
24
25 [gtest]: https://github.com/google/googletest
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include "Settings.h"
35
36 namespace glslangtest {
37
38 GTestSettings GlobalTestSettings = {nullptr, false};
39
40 } // namespace glslangtest
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #ifndef GLSLANG_GTESTS_SETTINGS_H
35 #define GLSLANG_GTESTS_SETTINGS_H
36
37 namespace glslangtest {
38
39 class GlslangInitializer;
40
41 struct GTestSettings {
42 // A handle to GlslangInitializer instance.
43 GlslangInitializer* initializer;
44 // An indicator of whether GTest should write real output to the file for
45 // the expected output.
46 bool updateMode;
47 };
48
49 extern GTestSettings GlobalTestSettings;
50
51 } // namespace glslangtest
52
53 #endif // GLSLANG_GTESTS_SETTINGS_H
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <algorithm>
35
36 #include <gtest/gtest.h>
37
38 #include "TestFixture.h"
39
40 namespace glslangtest {
41 namespace {
42
43 using CompileToSpirvTest = GlslangTest<::testing::TestWithParam<std::string>>;
44 using VulkanSemantics = GlslangTest<::testing::TestWithParam<std::string>>;
45
46 // Compiling GLSL to SPIR-V under Vulkan semantics. Expected to successfully
47 // generate SPIR-V.
48 TEST_P(CompileToSpirvTest, FromFile)
49 {
50 loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
51 Semantics::Vulkan, Target::Spirv);
52 }
53
54 // GLSL-level Vulkan semantics test. Expected to error out before generating
55 // SPIR-V.
56 TEST_P(VulkanSemantics, FromFile)
57 {
58 loadFileCompileAndCheck(GLSLANG_TEST_DIRECTORY, GetParam(),
59 Semantics::Vulkan, Target::Spirv);
60 }
61
62 // clang-format off
63 INSTANTIATE_TEST_CASE_P(
64 Glsl, CompileToSpirvTest,
65 ::testing::ValuesIn(std::vector<std::string>({
66 // Test looping constructs.
67 // No tests yet for making sure break and continue from a nested loop
68 // goes to the innermost target.
69 "spv.do-simple.vert",
70 "spv.do-while-continue-break.vert",
71 "spv.for-complex-condition.vert",
72 "spv.for-continue-break.vert",
73 "spv.for-simple.vert",
74 "spv.for-notest.vert",
75 "spv.for-nobody.vert",
76 "spv.while-continue-break.vert",
77 "spv.while-simple.vert",
78 // vulkan-specific tests
79 "spv.set.vert",
80 "spv.double.comp",
81 "spv.100ops.frag",
82 "spv.130.frag",
83 "spv.140.frag",
84 "spv.150.geom",
85 "spv.150.vert",
86 "spv.300BuiltIns.vert",
87 "spv.300layout.frag",
88 "spv.300layout.vert",
89 "spv.300layoutp.vert",
90 "spv.310.comp",
91 "spv.330.geom",
92 "spv.400.frag",
93 "spv.400.tesc",
94 "spv.400.tese",
95 "spv.420.geom",
96 "spv.430.vert",
97 "spv.accessChain.frag",
98 "spv.aggOps.frag",
99 "spv.always-discard.frag",
100 "spv.always-discard2.frag",
101 "spv.bitCast.frag",
102 "spv.bool.vert",
103 "spv.boolInBlock.frag",
104 "spv.branch-return.vert",
105 "spv.conditionalDiscard.frag",
106 "spv.conversion.frag",
107 "spv.dataOut.frag",
108 "spv.dataOutIndirect.frag",
109 "spv.dataOutIndirect.vert",
110 "spv.deepRvalue.frag",
111 "spv.depthOut.frag",
112 "spv.discard-dce.frag",
113 "spv.doWhileLoop.frag",
114 "spv.earlyReturnDiscard.frag",
115 "spv.flowControl.frag",
116 "spv.forLoop.frag",
117 "spv.forwardFun.frag",
118 "spv.functionCall.frag",
119 "spv.functionSemantics.frag",
120 "spv.interpOps.frag",
121 "spv.layoutNested.vert",
122 "spv.length.frag",
123 "spv.localAggregates.frag",
124 "spv.loops.frag",
125 "spv.loopsArtificial.frag",
126 "spv.matFun.vert",
127 "spv.matrix.frag",
128 "spv.matrix2.frag",
129 "spv.memoryQualifier.frag",
130 "spv.merge-unreachable.frag",
131 "spv.newTexture.frag",
132 "spv.noDeadDecorations.vert",
133 "spv.nonSquare.vert",
134 "spv.Operations.frag",
135 "spv.intOps.vert",
136 "spv.precision.frag",
137 "spv.prepost.frag",
138 "spv.qualifiers.vert",
139 "spv.shiftOps.frag",
140 "spv.simpleFunctionCall.frag",
141 "spv.simpleMat.vert",
142 "spv.sparseTexture.frag",
143 "spv.sparseTextureClamp.frag",
144 "spv.structAssignment.frag",
145 "spv.structDeref.frag",
146 "spv.structure.frag",
147 "spv.switch.frag",
148 "spv.swizzle.frag",
149 "spv.test.frag",
150 "spv.test.vert",
151 "spv.texture.frag",
152 "spv.texture.vert",
153 "spv.image.frag",
154 "spv.types.frag",
155 "spv.uint.frag",
156 "spv.uniformArray.frag",
157 "spv.variableArrayIndex.frag",
158 "spv.varyingArray.frag",
159 "spv.varyingArrayIndirect.frag",
160 "spv.voidFunction.frag",
161 "spv.whileLoop.frag",
162 "spv.AofA.frag",
163 "spv.queryL.frag",
164 "spv.separate.frag",
165 "spv.shortCircuit.frag",
166 "spv.pushConstant.vert",
167 "spv.subpass.frag",
168 "spv.specConstant.vert",
169 "spv.specConstant.comp",
170 "spv.specConstantComposite.vert",
171 })),
172 FileNameAsCustomTestName
173 );
174
175 INSTANTIATE_TEST_CASE_P(
176 Glsl, VulkanSemantics,
177 ::testing::ValuesIn(std::vector<std::string>({
178 "vulkan.frag",
179 "vulkan.vert",
180 "vulkan.comp",
181 })),
182 FileNameAsCustomTestName
183 );
184 // clang-format on
185
186 } // anonymous namespace
187 } // namespace glslangtest
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include "TestFixture.h"
35
36 namespace glslangtest {
37
38 std::string FileNameAsCustomTestName(
39 const ::testing::TestParamInfo<std::string>& info)
40 {
41 std::string name = info.param;
42 // A valid test case suffix cannot have '.' and '-' inside.
43 std::replace(name.begin(), name.end(), '.', '_');
44 std::replace(name.begin(), name.end(), '-', '_');
45 return name;
46 }
47
48 EShLanguage GetGlslLanguageForStage(const std::string& stage)
49 {
50 if (stage == "vert") {
51 return EShLangVertex;
52 } else if (stage == "tesc") {
53 return EShLangTessControl;
54 } else if (stage == "tese") {
55 return EShLangTessEvaluation;
56 } else if (stage == "geom") {
57 return EShLangGeometry;
58 } else if (stage == "frag") {
59 return EShLangFragment;
60 } else if (stage == "comp") {
61 return EShLangCompute;
62 } else {
63 assert(0 && "Unknown shader stage");
64 return EShLangCount;
65 }
66 }
67
68 EShMessages GetSpirvMessageOptionsForSemanticsAndTarget(Semantics semantics,
69 Target target)
70 {
71 EShMessages result = EShMsgDefault;
72
73 switch (target) {
74 case Target::AST:
75 result = EShMsgAST;
76 break;
77 case Target::Spirv:
78 result = EShMsgSpvRules;
79 break;
80 };
81
82 switch (semantics) {
83 case Semantics::OpenGL:
84 break;
85 case Semantics::Vulkan:
86 result = static_cast<EShMessages>(result | EShMsgVulkanRules);
87 break;
88 }
89
90 return result;
91 }
92
93 std::pair<bool, std::string> ReadFile(const std::string& path)
94 {
95 std::ifstream fstream(path, std::ios::in);
96 if (fstream) {
97 std::string contents;
98 fstream.seekg(0, std::ios::end);
99 contents.reserve(fstream.tellg());
100 fstream.seekg(0, std::ios::beg);
101 contents.assign((std::istreambuf_iterator<char>(fstream)),
102 std::istreambuf_iterator<char>());
103 return std::make_pair(true, contents);
104 }
105 return std::make_pair(false, "");
106 }
107
108 bool WriteFile(const std::string& path, const std::string& contents)
109 {
110 std::ofstream fstream(path, std::ios::out);
111 if (!fstream) return false;
112 fstream << contents;
113 fstream.flush();
114 return true;
115 }
116
117 std::string GetSuffix(const std::string& name)
118 {
119 const size_t pos = name.rfind('.');
120 return (pos == std::string::npos) ? "" : name.substr(name.rfind('.') + 1);
121 }
122
123 } // namespace glslangtest
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #ifndef GLSLANG_GTESTS_TEST_FIXTURE_H
35 #define GLSLANG_GTESTS_TEST_FIXTURE_H
36
37 #include <stdint.h>
38 #include <fstream>
39 #include <sstream>
40 #include <streambuf>
41 #include <tuple>
42
43 #include <gtest/gtest.h>
44
45 #include "SPIRV/GlslangToSpv.h"
46 #include "SPIRV/disassemble.h"
47 #include "SPIRV/doc.h"
48 #include "StandAlone/DefaultResourceLimits.h"
49 #include "glslang/Public/ShaderLang.h"
50
51 #include "Initializer.h"
52 #include "Settings.h"
53
54 // We need CMake to provide us the absolute path to the directory containing
55 // test files, so we are certain to find those files no matter where the test
56 // harness binary is generated. This provides out-of-source build capability.
57 #ifndef GLSLANG_TEST_DIRECTORY
58 #error \
59 "GLSLANG_TEST_DIRECTORY needs to be defined for gtest to locate test files."
60 #endif
61
62 namespace glslangtest {
63
64 // This function is used to provide custom test name suffixes based on the
65 // shader source file names. Otherwise, the test name suffixes will just be
66 // numbers, which are not quite obvious.
67 std::string FileNameAsCustomTestName(
68 const ::testing::TestParamInfo<std::string>& info);
69
70 // Enum for shader compilation semantics.
71 enum class Semantics {
72 OpenGL,
73 Vulkan,
74 };
75
76 // Enum for compilation target.
77 enum class Target {
78 AST,
79 Spirv,
80 };
81
82 EShLanguage GetGlslLanguageForStage(const std::string& stage);
83
84 EShMessages GetSpirvMessageOptionsForSemanticsAndTarget(Semantics semantics,
85 Target target);
86
87 // Reads the content of the file at the given |path|. On success, returns true
88 // and the contents; otherwise, returns false and an empty string.
89 std::pair<bool, std::string> ReadFile(const std::string& path);
90
91 // Writes the given |contents| into the file at the given |path|. Returns true
92 // on successful output.
93 bool WriteFile(const std::string& path, const std::string& contents);
94
95 // Returns the suffix of the given |name|.
96 std::string GetSuffix(const std::string& name);
97
98 // Base class for glslang integration tests. It contains many handy utility-like
99 // methods such as reading shader source files, compiling into AST/SPIR-V, and
100 // comparing with expected outputs.
101 //
102 // To write value-Parameterized tests:
103 // using ValueParamTest = GlslangTest<::testing::TestWithParam<std::string>>;
104 // To use as normal fixture:
105 // using FixtureTest = GlslangTest<::testing::Test>;
106 template <typename GT>
107 class GlslangTest : public GT {
108 public:
109 GlslangTest()
110 : defaultVersion(100),
111 defaultProfile(ENoProfile),
112 forceVersionProfile(false),
113 isForwardCompatible(false) {}
114
115 // Tries to load the contents from the file at the given |path|. On success,
116 // writes the contents into |contents|. On failure, errors out.
117 void tryLoadFile(const std::string& path, const std::string& tag,
118 std::string* contents)
119 {
120 bool fileReadOk;
121 std::tie(fileReadOk, *contents) = ReadFile(path);
122 ASSERT_TRUE(fileReadOk) << "Cannot open " << tag << " file: " << path;
123 }
124
125 // Checks the equality of |expected| and |real|. If they are not equal,
126 // write
127 // |real| to the given file named as |fname| if update mode is on.
128 void checkEqAndUpdateIfRequested(const std::string& expected,
129 const std::string& real,
130 const std::string& fname)
131 {
132 // In order to output the message we want under proper circumstances, we
133 // need the following operator<< stuff.
134 EXPECT_EQ(expected, real)
135 << (GlobalTestSettings.updateMode
136 ? ("Mismatch found and update mode turned on - "
137 "flushing expected result output.")
138 : "");
139
140 // Update the expected output file if requested.
141 // It looks weird to duplicate the comparison between expected_output
142 // and
143 // stream.str(). However, if creating a variable for the comparison
144 // result,
145 // we cannot have pretty print of the string diff in the above.
146 if (GlobalTestSettings.updateMode && expected != real) {
147 EXPECT_TRUE(WriteFile(fname, real)) << "Flushing failed";
148 }
149 }
150
151 // A struct for holding all the information returned by glslang compilation
152 // and linking.
153 struct GlslangResult {
154 const std::string compilationOutput;
155 const std::string compilationError;
156 const std::string linkingOutput;
157 const std::string linkingError;
158 const std::string spirv; // Optional SPIR-V disassembly text.
159 };
160
161 // Compiles and linkes the given GLSL |source| code of the given shader
162 // |stage| into the given |target| under the given |semantics|. Returns
163 // a GlslangResult instance containing all the information generated
164 // during the process. If |target| is Target::Spirv, also disassembles
165 // the result and returns disassembly text.
166 GlslangResult compileGlsl(const std::string& source,
167 const std::string& stage, Semantics semantics,
168 Target target)
169 {
170 const char* shaderStrings = source.data();
171 const int shaderLengths = static_cast<int>(source.size());
172 const EShLanguage language = GetGlslLanguageForStage(stage);
173
174 glslang::TShader shader(language);
175 shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
176 const EShMessages messages =
177 GetSpirvMessageOptionsForSemanticsAndTarget(semantics, target);
178 // Reinitialize glslang if the semantics change.
179 GlslangInitializer::InitializationToken token =
180 GlobalTestSettings.initializer->acquire(messages);
181 bool success =
182 shader.parse(&glslang::DefaultTBuiltInResource, defaultVersion,
183 isForwardCompatible, messages);
184
185 glslang::TProgram program;
186 program.addShader(&shader);
187 success &= program.link(messages);
188
189 if (success && target == Target::Spirv) {
190 std::vector<uint32_t> spirv_binary;
191 glslang::GlslangToSpv(*program.getIntermediate(language),
192 spirv_binary);
193
194 std::ostringstream disassembly_stream;
195 spv::Parameterize();
196 spv::Disassemble(disassembly_stream, spirv_binary);
197 return {shader.getInfoLog(), shader.getInfoDebugLog(),
198 program.getInfoLog(), program.getInfoDebugLog(),
199 disassembly_stream.str()};
200 } else {
201 return {shader.getInfoLog(), shader.getInfoDebugLog(),
202 program.getInfoLog(), program.getInfoDebugLog(), ""};
203 }
204 }
205
206 void loadFileCompileAndCheck(const std::string& testDir,
207 const std::string& testName,
208 Semantics semantics, Target target)
209 {
210 const std::string inputFname = testDir + "/" + testName;
211 const std::string expectedOutputFname =
212 testDir + "/baseResults/" + testName + ".out";
213 std::string input, expectedOutput;
214
215 tryLoadFile(inputFname, "input", &input);
216 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
217
218 GlslangResult result =
219 compileGlsl(input, GetSuffix(testName), semantics, target);
220
221 // Generate the hybrid output in the way of glslangValidator.
222 std::ostringstream stream;
223
224 const auto outputIfNotEmpty = [&stream](const std::string& str) {
225 if (!str.empty()) stream << str << "\n";
226 };
227
228 stream << testName << "\n";
229 outputIfNotEmpty(result.compilationOutput);
230 outputIfNotEmpty(result.compilationError);
231 outputIfNotEmpty(result.linkingOutput);
232 outputIfNotEmpty(result.linkingError);
233 if (target == Target::Spirv) {
234 stream
235 << (result.spirv.empty()
236 ? "SPIR-V is not generated for failed compile or link\n"
237 : result.spirv);
238 }
239
240 checkEqAndUpdateIfRequested(expectedOutput, stream.str(),
241 expectedOutputFname);
242 }
243
244 // Preprocesses the given GLSL |source| code. On success, returns true, the
245 // preprocessed shader, and warning messages. Otherwise, returns false, an
246 // empty string, and error messages.
247 std::tuple<bool, std::string, std::string> preprocessGlsl(
248 const std::string& source)
249 {
250 const char* shaderStrings = source.data();
251 const int shaderLengths = static_cast<int>(source.size());
252
253 glslang::TShader shader(EShLangVertex);
254 shader.setStringsWithLengths(&shaderStrings, &shaderLengths, 1);
255 std::string ppShader;
256 glslang::TShader::ForbidInclude includer;
257 const bool success = shader.preprocess(
258 &glslang::DefaultTBuiltInResource, defaultVersion, defaultProfile,
259 forceVersionProfile, isForwardCompatible, EShMsgOnlyPreprocessor,
260 &ppShader, includer);
261
262 std::string log = shader.getInfoLog();
263 log += shader.getInfoDebugLog();
264 if (success) {
265 return std::make_tuple(true, ppShader, log);
266 } else {
267 return std::make_tuple(false, "", log);
268 }
269 }
270
271 void loadFilePreprocessAndCheck(const std::string& testDir,
272 const std::string& testName)
273 {
274 const std::string inputFname = testDir + "/" + testName;
275 const std::string expectedOutputFname =
276 testDir + "/baseResults/" + testName + ".out";
277 const std::string expectedErrorFname =
278 testDir + "/baseResults/" + testName + ".err";
279 std::string input, expectedOutput, expectedError;
280
281 tryLoadFile(inputFname, "input", &input);
282 tryLoadFile(expectedOutputFname, "expected output", &expectedOutput);
283 tryLoadFile(expectedErrorFname, "expected error", &expectedError);
284
285 bool ppOk;
286 std::string output, error;
287 std::tie(ppOk, output, error) = preprocessGlsl(input);
288 if (!output.empty()) output += '\n';
289 if (!error.empty()) error += '\n';
290
291 checkEqAndUpdateIfRequested(expectedOutput, output,
292 expectedOutputFname);
293 checkEqAndUpdateIfRequested(expectedError, error,
294 expectedErrorFname);
295 }
296
297 private:
298 const int defaultVersion;
299 const EProfile defaultProfile;
300 const bool forceVersionProfile;
301 const bool isForwardCompatible;
302 };
303
304 } // namespace glslangtest
305
306 #endif // GLSLANG_GTESTS_TEST_FIXTURE_H
0 //
1 // Copyright (C) 2016 Google, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 //
9 // Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 // POSSIBILITY OF SUCH DAMAGE.
33
34 #include <memory>
35
36 #include <gtest/gtest.h>
37
38 #include "Initializer.h"
39 #include "Settings.h"
40
41 int main(int argc, char** argv)
42 {
43 ::testing::InitGoogleTest(&argc, argv);
44
45 std::unique_ptr<glslangtest::GlslangInitializer> initializer(
46 new glslangtest::GlslangInitializer);
47
48 glslangtest::GlobalTestSettings.initializer = initializer.get();
49
50 for (int i = 1; i < argc; ++i) {
51 if (!strncmp("--update-mode", argv[i], 13)) {
52 glslangtest::GlobalTestSettings.updateMode = true;
53 break;
54 }
55 }
56
57 const int result = RUN_ALL_TESTS();
58
59 glslangtest::GlobalTestSettings.initializer = nullptr;
60
61 return result;
62 }