Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e24871

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Clean up SkSL test compilation in preparation for Metal support.
Now uses a GN template to avoid copy-pasting the same logic for each type of test we want to perform, and the same file to be compiled in more than one way at a time via an extra flag to compile_sksl_tests.py. Change-Id: I8aadedeb140d78d58a345a2bac0da3d9c77e9a19 Bug: skia:10694 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319347 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
1 parent a28ea67 commit 7e24871

File tree

3 files changed

+101
-82
lines changed

3 files changed

+101
-82
lines changed

BUILD.gn

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -670,86 +670,84 @@ if (skia_compile_processors) {
670670

671671
if (skia_compile_sksl_tests) {
672672
import("gn/sksl_tests.gni")
673-
sksl_fp_tests_outputs = []
674-
foreach(src, sksl_fp_tests_sources) {
675-
dir = get_path_info(src, "dir")
676-
name = get_path_info(src, "name")
677-
sksl_fp_tests_outputs += [
678-
"$target_out_dir/" + rebase_path("$dir/golden/$name.cpp", target_out_dir),
679-
"$target_out_dir/" + rebase_path("$dir/golden/$name.h", target_out_dir),
680-
]
681-
}
682-
683-
sksl_glsl_tests_outputs = []
684-
foreach(src, sksl_glsl_tests_sources) {
685-
dir = get_path_info(src, "dir")
686-
name = get_path_info(src, "name")
687-
sksl_glsl_tests_outputs +=
688-
[ "$target_out_dir/" +
689-
rebase_path("$dir/golden/$name.glsl", target_out_dir) ]
690-
}
691673

692-
sksl_glsl_settings_tests_outputs = []
693-
foreach(src, sksl_glsl_settings_tests_sources) {
694-
dir = get_path_info(src, "dir")
695-
name = get_path_info(src, "name")
696-
sksl_glsl_tests_outputs +=
697-
[ "$target_out_dir/" +
698-
rebase_path("$dir/golden/$name.glsl", target_out_dir) ]
699-
sksl_glsl_settings_tests_outputs +=
700-
[ "$target_out_dir/" +
701-
rebase_path("$dir/golden/${name}StandaloneSettings.glsl",
702-
target_out_dir) ]
703-
}
704-
705-
action("compile_sksl_tests") {
706-
# This action compiles SkSL tests with their settings enabled, i.e. in --settings mode.
707-
script = "gn/compile_sksl_tests.py"
708-
deps = [
709-
":create_sksl_fp",
710-
":sksl_pre_includes",
711-
":skslc(//gn/toolchain:$host_toolchain)",
712-
]
713-
sources = sksl_fp_tests_sources + sksl_glsl_tests_sources +
714-
sksl_glsl_settings_tests_sources
715-
outputs = sksl_fp_tests_outputs + sksl_glsl_tests_outputs
716-
args = [
717-
rebase_path(skslc_path),
718-
"--settings",
719-
]
720-
args += rebase_path(sksl_fp_tests_sources)
721-
args += rebase_path(sksl_glsl_tests_sources)
722-
args += rebase_path(sksl_glsl_settings_tests_sources)
723-
}
724-
action("compile_sksl_tests_nosettings") {
725-
# This action compiles SkSL tests with their settings disabled, i.e. in --nosettings mode.
726-
script = "gn/compile_sksl_tests.py"
727-
deps = [
728-
":create_sksl_fp",
729-
":sksl_pre_includes",
730-
":skslc(//gn/toolchain:$host_toolchain)",
731-
]
674+
template("compile_sksl") {
675+
# Compile the passed-in `sources` into `outputs` using skslc, with the given language/settings.
676+
action("compile_sksl_${target_name}") {
677+
script = "gn/compile_sksl_tests.py"
678+
deps = [
679+
":create_sksl_fp",
680+
":sksl_pre_includes",
681+
":skslc(//gn/toolchain:$host_toolchain)",
682+
]
683+
sources = invoker.sources
684+
outputs = []
685+
foreach(src, sources) {
686+
dir = get_path_info(src, "dir")
687+
name = get_path_info(src, "name")
688+
foreach(outputPattern, invoker.outputPatterns) {
689+
outputs += [ target_out_dir + "/" + rebase_path(
690+
dir + outputPattern[0] + name + outputPattern[1],
691+
target_out_dir) ]
692+
}
693+
}
694+
args = [
695+
rebase_path(skslc_path),
696+
invoker.lang,
697+
invoker.settings,
698+
]
699+
args += rebase_path(sources)
700+
}
701+
}
702+
compile_sksl("fp_tests") {
703+
sources = sksl_fp_tests_sources
704+
outputPatterns = [
705+
[
706+
"/golden/",
707+
".cpp",
708+
],
709+
[
710+
"/golden/",
711+
".h",
712+
],
713+
]
714+
lang = "--fp"
715+
settings = "--settings"
716+
}
717+
compile_sksl("glsl_tests") {
718+
sources = sksl_glsl_tests_sources + sksl_glsl_settings_tests_sources
719+
outputPatterns = [ [
720+
"/golden/",
721+
".glsl",
722+
] ]
723+
lang = "--glsl"
724+
settings = "--settings"
725+
}
726+
compile_sksl("glsl_nosettings_tests") {
732727
sources = sksl_glsl_settings_tests_sources
733-
outputs = sksl_glsl_settings_tests_outputs
734-
args = [
735-
rebase_path(skslc_path),
736-
"--nosettings",
737-
]
738-
args += rebase_path(sksl_glsl_settings_tests_sources)
728+
outputPatterns = [ [
729+
"/golden/",
730+
"StandaloneSettings.glsl",
731+
] ]
732+
lang = "--glsl"
733+
settings = "--nosettings"
739734
}
740735
} else {
741-
group("compile_sksl_tests") {
736+
group("compile_sksl_fp_tests") {
737+
}
738+
group("compile_sksl_glsl_tests") {
742739
}
743-
group("compile_sksl_tests_nosettings") {
740+
group("compile_sksl_glsl_nosettings_tests") {
744741
}
745742
}
746743

747744
optional("gpu") {
748745
enabled = skia_enable_gpu
749746
deps = [
750747
":compile_processors",
751-
":compile_sksl_tests",
752-
":compile_sksl_tests_nosettings",
748+
":compile_sksl_fp_tests",
749+
":compile_sksl_glsl_nosettings_tests",
750+
":compile_sksl_glsl_tests",
753751
":dehydrate_sksl",
754752
":run_sksllex",
755753
]

gn/compile_sksl_tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import sys
1111

1212
skslc = sys.argv[1]
13-
settings = sys.argv[2]
14-
inputs = sys.argv[3:]
13+
lang = sys.argv[2]
14+
settings = sys.argv[3]
15+
inputs = sys.argv[4:]
1516

1617
def makeEmptyFile(path):
1718
try:
@@ -32,9 +33,8 @@ def compile(skslc, input, target, extension):
3233
dst.write("\n")
3334
return False
3435

35-
3636
if settings != "--settings" and settings != "--nosettings":
37-
sys.exit("### Expected --settings or --nosettings")
37+
sys.exit("### Expected --settings or --nosettings, got " + settings)
3838

3939
for input in inputs:
4040
noExt, ext = os.path.splitext(input)
@@ -47,7 +47,7 @@ def compile(skslc, input, target, extension):
4747
if settings == "--nosettings":
4848
target += "StandaloneSettings"
4949

50-
if ext == ".fp":
50+
if lang == "--fp":
5151
# First, compile the CPP. If we get an error, stop here.
5252
if compile(skslc, input, target, ".cpp"):
5353
# Next, compile the header.
@@ -62,7 +62,7 @@ def compile(skslc, input, target, extension):
6262
# The CPP generated an error. We didn't actually generate a header at all, but Ninja
6363
# expects an output file to exist or it won't reach steady-state.
6464
makeEmptyFile(target + ".h")
65-
elif ext == ".sksl" or ext == ".vert" or ext == ".geom":
65+
elif lang == "--glsl":
6666
compile(skslc, input, target, ".glsl")
6767
else:
68-
print("### Unrecognized file type for " + input + ", skipped")
68+
sys.exit("### Expected one of: --fp --glsl, got " + lang)

gn/sksl_tests.gni

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
# Things are easiest for everyone if these source paths are absolute.
77
_tests = get_path_info("../tests", "abspath")
88

9-
# Tests in sksl_fp_tests_sources will be compiled with --settings on.
10-
sksl_fp_tests_sources = [
9+
sksl_fp_error_tests = [
1110
"$_tests/sksl/errors/GrBadIn.fp",
1211
"$_tests/sksl/errors/GrBothExplicitReturnAndSkOutColor.fp",
1312
"$_tests/sksl/errors/GrCannotReturnWithSkOutColor.fp",
@@ -16,6 +15,9 @@ sksl_fp_tests_sources = [
1615
"$_tests/sksl/errors/GrNoFragmentProcessorLocals.fp",
1716
"$_tests/sksl/errors/GrNoFragmentProcessorParams.fp",
1817
"$_tests/sksl/errors/GrNoFragmentProcessorReturn.fp",
18+
]
19+
20+
sksl_fp_tests = [
1921
"$_tests/sksl/fp/GrChildProcessorAndGlobal.fp",
2022
"$_tests/sksl/fp/GrChildProcessorFieldAccess.fp",
2123
"$_tests/sksl/fp/GrChildProcessorInlineFieldAccess.fp",
@@ -61,8 +63,7 @@ sksl_fp_tests_sources = [
6163
"$_tests/sksl/fp/GrUseExplicitReturn.fp",
6264
]
6365

64-
# Tests in sksl_glsl_tests_sources will be compiled with --settings on.
65-
sksl_glsl_tests_sources = [
66+
sksl_error_tests = [
6667
"$_tests/sksl/errors/ArgumentCountMismatch.sksl",
6768
"$_tests/sksl/errors/ArgumentMismatch.sksl",
6869
"$_tests/sksl/errors/ArgumentModifiers.sksl",
@@ -127,6 +128,9 @@ sksl_glsl_tests_sources = [
127128
"$_tests/sksl/errors/UseWithoutInitializeVarDecl.sksl",
128129
"$_tests/sksl/errors/UsingInvalidValue.sksl",
129130
"$_tests/sksl/errors/WhileTypeMismatch.sksl",
131+
]
132+
133+
sksl_common_tests = [
130134
"$_tests/sksl/glsl/ArrayConstructors.sksl",
131135
"$_tests/sksl/glsl/ArrayIndexTypes.sksl",
132136
"$_tests/sksl/glsl/ArrayTypes.sksl",
@@ -224,6 +228,9 @@ sksl_glsl_tests_sources = [
224228
"$_tests/sksl/glsl/Version450Core.sksl",
225229
"$_tests/sksl/glsl/VertexID.vert",
226230
"$_tests/sksl/glsl/Width.sksl",
231+
]
232+
233+
sksl_inliner_tests = [
227234
"$_tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl",
228235
"$_tests/sksl/inliner/DoWhileTestCannotBeInlined.sksl",
229236
"$_tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl",
@@ -256,9 +263,7 @@ sksl_glsl_tests_sources = [
256263
"$_tests/sksl/inliner/WhileTestCannotBeInlined.sksl",
257264
]
258265

259-
# Tests in sksl_glsl_settings_tests_sources will be compiled twice, once with --settings and once
260-
# using --nosettings. In the latter mode, StandaloneSettings is appended to the output filename.
261-
sksl_glsl_settings_tests_sources = [
266+
sksl_blend_tests = [
262267
"$_tests/sksl/blend/BlendClear.sksl",
263268
"$_tests/sksl/blend/BlendColor.sksl",
264269
"$_tests/sksl/blend/BlendColorBurn.sksl",
@@ -288,6 +293,9 @@ sksl_glsl_settings_tests_sources = [
288293
"$_tests/sksl/blend/BlendSrcOut.sksl",
289294
"$_tests/sksl/blend/BlendSrcOver.sksl",
290295
"$_tests/sksl/blend/BlendXor.sksl",
296+
]
297+
298+
sksl_settings_tests = [
291299
"$_tests/sksl/glsl/Derivatives.sksl",
292300
"$_tests/sksl/glsl/DerivativesFlipY.sksl",
293301
"$_tests/sksl/glsl/TypePrecision.sksl",
@@ -302,3 +310,16 @@ sksl_glsl_settings_tests_sources = [
302310
"$_tests/sksl/workarounds/RewriteDoWhileLoops.sksl",
303311
"$_tests/sksl/workarounds/TernaryShortCircuit.sksl",
304312
]
313+
314+
# Tests in sksl_fp_tests_sources will be compiled with --settings on, and are expected to generate
315+
# a .cpp and a .h output file.
316+
sksl_fp_tests_sources = sksl_fp_error_tests + sksl_fp_tests
317+
318+
# Tests in sksl_glsl_tests_sources will be compiled with --settings on, and are expected to generate
319+
# a .glsl output file.
320+
sksl_glsl_tests_sources =
321+
sksl_error_tests + sksl_common_tests + sksl_inliner_tests
322+
323+
# Tests in sksl_glsl_settings_tests_sources will be compiled twice, once with --settings and once
324+
# using --nosettings. In the latter mode, StandaloneSettings is appended to the output filename.
325+
sksl_glsl_settings_tests_sources = sksl_blend_tests + sksl_settings_tests

0 commit comments

Comments
 (0)