Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 1 | /* |
Jesse Barker | bccca29 | 2012-01-26 09:36:24 -0800 | [diff] [blame] | 2 | * Copyright © 2011-2012 Linaro Limited |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 3 | * |
| 4 | * This file is part of glcompbench. |
| 5 | * |
| 6 | * glcompbench is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * glcompbench is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with glcompbench. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * Authors: |
| 20 | * Alexandros Frantzis <alexandros.frantzis@linaro.org> |
| 21 | * Jesse Barker <jesse.barker@linaro.org> |
| 22 | */ |
| 23 | |
| 24 | #include <cstring> |
| 25 | #include <cstdlib> |
| 26 | #include <cstdio> |
| 27 | #include <getopt.h> |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 28 | #include <sstream> |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 29 | |
| 30 | #include "options.h" |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 31 | #include "util.h" |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 32 | |
Alexandros Frantzis | d97db37 | 2011-06-09 17:24:50 +0300 | [diff] [blame] | 33 | std::vector<std::string> Options::benchmarks; |
Alexandros Frantzis | fd3ed31 | 2011-09-20 15:52:21 +0300 | [diff] [blame] | 34 | std::vector<std::string> Options::benchmark_files; |
Alexandros Frantzis | 35a1fa1 | 2011-06-15 14:25:14 +0300 | [diff] [blame] | 35 | bool Options::validate = false; |
Alexandros Frantzis | 3f2913a | 2012-03-20 14:55:49 +0200 | [diff] [blame] | 36 | Options::FrameEnd Options::frame_end = Options::FrameEndDefault; |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 37 | std::pair<int,int> Options::size(800, 600); |
Alexandros Frantzis | ced8c58 | 2011-06-09 12:54:56 +0300 | [diff] [blame] | 38 | bool Options::list_scenes = false; |
Alexandros Frantzis | 15bb051 | 2011-09-20 12:45:24 +0300 | [diff] [blame] | 39 | bool Options::show_all_options = false; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 40 | bool Options::show_debug = false; |
| 41 | bool Options::show_help = false; |
Jesse Barker | af9c7bb | 2012-01-04 09:15:29 -0800 | [diff] [blame] | 42 | bool Options::reuse_context = false; |
Alexandros Frantzis | ae8deb9 | 2012-02-15 19:09:14 +0200 | [diff] [blame] | 43 | bool Options::run_forever = false; |
Alexandros Frantzis | 1c377f1 | 2012-02-16 11:03:42 +0200 | [diff] [blame] | 44 | bool Options::annotate = false; |
Alexandros Frantzis | c047bb9 | 2012-03-20 13:29:25 +0200 | [diff] [blame] | 45 | bool Options::offscreen = false; |
Alexandros Frantzis | 967efea | 2012-05-10 12:18:53 +0300 | [diff] [blame] | 46 | GLVisualConfig Options::visual_config; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 47 | |
| 48 | static struct option long_options[] = { |
Alexandros Frantzis | 1c377f1 | 2012-02-16 11:03:42 +0200 | [diff] [blame] | 49 | {"annotate", 0, 0, 0}, |
Alexandros Frantzis | d97db37 | 2011-06-09 17:24:50 +0300 | [diff] [blame] | 50 | {"benchmark", 1, 0, 0}, |
Alexandros Frantzis | fd3ed31 | 2011-09-20 15:52:21 +0300 | [diff] [blame] | 51 | {"benchmark-file", 1, 0, 0}, |
Alexandros Frantzis | 35a1fa1 | 2011-06-15 14:25:14 +0300 | [diff] [blame] | 52 | {"validate", 0, 0, 0}, |
Alexandros Frantzis | 3f2913a | 2012-03-20 14:55:49 +0200 | [diff] [blame] | 53 | {"frame-end", 1, 0, 0}, |
Alexandros Frantzis | c047bb9 | 2012-03-20 13:29:25 +0200 | [diff] [blame] | 54 | {"off-screen", 0, 0, 0}, |
Alexandros Frantzis | 967efea | 2012-05-10 12:18:53 +0300 | [diff] [blame] | 55 | {"visual-config", 1, 0, 0}, |
Jesse Barker | af9c7bb | 2012-01-04 09:15:29 -0800 | [diff] [blame] | 56 | {"reuse-context", 0, 0, 0}, |
Alexandros Frantzis | ae8deb9 | 2012-02-15 19:09:14 +0200 | [diff] [blame] | 57 | {"run-forever", 0, 0, 0}, |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 58 | {"size", 1, 0, 0}, |
Alexandros Frantzis | cfffb57 | 2012-06-15 12:03:04 +0300 | [diff] [blame] | 59 | {"fullscreen", 0, 0, 0}, |
Alexandros Frantzis | ced8c58 | 2011-06-09 12:54:56 +0300 | [diff] [blame] | 60 | {"list-scenes", 0, 0, 0}, |
Alexandros Frantzis | 15bb051 | 2011-09-20 12:45:24 +0300 | [diff] [blame] | 61 | {"show-all-options", 0, 0, 0}, |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 62 | {"debug", 0, 0, 0}, |
| 63 | {"help", 0, 0, 0}, |
| 64 | {0, 0, 0, 0} |
| 65 | }; |
| 66 | |
Alexandros Frantzis | ebdfc72 | 2011-10-26 14:12:19 +0300 | [diff] [blame] | 67 | /** |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 68 | * Parses a size string of the form WxH |
Alexandros Frantzis | ebdfc72 | 2011-10-26 14:12:19 +0300 | [diff] [blame] | 69 | * |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 70 | * @param str the string to parse |
Alexandros Frantzis | ebdfc72 | 2011-10-26 14:12:19 +0300 | [diff] [blame] | 71 | * @param size the parsed size (width, height) |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 72 | */ |
| 73 | static void |
| 74 | parse_size(const std::string &str, std::pair<int,int> &size) |
| 75 | { |
| 76 | std::vector<std::string> d; |
| 77 | Util::split(str, 'x', d); |
| 78 | |
Alexandros Frantzis | 1583223 | 2011-11-01 18:46:08 +0200 | [diff] [blame] | 79 | size.first = Util::fromString<int>(d[0]); |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * Parse the second element (height). If there is none, use the value |
| 83 | * of the first element for the second (width = height) |
| 84 | */ |
Alexandros Frantzis | 1583223 | 2011-11-01 18:46:08 +0200 | [diff] [blame] | 85 | if (d.size() > 1) |
| 86 | size.second = Util::fromString<int>(d[1]); |
Alexandros Frantzis | ebdfc72 | 2011-10-26 14:12:19 +0300 | [diff] [blame] | 87 | else |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 88 | size.second = size.first; |
| 89 | } |
| 90 | |
Alexandros Frantzis | 3f2913a | 2012-03-20 14:55:49 +0200 | [diff] [blame] | 91 | /** |
| 92 | * Parses a frame-end method string |
| 93 | * |
| 94 | * @param str the string to parse |
| 95 | * |
| 96 | * @return the parsed frame end method |
| 97 | */ |
| 98 | static Options::FrameEnd |
| 99 | frame_end_from_str(const std::string &str) |
| 100 | { |
| 101 | Options::FrameEnd m = Options::FrameEndDefault; |
| 102 | |
| 103 | if (str == "swap") |
| 104 | m = Options::FrameEndSwap; |
| 105 | else if (str == "finish") |
| 106 | m = Options::FrameEndFinish; |
| 107 | else if (str == "readpixels") |
| 108 | m = Options::FrameEndReadPixels; |
| 109 | else if (str == "none") |
| 110 | m = Options::FrameEndNone; |
| 111 | |
| 112 | return m; |
| 113 | } |
| 114 | |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 115 | void |
| 116 | Options::print_help() |
| 117 | { |
| 118 | printf("A benchmark for Open GL (ES) 2.0\n" |
| 119 | "\n" |
| 120 | "Options:\n" |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 121 | " -b, --benchmark BENCH A benchmark to run: 'scene(:opt1=val1)*'\n" |
| 122 | " (the option can be used multiple times)\n" |
Alexandros Frantzis | fd3ed31 | 2011-09-20 15:52:21 +0300 | [diff] [blame] | 123 | " -f, --benchmark-file F Load benchmarks to run from a file containing a\n" |
Alexandros Frantzis | d03a01b | 2011-09-21 17:10:37 +0300 | [diff] [blame] | 124 | " list of benchmark descriptions (one per line)\n" |
| 125 | " (the option can be used multiple times)\n" |
Alexandros Frantzis | 35a1fa1 | 2011-06-15 14:25:14 +0300 | [diff] [blame] | 126 | " --validate Run a quick output validation test instead of \n" |
| 127 | " running the benchmarks\n" |
Alexandros Frantzis | 3f2913a | 2012-03-20 14:55:49 +0200 | [diff] [blame] | 128 | " --frame-end METHOD How to end a frame [default,none,swap,finish,readpixels]\n" |
Alexandros Frantzis | c047bb9 | 2012-03-20 13:29:25 +0200 | [diff] [blame] | 129 | " --off-screen Render to an off-screen surface\n" |
Alexandros Frantzis | 967efea | 2012-05-10 12:18:53 +0300 | [diff] [blame] | 130 | " --visual-config C The visual configuration to use for the rendering\n" |
| 131 | " target: 'red=R:green=G:blue=B:alpha=A:buffer=BUF'.\n" |
| 132 | " The parameters may be defined in any order, and any\n" |
| 133 | " omitted parameters assume a default value of '1'\n" |
Jesse Barker | af9c7bb | 2012-01-04 09:15:29 -0800 | [diff] [blame] | 134 | " --reuse-context Use a single context for all scenes\n" |
| 135 | " (by default, each scene gets its own context)\n" |
Alexandros Frantzis | d03a01b | 2011-09-21 17:10:37 +0300 | [diff] [blame] | 136 | " -s, --size WxH Size of the output window (default: 800x600)\n" |
Alexandros Frantzis | cfffb57 | 2012-06-15 12:03:04 +0300 | [diff] [blame] | 137 | " --fullscreen Run in fullscreen mode (equivalent to --size -1x-1)\n" |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 138 | " -l, --list-scenes Display information about the available scenes\n" |
| 139 | " and their options\n" |
Alexandros Frantzis | 15bb051 | 2011-09-20 12:45:24 +0300 | [diff] [blame] | 140 | " --show-all-options Show all scene option values used for benchmarks\n" |
| 141 | " (only explicitly set options are shown by default)\n" |
Alexandros Frantzis | ae8deb9 | 2012-02-15 19:09:14 +0200 | [diff] [blame] | 142 | " --run-forever Run indefinitely, looping from the last benchmark\n" |
| 143 | " back to the first\n" |
Alexandros Frantzis | 1c377f1 | 2012-02-16 11:03:42 +0200 | [diff] [blame] | 144 | " --annotate Annotate the benchmarks with on-screen information\n" |
| 145 | " (same as -b :show-fps=true:title=#info#)\n" |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 146 | " -d, --debug Display debug messages\n" |
| 147 | " -h, --help Display help\n"); |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 148 | } |
| 149 | |
Alexandros Frantzis | cabf040 | 2011-06-09 14:34:18 +0300 | [diff] [blame] | 150 | bool |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 151 | Options::parse_args(int argc, char **argv) |
| 152 | { |
| 153 | while (1) { |
Alexandros Frantzis | 7af1c6f | 2011-06-09 17:49:13 +0300 | [diff] [blame] | 154 | int option_index = -1; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 155 | int c; |
Alexandros Frantzis | 7af1c6f | 2011-06-09 17:49:13 +0300 | [diff] [blame] | 156 | const char *optname = ""; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 157 | |
Alexandros Frantzis | fd3ed31 | 2011-09-20 15:52:21 +0300 | [diff] [blame] | 158 | c = getopt_long(argc, argv, "b:f:s:ldh", |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 159 | long_options, &option_index); |
| 160 | if (c == -1) |
| 161 | break; |
Alexandros Frantzis | cabf040 | 2011-06-09 14:34:18 +0300 | [diff] [blame] | 162 | if (c == ':' || c == '?') |
| 163 | return false; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 164 | |
Alexandros Frantzis | 7af1c6f | 2011-06-09 17:49:13 +0300 | [diff] [blame] | 165 | if (option_index != -1) |
| 166 | optname = long_options[option_index].name; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 167 | |
Alexandros Frantzis | 1c377f1 | 2012-02-16 11:03:42 +0200 | [diff] [blame] | 168 | if (!strcmp(optname, "annotate")) |
| 169 | Options::annotate = true; |
Alexandros Frantzis | 5bd5d76 | 2011-06-09 17:48:20 +0300 | [diff] [blame] | 170 | if (c == 'b' || !strcmp(optname, "benchmark")) |
| 171 | Options::benchmarks.push_back(optarg); |
Alexandros Frantzis | fd3ed31 | 2011-09-20 15:52:21 +0300 | [diff] [blame] | 172 | else if (c == 'f' || !strcmp(optname, "benchmark-file")) |
| 173 | Options::benchmark_files.push_back(optarg); |
Alexandros Frantzis | 35a1fa1 | 2011-06-15 14:25:14 +0300 | [diff] [blame] | 174 | else if (!strcmp(optname, "validate")) |
| 175 | Options::validate = true; |
Alexandros Frantzis | 3f2913a | 2012-03-20 14:55:49 +0200 | [diff] [blame] | 176 | else if (!strcmp(optname, "frame-end")) |
| 177 | Options::frame_end = frame_end_from_str(optarg); |
Alexandros Frantzis | c047bb9 | 2012-03-20 13:29:25 +0200 | [diff] [blame] | 178 | else if (!strcmp(optname, "off-screen")) |
| 179 | Options::offscreen = true; |
Alexandros Frantzis | 967efea | 2012-05-10 12:18:53 +0300 | [diff] [blame] | 180 | else if (!strcmp(optname, "visual-config")) |
| 181 | Options::visual_config = GLVisualConfig(optarg); |
Jesse Barker | af9c7bb | 2012-01-04 09:15:29 -0800 | [diff] [blame] | 182 | else if (!strcmp(optname, "reuse-context")) |
| 183 | Options::reuse_context = true; |
Alexandros Frantzis | cad7bef | 2011-08-09 14:13:43 +0300 | [diff] [blame] | 184 | else if (c == 's' || !strcmp(optname, "size")) |
| 185 | parse_size(optarg, Options::size); |
Alexandros Frantzis | cfffb57 | 2012-06-15 12:03:04 +0300 | [diff] [blame] | 186 | else if (!strcmp(optname, "fullscreen")) |
| 187 | Options::size = std::pair<int,int>(-1, -1); |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 188 | else if (c == 'l' || !strcmp(optname, "list-scenes")) |
Alexandros Frantzis | 5bd5d76 | 2011-06-09 17:48:20 +0300 | [diff] [blame] | 189 | Options::list_scenes = true; |
Alexandros Frantzis | 15bb051 | 2011-09-20 12:45:24 +0300 | [diff] [blame] | 190 | else if (!strcmp(optname, "show-all-options")) |
| 191 | Options::show_all_options = true; |
Alexandros Frantzis | ae8deb9 | 2012-02-15 19:09:14 +0200 | [diff] [blame] | 192 | else if (!strcmp(optname, "run-forever")) |
| 193 | Options::run_forever = true; |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 194 | else if (c == 'd' || !strcmp(optname, "debug")) |
Alexandros Frantzis | 5bd5d76 | 2011-06-09 17:48:20 +0300 | [diff] [blame] | 195 | Options::show_debug = true; |
Alexandros Frantzis | 4e01b6b | 2011-06-09 17:54:24 +0300 | [diff] [blame] | 196 | else if (c == 'h' || !strcmp(optname, "help")) |
Alexandros Frantzis | 5bd5d76 | 2011-06-09 17:48:20 +0300 | [diff] [blame] | 197 | Options::show_help = true; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 198 | } |
Alexandros Frantzis | cabf040 | 2011-06-09 14:34:18 +0300 | [diff] [blame] | 199 | |
| 200 | return true; |
Alexandros Frantzis | 7248309 | 2011-06-08 14:24:18 +0300 | [diff] [blame] | 201 | } |