diff options
author | Oded Gabbay <oded.gabbay@gmail.com> | 2016-02-29 09:58:35 +0200 |
---|---|---|
committer | Oded Gabbay <oded.gabbay@gmail.com> | 2016-04-21 17:05:45 +0300 |
commit | aa706274458836d900cb67595de159d37886456b (patch) | |
tree | 260896f0b30d65da87fadad0e8a29cf92e4792b1 | |
parent | 7ab3fc6a10e7a0daf26fa49a5d77727dd8e223f2 (diff) |
add debug coder600g-upstream
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
debug2 - cpu_upload_texture
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 9 | ||||
-rw-r--r-- | src/gallium/drivers/r600/evergreen_state.c | 87 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_blit.c | 35 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_pipe.h | 6 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_state.c | 16 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_state_common.c | 300 | ||||
-rw-r--r-- | src/gallium/drivers/radeon/r600_pipe_common.h | 2 | ||||
-rw-r--r-- | src/gallium/drivers/radeon/r600_texture.c | 131 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_state.c | 4 | ||||
-rw-r--r-- | src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 35 | ||||
-rw-r--r-- | src/mesa/main/debug.c | 3 | ||||
-rw-r--r-- | src/mesa/main/format_utils.c | 69 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 3 | ||||
-rw-r--r-- | src/mesa/main/readpix.c | 41 | ||||
-rw-r--r-- | src/mesa/main/texstore.c | 14 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_clear.c | 1 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_drawpixels.c | 57 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_readpixels.c | 18 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_texture.c | 23 |
19 files changed, 742 insertions, 112 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 3ca2c48c4c..14554211f2 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -1536,6 +1536,15 @@ void util_blitter_blit_generic(struct blitter_context *blitter, util_format_description(src->format); const struct util_format_description *dst_desc = util_format_description(dst->format); + char *prints; + + prints = getenv("PRINTS"); + + if (prints) + printf("%s : source format is %s (%d), dest format is %s (%d)\n", + __FUNCTION__, + util_format_name(src->format), src->format, + util_format_name(dst->format), dst->format); has_color = src_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS && dst_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS; diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c index 8ff40aa44e..ffa9289d2c 100644 --- a/src/gallium/drivers/r600/evergreen_state.c +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -193,39 +193,72 @@ static unsigned r600_tex_dim(unsigned dim, unsigned nr_samples) } } -static uint32_t r600_translate_dbformat(enum pipe_format format) +static uint32_t r600_translate_dbformat(enum pipe_format format, bool is_check) { + char *prints, mode[50]; + char* dbformat[20]; + int i, ret= ~0U, entry = ~0U; + + prints = getenv("PRINTS"); + if (is_check) + prints = NULL; + for (i = 0 ; i < 20 ; i++) { + sprintf(mode, "DBFORMAT%d", i); + dbformat[i] = getenv(mode); + } + + if (prints) + printf("r600_translate_dbformat : format == %s (%d), ", + util_format_name(format), format); + switch (format) { case PIPE_FORMAT_Z16_UNORM: - return V_028040_Z_16; + entry = 0; + ret = V_028040_Z_16; + break; case PIPE_FORMAT_Z24X8_UNORM: case PIPE_FORMAT_Z24_UNORM_S8_UINT: case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_S8_UINT_Z24_UNORM: - return V_028040_Z_24; + entry = 1; + ret = V_028040_Z_24; + break; case PIPE_FORMAT_Z32_FLOAT: case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: - return V_028040_Z_32_FLOAT; + entry = 2; + ret = V_028040_Z_32_FLOAT; + break; default: - return ~0U; + ret = ~0U; + break; } + + if (prints) + printf("entry == %d, ret == 0x%02x\n", entry, ret); + if (entry != ~0U && dbformat[entry]) { + ret = strtol(dbformat[entry], NULL, 10); + if (prints) + printf("Changing entry %d to %d\n", entry, ret); + } + + return ret; } static bool r600_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format) { return r600_translate_texformat(screen, format, NULL, NULL, NULL, - FALSE) != ~0U; + FALSE, 1) != ~0U; } static bool r600_is_colorbuffer_format_supported(enum chip_class chip, enum pipe_format format) { - return r600_translate_colorformat(chip, format, FALSE) != ~0U && - r600_translate_colorswap(format, FALSE) != ~0U; + return r600_translate_colorformat(chip, format, FALSE, 1) != ~0U && + r600_translate_colorswap(format, FALSE, 1) != ~0U; } static bool r600_is_zs_format_supported(enum pipe_format format) { - return r600_translate_dbformat(format) != ~0U; + return r600_translate_dbformat(format, 1) != ~0U; } boolean evergreen_is_format_supported(struct pipe_screen *screen, @@ -679,10 +712,18 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx, unsigned dim, last_layer; uint64_t va; bool do_endian_swap = FALSE; + char *prints; + + prints = getenv("PRINTS"); if (!view) return NULL; + if (prints) + printf("%s : sampler view format is %s (%d)\n", + __FUNCTION__, + util_format_name(pipe_format), pipe_format); + /* initialize base object */ view->base = *state; view->base.texture = NULL; @@ -729,14 +770,14 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx, format = r600_translate_texformat(ctx->screen, pipe_format, swizzle, - &word4, &yuv_format, do_endian_swap); + &word4, &yuv_format, do_endian_swap, 0); assert(format != ~0); if (format == ~0) { FREE(view); return NULL; } - endian = r600_colorformat_endian_swap(format, do_endian_swap); + endian = r600_colorformat_endian_swap(format, do_endian_swap, 0); base_level = 0; first_level = state->u.tex.first_level; @@ -873,6 +914,16 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx, S_03001C_MACRO_TILE_ASPECT(macro_aspect) | S_03001C_NUM_BANKS(nbanks) | S_03001C_DEPTH_SAMPLE_ORDER(tmp->is_depth && !tmp->is_flushing_texture); + + if (prints) { + int i; + + printf(" "); + for (i = 0 ; i < 8 ; i++) + printf("0x%08x ", view->tex_resource_words[i]); + printf("\n"); + } + return &view->base; } @@ -960,9 +1011,9 @@ void evergreen_init_color_surface_rat(struct r600_context *rctx, do_endian_swap = !(rtex->is_depth && !rtex->is_flushing_texture); format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format, - do_endian_swap); - endian = r600_colorformat_endian_swap(format, do_endian_swap); - swap = r600_translate_colorswap(surf->base.format, do_endian_swap); + do_endian_swap, 0); + endian = r600_colorformat_endian_swap(format, do_endian_swap, 1); + swap = r600_translate_colorswap(surf->base.format, do_endian_swap, 0); surf->cb_color_base = r600_resource(pipe_buffer)->gpu_address >> 8; @@ -1112,13 +1163,13 @@ void evergreen_init_color_surface(struct r600_context *rctx, do_endian_swap = !(rtex->is_depth && !rtex->is_flushing_texture); format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format, - do_endian_swap); + do_endian_swap, 0); assert(format != ~0); - swap = r600_translate_colorswap(surf->base.format, do_endian_swap); + swap = r600_translate_colorswap(surf->base.format, do_endian_swap, 0); assert(swap != ~0); - endian = r600_colorformat_endian_swap(format, do_endian_swap); + endian = r600_colorformat_endian_swap(format, do_endian_swap, 1); /* blend clamp should be set for all NORM/SRGB types */ if (ntype == V_028C70_NUMBER_UNORM || ntype == V_028C70_NUMBER_SNORM || @@ -1196,7 +1247,7 @@ static void evergreen_init_depth_surface(struct r600_context *rctx, unsigned macro_aspect, tile_split, bankh, bankw, nbanks; - format = r600_translate_dbformat(surf->base.format); + format = r600_translate_dbformat(surf->base.format, 0); assert(format != ~0); offset = rtex->resource.gpu_address; diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index 2d30807c9f..497f6b1cc0 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -27,6 +27,8 @@ #include "util/u_format.h" #include "evergreend.h" +void radeon_dump_bo(struct pb_buffer *buf); + enum r600_blitter_op /* bitmask */ { R600_SAVE_FRAGMENT_STATE = 1, @@ -262,6 +264,9 @@ void r600_decompress_depth_textures(struct r600_context *rctx, { unsigned i; unsigned depth_texture_mask = textures->compressed_depthtex_mask; + char *prints; + + prints = getenv("DUMP_BO"); while (depth_texture_mask) { struct pipe_sampler_view *view; @@ -289,6 +294,12 @@ void r600_decompress_depth_textures(struct r600_context *rctx, 0, util_max_layer(&tex->resource.b.b, view->u.tex.first_level), 0, u_max_sample(&tex->resource.b.b)); } + + if (prints) { + r600_context_gfx_flush(rctx, 0, NULL); + printf("\nIn %s, after blit:\n", __FUNCTION__); + radeon_dump_bo(tex->resource.buf); + } } } @@ -376,9 +387,11 @@ static bool r600_decompress_subresource(struct pipe_context *ctx, if (rtex->is_depth && !rtex->is_flushing_texture) { if (rctx->b.chip_class >= EVERGREEN || r600_can_read_depth(rtex)) { + r600_blit_decompress_depth_in_place(rctx, rtex, false, level, level, first_layer, last_layer); + if (rtex->surface.flags & RADEON_SURF_SBUFFER) { r600_blit_decompress_depth_in_place(rctx, rtex, true, level, level, @@ -622,6 +635,10 @@ void r600_resource_copy_region(struct pipe_context *ctx, unsigned dst_width, dst_height, src_width0, src_height0, src_widthFL, src_heightFL; unsigned src_force_level = 0; struct pipe_box sbox, dstbox; + char *prints, *dumpbo; + + prints = getenv("PRINTS"); + dumpbo = getenv("DUMP_BO"); /* Handle buffers first. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { @@ -730,6 +747,12 @@ void r600_resource_copy_region(struct pipe_context *ctx, } } + if (prints) + printf("%s : source format is %s (%d), dest format is %s (%d)\n", + __FUNCTION__, + util_format_name(src->format), src->format, + util_format_name(dst->format), dst->format); + dst_view = r600_create_surface_custom(ctx, dst, &dst_templ, dst_width, dst_height); if (rctx->b.chip_class >= EVERGREEN) { @@ -744,6 +767,12 @@ void r600_resource_copy_region(struct pipe_context *ctx, u_box_3d(dstx, dsty, dstz, abs(src_box->width), abs(src_box->height), abs(src_box->depth), &dstbox); + if (dumpbo) { + r600_context_gfx_flush(rctx, 0, NULL); + printf("\nIn %s, before blit:\n", __FUNCTION__); + radeon_dump_bo(((struct r600_resource *) src_view->texture)->buf); + } + /* Copy. */ r600_blitter_begin(ctx, R600_COPY_TEXTURE); util_blitter_blit_generic(rctx->blitter, dst_view, &dstbox, @@ -752,6 +781,12 @@ void r600_resource_copy_region(struct pipe_context *ctx, FALSE); r600_blitter_end(ctx); + if (dumpbo) { + r600_context_gfx_flush(rctx, 0, NULL); + printf("\nIn %s, after blit:\n", __FUNCTION__); + radeon_dump_bo(((struct r600_resource *) dst_view->texture)->buf); + } + pipe_surface_reference(&dst_view, NULL); pipe_sampler_view_reference(&src_view, NULL); } diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index e6e74443b3..3a7cb2e8e9 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -734,10 +734,10 @@ 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, - bool do_endian_swap); + bool do_endian_swap, bool is_check); 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); + bool do_endian_swap, bool is_check); +uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap, bool is_check); /* r600_uvd.c */ struct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context, diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c index 75a4363905..2ba19dcb4e 100644 --- a/src/gallium/drivers/r600/r600_state.c +++ b/src/gallium/drivers/r600/r600_state.c @@ -144,13 +144,13 @@ 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, - FALSE) != ~0U; + FALSE, 1) != ~0U; } static bool r600_is_colorbuffer_format_supported(enum chip_class chip, enum pipe_format format) { - return r600_translate_colorformat(chip, format, FALSE) != ~0U && - r600_translate_colorswap(format, FALSE) != ~0U; + return r600_translate_colorformat(chip, format, FALSE, 1) != ~0U && + r600_translate_colorswap(format, FALSE, 1) != ~0U; } static bool r600_is_zs_format_supported(enum pipe_format format) @@ -686,7 +686,7 @@ r600_create_sampler_view_custom(struct pipe_context *ctx, format = r600_translate_texformat(ctx->screen, state->format, swizzle, - &word4, &yuv_format, do_endian_swap); + &word4, &yuv_format, do_endian_swap, 0); assert(format != ~0); if (format == ~0) { FREE(view); @@ -701,7 +701,7 @@ r600_create_sampler_view_custom(struct pipe_context *ctx, tmp = tmp->flushed_depth_texture; } - endian = r600_colorformat_endian_swap(format, do_endian_swap); + endian = r600_colorformat_endian_swap(format, do_endian_swap, 0); offset_level = state->u.tex.first_level; last_level = state->u.tex.last_level - offset_level; @@ -896,13 +896,13 @@ static void r600_init_color_surface(struct r600_context *rctx, do_endian_swap = !(rtex->is_depth && !rtex->is_flushing_texture); format = r600_translate_colorformat(rctx->b.chip_class, surf->base.format, - do_endian_swap); + do_endian_swap, 0); assert(format != ~0); - swap = r600_translate_colorswap(surf->base.format, do_endian_swap); + swap = r600_translate_colorswap(surf->base.format, do_endian_swap, 0); assert(swap != ~0); - endian = r600_colorformat_endian_swap(format, do_endian_swap); + endian = r600_colorformat_endian_swap(format, do_endian_swap, 1); /* set blend bypass according to docs if SINT/UINT or 8/24 COLOR variants */ diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index 2c82e7e4e2..d5b218d3eb 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -37,6 +37,8 @@ #include "tgsi/tgsi_scan.h" #include "tgsi/tgsi_ureg.h" +void radeon_dump_bo(struct pb_buffer *buf); + void r600_init_command_buffer(struct r600_command_buffer *cb, unsigned num_dw) { assert(!cb->buf); @@ -2218,7 +2220,7 @@ 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, - bool do_endian_swap) + bool do_endian_swap, bool is_check) { struct r600_screen *rscreen = (struct r600_screen *)screen; uint32_t result = 0, word4 = 0, yuv_format = 0; @@ -2230,8 +2232,19 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, const unsigned char swizzle_xxxy[4] = {0, 0, 0, 1}; const unsigned char swizzle_zyx1[4] = {2, 1, 0, 5}; const unsigned char swizzle_zyxw[4] = {2, 1, 0, 3}; - + char *prints, mode[50]; + char* texformat[50]; + int entry = ~0U; int i; + + prints = getenv("PRINTS"); + if (is_check) + prints = NULL; + for (i = 0 ; i < 50 ; i++) { + sprintf(mode, "TEXFORMAT%d", i); + texformat[i] = getenv(mode); + } + const uint32_t sign_bit[4] = { S_038010_FORMAT_COMP_X(V_038010_SQ_FORMAT_COMP_SIGNED), S_038010_FORMAT_COMP_Y(V_038010_SQ_FORMAT_COMP_SIGNED), @@ -2275,20 +2288,28 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, } } + if (prints) + printf("r600_translate_texformat : format == %s (%d), ", + util_format_name(format), format); + /* Colorspace (return non-RGB formats directly). */ switch (desc->colorspace) { /* Depth stencil formats */ case UTIL_FORMAT_COLORSPACE_ZS: + if (prints) + printf("UTIL_FORMAT_COLORSPACE_ZS, "); switch (format) { /* Depth sampler formats. */ case PIPE_FORMAT_Z16_UNORM: word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_16; + entry = 0; goto out_word4; case PIPE_FORMAT_Z24X8_UNORM: case PIPE_FORMAT_Z24_UNORM_S8_UINT: word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_8_24; + entry = 1; goto out_word4; case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_S8_UINT_Z24_UNORM: @@ -2296,25 +2317,30 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, goto out_unknown; word4 |= r600_get_swizzle_combined(swizzle_yyyy, swizzle_view, FALSE); result = FMT_24_8; + entry = 2; goto out_word4; case PIPE_FORMAT_Z32_FLOAT: word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_32_FLOAT; + entry = 3; goto out_word4; case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT: word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_X24_8_32_FLOAT; + entry = 4; goto out_word4; /* Stencil sampler formats. */ case PIPE_FORMAT_S8_UINT: word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_8; + entry = 5; goto out_word4; case PIPE_FORMAT_X24S8_UINT: word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); word4 |= r600_get_swizzle_combined(swizzle_yyyy, swizzle_view, FALSE); result = FMT_8_24; + entry = 6; goto out_word4; case PIPE_FORMAT_S8X24_UINT: if (rscreen->b.chip_class < EVERGREEN) @@ -2322,17 +2348,21 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); word4 |= r600_get_swizzle_combined(swizzle_xxxx, swizzle_view, FALSE); result = FMT_24_8; + entry = 7; goto out_word4; case PIPE_FORMAT_X32_S8X24_UINT: word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); word4 |= r600_get_swizzle_combined(swizzle_yyyy, swizzle_view, FALSE); result = FMT_X24_8_32_FLOAT; + entry = 8; goto out_word4; default: goto out_unknown; } case UTIL_FORMAT_COLORSPACE_YUV: + if (prints) + printf("UTIL_FORMAT_COLORSPACE_YUV, "); yuv_format |= (1 << 30); switch (format) { case PIPE_FORMAT_UYVY: @@ -2343,7 +2373,10 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, goto out_unknown; /* XXX */ case UTIL_FORMAT_COLORSPACE_SRGB: + if (prints) + printf("UTIL_FORMAT_COLORSPACE_SRGB, "); word4 |= S_038010_FORCE_DEGAMMA(1); + entry = 9; break; default: @@ -2351,6 +2384,8 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, } if (desc->layout == UTIL_FORMAT_LAYOUT_RGTC) { + if (prints) + printf("UTIL_FORMAT_LAYOUT_RGTC, "); switch (format) { case PIPE_FORMAT_RGTC1_SNORM: case PIPE_FORMAT_LATC1_SNORM: @@ -2372,6 +2407,8 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, } if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) { + if (prints) + printf("UTIL_FORMAT_LAYOUT_S3TC, "); if (!util_format_s3tc_enabled) { goto out_unknown; } @@ -2383,16 +2420,19 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, case PIPE_FORMAT_DXT1_SRGBA: result = FMT_BC1; is_srgb_valid = TRUE; + entry = 10; goto out_word4; case PIPE_FORMAT_DXT3_RGBA: case PIPE_FORMAT_DXT3_SRGBA: result = FMT_BC2; is_srgb_valid = TRUE; + entry = 11; goto out_word4; case PIPE_FORMAT_DXT5_RGBA: case PIPE_FORMAT_DXT5_SRGBA: result = FMT_BC3; is_srgb_valid = TRUE; + entry = 12; goto out_word4; default: goto out_unknown; @@ -2400,6 +2440,8 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, } if (desc->layout == UTIL_FORMAT_LAYOUT_BPTC) { + if (prints) + printf("UTIL_FORMAT_LAYOUT_BPTC, "); if (rscreen->b.chip_class < EVERGREEN) goto out_unknown; @@ -2408,12 +2450,14 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, case PIPE_FORMAT_BPTC_SRGBA: result = FMT_BC7; is_srgb_valid = TRUE; + entry = 13; goto out_word4; case PIPE_FORMAT_BPTC_RGB_FLOAT: word4 |= sign_bit[0] | sign_bit[1] | sign_bit[2]; /* fall through */ case PIPE_FORMAT_BPTC_RGB_UFLOAT: result = FMT_BC6; + entry = 14; goto out_word4; default: goto out_unknown; @@ -2421,14 +2465,18 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, } if (desc->layout == UTIL_FORMAT_LAYOUT_SUBSAMPLED) { + if (prints) + printf("UTIL_FORMAT_LAYOUT_SUBSAMPLED, "); switch (format) { case PIPE_FORMAT_R8G8_B8G8_UNORM: case PIPE_FORMAT_G8R8_B8R8_UNORM: result = FMT_GB_GR; + entry = 15; goto out_word4; case PIPE_FORMAT_G8R8_G8B8_UNORM: case PIPE_FORMAT_R8G8_R8B8_UNORM: result = FMT_BG_RG; + entry = 16; goto out_word4; default: goto out_unknown; @@ -2437,9 +2485,11 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, if (format == PIPE_FORMAT_R9G9B9E5_FLOAT) { result = FMT_5_9_9_9_SHAREDEXP; + entry = 17; goto out_word4; } else if (format == PIPE_FORMAT_R11G11B10_FLOAT) { result = FMT_10_11_11_FLOAT; + entry = 18; goto out_word4; } @@ -2464,19 +2514,25 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, word4 |= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT); switch(desc->nr_channels) { case 3: + if (prints) + printf("nr_channels == 3, "); if (desc->channel[0].size == 5 && desc->channel[1].size == 6 && desc->channel[2].size == 5) { result = FMT_5_6_5; + entry = 19; goto out_word4; } goto out_unknown; case 4: + if (prints) + printf("nr_channels == 4, "); if (desc->channel[0].size == 5 && desc->channel[1].size == 5 && desc->channel[2].size == 5 && desc->channel[3].size == 1) { result = FMT_1_5_5_5; + entry = 20; goto out_word4; } if (desc->channel[0].size == 10 && @@ -2484,6 +2540,7 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, desc->channel[2].size == 10 && desc->channel[3].size == 2) { result = FMT_2_10_10_10; + entry = 21; goto out_word4; } goto out_unknown; @@ -2519,50 +2576,83 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, case 4: switch (desc->nr_channels) { case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_4_4; + entry = 23; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_4_4_4_4; + entry = 24; goto out_word4; } goto out_unknown; case 8: switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); result = FMT_8; + entry = 25; goto out_word4; case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_8_8; + entry = 26; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_8_8_8_8; is_srgb_valid = TRUE; + entry = 27; goto out_word4; } goto out_unknown; case 16: switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); result = FMT_16; + entry = 28; goto out_word4; case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_16_16; + entry = 29; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_16_16_16_16; + entry = 30; goto out_word4; } goto out_unknown; case 32: switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); result = FMT_32; + entry = 31; goto out_word4; case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_32_32; + entry = 32; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_32_32_32_32; + entry = 33; goto out_word4; } } @@ -2573,26 +2663,44 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, case 16: switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); result = FMT_16_FLOAT; + entry = 34; goto out_word4; case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_16_16_FLOAT; + entry = 35; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_16_16_16_16_FLOAT; + entry = 36; goto out_word4; } goto out_unknown; case 32: switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); result = FMT_32_FLOAT; + entry = 37; goto out_word4; case 2: + if (prints) + printf("nr_channels == 2, "); result = FMT_32_32_FLOAT; + entry = 38; goto out_word4; case 4: + if (prints) + printf("nr_channels == 4, "); result = FMT_32_32_32_32_FLOAT; + entry = 39; goto out_word4; } } @@ -2601,6 +2709,14 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen, out_word4: + if (prints) + printf("entry == %2d, result == 0x%02x\n", entry, result); + if (entry != ~0U && texformat[entry]) { + result = strtol(texformat[entry], NULL, 10); + if (prints) + printf("Changing entry %d to %d\n", entry, result); + } + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB && !is_srgb_valid) return ~0; if (word4_p) @@ -2609,119 +2725,202 @@ out_word4: *yuv_format_p = yuv_format; return result; out_unknown: + if (prints) + printf("\n"); /* R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); */ return ~0; } uint32_t r600_translate_colorformat(enum chip_class chip, enum pipe_format format, - bool do_endian_swap) + bool do_endian_swap, bool is_check) { + char *prints, mode[50]; + char* colorformat[30]; const struct util_format_description *desc = util_format_description(format); int channel = util_format_get_first_non_void_channel(format); bool is_float; + int i, ret = ~0U, entry = ~0U; + + prints = getenv("PRINTS"); + if (is_check) + prints = NULL; + for (i = 0 ; i < 30 ; i++) { + sprintf(mode, "COLORFORMAT%d", i); + colorformat[i] = getenv(mode); + } #define HAS_SIZE(x,y,z,w) \ (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \ desc->channel[2].size == (z) && desc->channel[3].size == (w)) - if (format == PIPE_FORMAT_R11G11B10_FLOAT) /* isn't plain */ + if (prints) + printf("r600_translate_colorformat : format == %s (%d), ", + util_format_name(format), format); + + if (format == PIPE_FORMAT_R11G11B10_FLOAT) {/* isn't plain */ + if (prints) + printf("format == PIPE_FORMAT_R11G11B10_FLOAT\n"); + return V_0280A0_COLOR_10_11_11_FLOAT; + } if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || - channel == -1) + channel == -1) { + if (prints) + printf("desc->layout != UTIL_FORMAT_LAYOUT_PLAIN\n"); + return ~0U; + } is_float = desc->channel[channel].type == UTIL_FORMAT_TYPE_FLOAT; switch (desc->nr_channels) { case 1: + if (prints) + printf("nr_channels == 1, "); switch (desc->channel[0].size) { case 8: - return V_0280A0_COLOR_8; + ret = V_0280A0_COLOR_8; + entry = 0; + break; case 16: if (is_float) - return V_0280A0_COLOR_16_FLOAT; + ret = V_0280A0_COLOR_16_FLOAT; else - return V_0280A0_COLOR_16; + ret = V_0280A0_COLOR_16; + entry = 1; + break; case 32: if (is_float) - return V_0280A0_COLOR_32_FLOAT; + ret = V_0280A0_COLOR_32_FLOAT; else - return V_0280A0_COLOR_32; + ret = V_0280A0_COLOR_32; + entry = 2; + break; } break; case 2: + if (prints) + printf("nr_channels == 2, "); if (desc->channel[0].size == desc->channel[1].size) { switch (desc->channel[0].size) { case 4: if (chip <= R700) - return V_0280A0_COLOR_4_4; + ret = V_0280A0_COLOR_4_4; else - return ~0U; /* removed on Evergreen */ + ret = ~0U; /* removed on Evergreen */ + entry = 3; + break; case 8: - return V_0280A0_COLOR_8_8; + ret = V_0280A0_COLOR_8_8; + entry = 4; + break; case 16: if (is_float) - return V_0280A0_COLOR_16_16_FLOAT; + ret = V_0280A0_COLOR_16_16_FLOAT; else - return V_0280A0_COLOR_16_16; + ret = V_0280A0_COLOR_16_16; + entry = 5; + break; case 32: if (is_float) - return V_0280A0_COLOR_32_32_FLOAT; + ret = V_0280A0_COLOR_32_32_FLOAT; else - return V_0280A0_COLOR_32_32; + ret = V_0280A0_COLOR_32_32; + entry = 6; + break; } } else if (HAS_SIZE(8,24,0,0)) { - return (do_endian_swap ? V_0280A0_COLOR_8_24 : V_0280A0_COLOR_24_8); + ret = (do_endian_swap ? V_0280A0_COLOR_8_24 : V_0280A0_COLOR_24_8); + entry = 7; } else if (HAS_SIZE(24,8,0,0)) { - return V_0280A0_COLOR_8_24; + ret = V_0280A0_COLOR_8_24; + entry = 8; } break; case 3: + if (prints) + printf("nr_channels == 3, "); if (HAS_SIZE(5,6,5,0)) { - return V_0280A0_COLOR_5_6_5; + ret = V_0280A0_COLOR_5_6_5; + entry = 9; } else if (HAS_SIZE(32,8,24,0)) { - return V_0280A0_COLOR_X24_8_32_FLOAT; + ret = V_0280A0_COLOR_X24_8_32_FLOAT; + entry = 10; } break; case 4: + if (prints) + printf("nr_channels == 4, "); if (desc->channel[0].size == desc->channel[1].size && desc->channel[0].size == desc->channel[2].size && desc->channel[0].size == desc->channel[3].size) { switch (desc->channel[0].size) { case 4: - return V_0280A0_COLOR_4_4_4_4; + ret = V_0280A0_COLOR_4_4_4_4; + entry = 11; + break; case 8: - return V_0280A0_COLOR_8_8_8_8; + ret = V_0280A0_COLOR_8_8_8_8; + entry = 12; + break; case 16: if (is_float) - return V_0280A0_COLOR_16_16_16_16_FLOAT; + ret = V_0280A0_COLOR_16_16_16_16_FLOAT; else - return V_0280A0_COLOR_16_16_16_16; + ret = V_0280A0_COLOR_16_16_16_16; + entry = 13; + break; case 32: if (is_float) - return V_0280A0_COLOR_32_32_32_32_FLOAT; + ret = V_0280A0_COLOR_32_32_32_32_FLOAT; else - return V_0280A0_COLOR_32_32_32_32; + ret = V_0280A0_COLOR_32_32_32_32; + entry = 14; + break; } } else if (HAS_SIZE(5,5,5,1)) { - return V_0280A0_COLOR_1_5_5_5; + ret = V_0280A0_COLOR_1_5_5_5; + entry = 15; } else if (HAS_SIZE(10,10,10,2)) { - return V_0280A0_COLOR_2_10_10_10; + ret = V_0280A0_COLOR_2_10_10_10; + entry = 16; } break; } - return ~0U; + if (prints) + printf("entry == %2d, colorformat == 0x%02x, do_endian_swap == %d\n", + entry, ret, do_endian_swap); + if (entry != ~0U && colorformat[entry]) { + ret = strtol(colorformat[entry], NULL, 10); + if (prints) + printf("Changing entry %d to %d\n", entry, ret); + } + return ret; } -uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap) +uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap, bool is_color) { + char *prints, mode[20]; + char* endian[80]; + int i, ret, index; + + prints = getenv("PRINTS"); + for (i = 0 ; i < 80 ; i++) { + sprintf(mode, "ENDIAN%d", i); + endian[i] = getenv(mode); + } + if (R600_BIG_ENDIAN) { + if (prints) + printf("r600_colorformat_endian_swap : format == 0x%02x, ", colorformat); + switch(colorformat) { /* 8-bit buffers. */ case V_0280A0_COLOR_4_4: case V_0280A0_COLOR_8: - return ENDIAN_NONE; + ret = ENDIAN_NONE; + break; /* 16-bit buffers. */ case V_0280A0_COLOR_8_8: @@ -2730,13 +2929,15 @@ uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap) * as mesa<-->pipe formats conversion take into account * the endianess */ - return ENDIAN_NONE; + ret = ENDIAN_NONE; + break; case V_0280A0_COLOR_5_6_5: case V_0280A0_COLOR_1_5_5_5: case V_0280A0_COLOR_4_4_4_4: case V_0280A0_COLOR_16: - return (do_endian_swap ? ENDIAN_8IN16 : ENDIAN_NONE); + ret = (do_endian_swap ? ENDIAN_8IN16 : ENDIAN_NONE); + break; /* 32-bit buffers. */ case V_0280A0_COLOR_8_8_8_8: @@ -2746,35 +2947,52 @@ uint32_t r600_colorformat_endian_swap(uint32_t colorformat, bool do_endian_swap) * as mesa<-->pipe formats conversion take into account * the endianess */ - return ENDIAN_NONE; + ret = ENDIAN_NONE; + break; case V_0280A0_COLOR_2_10_10_10: case V_0280A0_COLOR_8_24: case V_0280A0_COLOR_24_8: case V_0280A0_COLOR_32_FLOAT: case V_0280A0_COLOR_16_16_FLOAT: - return (do_endian_swap ? ENDIAN_8IN32 : ENDIAN_NONE); + ret = (do_endian_swap ? ENDIAN_8IN32 : ENDIAN_NONE); + break; /* 64-bit buffers. */ case V_0280A0_COLOR_16_16_16_16: case V_0280A0_COLOR_16_16_16_16_FLOAT: - return ENDIAN_8IN16; + ret = ENDIAN_8IN16; + break; case V_0280A0_COLOR_32_32_FLOAT: case V_0280A0_COLOR_32_32: case V_0280A0_COLOR_X24_8_32_FLOAT: - return ENDIAN_8IN32; + ret = ENDIAN_8IN32; + break; /* 128-bit buffers. */ case V_0280A0_COLOR_32_32_32_32_FLOAT: case V_0280A0_COLOR_32_32_32_32: - return ENDIAN_8IN32; + ret = ENDIAN_8IN32; + break; default: - return ENDIAN_NONE; /* Unsupported. */ + ret = ENDIAN_NONE; /* Unsupported. */ + break; + } + if (prints) + printf("ret == %d, do_endian_swap == %d\n", + ret, do_endian_swap); + index = colorformat + (is_color * 40); + if (colorformat >=0 && colorformat < 40 && endian[index]) { + ret = strtol(endian[index], NULL, 10); + if (prints) + printf("Changing endian format 0x%x to %d\n", colorformat, ret); } } else { - return ENDIAN_NONE; + ret = ENDIAN_NONE; } + + return ret; } static void r600_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf) diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h index a0cc162486..ec0baecdcc 100644 --- a/src/gallium/drivers/radeon/r600_pipe_common.h +++ b/src/gallium/drivers/radeon/r600_pipe_common.h @@ -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, bool do_endian_swap); +unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap, bool is_check); void evergreen_do_fast_color_clear(struct r600_common_context *rctx, struct pipe_framebuffer_state *fb, struct r600_atom *fb_state, diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c index ead4dd75d8..6e697e642a 100644 --- a/src/gallium/drivers/radeon/r600_texture.c +++ b/src/gallium/drivers/radeon/r600_texture.c @@ -32,6 +32,10 @@ #include <errno.h> #include <inttypes.h> +void radeon_dump_bo(struct pb_buffer *buf); +void r600_context_gfx_flush(void *context, unsigned flags, + struct pipe_fence_handle **fence); + /* Same as resource_copy_region, except that both upsampling and downsampling are allowed. */ static void r600_copy_region_with_blit(struct pipe_context *pipe, struct pipe_resource *dst, @@ -1152,6 +1156,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, struct r600_resource *buf; unsigned offset = 0; char *map; + char *prints; /* We cannot map a tiled texture directly because the data is * in a different order, therefore we do detiling using a blit. @@ -1290,6 +1295,22 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx, return NULL; } + prints = getenv("DUMP_MAP"); + + if (prints) { + uint32_t j, my_width; + const uint32_t *s = ((const uint32_t *) map + offset); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (buf->b.b.width0 > 16 ? 16 : buf->b.b.width0); + for (j = 0; j < my_width; j++) { + printf("0x%08x ", s[j]); + if ((j+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + *ptransfer = &trans->transfer; return map + offset; } @@ -1392,64 +1413,116 @@ static void r600_surface_destroy(struct pipe_context *pipe, FREE(surface); } -unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap) +unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap, bool is_check) { + char *prints, mode[50]; + char* colorswap[20]; const struct util_format_description *desc = util_format_description(format); + int i, ret= ~0U, entry = ~0U; + + prints = getenv("PRINTS"); + if (is_check) + prints = NULL; + for (i = 0 ; i < 20 ; i++) { + sprintf(mode, "COLORSWAP%d", i); + colorswap[i] = getenv(mode); + } #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == UTIL_FORMAT_SWIZZLE_##swz) - if (format == PIPE_FORMAT_R11G11B10_FLOAT) /* isn't plain */ + if (prints) + printf("r600_translate_colorswap : format == %s (%d), ", + util_format_name(format), format); + + if (format == PIPE_FORMAT_R11G11B10_FLOAT) {/* isn't plain */ + if (prints) + printf("format == PIPE_FORMAT_R11G11B10_FLOAT\n"); + return V_0280A0_SWAP_STD; + } + + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { + if (prints) + printf("desc->layout != UTIL_FORMAT_LAYOUT_PLAIN\n"); - if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) return ~0U; + } switch (desc->nr_channels) { case 1: - if (HAS_SWIZZLE(0,X)) - return V_0280A0_SWAP_STD; /* X___ */ - else if (HAS_SWIZZLE(3,X)) - return V_0280A0_SWAP_ALT_REV; /* ___X */ + if (prints) + printf("nr_channels == 1, "); + if (HAS_SWIZZLE(0,X)) { + entry = 0; + ret = V_0280A0_SWAP_STD; /* X___ */ + } else if (HAS_SWIZZLE(3,X)) { + entry = 1; + ret = V_0280A0_SWAP_ALT_REV; /* ___X */ + } break; case 2: + if (prints) + printf("nr_channels == 2, "); if ((HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,Y)) || (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(1,NONE)) || - (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y))) - return V_0280A0_SWAP_STD; /* XY__ */ - else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) || + (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,Y))) { + entry = 2; + ret = V_0280A0_SWAP_STD; /* XY__ */ + } else if ((HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,X)) || (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(1,NONE)) || - (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X))) - /* YX__ */ - return (do_endian_swap ? V_0280A0_SWAP_STD : V_0280A0_SWAP_STD_REV); - else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y)) - return V_0280A0_SWAP_ALT; /* X__Y */ - else if (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(3,X)) - return V_0280A0_SWAP_ALT_REV; /* Y__X */ + (HAS_SWIZZLE(0,NONE) && HAS_SWIZZLE(1,X))) { + entry = 3; + ret = (do_endian_swap ? V_0280A0_SWAP_STD : V_0280A0_SWAP_STD_REV); + } else if (HAS_SWIZZLE(0,X) && HAS_SWIZZLE(3,Y)) { + entry = 4; + ret = V_0280A0_SWAP_ALT; /* X__Y */ + } else if (HAS_SWIZZLE(0,Y) && HAS_SWIZZLE(3,X)) { + entry = 5; + ret = V_0280A0_SWAP_ALT_REV; /* Y__X */ + } break; case 3: - if (HAS_SWIZZLE(0,X)) - return (do_endian_swap ? V_0280A0_SWAP_STD_REV : V_0280A0_SWAP_STD); - else if (HAS_SWIZZLE(0,Z)) - return V_0280A0_SWAP_STD_REV; /* ZYX */ + if (prints) + printf("nr_channels == 3, "); + if (HAS_SWIZZLE(0,X)) { + entry = 6; + ret = (do_endian_swap ? V_0280A0_SWAP_STD_REV : V_0280A0_SWAP_STD); + } else if (HAS_SWIZZLE(0,Z)) { + entry = 7; + ret = V_0280A0_SWAP_STD_REV; /* ZYX */ + } break; case 4: + if (prints) + printf("nr_channels == 4, "); /* check the middle channels, the 1st and 4th channel can be NONE */ if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,Z)) { - return V_0280A0_SWAP_STD; /* XYZW */ + entry = 8; + ret = V_0280A0_SWAP_STD; /* XYZW */ } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,Y)) { - return V_0280A0_SWAP_STD_REV; /* WZYX */ + entry = 9; + ret = V_0280A0_SWAP_STD_REV; /* WZYX */ } else if (HAS_SWIZZLE(1,Y) && HAS_SWIZZLE(2,X)) { - return V_0280A0_SWAP_ALT; /* ZYXW */ + entry = 10; + ret = V_0280A0_SWAP_ALT; /* ZYXW */ } else if (HAS_SWIZZLE(1,Z) && HAS_SWIZZLE(2,W)) { - /* YZWX */ + entry = 11; if (desc->is_array) - return V_0280A0_SWAP_ALT_REV; + ret = V_0280A0_SWAP_ALT_REV; /* YZWX */ else - return (do_endian_swap ? V_0280A0_SWAP_ALT : V_0280A0_SWAP_ALT_REV); + ret = (do_endian_swap ? V_0280A0_SWAP_ALT : V_0280A0_SWAP_ALT_REV); } break; } - return ~0U; + if (prints) + printf("entry == %2d, colorswap == 0x%02x, do_endian_swap == %d\n", + entry, ret, do_endian_swap); + if (entry != ~0U && colorswap[entry]) { + ret = strtol(colorswap[entry], NULL, 10); + if (prints) + printf("Changing entry %d to %d\n", entry, ret); + } + return ret; } static void evergreen_set_clear_color(struct r600_texture *rtex, @@ -1497,7 +1570,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, FALSE) <= 1) + if(r600_translate_colorswap(surface_format, FALSE, 0) <= 1) extra_channel = desc->nr_channels - 1; else extra_channel = 0; diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index c713c5c3e6..0269495d02 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -1876,7 +1876,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, FALSE) != ~0U; + r600_translate_colorswap(format, FALSE, 1) != ~0U; } static bool si_is_zs_format_supported(enum pipe_format format) @@ -2169,7 +2169,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, FALSE); + swap = r600_translate_colorswap(surf->base.format, FALSE, 0); endian = si_colorformat_endian_swap(format); /* blend clamp should be set for all NORM/SRGB types */ diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c index dd6555c950..b12a97134b 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c @@ -1065,3 +1065,38 @@ void radeon_drm_bo_init_functions(struct radeon_drm_winsys *ws) ws->base.buffer_get_virtual_address = radeon_winsys_bo_va; ws->base.buffer_get_initial_domain = radeon_bo_get_initial_domain; } + +void radeon_dump_bo(struct pb_buffer *buf); + +void radeon_dump_bo(struct pb_buffer *buf) +{ + struct radeon_bo *bo = radeon_bo(buf); + uint32_t *ptr; + int i, size; + + if (!bo) { + printf("bo is NULL!!!\n"); + return; + } + + printf("bo->handle == %d\n", bo->handle); + + ptr = radeon_bo_do_map(bo); + + if (!ptr) { + printf("ptr is NULL!!!\n"); + radeon_bo_unmap(buf); + return; + } + + size = (bo->base.size > 1024 ? 1024 : bo->base.size); + for (i = 0 ; i < size / 4 ; i++) { + if (i % 8 == 0) + printf("\n0x%04x: ", i * 4); + printf("0x%08x ", ptr[i]); + } + + printf("\n\n"); + + radeon_bo_unmap(buf); +} diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c index 5ca7d5ce50..b0fe1a3173 100644 --- a/src/mesa/main/debug.c +++ b/src/mesa/main/debug.c @@ -156,7 +156,8 @@ set_verbose_flags(const char *str) { "lighting", VERBOSE_LIGHTING }, { "disassem", VERBOSE_DISASSEM }, { "draw", VERBOSE_DRAW }, - { "swap", VERBOSE_SWAPBUFFERS } + { "swap", VERBOSE_SWAPBUFFERS }, + { "dump", VERBOSE_DUMPBUFFERS } }; GLuint i; diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c index d16d69c379..52174ebbd4 100644 --- a/src/mesa/main/format_utils.c +++ b/src/mesa/main/format_utils.c @@ -282,6 +282,9 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, uint32_t (*tmp_uint)[4]; int bits; size_t row; + char *swap_bytes; + + swap_bytes = getenv("SWAP_BYTES"); if (_mesa_format_is_mesa_array_format(src_format)) { src_format_is_mesa_array_format = true; @@ -321,7 +324,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } else if (dst_array_format == RGBA8_UBYTE) { assert(!_mesa_is_format_integer_color(src_format)); for (row = 0; row < height; ++row) { @@ -330,7 +333,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } else if (dst_array_format == RGBA32_UINT && _mesa_is_format_unsigned(src_format)) { assert(_mesa_is_format_integer_color(src_format)); @@ -340,7 +343,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } } @@ -353,7 +356,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } else if (src_array_format == RGBA8_UBYTE) { assert(!_mesa_is_format_integer_color(dst_format)); @@ -369,7 +372,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, dst += dst_stride; } } - return; + goto print_at_end; } else if (src_array_format == RGBA32_UINT && _mesa_is_format_unsigned(dst_format)) { assert(_mesa_is_format_integer_color(dst_format)); @@ -379,7 +382,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } } } @@ -421,7 +424,7 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, src += src_stride; dst += dst_stride; } - return; + goto print_at_end; } /* At this point, we're fresh out of fast-paths and we need to convert @@ -630,6 +633,58 @@ _mesa_format_convert(void *void_dst, uint32_t dst_format, size_t dst_stride, free(tmp_ubyte); } + +print_at_end: + if (swap_bytes) { + int z, w; + +#if 1 + GLbyte *s = ((GLbyte *) void_dst); + GLbyte val; + + for (z = 0 ; z < height ; z++) { + for (w = 0 ; w < dst_stride ; w++) { + val = *(s + z * dst_stride + w); + *(s + z * dst_stride + w) = + (((val & 0xF0) >> 4) | + ((val & 0x0F) << 4)); + } + } +#else + GLuint *s = ((GLuint *) void_dst); + GLuint val; + + for (z = 0 ; z < (height / 4) ; z++) { + for (w = 0 ; w < (width / 4) ; w++) { + val = *(s + z * dst_stride + w); + *(s + z * dst_stride + w) = + (((val & 0xFF000000) >> 24) | + ((val & 0x00FF0000) >> 8) | + ((val & 0x0000FF00) << 8) | + ((val & 0x000000FF) << 24)); + } + } +#endif + } + + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei i, my_width; + const GLuint *s = ((const GLuint *) void_dst); + + printf("\n%s:\n\n", __FUNCTION__); + if (_mesa_format_is_mesa_array_format(dst_format)) + printf("Destination format is 0x%08X\n\n", dst_format); + else + printf("Destination format is %s (%d)\n\n", + _mesa_get_format_name(dst_format), dst_format); + my_width = (width > 16 ? 16 : width); + for (i = 0; i < my_width; i++) { + printf("0x%08x ", s[i]); + if ((i+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } } static const uint8_t map_identity[7] = { 0, 1, 2, 3, 4, 5, 6 }; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index e4a3036437..52dc8f5a55 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4605,7 +4605,8 @@ enum _verbose VERBOSE_VERTS = 0x0800, VERBOSE_DISASSEM = 0x1000, VERBOSE_DRAW = 0x2000, - VERBOSE_SWAPBUFFERS = 0x4000 + VERBOSE_SWAPBUFFERS = 0x4000, + VERBOSE_DUMPBUFFERS = 0x8000 }; diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c index 882d863c1c..319d8c45e3 100644 --- a/src/mesa/main/readpix.c +++ b/src/mesa/main/readpix.c @@ -289,6 +289,20 @@ read_uint_depth_pixels( struct gl_context *ctx, dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, 0); + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei i, my_width; + const GLuint *s = ((const GLuint *) map); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (i = 0; i < my_width; i++) { + printf("0x%08x ", s[i]); + if ((i+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + for (j = 0; j < height; j++) { _mesa_unpack_uint_z_row(rb->Format, width, map, (GLuint *)dst); @@ -345,6 +359,19 @@ read_depth_pixels( struct gl_context *ctx, depthValues = malloc(width * sizeof(GLfloat)); if (depthValues) { + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei i, my_width; + const GLuint *s = ((const GLuint *) map); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (i = 0; i < my_width; i++) { + printf("0x%08x ", s[i]); + if ((i+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } /* General case (slower) */ for (j = 0; j < height; j++, y++) { _mesa_unpack_float_z_row(rb->Format, width, map, depthValues); @@ -652,6 +679,20 @@ fast_read_depth_stencil_pixels(struct gl_context *ctx, return GL_TRUE; /* don't bother trying the slow path */ } + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei j, my_width; + const GLuint *s = ((const GLuint *) map); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (j = 0; j < my_width; j++) { + printf("0x%08x ", s[j]); + if ((j+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + for (i = 0; i < height; i++) { _mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width, map, (GLuint *)dst); diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index 48f6086708..4d3d76f685 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -1006,6 +1006,20 @@ store_texsubimage(struct gl_context *ctx, if (!src) return; + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei w, j, my_width; + const GLuint *s = ((const GLuint *) src); + + printf("\n%s:\n\n", __FUNCTION__); + + my_width = (width > 16 ? 16 : width); + for (w = 0; w < my_width; w++) { + for (j = 0 ; j < 4 ; j++) + printf("0x%08x ", s[w * 4 + j]); + printf("\n"); + } + } + /* compute slice info (and do some sanity checks) */ switch (target) { case GL_TEXTURE_2D: diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 362cef4628..52ed3763c6 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -372,7 +372,6 @@ is_stencil_masked(struct gl_context *ctx, struct gl_renderbuffer *rb) return (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax; } - /** * Called via ctx->Driver.Clear() */ diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c3e05bbb7c..738cf60e03 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -387,6 +387,9 @@ make_texture(struct st_context *st, struct pipe_resource *pt = NULL; enum pipe_format pipeFormat; GLenum baseInternalFormat; + char *swap_bytes; + + swap_bytes = getenv("SWAP_BYTES"); #if USE_DRAWPIXELS_CACHE const GLint bpp = _mesa_bytes_per_pixel(format, type); @@ -508,6 +511,23 @@ make_texture(struct st_context *st, unpack); } + if (swap_bytes) { + int z, w; + GLuint *s = ((GLuint *) dest); + GLuint val; + + for (z = 0 ; z < (height / 4) ; z++) { + for (w = 0 ; w < (width / 4) ; w++) { + val = *(s + z * (width / 4) + w); + *(s + z * (width / 4) + w) = + (((val & 0xFF000000) >> 24) | + ((val & 0x00FF0000) >> 8) | + ((val & 0x0000FF00) << 8) | + ((val & 0x000000FF) << 24)); + } + } + } + /* unmap */ pipe_transfer_unmap(pipe, transfer); @@ -1124,6 +1144,20 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y, PIPE_SHADER_FRAGMENT); } + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei i, my_width; + const GLuint *s = ((const GLuint *) pixels); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (i = 0; i < my_width; i++) { + printf("0x%08x ", s[i]); + if ((i+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + /* Put glDrawPixels image into a texture */ pt = make_texture(st, width, height, format, type, unpack, pixels); if (!pt) { @@ -1223,6 +1257,20 @@ copy_stencil_pixels(struct gl_context *ctx, GLint srcx, GLint srcy, } } + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei i, my_width; + const GLuint *s = ((const GLuint *) buffer); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (i = 0; i < my_width; i++) { + printf("0x%08x ", s[i]); + if ((i+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + if (_mesa_is_format_packed_depth_stencil(rbDraw->Base.Format)) usage = PIPE_TRANSFER_READ_WRITE; else @@ -1431,6 +1479,9 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, GLboolean invertTex = GL_FALSE; GLint readX, readY, readW, readH; struct gl_pixelstore_attrib pack = ctx->DefaultPacking; + char *prints; + + prints = getenv("PRINTS"); st_flush_bitmap_cache(st); @@ -1574,6 +1625,12 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy, if (!pt) return; + if (prints) + printf("%s : source format is %s (%d), dest format is %s (%d)\n", + __FUNCTION__, + util_format_name(srcFormat), srcFormat, + util_format_name(pt->format), pt->format); + sv[0] = st_create_texture_sampler_view(st->pipe, pt); if (!sv[0]) { pipe_resource_reference(&pt, NULL); diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 393b881ea4..1849e2c3b2 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -232,6 +232,24 @@ st_ReadPixels(struct gl_context *ctx, GLint x, GLint y, goto fallback; } + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei j, my_width; + const GLuint *s = ((const GLuint *) map); + + printf("\n%s:\n\n", __FUNCTION__); + printf("Source format is %s (%d)\n", + util_format_name(src_format), src_format); + printf("Destination format is %s (%d)\n\n", + util_format_name(dst_format), dst_format); + my_width = (width > 16 ? 16 : width); + for (j = 0; j < my_width; j++) { + printf("0x%08x ", s[j]); + if ((j+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + /* memcpy data into a user buffer */ { const uint bytesPerRow = width * util_format_get_blocksize(dst_format); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index a18b08b322..e4acd2bcd3 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1698,6 +1698,9 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims, GLenum gl_target = texImage->TexObject->Target; unsigned bind; GLubyte *map; + char *prints; + + prints = getenv("PRINTS"); assert(!_mesa_is_format_etc2(texImage->TexFormat) && texImage->TexFormat != MESA_FORMAT_ETC1_RGB8); @@ -1764,6 +1767,12 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims, goto fallback; } + if (prints) + printf("%s : source format is %s (%d), dest format is %s (%d)\n", + __FUNCTION__, + util_format_name(src_format), src_format, + util_format_name(dst_format), dst_format); + mesa_src_format = st_pipe_format_to_mesa_format(src_format); /* There is no reason to do this if we cannot use memcpy for the temporary @@ -1820,6 +1829,20 @@ st_TexSubImage(struct gl_context *ctx, GLuint dims, return; } + if (MESA_VERBOSE & VERBOSE_DUMPBUFFERS) { + GLsizei j, my_width; + const GLuint *s = ((const GLuint *) pixels); + + printf("\n%s:\n\n", __FUNCTION__); + my_width = (width > 16 ? 16 : width); + for (j = 0; j < my_width; j++) { + printf("0x%08x ", s[j]); + if ((j+1) % 4 == 0) + printf("\n"); + } + printf("\n"); + } + /* From now on, we need the gallium representation of dimensions. */ if (gl_target == GL_TEXTURE_1D_ARRAY) { zoffset = yoffset; |