Output Runtime Effect files from import_conformance_tests.

Previously the results were dumped to stdout.

Change-Id: I20a634744f287f97e660912549f429ebea479162
Bug: skia:12484
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/454636
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 2021-09-30 11:05:41 -04:00 committed by SkCQ
parent 30d55d11fc
commit 9c0b844173

View File

@ -7,9 +7,18 @@
#
# GLSL ES2 conformance test files can be found at
# https://github.com/KhronosGroup/VK-GL-CTS/tree/master/data/gles2/shaders
#
# Usage:
# cat ${TEST_FILES}/*.test | ./import_conformance_tests.py
#
# This will generate two directories, "pass" and "fail", containing finished runtime shaders.
#
# Not all ES2 test files are meaningful in SkSL. These input files are not supported:
# - linkage.test: Runtime Effects only handle fragment processing
# - invalid_texture_functions.test: no GL texture functions in Runtime Effects
# - preprocessor.test: no preprocessor in SkSL
import os
import pprint
import pyparsing as pp
import sys
@ -73,6 +82,14 @@ group.ignore('#' + pp.restOfLine)
testCases = grammar.parse_string(sys.stdin.read(), parse_all=True)
# Write output files in subdirectories next to this script.
testDirectory = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
passDirectory = testDirectory + "/pass"
failDirectory = testDirectory + "/fail"
os.makedirs(passDirectory, exist_ok=True)
os.makedirs(failDirectory, exist_ok=True)
written = {}
for c in testCases:
# Parse the case header
assert c[0] == 'case'
@ -129,8 +146,7 @@ for c in testCases:
skipTest = 'Missing main'
if skipTest != '':
print("/////////// skipped %s (%s) ///////////" % (testName, skipTest))
print("")
print("skipped %s (%s)" % (testName, skipTest))
continue
# Apply fixups to the test code.
@ -155,15 +171,14 @@ for c in testCases:
testCode = "vec4 PositionFragColor;\n" + testCode
# Create a runnable SkSL test by returning green or red based on the test result.
testSuffix = ''
if expectPass:
testCode += "\n"
testCode += "half4 main(float2 coords) {\n"
testCode += " return execute_test() ? half4(0,1,0,1) : half4(1,0,0,1);\n"
testCode += "}\n"
else:
testSuffix = '_ERROR'
testDirectory = passDirectory
if not expectPass:
testDirectory = failDirectory
# Find the total number of input/output fields.
numVariables = 0
@ -174,7 +189,6 @@ for c in testCases:
assert "${DECLARATIONS}" in testCode
assert "${OUTPUT}" in testCode
for varIndex in range(0, numVariables):
print("/////////// %s_%d%s.sksl ///////////" % (testName, varIndex, testSuffix))
testSpecialization = testCode
# Assemble input variable declarations for ${DECLARATIONS}.
@ -199,14 +213,22 @@ for c in testCases:
testSpecialization = testSpecialization.replace("${DECLARATIONS}", declarations)
testSpecialization = testSpecialization.replace("${SETUP}", '')
testSpecialization = testSpecialization.replace("${OUTPUT}", outputChecks)
print(testSpecialization)
# Generate an SkSL test file.
path = "%s/%s_%d.rts" % (testDirectory, testName, varIndex)
assert path not in written
written[path] = True
f = open(path, "w")
f.write(testSpecialization)
else: # not (numVariables > 0)
print ("/////////// %s%s.sksl ///////////" % (testName, testSuffix))
testCode = testCode.replace("${DECLARATIONS}", '')
testCode = testCode.replace("${SETUP}", '')
testCode = testCode.replace("${OUTPUT}", 'return true;')
# Generate an SkSL test file.
print (testCode)
path = "%s/%s.rts" % (testDirectory, testName)
assert path not in written
written[path] = True
f = open(path, "w")
f.write(testCode)