blob: 36eb1b500069c1112ba8384e90fd4a38dca0aeca [file] [log] [blame]
Mark Lobodzinski288e4f72016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -06004 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -07005 * 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 Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060011 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070012 * The above copyright notice(s) and this permission notice shall be included
13 * in all copies or substantial portions of the Materials.
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060014 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070015 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070017 * 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 Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060023 *
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060024 * Author: Tobin Ehlis <tobin@lunarg.com>
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060025 */
26
27#ifndef LAYER_DATA_H
28#define LAYER_DATA_H
29
30#include <unordered_map>
Tobin Ehlis56d204a2015-07-03 10:15:26 -060031#include "vk_layer_table.h"
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060032
Jon Ashburn491a3cd2016-03-08 17:48:44 -070033template <typename DATA_T> DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) {
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060034 DATA_T *debug_data;
35 typename std::unordered_map<void *, DATA_T *>::const_iterator got;
36
Courtney Goeltzenleuchterd97cc722015-07-05 11:19:03 -060037 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060038 got = layer_data_map.find(data_key);
39
Jon Ashburn491a3cd2016-03-08 17:48:44 -070040 if (got == layer_data_map.end()) {
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060041 debug_data = new DATA_T;
Jon Ashburn491a3cd2016-03-08 17:48:44 -070042 layer_data_map[(void *)data_key] = debug_data;
Courtney Goeltzenleuchterc3442fc2015-06-13 11:18:17 -060043 } else {
44 debug_data = got->second;
45 }
46
47 return debug_data;
48}
49
50#endif // LAYER_DATA_H