| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "interface/khronos/common/khrn_options.h" |
| 29 | |
| 30 | #include <memory.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <stdio.h> |
| 33 | |
| 34 | KHRN_OPTIONS_T khrn_options; |
| 35 | |
| 36 | /* For now, we will use environment variables for the options. |
| 37 | We might, at some point, want to use ini files perhaps */ |
| 38 | static bool read_bool_option(const char *name, bool cur) |
| 39 | { |
| 40 | char *val = getenv(name); |
| 41 | |
| 42 | if (val == NULL) |
| 43 | return cur; |
| 44 | |
| 45 | if (val[0] == 't' || val[0] == 'T' || val[0] == '1') |
| 46 | return true; |
| 47 | |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | static uint32_t read_uint32_option(const char *name, uint32_t cur) |
| 52 | { |
| 53 | char *val = getenv(name); |
| 54 | |
| 55 | if (val == NULL) |
| 56 | return cur; |
| 57 | |
| 58 | if (val[0] != '\0') |
| 59 | return atoi(val); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | void khrn_init_options(void) |
| 65 | { |
| 66 | /* Default values are all 0 */ |
| 67 | memset(&khrn_options, 0, sizeof(KHRN_OPTIONS_T)); |
| 68 | |
| 69 | #ifndef DISABLE_OPTION_PARSING |
| 70 | /* Now read the options */ |
| 71 | khrn_options.gl_error_assist = read_bool_option( "V3D_GL_ERROR_ASSIST" , khrn_options.gl_error_assist); |
| 72 | khrn_options.double_buffer = read_bool_option( "V3D_DOUBLE_BUFFER" , khrn_options.double_buffer); |
| 73 | khrn_options.no_bin_render_overlap = read_bool_option( "V3D_NO_BIN_RENDER_OVERLAP" , khrn_options.no_bin_render_overlap); |
| 74 | khrn_options.reg_dump_on_lock = read_bool_option( "V3D_REG_DUMP_ON_LOCK" , khrn_options.reg_dump_on_lock); |
| 75 | khrn_options.clif_dump_on_lock = read_bool_option( "V3D_CLIF_DUMP_ON_LOCK" , khrn_options.clif_dump_on_lock); |
| 76 | khrn_options.force_dither_off = read_bool_option( "V3D_FORCE_DITHER_OFF" , khrn_options.force_dither_off); |
| 77 | |
| 78 | khrn_options.bin_block_size = read_uint32_option("V3D_BIN_BLOCK_SIZE" , khrn_options.bin_block_size); |
| 79 | khrn_options.max_bin_blocks = read_uint32_option("V3D_MAX_BIN_BLOCKS" , khrn_options.max_bin_blocks); |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | void khrn_error_assist(GLenum error, const char *func) |
| 84 | { |
| 85 | if (khrn_options.gl_error_assist && error != GL_NO_ERROR) |
| 86 | { |
| 87 | fprintf(stderr, "V3D ERROR ASSIST : " ); |
| 88 | switch (error) |
| 89 | { |
| 90 | case GL_INVALID_ENUM : fprintf(stderr, "GL_INVALID_ENUM in %s\n" , func); break; |
| 91 | case GL_INVALID_VALUE : fprintf(stderr, "GL_INVALID_VALUE in %s\n" , func); break; |
| 92 | case GL_INVALID_OPERATION : fprintf(stderr, "GL_INVALID_OPERATION in %s\n" , func); break; |
| 93 | case GL_OUT_OF_MEMORY : fprintf(stderr, "GL_OUT_OF_MEMORY in %s\n" , func); break; |
| 94 | default : fprintf(stderr, "ERROR CODE %d in %s\n" , (int)error, func); break; |
| 95 | } |
| 96 | fflush(stderr); |
| 97 | } |
| 98 | } |
| 99 | |