anv/cmd_buffer: Rework the way we emit UBO surface state
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 6 Nov 2015 23:14:10 +0000 (15:14 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 6 Nov 2015 23:14:12 +0000 (15:14 -0800)
The new mechanism should be able to handle SSBOs as well as properly handle
emitting surface state on gen7 where we need different strides depending on
shader stage.

src/vulkan/anv_cmd_buffer.c
src/vulkan/anv_device.c
src/vulkan/anv_private.h
src/vulkan/gen7_state.c
src/vulkan/gen8_state.c

index 77471941071fc0e7b45b3a28e7cbc8b6f1d4eb55..6763278c5ef02353cb591af8963439798a16397b 100644 (file)
@@ -548,6 +548,41 @@ add_surface_state_reloc(struct anv_cmd_buffer *cmd_buffer,
                       state.offset + dword * 4, bo, offset);
 }
 
+static void
+fill_descriptor_buffer_surface_state(struct anv_device *device, void *state,
+                                     VkShaderStage stage, VkDescriptorType type,
+                                     uint32_t offset, uint32_t range)
+{
+   VkFormat format;
+   uint32_t stride;
+
+   switch (type) {
+   case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+   case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+      if (anv_is_scalar_shader_stage(device->instance->physicalDevice.compiler,
+                                     stage)) {
+         stride = 4;
+      } else {
+         stride = 16;
+      }
+      format = VK_FORMAT_R32G32B32A32_SFLOAT;
+      break;
+
+   case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+   case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+      stride = 1;
+      format = VK_FORMAT_UNDEFINED;
+      break;
+
+   default:
+      unreachable("Invalid descriptor type");
+   }
+
+   anv_fill_buffer_surface_state(device, state,
+                                 anv_format_for_vk_format(format),
+                                 offset, range, stride);
+}
+
 VkResult
 anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
                                   VkShaderStage stage, struct anv_state *bt_state)
@@ -623,9 +658,11 @@ anv_cmd_buffer_emit_binding_table(struct anv_cmd_buffer *cmd_buffer,
 
          surface_state =
             anv_cmd_buffer_alloc_surface_state(cmd_buffer);
-         anv_fill_buffer_surface_state(cmd_buffer->device, surface_state.map,
-                                       anv_format_for_vk_format(VK_FORMAT_R32G32B32A32_SFLOAT),
-                                       bo_offset, desc->range);
+
+         fill_descriptor_buffer_surface_state(cmd_buffer->device,
+                                              surface_state.map,
+                                              stage, desc->type,
+                                              bo_offset, desc->range);
          break;
       }
 
index dcb3ef20115f7c8a2b1a400dbdd2b401909ef9d1..a4b58caab1374ec1fe13aa42d74e2e91f3848099 100644 (file)
@@ -1415,14 +1415,14 @@ void anv_DestroyBuffer(
 void
 anv_fill_buffer_surface_state(struct anv_device *device, void *state,
                               const struct anv_format *format,
-                              uint32_t offset, uint32_t range)
+                              uint32_t offset, uint32_t range, uint32_t stride)
 {
    switch (device->info.gen) {
    case 7:
-      gen7_fill_buffer_surface_state(state, format, offset, range);
+      gen7_fill_buffer_surface_state(state, format, offset, range, stride);
       break;
    case 8:
-      gen8_fill_buffer_surface_state(state, format, offset, range);
+      gen8_fill_buffer_surface_state(state, format, offset, range, stride);
       break;
    default:
       unreachable("unsupported gen\n");
index 631b92cf26716e6f9ef8fade9ead2e1ae09f3ff0..500904713a6fef704e39f78b1c6e05d2894959e9 100644 (file)
@@ -1361,12 +1361,15 @@ gen8_image_view_init(struct anv_image_view *iview,
 
 void anv_fill_buffer_surface_state(struct anv_device *device, void *state,
                                    const struct anv_format *format,
-                                   uint32_t offset, uint32_t range);
+                                   uint32_t offset, uint32_t range,
+                                   uint32_t stride);
 
 void gen7_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                                    uint32_t offset, uint32_t range);
+                                    uint32_t offset, uint32_t range,
+                                    uint32_t stride);
 void gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                                    uint32_t offset, uint32_t range);
+                                    uint32_t offset, uint32_t range,
+                                    uint32_t stride);
 
 struct anv_sampler {
    uint32_t state[4];
index 0d67be4a99b2764e66fd28559d6448aec029b481..6f1cb8553e99fb247c182a1408e41ba083a9c2ba 100644 (file)
 
 void
 gen7_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                               uint32_t offset, uint32_t range)
+                               uint32_t offset, uint32_t range, uint32_t stride)
 {
-   /* This assumes RGBA float format. */
-
-   uint32_t stride = 16; /* Depends on whether accessing shader is simd8 or
-                          * vec4.  Will need one of each for buffers that are
-                          * used in both vec4 and simd8. */
-
    uint32_t num_elements = range / stride;
 
    struct GEN7_RENDER_SURFACE_STATE surface_state = {
index 61aede99ad41e2459f1861eb0971187e4ec14a87..ce69377fd77d07ecce2ce5d74c0d8dc90975357d 100644 (file)
 
 void
 gen8_fill_buffer_surface_state(void *state, const struct anv_format *format,
-                               uint32_t offset, uint32_t range)
+                               uint32_t offset, uint32_t range, uint32_t stride)
 {
-   /* This assumes RGBA float format. */
-   uint32_t stride = 4;
    uint32_t num_elements = range / stride;
 
    struct GEN8_RENDER_SURFACE_STATE surface_state = {