intel: allocate a separate surface state bo

Add INTEL_CMD_WRITER_SURFACE to intel_cmd, and write BINDING_TABLE_STATEs and
SURFACE_STATEs to the new writer.  Fix cmd_batch_state_base_address() up for
the separation.
diff --git a/icd/intel/cmd.c b/icd/intel/cmd.c
index 4d38da3..47f8629 100644
--- a/icd/intel/cmd.c
+++ b/icd/intel/cmd.c
@@ -82,6 +82,8 @@
 {
     static const char *writer_names[INTEL_CMD_WRITER_COUNT] = {
         [INTEL_CMD_WRITER_BATCH] = "batch",
+        [INTEL_CMD_WRITER_SURFACE] = "surface",
+        [INTEL_CMD_WRITER_STATE] = "state",
         [INTEL_CMD_WRITER_INSTRUCTION] = "instruction",
     };
 
@@ -350,7 +352,8 @@
             divider *= 4;
 
         cmd->writers[INTEL_CMD_WRITER_BATCH].size = size / divider;
-        cmd->writers[INTEL_CMD_WRITER_STATE].size = size / divider;
+        cmd->writers[INTEL_CMD_WRITER_SURFACE].size = size / divider / 2;
+        cmd->writers[INTEL_CMD_WRITER_STATE].size = size / divider / 2;
         cmd->writers[INTEL_CMD_WRITER_INSTRUCTION].size = 16384 / divider;
     }
 
diff --git a/icd/intel/cmd.h b/icd/intel/cmd.h
index a1a076d..dcb1965 100644
--- a/icd/intel/cmd.h
+++ b/icd/intel/cmd.h
@@ -122,6 +122,7 @@
 
 enum intel_cmd_writer_type {
     INTEL_CMD_WRITER_BATCH,
+    INTEL_CMD_WRITER_SURFACE,
     INTEL_CMD_WRITER_STATE,
     INTEL_CMD_WRITER_INSTRUCTION,
 
diff --git a/icd/intel/cmd_decode.c b/icd/intel/cmd_decode.c
index 362efc3..0a6c502 100644
--- a/icd/intel/cmd_decode.c
+++ b/icd/intel/cmd_decode.c
@@ -569,8 +569,13 @@
                     writer->bo, writer->used);
         }
         break;
+    case INTEL_CMD_WRITER_SURFACE:
+        fprintf(stderr, "decoding surface state buffer: %d states\n",
+                writer->item_used);
+        cmd_writer_decode_items(cmd, which);
+        break;
     case INTEL_CMD_WRITER_STATE:
-        fprintf(stderr, "decoding state buffer: %d states\n",
+        fprintf(stderr, "decoding dynamic state buffer: %d states\n",
                 writer->item_used);
         cmd_writer_decode_items(cmd, which);
         break;
diff --git a/icd/intel/cmd_pipeline.c b/icd/intel/cmd_pipeline.c
index d600a0a..55947ad 100644
--- a/icd/intel/cmd_pipeline.c
+++ b/icd/intel/cmd_pipeline.c
@@ -1200,7 +1200,7 @@
     dw[9] = 1;
 
     cmd_reserve_reloc(cmd, 3);
-    cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_STATE, 1);
+    cmd_batch_reloc_writer(cmd, pos + 2, INTEL_CMD_WRITER_SURFACE, 1);
     cmd_batch_reloc_writer(cmd, pos + 3, INTEL_CMD_WRITER_STATE, 1);
     cmd_batch_reloc_writer(cmd, pos + 5, INTEL_CMD_WRITER_INSTRUCTION, 1);
 }
diff --git a/icd/intel/cmd_priv.h b/icd/intel/cmd_priv.h
index dda45e1..9349b10 100644
--- a/icd/intel/cmd_priv.h
+++ b/icd/intel/cmd_priv.h
@@ -286,10 +286,27 @@
                                          size_t alignment, uint32_t len,
                                          const uint32_t *dw)
 {
+    const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
+    const XGL_SIZE size = len << 2;
+    const uint32_t offset = cmd_writer_reserve(cmd, which, alignment, size);
+    struct intel_cmd_writer *writer = &cmd->writers[which];
+    uint32_t *dst;
+
     assert(item == INTEL_CMD_ITEM_SURFACE ||
            item == INTEL_CMD_ITEM_BINDING_TABLE);
 
-    return cmd_state_write(cmd, item, alignment, len, dw);
+    /* all states are at least aligned to 32-bytes */
+    assert(alignment % 32 == 0);
+
+    writer->used = offset + size;
+
+    if (intel_debug & INTEL_DEBUG_BATCH)
+        cmd_writer_record(cmd, which, item, offset, size);
+
+    dst = (uint32_t *) ((char *) writer->ptr + offset);
+    memcpy(dst, dw, size);
+
+    return offset;
 }
 
 /**
@@ -300,7 +317,7 @@
                                      struct intel_bo *bo,
                                      uint32_t bo_offset, uint32_t reloc_flags)
 {
-    const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
+    const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
 
     cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
             (intptr_t) bo, bo_offset, reloc_flags);
@@ -311,7 +328,7 @@
                                             enum intel_cmd_writer_type writer,
                                             uint32_t writer_offset)
 {
-    const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_STATE;
+    const enum intel_cmd_writer_type which = INTEL_CMD_WRITER_SURFACE;
 
     cmd_writer_reloc(cmd, which, offset + (dw_index << 2),
             (intptr_t) writer, writer_offset,