gallium/radeon: add can_sample_z/s flags for textures
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 29 Jun 2016 19:56:42 +0000 (21:56 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 6 Jul 2016 08:43:43 +0000 (10:43 +0200)
v2: adjust r600_init_color_surface as well

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/r600_texture.c

index edf9726..6e5675b 100644 (file)
@@ -277,8 +277,7 @@ void r600_decompress_depth_textures(struct r600_context *rctx,
                tex = (struct r600_texture *)view->texture;
                assert(tex->is_depth && !tex->is_flushing_texture);
 
-               if (rctx->b.chip_class >= EVERGREEN ||
-                   r600_can_read_depth(tex)) {
+               if (r600_can_sample_zs(tex, rview->is_stencil_sampler)) {
                        r600_blit_decompress_depth_in_place(rctx, tex,
                                                   rview->is_stencil_sampler,
                                                   view->u.tex.first_level, view->u.tex.last_level,
@@ -374,8 +373,7 @@ static bool r600_decompress_subresource(struct pipe_context *ctx,
        struct r600_texture *rtex = (struct r600_texture*)tex;
 
        if (rtex->is_depth && !rtex->is_flushing_texture) {
-               if (rctx->b.chip_class >= EVERGREEN ||
-                   r600_can_read_depth(rtex)) {
+               if (r600_can_sample_zs(rtex, false)) {
                        r600_blit_decompress_depth_in_place(rctx, rtex, false,
                                                   level, level,
                                                   first_layer, last_layer);
index 0dd538b..e1b2aed 100644 (file)
@@ -926,14 +926,6 @@ static inline unsigned r600_pack_float_12p4(float x)
               x >= 4096 ? 0xffff : x * 16;
 }
 
-/* Return if the depth format can be read without the DB->CB copy on r6xx-r7xx. */
-static inline bool r600_can_read_depth(struct r600_texture *rtex)
-{
-       return rtex->resource.b.b.nr_samples <= 1 &&
-              (rtex->resource.b.b.format == PIPE_FORMAT_Z16_UNORM ||
-               rtex->resource.b.b.format == PIPE_FORMAT_Z32_FLOAT);
-}
-
 static inline unsigned r600_get_flush_flags(enum r600_coherency coher)
 {
        switch (coher) {
index e805d33..ea551be 100644 (file)
@@ -706,7 +706,13 @@ r600_create_sampler_view_custom(struct pipe_context *ctx,
                return NULL;
        }
 
-       if (tmp->is_depth && !tmp->is_flushing_texture && !r600_can_read_depth(tmp)) {
+       if (state->format == PIPE_FORMAT_X24S8_UINT ||
+           state->format == PIPE_FORMAT_S8X24_UINT ||
+           state->format == PIPE_FORMAT_X32_S8X24_UINT ||
+           state->format == PIPE_FORMAT_S8_UINT)
+               view->is_stencil_sampler = true;
+
+       if (tmp->is_depth && !r600_can_sample_zs(tmp, view->is_stencil_sampler)) {
                if (!r600_init_flushed_depth_texture(ctx, texture, NULL)) {
                        FREE(view);
                        return NULL;
@@ -744,12 +750,6 @@ r600_create_sampler_view_custom(struct pipe_context *ctx,
                break;
        }
 
-       if (state->format == PIPE_FORMAT_X24S8_UINT ||
-           state->format == PIPE_FORMAT_S8X24_UINT ||
-           state->format == PIPE_FORMAT_X32_S8X24_UINT ||
-           state->format == PIPE_FORMAT_S8_UINT)
-               view->is_stencil_sampler = true;
-
        view->tex_resource = &tmp->resource;
        view->tex_resource_words[0] = (S_038000_DIM(r600_tex_dim(texture->target, texture->nr_samples)) |
                                       S_038000_TILE_MODE(array_mode) |
@@ -842,7 +842,7 @@ static void r600_init_color_surface(struct r600_context *rctx,
        int i;
        bool blend_bypass = 0, blend_clamp = 1, do_endian_swap = FALSE;
 
-       if (rtex->is_depth && !rtex->is_flushing_texture && !r600_can_read_depth(rtex)) {
+       if (rtex->is_depth && !rtex->is_flushing_texture && !r600_can_sample_zs(rtex, false)) {
                r600_init_flushed_depth_texture(&rctx->b.b, surf->base.texture, NULL);
                rtex = rtex->flushed_depth_texture;
                assert(rtex);
index 1ad69f8..1840640 100644 (file)
@@ -242,6 +242,8 @@ struct r600_texture {
        uint64_t                        size;
        unsigned                        num_level0_transfers;
        bool                            is_depth;
+       bool                            can_sample_z;
+       bool                            can_sample_s;
        unsigned                        dirty_level_mask; /* each bit says if that mipmap is compressed */
        unsigned                        stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */
        struct r600_texture             *flushed_depth_texture;
@@ -872,6 +874,13 @@ r600_get_sampler_view_priority(struct r600_resource *res)
        return RADEON_PRIO_SAMPLER_TEXTURE;
 }
 
+static inline bool
+r600_can_sample_zs(struct r600_texture *tex, bool stencil_sampler)
+{
+       return (stencil_sampler && tex->can_sample_s) ||
+              (!stencil_sampler && tex->can_sample_z);
+}
+
 #define COMPUTE_DBG(rscreen, fmt, args...) \
        do { \
                if ((rscreen->b.debug_flags & DBG_COMPUTE)) fprintf(stderr, fmt, ##args); \
index 614dd0e..6b88fc1 100644 (file)
@@ -1027,11 +1027,22 @@ r600_texture_create_object(struct pipe_screen *screen,
        rtex->ps_draw_ratio = 0;
 
        if (rtex->is_depth) {
-               if (!(base->flags & (R600_RESOURCE_FLAG_TRANSFER |
-                                    R600_RESOURCE_FLAG_FLUSHED_DEPTH)) &&
-                   !(rscreen->debug_flags & DBG_NO_HYPERZ)) {
+               if (base->flags & (R600_RESOURCE_FLAG_TRANSFER |
+                                  R600_RESOURCE_FLAG_FLUSHED_DEPTH) ||
+                   rscreen->chip_class >= EVERGREEN) {
+                       rtex->can_sample_z = true;
+                       rtex->can_sample_s = true;
+               } else {
+                       if (rtex->resource.b.b.nr_samples <= 1 &&
+                           (rtex->resource.b.b.format == PIPE_FORMAT_Z16_UNORM ||
+                            rtex->resource.b.b.format == PIPE_FORMAT_Z32_FLOAT))
+                               rtex->can_sample_z = true;
+               }
 
-                       r600_texture_allocate_htile(rscreen, rtex);
+               if (!(base->flags & (R600_RESOURCE_FLAG_TRANSFER |
+                                    R600_RESOURCE_FLAG_FLUSHED_DEPTH))) {
+                       if (!(rscreen->debug_flags & DBG_NO_HYPERZ))
+                               r600_texture_allocate_htile(rscreen, rtex);
                }
        } else {
                if (base->nr_samples > 1) {