vk: Move anv_CreateBufferView to anv_gen8.c
authorKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Fri, 14 Aug 2015 04:48:19 +0000 (21:48 -0700)
committerKristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
Mon, 24 Aug 2015 20:45:40 +0000 (13:45 -0700)
Signed-off-by: Kristian Høgsberg Kristensen <kristian.h.kristensen@intel.com>
src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_device.c
src/vulkan/anv_gen8.c
src/vulkan/anv_private.h

index 5178f6529abef6c1f751d050759978320349b527..e0e850b8cc455064485a154f0c620687506998a9 100644 (file)
@@ -518,8 +518,8 @@ cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
                d->dynamic_offsets[surface_slots[b].dynamic_slot];
 
             offset = view->offset + dynamic_offset;
-            anv_fill_buffer_surface_state(state.map, view->format, offset,
-                                          view->range - dynamic_offset);
+            gen8_fill_buffer_surface_state(state.map, view->format, offset,
+                                           view->range - dynamic_offset);
          } else {
             offset = view->offset;
             memcpy(state.map, view->surface_state.map, 64);
index ba0966aa3b2d98924083e7d7095d5d27daa74992..78c35dd83fe7c899c66f878d069d62affc83c9ba 100644 (file)
@@ -1324,90 +1324,44 @@ VkResult anv_DestroyBuffer(
    return VK_SUCCESS;
 }
 
-// Buffer view functions
-
-void
-anv_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                              uint32_t offset, uint32_t range)
-{
-   /* This assumes RGBA float format. */
-   uint32_t stride = 4;
-   uint32_t num_elements = range / stride;
-
-   struct GEN8_RENDER_SURFACE_STATE surface_state = {
-      .SurfaceType = SURFTYPE_BUFFER,
-      .SurfaceArray = false,
-      .SurfaceFormat = format->surface_format,
-      .SurfaceVerticalAlignment = VALIGN4,
-      .SurfaceHorizontalAlignment = HALIGN4,
-      .TileMode = LINEAR,
-      .VerticalLineStride = 0,
-      .VerticalLineStrideOffset = 0,
-      .SamplerL2BypassModeDisable = true,
-      .RenderCacheReadWriteMode = WriteOnlyCache,
-      .MemoryObjectControlState = GEN8_MOCS,
-      .BaseMipLevel = 0.0,
-      .SurfaceQPitch = 0,
-      .Height = (num_elements >> 7) & 0x3fff,
-      .Width = num_elements & 0x7f,
-      .Depth = (num_elements >> 21) & 0x3f,
-      .SurfacePitch = stride - 1,
-      .MinimumArrayElement = 0,
-      .NumberofMultisamples = MULTISAMPLECOUNT_1,
-      .XOffset = 0,
-      .YOffset = 0,
-      .SurfaceMinLOD = 0,
-      .MIPCountLOD = 0,
-      .AuxiliarySurfaceMode = AUX_NONE,
-      .RedClearColor = 0,
-      .GreenClearColor = 0,
-      .BlueClearColor = 0,
-      .AlphaClearColor = 0,
-      .ShaderChannelSelectRed = SCS_RED,
-      .ShaderChannelSelectGreen = SCS_GREEN,
-      .ShaderChannelSelectBlue = SCS_BLUE,
-      .ShaderChannelSelectAlpha = SCS_ALPHA,
-      .ResourceMinLOD = 0.0,
-      /* FIXME: We assume that the image must be bound at this time. */
-      .SurfaceBaseAddress = { NULL, offset },
-   };
-
-   GEN8_RENDER_SURFACE_STATE_pack(NULL, state, &surface_state);
-}
-
-VkResult anv_CreateBufferView(
-    VkDevice                                    _device,
-    const VkBufferViewCreateInfo*               pCreateInfo,
-    VkBufferView*                               pView)
+VkResult
+anv_buffer_view_create(
+   struct anv_device *                          device,
+   const VkBufferViewCreateInfo*                pCreateInfo,
+   struct anv_buffer_view **                    view_out)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
    ANV_FROM_HANDLE(anv_buffer, buffer, pCreateInfo->buffer);
-   struct anv_buffer_view *bview;
-   struct anv_surface_view *view;
+   struct anv_buffer_view *view;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
 
-   bview = anv_device_alloc(device, sizeof(*view), 8,
-                            VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
-   if (bview == NULL)
+   view = anv_device_alloc(device, sizeof(*view), 8,
+                           VK_SYSTEM_ALLOC_TYPE_API_OBJECT);
+   if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view = &bview->view;
-   view->bo = buffer->bo;
-   view->offset = buffer->offset + pCreateInfo->offset;
-   view->surface_state =
-      anv_state_pool_alloc(&device->surface_state_pool, 64, 64);
-   view->format = anv_format_for_vk_format(pCreateInfo->format);
-   view->range = pCreateInfo->range;
-
-   anv_fill_buffer_surface_state(view->surface_state.map, view->format,
-                                 view->offset, pCreateInfo->range);
+   view->view = (struct anv_surface_view) {
+      .bo = buffer->bo,
+      .offset = buffer->offset + pCreateInfo->offset,
+      .surface_state = anv_state_pool_alloc(&device->surface_state_pool, 64, 64),
+      .format = anv_format_for_vk_format(pCreateInfo->format),
+      .range = pCreateInfo->range,
+   };
 
-   *pView = anv_buffer_view_to_handle(bview);
+   *view_out = view;
 
    return VK_SUCCESS;
 }
 
