blob: b7e71f2cdae7e87cea188d5ec0a99f79b63e3031 [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
Jon Ashburn5484e0c2016-03-08 17:48:44 -070026template <typename DATA_T> DATA_T *get_my_data_ptr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060027 DATA_T *debug_data;
28 typename std::unordered_map<void *, DATA_T *>::const_iterator got;
29
Courtney Goeltzenleuchterdb9a96f2015-07-05 11:19:03 -060030 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060031 got = layer_data_map.find(data_key);
32
Jon Ashburn5484e0c2016-03-08 17:48:44 -070033 if (got == layer_data_map.end()) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060034 debug_data = new DATA_T;
Jon Ashburn5484e0c2016-03-08 17:48:44 -070035 layer_data_map[(void *)data_key] = debug_data;
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060036 } else {
37 debug_data = got->second;
38 }
39
40 return debug_data;
41}
42
43#endif // LAYER_DATA_H