• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016 Red Hat.
3  * Copyright © 2016 Bas Nieuwenhuizen
4  * SPDX-License-Identifier: MIT
5  *
6  * based in part on anv driver which is:
7  * Copyright © 2015 Intel Corporation
8  */
9 
10 #ifndef TU_IMAGE_H
11 #define TU_IMAGE_H
12 
13 #include "tu_common.h"
14 
15 #define tu_image_view_stencil(iview, x) \
16    ((iview->view.x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT))
17 
18 #define tu_image_view_depth(iview, x) \
19    ((iview->view.x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_32_FLOAT))
20 
21 struct tu_image
22 {
23    struct vk_image vk;
24 
25    struct fdl_layout layout[3];
26    uint32_t total_size;
27 
28 #if DETECT_OS_ANDROID
29    /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
30    VkDeviceMemory owned_memory;
31 #endif
32 
33    /* Set when bound */
34    struct tu_bo *bo;
35    uint64_t iova;
36 
37    /* For fragment density map */
38    void *map;
39 
40    uint32_t lrz_height;
41    uint32_t lrz_pitch;
42    uint32_t lrz_offset;
43    uint32_t lrz_fc_offset;
44    uint32_t lrz_fc_size;
45 };
46 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
47 
48 struct tu_image_view
49 {
50    struct vk_image_view vk;
51 
52    struct tu_image *image; /**< VkImageViewCreateInfo::image */
53 
54    struct fdl6_view view;
55 
56    unsigned char swizzle[4];
57 
58    /* for d32s8 separate depth */
59    uint64_t depth_base_addr;
60    uint32_t depth_layer_size;
61    uint32_t depth_pitch;
62 
63    /* for d32s8 separate stencil */
64    uint64_t stencil_base_addr;
65    uint32_t stencil_layer_size;
66    uint32_t stencil_pitch;
67 };
68 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, vk.base, VkImageView,
69                                VK_OBJECT_TYPE_IMAGE_VIEW);
70 
71 struct tu_buffer_view
72 {
73    struct vk_object_base base;
74 
75    uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
76 
77    struct tu_buffer *buffer;
78 };
79 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_buffer_view, base, VkBufferView,
80                                VK_OBJECT_TYPE_BUFFER_VIEW)
81 
82 uint32_t tu6_plane_count(VkFormat format);
83 enum pipe_format tu6_plane_format(VkFormat format, uint32_t plane);
84 
85 uint32_t tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask);
86 
87 enum pipe_format tu_format_for_aspect(enum pipe_format format,
88                                       VkImageAspectFlags aspect_mask);
89 
90 void
91 tu_cs_image_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
92 
93 template <chip CHIP>
94 void
95 tu_cs_image_ref_2d(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer, bool src);
96 
97 void
98 tu_cs_image_flag_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer);
99 
100 void
101 tu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
102 
103 void
104 tu_cs_image_depth_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer);
105 
106 bool
107 tiling_possible(VkFormat format);
108 
109 bool
110 ubwc_possible(struct tu_device *device,
111               VkFormat format,
112               VkImageType type,
113               VkImageUsageFlags usage,
114               VkImageUsageFlags stencil_usage,
115               const struct fd_dev_info *info,
116               VkSampleCountFlagBits samples,
117               bool use_z24uint_s8uint);
118 
119 void
120 tu_buffer_view_init(struct tu_buffer_view *view,
121                     struct tu_device *device,
122                     const VkBufferViewCreateInfo *pCreateInfo);
123 
124 struct tu_frag_area {
125    float width;
126    float height;
127 };
128 
129 void
130 tu_fragment_density_map_sample(const struct tu_image_view *fdm,
131                                uint32_t x, uint32_t y,
132                                uint32_t width, uint32_t height,
133                                uint32_t layers, struct tu_frag_area *areas);
134 
135 #endif /* TU_IMAGE_H */
136