r600g/radeonsi: send endian info to format translation functions
authorOded Gabbay <oded.gabbay@gmail.com>
Mon, 21 Mar 2016 21:46:15 +0000 (23:46 +0200)
committerOded Gabbay <oded.gabbay@gmail.com>
Tue, 26 Apr 2016 08:00:16 +0000 (11:00 +0300)
Because r600 GPUs can't do swap in their DB unit, we need to disable
endianess swapping for textures that are handled by DB.

There are four format translation functions in r600g driver:

- r600_translate_texformat
- r600_colorformat_endian_swap
- r600_translate_colorformat
- r600_translate_colorswap

This patch adds a new parameters to those functions, called
"do_endian_swap". When running in a big-endian machine, the calling
functions will check whether the texture/color is handled by DB -
"rtex->is_depth && !rtex->is_flushing_texture" - and if so, they will
send FALSE through this parameter. Otherwise, they will send TRUE.

The translation functions, in specific cases, will look at this parameter
and configure the swapping accordingly.

v4:
evergreen_init_color_surface_rat() is only used by compute and don't
handle DB surfaces, so just sent hard-coded FALSE to translation
functions when called by it.

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
Cc: "11.1 11.2" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_common.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/r600_texture.c
src/gallium/drivers/radeonsi/si_state.c

index 81feb2931222e40c775b1159efc0cc124ef731e9..eec567c7150e7f9a05b4273fe5a26229b76bb94b 100644 (file)
@@ -213,13 +213,14 @@ static uint32_t r600_translate_dbformat(enum pipe_format format)
 
 static bool r600_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format)
 {
-       return r600_translate_texformat(screen, format, NULL, NULL, NULL) != ~0U;
+       return r600_translate_texformat(screen, format, NULL, NULL, NULL,
+                                   FALSE) != ~0U;
 }
 
 static bool r600_is_colorbuffer_format_supported(enum chip_class chip, enum pipe_format format)
 {
-       return r600_translate_colorformat(chip, format) != ~0U &&
-               r600_translate_colorswap(format) != ~0U;
+       return r600_translate_colorformat(chip, format, FALSE) != ~0U &&
+               r600_translate_colorswap(format, FALSE) != ~0U;
 }
 
 static bool r600_is_zs_format_supported(enum pipe_format format)
@@ -677,6 +678,7 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
        unsigned base_level, first_level, last_level;
        unsigned dim, last_layer;
        uint64_t va;
+       bool do_endian_swap = FALSE;
 
        if (!view)
                return NULL;
@@ -722,16 +724,19 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
                }
        }
 
+       if (R600_BIG_ENDIAN)
+               do_endian_swap = !(tmp->is_depth && !tmp->is_flushing_texture);
+
        format = r600_translate_texformat(ctx->screen, pipe_format,
                                          swizzle,
-                                         &word4, &yuv_format);
+                                         &word4, &yuv_format, do_endian_swap);
        assert(format != ~0);
        if (format == ~0) {
                FREE(view);
                return NULL;
        }
 
-       endian = r600_colorformat_endian_swap(format);
+       endian = r600_colorformat_endian_swap(format, do_endian_swap);
 
        base_level = 0;
        first_level = state->u.tex.first_level;
