diff --git a/.github/actions/get-gltf-assets/action.yml b/.github/actions/get-gltf-assets/action.yml new file mode 100644 index 0000000000..fd901c2378 --- /dev/null +++ b/.github/actions/get-gltf-assets/action.yml @@ -0,0 +1,23 @@ +name: 'Get and cache glTF Assets' +description: 'Downloads and caches glTF assets by calling the get-gltf-sample-assets.sh script.' + +runs: + using: "composite" + steps: + - uses: ./.github/actions/dep-versions + - name: Hash models file + id: hash-models + shell: bash + run: echo "hash=$(cat test/renderdiff/tests/gltf_models.txt | md5sum | sed 's/ -//g')" >> $GITHUB_OUTPUT + - name: Cache glTF assets + id: cache-gltf + uses: actions/cache@v4 + with: + path: gltf + key: gltf-assets-${{ env.GITHUB_GLTF_SAMPLE_ASSETS_COMMIT }}-${{ steps.hash-models.outputs.hash }} + - name: Download assets via script if cache not found + if: steps.cache-gltf.outputs.cache-hit != 'true' + shell: bash + run: | + echo "Cache miss for commit ${{ env.GITHUB_GLTF_SAMPLE_ASSETS_COMMIT }}. Running download script..." + xargs bash build/common/get-gltf-sample-assets.sh < test/renderdiff/tests/gltf_models.txt diff --git a/.github/actions/get-mesa/action.yml b/.github/actions/get-mesa/action.yml index 1edbdcdb4c..8c3d0f93c2 100644 --- a/.github/actions/get-mesa/action.yml +++ b/.github/actions/get-mesa/action.yml @@ -1,5 +1,6 @@ -name: 'Get Mesa' -description: 'Caches and installs Mesa' +name: 'Get and cache Mesa' +description: 'Get and cache Mesa' + runs: using: "composite" steps: diff --git a/.github/actions/mac-prereq/action.yml b/.github/actions/mac-prereq/action.yml index 59a5ae5593..6563952e13 100644 --- a/.github/actions/mac-prereq/action.yml +++ b/.github/actions/mac-prereq/action.yml @@ -19,5 +19,7 @@ runs: - name: Install Mac Prerequisites shell: bash run: | + # Install brew prereqs + brew install coreutils # Install ninja source ./build/common/get-ninja.sh diff --git a/.github/workflows/presubmit.yml b/.github/workflows/presubmit.yml index 89ef628a82..0f80637c29 100644 --- a/.github/workflows/presubmit.yml +++ b/.github/workflows/presubmit.yml @@ -118,11 +118,12 @@ jobs: - uses: actions/checkout@v4.1.6 with: fetch-depth: 0 + - uses: ./.github/actions/mac-prereq + - uses: ./.github/actions/get-gltf-assets + - uses: ./.github/actions/get-mesa + - uses: ./.github/actions/get-vulkan-sdk - id: get_commit_msg uses: ./.github/actions/get-commit-msg - - uses: ./.github/actions/mac-prereq - - uses: ./.github/actions/get-mesa - - uses: ./.github/actions/get-vulkan-sdk - name: Prerequisites run: | pip install tifffile numpy @@ -132,6 +133,7 @@ jobs: - name: Render and compare id: render_compare run: | + ls ./gltf/Models TEST_DIR=test/renderdiff source ${TEST_DIR}/src/preamble.sh start_ diff --git a/build/common/get-gltf-sample-assets.sh b/build/common/get-gltf-sample-assets.sh new file mode 100644 index 0000000000..9c5f4fef50 --- /dev/null +++ b/build/common/get-gltf-sample-assets.sh @@ -0,0 +1,60 @@ +# Copyright (C) 2025 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#!/usr/bin/bash +set -e + +GLTF_SAMPLE_ASSETS_COMMIT=${GITHUB_GLTF_SAMPLE_ASSETS_COMMIT:-d441dfdb87413ff412c620849a649d61789a470f} +COMMIT_HASH="${GLTF_SAMPLE_ASSETS_COMMIT}" +REPO_URL="https://github.com/KhronosGroup/glTF-Sample-Assets.git" +TARGET_DIR="gltf" + +# The default directories to check out if none are specified +DEFAULT_SPARSE_PATHS=( + "Models/Box/" + "Models/Triangle/" + "Models/AnimatedCube/" +) + +# Check if command-line arguments are provided +if [ "$#" -gt 0 ]; then + # If arguments are provided, use them as the paths + SPARSE_PATHS=() + for model_name in "$@"; do + SPARSE_PATHS+=("Models/${model_name}/") + done + echo "Downloading specified models: $@" +else + # Otherwise, use the default list + SPARSE_PATHS=("${DEFAULT_SPARSE_PATHS[@]}") + echo "No models specified, downloading default set." +fi + +echo "Removing old directory..." +rm -rf "${TARGET_DIR}" + +# Clone the repository using a "treeless" clone, which is highly efficient. +# --filter=tree:0: Clones only the repository structure without file content (no historical directory listings), making the initial clone very small. +# --no-checkout: Prevents automatically checking out the main branch. We will check out a specific commit later. +# --sparse: Initializes the repository for sparse checkout, allowing us to fetch only specific directories. +git clone --filter=tree:0 --no-checkout --sparse "${REPO_URL}" "${TARGET_DIR}" + +cd "${TARGET_DIR}" + +git sparse-checkout set "${SPARSE_PATHS[@]}" + +echo "Checking out commit ${COMMIT_HASH}..." +git checkout "${COMMIT_HASH}" + +echo "Successfully checked out the specified models into the '${TARGET_DIR}' directory." diff --git a/build/common/versions b/build/common/versions index f6a25e0912..c5732dd2ef 100644 --- a/build/common/versions +++ b/build/common/versions @@ -5,4 +5,5 @@ GITHUB_MESA_VERSION=24.2.1 GITHUB_LLVM_VERSION=16 GITHUB_NDK_VERSION=27.0.11718014 GITHUB_EMSDK_VERSION=3.1.60 -GITHUB_VULKANSDK_VERSION=1.4.321.0 \ No newline at end of file +GITHUB_VULKANSDK_VERSION=1.4.321.0 +GITHUB_GLTF_SAMPLE_ASSETS_COMMIT=d441dfdb87413ff412c620849a649d61789a470f \ No newline at end of file diff --git a/test/renderdiff/generate.sh b/test/renderdiff/generate.sh index ab161bfe5a..5dbf3186be 100755 --- a/test/renderdiff/generate.sh +++ b/test/renderdiff/generate.sh @@ -23,6 +23,10 @@ function start_render_() { bash ${BUILD_COMMON_DIR}/get-mesa.sh fi + if [ ! -d ${GLTF_DIR} ]; then + cat ${RENDERDIFF_TEST_DIR}/tests/gltf_models.txt | xargs bash ${BUILD_COMMON_DIR}/get-gltf-sample-assets.sh + fi + # Install python deps python3 -m venv ${VENV_DIR} source ${VENV_DIR}/bin/activate diff --git a/test/renderdiff/src/preamble.sh b/test/renderdiff/src/preamble.sh index bbf200d09e..e58330f98c 100644 --- a/test/renderdiff/src/preamble.sh +++ b/test/renderdiff/src/preamble.sh @@ -22,6 +22,7 @@ GOLDEN_OUTPUT_DIR="$(pwd)/out/renderdiff/goldens" RENDERDIFF_TEST_DIR="$(pwd)/test/renderdiff" MESA_DIR="$(pwd)/mesa/out/" VENV_DIR="$(pwd)/venv" +GLTF_DIR="$(pwd)/gltf/Models" BUILD_COMMON_DIR="$(pwd)/build/common" os_name=$(uname -s) diff --git a/test/renderdiff/src/test_config.py b/test/renderdiff/src/test_config.py index c7b5a024f5..4e57c49a2f 100644 --- a/test/renderdiff/src/test_config.py +++ b/test/renderdiff/src/test_config.py @@ -44,11 +44,22 @@ class RenderingConfig(): class PresetConfig(RenderingConfig): def __init__(self, data, existing_models): RenderingConfig.__init__(self, data) - models = data.get('models') - if models: + self.models = [] + + def _check(models): assert _is_list_of_strings(models) assert all(m in existing_models for m in models) + + models = data.get('models') + if models: + _check(models) self.models = models + model_list_file = data.get('model_list_file') + if model_list_file and os.path.exists(model_list_file): + with open(model_list_file, 'r') as f: + models = list(filter(lambda a: len(a) > 0, map(lambda a: a.strip(), f.read().split('\n')))) + _check(models) + self.models += models class TestConfig(RenderingConfig): def __init__(self, data, existing_models, presets): @@ -105,7 +116,9 @@ class RenderTestConfig(): 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))) + chain(*(glob.glob(f'{d}/**/*.glb', recursive=True) for d in model_search_paths))) + \ + list( + chain(*(glob.glob(f'{d}/**/*.gltf', 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} diff --git a/test/renderdiff/tests/gltf_models.txt b/test/renderdiff/tests/gltf_models.txt new file mode 100644 index 0000000000..b8e997221a --- /dev/null +++ b/test/renderdiff/tests/gltf_models.txt @@ -0,0 +1,20 @@ +AlphaBlendModeTest +AttenuationTest +Box +BoomBoxWithAxes +BoxInterleaved +BoxTextured +BoxTexturedNonPowerOfTwo +Duck +IridescenceSuzanne +Lantern +MetalRoughSpheres +NegativeScaleTest +NormalTangentMirrorTest +NormalTangentTest +SpecularTest +Sponza +Suzanne +TextureCoordinateTest +TextureSettingsTest +TwoSidedPlane