From 65e432695d9eadca8ac8be928bf5d434e1d9e912 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 22 Jan 2020 12:25:10 -0800 Subject: [PATCH] turnip: Add support for uniform texel buffers. Pretty straightforward: Port texture descriptor code from freedreno, fill in alignment limits from closed vk, and tu_cmd_buffer.c was already uploading the texture descriptor. This doesn't implement storage texel buffers (required in the compute pipeline) yet, since those will need an IBO descriptor for the store path. Still, making the load path be connected to the texture descriptor won't hurt. Part of #2237 Fixes dEQP-VK.binding_model.shader_access.primary_cmd_buf.uniform_texel_buffer.* Reviewed-by: Jonathan Marek Tested-by: Marge Bot Part-of: --- src/freedreno/vulkan/tu_descriptor_set.c | 15 +++++--- src/freedreno/vulkan/tu_device.c | 2 +- src/freedreno/vulkan/tu_image.c | 44 +++++++++++++++++++++--- src/freedreno/vulkan/tu_private.h | 6 ++-- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/freedreno/vulkan/tu_descriptor_set.c b/src/freedreno/vulkan/tu_descriptor_set.c index 713a246c9a9..deae984d1da 100644 --- a/src/freedreno/vulkan/tu_descriptor_set.c +++ b/src/freedreno/vulkan/tu_descriptor_set.c @@ -85,12 +85,12 @@ descriptor_size(enum VkDescriptorType type) return 0; case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: - case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: /* 64bit pointer */ return 8; case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: return A6XX_TEX_CONST_DWORDS * 4; case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: /* We may need the IBO or the TEX representation, or both. */ @@ -696,9 +696,16 @@ static void write_texel_buffer_descriptor(struct tu_device *device, struct tu_cmd_buffer *cmd_buffer, unsigned *dst, struct tu_bo **buffer_list, - const VkBufferView _buffer_view) + const VkBufferView buffer_view) { - tu_finishme("texel buffer descriptor"); + TU_FROM_HANDLE(tu_buffer_view, view, buffer_view); + + memcpy(dst, view->descriptor, sizeof(view->descriptor)); + + if (cmd_buffer) + tu_bo_list_add(&cmd_buffer->bo_list, view->buffer->bo, MSM_SUBMIT_BO_READ); + else + *buffer_list = view->buffer->bo; } static void write_buffer_descriptor(struct tu_device *device, diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c index ba8796be7aa..95fdccb69fe 100644 --- a/src/freedreno/vulkan/tu_device.c +++ b/src/freedreno/vulkan/tu_device.c @@ -786,7 +786,7 @@ tu_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, .viewportBoundsRange = { INT16_MIN, INT16_MAX }, .viewportSubPixelBits = 8, .minMemoryMapAlignment = 4096, /* A page */ - .minTexelBufferOffsetAlignment = 1, + .minTexelBufferOffsetAlignment = 64, .minUniformBufferOffsetAlignment = 4, .minStorageBufferOffsetAlignment = 4, .minTexelOffset = -32, diff --git a/src/freedreno/vulkan/tu_image.c b/src/freedreno/vulkan/tu_image.c index f596feb9855..08028e52063 100644 --- a/src/freedreno/vulkan/tu_image.c +++ b/src/freedreno/vulkan/tu_image.c @@ -29,6 +29,7 @@ #include "util/debug.h" #include "util/u_atomic.h" +#include "util/format/u_format.h" #include "vk_format.h" #include "vk_util.h" #include "drm-uapi/drm_fourcc.h" @@ -484,10 +485,45 @@ tu_buffer_view_init(struct tu_buffer_view *view, { TU_FROM_HANDLE(tu_buffer, buffer, pCreateInfo->buffer); - view->range = pCreateInfo->range == VK_WHOLE_SIZE - ? buffer->size - pCreateInfo->offset - : pCreateInfo->range; - view->vk_format = pCreateInfo->format; + view->buffer = buffer; + + enum VkFormat vfmt = pCreateInfo->format; + enum pipe_format pfmt = vk_format_to_pipe_format(vfmt); + const struct tu_native_format *fmt = tu6_get_native_format(vfmt); + + uint32_t range; + if (pCreateInfo->range == VK_WHOLE_SIZE) + range = buffer->size - pCreateInfo->offset; + else + range = pCreateInfo->range; + uint32_t elements = range / util_format_get_blocksize(pfmt); + + static const VkComponentMapping components = { + .r = VK_COMPONENT_SWIZZLE_R, + .g = VK_COMPONENT_SWIZZLE_G, + .b = VK_COMPONENT_SWIZZLE_B, + .a = VK_COMPONENT_SWIZZLE_A, + }; + + uint64_t iova = tu_buffer_iova(buffer) + pCreateInfo->offset; + + memset(&view->descriptor, 0, sizeof(view->descriptor)); + + view->descriptor[0] = + A6XX_TEX_CONST_0_TILE_MODE(TILE6_LINEAR) | + A6XX_TEX_CONST_0_SWAP(fmt->swap) | + A6XX_TEX_CONST_0_FMT(fmt->tex) | + A6XX_TEX_CONST_0_MIPLVLS(0) | + tu6_texswiz(&components, vfmt, VK_IMAGE_ASPECT_COLOR_BIT); + COND(vk_format_is_srgb(vfmt), A6XX_TEX_CONST_0_SRGB); + view->descriptor[1] = + A6XX_TEX_CONST_1_WIDTH(elements & MASK(15)) | + A6XX_TEX_CONST_1_HEIGHT(elements >> 15); + view->descriptor[2] = + A6XX_TEX_CONST_2_UNK4 | + A6XX_TEX_CONST_2_UNK31; + view->descriptor[4] = iova; + view->descriptor[5] = iova >> 32; } VkResult diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index 4169d015ce1..79de5dc82de 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -1413,9 +1413,9 @@ tu_image_view_init(struct tu_image_view *view, struct tu_buffer_view { - VkFormat vk_format; - uint64_t range; /**< VkBufferViewCreateInfo::range */ - uint32_t state[4]; + uint32_t descriptor[A6XX_TEX_CONST_DWORDS]; + + struct tu_buffer *buffer; }; void tu_buffer_view_init(struct tu_buffer_view *view, -- 2.30.2