vk: Consolidate image, buffer and color attachment views
authorKristian Høgsberg <kristian.h.kristensen@intel.com>
Wed, 13 May 2015 22:31:26 +0000 (15:31 -0700)
committerKristian Høgsberg <kristian.h.kristensen@intel.com>
Fri, 15 May 2015 22:22:29 +0000 (15:22 -0700)
These are all just surface state, offset and a bo.

src/vulkan/device.c
src/vulkan/image.c
src/vulkan/meta.c
src/vulkan/private.h
src/vulkan/vk.c

index cf855a87387d7d8bfaf29d9f7f97b4983928ea7e..e1aac64ffb028c6a6786f279f1f494ebe8efceb8 100644 (file)
@@ -1252,7 +1252,8 @@ VkResult VKAPI vkCreateBufferView(
     VkBufferView*                               pView)
 {
    struct anv_device *device = (struct anv_device *) _device;
-   struct anv_buffer_view *view;
+   struct anv_buffer *buffer = (struct anv_buffer *) pCreateInfo->buffer;
+   struct anv_surface_view *view;
    const struct anv_format *format;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO);
@@ -1262,10 +1263,11 @@ VkResult VKAPI vkCreateBufferView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view->buffer = (struct anv_buffer *) pCreateInfo->buffer;
-   view->offset = pCreateInfo->offset;
+   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 = pCreateInfo->format;
 
    format = anv_format_for_vk_format(pCreateInfo->format);
    /* This assumes RGBA float format. */
@@ -1306,7 +1308,7 @@ VkResult VKAPI vkCreateBufferView(
       .ShaderChannelSelectAlpha = SCS_ALPHA,
       .ResourceMinLOD = 0,
       /* FIXME: We assume that the image must be bound at this time. */
-      .SurfaceBaseAddress = { NULL, view->buffer->offset + view->offset },
+      .SurfaceBaseAddress = { NULL, view->offset },
    };
 
    GEN8_RENDER_SURFACE_STATE_pack(NULL, view->surface_state.map, &surface_state);
