summaryrefslogtreecommitdiffstats
path: root/src/freedreno/vulkan
diff options
context:
space:
mode:
authorJonathan Marek <[email protected]>2019-09-25 22:24:13 -0400
committerJonathan Marek <[email protected]>2019-09-26 17:18:13 -0400
commit54c80d080a77d1d69e5ef42d35712b7eccc2bb6f (patch)
tree6c9b30809acd8cf47192323c5c825ba3e8618ec8 /src/freedreno/vulkan
parent5f2fb904a194fd30c97b54b45d85a692de5403f8 (diff)
turnip: implement image view descriptor
Signed-off-by: Jonathan Marek <[email protected]> Reviewed-by: Kristian H. Kristensen <[email protected]> Acked-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/freedreno/vulkan')
-rw-r--r--src/freedreno/vulkan/tu_image.c87
-rw-r--r--src/freedreno/vulkan/tu_private.h5
2 files changed, 90 insertions, 2 deletions
diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c
index 657612d42c3..8bea11b6ff7 100644
--- a/src/freedreno/vulkan/tu_image.c
+++ b/src/freedreno/vulkan/tu_image.c
@@ -181,6 +181,54 @@ tu_image_create(VkDevice _device,
return VK_SUCCESS;
}
+static enum a6xx_tex_fetchsize
+translate_fetchsize(uint32_t cpp)
+{
+ switch (cpp) {
+ case 1: return TFETCH6_1_BYTE;
+ case 2: return TFETCH6_2_BYTE;
+ case 4: return TFETCH6_4_BYTE;
+ case 8: return TFETCH6_8_BYTE;
+ case 16: return TFETCH6_16_BYTE;
+ default:
+ unreachable("bad block size");
+ }
+}
+
+static enum a6xx_tex_swiz
+translate_swiz(VkComponentSwizzle swiz, enum a6xx_tex_swiz ident)
+{
+ switch (swiz) {
+ default:
+ case VK_COMPONENT_SWIZZLE_IDENTITY: return ident;
+ case VK_COMPONENT_SWIZZLE_R: return A6XX_TEX_X;
+ case VK_COMPONENT_SWIZZLE_G: return A6XX_TEX_Y;
+ case VK_COMPONENT_SWIZZLE_B: return A6XX_TEX_Z;
+ case VK_COMPONENT_SWIZZLE_A: return A6XX_TEX_W;
+ case VK_COMPONENT_SWIZZLE_ZERO: return A6XX_TEX_ZERO;
+ case VK_COMPONENT_SWIZZLE_ONE: return A6XX_TEX_ONE;
+ }
+}
+
+static enum a6xx_tex_type
+translate_tex_type(VkImageViewType type)
+{
+ switch (type) {
+ default:
+ case VK_IMAGE_VIEW_TYPE_1D:
+ case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
+ return A6XX_TEX_1D;
+ case VK_IMAGE_VIEW_TYPE_2D:
+ case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
+ return A6XX_TEX_2D;
+ case VK_IMAGE_VIEW_TYPE_3D:
+ return A6XX_TEX_3D;
+ case VK_IMAGE_VIEW_TYPE_CUBE:
+ case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
+ return A6XX_TEX_CUBE;
+ }
+}
+
void
tu_image_view_init(struct tu_image_view *iview,
struct tu_device *device,
@@ -221,6 +269,45 @@ tu_image_view_init(struct tu_image_view *iview,
iview->layer_count = tu_get_layerCount(image, range);
iview->base_mip = range->baseMipLevel;
iview->level_count = tu_get_levelCount(image, range);
+
+ memset(iview->descriptor, 0, sizeof(iview->descriptor));
+
+ const struct tu_native_format *fmt = tu6_get_native_format(iview->vk_format);
+ assert(fmt && fmt->tex >= 0);
+
+ struct tu_image_level *slice0 = &image->levels[iview->base_mip];
+ uint32_t cpp = vk_format_get_blocksize(iview->vk_format);
+ uint32_t block_width = vk_format_get_blockwidth(iview->vk_format);
+ const VkComponentMapping *comps = &pCreateInfo->components;
+
+ iview->descriptor[0] =
+ A6XX_TEX_CONST_0_TILE_MODE(image->tile_mode) |
+ COND(vk_format_is_srgb(iview->vk_format), A6XX_TEX_CONST_0_SRGB) |
+ A6XX_TEX_CONST_0_FMT(fmt->tex) |
+ A6XX_TEX_CONST_0_SAMPLES(0) |
+ A6XX_TEX_CONST_0_SWAP(fmt->swap) |
+ A6XX_TEX_CONST_0_SWIZ_X(translate_swiz(comps->r, A6XX_TEX_X)) |
+ A6XX_TEX_CONST_0_SWIZ_Y(translate_swiz(comps->g, A6XX_TEX_Y)) |
+ A6XX_TEX_CONST_0_SWIZ_Z(translate_swiz(comps->b, A6XX_TEX_Z)) |
+ A6XX_TEX_CONST_0_SWIZ_W(translate_swiz(comps->a, A6XX_TEX_W)) |
+ A6XX_TEX_CONST_0_MIPLVLS(iview->level_count - 1);
+ iview->descriptor[1] =
+ A6XX_TEX_CONST_1_WIDTH(u_minify(image->extent.width, iview->base_mip)) |
+ A6XX_TEX_CONST_1_HEIGHT(u_minify(image->extent.height, iview->base_mip));
+ iview->descriptor[2] =
+ A6XX_TEX_CONST_2_FETCHSIZE(translate_fetchsize(cpp)) |
+ A6XX_TEX_CONST_2_PITCH(slice0->pitch / block_width * cpp) |
+ A6XX_TEX_CONST_2_TYPE(translate_tex_type(pCreateInfo->viewType));
+ if (pCreateInfo->viewType != VK_IMAGE_VIEW_TYPE_3D) {
+ iview->descriptor[3] = A6XX_TEX_CONST_3_ARRAY_PITCH(image->layer_size);
+ } else {
+ iview->descriptor[3] =
+ A6XX_TEX_CONST_3_MIN_LAYERSZ(image->levels[image->level_count - 1].size) |
+ A6XX_TEX_CONST_3_ARRAY_PITCH(slice0->size);
+ }
+ uint64_t base_addr = image->bo->iova + iview->base_layer * image->layer_size + slice0->offset;
+ iview->descriptor[4] = base_addr;
+ iview->descriptor[5] = base_addr >> 32 | A6XX_TEX_CONST_5_DEPTH(iview->layer_count);
}
unsigned
diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h
index 201ac49eda0..050fe5928fc 100644
--- a/src/freedreno/vulkan/tu_private.h
+++ b/src/freedreno/vulkan/tu_private.h
@@ -103,6 +103,7 @@ typedef uint32_t xcb_window_t;
*/
#define TU_BUFFER_OPS_CS_THRESHOLD 4096
+#define A6XX_TEX_CONST_DWORDS 16
#define A6XX_TEX_SAMP_DWORDS 4
enum tu_mem_heap
@@ -1268,12 +1269,12 @@ struct tu_image_view
uint32_t level_count;
VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
- uint32_t descriptor[16];
+ uint32_t descriptor[A6XX_TEX_CONST_DWORDS];
/* Descriptor for use as a storage image as opposed to a sampled image.
* This has a few differences for cube maps (e.g. type).
*/
- uint32_t storage_descriptor[16];
+ uint32_t storage_descriptor[A6XX_TEX_CONST_DWORDS];
};
struct tu_sampler