-
Notifications
You must be signed in to change notification settings - Fork 0
/
wgslgen.sh
executable file
·124 lines (120 loc) · 3.88 KB
/
wgslgen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
set -e
# default config values
SEED=
OUTPUT_FILE=
RANDOMIZE_OUTPUT_FILE=0
CONFIG_FILE=
TINT_SAFE=1
NAGA_SAFE=1
USE_JAR=0
while [ $# -gt 0 ]; do
case "${1}" in
-h|--help)
echo "
USAGE: ./wgslgen.sh [OPTIONS]
OPTIONS:
-h, --help Print help message
-o, --output-shader <OUTPUT_SHADER> Path the generated shader should be written to
[default: none - shader printed to stdout]
-c, --input-config <INPUT_CONFIG> Path of the config file that should be passed [default:
none - internal default config used]
-s, --seed <SEED> Seed (signed 64-bit integer) to provide to internal
random generator [default: none - random seed generated]
-j, --use-jar Use the standalone wgslgenerator jar, which must be
located in the top-level wgslgenerator directory
[default: disabled]
-(r/R), --(enable/disable)-randomize-output-file Enable/disable output logging if any test fails
[default: enabled]
-(t/T), --set-tint-(safe/not-safe) Enable/disable output logging if all tests pass
[default: disabled]
-(n/N), --set-naga-(safe/not-safe) Enable/disable printing error output to the console if
any tests fail [default: disabled]"
exit 0
;;
-s|--seed)
if [ ! "${2}" ]; then
echo "Error: no seed was provided."
exit 1
else
SEED="${2}"
fi
shift
shift
;;
-o|--output-shader)
if [ ! "${2}" ]; then
echo "Error: no output file path was provided."
exit 1
else
OUTPUT_FILE="${2}"
fi
# validate that the provided output path ends in .wgsl
if [ "${OUTPUT_FILE##*.}" != wgsl ]; then
echo "Error: provided output file is not a WGSL file."
exit 1
elif [ -f "${OUTPUT_FILE}" ] && [ ! -w "${OUTPUT_FILE}" ]; then
echo "Error: existing output file at provided path cannot be written to."
exit 1
fi
shift
shift
;;
-c|--input-config)
if [ ! "${2}" ]; then
echo "Error: no config file was provided."
exit 1
else
CONFIG_FILE="${2}"
fi
if [ ! -f "${CONFIG_FILE}" ]; then
echo "Error: provided config file does not exist."
exit 1
# validate that the provided config file ends in .json
elif [ "${CONFIG_FILE##*.}" != json ]; then
echo "Error: provided config file is not a JSON file."
exit 1
fi
shift
shift
;;
-r|--enable-randomize-output-file)
RANDOMIZE_OUTPUT_FILE=1
shift
;;
-R|--disable-randomize-output-file)
RANDOMIZE_OUTPUT_FILE=0
shift
;;
-t|--set-tint-safe)
TINT_SAFE=1
shift
;;
-T|--set-tint-not-safe)
TINT_SAFE=0
shift
;;
-n|--set-naga-safe)
NAGA_SAFE=1
shift
;;
-N|--set-naga-not-safe)
NAGA_SAFE=0
shift
;;
-j|--use-jar)
USE_JAR=1
shift
;;
*)
echo "Error: unrecognised argument provided."
exit 1
;;
esac
done
if [ "${USE_JAR}" -eq 1 ]; then
java -jar wgslgenerator.jar "${RANDOMIZE_OUTPUT_FILE}" "${TINT_SAFE}" "${NAGA_SAFE}" \
"conf:${CONFIG_FILE}" "out:${OUTPUT_FILE}" "seed:${SEED}"
else
./gradlew run --args="${RANDOMIZE_OUTPUT_FILE} ${TINT_SAFE} ${NAGA_SAFE} \
conf:${CONFIG_FILE} out:${OUTPUT_FILE} seed:${SEED}" -quiet
fi