rs2spirv_driver.sh revision bf22a8ab4f46a98ee37f95fc0402744132cc3ed2
1# Copyright 2016, The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15#!/bin/bash
16
17ME=$0
18
19function usage {
20  echo >&2 "$ME: $*: Expected [-d|--dump] [-t|--trace] <SPIRV_TOOLS_PATH> <SCRIPT_NAME> <OUTPUT_DIR>)"
21  exit 2
22}
23
24function dump {
25  if [[ -z "${DUMP:-}" ]] ; then
26    return 0
27  fi
28  eval rs2spirv "$output_folder/$script.spv" -print-as-words
29  return $?
30}
31
32DUMP=
33TRACE=
34
35while [[ "${1:-}" = -* ]] ; do
36  case "$1" in
37    -d|--dump)
38      DUMP=t
39      ;;
40    -t|--trace)
41      TRACE=t
42      ;;
43    *)
44      usage "Unexpected option \"$1\""
45      ;;
46  esac
47  shift
48done
49
50if [[ $# -ne 3 ]] ; then
51  usage "Bad argument count (got $#)"
52fi
53
54if [[ -n "${TRACE:-}" ]] ; then
55  set -x
56fi
57
58AND_HOME=$ANDROID_BUILD_TOP
59SPIRV_TOOLS_PATH=$1
60
61script_name="$2"
62script=`basename ${2%.*}` # Remove enclosing directories and extension.
63
64output_folder="$3"
65mkdir -p $output_folder
66
67eval llvm-rs-cc -o "$output_folder" -S -emit-llvm -Wall -Werror -target-api 24 \
68  -I "$AND_HOME/external/clang/lib/Headers" -I "$AND_HOME/frameworks/rs/script_api/include" \
69  "$script_name" &&
70eval llvm-as "$output_folder/bc32/$script.ll" -o "$output_folder/$script.bc" &&
71eval rs2spirv "$output_folder/$script.bc" -o "$output_folder/$script.spv" &&
72dump &&
73eval "$SPIRV_TOOLS_PATH/spirv-val" "$output_folder/$script.spv" &&
74
75exit $?
76