blender/tests/python/compositor_render_tests.py

103 lines
3.4 KiB
Python

#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2015-2025 Blender Authors
#
# SPDX-License-Identifier: Apache-2.0
import argparse
import os
import sys
from pathlib import Path
# When run from inside Blender, render and exit.
try:
import bpy
inside_blender = True
except ImportError:
inside_blender = False
def get_compositor_device_setter_script(execution_device: str) -> str:
return f"import bpy; bpy.data.scenes[0].render.compositor_device = '{execution_device}'"
def get_arguments(filepath: Path, output_filepath: Path, backend: str) -> list[str | Path]:
arguments: list[str | Path] = [
"--background",
"--factory-startup",
"--enable-autoexec",
"--debug-memory",
"--console-crash-handler",
"--debug-exit-on-error"]
execution_device = "CPU"
if backend != "CPU":
execution_device = "GPU"
arguments.extend(["--gpu-backend", backend, "--debug-gpu-backend-no-fallback"])
arguments.extend([
filepath,
"-P", os.path.realpath(__file__),
"--python-expr", get_compositor_device_setter_script(execution_device),
"-o", output_filepath,
"-F", "PNG",
"-f", "1"])
return arguments
def create_argparse():
parser = argparse.ArgumentParser(
description="Run test script for each blend file in TESTDIR, comparing the render result with known output."
)
parser.add_argument("--blender", required=True, type=Path)
parser.add_argument("--testdir", required=True, type=Path)
parser.add_argument("--outdir", required=True, type=Path)
parser.add_argument("--oiiotool", required=True, type=Path)
parser.add_argument('--batch', default=False, action='store_true')
parser.add_argument('--gpu-backend')
return parser
BLOCKLIST_OPENGL_LINUX = [
# Unknown failure than can not be reproduced locally.
"node_integer_math.blend",
"Fire2.blend",
"node_keying_matte.blend",
]
def main():
parser = create_argparse()
args = parser.parse_args()
blocklist = []
if args.gpu_backend == "opengl" and sys.platform == "linux":
blocklist += BLOCKLIST_OPENGL_LINUX
from modules import render_report
backend = args.gpu_backend if args.gpu_backend else "CPU"
report_title = f"Compositor {backend.upper()}"
report = render_report.Report(report_title, args.outdir, args.oiiotool, variation=None, blocklist=blocklist)
report.set_pixelated(True)
report.set_reference_dir("compositor_renders")
if args.testdir.name == 'filter':
# Temporary change to pass OpenImageDenoise test with both 1.3 and 1.4.
report.set_fail_threshold(0.05)
elif args.testdir.name == 'mask' or args.testdir.name == 'keying':
# The node_keying_matte.blend test is very sensitive to the exact values in the
# input image. It makes it hard to precisely match results on different systems
# (with and without SSE, i.e.), especially when OCIO has different precision for
# the exponent transform on different platforms.
report.set_fail_threshold(0.06)
report.set_fail_percent(2)
def arguments_callback(filepath: Path, output_filepath: Path) -> list[str | Path]:
return get_arguments(filepath, output_filepath, backend)
ok = report.run(args.testdir, args.blender, arguments_callback, batch=args.batch)
sys.exit(not ok)
if not inside_blender and __name__ == "__main__":
main()