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_MAX_PLANE_COUNT 3 16 17 #define tu_fdl_view_stencil(view, x) \ 18 (((view)->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT)) 19 20 #define tu_fdl_view_depth(view, x) \ 21 (((view)->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_32_FLOAT)) 22 23 #define tu_image_view_stencil(iview, x) \ 24 tu_fdl_view_stencil(&iview->view, x) 25 26 #define tu_image_view_depth(iview, x) \ 27 tu_fdl_view_depth(&iview->view, x) 28 29 struct tu_image 30 { 31 struct vk_image vk; 32 33 struct fdl_layout layout[3]; 34 uint64_t total_size; 35 36 /* Set when bound */ 37 struct tu_bo *bo; 38 uint64_t iova; 39 40 /* For fragment density map */ 41 void *map; 42 43 uint32_t lrz_height; 44 uint32_t lrz_pitch; 45 uint32_t lrz_offset; 46 uint32_t lrz_fc_offset; 47 bool has_lrz_fc; 48 49 bool ubwc_enabled; 50 bool force_linear_tile; 51 bool ubwc_fc_mutable; 52 }; 53 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE) 54 55 struct tu_image_view 56 { 57 struct vk_image_view vk; 58 59 struct tu_image *image; /**< VkImageViewCreateInfo::image */ 60 61 struct fdl6_view view; 62 63 unsigned char swizzle[4]; 64 65 /* for d32s8 separate depth */ 66 uint64_t depth_base_addr; 67 uint32_t depth_layer_size; 68 uint32_t depth_pitch; 69 70 /* for d32s8 separate stencil */ 71 uint64_t stencil_base_addr; 72 uint32_t stencil_layer_size; 73 uint32_t stencil_pitch; 74 }; 75 VK_DEFINE_NONDISP_HANDLE_CASTS(tu_image_view, vk.base, VkImageView, 76 VK_OBJECT_TYPE_IMAGE_VIEW); 77 78 uint32_t tu6_plane_count(VkFormat format); 79 enum pipe_format tu6_plane_format(VkFormat format, uint32_t plane); 80 81 uint32_t tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask); 82 83 enum pipe_format tu_format_for_aspect(enum pipe_format format, 84 VkImageAspectFlags aspect_mask); 85 86 uint64_t 87 tu_layer_address(const struct fdl6_view *iview, uint32_t layer); 88 89 void 90 tu_cs_image_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer); 91 92 template <chip CHIP> 93 void 94 tu_cs_image_ref_2d(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer, bool src); 95 96 void 97 tu_cs_image_flag_ref(struct tu_cs *cs, const struct fdl6_view *iview, uint32_t layer); 98 99 void 100 tu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer); 101 102 void 103 tu_cs_image_depth_ref(struct tu_cs *cs, const struct tu_image_view *iview, uint32_t layer); 104 105 bool 106 tiling_possible(VkFormat format); 107 108 bool 109 ubwc_possible(struct tu_device *device, 110 VkFormat format, 111 VkImageType type, 112 VkImageUsageFlags usage, 113 VkImageUsageFlags stencil_usage, 114 const struct fd_dev_info *info, 115 VkSampleCountFlagBits samples, 116 bool use_z24uint_s8uint); 117 118 struct tu_frag_area { 119 float width; 120 float height; 121 }; 122 123 void 124 tu_fragment_density_map_sample(const struct tu_image_view *fdm, 125 uint32_t x, uint32_t y, 126 uint32_t width, uint32_t height, 127 uint32_t layers, struct tu_frag_area *areas); 128 129 VkResult 130 tu_image_update_layout(struct tu_device *device, struct tu_image *image, 131 uint64_t modifier, const VkSubresourceLayout *plane_layouts); 132 133 #endif /* TU_IMAGE_H */ 134