• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google LLC
3  * SPDX-License-Identifier: MIT
4  *
5  * based in part on anv and radv which are:
6  * Copyright © 2015 Intel Corporation
7  * Copyright © 2016 Red Hat.
8  * Copyright © 2016 Bas Nieuwenhuizen
9  */
10 
11 #ifndef VN_IMAGE_H
12 #define VN_IMAGE_H
13 
14 #include "vn_common.h"
15 
16 /* changing this to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR disables ownership
17  * transfers and can be useful for debugging
18  */
19 #define VN_PRESENT_SRC_INTERNAL_LAYOUT VK_IMAGE_LAYOUT_GENERAL
20 
21 struct vn_image_memory_requirements {
22    VkMemoryRequirements2 memory;
23    VkMemoryDedicatedRequirements dedicated;
24 };
25 
26 struct vn_image_create_deferred_info {
27    VkImageCreateInfo create;
28    VkImageFormatListCreateInfo list;
29    VkImageStencilUsageCreateInfo stencil;
30 
31    /* True if VkImageCreateInfo::format is translated from a non-zero
32     * VkExternalFormatANDROID::externalFormat for the AHB image.
33     */
34    bool from_external_format;
35    /* track whether vn_image_init_deferred succeeds */
36    bool initialized;
37 };
38 
39 struct vn_image {
40    struct vn_object_base base;
41 
42    VkSharingMode sharing_mode;
43 
44    struct vn_image_memory_requirements requirements[4];
45 
46    /* For VK_ANDROID_external_memory_android_hardware_buffer, real image
47     * creation is deferred until bind image memory.
48     */
49    struct vn_image_create_deferred_info *deferred_info;
50 
51    struct {
52       /* True if this is a swapchain image and VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
53        * is a valid layout.  A swapchain image can be created internally
54        * (wsi_image_create_info) or externally (VkNativeBufferANDROID and
55        * VkImageSwapchainCreateInfoKHR).
56        */
57       bool is_wsi;
58       bool is_prime_blit_src;
59       VkImageTiling tiling_override;
60       /* valid when tiling is VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT */
61       uint64_t drm_format_modifier;
62 
63       struct vn_device_memory *memory;
64 
65       /* For VK_ANDROID_native_buffer, the WSI image owns the memory. */
66       bool memory_owned;
67    } wsi;
68 };
69 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_image,
70                                base.base,
71                                VkImage,
72                                VK_OBJECT_TYPE_IMAGE)
73 
74 struct vn_image_view {
75    struct vn_object_base base;
76 
77    const struct vn_image *image;
78 };
79 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_image_view,
80                                base.base,
81                                VkImageView,
82                                VK_OBJECT_TYPE_IMAGE_VIEW)
83 
84 struct vn_sampler {
85    struct vn_object_base base;
86 };
87 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_sampler,
88                                base.base,
89                                VkSampler,
90                                VK_OBJECT_TYPE_SAMPLER)
91 
92 struct vn_sampler_ycbcr_conversion {
93    struct vn_object_base base;
94 };
95 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_sampler_ycbcr_conversion,
96                                base.base,
97                                VkSamplerYcbcrConversion,
98                                VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)
99 
100 VkResult
101 vn_image_create(struct vn_device *dev,
102                 const VkImageCreateInfo *create_info,
103                 const VkAllocationCallbacks *alloc,
104                 struct vn_image **out_img);
105 
106 VkResult
107 vn_image_init_deferred(struct vn_device *dev,
108                        const VkImageCreateInfo *create_info,
109                        struct vn_image *img);
110 
111 VkResult
112 vn_image_create_deferred(struct vn_device *dev,
113                          const VkImageCreateInfo *create_info,
114                          const VkAllocationCallbacks *alloc,
115                          struct vn_image **out_img);
116 
117 #endif /* VN_IMAGE_H */
118