anv: Add initial support for texel buffers
authorJason Ekstrand <jason.ekstrand@intel.com>
Sun, 13 Dec 2015 00:11:23 +0000 (16:11 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sun, 13 Dec 2015 00:11:23 +0000 (16:11 -0800)
src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_descriptor_set.c
src/vulkan/anv_device.c
src/vulkan/anv_image.c
src/vulkan/anv_private.h

index 8ade08ea746006e74075fe5cd22d43605b99d770..0531cd80f4f923a145f41da027f02a79b4b29302 100644 (file)
@@ -730,6 +730,11 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
       }
 
       case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+         surface_state = desc->buffer_view->surface_state;
+         bo = desc->buffer_view->buffer->bo;
+         bo_offset = desc->buffer_view->buffer->offset;
+         break;
+
       case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
          assert(!"Unsupported descriptor type");
          break;
index 9c4210025e3d1b5487e958f1f05a5a2584f87c6a..52d2ffecdd6755106955b8b974d18bb4c7a77083 100644 (file)
@@ -483,7 +483,15 @@ void anv_UpdateDescriptorSets(
 
       case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
       case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-         anv_finishme("texel buffers not implemented");
+         for (uint32_t j = 0; j < write->descriptorCount; j++) {
+            ANV_FROM_HANDLE(anv_buffer_view, bview,
+                            write->pTexelBufferView[j]);
+
+            desc[j] = (struct anv_descriptor) {
+               .type = write->descriptorType,
+               .buffer_view = bview,
+            };
+         }
          break;
 
       case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
index 7556d8353d5e66c7fc7375d3b5473562ba13652f..7ddad58cf6f580e95321e5c84df14b7d86b629a7 100644 (file)
@@ -1514,23 +1514,6 @@ anv_fill_buffer_surface_state(struct anv_device *device, void *state,
    }
 }
 
-VkResult anv_CreateBufferView(
-    VkDevice                                    _device,
-    const VkBufferViewCreateInfo*               pCreateInfo,
-    const VkAllocationCallbacks*                pAllocator,
-    VkBufferView*                               pView)
-{
-   stub_return(VK_ERROR_INCOMPATIBLE_DRIVER);
-}
-
-void anv_DestroyBufferView(
-    VkDevice                                    _device,
-    VkBufferView                                _bview,
-    const VkAllocationCallbacks*                pAllocator)
-{
-   stub();
-}
-
 void anv_DestroySampler(
     VkDevice                                    _device,
     VkSampler                                   _sampler,
index dc52e6b368c98cb5870606c229aa496dabdc3d3f..ffc7ae8cae6ac3c3563b558265467a37cc9acb81 100644 (file)
@@ -506,6 +506,50 @@ anv_DestroyImageView(VkDevice _device, VkImageView _iview,
    anv_free2(&device->alloc, pAllocator, iview);
 }
 
+VkResult
+anv_CreateBufferView(VkDevice _device,
+                     const VkBufferViewCreateInfo *pCreateInfo,
+                     const VkAllocationCallbacks *pAllocator,
+                     VkBufferView *pView)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
+   struct anv_buffer_view *view;
+
+   /* TODO: Storage texel buffers */
+
+   view = anv_alloc2(&device->alloc, pAllocator, sizeof(*view), 8,
+                     VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   if (!view)
+      return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   view->buffer = buffer;
+   view->surface_state =
+      anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
+
+   const struct anv_format *format =
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   anv_fill_buffer_surface_state(device, view->surface_state.map, format,
+                                 pCreateInfo->offset, pCreateInfo->range,
+                                 format->isl_layout->bpb / 8);
+
+   *pView = anv_buffer_view_to_handle(view);
+
+   return VK_SUCCESS;
+}
+
+void
+anv_DestroyBufferView(VkDevice _device, VkBufferView bufferView,
+                      const VkAllocationCallbacks *pAllocator)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_buffer_view, view, bufferView);
+
+   anv_state_pool_free(&device->surface_state_pool, view->surface_state);
+   anv_free2(&device->alloc, pAllocator, view);
+}
+
 struct anv_surface *
 anv_image_get_surface_for_aspect_mask(struct anv_image *image, VkImageAspectFlags aspect_mask)
 {
index a180b9c69c3b58dc4823b03150dea1fc2011ac92..3b5a4be835593e5302be7e2911bb5e62d3fd7f61 100644 (file)
@@ -851,6 +851,8 @@ struct anv_descriptor {
          struct anv_sampler *sampler;
       };
 
+      struct anv_buffer_view *buffer_view;
+
       struct {
          struct anv_buffer *buffer;
          uint64_t offset;
@@ -1516,6 +1518,11 @@ gen9_image_view_init(struct anv_image_view *iview,
                      const VkImageViewCreateInfo* pCreateInfo,
                      struct anv_cmd_buffer *cmd_buffer);
 
+struct anv_buffer_view {
+   struct anv_buffer *buffer;
+   struct anv_state surface_state;
+};
+
 void anv_fill_buffer_surface_state(struct anv_device *device, void *state,
                                    const struct anv_format *format,
                                    uint32_t offset, uint32_t range,
@@ -1636,6 +1643,7 @@ ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
 
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
+ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)