1 /*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm/gm.h"
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkData.h"
12 #include "include/core/SkFont.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkSize.h"
15 #include "include/core/SkString.h"
16 #include "include/core/SkSurface.h"
17 #include "include/effects/SkGradientShader.h"
18 #include "include/effects/SkImageFilters.h"
19 #include "include/effects/SkRuntimeEffect.h"
20 #include "include/private/SkSLDefines.h" // for kDefaultInlineThreshold
21 #include "include/sksl/DSLCore.h"
22 #include "include/utils/SkRandom.h"
23 #include "src/core/SkRuntimeEffectPriv.h"
24 #include "src/gpu/GrCaps.h"
25 #include "src/gpu/GrDirectContextPriv.h"
26 #include "src/sksl/SkSLCompiler.h"
27 #include "src/sksl/SkSLDehydrator.h"
28 #include "src/sksl/SkSLRehydrator.h"
29 #include "src/sksl/SkSLThreadContext.h"
30 #include "tests/Test.h"
31 #include "tests/TestHarness.h"
32 #include "tools/Resources.h"
33 #include "tools/ToolUtils.h"
34
35 static constexpr int kWidth = 2;
36 static constexpr int kHeight = 2;
37
38 namespace SkSLTestFlags {
39 /** CPU tests must pass on the CPU backend. */
40 static constexpr int CPU = 1 << 0;
41
42 /** CPU_ES3 tests must pass on the CPU backend when "enforce ES2 restrictions" is off. */
43 static constexpr int CPU_ES3 = 1 << 1;
44
45 /** GPU tests must pass on all GPU backends. */
46 static constexpr int GPU = 1 << 2;
47
48 /** GPU_ES3 tests must pass on ES3-compatible GPUs when "enforce ES2 restrictions" is off. */
49 static constexpr int GPU_ES3 = 1 << 3;
50
51 /** SkQP tests will be run in Android/Fuchsia conformance tests with no driver workarounds. */
52 static constexpr int SkQP = 1 << 4;
53 }
54
is_cpu(int flags)55 static constexpr bool is_cpu(int flags) {
56 return flags & (SkSLTestFlags::CPU | SkSLTestFlags::CPU_ES3);
57 }
58
is_gpu(int flags)59 static constexpr bool is_gpu(int flags) {
60 return flags & (SkSLTestFlags::GPU | SkSLTestFlags::GPU_ES3);
61 }
62
is_strict_es2(int flags)63 static constexpr bool is_strict_es2(int flags) {
64 return !(flags & (SkSLTestFlags::CPU_ES3 | SkSLTestFlags::GPU_ES3));
65 }
66
should_run_in_skqp(int flags)67 static bool should_run_in_skqp(int flags) {
68 if (CurrentTestHarnessIsSkQP()) {
69 // Official SkQP builds should only run tests marked with the SkQP flag.
70 return flags & (SkSLTestFlags::SkQP);
71 } else {
72 // Other test binaries (dm/fm) should run every test, regardless of the SkQP flag.
73 return true;
74 }
75 }
76
77 template <typename T>
set_uniform(SkRuntimeShaderBuilder * builder,const char * name,const T & value)78 static void set_uniform(SkRuntimeShaderBuilder* builder, const char* name, const T& value) {
79 SkRuntimeShaderBuilder::BuilderUniform uniform = builder->uniform(name);
80 if (uniform.fVar) {
81 uniform = value;
82 }
83 }
84
85 template <typename T>
set_uniform_array(SkRuntimeShaderBuilder * builder,const char * name,SkSpan<T> values)86 static void set_uniform_array(SkRuntimeShaderBuilder* builder, const char* name, SkSpan<T> values) {
87 SkRuntimeShaderBuilder::BuilderUniform uniform = builder->uniform(name);
88 if (uniform.fVar) {
89 uniform.set(values.data(), values.size());
90 }
91 }
92
load_source(skiatest::Reporter * r,const char * testFile,const char * permutationSuffix)93 static SkString load_source(skiatest::Reporter* r,
94 const char* testFile,
95 const char* permutationSuffix) {
96 SkString resourcePath = SkStringPrintf("sksl/%s", testFile);
97 sk_sp<SkData> shaderData = GetResourceAsData(resourcePath.c_str());
98 if (!shaderData) {
99 ERRORF(r, "%s%s: Unable to load file", testFile, permutationSuffix);
100 return SkString("");
101 }
102 return SkString{reinterpret_cast<const char*>(shaderData->bytes()), shaderData->size()};
103 }
104
test_one_permutation(skiatest::Reporter * r,SkSurface * surface,const char * testFile,const char * permutationSuffix,const SkRuntimeEffect::Options & options)105 static void test_one_permutation(skiatest::Reporter* r,
106 SkSurface* surface,
107 const char* testFile,
108 const char* permutationSuffix,
109 const SkRuntimeEffect::Options& options) {
110 SkString shaderString = load_source(r, testFile, permutationSuffix);
111 if (shaderString.isEmpty()) {
112 return;
113 }
114 SkRuntimeEffect::Result result = SkRuntimeEffect::MakeForShader(shaderString, options);
115 if (!result.effect) {
116 ERRORF(r, "%s%s: %s", testFile, permutationSuffix, result.errorText.c_str());
117 return;
118 }
119
120 static constexpr float kArray[5] = {1, 2, 3, 4, 5};
121
122 SkRuntimeShaderBuilder builder(result.effect);
123 set_uniform(&builder, "colorBlack", SkV4{0, 0, 0, 1});
124 set_uniform(&builder, "colorRed", SkV4{1, 0, 0, 1});
125 set_uniform(&builder, "colorGreen", SkV4{0, 1, 0, 1});
126 set_uniform(&builder, "colorBlue", SkV4{0, 0, 1, 1});
127 set_uniform(&builder, "colorWhite", SkV4{1, 1, 1, 1});
128 set_uniform(&builder, "testInputs", SkV4{-1.25, 0, 0.75, 2.25});
129 set_uniform(&builder, "unknownInput", 1.0f);
130 set_uniform(&builder, "testMatrix2x2", std::array<float,4>{1, 2,
131 3, 4});
132 set_uniform(&builder, "testMatrix3x3", std::array<float,9>{1, 2, 3,
133 4, 5, 6,
134 7, 8, 9});
135 set_uniform(&builder, "testMatrix4x4", std::array<float,16>{1, 2, 3, 4,
136 5, 6, 7, 8,
137 9, 10, 11, 12,
138 13, 14, 15, 16});
139 set_uniform_array(&builder, "testArray", SkMakeSpan(kArray));
140
141 sk_sp<SkShader> shader = builder.makeShader();
142 if (!shader) {
143 ERRORF(r, "%s%s: Unable to build shader", testFile, permutationSuffix);
144 return;
145 }
146
147 surface->getCanvas()->clear(SK_ColorBLACK);
148
149 SkPaint paintShader;
150 paintShader.setShader(shader);
151 surface->getCanvas()->drawRect(SkRect::MakeWH(kWidth, kHeight), paintShader);
152
153 SkBitmap bitmap;
154 REPORTER_ASSERT(r, bitmap.tryAllocPixels(surface->imageInfo()));
155 REPORTER_ASSERT(r, surface->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
156 /*srcX=*/0, /*srcY=*/0));
157
158 bool success = true;
159 SkColor color[kHeight][kWidth];
160 for (int y = 0; y < kHeight; ++y) {
161 for (int x = 0; x < kWidth; ++x) {
162 color[y][x] = bitmap.getColor(x, y);
163 if (color[y][x] != SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00)) {
164 success = false;
165 }
166 }
167 }
168
169 if (!success) {
170 static_assert(kWidth == 2);
171 static_assert(kHeight == 2);
172 ERRORF(r, "Expected: solid green. Actual:\n"
173 "RRGGBBAA RRGGBBAA\n"
174 "%02X%02X%02X%02X %02X%02X%02X%02X\n"
175 "%02X%02X%02X%02X %02X%02X%02X%02X",
176 SkColorGetR(color[0][0]), SkColorGetG(color[0][0]),
177 SkColorGetB(color[0][0]), SkColorGetA(color[0][0]),
178
179 SkColorGetR(color[0][1]), SkColorGetG(color[0][1]),
180 SkColorGetB(color[0][1]), SkColorGetA(color[0][1]),
181
182 SkColorGetR(color[1][0]), SkColorGetG(color[1][0]),
183 SkColorGetB(color[1][0]), SkColorGetA(color[1][0]),
184
185 SkColorGetR(color[1][1]), SkColorGetG(color[1][1]),
186 SkColorGetB(color[1][1]), SkColorGetA(color[1][1]));
187 }
188 }
189
test_permutations(skiatest::Reporter * r,SkSurface * surface,const char * testFile,bool strictES2)190 static void test_permutations(skiatest::Reporter* r,
191 SkSurface* surface,
192 const char* testFile,
193 bool strictES2) {
194 SkRuntimeEffect::Options options =
195 strictES2 ? SkRuntimeEffect::Options{} : SkRuntimeEffectPriv::ES3Options();
196 options.forceNoInline = false;
197 test_one_permutation(r, surface, testFile, "", options);
198
199 options.forceNoInline = true;
200 test_one_permutation(r, surface, testFile, " (NoInline)", options);
201 }
202
test_cpu(skiatest::Reporter * r,const char * testFile,int flags)203 static void test_cpu(skiatest::Reporter* r, const char* testFile, int flags) {
204 bool shouldRunCPU = (flags & SkSLTestFlags::CPU);
205 bool shouldRunCPU_ES3 = (flags & SkSLTestFlags::CPU_ES3);
206 SkASSERT(shouldRunCPU || shouldRunCPU_ES3);
207
208 // Create a raster-backed surface.
209 const SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
210 sk_sp<SkSurface> surface(SkSurface::MakeRaster(info));
211
212 if (shouldRunCPU) {
213 test_permutations(r, surface.get(), testFile, /*strictES2=*/true);
214 }
215 if (shouldRunCPU_ES3) {
216 test_permutations(r, surface.get(), testFile, /*strictES2=*/false);
217 }
218 }
219
test_gpu(skiatest::Reporter * r,GrDirectContext * ctx,const char * testFile,int flags)220 static void test_gpu(skiatest::Reporter* r, GrDirectContext* ctx, const char* testFile, int flags) {
221 // If this is an ES3-only test on a GPU which doesn't support SkSL ES3, return immediately.
222 bool shouldRunGPU = (flags & SkSLTestFlags::GPU);
223 bool shouldRunGPU_ES3 = (flags & SkSLTestFlags::GPU_ES3) &&
224 ctx->priv().caps()->shaderCaps()->supportsSkSLES3();
225 if (!shouldRunGPU && !shouldRunGPU_ES3) {
226 return;
227 }
228 // Create a GPU-backed surface.
229 const SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
230 sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
231
232 if (shouldRunGPU) {
233 test_permutations(r, surface.get(), testFile, /*strictES2=*/true);
234 }
235 if (shouldRunGPU_ES3) {
236 test_permutations(r, surface.get(), testFile, /*strictES2=*/false);
237 }
238 }
239
test_clone(skiatest::Reporter * r,const char * testFile,int flags)240 static void test_clone(skiatest::Reporter* r, const char* testFile, int flags) {
241 SkString shaderString = load_source(r, testFile, "");
242 if (shaderString.isEmpty()) {
243 return;
244 }
245 std::unique_ptr<SkSL::ShaderCaps> caps = SkSL::ShaderCapsFactory::Standalone();
246 SkSL::Program::Settings settings;
247 settings.fAllowVarDeclarationCloneForTesting = true;
248 settings.fEnforceES2Restrictions = is_strict_es2(flags);
249 SkSL::Compiler compiler(caps.get());
250 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
251 SkSL::ProgramKind::kRuntimeShader, shaderString.c_str(), settings);
252 if (!program) {
253 ERRORF(r, "%s", compiler.errorText().c_str());
254 return;
255 }
256 // Starting DSL allows us to get access to the ThreadContext::Settings
257 SkSL::dsl::Start(&compiler, SkSL::ProgramKind::kFragment, settings);
258 for (const std::unique_ptr<SkSL::ProgramElement>& element : program->fOwnedElements) {
259 std::string original = element->description();
260 std::string cloned = element->clone()->description();
261 REPORTER_ASSERT(r, original == cloned,
262 "Mismatch after clone!\nOriginal: %s\nCloned: %s\n", original.c_str(),
263 cloned.c_str());
264 }
265 SkSL::dsl::End();
266 }
267
test_rehydrate(skiatest::Reporter * r,const char * testFile,int flags)268 static void test_rehydrate(skiatest::Reporter* r, const char* testFile, int flags) {
269 SkString shaderString = load_source(r, testFile, "");
270 if (shaderString.isEmpty()) {
271 return;
272 }
273 std::unique_ptr<SkSL::ShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
274 SkSL::Compiler compiler(caps.get());
275 SkSL::Program::Settings settings;
276 settings.fEnforceES2Restrictions = is_strict_es2(flags);
277 // Inlining causes problems because it can create expressions like bool(1) that can't be
278 // directly instantiated. After a dehydrate/recycle pass, that expression simply becomes "true"
279 // due to optimization - which is fine, but would cause us to fail an equality comparison. We
280 // disable inlining to avoid this issue.
281 settings.fInlineThreshold = 0;
282 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
283 SkSL::ProgramKind::kRuntimeShader, shaderString.c_str(), settings);
284 if (!program) {
285 ERRORF(r, "%s", compiler.errorText().c_str());
286 return;
287 }
288 SkSL::Dehydrator dehydrator;
289 dehydrator.write(*program);
290 SkSL::StringStream stream;
291 dehydrator.finish(stream);
292
293 SkSL::Rehydrator rehydrator(compiler, (const uint8_t*) stream.str().data(),
294 stream.str().length());
295 std::unique_ptr<SkSL::Program> rehydrated = rehydrator.program();
296 REPORTER_ASSERT(r, rehydrated->description() == program->description(),
297 "Mismatch between original and dehydrated/rehydrated:\n-- Original:\n%s\n"
298 "-- Rehydrated:\n%s", program->description().c_str(),
299 rehydrated->description().c_str());
300 }
301
302 #define SKSL_TEST(flags, name, path) \
303 DEF_CONDITIONAL_TEST(SkSL##name##_CPU, r, is_cpu(flags) && should_run_in_skqp(flags)) { \
304 test_cpu(r, path, flags); \
305 } \
306 DEF_CONDITIONAL_GPUTEST_FOR_RENDERING_CONTEXTS( \
307 SkSL##name##_GPU, r, ctxInfo, is_gpu(flags) && should_run_in_skqp(flags)) { \
308 test_gpu(r, ctxInfo.directContext(), path, flags); \
309 } \
310 DEF_TEST(SkSL##name##_Clone, r) { test_clone(r, path, flags); } \
311 DEF_TEST(SkSL##name##_Rehydrate, r) { test_rehydrate(r, path, flags); }
312
313 /**
314 * Test flags:
315 * - CPU: this test should pass on the CPU backend
316 * - CPU_ES3: this test should pass on the CPU backend when "enforce ES2 restrictions" is off
317 * - GPU: this test should pass on the GPU backends
318 * - GPU_ES3: this test should pass on an ES3-compatible GPU when "enforce ES2 restrictions" is off
319 * - SkQP: Android CTS (go/wtf/cts) enforces that devices must pass this test
320 */
321
322 // clang-format off
323
324 using namespace SkSLTestFlags;
325
326 SKSL_TEST(CPU + GPU + SkQP, ArraySizeFolding, "folding/ArraySizeFolding.sksl")
327 SKSL_TEST(CPU + GPU + SkQP, AssignmentOps, "folding/AssignmentOps.sksl")
328 SKSL_TEST(CPU + GPU + SkQP, BoolFolding, "folding/BoolFolding.sksl")
329 SKSL_TEST(CPU + GPU + SkQP, CastFolding, "folding/CastFolding.sksl")
330 SKSL_TEST(CPU + GPU + SkQP, IntFoldingES2, "folding/IntFoldingES2.sksl")
331 SKSL_TEST(GPU_ES3, IntFoldingES3, "folding/IntFoldingES3.sksl")
332 SKSL_TEST(CPU + GPU + SkQP, FloatFolding, "folding/FloatFolding.sksl")
333 SKSL_TEST(CPU + GPU + SkQP, MatrixFoldingES2, "folding/MatrixFoldingES2.sksl")
334 SKSL_TEST(GPU_ES3, MatrixFoldingES3, "folding/MatrixFoldingES3.sksl")
335 SKSL_TEST(CPU + GPU + SkQP, Negation, "folding/Negation.sksl")
336 SKSL_TEST(CPU + GPU + SkQP, SelfAssignment, "folding/SelfAssignment.sksl")
337 SKSL_TEST(CPU + GPU + SkQP, ShortCircuitBoolFolding, "folding/ShortCircuitBoolFolding.sksl")
338 SKSL_TEST(CPU + GPU + SkQP, SwitchCaseFolding, "folding/SwitchCaseFolding.sksl")
339 SKSL_TEST(CPU + GPU + SkQP, SwizzleFolding, "folding/SwizzleFolding.sksl")
340 SKSL_TEST(CPU + GPU + SkQP, VectorScalarFolding, "folding/VectorScalarFolding.sksl")
341 SKSL_TEST(CPU + GPU + SkQP, VectorVectorFolding, "folding/VectorVectorFolding.sksl")
342
343 SKSL_TEST(GPU_ES3, DoWhileBodyMustBeInlinedIntoAScope, "inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl")
344 SKSL_TEST(GPU_ES3, DoWhileTestCannotBeInlined, "inliner/DoWhileTestCannotBeInlined.sksl")
345 SKSL_TEST(CPU + GPU + SkQP, ForBodyMustBeInlinedIntoAScope, "inliner/ForBodyMustBeInlinedIntoAScope.sksl")
346 SKSL_TEST(GPU_ES3, ForInitializerExpressionsCanBeInlined, "inliner/ForInitializerExpressionsCanBeInlined.sksl")
347 SKSL_TEST(CPU + GPU + SkQP, ForWithoutReturnInsideCanBeInlined, "inliner/ForWithoutReturnInsideCanBeInlined.sksl")
348 SKSL_TEST(CPU + GPU + SkQP, ForWithReturnInsideCannotBeInlined, "inliner/ForWithReturnInsideCannotBeInlined.sksl")
349 SKSL_TEST(CPU + GPU + SkQP, IfBodyMustBeInlinedIntoAScope, "inliner/IfBodyMustBeInlinedIntoAScope.sksl")
350 SKSL_TEST(CPU + GPU + SkQP, IfElseBodyMustBeInlinedIntoAScope, "inliner/IfElseBodyMustBeInlinedIntoAScope.sksl")
351 SKSL_TEST(CPU + GPU + SkQP, IfElseChainWithReturnsCanBeInlined, "inliner/IfElseChainWithReturnsCanBeInlined.sksl")
352 SKSL_TEST(CPU + GPU + SkQP, IfTestCanBeInlined, "inliner/IfTestCanBeInlined.sksl")
353 SKSL_TEST(CPU + GPU + SkQP, IfWithReturnsCanBeInlined, "inliner/IfWithReturnsCanBeInlined.sksl")
354 SKSL_TEST(CPU + GPU + SkQP, InlineKeywordOverridesThreshold, "inliner/InlineKeywordOverridesThreshold.sksl")
355 SKSL_TEST(CPU + GPU + SkQP, InlinerAvoidsVariableNameOverlap, "inliner/InlinerAvoidsVariableNameOverlap.sksl")
356 SKSL_TEST(CPU + GPU + SkQP, InlinerElidesTempVarForReturnsInsideBlock, "inliner/InlinerElidesTempVarForReturnsInsideBlock.sksl")
357 SKSL_TEST(CPU + GPU + SkQP, InlinerUsesTempVarForMultipleReturns, "inliner/InlinerUsesTempVarForMultipleReturns.sksl")
358 SKSL_TEST(CPU + GPU + SkQP, InlinerUsesTempVarForReturnsInsideBlockWithVar, "inliner/InlinerUsesTempVarForReturnsInsideBlockWithVar.sksl")
359 SKSL_TEST(CPU + GPU + SkQP, InlineThreshold, "inliner/InlineThreshold.sksl")
360 SKSL_TEST(CPU + GPU + SkQP, InlineWithModifiedArgument, "inliner/InlineWithModifiedArgument.sksl")
361 SKSL_TEST(CPU + GPU + SkQP, InlineWithNestedBigCalls, "inliner/InlineWithNestedBigCalls.sksl")
362 SKSL_TEST(CPU + GPU + SkQP, InlineWithUnmodifiedArgument, "inliner/InlineWithUnmodifiedArgument.sksl")
363 SKSL_TEST(CPU + GPU + SkQP, InlineWithUnnecessaryBlocks, "inliner/InlineWithUnnecessaryBlocks.sksl")
364 SKSL_TEST(CPU + GPU + SkQP, NoInline, "inliner/NoInline.sksl")
365 SKSL_TEST(CPU + GPU + SkQP, ShortCircuitEvaluationsCannotInlineRightHandSide, "inliner/ShortCircuitEvaluationsCannotInlineRightHandSide.sksl")
366 SKSL_TEST(GPU_ES3, StaticSwitchInline, "inliner/StaticSwitch.sksl")
367 SKSL_TEST(CPU + GPU + SkQP, StructsCanBeInlinedSafely, "inliner/StructsCanBeInlinedSafely.sksl")
368 SKSL_TEST(CPU + GPU + SkQP, SwizzleCanBeInlinedDirectly, "inliner/SwizzleCanBeInlinedDirectly.sksl")
369 SKSL_TEST(CPU + GPU + SkQP, TernaryResultsCannotBeInlined, "inliner/TernaryResultsCannotBeInlined.sksl")
370 SKSL_TEST(CPU + GPU + SkQP, TernaryTestCanBeInlined, "inliner/TernaryTestCanBeInlined.sksl")
371 SKSL_TEST(CPU + GPU + SkQP, TrivialArgumentsInlineDirectly, "inliner/TrivialArgumentsInlineDirectly.sksl")
372 SKSL_TEST(GPU_ES3, WhileBodyMustBeInlinedIntoAScope, "inliner/WhileBodyMustBeInlinedIntoAScope.sksl")
373 SKSL_TEST(GPU_ES3, WhileTestCannotBeInlined, "inliner/WhileTestCannotBeInlined.sksl")
374
375 SKSL_TEST(CPU + GPU + SkQP, IntrinsicAbsFloat, "intrinsics/AbsFloat.sksl")
376 SKSL_TEST(GPU_ES3, IntrinsicAbsInt, "intrinsics/AbsInt.sksl")
377 SKSL_TEST(CPU + GPU + SkQP, IntrinsicCeil, "intrinsics/Ceil.sksl")
378 SKSL_TEST(GPU_ES3, IntrinsicDeterminant, "intrinsics/Determinant.sksl")
379 SKSL_TEST(GPU_ES3, IntrinsicDFdx, "intrinsics/DFdx.sksl")
380 SKSL_TEST(GPU_ES3, IntrinsicDFdy, "intrinsics/DFdy.sksl")
381 SKSL_TEST(GPU_ES3, IntrinsicFloatBitsToInt, "intrinsics/FloatBitsToInt.sksl")
382 SKSL_TEST(GPU_ES3, IntrinsicFloatBitsToUint, "intrinsics/FloatBitsToUint.sksl")
383 SKSL_TEST(GPU_ES3, IntrinsicFwidth, "intrinsics/Fwidth.sksl")
384 SKSL_TEST(GPU_ES3, IntrinsicIntBitsToFloat, "intrinsics/IntBitsToFloat.sksl")
385 SKSL_TEST(GPU_ES3, IntrinsicIsInf, "intrinsics/IsInf.sksl")
386 SKSL_TEST(GPU_ES3, IntrinsicClampInt, "intrinsics/ClampInt.sksl")
387 SKSL_TEST(GPU_ES3, IntrinsicClampUInt, "intrinsics/ClampUInt.sksl")
388 SKSL_TEST(CPU + GPU + SkQP, IntrinsicClampFloat, "intrinsics/ClampFloat.sksl")
389 SKSL_TEST(CPU + GPU + SkQP, IntrinsicMatrixCompMultES2, "intrinsics/MatrixCompMultES2.sksl")
390 SKSL_TEST(GPU_ES3, IntrinsicMatrixCompMultES3, "intrinsics/MatrixCompMultES3.sksl")
391 SKSL_TEST(CPU + GPU + SkQP, IntrinsicMaxFloat, "intrinsics/MaxFloat.sksl")
392 SKSL_TEST(GPU_ES3, IntrinsicMaxInt, "intrinsics/MaxInt.sksl")
393 SKSL_TEST(CPU + GPU + SkQP, IntrinsicMinFloat, "intrinsics/MinFloat.sksl")
394 SKSL_TEST(GPU_ES3, IntrinsicMinInt, "intrinsics/MinInt.sksl")
395 SKSL_TEST(CPU + GPU + SkQP, IntrinsicMixFloat, "intrinsics/MixFloat.sksl")
396 SKSL_TEST(GPU_ES3, IntrinsicModf, "intrinsics/Modf.sksl")
397 SKSL_TEST(GPU_ES3, IntrinsicOuterProduct, "intrinsics/OuterProduct.sksl")
398 // Fails on Mac OpenGL + Radeon 5300M (skia:12434)
399 // SKSL_TEST(GPU_ES3, IntrinsicPackUnorm2x16, "intrinsics/PackUnorm2x16.sksl")
400 SKSL_TEST(GPU_ES3, IntrinsicRound, "intrinsics/Round.sksl")
401 SKSL_TEST(GPU_ES3, IntrinsicRoundEven, "intrinsics/RoundEven.sksl")
402 SKSL_TEST(CPU + GPU + SkQP, IntrinsicSignFloat, "intrinsics/SignFloat.sksl")
403 SKSL_TEST(GPU_ES3, IntrinsicSignInt, "intrinsics/SignInt.sksl")
404 SKSL_TEST(CPU + GPU + SkQP, IntrinsicStep, "intrinsics/Step.sksl")
405 SKSL_TEST(GPU_ES3, IntrinsicTrunc, "intrinsics/Trunc.sksl")
406 SKSL_TEST(GPU_ES3, IntrinsicTranspose, "intrinsics/Transpose.sksl")
407 SKSL_TEST(GPU_ES3, IntrinsicUintBitsToFloat, "intrinsics/UintBitsToFloat.sksl")
408
409 SKSL_TEST(GPU_ES3, ArrayNarrowingConversions, "runtime/ArrayNarrowingConversions.rts")
410 SKSL_TEST(CPU + GPU + SkQP, LoopFloat, "runtime/LoopFloat.rts")
411 SKSL_TEST(CPU + GPU + SkQP, LoopInt, "runtime/LoopInt.rts")
412 SKSL_TEST(CPU + GPU + SkQP, QualifierOrder, "runtime/QualifierOrder.rts")
413 SKSL_TEST(CPU + GPU + SkQP, PrecisionQualifiers, "runtime/PrecisionQualifiers.rts")
414
415 // These tests specifically rely the behavior of NaN values, but some older GPUs do not reliably
416 // implement full IEEE support (skia:12977). They also rely on equality operators on array types
417 // which are not available in GLSL ES 1.00. Therefore these tests are restricted to run on CPU and
418 // with "strict ES2 mode" disabled.
419 SKSL_TEST(CPU_ES3, RecursiveComparison_Arrays, "runtime/RecursiveComparison_Arrays.rts")
420 SKSL_TEST(CPU_ES3, RecursiveComparison_Structs, "runtime/RecursiveComparison_Structs.rts")
421 SKSL_TEST(CPU_ES3, RecursiveComparison_Types, "runtime/RecursiveComparison_Types.rts")
422 SKSL_TEST(CPU_ES3, RecursiveComparison_Vectors, "runtime/RecursiveComparison_Vectors.rts")
423
424 SKSL_TEST(GPU_ES3, ArrayCast, "shared/ArrayCast.sksl")
425 SKSL_TEST(GPU_ES3, ArrayComparison, "shared/ArrayComparison.sksl")
426 SKSL_TEST(GPU_ES3, ArrayConstructors, "shared/ArrayConstructors.sksl")
427 SKSL_TEST(GPU_ES3, ArrayFollowedByScalar, "shared/ArrayFollowedByScalar.sksl")
428 SKSL_TEST(CPU + GPU + SkQP, ArrayTypes, "shared/ArrayTypes.sksl")
429 SKSL_TEST(CPU + GPU + SkQP, Assignment, "shared/Assignment.sksl")
430 SKSL_TEST(CPU + GPU + SkQP, CastsRoundTowardZero, "shared/CastsRoundTowardZero.sksl")
431 SKSL_TEST(CPU + GPU + SkQP, CommaMixedTypes, "shared/CommaMixedTypes.sksl")
432 SKSL_TEST(CPU + GPU + SkQP, CommaSideEffects, "shared/CommaSideEffects.sksl")
433 SKSL_TEST(CPU + GPU + SkQP, ConstantIf, "shared/ConstantIf.sksl")
434 SKSL_TEST(GPU_ES3, ConstArray, "shared/ConstArray.sksl")
435 SKSL_TEST(CPU + GPU + SkQP, ConstVariableComparison, "shared/ConstVariableComparison.sksl")
436 SKSL_TEST(GPU_ES3, DeadLoopVariable, "shared/DeadLoopVariable.sksl")
437 SKSL_TEST(CPU + GPU + SkQP, DeadIfStatement, "shared/DeadIfStatement.sksl")
438 SKSL_TEST(CPU + GPU + SkQP, DeadReturn, "shared/DeadReturn.sksl")
439 // TODO(skia:12012): some Radeons crash when compiling this code; disable them.
440 // SKSL_TEST(GPU_ES3, SkSLDeadReturnES3, "shared/DeadReturnES3.sksl")
441 SKSL_TEST(CPU + GPU + SkQP, DeadStripFunctions, "shared/DeadStripFunctions.sksl")
442 SKSL_TEST(CPU + GPU + SkQP, DependentInitializers, "shared/DependentInitializers.sksl")
443 SKSL_TEST(GPU_ES3, DoWhileControlFlow, "shared/DoWhileControlFlow.sksl")
444 SKSL_TEST(CPU + GPU + SkQP, EmptyBlocksES2, "shared/EmptyBlocksES2.sksl")
445 SKSL_TEST(GPU_ES3, EmptyBlocksES3, "shared/EmptyBlocksES3.sksl")
446 SKSL_TEST(CPU + GPU + SkQP, ForLoopControlFlow, "shared/ForLoopControlFlow.sksl")
447 SKSL_TEST(CPU + GPU + SkQP, FunctionAnonymousParameters, "shared/FunctionAnonymousParameters.sksl")
448 SKSL_TEST(CPU + GPU + SkQP, FunctionArgTypeMatch, "shared/FunctionArgTypeMatch.sksl")
449 SKSL_TEST(CPU + GPU + SkQP, FunctionReturnTypeMatch, "shared/FunctionReturnTypeMatch.sksl")
450 SKSL_TEST(CPU + GPU + SkQP, Functions, "shared/Functions.sksl")
451 SKSL_TEST(CPU + GPU + SkQP, FunctionPrototype, "shared/FunctionPrototype.sksl")
452 SKSL_TEST(CPU + GPU + SkQP, GeometricIntrinsics, "shared/GeometricIntrinsics.sksl")
453 SKSL_TEST(CPU + GPU + SkQP, HelloWorld, "shared/HelloWorld.sksl")
454 SKSL_TEST(CPU + GPU + SkQP, Hex, "shared/Hex.sksl")
455 SKSL_TEST(GPU_ES3, HexUnsigned, "shared/HexUnsigned.sksl")
456 SKSL_TEST(CPU + GPU + SkQP, InoutParameters, "shared/InoutParameters.sksl")
457 SKSL_TEST(CPU + GPU + SkQP, Matrices, "shared/Matrices.sksl")
458 SKSL_TEST(GPU_ES3, MatricesNonsquare, "shared/MatricesNonsquare.sksl")
459 // TODO(skia:12443) These tests actually don't work on MANY devices. The GLSL SkQP suite
460 // does a terrible job of enforcing this rule. We still test them on CPU.
461 SKSL_TEST(CPU, MatrixConstructorsES2, "shared/MatrixConstructorsES2.sksl")
462 SKSL_TEST(CPU_ES3, MatrixConstructorsES3, "shared/MatrixConstructorsES3.sksl")
463 SKSL_TEST(CPU + GPU + SkQP, MatrixEquality, "shared/MatrixEquality.sksl")
464 SKSL_TEST(CPU + GPU + SkQP, MatrixScalarMath, "shared/MatrixScalarMath.sksl")
465 SKSL_TEST(CPU + GPU + SkQP, MatrixToVectorCast, "shared/MatrixToVectorCast.sksl")
466 SKSL_TEST(CPU + GPU + SkQP, MultipleAssignments, "shared/MultipleAssignments.sksl")
467 SKSL_TEST(CPU + GPU + SkQP, NumberCasts, "shared/NumberCasts.sksl")
468 SKSL_TEST(CPU + GPU + SkQP, OperatorsES2, "shared/OperatorsES2.sksl")
469 SKSL_TEST(GPU_ES3, OperatorsES3, "shared/OperatorsES3.sksl")
470 SKSL_TEST(CPU + GPU + SkQP, Ossfuzz36852, "shared/Ossfuzz36852.sksl")
471 SKSL_TEST(CPU + GPU + SkQP, OutParams, "shared/OutParams.sksl")
472 SKSL_TEST(CPU + GPU + SkQP, OutParamsAreDistinct, "shared/OutParamsAreDistinct.sksl")
473 SKSL_TEST(CPU + GPU + SkQP, OutParamsTricky, "shared/OutParamsTricky.sksl")
474 SKSL_TEST(CPU + GPU + SkQP, ResizeMatrix, "shared/ResizeMatrix.sksl")
475 SKSL_TEST(GPU_ES3, ResizeMatrixNonsquare, "shared/ResizeMatrixNonsquare.sksl")
476 SKSL_TEST(CPU + GPU + SkQP, ReturnsValueOnEveryPathES2, "shared/ReturnsValueOnEveryPathES2.sksl")
477 SKSL_TEST(GPU_ES3, ReturnsValueOnEveryPathES3, "shared/ReturnsValueOnEveryPathES3.sksl")
478 SKSL_TEST(CPU + GPU + SkQP, ScalarConversionConstructorsES2, "shared/ScalarConversionConstructorsES2.sksl")
479 SKSL_TEST(GPU_ES3, ScalarConversionConstructorsES3, "shared/ScalarConversionConstructorsES3.sksl")
480 SKSL_TEST(CPU + GPU + SkQP, ScopedSymbol, "shared/ScopedSymbol.sksl")
481 SKSL_TEST(CPU + GPU + SkQP, StackingVectorCasts, "shared/StackingVectorCasts.sksl")
482 SKSL_TEST(CPU + GPU + SkQP, StaticIf, "shared/StaticIf.sksl")
483 SKSL_TEST(GPU_ES3, StaticSwitch, "shared/StaticSwitch.sksl")
484 SKSL_TEST(CPU + GPU + SkQP, StructArrayFollowedByScalar, "shared/StructArrayFollowedByScalar.sksl")
485 SKSL_TEST(CPU + GPU + SkQP, StructsInFunctions, "shared/StructsInFunctions.sksl")
486 SKSL_TEST(CPU + GPU + SkQP, Switch, "shared/Switch.sksl")
487 SKSL_TEST(CPU + GPU + SkQP, SwitchDefaultOnly, "shared/SwitchDefaultOnly.sksl")
488 SKSL_TEST(CPU + GPU + SkQP, SwitchWithFallthrough, "shared/SwitchWithFallthrough.sksl")
489 SKSL_TEST(CPU + GPU + SkQP, SwitchWithLoops, "shared/SwitchWithLoops.sksl")
490 SKSL_TEST(CPU + GPU + SkQP, SwizzleBoolConstants, "shared/SwizzleBoolConstants.sksl")
491 SKSL_TEST(CPU + GPU + SkQP, SwizzleByConstantIndex, "shared/SwizzleByConstantIndex.sksl")
492 SKSL_TEST(GPU_ES3, SwizzleByIndex, "shared/SwizzleByIndex.sksl")
493 SKSL_TEST(CPU + GPU + SkQP, SwizzleConstants, "shared/SwizzleConstants.sksl")
494 SKSL_TEST(CPU + GPU + SkQP, SwizzleLTRB, "shared/SwizzleLTRB.sksl")
495 SKSL_TEST(CPU + GPU + SkQP, SwizzleOpt, "shared/SwizzleOpt.sksl")
496 SKSL_TEST(CPU + GPU + SkQP, SwizzleScalar, "shared/SwizzleScalar.sksl")
497 SKSL_TEST(CPU + GPU + SkQP, SwizzleScalarBool, "shared/SwizzleScalarBool.sksl")
498 SKSL_TEST(CPU + GPU + SkQP, SwizzleScalarInt, "shared/SwizzleScalarInt.sksl")
499 SKSL_TEST(CPU + GPU + SkQP, TernaryAsLValueEntirelyFoldable, "shared/TernaryAsLValueEntirelyFoldable.sksl")
500 SKSL_TEST(CPU + GPU + SkQP, TernaryAsLValueFoldableTest, "shared/TernaryAsLValueFoldableTest.sksl")
501 SKSL_TEST(CPU + GPU + SkQP, TernaryExpression, "shared/TernaryExpression.sksl")
502 SKSL_TEST(CPU + GPU + SkQP, UnaryPositiveNegative, "shared/UnaryPositiveNegative.sksl")
503 SKSL_TEST(CPU + GPU + SkQP, UniformArray, "shared/UniformArray.sksl")
504 SKSL_TEST(CPU + GPU + SkQP, UnusedVariables, "shared/UnusedVariables.sksl")
505 SKSL_TEST(CPU + GPU + SkQP, VectorConstructors, "shared/VectorConstructors.sksl")
506 SKSL_TEST(CPU + GPU + SkQP, VectorToMatrixCast, "shared/VectorToMatrixCast.sksl")
507 SKSL_TEST(CPU + GPU + SkQP, VectorScalarMath, "shared/VectorScalarMath.sksl")
508 SKSL_TEST(GPU_ES3, WhileLoopControlFlow, "shared/WhileLoopControlFlow.sksl")
509