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