Skip to content

Commit

Permalink
github: add software rasterizer job for GL
Browse files Browse the repository at this point in the history
  • Loading branch information
poweifeng committed Sep 25, 2024
1 parent 67f37d4 commit 98b848a
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/presubmit-gl-pixel-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Pixel_Test_Presbumit

on:
push:
branches:
- main
- release
- rc/**

jobs:
run-gl-pixel-test:
name: run-gl-pixel-test
runs-on: ubuntu-22.04-32core

steps:
- uses: actions/[email protected]
- name: Run build script
run: |
echo "deb-src http://archive.ubuntu.com/ubuntu jammy main restricted universe" >> /etc/apt/sources.list
apt update
source ./build/linux/ci-common.sh && bash test/run_pixel_tests.sh
- uses: actions/upload-artifact@v4
with:
name: presubmit-gl-pixel-tests-output
path: pixel_tests.zip
16 changes: 16 additions & 0 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,19 @@ jobs:
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh presubmit
run-gl-pixel-test:
name: run-gl-pixel-test
runs-on: ubuntu-22.04-32core

steps:
- uses: actions/[email protected]
- name: Run build script
run: |
echo "deb-src http://archive.ubuntu.com/ubuntu jammy main restricted universe" | sudo tee /etc/apt/sources.list.d/my.list
apt-get update
source ./build/linux/ci-common.sh && bash test/run_pixel_tests.sh
- uses: actions/upload-artifact@v4
with:
name: presubmit-gl-pixel-tests-output
path: pixel_tests.zip
17 changes: 17 additions & 0 deletions build/pixels/get_mesa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e
set -x

sudo apt-get build-dep mesa

git clone https://gitlab.freedesktop.org/mesa/mesa.git

pushd .

cd mesa
mkdir -p out
meson setup builddir/ -Dprefix=$(pwd)/out -Dglx=xlib -Dgallium-drivers=swrast -Dvulkan-drivers=swrast
meson install -C builddir/

popd
128 changes: 128 additions & 0 deletions test/parse_test_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
from utils import execute, ArgParseImpl

import glob
from itertools import chain
import json
import sys
import os
from os import path

def _is_list_of_strings(field):
return isinstance(field, list) and\
all(isinstance(item, str) for item in field)

def _is_string(s):
return isinstance(s, str)

def _is_dict(s):
return isinstance(s, dict)

class RenderingConfig():
def __init__(self, data):
assert 'name' in data
assert _is_string(data['name'])
self.name = data['name']

assert 'rendering' in data
assert _is_dict(data['rendering'])
self.rendering = data['rendering']

class PresetConfig(RenderingConfig):
def __init__(self, data, existing_models):
RenderingConfig.__init__(self, data)
models = data.get('models')
if models:
assert _is_list_of_strings(models)
assert all(m in existing_models for m in models)
self.models = models

class TestConfig(RenderingConfig):
def __init__(self, data, existing_models, presets):
RenderingConfig.__init__(self, data)
description = data.get('description')
if description:
assert _is_string(description)
self.description = description

apply_presets = data.get('apply_presets')
rendering = {}
preset_models = []
if apply_presets:
given_presets = {p.name: p for p in presets}
assert all((name in given_presets) for name in apply_presets)
for preset in apply_presets:
rendering.update(given_presets[preset].rendering)
preset_models += given_presets[preset].models

assert 'rendering' in data
rendering.update(data['rendering'])
self.rendering = rendering

models = data.get('models')
self.models = preset_models
if models:
assert _is_list_of_strings(models)
assert all(m in existing_models for m in models)
self.models = set(models + self.models)

def to_filament_format(self):
json_out = {
'name': self.name,
'base': self.rendering
}
return json.dumps(json_out)

class PixelTestConfig():
def __init__(self, data):
assert 'name' in data
name = data['name']
assert _is_string(name)
self.name = name

assert 'backends' in data
backends = data['backends']
assert _is_list_of_strings(backends)
self.backends = backends

assert 'model_search_paths' in data
model_search_paths = data.get('model_search_paths')
assert _is_list_of_strings(model_search_paths)
assert all(path.isdir(p) for p in model_search_paths)

model_paths = list(
chain(*(glob.glob(f'{d}/**/*.glb', recursive=True) for d in model_search_paths)))
# This flatten the output for glob.glob
self.models = {path.splitext(path.basename(model))[0]: model for model in model_paths}

preset_data = data.get('presets')
presets = []
if preset_data:
presets = [PresetConfig(p, self.models) for p in preset_data]

assert 'tests' in data
self.tests = [TestConfig(t, self.models, presets) for t in data['tests']]
test_names = list([t.name for t in self.tests])

# We cannot have duplicate test names
assert len(test_names) == len(set(test_names))

def _remove_comments_from_json_txt(json_txt):
res = []
for line in json_txt.split('\n'):
if '//' in line:
line = line.split('//')[0]
res.append(line)
return '\n'.join(res)

def parse_test_config_from_path(config_path):
with open(config_path, 'r') as f:
json_txt = json.loads(_remove_comments_from_json_txt(f.read()))
return PixelTestConfig(json_txt)


if __name__ == "__main__":
parser = ArgParseImpl()
parser.add_argument('--test', help='Configuration of the test', required=True)

