1 /* Copyright (c) 2015-2016 The Khronos Group Inc. 2 * Copyright (c) 2015-2016 Valve Corporation 3 * Copyright (c) 2015-2016 LunarG, Inc. 4 * 5 * 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 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * 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. 16 * 17 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com> 18 * 19 */ 20 21 #include "string.h" 22 #include "vk_layer_extension_utils.h" 23 24 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) 25 26 /* 27 * This file contains utility functions for layers 28 */ 29 30 VK_LAYER_EXPORT VkResult util_GetExtensionProperties(const uint32_t count, const VkExtensionProperties *layer_extensions, 31 uint32_t *pCount, VkExtensionProperties *pProperties) { 32 uint32_t copy_size; 33 34 if (pProperties == NULL || layer_extensions == NULL) { 35 *pCount = count; 36 return VK_SUCCESS; 37 } 38 39 copy_size = *pCount < count ? *pCount : count; 40 memcpy(pProperties, layer_extensions, copy_size * sizeof(VkExtensionProperties)); 41 *pCount = copy_size; 42 if (copy_size < count) { 43 return VK_INCOMPLETE; 44 } 45 46 return VK_SUCCESS; 47 } 48 49 VK_LAYER_EXPORT VkResult util_GetLayerProperties(const uint32_t count, const VkLayerProperties *layer_properties, uint32_t *pCount, 50 VkLayerProperties *pProperties) { 51 uint32_t copy_size; 52 53 if (pProperties == NULL || layer_properties == NULL) { 54 *pCount = count; 55 return VK_SUCCESS; 56 } 57 58 copy_size = *pCount < count ? *pCount : count; 59 memcpy(pProperties, layer_properties, copy_size * sizeof(VkLayerProperties)); 60 *pCount = copy_size; 61 if (copy_size < count) { 62 return VK_INCOMPLETE; 63 } 64 65 return VK_SUCCESS; 66 } 67