@@ -1581,8 +1583,8 @@ void VKAPI vkUpdateDescriptors(
          update_sampler_textures = (VkUpdateSamplerTextures *) common;
 
          for (uint32_t j = 0; j < update_sampler_textures->count; j++) {
-            set->descriptors[update_sampler_textures->binding + j].image_view =
-               (struct anv_image_view *)
+            set->descriptors[update_sampler_textures->binding + j].view =
+               (struct anv_surface_view *)
                update_sampler_textures->pSamplerImageViews[j].pImageView->view;
             set->descriptors[update_sampler_textures->binding + j].sampler =
                (struct anv_sampler *)
@@ -1594,8 +1596,8 @@ void VKAPI vkUpdateDescriptors(
          update_images = (VkUpdateImages *) common;
 
          for (uint32_t j = 0; j < update_images->count; j++) {
-            set->descriptors[update_images->binding + j].image_view =
-               (struct anv_image_view *) update_images->pImageViews[j].view;
+            set->descriptors[update_images->binding + j].view =
+               (struct anv_surface_view *) update_images->pImageViews[j].view;
          }
          break;
 
@@ -1603,8 +1605,8 @@ void VKAPI vkUpdateDescriptors(
          update_buffers = (VkUpdateBuffers *) common;
 
          for (uint32_t j = 0; j < update_buffers->count; j++) {
-            set->descriptors[update_buffers->binding + j].buffer_view =
-               (struct anv_buffer_view *) update_buffers->pBufferViews[j].view;
+            set->descriptors[update_buffers->binding + j].view =
+               (struct anv_surface_view *) update_buffers->pBufferViews[j].view;
          }
          /* FIXME: descriptor arrays? */
          break;
@@ -2185,24 +2187,21 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
 
       if (s == VK_SHADER_STAGE_FRAGMENT) {
          for (uint32_t i = 0; i < framebuffer->color_attachment_count; i++) {
-            struct anv_color_attachment_view *view = framebuffer->color_attachments[i];
+            struct anv_surface_view *view = framebuffer->color_attachments[i];
             table[i] = view->surface_state.offset;
 
             /* Don't write the reloc back to the surface state. We do that at
              * submit time. Surface address is dwords 8-9. */
             anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
                                view->surface_state.offset + 8 * sizeof(int32_t),
-                               view->image->bo, view->image->offset);
+                               view->bo, view->offset);
          }
       }
 
       if (layout) {
          for (uint32_t i = 0; i < layout->stage[s].surface_count; i++) {
             struct anv_pipeline_layout_entry *e = &layout->stage[s].surface_entries[i];
-            struct anv_descriptor *d =
-               &cmd_buffer->descriptor_sets[e->set]->descriptors[e->index];
-            struct anv_image_view *image_view;
-            struct anv_buffer_view *buffer_view;
+            struct anv_surface_view *view;
 
             switch (e->type) {
             case VK_DESCRIPTOR_TYPE_SAMPLER:
@@ -2211,26 +2210,15 @@ flush_descriptor_sets(struct anv_cmd_buffer *cmd_buffer)
             case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
             case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
             case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
-               image_view = d->image_view;
-               table[bias + i] = image_view->surface_state.offset;
-               anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
-                                  image_view->surface_state.offset + 8 * sizeof(int32_t),
-                                  image_view->image->bo,
-                                  image_view->image->offset);
-               break;
             case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
             case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
-               /* FIXME: What are these? TBOs? */
-               break;
-
             case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
             case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
-               buffer_view = d->buffer_view;
-               table[bias + i] = buffer_view->surface_state.offset;
+               view = cmd_buffer->descriptor_sets[e->set]->descriptors[e->index].view;
+               table[bias + i] = view->surface_state.offset;
                anv_reloc_list_add(&cmd_buffer->batch.surf_relocs,
-                                  buffer_view->surface_state.offset + 8 * sizeof(int32_t),
-                                  buffer_view->buffer->bo,
-                                  buffer_view->buffer->offset + buffer_view->offset);
+                                  view->surface_state.offset + 8 * sizeof(int32_t),
+                                  view->bo, view->offset);
                break;
 
             case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
@@ -2673,7 +2661,7 @@ VkResult VKAPI vkCreateFramebuffer(
    framebuffer->color_attachment_count = pCreateInfo->colorAttachmentCount;
    for (uint32_t i = 0; i < pCreateInfo->colorAttachmentCount; i++) {
       framebuffer->color_attachments[i] =
-         (struct anv_color_attachment_view *) pCreateInfo->pColorAttachments[i].view;
+         (struct anv_surface_view *) pCreateInfo->pColorAttachments[i].view;
    }
 
    if (pCreateInfo->pDepthStencilAttachment) {
index c1504211cadaed5d7a27c8259b4b097ef1b48555..aae9fbf0e8c89f164fafc372e123968ddcfbc313 100644 (file)
@@ -348,7 +348,8 @@ VkResult VKAPI vkCreateImageView(
     VkImageView*                                pView)
 {
    struct anv_device *device = (struct anv_device *) _device;
-   struct anv_image_view *view;
+   struct anv_surface_view *view;
+   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
    const struct anv_format *format =
       anv_format_for_vk_format(pCreateInfo->format);
 
@@ -359,12 +360,13 @@ VkResult VKAPI vkCreateImageView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view->image = (struct anv_image *) pCreateInfo->image;
-
-   view->surface_state = create_surface_state(device, view->image, format);
+   view->bo = image->bo;
+   view->offset = image->offset;
+   view->surface_state = create_surface_state(device, image, format);
+   view->format = pCreateInfo->format;
 
    /* TODO: Miplevels */
-   view->extent = view->image->extent;
+   view->extent = image->extent;
 
    *pView = (VkImageView) view;
 
@@ -377,7 +379,8 @@ VkResult VKAPI vkCreateColorAttachmentView(
     VkColorAttachmentView*                      pView)
 {
    struct anv_device *device = (struct anv_device *) _device;
-   struct anv_color_attachment_view *view;
+   struct anv_surface_view *view;
+   struct anv_image *image = (struct anv_image *) pCreateInfo->image;
    const struct anv_format *format =
       anv_format_for_vk_format(pCreateInfo->format);
 
@@ -388,12 +391,11 @@ VkResult VKAPI vkCreateColorAttachmentView(
    if (view == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   view->image = (struct anv_image *) pCreateInfo->image;
-
-   view->surface_state = create_surface_state(device, view->image, format);
-
-   /* TODO: Miplevels */
-   view->extent = view->image->extent;
+   view->bo = image->bo;
+   view->offset = image->offset;
+   view->surface_state = create_surface_state(device, image, format);
+   view->extent = image->extent;
+   view->format = pCreateInfo->format;
 
    *pView = (VkColorAttachmentView) view;
 
index d39cba4ea42b722e1a280ba41d3046deea9c0473..4f210e3f2355b851da8f5af8b2dbb9cea26dea2b 100644 (file)
@@ -468,10 +468,10 @@ struct blit_region {
 
 static void
 meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
-               struct anv_image_view *src,
+               struct anv_surface_view *src,
                VkOffset3D src_offset,
                VkExtent3D src_extent,
-               struct anv_color_attachment_view *dest,
+               struct anv_surface_view *dest,
                VkOffset3D dest_offset,
                VkExtent3D dest_extent)
 {
@@ -587,7 +587,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer,
       .extent = { },
       .sampleCount = 1,
       .layers = 1,
-      .pColorFormats = (VkFormat[]) { dest->image->format },
+      .pColorFormats = (VkFormat[]) { dest->format },
       .pColorLayouts = (VkImageLayout[]) { VK_IMAGE_LAYOUT_GENERAL },
       .pColorLoadOps = (VkAttachmentLoadOp[]) { VK_ATTACHMENT_LOAD_OP_LOAD },
       .pColorStoreOps = (VkAttachmentStoreOp[]) { VK_ATTACHMENT_STORE_OP_STORE },
@@ -750,10 +750,10 @@ void VKAPI vkCmdCopyImageToBuffer(
       vkCreateColorAttachmentView(vk_device, &dest_view_info, &dest_view);
 
       meta_emit_blit(cmd_buffer,
-                     (struct anv_image_view *)src_view,
+                     (struct anv_surface_view *)src_view,
                      pRegions[r].imageOffset,
                      pRegions[r].imageExtent,
-                     (struct anv_color_attachment_view *)dest_view,
+                     (struct anv_surface_view *)dest_view,
                      (VkOffset3D) { 0, 0, 0 },
                      pRegions[r].imageExtent);
    }
index 34b4ce8d14a5d55838ff3c65ab3fd1169c364d41..62f77cd96d9ae91d02d227fdf1b132d64555d839 100644 (file)
@@ -463,13 +463,8 @@ struct anv_descriptor_set_layout {
 };
 
 struct anv_descriptor {
-   union {
-      struct {
-         struct anv_sampler *sampler;
-         struct anv_image_view *image_view;
-      };
-      struct anv_buffer_view *buffer_view;
-   };
+   struct anv_sampler *sampler;
+   struct anv_surface_view *view;
 };
 
 struct anv_descriptor_set {
@@ -630,24 +625,12 @@ struct anv_image {
    VkDeviceSize                                 offset;
 };
 
-struct anv_buffer_view {
-   struct anv_buffer *                          buffer;
+struct anv_surface_view {
    struct anv_state                             surface_state;
+   struct anv_bo *                              bo;
    uint32_t                                     offset;
-};
-
-struct anv_color_attachment_view {
-   struct anv_image *                           image;
-   struct anv_state                             surface_state;
-
-   VkExtent3D                                   extent;
-};
-
-struct anv_image_view {
-   struct anv_image *                           image;
-   struct anv_state                             surface_state;
-
    VkExtent3D                                   extent;
+   VkFormat                                     format;
 };
 
 struct anv_sampler {
@@ -659,7 +642,7 @@ struct anv_depth_stencil_view {
 
 struct anv_framebuffer {
    uint32_t                                     color_attachment_count;
-   struct anv_color_attachment_view *           color_attachments[MAX_RTS];
+   struct anv_surface_view *                    color_attachments[MAX_RTS];
    struct anv_depth_stencil_view *              depth_stencil;
 
    uint32_t                                     sample_count;
index 484f61601c36e7dfda19fe4bf3aa0f477b1a7f11..399a1c2db1d2bccb2f47d20296b0f2bc150b28cd 100644 (file)
@@ -562,6 +562,11 @@ int main(int argc, char *argv[])
                  },
                  &texture);
 
+   vkQueueBindObjectMemory(queue, VK_OBJECT_TYPE_IMAGE,
+                           texture,
+                           0, /* allocation index; for objects which need to bind to multiple mems */
+                           mem, 2048 + 256 * 256 * 4);
+
    VkImageView image_view;
    vkCreateImageView(device,
                      &(VkImageViewCreateInfo) {
@@ -586,11 +591,6 @@ int main(int argc, char *argv[])
                       },
                       &image_view);
 
-   vkQueueBindObjectMemory(queue, VK_OBJECT_TYPE_IMAGE,
-                           texture,
-                           0, /* allocation index; for objects which need to bind to multiple mems */
-                           mem, 2048 + 256 * 256 * 4);
-
    VkSampler sampler;
    vkCreateSampler(device,
                    &(VkSamplerCreateInfo) {