diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/Makefile.sources | 4 | ||||
-rw-r--r-- | src/compiler/glsl/link_uniform_initializers.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/link_uniforms.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/linker.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/shader_cache.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/standalone.cpp | 2 | ||||
-rw-r--r-- | src/compiler/glsl/string_to_uint_map.cpp | 42 | ||||
-rw-r--r-- | src/compiler/glsl/string_to_uint_map.h | 177 | ||||
-rw-r--r-- | src/compiler/glsl/tests/set_uniform_initializer_tests.cpp | 2 |
9 files changed, 228 insertions, 7 deletions
diff --git a/src/compiler/Makefile.sources b/src/compiler/Makefile.sources index a56a7103515..0153df2d812 100644 --- a/src/compiler/Makefile.sources +++ b/src/compiler/Makefile.sources @@ -140,7 +140,9 @@ LIBGLSL_FILES = \ glsl/program.h \ glsl/propagate_invariance.cpp \ glsl/s_expression.cpp \ - glsl/s_expression.h + glsl/s_expression.h \ + glsl/string_to_uint_map.cpp \ + glsl/string_to_uint_map.h LIBGLSL_SHADER_CACHE_FILES = \ glsl/shader_cache.cpp \ diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp index 4ca1a0fe0c4..01754cd3daf 100644 --- a/src/compiler/glsl/link_uniform_initializers.cpp +++ b/src/compiler/glsl/link_uniform_initializers.cpp @@ -25,7 +25,7 @@ #include "ir.h" #include "linker.h" #include "ir_uniform.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" /* These functions are put in a "private" namespace instead of being marked * static so that the unit tests can access them. See diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index f7ee17ef021..7d141549f55 100644 --- a/src/compiler/glsl/link_uniforms.cpp +++ b/src/compiler/glsl/link_uniforms.cpp @@ -27,7 +27,7 @@ #include "ir_uniform.h" #include "glsl_symbol_table.h" #include "program.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" #include "ir_array_refcount.h" /** diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 131518b15fc..5c3f1d12bbc 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -75,7 +75,7 @@ #include "program/program.h" #include "util/mesa-sha1.h" #include "util/set.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" #include "linker.h" #include "link_varyings.h" #include "ir_optimization.h" diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp index a6e99821842..c9109aa222b 100644 --- a/src/compiler/glsl/shader_cache.cpp +++ b/src/compiler/glsl/shader_cache.cpp @@ -59,7 +59,7 @@ #include "program.h" #include "shader_cache.h" #include "util/mesa-sha1.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" extern "C" { #include "main/enums.h" diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp index 7e5c06d2054..2f74813182f 100644 --- a/src/compiler/glsl/standalone.cpp +++ b/src/compiler/glsl/standalone.cpp @@ -36,7 +36,7 @@ #include "loop_analysis.h" #include "standalone_scaffolding.h" #include "standalone.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" #include "util/set.h" #include "linker.h" #include "glsl_parser_extras.h" diff --git a/src/compiler/glsl/string_to_uint_map.cpp b/src/compiler/glsl/string_to_uint_map.cpp new file mode 100644 index 00000000000..35fb76bf78d --- /dev/null +++ b/src/compiler/glsl/string_to_uint_map.cpp @@ -0,0 +1,42 @@ +/* + * Copyright © 2011 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file string_to_uint_map.cpp + * \brief Dumb wrapprs so that C code can create and destroy maps. + * + * \author Ian Romanick <[email protected]> + */ +#include "string_to_uint_map.h" + +extern "C" struct string_to_uint_map * +string_to_uint_map_ctor() +{ + return new string_to_uint_map; +} + +extern "C" void +string_to_uint_map_dtor(struct string_to_uint_map *map) +{ + delete map; +} diff --git a/src/compiler/glsl/string_to_uint_map.h b/src/compiler/glsl/string_to_uint_map.h new file mode 100644 index 00000000000..e0533ec6ea5 --- /dev/null +++ b/src/compiler/glsl/string_to_uint_map.h @@ -0,0 +1,177 @@ +/* + * Copyright © 2008 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#ifndef STRING_TO_UINT_MAP_H +#define STRING_TO_UINT_MAP_H + +#include <string.h> +#include <limits.h> +#include "util/hash_table.h" + +struct string_to_uint_map; + +#ifdef __cplusplus +extern "C" { +#endif + +struct string_to_uint_map * +string_to_uint_map_ctor(); + +void +string_to_uint_map_dtor(struct string_to_uint_map *); + + +#ifdef __cplusplus +} + +struct string_map_iterate_wrapper_closure { + void (*callback)(const char *key, unsigned value, void *closure); + void *closure; +}; + +/** + * Map from a string (name) to an unsigned integer value + * + * \note + * Because of the way this class interacts with the \c hash_table + * implementation, values of \c UINT_MAX cannot be stored in the map. + */ +struct string_to_uint_map { +public: + string_to_uint_map() + { + this->ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string, + _mesa_key_string_equal); + } + + ~string_to_uint_map() + { + hash_table_call_foreach(this->ht, delete_key, NULL); + _mesa_hash_table_destroy(this->ht, NULL); + } + + /** + * Remove all mappings from this map. + */ + void clear() + { + hash_table_call_foreach(this->ht, delete_key, NULL); + _mesa_hash_table_clear(this->ht, NULL); + } + + /** + * Runs a passed callback for the hash + */ + void iterate(void (*func)(const char *, unsigned, void *), void *closure) + { + struct string_map_iterate_wrapper_closure *wrapper; + + wrapper = (struct string_map_iterate_wrapper_closure *) + malloc(sizeof(struct string_map_iterate_wrapper_closure)); + if (wrapper == NULL) + return; + + wrapper->callback = func; + wrapper->closure = closure; + + hash_table_call_foreach(this->ht, subtract_one_wrapper, wrapper); + free(wrapper); + } + + /** + * Get the value associated with a particular key + * + * \return + * If \c key is found in the map, \c true is returned. Otherwise \c false + * is returned. + * + * \note + * If \c key is not found in the table, \c value is not modified. + */ + bool get(unsigned &value, const char *key) + { + hash_entry *entry = _mesa_hash_table_search(this->ht, + (const void *) key); + + if (!entry) + return false; + + const intptr_t v = (intptr_t) entry->data; + value = (unsigned)(v - 1); + return true; + } + + void put(unsigned value, const char *key) + { + /* The low-level hash table structure returns NULL if key is not in the + * hash table. However, users of this map might want to store zero as a + * valid value in the table. Bias the value by +1 so that a + * user-specified zero is stored as 1. This enables ::get to tell the + * difference between a user-specified zero (returned as 1 by + * _mesa_hash_table_search) and the key not in the table (returned as 0 by + * _mesa_hash_table_search). + * + * The net effect is that we can't store UINT_MAX in the table. This is + * because UINT_MAX+1 = 0. + */ + assert(value != UINT_MAX); + char *dup_key = strdup(key); + + struct hash_entry *entry = _mesa_hash_table_search(this->ht, dup_key); + if (entry) { + entry->data = (void *) (intptr_t) (value + 1); + } else { + _mesa_hash_table_insert(this->ht, dup_key, + (void *) (intptr_t) (value + 1)); + } + + if (entry) + free(dup_key); + } + +private: + static void delete_key(const void *key, void *data, void *closure) + { + (void) data; + (void) closure; + + free((char *)key); + } + + static void subtract_one_wrapper(const void *key, void *data, void *closure) + { + struct string_map_iterate_wrapper_closure *wrapper = + (struct string_map_iterate_wrapper_closure *) closure; + unsigned value = (intptr_t) data; + + value -= 1; + + wrapper->callback((const char *) key, value, wrapper->closure); + } + + struct hash_table *ht; +}; + +#endif /* __cplusplus */ +#endif /* STRING_TO_UINT_MAP_H */ diff --git a/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp b/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp index d30abc320b3..94a6d270ec4 100644 --- a/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp +++ b/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp @@ -25,7 +25,7 @@ #include "main/mtypes.h" #include "main/macros.h" #include "util/ralloc.h" -#include "util/string_to_uint_map.h" +#include "string_to_uint_map.h" #include "uniform_initializer_utils.h" namespace linker { |