Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Vulkan |
| 3 | * |
| 4 | * Copyright (C) 2015 LunarG, Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included |
| 14 | * in all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 | * DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: |
| 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | */ |
| 27 | |
| 28 | #include "string.h" |
| 29 | #include "vk_layer_extension_utils.h" |
| 30 | |
Courtney Goeltzenleuchter | 58e1e3b | 2015-07-06 22:29:41 -0600 | [diff] [blame^] | 31 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) |
| 32 | |
Courtney Goeltzenleuchter | 110fdf9 | 2015-06-29 15:39:26 -0600 | [diff] [blame] | 33 | /* |
| 34 | * This file contains utility functions for layers |
| 35 | */ |
| 36 | |
| 37 | VkResult util_GetExtensionProperties( |
| 38 | const uint32_t count, |
| 39 | const VkExtensionProperties *layer_extensions, |
| 40 | uint32_t* pCount, |
| 41 | VkExtensionProperties* pProperties) |
| 42 | { |
| 43 | uint32_t copy_size; |
| 44 | |
| 45 | if (pCount == NULL) { |
| 46 | return VK_ERROR_INVALID_POINTER; |
| 47 | } |
| 48 | |
| 49 | if (pProperties == NULL || layer_extensions == NULL) { |
| 50 | *pCount = count; |
| 51 | return VK_SUCCESS; |
| 52 | } |
| 53 | |
| 54 | copy_size = *pCount < count ? *pCount : count; |
| 55 | memcpy(pProperties, layer_extensions, copy_size * sizeof(VkExtensionProperties)); |
| 56 | *pCount = copy_size; |
| 57 | if (copy_size < count) { |
| 58 | return VK_INCOMPLETE; |
| 59 | } |
| 60 | |
| 61 | return VK_SUCCESS; |
| 62 | } |
| 63 | |
| 64 | VkResult util_GetLayerProperties( |
| 65 | const uint32_t count, |
| 66 | const VkLayerProperties *layer_properties, |
| 67 | uint32_t* pCount, |
| 68 | VkLayerProperties* pProperties) |
| 69 | { |
| 70 | uint32_t copy_size; |
| 71 | |
| 72 | if (pCount == NULL) { |
| 73 | return VK_ERROR_INVALID_POINTER; |
| 74 | } |
| 75 | |
| 76 | if (pProperties == NULL || layer_properties == NULL) { |
| 77 | *pCount = count; |
| 78 | return VK_SUCCESS; |
| 79 | } |
| 80 | |
| 81 | copy_size = *pCount < count ? *pCount : count; |
| 82 | memcpy(pProperties, layer_properties, copy_size * sizeof(VkLayerProperties)); |
| 83 | *pCount = copy_size; |
| 84 | if (copy_size < count) { |
| 85 | return VK_INCOMPLETE; |
| 86 | } |
| 87 | |
| 88 | return VK_SUCCESS; |
| 89 | } |