<div dir="ltr"><div>I kind-of wonder if we want to allow for relocations and not surface state base address in which case you'd want to do something "real" with offset.  Making this an address and then ignoring the buffer part entirely seems like it promises a bit too much.  Then again, I don't think it's really hurting anything.  Meh; this is probably fine.</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 29, 2018 at 2:24 AM Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In i965, shader programs live in a single buffer, and every batch emits<br>
a STATE_BASE_ADDRESS packet pointing to that buffer.  This takes care of<br>
pinning the buffer for the batch; from then on, we can use an offset.<br>
<br>
In the upcoming Iris driver, shader programs can live in multiple<br>
buffers, and those buffers need to be pinned when shader assembly is<br>
referenced.  To aid in this, we turn KSP into a blorp_address rather<br>
than a 32-bit offset.  This lets us also pass a buffer to pin.<br>
<br>
For now, we simply assert the BO is NULL and return the offset, as<br>
we did before - nothing should behave differently.<br>
---<br>
 src/intel/blorp/blorp.h                     |  7 ++++--<br>
 src/intel/blorp/blorp_genX_exec.h           | 27 +++++++++++++--------<br>
 src/intel/blorp/blorp_priv.h                |  6 ++---<br>
 src/intel/vulkan/anv_blorp.c                | 10 +++++---<br>
 src/mesa/drivers/dri/i965/brw_blorp.c       | 18 ++++++++++----<br>
 src/mesa/drivers/dri/i965/gen4_blorp_exec.h | 12 ++++-----<br>
 6 files changed, 50 insertions(+), 30 deletions(-)<br>
<br>
diff --git a/src/intel/blorp/blorp.h b/src/intel/blorp/blorp.h<br>
index 1e22712602d..da0c9ac205c 100644<br>
--- a/src/intel/blorp/blorp.h<br>
+++ b/src/intel/blorp/blorp.h<br>
@@ -35,6 +35,7 @@ struct brw_stage_prog_data;<br>
 extern "C" {<br>
 #endif<br>
<br>
+struct blorp_address;<br>
 struct blorp_batch;<br>
 struct blorp_params;<br>
<br>
@@ -47,13 +48,15 @@ struct blorp_context {<br>
<br>
    bool (*lookup_shader)(struct blorp_context *blorp,<br>
                          const void *key, uint32_t key_size,<br>
-                         uint32_t *kernel_out, void *prog_data_out);<br>
+                         struct blorp_address *kernel_out,<br>
+                         void *prog_data_out);<br>
    bool (*upload_shader)(struct blorp_context *blorp,<br>
                          const void *key, uint32_t key_size,<br>
                          const void *kernel, uint32_t kernel_size,<br>
                          const struct brw_stage_prog_data *prog_data,<br>
                          uint32_t prog_data_size,<br>
-                         uint32_t *kernel_out, void *prog_data_out);<br>
+                         struct blorp_address *kernel_out,<br>
+                         void *prog_data_out);<br>
    void (*exec)(struct blorp_batch *batch, const struct blorp_params *params);<br>
 };<br>
<br>
diff --git a/src/intel/blorp/blorp_genX_exec.h b/src/intel/blorp/blorp_genX_exec.h<br>
index 065980616ec..20f30c7116d 100644<br>
--- a/src/intel/blorp/blorp_genX_exec.h<br>
+++ b/src/intel/blorp/blorp_genX_exec.h<br>
@@ -108,6 +108,13 @@ _blorp_combine_address(struct blorp_batch *batch, void *location,<br>
    }<br>
 }<br>
<br>
+static uint64_t<br>
+KSP(struct blorp_batch *batch, struct blorp_address address)<br>
+{<br>
+   assert(address.buffer == NULL);<br>
+   return address.offset;<br>
+}<br>
+<br>
 #define __gen_address_type struct blorp_address<br>
 #define __gen_user_data struct blorp_batch<br>
 #define __gen_combine_address _blorp_combine_address<br>
@@ -615,7 +622,7 @@ blorp_emit_vs_config(struct blorp_batch *batch,<br>
       if (vs_prog_data) {<br>
          vs.Enable = true;<br>
<br>
-         vs.KernelStartPointer = params->vs_prog_kernel;<br>
+         vs.KernelStartPointer = KSP(batch, params->vs_prog_kernel);<br>
<br>
          vs.DispatchGRFStartRegisterForURBData =<br>
             vs_prog_data->base.base.dispatch_grf_start_reg;<br>
@@ -795,11 +802,11 @@ blorp_emit_ps_config(struct blorp_batch *batch,<br>
          ps.DispatchGRFStartRegisterForConstantSetupData2 =<br>
             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 2);<br>
<br>
-         ps.KernelStartPointer0 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer0 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 0);<br>
-         ps.KernelStartPointer1 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer1 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 1);<br>
-         ps.KernelStartPointer2 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer2 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 2);<br>
       }<br>