args, _ = parser.parse_known_args(sys.argv[1:])
test = parse_test_config_from_path(args.test)
34 changes: 34 additions & 0 deletions test/pixels/presubmit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "PresubmitPixelTests",
"backends": ["opengl"],
"model_search_paths": ["third_party/models"],
"presets": [
{
"name": "StandardLit",
"models": ["lucy", "DamagedHelmet"], // optional
"rendering": {
"viewer.cameraFocusDistance": 0,
"view.postProcessingEnabled": true
}
}
],
"tests": [
{
"name": "BloomFlare",
"description": "Testing bloom and flare", // optional
"apply_presets": ["StandardLit"], // optional
"rendering": {
"view.bloom.enabled": true,
"view.bloom.lensFlare": true
}
},
{
"name": "MSAA",
"description": "Testing Multi-sample Anti-aliasing", // optional
"apply_presets": ["StandardLit"], // optional
"rendering": {
"view.msaa.enabled": true
}
}
]
}
26 changes: 26 additions & 0 deletions test/pixels/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "SampleTests",
"backends": ["opengl"],
"model_search_paths": ["third_party/models"],
"presets": [
{
"name": "StandardLit",
"models": ["lucy", "DamagedHelmet"], // optional
"rendering": {
"viewer.cameraFocusDistance": 0,
"view.postProcessingEnabled": true
}
}
],
"tests": [
{
"name": "BloomFlare",
"description": "Testing bloom and flare", // optional
"apply_presets": ["StandardLit"], // optional
"rendering": {
"view.bloom.enabled": true,
"view.bloom.lensFlare": true
}
}
]
}
39 changes: 39 additions & 0 deletions test/run_pixel_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from utils import execute, ArgParseImpl

from parse_test_json import parse_test_config_from_path
import sys
import os

def run_test(gltf_viewer, pixel_test, output_dir, opengl_lib=None, vk_icd=None):
assert os.path.isdir(output_dir)
assert os.access(gltf_viewer, os.X_OK)

for test in pixel_test.tests:
test_json_path = f'{output_dir}/{test.name}.json'

with open(test_json_path, 'w') as f:
f.write(f'[{test.to_filament_format()}]')

for backend in pixel_test.backends:
env = None
if backend == 'opengl' and opengl_lib and os.path.isdir(opengl_lib):
env = {'LD_LIBRARY_PATH': opengl_lib}

for model in test.models:
model_path = pixel_test.models[model]
out_name = f'{test.name}_{model}_{backend}'
execute(f'{gltf_viewer} -a {backend} --batch={test_json_path} -e {model_path}', env=env, capture_output=False)
execute(f'mv -f {test.name}0.ppm {output_dir}/{out_name}.ppm', capture_output=False)
execute(f'mv -f {test.name}0.json {output_dir}/{test.name}.json', capture_output=False)

if __name__ == "__main__":
parser = ArgParseImpl()
parser.add_argument('--test', help='Configuration of the test', required=True)
parser.add_argument('--gltf_viewer', help='Path to the gltf_viewer', required=True)
parser.add_argument('--output_dir', help='Output Directory', required=True)
parser.add_argument('--opengl_lib', help='Path to the folder containing OpenGL driver lib (for LD_LIBRARY_PATH)')
parser.add_argument('--vk_icd', help='Path to VK ICD file')

args, _ = parser.parse_known_args(sys.argv[1:])
test = parse_test_config_from_path(args.test)
run_test(args.gltf_viewer, test, args.output_dir, opengl_lib=args.opengl_lib, vk_icd=args.vk_icd)
24 changes: 24 additions & 0 deletions test/run_pixel_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/bash

# Build gltf_viewer
OUTPUT_DIR=$(pwd)/out/pixel_tests

function prepare_mesa() {
export MESA_LIB_DIR=$(pwd)/mesa/out/lib/x86_64-linux-gnu
if [ ! -d ${MESA_LIB_DIR} ]; then
rm -rf mesa
bash ./build/pixels/get_mesa.sh
fi
}

prepare_mesa && set -e && set -x && \
mkdir -p ${OUTPUT_DIR} && \
./build.sh -p desktop debug gltf_viewer && \
python3 test/run_pixel_tests.py \
--gltf_viewer=$(pwd)/out/cmake-debug/samples/gltf_viewer \
--test=$(pwd)/test/pixels/presubmit.json \
--output_dir=${OUTPUT_DIR} \
--opengl_lib=${MESA_LIB_DIR} && \
zip -r pixel_tests.zip ${OUTPUT_DIR}

unset MESA_LIB_DIR
54 changes: 54 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import subprocess
import os
import argparse
import sys

def execute(cmd,
cwd=None,
capture_output=True,
stdin=None,
env=None,
raise_errors=False):
in_env = os.environ
in_env.update(env if env else {})
home = os.environ['HOME']
if f'{home}/bin' not in in_env['PATH']:
in_env['PATH'] = in_env['PATH'] + f':{home}/bin'

stdout = subprocess.PIPE if capture_output else sys.stdout
stderr = subprocess.PIPE if capture_output else sys.stdout
output = ''
err_output = ''
return_code = -1
kwargs = {
'cwd': cwd,
'env': in_env,
'stdout': stdout,
'stderr': stderr,
'stdin': stdin,
'universal_newlines': True
}
if capture_output:
process = subprocess.Popen(cmd.split(' '), **kwargs)
output, err_output = process.communicate()
return_code = process.returncode
else:
return_code = subprocess.call(cmd.split(' '), **kwargs)

if return_code:
# Error
if raise_errors:
raise subprocess.CalledProcessError(return_code, cmd)
if output:
if type(output) != str:
try:
output = output.decode('utf-8').strip()
except UnicodeDecodeError as e:
print('cannot decode ', output, file=sys.stderr)
return return_code, (output if return_code == 0 else err_output)

class ArgParseImpl(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('error: %s\n' % message)
self.print_help()
sys.exit(1)

0 comments on commit 98b848a

Please sign in to comment.