ilo: clean up SURFACE_STATE and BINDING_TABLE_STATE
authorChia-I Wu <olvaffe@gmail.com>
Thu, 5 Mar 2015 20:27:16 +0000 (04:27 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Thu, 5 Mar 2015 20:43:20 +0000 (04:43 +0800)
Add ilo_builder_surface_pointer() to replace ilo_builder_surface_write().
Make Gen8+ take a different path in gen6_SURFACE_STATE().

src/gallium/drivers/ilo/ilo_builder.h
src/gallium/drivers/ilo/ilo_builder_3d_top.h

index c902a8f3cf281caa2c4f637ca9a57ed1c45c51c3..cb639d1bf12fe46df1f8627cf864138dac6ff235 100644 (file)
@@ -350,21 +350,22 @@ ilo_builder_dynamic_used(const struct ilo_builder *builder)
 }
 
 /**
- * Write a surface state to the surface buffer.  The offset, in bytes, of the
- * state is returned.
+ * Reserve a region from the surface buffer.  Both the offset, in bytes, and
+ * the pointer to the reserved region are returned.  The pointer is only valid
+ * until the next reserve call.
  *
  * Note that \p alignment is in bytes and \p len is in DWords.
  */
 static inline uint32_t
-ilo_builder_surface_write(struct ilo_builder *builder,
-                          enum ilo_builder_item_type item,
-                          unsigned alignment, unsigned len,
-                          const uint32_t *dw)
+ilo_builder_surface_pointer(struct ilo_builder *builder,
+                            enum ilo_builder_item_type item,
+                            unsigned alignment, unsigned len,
+                            uint32_t **dw)
 {
    assert(item == ILO_BUILDER_ITEM_SURFACE ||
           item == ILO_BUILDER_ITEM_BINDING_TABLE);
 
-   return ilo_builder_dynamic_write(builder, item, alignment, len, dw);
+   return ilo_builder_dynamic_pointer(builder, item, alignment, len, dw);
 }
 
 /**
index d359252aa8c956760b28944953e45a83d0a3d3b7..ab1374a4d2bbe6924cf31aabf5ce35d0803a8cc5 100644 (file)
@@ -1585,11 +1585,12 @@ gen7_3DSTATE_CONSTANT_GS(struct ilo_builder *builder,
 
 static inline uint32_t
 gen6_BINDING_TABLE_STATE(struct ilo_builder *builder,
-                         uint32_t *surface_states,
+                         const uint32_t *surface_states,
                          int num_surface_states)
 {
    const int state_align = 32;
    const int state_len = num_surface_states;
+   uint32_t state_offset, *dw;
 
    ILO_DEV_ASSERT(builder->dev, 6, 8);
 
@@ -1603,8 +1604,11 @@ gen6_BINDING_TABLE_STATE(struct ilo_builder *builder,
    if (!num_surface_states)
       return 0;
 
-   return ilo_builder_surface_write(builder, ILO_BUILDER_ITEM_BINDING_TABLE,
-         state_align, state_len, surface_states);
+   state_offset = ilo_builder_surface_pointer(builder,
+         ILO_BUILDER_ITEM_BINDING_TABLE, state_align, state_len, &dw);
+   memcpy(dw, surface_states, state_len << 2);
+
+   return state_offset;
 }
 
 static inline uint32_t
@@ -1612,23 +1616,32 @@ gen6_SURFACE_STATE(struct ilo_builder *builder,
                    const struct ilo_view_surface *surf,
                    bool for_render)
 {
-   const int state_align =
-      (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 64 : 32;
-   const int state_len =
-      (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) ? 13 :
-      (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ? 8 : 6;
-   uint32_t state_offset;
+   int state_align, state_len;
+   uint32_t state_offset, *dw;
 
    ILO_DEV_ASSERT(builder->dev, 6, 8);
 
-   state_offset = ilo_builder_surface_write(builder, ILO_BUILDER_ITEM_SURFACE,
-         state_align, state_len, surf->payload);
+   if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
+      state_align = 64;
+      state_len = 13;
 
-   if (surf->bo) {
-      if (ilo_dev_gen(builder->dev) >= ILO_GEN(8)) {
+      state_offset = ilo_builder_surface_pointer(builder,
+            ILO_BUILDER_ITEM_SURFACE, state_align, state_len, &dw);
+      memcpy(dw, surf->payload, state_len << 2);
+
+      if (surf->bo) {
          ilo_builder_surface_reloc64(builder, state_offset, 8, surf->bo,
                surf->payload[8], (for_render) ? INTEL_RELOC_WRITE : 0);
-      } else {
+      }
+   } else {
+      state_align = 32;
+      state_len = (ilo_dev_gen(builder->dev) >= ILO_GEN(7)) ? 8 : 6;
+
+      state_offset = ilo_builder_surface_pointer(builder,
+            ILO_BUILDER_ITEM_SURFACE, state_align, state_len, &dw);
+      memcpy(dw, surf->payload, state_len << 2);
+
+      if (surf->bo) {
          ilo_builder_surface_reloc(builder, state_offset, 1, surf->bo,
                surf->payload[1], (for_render) ? INTEL_RELOC_WRITE : 0);
       }