#!/bin/bash -xe
## Copyright 2023 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

# These tests are to verify if rendered image is correct for big volume size on PVC.
# `time` command used here is just to see what is total execution time (for roughly estimation).

IMG_DIFF_TOOL=$STORAGE_PATH/tools/img_diff/img_diff

# Enable persistent JIT cache
export SYCL_CACHE_PERSISTENT=1
export SYCL_CACHE_DIR=./jit_cache

# dim = 2048^3*sizeof(float) for float give us 32GB of vol. size
dim=2048

time ./bin/vklExamplesGPU -renderer density_pathtracer_gpu -batch -printStats -spp 50 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesGPU -renderer ray_march_iterator_gpu -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesGPU -renderer hit_iterator_renderer_gpu -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesGPU -renderer interval_iterator_debug_gpu -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim

# Run cpu examples to get reference images
time ./bin/vklExamplesCPU -renderer density_pathtracer -batch -printStats -spp 50 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesCPU -renderer ray_march_iterator -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesCPU -renderer hit_iterator_renderer -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim
time ./bin/vklExamplesCPU -renderer interval_iterator_debug -batch -printStats -spp 2 -framebufferSize 1024 1024 -gridDimensions $dim $dim $dim

# Compare images generated by GPU examples vs CPU examples
$IMG_DIFF_TOOL density_pathtracer.pfm density_pathtracer_gpu.pfm
$IMG_DIFF_TOOL ray_march_iterator.pfm ray_march_iterator_gpu.pfm 0.0001
$IMG_DIFF_TOOL hit_iterator_renderer.pfm hit_iterator_renderer_gpu.pfm 0.00005
$IMG_DIFF_TOOL interval_iterator_debug.pfm interval_iterator_debug_gpu.pfm 0.00003