ilo: make constant buffer 0 upload optional
authorChia-I Wu <olvaffe@gmail.com>
Wed, 17 Jul 2013 21:43:00 +0000 (05:43 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Tue, 13 Aug 2013 07:52:37 +0000 (15:52 +0800)
Add ILO_KERNEL_SKIP_CBUF0_UPLOAD so that we can skip constant buffer 0 upload
when the kernel does not need it.

src/gallium/drivers/ilo/ilo_shader.c
src/gallium/drivers/ilo/ilo_shader.h
src/gallium/drivers/ilo/ilo_state.c

index 27555262b972ab27826cf2aa085336c11a3d95da..0db03966c6b2bbcaeeb2b4c0bb33246e0f413a0a 100644 (file)
@@ -1060,6 +1060,9 @@ ilo_shader_get_kernel_param(const struct ilo_shader_state *shader,
    case ILO_KERNEL_URB_DATA_START_REG:
       val = kernel->in.start_grf;
       break;
+   case ILO_KERNEL_SKIP_CBUF0_UPLOAD:
+      val = false;
+      break;
 
    case ILO_KERNEL_VS_INPUT_INSTANCEID:
       val = shader->info.has_instanceid;
index 6a2b8a397b39679eb1fdcf6a59a2b8beebb9674e..67f190c7bc04e42beae1f1d798f4eeb813716c18 100644 (file)
@@ -34,6 +34,7 @@ enum ilo_kernel_param {
    ILO_KERNEL_INPUT_COUNT,
    ILO_KERNEL_OUTPUT_COUNT,
    ILO_KERNEL_URB_DATA_START_REG,
+   ILO_KERNEL_SKIP_CBUF0_UPLOAD,
 
    ILO_KERNEL_VS_INPUT_INSTANCEID,
    ILO_KERNEL_VS_INPUT_VERTEXID,
index ce6930c4aec78dd04cce4e1b01dc87f69b51cf7e..c72d93a49df14011c39eb321b664edc8ae7bf180 100644 (file)
@@ -85,44 +85,46 @@ finalize_shader_states(struct ilo_context *ilo)
 }
 
 static void
-finalize_constant_buffers(struct ilo_context *ilo)
+finalize_cbuf_state(struct ilo_context *ilo,
+                    struct ilo_cbuf_state *cbuf,
+                    const struct ilo_shader_state *sh)
 {
-   int sh;
+   uint32_t upload_mask = cbuf->enabled_mask;
 
-   if (!(ilo->dirty & ILO_DIRTY_CBUF))
-      return;
+   /* skip CBUF0 if the kernel does not need it */
+   upload_mask &=
+      ~ilo_shader_get_kernel_param(sh, ILO_KERNEL_SKIP_CBUF0_UPLOAD);
 
-   /* TODO push constants? */
-   for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
-      unsigned enabled_mask = ilo->cbuf[sh].enabled_mask;
+   while (upload_mask) {
+      const enum pipe_format elem_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+      unsigned offset, i;
 
-      while (enabled_mask) {
-         struct ilo_cbuf_cso *cbuf;
-         int i;
+      i = u_bit_scan(&upload_mask);
+      /* no need to upload */
+      if (cbuf->cso[i].resource)
+         continue;
 
-         i = u_bit_scan(&enabled_mask);
-         cbuf = &ilo->cbuf[sh].cso[i];
+      u_upload_data(ilo->uploader, 0, cbuf->cso[i].user_buffer_size,
+            cbuf->cso[i].user_buffer, &offset, &cbuf->cso[i].resource);
 
-         /* upload user buffer */
-         if (cbuf->user_buffer) {
-            const enum pipe_format elem_format =
-               PIPE_FORMAT_R32G32B32A32_FLOAT;
-            unsigned offset;
+      ilo_gpe_init_view_surface_for_buffer(ilo->dev,
+            ilo_buffer(cbuf->cso[i].resource),
+            offset, cbuf->cso[i].user_buffer_size,
+            util_format_get_blocksize(elem_format), elem_format,
+            false, false, &cbuf->cso[i].surface);
 
-            u_upload_data(ilo->uploader, 0, cbuf->user_buffer_size,
-                  cbuf->user_buffer, &offset, &cbuf->resource);
+      ilo->dirty |= ILO_DIRTY_CBUF;
+   }
+}
 
-            ilo_gpe_init_view_surface_for_buffer(ilo->dev,
-                  ilo_buffer(cbuf->resource),
-                  offset, cbuf->user_buffer_size,
-                  util_format_get_blocksize(elem_format), elem_format,
-                  false, false, &cbuf->surface);
+static void
+finalize_constant_buffers(struct ilo_context *ilo)
+{
+   if (ilo->dirty & (ILO_DIRTY_CBUF | ILO_DIRTY_VS))
+      finalize_cbuf_state(ilo, &ilo->cbuf[PIPE_SHADER_VERTEX], ilo->vs);
 
-            cbuf->user_buffer = NULL;
-            cbuf->user_buffer_size = 0;
-         }
-      }
-   }
+   if (ilo->dirty & (ILO_DIRTY_CBUF | ILO_DIRTY_FS))
+      finalize_cbuf_state(ilo, &ilo->cbuf[PIPE_SHADER_FRAGMENT], ilo->fs);
 }
 
 static void