iris: null surface for unbound textures
authorKenneth Graunke <kenneth@whitecape.org>
Wed, 27 Jun 2018 23:59:59 +0000 (16:59 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:07 +0000 (10:26 -0800)
avoids crashes...may not be really right

src/gallium/drivers/iris/iris_context.h
src/gallium/drivers/iris/iris_state.c

index b5489c7e46ece80a55c1b93f10c4ba2d43d13028..5e6b9e0228003a2c38e7cbaf1aa57828cb8467b6 100644 (file)
@@ -269,6 +269,9 @@ struct iris_context {
       unsigned num_samplers[MESA_SHADER_STAGES];
       unsigned num_textures[MESA_SHADER_STAGES];
 
+      struct pipe_resource *unbound_tex_surface_state_resource;
+      unsigned unbound_tex_surface_state_offset;
+
       struct u_upload_mgr *surface_uploader;
       // XXX: may want a separate uploader for "hey I made a CSO!" vs
       // "I'm streaming this out at draw time and never want it again!"
index 01bdab0fb5b2e96b2fb1c92c1951a3449806b344..4efef936ac4c3286055d87d1ccceb9a0c2fb5a87 100644 (file)
@@ -2260,6 +2260,17 @@ use_const_buffer(struct iris_batch *batch, struct iris_const_buffer *cbuf)
    return cbuf->surface_state_offset;
 }
 
+static uint32_t
+use_null_surface(struct iris_batch *batch, struct iris_context *ice)
+{
+   struct iris_resource *state_res =
+      (void *) ice->state.unbound_tex_surface_state_resource;
+
+   iris_use_pinned_bo(batch, state_res->bo, false);
+
+   return ice->state.unbound_tex_surface_state_offset;
+}
+
 static void
 iris_populate_binding_table(struct iris_context *ice,
                             struct iris_batch *batch,
@@ -2293,7 +2304,8 @@ iris_populate_binding_table(struct iris_context *ice,
 
    for (int i = 0; i < ice->state.num_textures[stage]; i++) {
       struct iris_sampler_view *view = ice->state.textures[stage][i];
-      bt_map[s++] = use_sampler_view(batch, view);
+      bt_map[s++] = view ? use_sampler_view(batch, view)
+                         : use_null_surface(batch, ice);
    }
 
    // XXX: want the number of BTE's to shorten this loop
@@ -3293,6 +3305,7 @@ void
 genX(init_state)(struct iris_context *ice)
 {
    struct pipe_context *ctx = &ice->ctx;
+   struct iris_screen *screen = (struct iris_screen *)ctx->screen;
 
    ctx->create_blend_state = iris_create_blend_state;
    ctx->create_depth_stencil_alpha_state = iris_create_zsa_state;
@@ -3356,4 +3369,13 @@ genX(init_state)(struct iris_context *ice)
    ice->state.cso_vp = calloc(1, sizeof(struct iris_viewport_state));
    ice->state.cso_vertex_buffers =
       calloc(1, sizeof(struct iris_vertex_buffer_state));
+
+   /* Make a 1x1x1 null surface for unbound textures */
+   void *null_surf_map = NULL;
+   u_upload_alloc(ice->state.surface_uploader, 0,
+                  4 * GENX(RENDER_SURFACE_STATE_length), 64,
+                  &ice->state.unbound_tex_surface_state_offset,
+                  &ice->state.unbound_tex_surface_state_resource,
+                  &null_surf_map);
+   isl_null_fill_state(&screen->isl_dev, null_surf_map, isl_extent3d(1, 1, 1));
 }