iris: Move upload_ubo_ssbo_surf_state to iris_program.c
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 28 May 2019 22:52:58 +0000 (17:52 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Wed, 29 May 2019 21:09:16 +0000 (21:09 +0000)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_program.c
src/gallium/drivers/iris/iris_state.c

index 42cad5e85512d2742e5d1e0f6842fe8563da55a6..3009c8d5627f2c172dc305e7cbbb3f5e508b50f4 100644 (file)
@@ -780,6 +780,10 @@ void gen11_emit_urb_setup(struct iris_context *ice,
                           bool tess_present, bool gs_present);
 
 /* iris_program.c */
+void iris_upload_ubo_ssbo_surf_state(struct iris_context *ice,
+                                     struct pipe_shader_buffer *buf,
+                                     struct iris_state_ref *surf_state,
+                                     bool ssbo);
 const struct shader_info *iris_get_shader_info(const struct iris_context *ice,
                                                gl_shader_stage stage);
 struct iris_bo *iris_get_scratch_space(struct iris_context *ice,
index 0e294d1b8e0f7fc4cceb04b22b2997f6cdd99764..37cf123ae6b68134f099545be82bd7b375afa0d5 100644 (file)
@@ -36,6 +36,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_screen.h"
 #include "util/u_atomic.h"
+#include "util/u_upload_mgr.h"
 #include "compiler/nir/nir.h"
 #include "compiler/nir/nir_builder.h"
 #include "compiler/nir/nir_serialize.h"
@@ -56,6 +57,50 @@ get_new_program_id(struct iris_screen *screen)
    return p_atomic_inc_return(&screen->program_id);
 }
 
+static void *
+upload_state(struct u_upload_mgr *uploader,
+             struct iris_state_ref *ref,
+             unsigned size,
+             unsigned alignment)
+{
+   void *p = NULL;
+   u_upload_alloc(uploader, 0, size, alignment, &ref->offset, &ref->res, &p);
+   return p;
+}
+
+void
+iris_upload_ubo_ssbo_surf_state(struct iris_context *ice,
+                                struct pipe_shader_buffer *buf,
+                                struct iris_state_ref *surf_state,
+                                bool ssbo)
+{
+   struct pipe_context *ctx = &ice->ctx;
+   struct iris_screen *screen = (struct iris_screen *) ctx->screen;
+
+   // XXX: these are not retained forever, use a separate uploader?
+   void *map =
+      upload_state(ice->state.surface_uploader, surf_state,
+                   screen->isl_dev.ss.size, 64);
+   if (!unlikely(map)) {
+      surf_state->res = NULL;
+      return;
+   }
+
+   struct iris_resource *res = (void *) buf->buffer;
+   struct iris_bo *surf_bo = iris_resource_bo(surf_state->res);
+   surf_state->offset += iris_bo_offset_from_base_address(surf_bo);
+
+   isl_buffer_fill_state(&screen->isl_dev, map,
+                         .address = res->bo->gtt_offset + res->offset +
+                                    buf->buffer_offset,
+                         .size_B = buf->buffer_size - res->offset,
+                         .format = ssbo ? ISL_FORMAT_RAW
+                                        : ISL_FORMAT_R32G32B32A32_FLOAT,
+                         .swizzle = ISL_SWIZZLE_IDENTITY,
+                         .stride_B = 1,
+                         .mocs = ice->vtbl.mocs(res->bo));
+}
+
 static nir_ssa_def *
 get_aoa_deref_offset(nir_builder *b,
                      nir_deref_instr *deref,
index da6e4a31c85b7099a56c850cec6d3620042f9e56..0f6290ae8dcabc65bf6407e434b3b1d270b628ac 100644 (file)
@@ -2575,40 +2575,6 @@ iris_set_framebuffer_state(struct pipe_context *ctx,
 #endif
 }
 
-static void
-upload_ubo_ssbo_surf_state(struct iris_context *ice,
-                           struct pipe_shader_buffer *buf,
-                           struct iris_state_ref *surf_state,
-                           bool ssbo)
-{
-   struct pipe_context *ctx = &ice->ctx;
-   struct iris_screen *screen = (struct iris_screen *) ctx->screen;
-
-   // XXX: these are not retained forever, use a separate uploader?
-   void *map =
-      upload_state(ice->state.surface_uploader, surf_state,
-                   4 * GENX(RENDER_SURFACE_STATE_length), 64);
-   if (!unlikely(map)) {
-      surf_state->res = NULL;
-      return;
-   }
-
-   struct iris_resource *res = (void *) buf->buffer;
-   struct iris_bo *surf_bo = iris_resource_bo(surf_state->res);
-   surf_state->offset += iris_bo_offset_from_base_address(surf_bo);
-
-   isl_buffer_fill_state(&screen->isl_dev, map,
-                         .address = res->bo->gtt_offset + res->offset +
-                                    buf->buffer_offset,
-                         .size_B = buf->buffer_size - res->offset,
-                         .format = ssbo ? ISL_FORMAT_RAW
-                                        : ISL_FORMAT_R32G32B32A32_FLOAT,
-                         .swizzle = ISL_SWIZZLE_IDENTITY,
-                         .stride_B = 1,
-                         .mocs = mocs(res->bo))
-
-}
-
 /**
  * The pipe->set_constant_buffer() driver hook.
  *
@@ -2639,8 +2605,9 @@ iris_set_constant_buffer(struct pipe_context *ctx,
       struct iris_resource *res = (void *) cbuf->buffer;
       res->bind_history |= PIPE_BIND_CONSTANT_BUFFER;
 
-      upload_ubo_ssbo_surf_state(ice, cbuf, &shs->constbuf_surf_state[index],
-                                 false);
+      iris_upload_ubo_ssbo_surf_state(ice, cbuf,
+                                      &shs->constbuf_surf_state[index],
+                                      false);
    } else {
       shs->bound_cbufs &= ~(1u << index);
       pipe_resource_reference(&cbuf->buffer, NULL);
@@ -2734,7 +2701,8 @@ upload_uniforms(struct iris_context *ice,
    }
 
    cbuf->buffer_size = upload_size;
-   upload_ubo_ssbo_surf_state(ice, cbuf, &shs->constbuf_surf_state[0], false);
+   iris_upload_ubo_ssbo_surf_state(ice, cbuf,
+                                   &shs->constbuf_surf_state[0], false);
 }
 
 /**
@@ -2773,7 +2741,7 @@ iris_set_shader_buffers(struct pipe_context *ctx,
 
          shs->bound_ssbos |= 1 << (start_slot + i);
 
-         upload_ubo_ssbo_surf_state(ice, ssbo, surf_state, true);
+         iris_upload_ubo_ssbo_surf_state(ice, ssbo, surf_state, true);
 
          res->bind_history |= PIPE_BIND_SHADER_BUFFER;
 
@@ -5807,7 +5775,7 @@ iris_rebind_buffer(struct iris_context *ice,
             struct iris_state_ref *surf_state = &shs->constbuf_surf_state[i];
 
             if (res->bo == iris_resource_bo(cbuf->buffer)) {
-               upload_ubo_ssbo_surf_state(ice, cbuf, surf_state, false);
+               iris_upload_ubo_ssbo_surf_state(ice, cbuf, surf_state, false);
                ice->state.dirty |= IRIS_DIRTY_CONSTANTS_VS << s;
             }
          }