iris: Defer uploading of surface states
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 1 Feb 2021 12:51:11 +0000 (04:51 -0800)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 4 Mar 2021 21:59:20 +0000 (13:59 -0800)
With u_threaded_context, create_surface and create_sampler_view will
be called from a different thread than the driver thread.  They aren't
allowed to access the context, which means that they can't use the
uploaders there to upload our SURFACE_STATE entries.

Thanks to backing-storage replacement and iris_rebind_buffer, we already
reworked things to maintain CPU-side copies of the SURFACE_STATE entries
and added the ability to upload or re-upload them later.  So we can skip
the upload at object creation time, and add a simple resource-is-NULL
check at binding table upload time to ensure that they get uploaded by
the time we need them.  (They might get uploaded earlier due to rebinds
or clear color updates, but this is the last moment to do so.)

Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8964>

src/gallium/drivers/iris/iris_state.c

index ec92720..fd621d9 100644 (file)
@@ -2430,7 +2430,6 @@ iris_create_sampler_view(struct pipe_context *ctx,
                          struct pipe_resource *tex,
                          const struct pipe_sampler_view *tmpl)
 {
-   struct iris_context *ice = (struct iris_context *) ctx;
    struct iris_screen *screen = (struct iris_screen *)ctx->screen;
    const struct gen_device_info *devinfo = &screen->devinfo;
    struct iris_sampler_view *isv = calloc(1, sizeof(struct iris_sampler_view));
@@ -2513,8 +2512,6 @@ iris_create_sampler_view(struct pipe_context *ctx,
                                 ISL_SURF_USAGE_TEXTURE_BIT);
    }
 
-   upload_surface_states(ice->state.surface_uploader, &isv->surface_state);
-
    return &isv->base;
 }
 
@@ -2540,7 +2537,6 @@ iris_create_surface(struct pipe_context *ctx,
                     struct pipe_resource *tex,
                     const struct pipe_surface *tmpl)
 {
-   struct iris_context *ice = (struct iris_context *) ctx;
    struct iris_screen *screen = (struct iris_screen *)ctx->screen;
    const struct gen_device_info *devinfo = &screen->devinfo;
 
@@ -2657,13 +2653,6 @@ iris_create_surface(struct pipe_context *ctx,
 #endif
       }
 
-      upload_surface_states(ice->state.surface_uploader, &surf->surface_state);
-
-#if GEN_GEN == 8
-      upload_surface_states(ice->state.surface_uploader,
-                            &surf->surface_state_read);
-#endif
-
       return psurf;
    }
 
@@ -2745,8 +2734,6 @@ iris_create_surface(struct pipe_context *ctx,
 
    isl_surf_fill_state_s(&screen->isl_dev, surf->surface_state.cpu, &f);
 
-   upload_surface_states(ice->state.surface_uploader, &surf->surface_state);
-
    return psurf;
 }
 
@@ -4819,6 +4806,16 @@ use_surface(struct iris_context *ice,
    struct iris_resource *res = (void *) p_surf->texture;
    uint32_t offset = 0;
 
+   if (GEN_GEN == 8 && is_read_surface && !surf->surface_state_read.ref.res) {
+      upload_surface_states(ice->state.surface_uploader,
+                            &surf->surface_state_read);
+   }
+
+   if (!surf->surface_state.ref.res) {
+      upload_surface_states(ice->state.surface_uploader,
+                            &surf->surface_state);
+   }
+
    if (res->aux.bo) {
       iris_use_pinned_bo(batch, res->aux.bo, writeable, access);
       if (res->aux.clear_color_bo)
@@ -4862,6 +4859,9 @@ use_sampler_view(struct iris_context *ice,
    enum isl_aux_usage aux_usage =
       iris_resource_texture_aux_usage(ice, isv->res, isv->view.format);
 
+   if (!isv->surface_state.ref.res)
+      upload_surface_states(ice->state.surface_uploader, &isv->surface_state);
+
    if (isv->res->aux.bo) {
       iris_use_pinned_bo(batch, isv->res->aux.bo,
                          false, IRIS_DOMAIN_OTHER_READ);