+
+VkResult anv_CreateBufferView(
+    VkDevice                                    _device,
+    const VkBufferViewCreateInfo*               pCreateInfo,
+    VkBufferView*                               pView)
+{
+   return driver_layer->CreateBufferView(_device, pCreateInfo, pView);
+}
+
 VkResult anv_DestroyBufferView(
     VkDevice                                    _device,
     VkBufferView                                _bview)
index 8d53ebb32f50c8b76155ccf05c945eacb12a44fd..16f2da1800636549d1f0ed4bce7dc7efd9e7258c 100644 (file)
@@ -68,3 +68,77 @@ VkResult gen8_CreateDynamicRasterState(
 
    return VK_SUCCESS;
 }
+
+void
+gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
+                               uint32_t offset, uint32_t range)
+{
+   /* This assumes RGBA float format. */
+   uint32_t stride = 4;
+   uint32_t num_elements = range / stride;
+
+   struct GEN8_RENDER_SURFACE_STATE surface_state = {
+      .SurfaceType = SURFTYPE_BUFFER,
+      .SurfaceArray = false,
+      .SurfaceFormat = format->surface_format,
+      .SurfaceVerticalAlignment = VALIGN4,
+      .SurfaceHorizontalAlignment = HALIGN4,
+      .TileMode = LINEAR,
+      .VerticalLineStride = 0,
+      .VerticalLineStrideOffset = 0,
+      .SamplerL2BypassModeDisable = true,
+      .RenderCacheReadWriteMode = WriteOnlyCache,
+      .MemoryObjectControlState = GEN8_MOCS,
+      .BaseMipLevel = 0.0,
+      .SurfaceQPitch = 0,
+      .Height = (num_elements >> 7) & 0x3fff,
+      .Width = num_elements & 0x7f,
+      .Depth = (num_elements >> 21) & 0x3f,
+      .SurfacePitch = stride - 1,
+      .MinimumArrayElement = 0,
+      .NumberofMultisamples = MULTISAMPLECOUNT_1,
+      .XOffset = 0,
+      .YOffset = 0,
+      .SurfaceMinLOD = 0,
+      .MIPCountLOD = 0,
+      .AuxiliarySurfaceMode = AUX_NONE,
+      .RedClearColor = 0,
+      .GreenClearColor = 0,
+      .BlueClearColor = 0,
+      .AlphaClearColor = 0,
+      .ShaderChannelSelectRed = SCS_RED,
+      .ShaderChannelSelectGreen = SCS_GREEN,
+      .ShaderChannelSelectBlue = SCS_BLUE,
+      .ShaderChannelSelectAlpha = SCS_ALPHA,
+      .ResourceMinLOD = 0.0,
+      /* FIXME: We assume that the image must be bound at this time. */
+      .SurfaceBaseAddress = { NULL, offset },
+   };
+
+   GEN8_RENDER_SURFACE_STATE_pack(NULL, state, &surface_state);
+}
+
+VkResult gen8_CreateBufferView(
+    VkDevice                                    _device,
+    const VkBufferViewCreateInfo*               pCreateInfo,
+    VkBufferView*                               pView)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   struct anv_buffer_view *view;
+   VkResult result;
+
+   result = anv_buffer_view_create(device, pCreateInfo, &view);
+   if (result != VK_SUCCESS)
+      return result;
+
+   const struct anv_format *format = 
+      anv_format_for_vk_format(pCreateInfo->format);
+
+   gen8_fill_buffer_surface_state(view->view.surface_state.map, format,
+                                  view->view.offset, pCreateInfo->range);
+
+   *pView = anv_buffer_view_to_handle(view);
+
+   return VK_SUCCESS;
+}
+
index 1de97fda83a37449ac7ec9170311d87b64a3f205..518a3ccdd257eae690e0e612ee9d3d155d2a320e 100644 (file)
@@ -1021,8 +1021,13 @@ void anv_color_attachment_view_init(struct anv_color_attachment_view *view,
                                     struct anv_device *device,
                                     const VkAttachmentViewCreateInfo* pCreateInfo,
                                     struct anv_cmd_buffer *cmd_buffer);
-void anv_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                                   uint32_t offset, uint32_t range);
+
+VkResult anv_buffer_view_create(struct anv_device *device,
+                                const VkBufferViewCreateInfo *pCreateInfo,
+                                struct anv_buffer_view **view_out);
+
+void gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
+                                    uint32_t offset, uint32_t range);
 
 void anv_surface_view_fini(struct anv_device *device,
                            struct anv_surface_view *view);