radeonsi: add support for sampler views where resource = NULL
authorMarek Olšák <marek.olsak@amd.com>
Sun, 1 Feb 2015 13:38:48 +0000 (14:38 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 4 Feb 2015 13:34:13 +0000 (14:34 +0100)
The hardware obeys swizzles even if the resource is NULL.
This will be used by set_polygon_stipple.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/radeonsi/si_state.c

index 811c1670f47a8c94619eeba1b0d22b3ed99c2c4b..3452be3de928526ce1e8d3b6259c918773f91988 100644 (file)
@@ -374,6 +374,9 @@ static void si_sampler_views_begin_new_cs(struct si_context *sctx,
                struct si_sampler_view *rview =
                        (struct si_sampler_view*)views->views[i];
 
+               if (!rview->resource)
+                       continue;
+
                r600_context_bo_reloc(&sctx->b, &sctx->b.rings.gfx,
                                      rview->resource, RADEON_USAGE_READ,
                                      si_get_resource_ro_priority(rview->resource));
@@ -398,9 +401,11 @@ static void si_set_sampler_view(struct si_context *sctx, unsigned shader,
                struct si_sampler_view *rview =
                        (struct si_sampler_view*)view;
 
-               r600_context_bo_reloc(&sctx->b, &sctx->b.rings.gfx,
-                                     rview->resource, RADEON_USAGE_READ,
-                                     si_get_resource_ro_priority(rview->resource));
+               if (rview->resource)
+                       r600_context_bo_reloc(&sctx->b, &sctx->b.rings.gfx,
+                               rview->resource, RADEON_USAGE_READ,
+                               si_get_resource_ro_priority(rview->resource));
+
 
                pipe_sampler_view_reference(&views->views[slot], view);
                views->desc_data[slot] = view_desc;
@@ -441,7 +446,7 @@ static void si_set_sampler_views(struct pipe_context *ctx,
 
                si_set_sampler_view(sctx, shader, slot, views[i], rviews[i]->state);
 
-               if (views[i]->texture->target != PIPE_BUFFER) {
+               if (views[i]->texture && views[i]->texture->target != PIPE_BUFFER) {
                        struct r600_texture *rtex =
                                (struct r600_texture*)views[i]->texture;
 
index 85954b74ea15b0b5b95f4192ac5cb31b1d6eb044..2deee4516d972af5fc6e6c5f0fe0bd29299f23f8 100644 (file)
@@ -2246,9 +2246,20 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
        /* initialize base object */
        view->base = *state;
        view->base.texture = NULL;
-       pipe_resource_reference(&view->base.texture, texture);
        view->base.reference.count = 1;
        view->base.context = ctx;
+
+       /* NULL resource, obey swizzle (only ZERO and ONE make sense). */
+       if (!texture) {
+               view->state[3] = S_008F1C_DST_SEL_X(si_map_swizzle(state->swizzle_r)) |
+                                S_008F1C_DST_SEL_Y(si_map_swizzle(state->swizzle_g)) |
+                                S_008F1C_DST_SEL_Z(si_map_swizzle(state->swizzle_b)) |
+                                S_008F1C_DST_SEL_W(si_map_swizzle(state->swizzle_a)) |
+                                S_008F1C_TYPE(V_008F1C_SQ_RSRC_IMG_1D);
+               return &view->base;
+       }
+
+       pipe_resource_reference(&view->base.texture, texture);
        view->resource = &tmp->resource;
 
        /* Buffer resource. */
@@ -2484,7 +2495,7 @@ static void si_sampler_view_destroy(struct pipe_context *ctx,
 {
        struct si_sampler_view *view = (struct si_sampler_view *)state;
 
-       if (view->resource->b.b.target == PIPE_BUFFER)
+       if (view->resource && view->resource->b.b.target == PIPE_BUFFER)
                LIST_DELINIT(&view->list);
 
        pipe_resource_reference(&state->texture, NULL);