X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_cb_accum.c;h=2fc37343bdfc1a392ff7ce035529029cad1d2af2;hb=4fb2daf42c8171579cdc18605c5ceeb1963f8b31;hp=cf2e9db51cb410404f45c1a7c36f9d35ac3a51eb;hpb=6c14cf58343135491068e96575bf4e61a6d34c87;p=mesa.git diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index cf2e9db51cb..01aba3e3dd4 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -34,19 +34,17 @@ #include "main/image.h" #include "main/macros.h" +#include "st_debug.h" #include "st_context.h" -#include "st_cache.h" #include "st_cb_accum.h" #include "st_cb_fbo.h" -#include "st_draw.h" -#include "st_format.h" +#include "st_public.h" +#include "st_texture.h" +#include "st_inlines.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" -#include "pipe/p_inlines.h" - - -#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \ - us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) ) +#include "util/u_inlines.h" +#include "util/u_tile.h" /** @@ -60,246 +58,229 @@ void st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) { struct st_renderbuffer *acc_strb = st_renderbuffer(rb); - struct pipe_surface *acc_ps = acc_strb->surface; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; - const GLfloat r = ctx->Accum.ClearColor[0]; - const GLfloat g = ctx->Accum.ClearColor[1]; - const GLfloat b = ctx->Accum.ClearColor[2]; - const GLfloat a = ctx->Accum.ClearColor[3]; - - (void) pipe_surface_map(acc_ps); + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; - switch (acc_ps->format) { + if(!data) + return; + + switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: { - const short sr = (short) (32767 * r); - const short sg = (short) (32767 * g); - const short sb = (short) (32767 * b); - const short sa = (short) (32767 * a); - short *acc = ((short *) acc_ps->map) - + (ypos * acc_ps->pitch + xpos) * 4; + GLshort r = FLOAT_TO_SHORT(ctx->Accum.ClearColor[0]); + GLshort g = FLOAT_TO_SHORT(ctx->Accum.ClearColor[1]); + GLshort b = FLOAT_TO_SHORT(ctx->Accum.ClearColor[2]); + GLshort a = FLOAT_TO_SHORT(ctx->Accum.ClearColor[3]); int i, j; for (i = 0; i < height; i++) { + GLshort *dst = (GLshort *) (data + (ypos + i) * stride + xpos * 8); for (j = 0; j < width; j++) { - acc[j*4+0] = sr; - acc[j*4+1] = sg; - acc[j*4+2] = sb; - acc[j*4+3] = sa; + dst[0] = r; + dst[1] = g; + dst[2] = b; + dst[3] = a; + dst += 4; } - acc += acc_ps->pitch * 4; } } break; default: - assert(0); + _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()"); } - - pipe_surface_unmap(acc_ps); } -/** Get block of values from accum buffer, converting to float */ +/** For ADD/MULT */ static void -get_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - float *buf) +accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, + GLint xpos, GLint ypos, GLint width, GLint height, + struct st_renderbuffer *acc_strb) { - switch (acc_surf->format) { + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; + + switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: { - const short *acc = ((const short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; int i, j; for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - buf[j*4+0] = SHORT_TO_FLOAT(acc[j*4+0]); - buf[j*4+1] = SHORT_TO_FLOAT(acc[j*4+1]); - buf[j*4+2] = SHORT_TO_FLOAT(acc[j*4+2]); - buf[j*4+3] = SHORT_TO_FLOAT(acc[j*4+3]); + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width * 4; j++) { + float val = SHORT_TO_FLOAT(*acc) * scale + bias; + *acc++ = FLOAT_TO_SHORT(val); } - acc += acc_surf->pitch * 4; - buf += width * 4; } } break; default: - assert(0); + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } } -/** Put block of values into accum buffer, converting from float */ static void -put_accum_tile(struct pipe_context *pipe, - struct pipe_surface *acc_surf, - int xpos, int ypos, int width, int height, - const float *buf) +accum_accum(struct st_context *st, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height, + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { - switch (acc_surf->format) { + struct pipe_context *pipe = st->pipe; + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; + GLfloat *buf; + + if (ST_DEBUG & DEBUG_FALLBACK) + debug_printf("%s: fallback processing\n", __FUNCTION__); + + color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); + + buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); + + switch (acc_strb->format) { case PIPE_FORMAT_R16G16B16A16_SNORM: { - short *acc = ((short *) acc_surf->map) - + (ypos * acc_surf->pitch + xpos) * 4; + const GLfloat *color = buf; int i, j; for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - short r, g, b, a; - UNCLAMPED_FLOAT_TO_SHORT(r, buf[j*4+0]); - UNCLAMPED_FLOAT_TO_SHORT(g, buf[j*4+1]); - UNCLAMPED_FLOAT_TO_SHORT(b, buf[j*4+2]); - UNCLAMPED_FLOAT_TO_SHORT(a, buf[j*4+3]); - acc[j*4+0] = r; - acc[j*4+1] = g; - acc[j*4+2] = b; - acc[j*4+3] = a; + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width * 4; j++) { + float val = *color++ * value; + *acc++ += FLOAT_TO_SHORT(val); } - acc += acc_surf->pitch * 4; - buf += width * 4; } } break; default: - assert(0); - } -} - - -/** For ADD/MULT */ -static void -accum_mad(struct pipe_context *pipe, GLfloat scale, GLfloat bias, - GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps) -{ - GLfloat *accBuf; - GLint i; - - accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - - (void) pipe_surface_map(acc_ps); - - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); - - for (i = 0; i < 4 * width * height; i++) { - accBuf[i] = accBuf[i] * scale + bias; + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); - - free(accBuf); - - pipe_surface_unmap(acc_ps); + free(buf); + pipe->tex_transfer_destroy(pipe, color_trans); } static void -accum_accum(struct pipe_context *pipe, GLfloat value, - GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) +accum_load(struct st_context *st, GLfloat value, + GLint xpos, GLint ypos, GLint width, GLint height, + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { - ubyte *colorMap, *accMap; - GLfloat *colorBuf, *accBuf; - GLint i; - - colorBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - accBuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - - colorMap = pipe_surface_map(color_ps); - accMap = pipe_surface_map(acc_ps); - - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, colorBuf); - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); - - for (i = 0; i < 4 * width * height; i++) { - accBuf[i] = accBuf[i] + colorBuf[i] * value; - } - - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, accBuf); - - free(colorBuf); - free(accBuf); + struct pipe_context *pipe = st->pipe; + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + GLubyte *data = acc_strb->data; + GLfloat *buf; - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); -} + if (ST_DEBUG & DEBUG_FALLBACK) + debug_printf("%s: fallback processing\n", __FUNCTION__); -static void -accum_load(struct pipe_context *pipe, GLfloat value, - GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) -{ - GLfloat *buf; - GLint i; + color_trans = st_cond_flush_get_tex_transfer(st, color_strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, xpos, ypos, + width, height); buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); - - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, buf); + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); - for (i = 0; i < 4 * width * height; i++) { - buf[i] = buf[i] * value; + switch (acc_strb->format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + { + const GLfloat *color = buf; + int i, j; + for (i = 0; i < height; i++) { + GLshort *acc = (GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width * 4; j++) { + float val = *color++ * value; + *acc++ = FLOAT_TO_SHORT(val); + } + } + } + break; + default: + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - put_accum_tile(pipe, acc_ps, xpos, ypos, width, height, buf); - free(buf); - - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); + pipe->tex_transfer_destroy(pipe, color_trans); } static void accum_return(GLcontext *ctx, GLfloat value, GLint xpos, GLint ypos, GLint width, GLint height, - struct pipe_surface *acc_ps, - struct pipe_surface *color_ps) + struct st_renderbuffer *acc_strb, + struct st_renderbuffer *color_strb) { struct pipe_context *pipe = ctx->st->pipe; - const GLubyte *colormask = ctx->Color.ColorMask; - GLfloat *abuf, *cbuf = NULL; - GLint i, ch; - - abuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - - (void) pipe_surface_map(color_ps); - (void) pipe_surface_map(acc_ps); + const GLubyte *colormask = ctx->Color.ColorMask[0]; + enum pipe_transfer_usage usage; + struct pipe_transfer *color_trans; + size_t stride = acc_strb->stride; + const GLubyte *data = acc_strb->data; + GLfloat *buf; - get_accum_tile(pipe, acc_ps, xpos, ypos, width, height, abuf); + if (ST_DEBUG & DEBUG_FALLBACK) + debug_printf("%s: fallback processing\n", __FUNCTION__); - if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) { - cbuf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - pipe->get_tile_rgba(pipe, color_ps, xpos, ypos, width, height, cbuf); - } + buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - for (i = 0; i < width * height; i++) { - for (ch = 0; ch < 4; ch++) { - if (colormask[ch]) { - GLfloat val = abuf[i * 4 + ch] * value; - abuf[i * 4 + ch] = CLAMP(val, 0.0, 1.0); - } - else { - abuf[i * 4 + ch] = cbuf[i * 4 + ch]; + if (!colormask[0] || !colormask[1] || !colormask[2] || !colormask[3]) + usage = PIPE_TRANSFER_READ_WRITE; + else + usage = PIPE_TRANSFER_WRITE; + + color_trans = st_cond_flush_get_tex_transfer(st_context(ctx), + color_strb->texture, 0, 0, 0, + usage, + xpos, ypos, + width, height); + + if (usage & PIPE_TRANSFER_READ) + pipe_get_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); + + switch (acc_strb->format) { + case PIPE_FORMAT_R16G16B16A16_SNORM: + { + GLfloat *color = buf; + int i, j, ch; + for (i = 0; i < height; i++) { + const GLshort *acc = (const GLshort *) (data + (ypos + i) * stride + xpos * 8); + for (j = 0; j < width; j++) { + for (ch = 0; ch < 4; ch++) { + if (colormask[ch]) { + GLfloat val = SHORT_TO_FLOAT(*acc * value); + *color = CLAMP(val, 0.0f, 1.0f); + } + else { + /* No change */ + } + ++acc; + ++color; + } + } } } + break; + default: + _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - pipe->put_tile_rgba(pipe, color_ps, xpos, ypos, width, height, abuf); - - free(abuf); - if (cbuf) - free(cbuf); + pipe_put_tile_rgba(pipe, color_trans, 0, 0, width, height, buf); - pipe_surface_unmap(color_ps); - pipe_surface_unmap(acc_ps); + free(buf); + pipe->tex_transfer_destroy(pipe, color_trans); } @@ -307,43 +288,43 @@ static void st_Accum(GLcontext *ctx, GLenum op, GLfloat value) { struct st_context *st = ctx->st; - struct pipe_context *pipe = st->pipe; struct st_renderbuffer *acc_strb = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer); struct st_renderbuffer *color_strb = st_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); - struct pipe_surface *acc_ps = acc_strb->surface; - struct pipe_surface *color_ps = color_strb->surface; const GLint xpos = ctx->DrawBuffer->_Xmin; const GLint ypos = ctx->DrawBuffer->_Ymin; const GLint width = ctx->DrawBuffer->_Xmax - xpos; const GLint height = ctx->DrawBuffer->_Ymax - ypos; + if(!acc_strb->data) + return; + /* make sure color bufs aren't cached */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + st_flush( st, PIPE_FLUSH_RENDER_CACHE, NULL ); switch (op) { case GL_ADD: if (value != 0.0F) { - accum_mad(pipe, 1.0, value, xpos, ypos, width, height, acc_ps); + accum_mad(ctx, 1.0, value, xpos, ypos, width, height, acc_strb); } break; case GL_MULT: if (value != 1.0F) { - accum_mad(pipe, value, 0.0, xpos, ypos, width, height, acc_ps); + accum_mad(ctx, value, 0.0, xpos, ypos, width, height, acc_strb); } break; case GL_ACCUM: if (value != 0.0F) { - accum_accum(pipe, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_accum(st, value, xpos, ypos, width, height, acc_strb, color_strb); } break; case GL_LOAD: - accum_load(pipe, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_load(st, value, xpos, ypos, width, height, acc_strb, color_strb); break; case GL_RETURN: - accum_return(ctx, value, xpos, ypos, width, height, acc_ps, color_ps); + accum_return(ctx, value, xpos, ypos, width, height, acc_strb, color_strb); break; default: assert(0);