@@ -943,9 +948,9 @@ void evergreen_init_color_surface_rat(struct r600_context *rctx,
 {
        struct pipe_resource *pipe_buffer = surf->base.texture;
        unsigned format = r600_translate_colorformat(rctx->b.chip_class,
-                                                    surf->base.format);
-       unsigned endian = r600_colorformat_endian_swap(format);
-       unsigned swap = r600_translate_colorswap(surf->base.format);
+                                                    surf->base.format, FALSE);
+       unsigned endian = r600_colorformat_endian_swap(format, FALSE);
+       unsigned swap = r600_translate_colorswap(surf->base.format, FALSE);
        unsigned block_size =
                align(util_format_get_blocksize(pipe_buffer->format), 4);
        unsigned pitch_alignment =
@@ -998,7 +1003,7 @@ void evergreen_init_color_surface(struct r600_context *rctx,
        unsigned non_disp_tiling, macro_aspect, tile_split, bankh, bankw, fmask_bankh, nbanks;
        const struct util_format_description *desc;
        int i;
-       bool blend_clamp = 0, blend_bypass = 0;
+       bool blend_clamp = 0, blend_bypass = 0, do_endian_swap = FALSE;
 
        offset = rtex->surface.level[level].offset;
        if (rtex->surface.level[level].mode == RADEON_SURF_MODE_LINEAR) {
@@ -1096,13 +1101,17 @@ void evergreen_init_color_surface(struct r600_context *rctx,
                        ntype = V_028C70_NUMBER_UINT;
        }
 
-       format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format);
+       if (R600_BIG_ENDIAN)
+               do_endian_swap = !(rtex->is_depth && !rtex->is_flushing_texture);
+
+       format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format,
+                                                     do_endian_swap);
        assert(format != ~0);
 
-       swap = r600_translate_colorswap(surf->base.format);
+       swap = r600_translate_colorswap(surf->base.format, do_endian_swap);
        assert(swap != ~0);
 
-       endian = r600_colorformat_endian_swap(format);
+       endian = r600_colorformat_endian_swap(format, do_endian_swap);
 
        /* blend clamp should be set for all NORM/SRGB types */
        if (ntype == V_028C70_NUMBER_UNORM || ntype == V_028C70_NUMBER_SNORM ||
index 4d16223eba02e5b3566e963c69640851f9e8da9d..afd046edd805c19525938d6fbd58b1b08a5bde4e 100644 (file)
@@ -734,9 +734,11 @@ unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
                                   boolean vtx);
 uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
                                  const unsigned char *swizzle_view,
-                                 uint32_t *word4_p, uint32_t *yuv_format_p);
-uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format);
-uint32_t r600_colorformat_endian_swap(uint32_t colorformat);
+                                 uint32_t *word4_p, uint32_t *yuv_format_p,
+                                 bool do_endian_swap);
+uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format,
+                                 bool do_endian_swap);
+uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap);
 
 /* r600_uvd.c */
 struct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context,
index 91e747fa937a0c5d59cd7bd74bb146b95b7ccc74..75a43639053c74ac791f67a9515ddb25a5aaa34e 100644 (file)
@@ -143,13 +143,14 @@ static uint32_t r600_translate_dbformat(enum pipe_format format)
 
 static bool r600_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format)
 {
-       return r600_translate_texformat(screen, format, NULL, NULL, NULL) != ~0U;
+       return r600_translate_texformat(screen, format, NULL, NULL, NULL,
+                                   FALSE) != ~0U;
 }
 
 static bool r600_is_colorbuffer_format_supported(enum chip_class chip, enum pipe_format format)
 {
-       return r600_translate_colorformat(chip, format) != ~0U &&
-              r600_translate_colorswap(format) != ~0U;
+       return r600_translate_colorformat(chip, format, FALSE) != ~0U &&
+              r600_translate_colorswap(format, FALSE) != ~0U;
 }
 
 static bool r600_is_zs_format_supported(enum pipe_format format)
@@ -659,6 +660,7 @@ r600_create_sampler_view_custom(struct pipe_context *ctx,
        uint32_t word4 = 0, yuv_format = 0, pitch = 0;
        unsigned char swizzle[4], array_mode = 0;
        unsigned width, height, depth, offset_level, last_level;
+       bool do_endian_swap = FALSE;
 
        if (!view)
                return NULL;
@@ -679,9 +681,12 @@ r600_create_sampler_view_custom(struct pipe_context *ctx,
        swizzle[2] = state->swizzle_b;
        swizzle[3] = state->swizzle_a;
 
+       if (R600_BIG_ENDIAN)
+               do_endian_swap = !(tmp->is_depth && !tmp->is_flushing_texture);
+
        format = r600_translate_texformat(ctx->screen, state->format,
                                          swizzle,
-                                         &word4, &yuv_format);
+                                         &word4, &yuv_format, do_endian_swap);
        assert(format != ~0);
        if (format == ~0) {
                FREE(view);
@@ -696,7 +701,7 @@ r600_create_sampler_view_custom(struct pipe_context *ctx,
                tmp = tmp->flushed_depth_texture;
        }
 
-       endian = r600_colorformat_endian_swap(format);
+       endian = r600_colorformat_endian_swap(format, do_endian_swap);
 
        offset_level = state->u.tex.first_level;
        last_level = state->u.tex.last_level - offset_level;
@@ -824,7 +829,7 @@ static void r600_init_color_surface(struct r600_context *rctx,
        unsigned offset;
        const struct util_format_description *desc;
        int i;
-       bool blend_bypass = 0, blend_clamp = 1;
+       bool blend_bypass = 0, blend_clamp = 1, do_endian_swap = FALSE;
 
        if (rtex->is_depth && !rtex->is_flushing_texture && !r600_can_read_depth(rtex)) {
                r600_init_flushed_depth_texture(&rctx->b.b, surf->base.texture, NULL);
@@ -887,13 +892,17 @@ static void r600_init_color_surface(struct r600_context *rctx,
                        ntype = V_0280A0_NUMBER_UINT;
        }
 
-       format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format);
+       if (R600_BIG_ENDIAN)
+               do_endian_swap = !(rtex->is_depth && !rtex->is_flushing_texture);
+
+       format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format,
+                                                     do_endian_swap);
        assert(format != ~0);
 
-       swap = r600_translate_colorswap(surf->base.format);
+       swap = r600_translate_colorswap(surf->base.format, do_endian_swap);
        assert(swap != ~0);
 
-       endian = r600_colorformat_endian_swap(format);
+       endian = r600_colorformat_endian_swap(format, do_endian_swap);
 
        /* set blend bypass according to docs if SINT/UINT or
           8/24 COLOR variants */
index abc41e008464b223089f0031456bc3dc2454f9e8..3e58d21735b36815bb8fe85b5724960f714fa75e 100644 (file)
@@ -2217,7 +2217,8 @@ unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
 uint32_t r600_translate_texformat(struct pipe_screen *screen,
                                  enum pipe_format format,
                                  const unsigned char *swizzle_view,
-                                 uint32_t *word4_p, uint32_t *yuv_format_p)
+                                 uint32_t *word4_p, uint32_t *yuv_format_p,
+                                 bool do_endian_swap)
 {
        struct r600_screen *rscreen = (struct r600_screen *)screen;
        uint32_t result = 0, word4 = 0, yuv_format = 0;
@@ -2579,7 +2580,8 @@ out_unknown:
        return ~0;
 }
 
-uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format)
+uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format,
+                                               bool do_endian_swap)
 {
        const struct util_format_description *desc = util_format_description(format);
        int channel = util_format_get_first_non_void_channel(format);
@@ -2679,7 +2681,7 @@ uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format forma
        return ~0U;
 }
 
