turnip: Add support for uniform texel buffers.
authorEric Anholt <eric@anholt.net>
Wed, 22 Jan 2020 20:25:10 +0000 (12:25 -0800)
committerMarge Bot <eric+marge@anholt.net>
Thu, 23 Jan 2020 02:40:09 +0000 (02:40 +0000)
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 <jonathan@marek.ca>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3522>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3522>

src/freedreno/vulkan/tu_descriptor_set.c
src/freedreno/vulkan/tu_device.c
src/freedreno/vulkan/tu_image.c
src/freedreno/vulkan/tu_private.h

index 713a246c9a995f1d73c1b7486acd2e6c69b0e39b..deae984d1da0f229ace93cdf2872d8bd3d0db5ef 100644 (file)
@@ -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,
index ba8796be7aa271f5910c7a99bf1f6adcdb61bff7..95fdccb69fe0d24d8f7361eaa484e811763ebd58 100644 (file)
@@ -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,
index f596feb9855408f57a70201b10b051830fddba1e..08028e520638f4aa7f29f03f438fc3d6f688b35d 100644 (file)
@@ -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
index 4169d015ce1471e82b07f1b925c79bde5aeba30c..79de5dc82de0df2626cd4190a2e8a9ba1b25ae29 100644 (file)
@@ -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,