• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 Valve Corporation
3  * SPDX-License-Identifier: MIT
4  *
5  * Authors:
6  *    Jonathan Marek <jonathan@marek.ca>
7  */
8 
9 #include <vulkan/vulkan.h>
10 #include <vulkan/vk_android_native_buffer.h> /* android tu_entrypoints.h depends on this */
11 #include <assert.h>
12 
13 #include "tu_entrypoints.h"
14 #include "vk_util.h"
15 
16 VKAPI_ATTR void VKAPI_CALL
tu_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice pdev,uint32_t * count,VkQueueFamilyProperties * props)17 tu_GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice pdev,
18                                           uint32_t *count,
19                                           VkQueueFamilyProperties *props)
20 {
21    if (!props)
22       return tu_GetPhysicalDeviceQueueFamilyProperties2(pdev, count, NULL);
23 
24    VkQueueFamilyProperties2 props2[*count];
25    for (uint32_t i = 0; i < *count; i++) {
26       props2[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2;
27       props2[i].pNext = NULL;
28    }
29    tu_GetPhysicalDeviceQueueFamilyProperties2(pdev, count, props2);
30    for (uint32_t i = 0; i < *count; i++)
31       props[i] = props2[i].queueFamilyProperties;
32 }
33 
34 VKAPI_ATTR void VKAPI_CALL
tu_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice pdev,VkFormat format,VkImageType type,VkSampleCountFlagBits samples,VkImageUsageFlags usage,VkImageTiling tiling,uint32_t * count,VkSparseImageFormatProperties * props)35 tu_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice pdev,
36                                                 VkFormat format,
37                                                 VkImageType type,
38                                                 VkSampleCountFlagBits samples,
39                                                 VkImageUsageFlags usage,
40                                                 VkImageTiling tiling,
41                                                 uint32_t *count,
42                                                 VkSparseImageFormatProperties *props)
43 {
44    const VkPhysicalDeviceSparseImageFormatInfo2 info = {
45       .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
46       .format = format,
47       .type = type,
48       .samples = samples,
49       .usage = usage,
50       .tiling = tiling,
51    };
52 
53    if (!props)
54       return tu_GetPhysicalDeviceSparseImageFormatProperties2(pdev, &info, count, NULL);
55 
56    VkSparseImageFormatProperties2 props2[*count];
57    for (uint32_t i = 0; i < *count; i++) {
58       props2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2;
59       props2[i].pNext = NULL;
60    }
61    tu_GetPhysicalDeviceSparseImageFormatProperties2(pdev, &info, count, props2);
62    for (uint32_t i = 0; i < *count; i++)
63       props[i] = props2[i].properties;
64 }
65 
66 VKAPI_ATTR void VKAPI_CALL
tu_GetImageSparseMemoryRequirements(VkDevice device,VkImage image,uint32_t * count,VkSparseImageMemoryRequirements * reqs)67 tu_GetImageSparseMemoryRequirements(VkDevice device,
68                                     VkImage image,
69                                     uint32_t *count,
70                                     VkSparseImageMemoryRequirements *reqs)
71 {
72    const VkImageSparseMemoryRequirementsInfo2 info = {
73       .sType = VK_STRUCTURE_TYPE_IMAGE_SPARSE_MEMORY_REQUIREMENTS_INFO_2,
74       .image = image
75    };
76 
77    if (!reqs)
78       return tu_GetImageSparseMemoryRequirements2(device, &info, count, NULL);
79 
80    VkSparseImageMemoryRequirements2 reqs2[*count];
81    for (uint32_t i = 0; i < *count; i++) {
82       reqs2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_MEMORY_REQUIREMENTS_2;
83       reqs2[i].pNext = NULL;
84    }
85    tu_GetImageSparseMemoryRequirements2(device, &info, count, reqs2);
86    for (uint32_t i = 0; i < *count; i++)
87       reqs[i] = reqs2[i].memoryRequirements;
88 }
89