radeonsi: silence a Coverity warning
[mesa.git] / src / gallium / drivers / radeonsi / si_descriptors.c
index 097ffcd3d723b2b3be85860c5427ad98a8dae12a..c92a6575ede4b613fe2b2fe58305b3441d4f503d 100644 (file)
@@ -58,6 +58,7 @@
 #include "radeon/r600_cs.h"
 #include "si_pipe.h"
 #include "sid.h"
+#include "gfx9d.h"
 
 #include "util/u_format.h"
 #include "util/u_memory.h"
@@ -112,6 +113,7 @@ static void si_init_descriptors(struct si_descriptors *desc,
        desc->shader_userdata_offset = shader_userdata_index * 4;
 
        if (ce_offset) {
+               desc->uses_ce = true;
                desc->ce_offset = *ce_offset;
 
                /* make sure that ce_offset stays 32 byte aligned */
@@ -137,8 +139,9 @@ static bool si_ce_upload(struct si_context *sctx, unsigned ce_offset, unsigned s
                         unsigned *out_offset, struct r600_resource **out_buf) {
        uint64_t va;
 
-       u_suballocator_alloc(sctx->ce_suballocator, size, 64, out_offset,
-                            (struct pipe_resource**)out_buf);
+       u_suballocator_alloc(sctx->ce_suballocator, size,
+                            sctx->screen->b.info.tcc_cache_line_size,
+                            out_offset, (struct pipe_resource**)out_buf);
        if (!out_buf)
                        return false;
 
@@ -208,7 +211,7 @@ static bool si_upload_descriptors(struct si_context *sctx,
        if (!desc->dirty_mask)
                return true;
 
-       if (sctx->ce_ib) {
+       if (sctx->ce_ib && desc->uses_ce) {
                uint32_t const* list = (uint32_t const*)desc->list;
 
                if (desc->ce_ram_dirty)
@@ -234,18 +237,19 @@ static bool si_upload_descriptors(struct si_context *sctx,
        } else {
                void *ptr;
 
-               u_upload_alloc(sctx->b.uploader, 0, list_size, 256,
-                       &desc->buffer_offset,
-                       (struct pipe_resource**)&desc->buffer, &ptr);
+               u_upload_alloc(sctx->b.b.const_uploader, 0, list_size,
+                              sctx->screen->b.info.tcc_cache_line_size,
+                              &desc->buffer_offset,
+                              (struct pipe_resource**)&desc->buffer, &ptr);
                if (!desc->buffer)
                        return false; /* skip the draw call */
 
                util_memcpy_cpu_to_le32(ptr, desc->list, list_size);
+               desc->gpu_list = ptr;
 
                radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx, desc->buffer,
                                    RADEON_USAGE_READ, RADEON_PRIO_DESCRIPTORS);
        }
-       desc->pointer_dirty = true;
        desc->dirty_mask = 0;
 
        if (atom)
@@ -320,14 +324,21 @@ static void si_sampler_view_add_buffer(struct si_context *sctx,
        if (resource->target == PIPE_BUFFER)
                return;
 
-       /* Now add separate DCC if it's present. */
+       /* Now add separate DCC or HTILE. */
        rtex = (struct r600_texture*)resource;
-       if (!rtex->dcc_separate_buffer)
-               return;
+       if (rtex->dcc_separate_buffer) {
+               radeon_add_to_buffer_list_check_mem(&sctx->b, &sctx->b.gfx,
+                                                   rtex->dcc_separate_buffer, usage,
+                                                   RADEON_PRIO_DCC, check_mem);
+       }
 
-       radeon_add_to_buffer_list_check_mem(&sctx->b, &sctx->b.gfx,
-                                           rtex->dcc_separate_buffer, usage,
-                                           RADEON_PRIO_DCC, check_mem);
+       if (rtex->htile_buffer &&
+           rtex->tc_compatible_htile &&
+           !is_stencil_sampler) {
+               radeon_add_to_buffer_list_check_mem(&sctx->b, &sctx->b.gfx,
+                                                   rtex->htile_buffer, usage,
+                                                   RADEON_PRIO_HTILE, check_mem);
+       }
 }
 
 static void si_sampler_views_begin_new_cs(struct si_context *sctx,
@@ -367,41 +378,92 @@ static void si_set_buf_desc_address(struct r600_resource *buf,
  * \param is_stencil           select between separate Z & Stencil
  * \param state                        descriptor to update
  */
-void si_set_mutable_tex_desc_fields(struct r600_texture *tex,
-                                   const struct radeon_surf_level *base_level_info,
+void si_set_mutable_tex_desc_fields(struct si_screen *sscreen,
+                                   struct r600_texture *tex,
+                                   const struct legacy_surf_level *base_level_info,
                                    unsigned base_level, unsigned first_level,
                                    unsigned block_width, bool is_stencil,
                                    uint32_t *state)
 {
-       uint64_t va;
-       unsigned pitch = base_level_info->nblk_x * block_width;
+       uint64_t va, meta_va = 0;
 
        if (tex->is_depth && !r600_can_sample_zs(tex, is_stencil)) {
                tex = tex->flushed_depth_texture;
                is_stencil = false;
        }
 
-       va = tex->resource.gpu_address + base_level_info->offset;
+       va = tex->resource.gpu_address;
 
-       state[1] &= C_008F14_BASE_ADDRESS_HI;
-       state[3] &= C_008F1C_TILING_INDEX;
-       state[4] &= C_008F20_PITCH;
-       state[6] &= C_008F28_COMPRESSION_EN;
+       if (sscreen->b.chip_class >= GFX9) {
+               /* Only stencil_offset needs to be added here. */
+               if (is_stencil)
+                       va += tex->surface.u.gfx9.stencil_offset;
+               else
+                       va += tex->surface.u.gfx9.surf_offset;
+       } else {
+               va += base_level_info->offset;
+       }
 
        state[0] = va >> 8;
+       state[1] &= C_008F14_BASE_ADDRESS_HI;
        state[1] |= S_008F14_BASE_ADDRESS_HI(va >> 40);
-       state[3] |= S_008F1C_TILING_INDEX(si_tile_mode_index(tex, base_level,
-                                                            is_stencil));
-       state[4] |= S_008F20_PITCH(pitch - 1);
-
-       if (tex->dcc_offset && first_level < tex->surface.num_dcc_levels) {
-               state[6] |= S_008F28_COMPRESSION_EN(1);
-               state[7] = ((!tex->dcc_separate_buffer ? tex->resource.gpu_address : 0) +
-                           tex->dcc_offset +
-                           base_level_info->dcc_offset) >> 8;
-       } else if (tex->tc_compatible_htile) {
-               state[6] |= S_008F28_COMPRESSION_EN(1);
-               state[7] = tex->htile_buffer->gpu_address >> 8;
+
+       if (sscreen->b.chip_class >= VI) {
+               state[6] &= C_008F28_COMPRESSION_EN;
+               state[7] = 0;
+
+               if (vi_dcc_enabled(tex, first_level)) {
+                       meta_va = (!tex->dcc_separate_buffer ? tex->resource.gpu_address : 0) +
+                                 tex->dcc_offset;
+
+                       if (sscreen->b.chip_class <= VI)
+                               meta_va += base_level_info->dcc_offset;
+               } else if (tex->tc_compatible_htile && !is_stencil) {
+                       meta_va = tex->htile_buffer->gpu_address;
+               }
+
+               if (meta_va) {
+                       state[6] |= S_008F28_COMPRESSION_EN(1);
+                       state[7] = meta_va >> 8;
+               }
+       }
+
+       if (sscreen->b.chip_class >= GFX9) {
+               state[3] &= C_008F1C_SW_MODE;
+               state[4] &= C_008F20_PITCH_GFX9;
+
+               if (is_stencil) {
+                       state[3] |= S_008F1C_SW_MODE(tex->surface.u.gfx9.stencil.swizzle_mode);
+                       state[4] |= S_008F20_PITCH_GFX9(tex->surface.u.gfx9.stencil.epitch);
+               } else {
+                       state[3] |= S_008F1C_SW_MODE(tex->surface.u.gfx9.surf.swizzle_mode);
+                       state[4] |= S_008F20_PITCH_GFX9(tex->surface.u.gfx9.surf.epitch);
+               }
+
+               state[5] &= C_008F24_META_DATA_ADDRESS &
+                           C_008F24_META_PIPE_ALIGNED &
+                           C_008F24_META_RB_ALIGNED;
+               if (meta_va) {
+                       struct gfx9_surf_meta_flags meta;
+
+                       if (tex->dcc_offset)
+                               meta = tex->surface.u.gfx9.dcc;
+                       else
+                               meta = tex->surface.u.gfx9.htile;
+
+                       state[5] |= S_008F24_META_DATA_ADDRESS(meta_va >> 40) |
+                                   S_008F24_META_PIPE_ALIGNED(meta.pipe_aligned) |
+                                   S_008F24_META_RB_ALIGNED(meta.rb_aligned);
+               }
+       } else {
+               /* SI-CI-VI */
+               unsigned pitch = base_level_info->nblk_x * block_width;
+               unsigned index = si_tile_mode_index(tex, base_level, is_stencil);
+
+               state[3] &= C_008F1C_TILING_INDEX;
+               state[3] |= S_008F1C_TILING_INDEX(index);
+               state[4] &= C_008F20_PITCH_GFX6;
+               state[4] |= S_008F20_PITCH_GFX6(pitch - 1);
        }
 }
 
@@ -413,19 +475,28 @@ static void si_set_sampler_view(struct si_context *sctx,
        struct si_sampler_views *views = &sctx->samplers[shader].views;
        struct si_sampler_view *rview = (struct si_sampler_view*)view;
        struct si_descriptors *descs = si_sampler_descriptors(sctx, shader);
+       uint32_t *desc = descs->list + slot * 16;
 
        if (views->views[slot] == view && !disallow_early_out)
                return;
 
        if (view) {
                struct r600_texture *rtex = (struct r600_texture *)view->texture;
-               uint32_t *desc = descs->list + slot * 16;
+               bool is_buffer = rtex->resource.b.b.target == PIPE_BUFFER;
+
+               if (unlikely(!is_buffer && rview->dcc_incompatible)) {
+                       if (vi_dcc_enabled(rtex, view->u.tex.first_level))
+                               if (!r600_texture_disable_dcc(&sctx->b, rtex))
+                                       sctx->b.decompress_dcc(&sctx->b.b, rtex);
+
+                       rview->dcc_incompatible = false;
+               }
 
                assert(rtex); /* views with texture == NULL aren't supported */
                pipe_sampler_view_reference(&views->views[slot], view);
                memcpy(desc, rview->state, 8*4);
 
-               if (rtex->resource.b.b.target == PIPE_BUFFER) {
+               if (is_buffer) {
                        rtex->resource.bind_history |= PIPE_BIND_SAMPLER_VIEW;
 
                        si_set_buf_desc_address(&rtex->resource,
@@ -436,7 +507,7 @@ static void si_set_sampler_view(struct si_context *sctx,
                                rtex->db_compatible &&
                                rview->is_stencil_sampler;
 
-                       si_set_mutable_tex_desc_fields(rtex,
+                       si_set_mutable_tex_desc_fields(sctx->screen, rtex,
                                                       rview->base_level_info,
                                                       rview->base_level,
                                                       rview->base.u.tex.first_level,
@@ -445,8 +516,7 @@ static void si_set_sampler_view(struct si_context *sctx,
                                                       desc);
                }
 
-               if (rtex->resource.b.b.target != PIPE_BUFFER &&
-                   rtex->fmask.size) {
+               if (!is_buffer && rtex->fmask.size) {
                        memcpy(desc + 8,
                               rview->fmask_state, 8*4);
                } else {
@@ -456,7 +526,7 @@ static void si_set_sampler_view(struct si_context *sctx,
 
                        if (views->sampler_states[slot])
                                memcpy(desc + 12,
-                                      views->sampler_states[slot], 4*4);
+                                      views->sampler_states[slot]->val, 4*4);
                }
 
                views->enabled_mask |= 1u << slot;
@@ -468,9 +538,14 @@ static void si_set_sampler_view(struct si_context *sctx,
                                           rview->is_stencil_sampler, true);
        } else {
                pipe_sampler_view_reference(&views->views[slot], NULL);
-               memcpy(descs->list + slot*16, null_texture_descriptor, 8*4);
+               memcpy(desc, null_texture_descriptor, 8*4);
                /* Only clear the lower dwords of FMASK. */
-               memcpy(descs->list + slot*16 + 8, null_texture_descriptor, 4*4);
+               memcpy(desc + 8, null_texture_descriptor, 4*4);
+               /* Re-set the sampler state if we are transitioning from FMASK. */
+               if (views->sampler_states[slot])
+                       memcpy(desc + 12,
+                              views->sampler_states[slot]->val, 4*4);
+
                views->enabled_mask &= ~(1u << slot);
        }
 
@@ -480,8 +555,30 @@ static void si_set_sampler_view(struct si_context *sctx,
 
 static bool is_compressed_colortex(struct r600_texture *rtex)
 {
-       return rtex->cmask.size || rtex->fmask.size ||
-              (rtex->dcc_offset && rtex->dirty_level_mask);
+       return rtex->fmask.size ||
+              (rtex->dirty_level_mask &&
+               (rtex->cmask.size || rtex->dcc_offset));
+}
+
+static bool depth_needs_decompression(struct r600_texture *rtex,
+                                     struct si_sampler_view *sview)
+{
+       return rtex->db_compatible &&
+              (!rtex->tc_compatible_htile || sview->is_stencil_sampler);
+}
+
+static void si_update_compressed_tex_shader_mask(struct si_context *sctx,
+                                                unsigned shader)
+{
+       struct si_textures_info *samplers = &sctx->samplers[shader];
+       unsigned shader_bit = 1 << shader;
+
+       if (samplers->depth_texture_mask ||
+           samplers->compressed_colortex_mask ||
+           sctx->images[shader].compressed_colortex_mask)
+               sctx->compressed_tex_shader_mask |= shader_bit;
+       else
+               sctx->compressed_tex_shader_mask &= ~shader_bit;
 }
 
 static void si_set_sampler_views(struct pipe_context *ctx,
@@ -513,8 +610,7 @@ static void si_set_sampler_views(struct pipe_context *ctx,
                                (struct r600_texture*)views[i]->texture;
                        struct si_sampler_view *rview = (struct si_sampler_view *)views[i];
 
-                       if (rtex->db_compatible &&
-                           (!rtex->tc_compatible_htile || rview->is_stencil_sampler)) {
+                       if (depth_needs_decompression(rtex, rview)) {
                                samplers->depth_texture_mask |= 1u << slot;
                        } else {
                                samplers->depth_texture_mask &= ~(1u << slot);
@@ -533,6 +629,8 @@ static void si_set_sampler_views(struct pipe_context *ctx,
                        samplers->compressed_colortex_mask &= ~(1u << slot);
                }
        }
+
+       si_update_compressed_tex_shader_mask(sctx, shader);
 }
 
 static void
@@ -632,7 +730,8 @@ si_mark_image_range_valid(const struct pipe_image_view *view)
 
 static void si_set_shader_image(struct si_context *ctx,
                                unsigned shader,
-                               unsigned slot, const struct pipe_image_view *view)
+                               unsigned slot, const struct pipe_image_view *view,
+                               bool skip_decompress)
 {
        struct si_screen *screen = ctx->screen;
        struct si_images_info *images = &ctx->images[shader];
@@ -657,8 +756,7 @@ static void si_set_shader_image(struct si_context *ctx,
                si_make_buffer_descriptor(screen, res,
                                          view->format,
                                          view->u.buf.offset,
-                                         view->u.buf.size,
-                                         descs->list + slot * 8);
+                                         view->u.buf.size, desc);
                si_set_buf_desc_address(res, view->u.buf.offset, desc + 4);
 
                images->compressed_colortex_mask &= ~(1 << slot);
@@ -667,14 +765,13 @@ static void si_set_shader_image(struct si_context *ctx,
                static const unsigned char swizzle[4] = { 0, 1, 2, 3 };
                struct r600_texture *tex = (struct r600_texture *)res;
                unsigned level = view->u.tex.level;
-               unsigned width, height, depth;
-               bool uses_dcc = tex->dcc_offset &&
-                               level < tex->surface.num_dcc_levels;
+               unsigned width, height, depth, hw_level;
+               bool uses_dcc = vi_dcc_enabled(tex, level);
 
                assert(!tex->is_depth);
                assert(tex->fmask.size == 0);
 
-               if (uses_dcc &&
+               if (uses_dcc && !skip_decompress &&
                    (view->access & PIPE_IMAGE_ACCESS_WRITE ||
                     !vi_dcc_formats_compatible(res->b.b.format, view->format))) {
                        /* If DCC can't be disabled, at least decompress it.
@@ -697,25 +794,37 @@ static void si_set_shader_image(struct si_context *ctx,
                    p_atomic_read(&tex->framebuffers_bound))
                        ctx->need_check_render_feedback = true;
 
-               /* Always force the base level to the selected level.
-                *
-                * This is required for 3D textures, where otherwise
-                * selecting a single slice for non-layered bindings
-                * fails. It doesn't hurt the other targets.
-                */
-               width = u_minify(res->b.b.width0, level);
-               height = u_minify(res->b.b.height0, level);
-               depth = u_minify(res->b.b.depth0, level);
+               if (ctx->b.chip_class >= GFX9) {
+                       /* Always set the base address. The swizzle modes don't
+                        * allow setting mipmap level offsets as the base.
+                        */
+                       width = res->b.b.width0;
+                       height = res->b.b.height0;
+                       depth = res->b.b.depth0;
+                       hw_level = level;
+               } else {
+                       /* Always force the base level to the selected level.
+                        *
+                        * This is required for 3D textures, where otherwise
+                        * selecting a single slice for non-layered bindings
+                        * fails. It doesn't hurt the other targets.
+                        */
+                       width = u_minify(res->b.b.width0, level);
+                       height = u_minify(res->b.b.height0, level);
+                       depth = u_minify(res->b.b.depth0, level);
+                       hw_level = 0;
+               }
 
                si_make_texture_descriptor(screen, tex,
                                           false, res->b.b.target,
                                           view->format, swizzle,
-                                          0, 0,
+                                          hw_level, hw_level,
                                           view->u.tex.first_layer,
                                           view->u.tex.last_layer,
                                           width, height, depth,
                                           desc, NULL);
-               si_set_mutable_tex_desc_fields(tex, &tex->surface.level[level],
+               si_set_mutable_tex_desc_fields(screen, tex,
+                                              &tex->surface.u.legacy.level[level],
                                               level, level,
                                               util_format_get_blockwidth(view->format),
                                               false, desc);
@@ -748,11 +857,13 @@ si_set_shader_images(struct pipe_context *pipe,
 
        if (views) {
                for (i = 0, slot = start_slot; i < count; ++i, ++slot)
-                       si_set_shader_image(ctx, shader, slot, &views[i]);
+                       si_set_shader_image(ctx, shader, slot, &views[i], false);
        } else {
                for (i = 0, slot = start_slot; i < count; ++i, ++slot)
-                       si_set_shader_image(ctx, shader, slot, NULL);
+                       si_set_shader_image(ctx, shader, slot, NULL, false);
        }
+
+       si_update_compressed_tex_shader_mask(ctx, shader);
 }
 
 static void
@@ -798,15 +909,18 @@ static void si_bind_sampler_states(struct pipe_context *ctx,
                    sstates[i] == samplers->views.sampler_states[slot])
                        continue;
 
+#ifdef DEBUG
+               assert(sstates[i]->magic == SI_SAMPLER_STATE_MAGIC);
+#endif
                samplers->views.sampler_states[slot] = sstates[i];
 
                /* If FMASK is bound, don't overwrite it.
                 * The sampler state will be set after FMASK is unbound.
                 */
-               if (samplers->views.views[i] &&
-                   samplers->views.views[i]->texture &&
-                   samplers->views.views[i]->texture->target != PIPE_BUFFER &&
-                   ((struct r600_texture*)samplers->views.views[i]->texture)->fmask.size)
+               if (samplers->views.views[slot] &&
+                   samplers->views.views[slot]->texture &&
+                   samplers->views.views[slot]->texture->target != PIPE_BUFFER &&
+                   ((struct r600_texture*)samplers->views.views[slot]->texture)->fmask.size)
                        continue;
 
                memcpy(desc->list + slot * 16 + 12, sstates[i]->val, 4*4);
@@ -894,11 +1008,11 @@ static void si_vertex_buffers_begin_new_cs(struct si_context *sctx)
 
                if (vb >= ARRAY_SIZE(sctx->vertex_buffer))
                        continue;
-               if (!sctx->vertex_buffer[vb].buffer)
+               if (!sctx->vertex_buffer[vb].buffer.resource)
                        continue;
 
                radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
-                                     (struct r600_resource*)sctx->vertex_buffer[vb].buffer,
+                                     (struct r600_resource*)sctx->vertex_buffer[vb].buffer.resource,
                                      RADEON_USAGE_READ, RADEON_PRIO_VERTEX_BUFFER);
        }
 
@@ -911,22 +1025,33 @@ static void si_vertex_buffers_begin_new_cs(struct si_context *sctx)
 
 bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
 {
+       struct si_vertex_element *velems = sctx->vertex_elements;
        struct si_descriptors *desc = &sctx->vertex_buffers;
-       bool bound[SI_NUM_VERTEX_BUFFERS] = {};
-       unsigned i, count = sctx->vertex_elements->count;
+       unsigned i, count;
+       unsigned desc_list_byte_size;
+       unsigned first_vb_use_mask;
        uint64_t va;
        uint32_t *ptr;
 
-       if (!sctx->vertex_buffers_dirty)
+       if (!sctx->vertex_buffers_dirty || !velems)
                return true;
-       if (!count || !sctx->vertex_elements)
+
+       count = velems->count;
+
+       if (!count)
                return true;
 
+       desc_list_byte_size = velems->desc_list_byte_size;
+       first_vb_use_mask = velems->first_vb_use_mask;
+
        /* Vertex buffer descriptors are the only ones which are uploaded
         * directly through a staging buffer and don't go through
         * the fine-grained upload path.
         */
-       u_upload_alloc(sctx->b.uploader, 0, count * 16, 256, &desc->buffer_offset,
+       u_upload_alloc(sctx->b.b.const_uploader, 0,
+                      desc_list_byte_size,
+                      si_optimal_tcc_alignment(sctx, desc_list_byte_size),
+                      &desc->buffer_offset,
                       (struct pipe_resource**)&desc->buffer, (void**)&ptr);
        if (!desc->buffer)
                return false;
@@ -935,22 +1060,18 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
                              desc->buffer, RADEON_USAGE_READ,
                              RADEON_PRIO_DESCRIPTORS);
 
-       assert(count <= SI_NUM_VERTEX_BUFFERS);
+       assert(count <= SI_MAX_ATTRIBS);
 
        for (i = 0; i < count; i++) {
-               struct pipe_vertex_element *ve = &sctx->vertex_elements->elements[i];
+               struct pipe_vertex_element *ve = &velems->elements[i];
                struct pipe_vertex_buffer *vb;
                struct r600_resource *rbuffer;
                unsigned offset;
+               unsigned vbo_index = ve->vertex_buffer_index;
                uint32_t *desc = &ptr[i*4];
 
-               if (ve->vertex_buffer_index >= ARRAY_SIZE(sctx->vertex_buffer)) {
-                       memset(desc, 0, 16);
-                       continue;
-               }
-
-               vb = &sctx->vertex_buffer[ve->vertex_buffer_index];
-               rbuffer = (struct r600_resource*)vb->buffer;
+               vb = &sctx->vertex_buffer[vbo_index];
+               rbuffer = (struct r600_resource*)vb->buffer.resource;
                if (!rbuffer) {
                        memset(desc, 0, 16);
                        continue;
@@ -964,43 +1085,21 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
                desc[1] = S_008F04_BASE_ADDRESS_HI(va >> 32) |
                          S_008F04_STRIDE(vb->stride);
 
-               if (sctx->b.chip_class <= CIK && vb->stride) {
+               if (sctx->b.chip_class != VI && vb->stride) {
                        /* Round up by rounding down and adding 1 */
-                       desc[2] = (vb->buffer->width0 - offset -
-                                  sctx->vertex_elements->format_size[i]) /
+                       desc[2] = (vb->buffer.resource->width0 - offset -
+                                  velems->format_size[i]) /
                                  vb->stride + 1;
                } else {
-                       uint32_t size3;
-
-                       desc[2] = vb->buffer->width0 - offset;
-
-                       /* For attributes of size 3 with byte or short
-                        * components, we use a 4-component data format.
-                        *
-                        * As a consequence, we have to round the buffer size
-                        * up so that the hardware sees four components as
-                        * being inside the buffer if and only if the first
-                        * three components are in the buffer.
-                        *
-                        * Since the offset and stride are guaranteed to be
-                        * 4-byte aligned, this alignment will never cross the
-                        * winsys buffer boundary.
-                        */
-                       size3 = (sctx->vertex_elements->fix_size3 >> (2 * i)) & 3;
-                       if (vb->stride && size3) {
-                               assert(offset % 4 == 0 && vb->stride % 4 == 0);
-                               assert(size3 <= 2);
-                               desc[2] = align(desc[2], size3 * 2);
-                       }
+                       desc[2] = vb->buffer.resource->width0 - offset;
                }
 
-               desc[3] = sctx->vertex_elements->rsrc_word3[i];
+               desc[3] = velems->rsrc_word3[i];
 
-               if (!bound[ve->vertex_buffer_index]) {
+               if (first_vb_use_mask & (1 << i)) {
                        radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
-                                             (struct r600_resource*)vb->buffer,
+                                             (struct r600_resource*)vb->buffer.resource,
                                              RADEON_USAGE_READ, RADEON_PRIO_VERTEX_BUFFER);
-                       bound[ve->vertex_buffer_index] = true;
                }
        }
 
@@ -1008,9 +1107,11 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
         * on performance (confirmed by testing). New descriptors are always
         * uploaded to a fresh new buffer, so I don't think flushing the const
         * cache is needed. */
-       desc->pointer_dirty = true;
        si_mark_atom_dirty(sctx, &sctx->shader_userdata.atom);
+       if (sctx->b.chip_class >= CIK)
+               si_mark_atom_dirty(sctx, &sctx->prefetch_L2);
        sctx->vertex_buffers_dirty = false;
+       sctx->vertex_buffer_pointer_dirty = true;
        return true;
 }
 
@@ -1035,7 +1136,9 @@ void si_upload_const_buffer(struct si_context *sctx, struct r600_resource **rbuf
 {
        void *tmp;
 
-       u_upload_alloc(sctx->b.uploader, 0, size, 256, const_offset,
+       u_upload_alloc(sctx->b.b.const_uploader, 0, size,
+                      si_optimal_tcc_alignment(sctx, size),
+                      const_offset,
                       (struct pipe_resource**)rbuffer, &tmp);
        if (*rbuffer)
                util_memcpy_cpu_to_le32(tmp, ptr, size);
@@ -1117,7 +1220,7 @@ void si_set_rw_buffer(struct si_context *sctx,
 }
 
 static void si_pipe_set_constant_buffer(struct pipe_context *ctx,
-                                       uint shader, uint slot,
+                                       enum pipe_shader_type shader, uint slot,
                                        const struct pipe_constant_buffer *input)
 {
        struct si_context *sctx = (struct si_context *)ctx;
@@ -1209,10 +1312,14 @@ static void si_set_shader_buffers(struct pipe_context *ctx,
                descs->dirty_mask |= 1u << slot;
                sctx->descriptors_dirty |=
                        1u << si_shader_buffer_descriptors_idx(shader);
+
+               util_range_add(&buf->valid_buffer_range, sbuffer->buffer_offset,
+                              sbuffer->buffer_offset + sbuffer->buffer_size);
        }
 }
 
-void si_get_shader_buffers(struct si_context *sctx, uint shader,
+void si_get_shader_buffers(struct si_context *sctx,
+                          enum pipe_shader_type shader,
                           uint start_slot, uint count,
                           struct pipe_shader_buffer *sbuf)
 {
@@ -1302,10 +1409,14 @@ void si_set_ring_buffer(struct pipe_context *ctx, uint slot,
                          S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W) |
                          S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT) |
                          S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32) |
-                         S_008F0C_ELEMENT_SIZE(element_size) |
                          S_008F0C_INDEX_STRIDE(index_stride) |
                          S_008F0C_ADD_TID_ENABLE(add_tid);
 
+               if (sctx->b.chip_class >= GFX9)
+                       assert(!swizzle || element_size == 1); /* always 4 bytes on GFX9 */
+               else
+                       desc[3] |= S_008F0C_ELEMENT_SIZE(element_size);
+
                pipe_resource_reference(&buffers->buffers[slot], buffer);
                radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
                                      (struct r600_resource*)buffer,
@@ -1482,6 +1593,7 @@ void si_update_compressed_colortex_masks(struct si_context *sctx)
        for (int i = 0; i < SI_NUM_SHADERS; ++i) {
                si_samplers_update_compressed_colortex_mask(&sctx->samplers[i]);
                si_images_update_compressed_colortex_mask(&sctx->images[i]);
+               si_update_compressed_tex_shader_mask(sctx, i);
        }
 }
 
@@ -1514,25 +1626,15 @@ static void si_reset_buffer_resources(struct si_context *sctx,
        }
 }
 
-/* Reallocate a buffer a update all resource bindings where the buffer is
- * bound.
- *
- * This is used to avoid CPU-GPU synchronizations, because it makes the buffer
- * idle by discarding its contents. Apps usually tell us when to do this using
- * map_buffer flags, for example.
- */
-static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf)
+static void si_rebind_buffer(struct pipe_context *ctx, struct pipe_resource *buf,
+                            uint64_t old_va)
 {
        struct si_context *sctx = (struct si_context*)ctx;
        struct r600_resource *rbuffer = r600_resource(buf);
        unsigned i, shader;
-       uint64_t old_va = rbuffer->gpu_address;
        unsigned num_elems = sctx->vertex_elements ?
                                       sctx->vertex_elements->count : 0;
 
-       /* Reallocate the buffer in the same pipe_resource. */
-       r600_alloc_resource(&sctx->screen->b, rbuffer);
-
        /* We changed the buffer, now we need to bind it where the old one
         * was bound. This consists of 2 things:
         *   1) Updating the resource descriptor and dirtying it.
@@ -1546,10 +1648,10 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
 
                        if (vb >= ARRAY_SIZE(sctx->vertex_buffer))
                                continue;
-                       if (!sctx->vertex_buffer[vb].buffer)
+                       if (!sctx->vertex_buffer[vb].buffer.resource)
                                continue;
 
-                       if (sctx->vertex_buffer[vb].buffer == buf) {
+                       if (sctx->vertex_buffer[vb].buffer.resource == buf) {
                                sctx->vertex_buffers_dirty = true;
                                break;
                        }
@@ -1660,6 +1762,25 @@ static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource
        }
 }
 
+/* Reallocate a buffer a update all resource bindings where the buffer is
+ * bound.
+ *
+ * This is used to avoid CPU-GPU synchronizations, because it makes the buffer
+ * idle by discarding its contents. Apps usually tell us when to do this using
+ * map_buffer flags, for example.
+ */
+static void si_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf)
+{
+       struct si_context *sctx = (struct si_context*)ctx;
+       struct r600_resource *rbuffer = r600_resource(buf);
+       uint64_t old_va = rbuffer->gpu_address;
+
+       /* Reallocate the buffer in the same pipe_resource. */
+       r600_alloc_resource(&sctx->screen->b, rbuffer);
+
+       si_rebind_buffer(ctx, buf, old_va);
+}
+
 /* Update mutable image descriptor fields of all bound textures. */
 void si_update_all_texture_descriptors(struct si_context *sctx)
 {
@@ -1680,7 +1801,7 @@ void si_update_all_texture_descriptors(struct si_context *sctx)
                            view->resource->target == PIPE_BUFFER)
                                continue;
 
-                       si_set_shader_image(sctx, shader, i, view);
+                       si_set_shader_image(sctx, shader, i, view, true);
                }
 
                /* Sampler views. */
@@ -1697,6 +1818,8 @@ void si_update_all_texture_descriptors(struct si_context *sctx)
                        si_set_sampler_view(sctx, shader, i,
                                            samplers->views[i], true);
                }
+
+               si_update_compressed_tex_shader_mask(sctx, shader);
        }
 }
 
@@ -1705,26 +1828,21 @@ void si_update_all_texture_descriptors(struct si_context *sctx)
 static void si_mark_shader_pointers_dirty(struct si_context *sctx,
                                          unsigned shader)
 {
-       struct si_descriptors *descs =
-               &sctx->descriptors[SI_DESCS_FIRST_SHADER + shader * SI_NUM_SHADER_DESCS];
-
-       for (unsigned i = 0; i < SI_NUM_SHADER_DESCS; ++i, ++descs)
-               descs->pointer_dirty = true;
+       sctx->shader_pointers_dirty |=
+               u_bit_consecutive(SI_DESCS_FIRST_SHADER + shader * SI_NUM_SHADER_DESCS,
+                                 SI_NUM_SHADER_DESCS);
 
        if (shader == PIPE_SHADER_VERTEX)
-               sctx->vertex_buffers.pointer_dirty = true;
+               sctx->vertex_buffer_pointer_dirty = sctx->vertex_buffers.buffer != NULL;
 
        si_mark_atom_dirty(sctx, &sctx->shader_userdata.atom);
 }
 
 static void si_shader_userdata_begin_new_cs(struct si_context *sctx)
 {
-       int i;
-
-       for (i = 0; i < SI_NUM_SHADERS; i++) {
-               si_mark_shader_pointers_dirty(sctx, i);
-       }
-       sctx->descriptors[SI_DESCS_RW_BUFFERS].pointer_dirty = true;
+       sctx->shader_pointers_dirty = u_bit_consecutive(0, SI_NUM_DESCS);
+       sctx->vertex_buffer_pointer_dirty = sctx->vertex_buffers.buffer != NULL;
+       si_mark_atom_dirty(sctx, &sctx->shader_userdata.atom);
 }
 
 /* Set a base register address for user data constants in the given shader.
@@ -1738,8 +1856,12 @@ static void si_set_user_data_base(struct si_context *sctx,
        if (*base != new_base) {
                *base = new_base;
 
-               if (new_base)
+               if (new_base) {
                        si_mark_shader_pointers_dirty(sctx, shader);
+
+                       if (shader == PIPE_SHADER_VERTEX)
+                               sctx->last_vs_state = ~0;
+               }
        }
 }
 
@@ -1752,15 +1874,21 @@ static void si_set_user_data_base(struct si_context *sctx,
 void si_shader_change_notify(struct si_context *sctx)
 {
        /* VS can be bound as VS, ES, or LS. */
-       if (sctx->tes_shader.cso)
-               si_set_user_data_base(sctx, PIPE_SHADER_VERTEX,
-                                     R_00B530_SPI_SHADER_USER_DATA_LS_0);
-       else if (sctx->gs_shader.cso)
+       if (sctx->tes_shader.cso) {
+               if (sctx->b.chip_class >= GFX9) {
+                       si_set_user_data_base(sctx, PIPE_SHADER_VERTEX,
+                                             R_00B430_SPI_SHADER_USER_DATA_LS_0);
+               } else {
+                       si_set_user_data_base(sctx, PIPE_SHADER_VERTEX,
+                                             R_00B530_SPI_SHADER_USER_DATA_LS_0);
+               }
+       } else if (sctx->gs_shader.cso) {
                si_set_user_data_base(sctx, PIPE_SHADER_VERTEX,
                                      R_00B330_SPI_SHADER_USER_DATA_ES_0);
-       else
+       } else {
                si_set_user_data_base(sctx, PIPE_SHADER_VERTEX,
                                      R_00B130_SPI_SHADER_USER_DATA_VS_0);
+       }
 
        /* TES can be bound as ES, VS, or not bound. */
        if (sctx->tes_shader.cso) {
@@ -1777,13 +1905,12 @@ void si_shader_change_notify(struct si_context *sctx)
 
 static void si_emit_shader_pointer(struct si_context *sctx,
                                   struct si_descriptors *desc,
-                                  unsigned sh_base, bool keep_dirty)
+                                  unsigned sh_base)
 {
        struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
        uint64_t va;
 
-       if (!desc->pointer_dirty || !desc->buffer)
-               return;
+       assert(desc->buffer);
 
        va = desc->buffer->gpu_address +
             desc->buffer_offset;
@@ -1792,55 +1919,78 @@ static void si_emit_shader_pointer(struct si_context *sctx,
        radeon_emit(cs, (sh_base + desc->shader_userdata_offset - SI_SH_REG_OFFSET) >> 2);
        radeon_emit(cs, va);
        radeon_emit(cs, va >> 32);
-
-       desc->pointer_dirty = keep_dirty;
 }
 
 void si_emit_graphics_shader_userdata(struct si_context *sctx,
                                       struct r600_atom *atom)
 {
-       unsigned shader;
+       unsigned mask;
        uint32_t *sh_base = sctx->shader_userdata.sh_base;
        struct si_descriptors *descs;
 
        descs = &sctx->descriptors[SI_DESCS_RW_BUFFERS];
 
-       if (descs->pointer_dirty) {
-               si_emit_shader_pointer(sctx, descs,
-                                      R_00B030_SPI_SHADER_USER_DATA_PS_0, true);
-               si_emit_shader_pointer(sctx, descs,
-                                      R_00B130_SPI_SHADER_USER_DATA_VS_0, true);
+       if (sctx->shader_pointers_dirty & (1 << SI_DESCS_RW_BUFFERS)) {
                si_emit_shader_pointer(sctx, descs,
-                                      R_00B230_SPI_SHADER_USER_DATA_GS_0, true);
+                                      R_00B030_SPI_SHADER_USER_DATA_PS_0);
                si_emit_shader_pointer(sctx, descs,
-                                      R_00B330_SPI_SHADER_USER_DATA_ES_0, true);
-               si_emit_shader_pointer(sctx, descs,
-                                      R_00B430_SPI_SHADER_USER_DATA_HS_0, true);
-               descs->pointer_dirty = false;
+                                      R_00B130_SPI_SHADER_USER_DATA_VS_0);
+
+               if (sctx->b.chip_class >= GFX9) {
+                       /* GFX9 merged LS-HS and ES-GS.
+                        * Set RW_BUFFERS in the special registers, so that
+                        * it's preloaded into s[0:1] instead of s[8:9].
+                        */
+                       si_emit_shader_pointer(sctx, descs,
+                                              R_00B208_SPI_SHADER_USER_DATA_ADDR_LO_GS);
+                       si_emit_shader_pointer(sctx, descs,
+                                              R_00B408_SPI_SHADER_USER_DATA_ADDR_LO_HS);
+               } else {
+                       si_emit_shader_pointer(sctx, descs,
+                                              R_00B230_SPI_SHADER_USER_DATA_GS_0);
+                       si_emit_shader_pointer(sctx, descs,
+                                              R_00B330_SPI_SHADER_USER_DATA_ES_0);
+                       si_emit_shader_pointer(sctx, descs,
+                                              R_00B430_SPI_SHADER_USER_DATA_HS_0);
+               }
        }
 
-       descs = &sctx->descriptors[SI_DESCS_FIRST_SHADER];
+       mask = sctx->shader_pointers_dirty &
+              u_bit_consecutive(SI_DESCS_FIRST_SHADER,
+                                SI_DESCS_FIRST_COMPUTE - SI_DESCS_FIRST_SHADER);
 
-       for (shader = 0; shader < SI_NUM_GRAPHICS_SHADERS; shader++) {
+       while (mask) {
+               unsigned i = u_bit_scan(&mask);
+               unsigned shader = (i - SI_DESCS_FIRST_SHADER) / SI_NUM_SHADER_DESCS;
                unsigned base = sh_base[shader];
-               unsigned i;
 
-               if (!base)
-                       continue;
+               if (base)
+                       si_emit_shader_pointer(sctx, descs + i, base);
+       }
+       sctx->shader_pointers_dirty &=
+               ~u_bit_consecutive(SI_DESCS_RW_BUFFERS, SI_DESCS_FIRST_COMPUTE);
 
-               for (i = 0; i < SI_NUM_SHADER_DESCS; i++, descs++)
-                       si_emit_shader_pointer(sctx, descs, base, false);
+       if (sctx->vertex_buffer_pointer_dirty) {
+               si_emit_shader_pointer(sctx, &sctx->vertex_buffers,
+                                      sh_base[PIPE_SHADER_VERTEX]);
+               sctx->vertex_buffer_pointer_dirty = false;
        }
-       si_emit_shader_pointer(sctx, &sctx->vertex_buffers, sh_base[PIPE_SHADER_VERTEX], false);
 }
 
 void si_emit_compute_shader_userdata(struct si_context *sctx)
 {
        unsigned base = R_00B900_COMPUTE_USER_DATA_0;
-       struct si_descriptors *descs = &sctx->descriptors[SI_DESCS_FIRST_COMPUTE];
+       struct si_descriptors *descs = sctx->descriptors;
+       unsigned compute_mask =
+               u_bit_consecutive(SI_DESCS_FIRST_COMPUTE, SI_NUM_SHADER_DESCS);
+       unsigned mask = sctx->shader_pointers_dirty & compute_mask;
 
-       for (unsigned i = 0; i < SI_NUM_SHADER_DESCS; ++i, ++descs)
-               si_emit_shader_pointer(sctx, descs, base, false);
+       while (mask) {
+               unsigned i = u_bit_scan(&mask);
+
+               si_emit_shader_pointer(sctx, descs + i, base);
+       }
+       sctx->shader_pointers_dirty &= ~compute_mask;
 }
 
 /* INIT/DEINIT/UPLOAD */
@@ -1850,25 +2000,56 @@ void si_init_all_descriptors(struct si_context *sctx)
        int i;
        unsigned ce_offset = 0;
 
+       STATIC_ASSERT(GFX9_SGPR_TCS_CONST_BUFFERS % 2 == 0);
+       STATIC_ASSERT(GFX9_SGPR_GS_CONST_BUFFERS % 2 == 0);
+
        for (i = 0; i < SI_NUM_SHADERS; i++) {
+               bool gfx9_tcs = sctx->b.chip_class == GFX9 &&
+                               i == PIPE_SHADER_TESS_CTRL;
+               bool gfx9_gs = sctx->b.chip_class == GFX9 &&
+                              i == PIPE_SHADER_GEOMETRY;
+               /* GFX9 has only 4KB of CE, while previous chips had 32KB.
+                * Rarely used descriptors don't use CE RAM.
+                */
+               bool big_ce = sctx->b.chip_class <= VI;
+               bool images_use_ce = big_ce;
+               bool shaderbufs_use_ce = big_ce ||
+                                        i == PIPE_SHADER_COMPUTE;
+               bool samplers_use_ce = big_ce ||
+                                      i == PIPE_SHADER_FRAGMENT;
+
                si_init_buffer_resources(&sctx->const_buffers[i],
                                         si_const_buffer_descriptors(sctx, i),
-                                        SI_NUM_CONST_BUFFERS, SI_SGPR_CONST_BUFFERS,
+                                        SI_NUM_CONST_BUFFERS,
+                                        gfx9_tcs ? GFX9_SGPR_TCS_CONST_BUFFERS :
+                                        gfx9_gs ? GFX9_SGPR_GS_CONST_BUFFERS :
+                                                  SI_SGPR_CONST_BUFFERS,
                                         RADEON_USAGE_READ, RADEON_PRIO_CONST_BUFFER,
                                         &ce_offset);
                si_init_buffer_resources(&sctx->shader_buffers[i],
                                         si_shader_buffer_descriptors(sctx, i),
-                                        SI_NUM_SHADER_BUFFERS, SI_SGPR_SHADER_BUFFERS,
+                                        SI_NUM_SHADER_BUFFERS,
+                                        gfx9_tcs ? GFX9_SGPR_TCS_SHADER_BUFFERS :
+                                        gfx9_gs ? GFX9_SGPR_GS_SHADER_BUFFERS :
+                                                  SI_SGPR_SHADER_BUFFERS,
                                         RADEON_USAGE_READWRITE, RADEON_PRIO_SHADER_RW_BUFFER,
-                                        &ce_offset);
+                                        shaderbufs_use_ce ? &ce_offset : NULL);
 
                si_init_descriptors(si_sampler_descriptors(sctx, i),
-                                   SI_SGPR_SAMPLERS, 16, SI_NUM_SAMPLERS,
-                                   null_texture_descriptor, &ce_offset);
+                                   gfx9_tcs ? GFX9_SGPR_TCS_SAMPLERS :
+                                   gfx9_gs ? GFX9_SGPR_GS_SAMPLERS :
+                                             SI_SGPR_SAMPLERS,
+                                   16, SI_NUM_SAMPLERS,
+                                   null_texture_descriptor,
+                                   samplers_use_ce ? &ce_offset : NULL);
 
                si_init_descriptors(si_image_descriptors(sctx, i),
-                                   SI_SGPR_IMAGES, 8, SI_NUM_IMAGES,
-                                   null_image_descriptor, &ce_offset);
+                                   gfx9_tcs ? GFX9_SGPR_TCS_IMAGES :
+                                   gfx9_gs ? GFX9_SGPR_GS_IMAGES :
+                                             SI_SGPR_IMAGES,
+                                   8, SI_NUM_IMAGES,
+                                   null_image_descriptor,
+                                   images_use_ce ? &ce_offset : NULL);
        }
 
        si_init_buffer_resources(&sctx->rw_buffers,
@@ -1881,7 +2062,10 @@ void si_init_all_descriptors(struct si_context *sctx)
 
        sctx->descriptors_dirty = u_bit_consecutive(0, SI_NUM_DESCS);
 
-       assert(ce_offset <= 32768);
+       if (sctx->b.chip_class >= GFX9)
+               assert(ce_offset <= 4096);
+       else
+               assert(ce_offset <= 32768);
 
        /* Set pipe_context functions. */
        sctx->b.b.bind_sampler_states = si_bind_sampler_states;
@@ -1892,6 +2076,7 @@ void si_init_all_descriptors(struct si_context *sctx)
        sctx->b.b.set_sampler_views = si_set_sampler_views;
        sctx->b.b.set_stream_output_targets = si_set_streamout_targets;
        sctx->b.invalidate_buffer = si_invalidate_buffer;
+       sctx->b.rebind_buffer = si_rebind_buffer;
 
        /* Shader user data. */
        si_init_atom(sctx, &sctx->shader_userdata.atom, &sctx->atoms.s.shader_userdata,
@@ -1899,8 +2084,18 @@ void si_init_all_descriptors(struct si_context *sctx)
 
        /* Set default and immutable mappings. */
        si_set_user_data_base(sctx, PIPE_SHADER_VERTEX, R_00B130_SPI_SHADER_USER_DATA_VS_0);
-       si_set_user_data_base(sctx, PIPE_SHADER_TESS_CTRL, R_00B430_SPI_SHADER_USER_DATA_HS_0);
-       si_set_user_data_base(sctx, PIPE_SHADER_GEOMETRY, R_00B230_SPI_SHADER_USER_DATA_GS_0);
+
+       if (sctx->b.chip_class >= GFX9) {
+               si_set_user_data_base(sctx, PIPE_SHADER_TESS_CTRL,
+                                     R_00B430_SPI_SHADER_USER_DATA_LS_0);
+               si_set_user_data_base(sctx, PIPE_SHADER_GEOMETRY,
+                                     R_00B330_SPI_SHADER_USER_DATA_ES_0);
+       } else {
+               si_set_user_data_base(sctx, PIPE_SHADER_TESS_CTRL,
+                                     R_00B430_SPI_SHADER_USER_DATA_HS_0);
+               si_set_user_data_base(sctx, PIPE_SHADER_GEOMETRY,
+                                     R_00B230_SPI_SHADER_USER_DATA_GS_0);
+       }
        si_set_user_data_base(sctx, PIPE_SHADER_FRAGMENT, R_00B030_SPI_SHADER_USER_DATA_PS_0);
 }
 
@@ -1909,6 +2104,9 @@ bool si_upload_graphics_shader_descriptors(struct si_context *sctx)
        const unsigned mask = u_bit_consecutive(0, SI_DESCS_FIRST_COMPUTE);
        unsigned dirty = sctx->descriptors_dirty & mask;
 
+       /* Assume nothing will go wrong: */
+       sctx->shader_pointers_dirty |= dirty;
+
        while (dirty) {
                unsigned i = u_bit_scan(&dirty);
 
@@ -1930,6 +2128,9 @@ bool si_upload_compute_shader_descriptors(struct si_context *sctx)
                                                SI_NUM_DESCS - SI_DESCS_FIRST_COMPUTE);
        unsigned dirty = sctx->descriptors_dirty & mask;
 
+       /* Assume nothing will go wrong: */
+       sctx->shader_pointers_dirty |= dirty;
+
        while (dirty) {
                unsigned i = u_bit_scan(&dirty);