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>
This commit is contained in:
John Stiles 2020-09-24 16:42:09 -04:00 committed by Skia Commit-Bot
parent a28ea67c2a
commit 7e248716e7
3 changed files with 98 additions and 79 deletions

128
BUILD.gn
View File

@ -670,77 +670,74 @@ if (skia_compile_processors) {
if (skia_compile_sksl_tests) {
import("gn/sksl_tests.gni")
sksl_fp_tests_outputs = []
foreach(src, sksl_fp_tests_sources) {
dir = get_path_info(src, "dir")
name = get_path_info(src, "name")
sksl_fp_tests_outputs += [
"$target_out_dir/" + rebase_path("$dir/golden/$name.cpp", target_out_dir),
"$target_out_dir/" + rebase_path("$dir/golden/$name.h", target_out_dir),
]
}
sksl_glsl_tests_outputs = []
foreach(src, sksl_glsl_tests_sources) {
dir = get_path_info(src, "dir")
name = get_path_info(src, "name")
sksl_glsl_tests_outputs +=
[ "$target_out_dir/" +
rebase_path("$dir/golden/$name.glsl", target_out_dir) ]
template("compile_sksl") {
# Compile the passed-in `sources` into `outputs` using skslc, with the given language/settings.
action("compile_sksl_${target_name}") {
script = "gn/compile_sksl_tests.py"
deps = [
":create_sksl_fp",
":sksl_pre_includes",
":skslc(//gn/toolchain:$host_toolchain)",
]
sources = invoker.sources
outputs = []
foreach(src, sources) {
dir = get_path_info(src, "dir")
name = get_path_info(src, "name")
foreach(outputPattern, invoker.outputPatterns) {
outputs += [ target_out_dir + "/" + rebase_path(
dir + outputPattern[0] + name + outputPattern[1],
target_out_dir) ]
}
}
args = [
rebase_path(skslc_path),
invoker.lang,
invoker.settings,
]
args += rebase_path(sources)
}
}
sksl_glsl_settings_tests_outputs = []
foreach(src, sksl_glsl_settings_tests_sources) {
dir = get_path_info(src, "dir")
name = get_path_info(src, "name")
sksl_glsl_tests_outputs +=
[ "$target_out_dir/" +
rebase_path("$dir/golden/$name.glsl", target_out_dir) ]
sksl_glsl_settings_tests_outputs +=
[ "$target_out_dir/" +
rebase_path("$dir/golden/${name}StandaloneSettings.glsl",
target_out_dir) ]
compile_sksl("fp_tests") {
sources = sksl_fp_tests_sources
outputPatterns = [
[
"/golden/",
".cpp",
],
[
"/golden/",
".h",
],
]
lang = "--fp"
settings = "--settings"
}
action("compile_sksl_tests") {
# This action compiles SkSL tests with their settings enabled, i.e. in --settings mode.
script = "gn/compile_sksl_tests.py"
deps = [
":create_sksl_fp",
":sksl_pre_includes",
":skslc(//gn/toolchain:$host_toolchain)",
]
sources = sksl_fp_tests_sources + sksl_glsl_tests_sources +
sksl_glsl_settings_tests_sources
outputs = sksl_fp_tests_outputs + sksl_glsl_tests_outputs
args = [
rebase_path(skslc_path),
"--settings",
]
args += rebase_path(sksl_fp_tests_sources)
args += rebase_path(sksl_glsl_tests_sources)
args += rebase_path(sksl_glsl_settings_tests_sources)
compile_sksl("glsl_tests") {
sources = sksl_glsl_tests_sources + sksl_glsl_settings_tests_sources
outputPatterns = [ [
"/golden/",
".glsl",
] ]
lang = "--glsl"
settings = "--settings"
}
action("compile_sksl_tests_nosettings") {
# This action compiles SkSL tests with their settings disabled, i.e. in --nosettings mode.
script = "gn/compile_sksl_tests.py"
deps = [
":create_sksl_fp",
":sksl_pre_includes",
":skslc(//gn/toolchain:$host_toolchain)",
]
compile_sksl("glsl_nosettings_tests") {
sources = sksl_glsl_settings_tests_sources
outputs = sksl_glsl_settings_tests_outputs
args = [
rebase_path(skslc_path),
"--nosettings",
]
args += rebase_path(sksl_glsl_settings_tests_sources)
outputPatterns = [ [
"/golden/",
"StandaloneSettings.glsl",
] ]
lang = "--glsl"
settings = "--nosettings"
}
} else {
group("compile_sksl_tests") {
group("compile_sksl_fp_tests") {
}
group("compile_sksl_tests_nosettings") {
group("compile_sksl_glsl_tests") {
}
group("compile_sksl_glsl_nosettings_tests") {
}
}
@ -748,8 +745,9 @@ optional("gpu") {
enabled = skia_enable_gpu
deps = [
":compile_processors",
":compile_sksl_tests",
":compile_sksl_tests_nosettings",
":compile_sksl_fp_tests",
":compile_sksl_glsl_nosettings_tests",
":compile_sksl_glsl_tests",
":dehydrate_sksl",
":run_sksllex",
]

View File

@ -10,8 +10,9 @@ import subprocess
import sys
skslc = sys.argv[1]
settings = sys.argv[2]
inputs = sys.argv[3:]
lang = sys.argv[2]
settings = sys.argv[3]
inputs = sys.argv[4:]
def makeEmptyFile(path):
try:
@ -32,9 +33,8 @@ def compile(skslc, input, target, extension):
dst.write("\n")
return False
if settings != "--settings" and settings != "--nosettings":
sys.exit("### Expected --settings or --nosettings")
sys.exit("### Expected --settings or --nosettings, got " + settings)
for input in inputs:
noExt, ext = os.path.splitext(input)
@ -47,7 +47,7 @@ for input in inputs:
if settings == "--nosettings":
target += "StandaloneSettings"
if ext == ".fp":
if lang == "--fp":
# First, compile the CPP. If we get an error, stop here.
if compile(skslc, input, target, ".cpp"):
# Next, compile the header.
@ -62,7 +62,7 @@ for input in inputs:
# The CPP generated an error. We didn't actually generate a header at all, but Ninja
# expects an output file to exist or it won't reach steady-state.
makeEmptyFile(target + ".h")
elif ext == ".sksl" or ext == ".vert" or ext == ".geom":
elif lang == "--glsl":
compile(skslc, input, target, ".glsl")
else:
print("### Unrecognized file type for " + input + ", skipped")
sys.exit("### Expected one of: --fp --glsl, got " + lang)

View File

@ -6,8 +6,7 @@
# Things are easiest for everyone if these source paths are absolute.
_tests = get_path_info("../tests", "abspath")
# Tests in sksl_fp_tests_sources will be compiled with --settings on.
sksl_fp_tests_sources = [
sksl_fp_error_tests = [
"$_tests/sksl/errors/GrBadIn.fp",
"$_tests/sksl/errors/GrBothExplicitReturnAndSkOutColor.fp",
"$_tests/sksl/errors/GrCannotReturnWithSkOutColor.fp",
@ -16,6 +15,9 @@ sksl_fp_tests_sources = [
"$_tests/sksl/errors/GrNoFragmentProcessorLocals.fp",
"$_tests/sksl/errors/GrNoFragmentProcessorParams.fp",
"$_tests/sksl/errors/GrNoFragmentProcessorReturn.fp",
]
sksl_fp_tests = [
"$_tests/sksl/fp/GrChildProcessorAndGlobal.fp",
"$_tests/sksl/fp/GrChildProcessorFieldAccess.fp",
"$_tests/sksl/fp/GrChildProcessorInlineFieldAccess.fp",
@ -61,8 +63,7 @@ sksl_fp_tests_sources = [
"$_tests/sksl/fp/GrUseExplicitReturn.fp",
]
# Tests in sksl_glsl_tests_sources will be compiled with --settings on.
sksl_glsl_tests_sources = [
sksl_error_tests = [
"$_tests/sksl/errors/ArgumentCountMismatch.sksl",
"$_tests/sksl/errors/ArgumentMismatch.sksl",
"$_tests/sksl/errors/ArgumentModifiers.sksl",
@ -127,6 +128,9 @@ sksl_glsl_tests_sources = [
"$_tests/sksl/errors/UseWithoutInitializeVarDecl.sksl",
"$_tests/sksl/errors/UsingInvalidValue.sksl",
"$_tests/sksl/errors/WhileTypeMismatch.sksl",
]
sksl_common_tests = [
"$_tests/sksl/glsl/ArrayConstructors.sksl",
"$_tests/sksl/glsl/ArrayIndexTypes.sksl",
"$_tests/sksl/glsl/ArrayTypes.sksl",
@ -224,6 +228,9 @@ sksl_glsl_tests_sources = [
"$_tests/sksl/glsl/Version450Core.sksl",
"$_tests/sksl/glsl/VertexID.vert",
"$_tests/sksl/glsl/Width.sksl",
]
sksl_inliner_tests = [
"$_tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl",
"$_tests/sksl/inliner/DoWhileTestCannotBeInlined.sksl",
"$_tests/sksl/inliner/ForBodyMustBeInlinedIntoAScope.sksl",
@ -256,9 +263,7 @@ sksl_glsl_tests_sources = [
"$_tests/sksl/inliner/WhileTestCannotBeInlined.sksl",
]
# Tests in sksl_glsl_settings_tests_sources will be compiled twice, once with --settings and once
# using --nosettings. In the latter mode, StandaloneSettings is appended to the output filename.
sksl_glsl_settings_tests_sources = [
sksl_blend_tests = [
"$_tests/sksl/blend/BlendClear.sksl",
"$_tests/sksl/blend/BlendColor.sksl",
"$_tests/sksl/blend/BlendColorBurn.sksl",
@ -288,6 +293,9 @@ sksl_glsl_settings_tests_sources = [
"$_tests/sksl/blend/BlendSrcOut.sksl",
"$_tests/sksl/blend/BlendSrcOver.sksl",
"$_tests/sksl/blend/BlendXor.sksl",
]
sksl_settings_tests = [
"$_tests/sksl/glsl/Derivatives.sksl",
"$_tests/sksl/glsl/DerivativesFlipY.sksl",
"$_tests/sksl/glsl/TypePrecision.sksl",
@ -302,3 +310,16 @@ sksl_glsl_settings_tests_sources = [
"$_tests/sksl/workarounds/RewriteDoWhileLoops.sksl",
"$_tests/sksl/workarounds/TernaryShortCircuit.sksl",
]
# Tests in sksl_fp_tests_sources will be compiled with --settings on, and are expected to generate
# a .cpp and a .h output file.
sksl_fp_tests_sources = sksl_fp_error_tests + sksl_fp_tests
# Tests in sksl_glsl_tests_sources will be compiled with --settings on, and are expected to generate
# a .glsl output file.
sksl_glsl_tests_sources =
sksl_error_tests + sksl_common_tests + sksl_inliner_tests
# Tests in sksl_glsl_settings_tests_sources will be compiled twice, once with --settings and once
# using --nosettings. In the latter mode, StandaloneSettings is appended to the output filename.
sksl_glsl_settings_tests_sources = sksl_blend_tests + sksl_settings_tests