blob: 84bbad219b0d4fa41c87a865e1a6b90c73931e89 [file] [log] [blame]
Tobin Ehlis8d6acde2017-02-08 07:40:40 -07001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 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 *
Tobin Ehlis8d6acde2017-02-08 07:40:40 -070017 * Author: Tobin Ehlis <tobine@google.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
Tobin Ehlis8d6acde2017-02-08 07:40:40 -070026// For the given data key, look up the layer_data instance from given layer_data_map
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070027template <typename DATA_T>
Tobin Ehlis8d6acde2017-02-08 07:40:40 -070028DATA_T *GetLayerDataPtr(void *data_key, std::unordered_map<void *, DATA_T *> &layer_data_map) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060029 DATA_T *debug_data;
30 typename std::unordered_map<void *, DATA_T *>::const_iterator got;
31
Courtney Goeltzenleuchterdb9a96f2015-07-05 11:19:03 -060032 /* TODO: We probably should lock here, or have caller lock */
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060033 got = layer_data_map.find(data_key);
34
Jon Ashburn5484e0c2016-03-08 17:48:44 -070035 if (got == layer_data_map.end()) {
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060036 debug_data = new DATA_T;
Jon Ashburn5484e0c2016-03-08 17:48:44 -070037 layer_data_map[(void *)data_key] = debug_data;
Courtney Goeltzenleuchter0fef9fd2015-06-13 11:18:17 -060038 } else {
39 debug_data = got->second;
40 }
41
42 return debug_data;
43}
44
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070045#endif // LAYER_DATA_H