From 7255a5486dcb3acd5d7d267b9f546aff38685555 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 8 Nov 2009 22:01:17 +0100 Subject: r300: use accelerated emit for CopyTex[Sub]Image functions --- src/mesa/drivers/dri/r300/r300_texcopy.c | 162 +++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 src/mesa/drivers/dri/r300/r300_texcopy.c (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c new file mode 100644 index 0000000000..efbe7538b8 --- /dev/null +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2009 Maciej Cencora + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "radeon_common.h" +#include "r300_context.h" + +#include "main/image.h" +#include "main/teximage.h" +#include "main/texstate.h" +#include "drivers/common/meta.h" + +#include "radeon_mipmap_tree.h" +#include "r300_blit.h" +#include
+ +static GLboolean +do_copy_texsubimage(GLcontext *ctx, + GLenum target, GLint level, + struct radeon_tex_obj *tobj, + radeon_texture_image *timg, + GLint dstx, GLint dsty, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + struct r300_context *r300 = R300_CONTEXT(ctx); + struct radeon_renderbuffer *rrb; + + if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) || + _mesa_get_format_bits(timg->base.TexFormat, GL_STENCIL_BITS)) { + rrb = radeon_get_depthbuffer(&r300->radeon); + return GL_FALSE; + } else { + rrb = radeon_get_colorbuffer(&r300->radeon); + } + + assert(rrb && rrb->bo); + assert(timg->mt && timg->mt->bo); + assert(timg->base.Width >= dstx + width); + assert(timg->base.Height >= dsty + height); + assert(tobj->mt == timg->mt); + + intptr_t src_offset = rrb->draw_offset + x * rrb->cpp + y * rrb->pitch; + intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level); + dst_offset += dstx * _mesa_get_format_bytes(timg->base.TexFormat) + + dsty * _mesa_format_row_stride(timg->base.TexFormat, timg->base.Width); + + if (0) { + fprintf(stderr, "%s: copying to face %d, level %d\n", + __FUNCTION__, _mesa_tex_target_to_face(target), level); + fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset); + fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d, width %d\n", + x, y, width, height, (uint32_t) src_offset, rrb->pitch, rrb->pitch/rrb->cpp); + + } + + /* blit from src buffer to texture */ + return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch, + width, height, timg->mt->bo, dst_offset, + timg->base.TexFormat, width, height); +} + +static void +r300CopyTexImage2D(GLcontext *ctx, GLenum target, GLint level, + GLenum internalFormat, + GLint x, GLint y, GLsizei width, GLsizei height, + GLint border) +{ + struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); + struct gl_texture_object *texObj = + _mesa_select_tex_object(ctx, texUnit, target); + struct gl_texture_image *texImage = + _mesa_select_tex_image(ctx, texObj, target, level); + int srcx, srcy, dstx, dsty; + + if (border) + goto fail; + + /* Setup or redefine the texture object, mipmap tree and texture + * image. Don't populate yet. + */ + ctx->Driver.TexImage2D(ctx, target, level, internalFormat, + width, height, border, + GL_RGBA, GL_UNSIGNED_BYTE, NULL, + &ctx->DefaultPacking, texObj, texImage); + + srcx = x; + srcy = y; + dstx = 0; + dsty = 0; + if (!_mesa_clip_copytexsubimage(ctx, + &dstx, &dsty, + &srcx, &srcy, + &width, &height)) { + return; + } + + if (!do_copy_texsubimage(ctx, target, level, + radeon_tex_obj(texObj), (radeon_texture_image *)texImage, + 0, 0, x, y, width, height)) { + goto fail; + } + + return; + +fail: + _mesa_meta_CopyTexImage2D(ctx, target, level, internalFormat, x, y, + width, height, border); +} + +static void +r300CopyTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, + GLsizei width, GLsizei height) +{ + struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); + struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); + struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); + + assert(target == GL_TEXTURE_2D); + + if (!do_copy_texsubimage(ctx, target, level, + radeon_tex_obj(texObj), (radeon_texture_image *)texImage, + xoffset, yoffset, x, y, width, height)) { + + //DEBUG_FALLBACKS + + _mesa_meta_CopyTexSubImage2D(ctx, target, level, + xoffset, yoffset, x, y, width, height); + } +} + + +void r300_init_texcopy_functions(struct dd_function_table *table) +{ + table->CopyTexImage2D = r300CopyTexImage2D; + table->CopyTexSubImage2D = r300CopyTexSubImage2D; +} \ No newline at end of file -- cgit v1.2.3 From cd5f167353f16fb4f5b349002625b704f3e23778 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Mon, 9 Nov 2009 23:01:35 +0100 Subject: blit WIP --- src/mesa/drivers/dri/r300/r300_blit.c | 15 ++++++++++++--- src/mesa/drivers/dri/r300/r300_texcopy.c | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index 7cb6f36c02..515a85caa2 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -424,10 +424,16 @@ GLboolean r300_blit(struct r300_context *r300, unsigned dst_width, unsigned dst_height) { - assert(src_width == dst_width); - assert(src_height == dst_height); + //assert(src_width == dst_width); + //assert(src_height == dst_height); - if (0) { + if (src_bo == dst_bo) { + return GL_FALSE; + } + + //return GL_FALSE; + + if (1) { fprintf(stderr, "src: width %d, height %d, pitch %d vs %d, format %s\n", src_width, src_height, src_pitch, _mesa_format_row_stride(src_mesaformat, src_width), @@ -441,6 +447,8 @@ GLboolean r300_blit(struct r300_context *r300, if (!validate_buffers(r300, src_bo, dst_bo)) return GL_FALSE; + rcommonEnsureCmdBufSpace(&r300->radeon, 200, __FUNCTION__); + other_stuff(r300); r300_emit_tx_setup(r300, src_mesaformat, src_bo, src_offset, src_width, src_height, src_pitch); @@ -463,6 +471,7 @@ GLboolean r300_blit(struct r300_context *r300, r300EmitCacheFlush(r300); radeonFlush(r300->radeon.glCtx); + //r300ResetHwState(r300); return GL_TRUE; } \ No newline at end of file diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index efbe7538b8..039276eacc 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -57,29 +57,38 @@ do_copy_texsubimage(GLcontext *ctx, rrb = radeon_get_colorbuffer(&r300->radeon); } + if (!timg->mt) { + radeon_validate_texture_miptree(ctx, &tobj->base); + } + assert(rrb && rrb->bo); - assert(timg->mt && timg->mt->bo); + assert(timg->mt->bo); assert(timg->base.Width >= dstx + width); assert(timg->base.Height >= dsty + height); - assert(tobj->mt == timg->mt); + //assert(tobj->mt == timg->mt); intptr_t src_offset = rrb->draw_offset + x * rrb->cpp + y * rrb->pitch; intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level); dst_offset += dstx * _mesa_get_format_bytes(timg->base.TexFormat) + dsty * _mesa_format_row_stride(timg->base.TexFormat, timg->base.Width); - if (0) { + if (src_offset % 32 || dst_offset % 32) { + return GL_FALSE; + } + + if (1) { fprintf(stderr, "%s: copying to face %d, level %d\n", __FUNCTION__, _mesa_tex_target_to_face(target), level); fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset); fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d, width %d\n", x, y, width, height, (uint32_t) src_offset, rrb->pitch, rrb->pitch/rrb->cpp); + fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size); } /* blit from src buffer to texture */ return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch, - width, height, timg->mt->bo, dst_offset, + rrb->base.Width, rrb->base.Height, timg->mt->bo ? timg->mt->bo : timg->bo, dst_offset, timg->base.TexFormat, width, height); } @@ -141,8 +150,6 @@ r300CopyTexSubImage2D(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target); struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); - assert(target == GL_TEXTURE_2D); - if (!do_copy_texsubimage(ctx, target, level, radeon_tex_obj(texObj), (radeon_texture_image *)texImage, xoffset, yoffset, x, y, width, height)) { -- cgit v1.2.3 From c1a7cc1e44e2c318eaa1de67893d20774f6fec5f Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Tue, 10 Nov 2009 19:47:04 +0100 Subject: more blit fixes --- src/mesa/drivers/dri/r300/r300_blit.c | 2 ++ src/mesa/drivers/dri/r300/r300_texcopy.c | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index 515a85caa2..b4c4b9c9cc 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -218,6 +218,8 @@ static uint32_t mesa_format_to_us_format(gl_format mesa_format) { switch(mesa_format) { + case MESA_FORMAT_S8_Z24: + case MESA_FORMAT_X8_Z24: case MESA_FORMAT_RGBA8888: // x return EASY_US_FORMAT(R500_OUT_FMT_C4_8, A, B, G, R, 0); case MESA_FORMAT_RGB565: // x diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index 039276eacc..1e10c7326c 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -49,10 +49,8 @@ do_copy_texsubimage(GLcontext *ctx, struct r300_context *r300 = R300_CONTEXT(ctx); struct radeon_renderbuffer *rrb; - if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) || - _mesa_get_format_bits(timg->base.TexFormat, GL_STENCIL_BITS)) { + if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) > 0) { rrb = radeon_get_depthbuffer(&r300->radeon); - return GL_FALSE; } else { rrb = radeon_get_colorbuffer(&r300->radeon); } -- cgit v1.2.3 From 784cca9fa527de771754d76545970f78094b9adf Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sat, 12 Dec 2009 00:50:26 +0100 Subject: r300: disable blit debugging info --- src/mesa/drivers/dri/r300/r300_blit.c | 2 +- src/mesa/drivers/dri/r300/r300_texcopy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index 4c3d3c8069..10e1b3c912 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -480,7 +480,7 @@ GLboolean r300_blit(struct r300_context *r300, //return GL_FALSE; - if (1) { + if (0) { fprintf(stderr, "src: width %d, height %d, pitch %d vs %d, format %s\n", src_width, src_height, src_pitch, _mesa_format_row_stride(src_mesaformat, src_width), diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index 1e10c7326c..5e3a724d4e 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -74,7 +74,7 @@ do_copy_texsubimage(GLcontext *ctx, return GL_FALSE; } - if (1) { + if (0) { fprintf(stderr, "%s: copying to face %d, level %d\n", __FUNCTION__, _mesa_tex_target_to_face(target), level); fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset); -- cgit v1.2.3 From 9d8501bf2742519cc958c5f32122e196b64f8278 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sun, 13 Dec 2009 16:12:11 +0100 Subject: r300: fix glCopyTexSubImage Need to properly setup colorbuffer when dst pitch != dst width. --- src/mesa/drivers/dri/r300/r300_blit.c | 12 ++++-------- src/mesa/drivers/dri/r300/r300_blit.h | 1 + src/mesa/drivers/dri/r300/r300_texcopy.c | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index 10e1b3c912..ff678bac45 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -428,6 +428,7 @@ static void emit_cb_setup(struct r300_context *r300, struct radeon_bo *bo, intptr_t offset, gl_format mesa_format, + unsigned pitch, unsigned width, unsigned height) { @@ -448,7 +449,7 @@ static void emit_cb_setup(struct r300_context *r300, r300_emit_cb_setup(r300, bo, offset, mesa_format, _mesa_get_format_bytes(mesa_format), - _mesa_format_row_stride(mesa_format, width)); + _mesa_format_row_stride(mesa_format, pitch)); BEGIN_BATCH_NO_AUTOSTATE(5); OUT_BATCH_REGSEQ(R300_SC_SCISSORS_TL, 2); @@ -468,18 +469,14 @@ GLboolean r300_blit(struct r300_context *r300, struct radeon_bo *dst_bo, intptr_t dst_offset, gl_format dst_mesaformat, + unsigned dst_pitch, unsigned dst_width, unsigned dst_height) { - //assert(src_width == dst_width); - //assert(src_height == dst_height); - if (src_bo == dst_bo) { return GL_FALSE; } - //return GL_FALSE; - if (0) { fprintf(stderr, "src: width %d, height %d, pitch %d vs %d, format %s\n", src_width, src_height, src_pitch, @@ -511,14 +508,13 @@ GLboolean r300_blit(struct r300_context *r300, emit_pvs_setup(r300, r300->blit.vp_code.body.d, 2); emit_vap_setup(r300, dst_width, dst_height); - emit_cb_setup(r300, dst_bo, dst_offset, dst_mesaformat, dst_width, dst_height); + emit_cb_setup(r300, dst_bo, dst_offset, dst_mesaformat, dst_pitch, dst_width, dst_height); emit_draw_packet(r300, dst_width, dst_height); r300EmitCacheFlush(r300); radeonFlush(r300->radeon.glCtx); - //r300ResetHwState(r300); return GL_TRUE; } \ No newline at end of file diff --git a/src/mesa/drivers/dri/r300/r300_blit.h b/src/mesa/drivers/dri/r300/r300_blit.h index 29c5aa9514..28ffd4ea42 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.h +++ b/src/mesa/drivers/dri/r300/r300_blit.h @@ -40,6 +40,7 @@ GLboolean r300_blit(struct r300_context *r300, struct radeon_bo *dst_bo, intptr_t dst_offset, gl_format dst_mesaformat, + unsigned dst_pitch, unsigned dst_width, unsigned dst_height); diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index 5e3a724d4e..7702a1d67d 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -63,7 +63,6 @@ do_copy_texsubimage(GLcontext *ctx, assert(timg->mt->bo); assert(timg->base.Width >= dstx + width); assert(timg->base.Height >= dsty + height); - //assert(tobj->mt == timg->mt); intptr_t src_offset = rrb->draw_offset + x * rrb->cpp + y * rrb->pitch; intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level); @@ -87,7 +86,7 @@ do_copy_texsubimage(GLcontext *ctx, /* blit from src buffer to texture */ return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch, rrb->base.Width, rrb->base.Height, timg->mt->bo ? timg->mt->bo : timg->bo, dst_offset, - timg->base.TexFormat, width, height); + timg->base.TexFormat, timg->base.Width, width, height); } static void -- cgit v1.2.3 From a1428868a66ab70a762ad863dafa00c3099f3d8a Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Tue, 15 Dec 2009 23:57:05 +0100 Subject: r300: better fix for glCopyTexSubImage --- src/mesa/drivers/dri/r300/r300_blit.c | 32 +++++++++++++++++++------------- src/mesa/drivers/dri/r300/r300_texcopy.c | 6 +++--- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index ca6dd3bcf8..d03fbfa07d 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -162,7 +162,7 @@ static void r300_emit_tx_setup(struct r300_context *r300, R300_TX_SIZE_TXPITCH_EN); OUT_BATCH_REGVAL(R300_TX_FORMAT_0, r300TranslateTexFormat(mesa_format)); - OUT_BATCH_REGVAL(R300_TX_FORMAT2_0, pitch/_mesa_get_format_bytes(mesa_format) - 1); + OUT_BATCH_REGVAL(R300_TX_FORMAT2_0, pitch - 1); OUT_BATCH_REGSEQ(R300_TX_OFFSET_0, 1); OUT_BATCH_RELOC(0, bo, offset, RADEON_GEM_DOMAIN_GTT|RADEON_GEM_DOMAIN_VRAM, 0, 0); @@ -339,7 +339,7 @@ static void emit_pvs_setup(struct r300_context *r300, END_BATCH(); } -static void emit_vap_setup(struct r300_context *r300, unsigned width, unsigned height) +static void emit_vap_setup(struct r300_context *r300) { BATCH_LOCALS(&r300->radeon); @@ -389,12 +389,14 @@ static GLboolean validate_buffers(struct r300_context *r300, return GL_TRUE; } -static void emit_draw_packet(struct r300_context *r300, float width, float height) +static void emit_draw_packet(struct r300_context *r300, + float src_width, float src_height, + float dst_width, float dst_height) { - float verts[] = { 0.0, 0.0, 0.0, 1.0, - 0.0, height, 0.0, 0.0, - width, height, 1.0, 0.0, - width, 0.0, 1.0, 1.0 }; + float verts[] = { 0.0, 0.0, 0.0, 1.0, + 0.0, dst_height, 0.0, 1.0 - dst_height/src_height, + dst_width, dst_height, dst_width/src_width, 1.0 - dst_height/src_height, + dst_width, 0.0, dst_width/src_width, 1.0 }; BATCH_LOCALS(&r300->radeon); @@ -473,18 +475,22 @@ GLboolean r300_blit(struct r300_context *r300, unsigned dst_width, unsigned dst_height) { + /* Need to clamp the destination size to make sure + * we don't write outside of the buffer + */ + dst_width = MIN2(dst_width, src_width); + dst_height = MIN2(src_height, dst_height); + if (src_bo == dst_bo) { return GL_FALSE; } if (0) { - fprintf(stderr, "src: width %d, height %d, pitch %d vs %d, format %s\n", + fprintf(stderr, "src: width %d, height %d, pitch %d, format %s\n", src_width, src_height, src_pitch, - _mesa_format_row_stride(src_mesaformat, src_width), _mesa_get_format_name(src_mesaformat)); fprintf(stderr, "dst: width %d, height %d, pitch %d, format %s\n", - dst_width, dst_height, - _mesa_format_row_stride(dst_mesaformat, dst_width), + dst_width, dst_height, dst_pitch, _mesa_get_format_name(dst_mesaformat)); } @@ -506,11 +512,11 @@ GLboolean r300_blit(struct r300_context *r300, } emit_pvs_setup(r300, r300->blit.vp_code.body.d, 2); - emit_vap_setup(r300, dst_width, dst_height); + emit_vap_setup(r300); emit_cb_setup(r300, dst_bo, dst_offset, dst_mesaformat, dst_pitch, dst_width, dst_height); - emit_draw_packet(r300, dst_width, dst_height); + emit_draw_packet(r300, src_width, src_height, dst_width, dst_height); r300EmitCacheFlush(r300); diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index 7702a1d67d..893c8586f7 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -77,14 +77,14 @@ do_copy_texsubimage(GLcontext *ctx, fprintf(stderr, "%s: copying to face %d, level %d\n", __FUNCTION__, _mesa_tex_target_to_face(target), level); fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset); - fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d, width %d\n", - x, y, width, height, (uint32_t) src_offset, rrb->pitch, rrb->pitch/rrb->cpp); + fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d\n", + x, y, rrb->base.Width, rrb->base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp); fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size); } /* blit from src buffer to texture */ - return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch, + return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch/rrb->cpp, rrb->base.Width, rrb->base.Height, timg->mt->bo ? timg->mt->bo : timg->bo, dst_offset, timg->base.TexFormat, timg->base.Width, width, height); } -- cgit v1.2.3 From 4b6dee08652706d02939844fe209cddbae8966e4 Mon Sep 17 00:00:00 2001 From: Maciej Cencora Date: Sat, 19 Dec 2009 14:25:53 +0100 Subject: r300: minor blit rework Use vert/tex coords instead of byte offsets for specyfing src/dst image offsets. This will allow for blitting between tiled/untiled buffers. --- src/mesa/drivers/dri/r300/r300_blit.c | 115 ++++++++++++++++++++++++++----- src/mesa/drivers/dri/r300/r300_blit.h | 9 ++- src/mesa/drivers/dri/r300/r300_texcopy.c | 12 ++-- 3 files changed, 113 insertions(+), 23 deletions(-) (limited to 'src/mesa/drivers/dri/r300/r300_texcopy.c') diff --git a/src/mesa/drivers/dri/r300/r300_blit.c b/src/mesa/drivers/dri/r300/r300_blit.c index d03fbfa07d..ea626d942d 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.c +++ b/src/mesa/drivers/dri/r300/r300_blit.c @@ -389,14 +389,49 @@ static GLboolean validate_buffers(struct r300_context *r300, return GL_TRUE; } +/** + * Calculate texcoords for given image region. + * Output values are [minx, maxx, miny, maxy] + */ +static void calc_tex_coords(float img_width, float img_height, + float x, float y, + float reg_width, float reg_height, + unsigned flip_y, float *buf) +{ + buf[0] = x / img_width; + buf[1] = buf[0] + reg_width / img_width; + buf[2] = y / img_height; + buf[3] = buf[2] + reg_height / img_height; + if (flip_y) + { + float tmp = buf[2]; + buf[2] = 1.0 - buf[3]; + buf[3] = 1.0 - tmp; + } +} + static void emit_draw_packet(struct r300_context *r300, - float src_width, float src_height, - float dst_width, float dst_height) + unsigned src_width, unsigned src_height, + unsigned src_x_offset, unsigned src_y_offset, + unsigned dst_x_offset, unsigned dst_y_offset, + unsigned reg_width, unsigned reg_height, + unsigned flip_y) { - float verts[] = { 0.0, 0.0, 0.0, 1.0, - 0.0, dst_height, 0.0, 1.0 - dst_height/src_height, - dst_width, dst_height, dst_width/src_width, 1.0 - dst_height/src_height, - dst_width, 0.0, dst_width/src_width, 1.0 }; + float texcoords[4]; + + calc_tex_coords(src_width, src_height, + src_x_offset, src_y_offset, + reg_width, reg_height, + flip_y, texcoords); + + float verts[] = { dst_x_offset, dst_y_offset, + texcoords[0], texcoords[3], + dst_x_offset, dst_y_offset + reg_height, + texcoords[0], texcoords[2], + dst_x_offset + reg_width, dst_y_offset + reg_height, + texcoords[1], texcoords[2], + dst_x_offset + reg_width, dst_y_offset, + texcoords[1], texcoords[3] }; BATCH_LOCALS(&r300->radeon); @@ -461,6 +496,30 @@ static void emit_cb_setup(struct r300_context *r300, END_BATCH(); } +/** + * Copy a region of [@a width x @a height] pixels from source buffer + * to destination buffer. + * @param[in] r300 r300 context + * @param[in] src_bo source radeon buffer object + * @param[in] src_offset offset of the source image in the @a src_bo + * @param[in] src_mesaformat source image format + * @param[in] src_pitch aligned source image width + * @param[in] src_width source image width + * @param[in] src_height source image height + * @param[in] src_x_offset x offset in the source image + * @param[in] src_y_offset y offset in the source image + * @param[in] dst_bo destination radeon buffer object + * @param[in] dst_offset offset of the destination image in the @a dst_bo + * @param[in] dst_mesaformat destination image format + * @param[in] dst_pitch aligned destination image width + * @param[in] dst_width destination image width + * @param[in] dst_height destination image height + * @param[in] dst_x_offset x offset in the destination image + * @param[in] dst_y_offset y offset in the destination image + * @param[in] width region width + * @param[in] height region height + * @param[in] flip_y set if y coords of the source image need to be flipped + */ GLboolean r300_blit(struct r300_context *r300, struct radeon_bo *src_bo, intptr_t src_offset, @@ -468,30 +527,48 @@ GLboolean r300_blit(struct r300_context *r300, unsigned src_pitch, unsigned src_width, unsigned src_height, + unsigned src_x_offset, + unsigned src_y_offset, struct radeon_bo *dst_bo, intptr_t dst_offset, gl_format dst_mesaformat, unsigned dst_pitch, unsigned dst_width, - unsigned dst_height) + unsigned dst_height, + unsigned dst_x_offset, + unsigned dst_y_offset, + unsigned reg_width, + unsigned reg_height, + unsigned flip_y) { - /* Need to clamp the destination size to make sure - * we don't write outside of the buffer + /* Need to clamp the region size to make sure + * we don't read outside of the source buffer + * or write outside of the destination buffer. */ - dst_width = MIN2(dst_width, src_width); - dst_height = MIN2(src_height, dst_height); + if (reg_width + src_x_offset > src_width) + reg_width = src_width - src_x_offset; + if (reg_height + src_y_offset > src_height) + reg_height = src_height - src_y_offset; + if (reg_width + dst_x_offset > dst_width) + reg_width = dst_width - dst_x_offset; + if (reg_height + dst_y_offset > dst_height) + reg_height = dst_height - dst_y_offset; if (src_bo == dst_bo) { return GL_FALSE; } if (0) { - fprintf(stderr, "src: width %d, height %d, pitch %d, format %s\n", + fprintf(stderr, "src: size [%d x %d], pitch %d, " + "offset [%d x %d], format %s, bo %p\n", src_width, src_height, src_pitch, - _mesa_get_format_name(src_mesaformat)); - fprintf(stderr, "dst: width %d, height %d, pitch %d, format %s\n", - dst_width, dst_height, dst_pitch, - _mesa_get_format_name(dst_mesaformat)); + src_offset, src_y_offset, + _mesa_get_format_name(src_mesaformat), + src_bo); + fprintf(stderr, "dst: pitch %d, offset[%d x %d], format %s, bo %p\n", + dst_pitch, dst_x_offset, dst_y_offset, + _mesa_get_format_name(dst_mesaformat), dst_bo); + fprintf(stderr, "region: %d x %d\n", reg_width, reg_height); } if (!validate_buffers(r300, src_bo, dst_bo)) @@ -516,7 +593,11 @@ GLboolean r300_blit(struct r300_context *r300, emit_cb_setup(r300, dst_bo, dst_offset, dst_mesaformat, dst_pitch, dst_width, dst_height); - emit_draw_packet(r300, src_width, src_height, dst_width, dst_height); + emit_draw_packet(r300, src_width, src_height, + src_x_offset, src_y_offset, + dst_x_offset, dst_y_offset, + reg_width, reg_height, + flip_y); r300EmitCacheFlush(r300); diff --git a/src/mesa/drivers/dri/r300/r300_blit.h b/src/mesa/drivers/dri/r300/r300_blit.h index 28ffd4ea42..dc21e88098 100644 --- a/src/mesa/drivers/dri/r300/r300_blit.h +++ b/src/mesa/drivers/dri/r300/r300_blit.h @@ -37,11 +37,18 @@ GLboolean r300_blit(struct r300_context *r300, unsigned src_pitch, unsigned src_width, unsigned src_height, + unsigned src_x_offset, + unsigned src_y_offset, struct radeon_bo *dst_bo, intptr_t dst_offset, gl_format dst_mesaformat, unsigned dst_pitch, unsigned dst_width, - unsigned dst_height); + unsigned dst_height, + unsigned dst_x_offset, + unsigned dst_y_offset, + unsigned width, + unsigned height, + unsigned flip_y); #endif // R300_BLIT_H \ No newline at end of file diff --git a/src/mesa/drivers/dri/r300/r300_texcopy.c b/src/mesa/drivers/dri/r300/r300_texcopy.c index 893c8586f7..ebc9c05b8a 100644 --- a/src/mesa/drivers/dri/r300/r300_texcopy.c +++ b/src/mesa/drivers/dri/r300/r300_texcopy.c @@ -37,6 +37,8 @@ #include "r300_blit.h" #include
+// TODO: +// need to pass correct pitch for small dst textures! static GLboolean do_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level, @@ -64,10 +66,8 @@ do_copy_texsubimage(GLcontext *ctx, assert(timg->base.Width >= dstx + width); assert(timg->base.Height >= dsty + height); - intptr_t src_offset = rrb->draw_offset + x * rrb->cpp + y * rrb->pitch; + intptr_t src_offset = rrb->draw_offset; intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level); - dst_offset += dstx * _mesa_get_format_bytes(timg->base.TexFormat) + - dsty * _mesa_format_row_stride(timg->base.TexFormat, timg->base.Width); if (src_offset % 32 || dst_offset % 32) { return GL_FALSE; @@ -85,8 +85,10 @@ do_copy_texsubimage(GLcontext *ctx, /* blit from src buffer to texture */ return r300_blit(r300, rrb->bo, src_offset, rrb->base.Format, rrb->pitch/rrb->cpp, - rrb->base.Width, rrb->base.Height, timg->mt->bo ? timg->mt->bo : timg->bo, dst_offset, - timg->base.TexFormat, timg->base.Width, width, height); + rrb->base.Width, rrb->base.Height, x, y, + timg->mt->bo, dst_offset, timg->base.TexFormat, + timg->base.Width, timg->base.Width, timg->base.Height, + dstx, dsty, width, height, 1); } static void -- cgit v1.2.3