Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 4 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and/or associated documentation files (the "Materials"), to |
| 7 | * deal in the Materials without restriction, including without limitation the |
| 8 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | * sell copies of the Materials, and to permit persons to whom the Materials |
| 10 | * are furnished to do so, subject to the following conditions: |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 11 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 12 | * The above copyright notice(s) and this permission notice shall be included |
| 13 | * in all copies or substantial portions of the Materials. |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 14 | * |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Mark Lobodzinski | 288e4f7 | 2016-02-02 15:55:36 -0700 | [diff] [blame] | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * |
| 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 20 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 22 | * USE OR OTHER DEALINGS IN THE MATERIALS |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 23 | * |
Courtney Goeltzenleuchter | 96cd795 | 2015-10-30 11:14:30 -0600 | [diff] [blame] | 24 | * Author: Tobin Ehlis <tobin@lunarg.com> |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #ifndef LAYER_DATA_H |
| 28 | #define LAYER_DATA_H |
| 29 | |
| 30 | #include <unordered_map> |
Tobin Ehlis | 56d204a | 2015-07-03 10:15:26 -0600 | [diff] [blame] | 31 | #include "vk_layer_table.h" |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 32 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 33 | template <typename DATA_T> DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) { |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 34 | DATA_T *debug_data; |
| 35 | typename std::unordered_map<void *, DATA_T *>::const_iterator got; |
| 36 | |
Courtney Goeltzenleuchter | d97cc72 | 2015-07-05 11:19:03 -0600 | [diff] [blame] | 37 | /* TODO: We probably should lock here, or have caller lock */ |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 38 | got = layer_data_map.find(data_key); |
| 39 | |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 40 | if (got == layer_data_map.end()) { |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 41 | debug_data = new DATA_T; |
Jon Ashburn | 491a3cd | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 42 | layer_data_map[(void *)data_key] = debug_data; |
Courtney Goeltzenleuchter | c3442fc | 2015-06-13 11:18:17 -0600 | [diff] [blame] | 43 | } else { |
| 44 | debug_data = got->second; |
| 45 | } |
| 46 | |
| 47 | return debug_data; |
| 48 | } |
| 49 | |
| 50 | #endif // LAYER_DATA_H |