-uint32_t r600_colorformat_endian_swap(uint32_t colorformat)
+uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap)
 {
        if (R600_BIG_ENDIAN) {
                switch(colorformat) {
index 44ab67537b135b9942c8870a1f9f49ce2f22fa83..a0cc162486dd5e1ab9d573af0171797cf1564665 100644 (file)
@@ -635,7 +635,7 @@ struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
                                                struct pipe_resource *texture,
                                                const struct pipe_surface *templ,
                                                unsigned width, unsigned height);
-unsigned r600_translate_colorswap(enum pipe_format format);
+unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap);
 void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                                   struct pipe_framebuffer_state *fb,
                                   struct r600_atom *fb_state,
index 4bbe04d1b7962b4badca403f904b4a09e343eb00..17dd3370437b7d85f8fbcaf0f8d0e75d307700df 100644 (file)
@@ -1392,7 +1392,7 @@ static void r600_surface_destroy(struct pipe_context *pipe,
        FREE(surface);
 }
 
-unsigned r600_translate_colorswap(enum pipe_format format)
+unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap)
 {
        const struct util_format_description *desc = util_format_description(format);
 
@@ -1491,7 +1491,7 @@ static void vi_get_fast_clear_parameters(enum pipe_format surface_format,
            surface_format == PIPE_FORMAT_B5G6R5_SRGB) {
                extra_channel = -1;
        } else if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
-               if(r600_translate_colorswap(surface_format) <= 1)
+               if(r600_translate_colorswap(surface_format, FALSE) <= 1)
                        extra_channel = desc->nr_channels - 1;
                else
                        extra_channel = 0;
index 7ae6e8aff08f6576cf14139fd03527cd6d55ba03..ae87a596398a7e7736b0c937f2e60c58774d757b 100644 (file)
@@ -1877,7 +1877,7 @@ static bool si_is_vertex_format_supported(struct pipe_screen *screen, enum pipe_
 static bool si_is_colorbuffer_format_supported(enum pipe_format format)
 {
        return si_translate_colorformat(format) != V_028C70_COLOR_INVALID &&
-               r600_translate_colorswap(format) != ~0U;
+               r600_translate_colorswap(format, FALSE) != ~0U;
 }
 
 static bool si_is_zs_format_supported(enum pipe_format format)
@@ -2170,7 +2170,7 @@ static void si_initialize_color_surface(struct si_context *sctx,
                R600_ERR("Invalid CB format: %d, disabling CB.\n", surf->base.format);
        }
        assert(format != V_028C70_COLOR_INVALID);
-       swap = r600_translate_colorswap(surf->base.format);
+       swap = r600_translate_colorswap(surf->base.format, FALSE);
        endian = si_colorformat_endian_swap(format);
 
        /* blend clamp should be set for all NORM/SRGB types */