blob: eb2b8b479e32fc109e9ee09168907b3dfc61f7f9 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-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 Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -06004 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -06008 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06009 * http://www.apache.org/licenses/LICENSE-2.0
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060016 *
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060017 * Author: Tobin Ehlis <tobin@lunarg.com>
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060018 */
19
20#ifndef LAYER_DATA_H
21#define LAYER_DATA_H
22
23#include <unordered_map>
Tobin Ehlisa0cb02e2015-07-03 10:15:26 -060024#include "vk_layer_table.h"
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060025
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070026template <typename DATA_T>
27DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060028 DATA_T *debug_data;
29 typename std::unordered_map<void *, DATA_T *>::const_iterator got;
30
Courtney Goeltzenleuchterdb9a96f2015-07-05 11:19:03 -060031 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060032 got = layer_data_map.find(data_key);
33
Jon Ashburn5484e0c2016-03-08 17:48:44 -070034 if (got == layer_data_map.end()) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060035 debug_data = new DATA_T;
Jon Ashburn5484e0c2016-03-08 17:48:44 -070036 layer_data_map[(void *)data_key] = debug_data;
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060037 } else {
38 debug_data = got->second;
39 }
40
41 return debug_data;
42}
43
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070044#endif // LAYER_DATA_H