## Copyright 2023 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

name: CI GPU Windows Workflow
on:
  push:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:

  build-windows-gpu:
    secrets: inherit
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/windows_gpu.yml@main
    with:
      force-delete: true    # guarantees .gitattributes are respected in working dir
      submodules: true
      runs-on: '[ "Windows", "build" ]'
      env-from-files: ./.github/deps/dpcpp-sycl-nightly.env
      artifact-out: build-windows-gpu
      artifact-path: ./build
      artifact-on-failure: true
      cmd: |
        # disable warnings which lead to excessively large log files
        $env:CXXFLAGS = '-w'
        $env:CFLAGS = '-w'

        mkdir build
        cd build

        cmake -L -G Ninja -D CMAKE_INSTALL_LIBDIR=lib -D BUILD_OPENVKL_BENCHMARKS=OFF -D BUILD_OPENVKL_TESTING=ON -D BUILD_OPENVDB=OFF -D CMAKE_CXX_COMPILER=clang-cl -D CMAKE_C_COMPILER=clang-cl -D OPENVKL_EXTRA_OPTIONS="-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DOPENVKL_ENABLE_DEVICE_GPU=ON -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR=OFF -DOPENVKL_DEVICE_CPU_STRUCTURED_REGULAR_LEGACY=ON" ../superbuild

        cmake --build . --config Release -j1 --verbose

  test-windows-dg2:
    secrets: inherit
    needs: [ build-windows-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/windows_gpu.yml@main
    with:
      force-delete: true    # guarantees .gitattributes are respected in working dir
      submodules: true
      runs-on: '[ "Windows", "dg2" ]'
      env-from-files: ./.github/deps/dpcpp-sycl-nightly.env ./.github/deps/gfx-windows-public.env
      artifact-in: build-windows-gpu
      cmd: |
        cd ./build/install/bin

        ./vklTutorialGPU
        ./vklTestsGPU --durations yes exclude:'Multiple devices'

  test-examples-windows-dg2:
    secrets: inherit
    needs: [ build-windows-gpu ]
    uses: intel-innersource/libraries.devops.renderkit.workflows/.github/workflows/windows_gpu.yml@main
    with:
      force-delete: true    # guarantees .gitattributes are respected in working dir
      submodules: true
      runs-on: '[ "Windows", "dg2" ]'
      env-from-files: ./.github/deps/dpcpp-sycl-nightly.env ./.github/deps/gfx-windows-public.env
      artifact-in: build-windows-gpu
      artifact-out: test-examples-dg2
      artifact-path: ./build/install/bin/*.pfm
      artifact-on-failure: true
      cmd: |
        # Prepare img_diff tool to be ready for CI usage (copy it on local runner)
        $img_diff_dir = $env:STORAGE_PATH + '\tools\img-diff\dist_windows'
        Copy-Item -Path "$img_diff_dir" -Destination $pwd\img-diff -Recurse
        $img_diff_path = "$pwd\img-diff\img_diff.exe"

        cd $env:GITHUB_WORKSPACE/build/install/bin
        python $env:GITHUB_WORKSPACE/.github/scripts/run-examples-tests.py "$img_diff_path"