forked from gnif/LookingGlass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl-check
executable file
·152 lines (126 loc) · 3.34 KB
/
gl-check
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"
WAYLAND_SHELL="${WAYLAND_SHELL:-xdg-shell}"
CLANG_QUERY="${CLANG_QUERY:-clang-query}"
BUILD_DIR="${BUILD_DIR:-$SCRIPT_DIR/client/build}"
case "$WAYLAND_SHELL" in
xdg-shell) shell_ignore=shell_libdecor.c ;;
libdecor) shell_ignore=shell_xdg.c ;;
*)
echo "Unknown Wayland shell: $WAYLAND_SHELL"
exit 1
esac
if ! command -v "$CLANG_QUERY" &> /dev/null; then
echo "clang-query is not installed"
exit 1
fi
if [ ! -f "$BUILD_DIR/compile_commands.json" ]; then
echo "compile_commands.json not found in $BUILD_DIR"
echo 'Run cmake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to enable'
exit 1
fi
tempdir="$(mktemp -d)"
cleanup() {
rm -rf "$tempdir"
}
trap cleanup EXIT
sed '/EGL_VERSION_1_5/,$d' /usr/include/EGL/egl.h > "$tempdir/egl1.4.h"
getCalls() {
query="$1"
dir="$2"
command=(find "$dir" -name '*.c')
if [ $# -gt 2 ]; then
command+=(-not)
shift 2
for exclude in "$@"; do
command+=(-name "$exclude")
done
fi
cat > "$tempdir/query" <<EOF
set output print
set bind-root false
m callExpr(callee(functionDecl(matchesName("::$query")).bind("func")))
EOF
"${command[@]}" -exec "$CLANG_QUERY" -p "$BUILD_DIR/compile_commands.json" -f "$tempdir/query" {} + | \
grep -Po "(?<= )\b$query(?=\()" | sort -u
}
checkCalls() {
name="$1"
file="$2"
standard="$3"
while read -r func; do
if ! grep -q "$func" "$file"; then
echo "Found $func in $name, which is not in $standard"
fails=$((fails+1))
fi
done
}
getGLCalls() {
getCalls 'gl[A-WYZ]\w*' "$@"
}
getEGLCalls() {
getCalls 'egl[A-Z]\w*' "$@"
}
getGLXCalls() {
getCalls 'glX\w+' "$@"
}
checkGLESCalls() {
name="$1"
shift
checkCalls "$name" /usr/include/GLES3/gl3.h 'OpenGL ES 3.0' < <(getGLCalls "$@")
}
checkEGLCalls() {
name="$1"
shift
checkCalls "$name" "$tempdir/egl1.4.h" 'EGL 1.4' < <(getEGLCalls "$@")
}
checkGLCalls() {
name="$1"
shift
checkCalls "$name" /usr/include/GL/gl.h 'OpenGL 1.3' < <(getGLCalls "$@")
}
checkGLXCalls() {
name="$1"
shift
checkCalls "$name" /usr/include/GL/glx.h 'GLX 1.3' < <(getGLXCalls "$@")
}
forbidCalls() {
name="$1"
while read -r func; do
echo "Found $func in $name, which is forbidden"
fails=$((fails+1))
done
}
forbidEGLCalls() {
name="$1"
shift
forbidCalls "$name" < <(getEGLCalls "$@")
}
forbidGLXCalls() {
name="$1"
shift
forbidCalls "$name" < <(getGLXCalls "$@")
}
forbidGLCalls() {
name="$1"
shift
forbidCalls "$name" < <(getGLCalls "$@")
}
fails=0
checkGLESCalls 'EGL backend' client/renderers/EGL
checkEGLCalls 'EGL backend' client/renderers/EGL
forbidGLXCalls 'EGL backend' client/renderers/EGL
checkGLCalls 'OpenGL backend' client/renderers/OpenGL
forbidGLXCalls 'OpenGL backend' client/renderers/OpenGL
checkGLXCalls 'X11 display server' client/displayservers/X11
forbidGLCalls 'X11 display server' client/displayservers/X11
checkEGLCalls 'Wayland display server' client/displayservers/Wayland "$shell_ignore"
forbidGLCalls 'Wayland display server' client/displayservers/Wayland "$shell_ignore"
forbidGLXCalls 'Wayland display server' client/displayservers/Wayland "$shell_ignore"
if [ "$fails" -eq 0 ]; then
echo 'All GL function calls look fine.'
else
echo 'Use indirection for the listed GL function calls.'
exit 1
fi