<br>
@@ -905,11 +912,11 @@ blorp_emit_ps_config(struct blorp_batch *batch,<br>
          ps.DispatchGRFStartRegisterForConstantSetupData2 =<br>
             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, ps, 2);<br>
<br>
-         ps.KernelStartPointer0 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer0 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 0);<br>
-         ps.KernelStartPointer1 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer1 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 1);<br>
-         ps.KernelStartPointer2 = params->wm_prog_kernel +<br>
+         ps.KernelStartPointer2 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, ps, 2);<br>
<br>
          ps.AttributeEnable = prog_data->num_varying_inputs > 0;<br>
@@ -973,11 +980,11 @@ blorp_emit_ps_config(struct blorp_batch *batch,<br>
          wm.DispatchGRFStartRegisterForConstantSetupData2 =<br>
             brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm, 2);<br>
<br>
-         wm.KernelStartPointer0 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer0 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 0);<br>
-         wm.KernelStartPointer1 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer1 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 1);<br>
-         wm.KernelStartPointer2 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer2 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 2);<br>
<br>
          wm.NumberofSFOutputAttributes = prog_data->num_varying_inputs;<br>
diff --git a/src/intel/blorp/blorp_priv.h b/src/intel/blorp/blorp_priv.h<br>
index a6aa2aa4151..b60505ea06a 100644<br>
--- a/src/intel/blorp/blorp_priv.h<br>
+++ b/src/intel/blorp/blorp_priv.h<br>
@@ -203,11 +203,11 @@ struct blorp_params<br>
    unsigned num_samples;<br>
    unsigned num_draw_buffers;<br>
    unsigned num_layers;<br>
-   uint32_t vs_prog_kernel;<br>
+   struct blorp_address vs_prog_kernel;<br>
    struct brw_vs_prog_data *vs_prog_data;<br>
-   uint32_t sf_prog_kernel;<br>
+   struct blorp_address sf_prog_kernel;<br>
    struct brw_sf_prog_data *sf_prog_data;<br>
-   uint32_t wm_prog_kernel;<br>
+   struct blorp_address wm_prog_kernel;<br>
    struct brw_wm_prog_data *wm_prog_data;<br>
<br>
    bool use_pre_baked_binding_table;<br>
diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c<br>
index 478b8e7a3db..e6bcf4b0bc1 100644<br>
--- a/src/intel/vulkan/anv_blorp.c<br>
+++ b/src/intel/vulkan/anv_blorp.c<br>
@@ -26,7 +26,8 @@<br>
 static bool<br>
 lookup_blorp_shader(struct blorp_context *blorp,<br>
                     const void *key, uint32_t key_size,<br>
-                    uint32_t *kernel_out, void *prog_data_out)<br>
+                    struct blorp_address *kernel_out,<br>
+                    void *prog_data_out)<br>
 {<br>
    struct anv_device *device = blorp->driver_ctx;<br>
<br>
@@ -43,7 +44,7 @@ lookup_blorp_shader(struct blorp_context *blorp,<br>
     */<br>
    anv_shader_bin_unref(device, bin);<br>
<br>
-   *kernel_out = bin->kernel.offset;<br>
+   *kernel_out = (struct blorp_address) { .offset = bin->kernel.offset };<br>
    *(const struct brw_stage_prog_data **)prog_data_out = bin->prog_data;<br>
<br>
    return true;<br>
@@ -55,7 +56,8 @@ upload_blorp_shader(struct blorp_context *blorp,<br>
                     const void *kernel, uint32_t kernel_size,<br>
                     const struct brw_stage_prog_data *prog_data,<br>
                     uint32_t prog_data_size,<br>
-                    uint32_t *kernel_out, void *prog_data_out)<br>
+                    struct blorp_address *kernel_out,<br>
+                    void *prog_data_out)<br>
 {<br>
    struct anv_device *device = blorp->driver_ctx;<br>
<br>
@@ -81,7 +83,7 @@ upload_blorp_shader(struct blorp_context *blorp,<br>
     */<br>
    anv_shader_bin_unref(device, bin);<br>
<br>
-   *kernel_out = bin->kernel.offset;<br>
+   *kernel_out = (struct blorp_address) { .offset = bin->kernel.offset };<br>
    *(const struct brw_stage_prog_data **)prog_data_out = bin->prog_data;<br>
<br>
    return true;<br>
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c b/src/mesa/drivers/dri/i965/brw_blorp.c<br>
index b286b231537..d021e2906fe 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_blorp.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c<br>
@@ -45,11 +45,16 @@<br>
 static bool<br>
 brw_blorp_lookup_shader(struct blorp_context *blorp,<br>
                         const void *key, uint32_t key_size,<br>
-                        uint32_t *kernel_out, void *prog_data_out)<br>
+                        struct blorp_address *kernel_out,<br>
+                        void *prog_data_out)<br>
 {<br>
    struct brw_context *brw = blorp->driver_ctx;<br>
-   return brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG, key, key_size,<br>
-                           kernel_out, prog_data_out, true);<br>
+   uint32_t offset;<br>
+   bool found =<br>
+      brw_search_cache(&brw->cache, BRW_CACHE_BLORP_PROG, key, key_size,<br>
+                       &offset, prog_data_out, true);<br>
+   *kernel_out = (struct blorp_address) { .offset = offset };<br>
+   return found;<br>
 }<br>
<br>
 static bool<br>
@@ -58,12 +63,15 @@ brw_blorp_upload_shader(struct blorp_context *blorp,<br>
                         const void *kernel, uint32_t kernel_size,<br>
                         const struct brw_stage_prog_data *prog_data,<br>
                         uint32_t prog_data_size,<br>
-                        uint32_t *kernel_out, void *prog_data_out)<br>
+                        struct blorp_address *kernel_out,<br>
+                        void *prog_data_out)<br>
 {<br>
    struct brw_context *brw = blorp->driver_ctx;<br>
+   uint32_t offset;<br>
    brw_upload_cache(&brw->cache, BRW_CACHE_BLORP_PROG, key, key_size,<br>
                     kernel, kernel_size, prog_data, prog_data_size,<br>
-                    kernel_out, prog_data_out);<br>
+                    &offset, prog_data_out);<br>
+   *kernel_out = (struct blorp_address) { .offset = offset };<br>
    return true;<br>
 }<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/gen4_blorp_exec.h b/src/mesa/drivers/dri/i965/gen4_blorp_exec.h<br>
index 0edc518fa35..3b0f1ea0979 100644<br>
--- a/src/mesa/drivers/dri/i965/gen4_blorp_exec.h<br>
+++ b/src/mesa/drivers/dri/i965/gen4_blorp_exec.h<br>
@@ -77,9 +77,9 @@ blorp_emit_sf_state(struct blorp_batch *batch,<br>
    blorp_emit_dynamic(batch, GENX(SF_STATE), sf, 64, &offset) {<br>
 #if GEN_GEN == 4<br>
       sf.KernelStartPointer =<br>
-         instruction_state_address(batch, params->sf_prog_kernel);<br>
+         instruction_state_address(batch, KSP(batch, params->sf_prog_kernel));<br>
 #else<br>
-      sf.KernelStartPointer = params->sf_prog_kernel;<br>
+      sf.KernelStartPointer = KSP(batch, params->sf_prog_kernel);<br>
 #endif<br>
       sf.GRFRegisterCount = DIV_ROUND_UP(prog_data->total_grf, 16) - 1;<br>
       sf.VertexURBEntryReadLength = prog_data->urb_read_length;<br>
@@ -136,14 +136,14 @@ blorp_emit_wm_state(struct blorp_batch *batch,<br>
<br>
 #if GEN_GEN == 4<br>
          wm.KernelStartPointer0 =<br>
-            instruction_state_address(batch, params->wm_prog_kernel);<br>
+            instruction_state_address(batch, KSP(batch, params->wm_prog_kernel));<br>
          wm.GRFRegisterCount0 = brw_wm_prog_data_reg_blocks(prog_data, wm, 0);<br>
 #else<br>
-         wm.KernelStartPointer0 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer0 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 0);<br>
-         wm.KernelStartPointer1 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer1 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 1);<br>
-         wm.KernelStartPointer2 = params->wm_prog_kernel +<br>
+         wm.KernelStartPointer2 = KSP(batch, params->wm_prog_kernel) +<br>
                                   brw_wm_prog_data_prog_offset(prog_data, wm, 2);<br>
          wm.GRFRegisterCount0 = brw_wm_prog_data_reg_blocks(prog_data, wm, 0);<br>
          wm.GRFRegisterCount1 = brw_wm_prog_data_reg_blocks(prog_data, wm, 1);<br>
-- <br>
2.19.1<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>