From 7ce99a11037e577e36480f3e29b2685b853f0330 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 11:18:31 -0600 Subject: Rename file since it's now a state atom --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 161 +++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 src/mesa/state_tracker/st_atom_pixeltransfer.c (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c new file mode 100644 index 0000000000..b1fce81755 --- /dev/null +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -0,0 +1,161 @@ +/************************************************************************** + * + * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * 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, sub license, 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 NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS 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. + * + **************************************************************************/ + +/* + * Generate fragment programs to implement pixel transfer ops, such as + * scale/bias, colormatrix, colortable, convolution... + * + * Authors: + * Brian Paul + */ + +#include "main/imports.h" +#include "main/image.h" +#include "main/macros.h" +#include "shader/program.h" +#include "shader/prog_instruction.h" +#include "shader/prog_parameter.h" +#include "shader/prog_print.h" + +#include "st_context.h" + + +#define MAX_INST 100 + +/** + * Returns a fragment program which implements the current pixel transfer ops. + */ +static struct gl_fragment_program * +get_pixel_transfer_program(GLcontext *ctx) +{ + struct prog_instruction inst[MAX_INST]; + struct gl_program_parameter_list *params; + struct gl_fragment_program *fp; + GLuint ic = 0; + + fp = (struct gl_fragment_program *) + ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); + if (!fp) + return NULL; + + params = _mesa_new_parameter_list(); + + /* TEX result.color, fragment.texcoord[0], texture[0], 2D; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_TEX; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].SrcReg[0].File = PROGRAM_INPUT; + inst[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; + inst[ic].TexSrcUnit = 0; + inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; + ic++; + fp->Base.InputsRead = (1 << FRAG_ATTRIB_TEX0); + fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); + + /* MAD result.color, result.color, scale, bias; */ + if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || + ctx->Pixel.GreenBias != 0.0 || ctx->Pixel.GreenScale != 1.0 || + ctx->Pixel.BlueBias != 0.0 || ctx->Pixel.BlueScale != 1.0 || + ctx->Pixel.AlphaBias != 0.0 || ctx->Pixel.AlphaScale != 1.0) { + GLfloat scale[4], bias[4]; + GLint scale_p, bias_p; + scale[0] = ctx->Pixel.RedScale; + scale[1] = ctx->Pixel.GreenScale; + scale[2] = ctx->Pixel.BlueScale; + scale[3] = ctx->Pixel.AlphaScale; + bias[0] = ctx->Pixel.RedBias; + bias[1] = ctx->Pixel.GreenBias; + bias[2] = ctx->Pixel.BlueBias; + bias[3] = ctx->Pixel.AlphaBias; + + scale_p = _mesa_add_named_constant(params, "RGBA_scale", scale, 4); + bias_p = _mesa_add_named_constant(params, "RGBA_bias", bias, 4); + + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MAD; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].SrcReg[0].File = PROGRAM_OUTPUT; + inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; + inst[ic].SrcReg[1].File = PROGRAM_CONSTANT; + inst[ic].SrcReg[1].Index = scale_p; + inst[ic].SrcReg[2].File = PROGRAM_CONSTANT; + inst[ic].SrcReg[2].Index = bias_p; + ic++; + } + + /* END; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_END; + ic++; + + assert(ic <= MAX_INST); + + + fp->Base.Instructions = _mesa_alloc_instructions(ic); + if (!fp->Base.Instructions) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, + "generating pixel transfer program"); + return NULL; + } + + _mesa_copy_instructions(fp->Base.Instructions, inst, ic); + fp->Base.NumInstructions = ic; + fp->Base.Parameters = params; + + printf("========= pixel transfer prog\n"); + _mesa_print_program(&fp->Base); + _mesa_print_parameter_list(fp->Base.Parameters); + + return fp; +} + + + +static void +update_pixel_transfer(struct st_context *st) +{ + /* XXX temporary - implement a program cache */ + GLcontext *ctx = st->ctx; + if (st->pixel_transfer_program) { + ctx->Driver.DeleteProgram(ctx, &st->pixel_transfer_program->Base); + } + + st->pixel_transfer_program = get_pixel_transfer_program(ctx); +} + + + +const struct st_tracked_state st_update_pixel_transfer = { + .name = "st_update_pixel_transfer", + .dirty = { + .mesa = _NEW_PIXEL, + .st = 0, + }, + .update = update_pixel_transfer +}; -- cgit v1.2.3 From ab3f6015aa7227da3137b60456deb3905680f95f Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 11:32:16 -0600 Subject: Disable debug code. Basic code for PixelTranslfer ops and glDrawPixels works now. A pixel transfer program is generated and combined with the current fragment shader. --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 ++ src/mesa/state_tracker/st_cb_drawpixels.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index b1fce81755..d3abf87d7d 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -128,9 +128,11 @@ get_pixel_transfer_program(GLcontext *ctx) fp->Base.NumInstructions = ic; fp->Base.Parameters = params; +#if 0 printf("========= pixel transfer prog\n"); _mesa_print_program(&fp->Base); _mesa_print_parameter_list(fp->Base.Parameters); +#endif return fp; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index ed0ef71192..ff7aa7d74b 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -184,15 +184,21 @@ make_drawpix_fragment_shader(struct st_context *st) struct st_fragment_program *stfp; struct gl_program *p; - printf("====== drawpix combine progs\n"); + /* + * XXX Use st_program's serial numbers to determine when the + * user-provided program and pixel-transfer program to avoid + * needless combining/translation here. + */ + p = _mesa_combine_programs(ctx, &st->pixel_transfer_program->Base, &ctx->FragmentProgram._Current->Base); - +#if 0 _mesa_print_program(p); printf("InputsRead: 0x%x\n", p->InputsRead); printf("OutputsWritten: 0x%x\n", p->OutputsWritten); _mesa_print_parameter_list(p->Parameters); +#endif stfp = (struct st_fragment_program *) p; st_translate_fragment_program(st, stfp, NULL, -- cgit v1.2.3 From 8aa42546add1fef4949e2d4ceded62e2d1dd0215 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 12:24:27 -0600 Subject: start using program cache --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 75 ++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index d3abf87d7d..f01196bee4 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -44,6 +44,60 @@ #include "st_context.h" + +struct state_key +{ + GLuint scaleAndBias:1; + GLuint colorMatrix:1; + +#if 0 + GLfloat Maps[3][256][4]; + int NumMaps; + GLint NumStages; + pipeline_stage Stages[STAGE_MAX]; + GLboolean StagesUsed[STAGE_MAX]; + GLfloat Scale1[4], Bias1[4]; + GLfloat Scale2[4], Bias2[4]; +#endif +}; + + +static GLboolean +is_identity(const GLfloat m[16]) +{ + GLuint i; + for (i = 0; i < 16; i++) { + const int row = i % 4, col = i / 4; + const float val = (row == col); + if (m[i] != val) + return GL_FALSE; + } + return GL_TRUE; +} + + +static void +make_state_key(GLcontext *ctx, struct state_key *key) +{ + /*GLuint i, j;*/ + + memset(key, 0, sizeof(*key)); + + if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || + ctx->Pixel.GreenBias != 0.0 || ctx->Pixel.GreenScale != 1.0 || + ctx->Pixel.BlueBias != 0.0 || ctx->Pixel.BlueScale != 1.0 || + ctx->Pixel.AlphaBias != 0.0 || ctx->Pixel.AlphaScale != 1.0) { + key->scaleAndBias = 1; + } + + if (!is_identity(ctx->ColorMatrixStack.Top->m)) { + key->colorMatrix = 1; + } +} + + + + #define MAX_INST 100 /** @@ -142,13 +196,24 @@ get_pixel_transfer_program(GLcontext *ctx) static void update_pixel_transfer(struct st_context *st) { - /* XXX temporary - implement a program cache */ - GLcontext *ctx = st->ctx; - if (st->pixel_transfer_program) { - ctx->Driver.DeleteProgram(ctx, &st->pixel_transfer_program->Base); + struct state_key key; + struct gl_fragment_program *fp; + + make_state_key(st->ctx, &key); + + fp = (struct gl_fragment_program *) + _mesa_search_program_cache(st->pixel_transfer_cache, &key, sizeof(key)); + if (!fp) { + printf("Cached program not found\n"); + fp = get_pixel_transfer_program(st->ctx); + _mesa_program_cache_insert(st->ctx, st->pixel_transfer_cache, + &key, sizeof(key), &fp->Base); + } + else { + printf("Use cached program\n"); } - st->pixel_transfer_program = get_pixel_transfer_program(ctx); + st->pixel_transfer_program = fp; } -- cgit v1.2.3 From 4836217850114e0972900a68fd7d93e2e241819b Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 13:54:24 -0600 Subject: color matrix --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 101 +++++++++++++++++++++---- 1 file changed, 86 insertions(+), 15 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index f01196bee4..b190c39343 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -104,7 +104,7 @@ make_state_key(GLcontext *ctx, struct state_key *key) * Returns a fragment program which implements the current pixel transfer ops. */ static struct gl_fragment_program * -get_pixel_transfer_program(GLcontext *ctx) +get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) { struct prog_instruction inst[MAX_INST]; struct gl_program_parameter_list *params; @@ -132,12 +132,14 @@ get_pixel_transfer_program(GLcontext *ctx) fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); /* MAD result.color, result.color, scale, bias; */ - if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || - ctx->Pixel.GreenBias != 0.0 || ctx->Pixel.GreenScale != 1.0 || - ctx->Pixel.BlueBias != 0.0 || ctx->Pixel.BlueScale != 1.0 || - ctx->Pixel.AlphaBias != 0.0 || ctx->Pixel.AlphaScale != 1.0) { + if (key->scaleAndBias) { + static const gl_state_index scale_state[STATE_LENGTH] = + { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; + static const gl_state_index bias_state[STATE_LENGTH] = + { STATE_INTERNAL, STATE_PT_BIAS, 0, 0, 0 }; GLfloat scale[4], bias[4]; GLint scale_p, bias_p; + scale[0] = ctx->Pixel.RedScale; scale[1] = ctx->Pixel.GreenScale; scale[2] = ctx->Pixel.BlueScale; @@ -147,8 +149,8 @@ get_pixel_transfer_program(GLcontext *ctx) bias[2] = ctx->Pixel.BlueBias; bias[3] = ctx->Pixel.AlphaBias; - scale_p = _mesa_add_named_constant(params, "RGBA_scale", scale, 4); - bias_p = _mesa_add_named_constant(params, "RGBA_bias", bias, 4); + scale_p = _mesa_add_state_reference(params, scale_state); + bias_p = _mesa_add_state_reference(params, bias_state); _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_MAD; @@ -156,13 +158,86 @@ get_pixel_transfer_program(GLcontext *ctx) inst[ic].DstReg.Index = FRAG_RESULT_COLR; inst[ic].SrcReg[0].File = PROGRAM_OUTPUT; inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; - inst[ic].SrcReg[1].File = PROGRAM_CONSTANT; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = scale_p; - inst[ic].SrcReg[2].File = PROGRAM_CONSTANT; + inst[ic].SrcReg[2].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[2].Index = bias_p; ic++; } + if (key->colorMatrix) { + static const gl_state_index row0_state[STATE_LENGTH] = + { STATE_COLOR_MATRIX, 0, 0, 0, 0 }; + static const gl_state_index row1_state[STATE_LENGTH] = + { STATE_COLOR_MATRIX, 0, 1, 1, 0 }; + static const gl_state_index row2_state[STATE_LENGTH] = + { STATE_COLOR_MATRIX, 0, 2, 2, 0 }; + static const gl_state_index row3_state[STATE_LENGTH] = + { STATE_COLOR_MATRIX, 0, 3, 3, 0 }; + + GLint row0_p = _mesa_add_state_reference(params, row0_state); + GLint row1_p = _mesa_add_state_reference(params, row1_state); + GLint row2_p = _mesa_add_state_reference(params, row2_state); + GLint row3_p = _mesa_add_state_reference(params, row3_state); + + /* MOV temp0, result.color; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MOV; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = 0; + inst[ic].SrcReg[0].File = PROGRAM_OUTPUT; + inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; + ic++; + + /* DP4 result.color.x, tmp0, matrow0; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_DP4; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.WriteMask = WRITEMASK_X; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[1].Index = row0_p; + ic++; + + /* DP4 result.color.y, tmp0, matrow1; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_DP4; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.WriteMask = WRITEMASK_Y; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[1].Index = row1_p; + ic++; + + /* DP4 result.color.z, tmp0, matrow2; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_DP4; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.WriteMask = WRITEMASK_Z; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[1].Index = row2_p; + ic++; + + /* DP4 result.color.w, tmp0, matrow3; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_DP4; + inst[ic].DstReg.File = PROGRAM_OUTPUT; + inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.WriteMask = WRITEMASK_W; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[1].Index = row3_p; + ic++; + } + /* END; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_END; @@ -204,14 +279,10 @@ update_pixel_transfer(struct st_context *st) fp = (struct gl_fragment_program *) _mesa_search_program_cache(st->pixel_transfer_cache, &key, sizeof(key)); if (!fp) { - printf("Cached program not found\n"); - fp = get_pixel_transfer_program(st->ctx); + fp = get_pixel_transfer_program(st->ctx, &key); _mesa_program_cache_insert(st->ctx, st->pixel_transfer_cache, &key, sizeof(key), &fp->Base); } - else { - printf("Use cached program\n"); - } st->pixel_transfer_program = fp; } @@ -221,7 +292,7 @@ update_pixel_transfer(struct st_context *st) const struct st_tracked_state st_update_pixel_transfer = { .name = "st_update_pixel_transfer", .dirty = { - .mesa = _NEW_PIXEL, + .mesa = _NEW_PIXEL | _NEW_COLOR_MATRIX, .st = 0, }, .update = update_pixel_transfer -- cgit v1.2.3 From d6a739f6b0658414a81715bf690159f7cfdb4961 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 30 Oct 2007 16:13:37 -0600 Subject: Use program serial numbers to avoid re-generating fragment programs for glDrawPixels. --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 14 ++++--- src/mesa/state_tracker/st_cb_drawpixels.c | 52 +++++++++++++++++--------- src/mesa/state_tracker/st_cb_program.c | 6 ++- src/mesa/state_tracker/st_context.c | 4 +- src/mesa/state_tracker/st_context.h | 10 ++++- 5 files changed, 58 insertions(+), 28 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index b190c39343..8cf340e685 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -42,6 +42,7 @@ #include "shader/prog_print.h" #include "st_context.h" +#include "st_program.h" @@ -79,8 +80,6 @@ is_identity(const GLfloat m[16]) static void make_state_key(GLcontext *ctx, struct state_key *key) { - /*GLuint i, j;*/ - memset(key, 0, sizeof(*key)); if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || @@ -189,6 +188,8 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; ic++; + /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ + /* DP4 result.color.x, tmp0, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; @@ -268,6 +269,9 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) +/** + * Update st->pixel_xfer.program in response to new pixel-transfer state. + */ static void update_pixel_transfer(struct st_context *st) { @@ -277,14 +281,14 @@ update_pixel_transfer(struct st_context *st) make_state_key(st->ctx, &key); fp = (struct gl_fragment_program *) - _mesa_search_program_cache(st->pixel_transfer_cache, &key, sizeof(key)); + _mesa_search_program_cache(st->pixel_xfer.cache, &key, sizeof(key)); if (!fp) { fp = get_pixel_transfer_program(st->ctx, &key); - _mesa_program_cache_insert(st->ctx, st->pixel_transfer_cache, + _mesa_program_cache_insert(st->ctx, st->pixel_xfer.cache, &key, sizeof(key), &fp->Base); } - st->pixel_transfer_program = fp; + st->pixel_xfer.program = (struct st_fragment_program *) fp; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 3359338385..c74c8fa641 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -182,30 +182,48 @@ make_drawpix_fragment_shader(struct st_context *st) { GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; - struct gl_program *p; - /* - * XXX Use st_program's serial numbers to determine when the - * user-provided program and pixel-transfer program to avoid - * needless combining/translation here. - */ + if (st->pixel_xfer.program->serialNo == st->pixel_xfer.xfer_prog_sn + && st->fp->serialNo == st->pixel_xfer.user_prog_sn) { + /* the pixel tranfer program has not changed and the user-defined + * shader has not changed, so re-use the combined program. + */ + stfp = st->pixel_xfer.combined_prog; + } + else { + /* Concatenate the pixel transfer program with the current user- + * defined shader. + */ + stfp = (struct st_fragment_program *) + _mesa_combine_programs(ctx, + &st->pixel_xfer.program->Base.Base, + &st->fp->Base.Base); - p = _mesa_combine_programs(ctx, - &st->pixel_transfer_program->Base, - &ctx->FragmentProgram._Current->Base); #if 0 - _mesa_print_program(p); - printf("InputsRead: 0x%x\n", p->InputsRead); - printf("OutputsWritten: 0x%x\n", p->OutputsWritten); - _mesa_print_parameter_list(p->Parameters); + { + struct gl_program *p = &stfp->Base.Base; + _mesa_print_program(p); + printf("InputsRead: 0x%x\n", p->InputsRead); + printf("OutputsWritten: 0x%x\n", p->OutputsWritten); + _mesa_print_parameter_list(p->Parameters); + } #endif - stfp = (struct st_fragment_program *) p; - st_translate_fragment_program(st, stfp, NULL, - stfp->tokens, ST_MAX_SHADER_TOKENS); + /* translate to TGSI tokens */ + st_translate_fragment_program(st, stfp, NULL, + stfp->tokens, ST_MAX_SHADER_TOKENS); + /* save new program, update serial numbers */ + st->pixel_xfer.xfer_prog_sn = st->pixel_xfer.program->serialNo; + st->pixel_xfer.user_prog_sn = st->fp->serialNo; + st->pixel_xfer.combined_prog_sn = stfp->serialNo; + st->pixel_xfer.combined_prog = stfp; + } - st_upload_constants( st, p->Parameters, PIPE_SHADER_FRAGMENT ); + /* Ideally we'd have updated the pipe constants during the normal + * st/atom mechanism. But we can't since this is specific to glDrawPixels. + */ + st_upload_constants(st, stfp->Base.Base.Parameters, PIPE_SHADER_FRAGMENT); return stfp; } diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index a330c1c922..aed6b1ee97 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -44,6 +44,8 @@ #include "st_atom_shader.h" +static GLuint SerialNo = 1; + /** * Called via ctx->Driver.BindProgram() to bind an ARB vertex or @@ -91,7 +93,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_VERTEX_PROGRAM_ARB: { struct st_vertex_program *prog = CALLOC_STRUCT(st_vertex_program); - prog->serialNo = 1; + prog->serialNo = SerialNo++; return _mesa_init_vertex_program( ctx, &prog->Base, @@ -103,7 +105,7 @@ static struct gl_program *st_new_program( GLcontext *ctx, case GL_FRAGMENT_PROGRAM_NV: { struct st_fragment_program *prog = CALLOC_STRUCT(st_fragment_program); - prog->serialNo = 1; + prog->serialNo = SerialNo++; return _mesa_init_fragment_program( ctx, &prog->Base, diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e872e8b12c..c7398233d8 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -92,7 +92,7 @@ struct st_context *st_create_context( GLcontext *ctx, st->haveFramebufferRegions = GL_TRUE; - st->pixel_transfer_cache = _mesa_new_program_cache(); + st->pixel_xfer.cache = _mesa_new_program_cache(); #if 0 st_init_cb_clear( st ); @@ -126,7 +126,7 @@ void st_destroy_context( struct st_context *st ) #endif cso_cache_delete( st->cache ); - _mesa_delete_program_cache(st->ctx, st->pixel_transfer_cache); + _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache); st->pipe->destroy( st->pipe ); FREE( st ); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 4de70a3b2e..8bbfb0d6fe 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -133,8 +133,14 @@ struct st_context struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ - struct gl_fragment_program *pixel_transfer_program; - struct gl_program_cache *pixel_transfer_cache; + struct { + struct gl_program_cache *cache; + struct st_fragment_program *program; /**< cur pixel transfer prog */ + GLuint xfer_prog_sn; /**< pixel xfer program serial no. */ + GLuint user_prog_sn; /**< user fragment program serial no. */ + struct st_fragment_program *combined_prog; + GLuint combined_prog_sn; + } pixel_xfer; /** * Buffer object which stores the ctx->Current.Attrib[] values. -- cgit v1.2.3 From 286380020b146d600ac86d519ddfbf765a5965b2 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 22 Jan 2008 20:52:48 -0700 Subject: gallium: use temp reg for storing color to avoid reading 'result.color' --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 65 +++++++++++++++----------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 8cf340e685..1e3effd549 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -109,6 +109,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) struct gl_program_parameter_list *params; struct gl_fragment_program *fp; GLuint ic = 0; + const GLuint colorTemp = 0; fp = (struct gl_fragment_program *) ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); @@ -117,11 +118,11 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) params = _mesa_new_parameter_list(); - /* TEX result.color, fragment.texcoord[0], texture[0], 2D; */ + /* TEX colorTemp, fragment.texcoord[0], texture[0], 2D; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_TEX; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; inst[ic].SrcReg[0].File = PROGRAM_INPUT; inst[ic].SrcReg[0].Index = FRAG_ATTRIB_TEX0; inst[ic].TexSrcUnit = 0; @@ -130,7 +131,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) fp->Base.InputsRead = (1 << FRAG_ATTRIB_TEX0); fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); - /* MAD result.color, result.color, scale, bias; */ + /* MAD colorTemp, colorTemp, scale, bias; */ if (key->scaleAndBias) { static const gl_state_index scale_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; @@ -153,10 +154,10 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_MAD; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; - inst[ic].SrcReg[0].File = PROGRAM_OUTPUT; - inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = scale_p; inst[ic].SrcReg[2].File = PROGRAM_STATE_VAR; @@ -178,67 +179,75 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) GLint row1_p = _mesa_add_state_reference(params, row1_state); GLint row2_p = _mesa_add_state_reference(params, row2_state); GLint row3_p = _mesa_add_state_reference(params, row3_state); + const GLuint temp = 1; - /* MOV temp0, result.color; */ + /* MOV temp, colorTemp; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_MOV; inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = 0; - inst[ic].SrcReg[0].File = PROGRAM_OUTPUT; - inst[ic].SrcReg[0].Index = FRAG_RESULT_COLR; + inst[ic].DstReg.Index = temp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; ic++; /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ - /* DP4 result.color.x, tmp0, matrow0; */ + /* DP4 colorTemp.x, temp, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; inst[ic].DstReg.WriteMask = WRITEMASK_X; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[0].Index = temp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row0_p; ic++; - /* DP4 result.color.y, tmp0, matrow1; */ + /* DP4 colorTemp.y, temp, matrow1; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; inst[ic].DstReg.WriteMask = WRITEMASK_Y; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[0].Index = temp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row1_p; ic++; - /* DP4 result.color.z, tmp0, matrow2; */ + /* DP4 colorTemp.z, temp, matrow2; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; inst[ic].DstReg.WriteMask = WRITEMASK_Z; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[0].Index = temp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row2_p; ic++; - /* DP4 result.color.w, tmp0, matrow3; */ + /* DP4 colorTemp.w, temp, matrow3; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; - inst[ic].DstReg.File = PROGRAM_OUTPUT; - inst[ic].DstReg.Index = FRAG_RESULT_COLR; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index =colorTemp; inst[ic].DstReg.WriteMask = WRITEMASK_W; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = 0; + inst[ic].SrcReg[0].Index = temp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row3_p; ic++; } + /* Modify last instruction's dst reg to write to result.color */ + { + struct prog_instruction *last = &inst[ic - 1]; + last->DstReg.File = PROGRAM_OUTPUT; + last->DstReg.Index = FRAG_RESULT_COLR; + } + /* END; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_END; -- cgit v1.2.3 From 72f2c55069f167a46560005931382e3b472f92ed Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 4 Apr 2008 11:20:44 -0600 Subject: gallium: make sure to set the SamplersUsed field for bitmap/drawpixels shaders Also, make sure that field is copied/updated in the program clone and combine functions. Without this we weren't getting SAMP declarations in the TGSI shaders. --- src/mesa/shader/program.c | 2 ++ src/mesa/state_tracker/st_atom_pixeltransfer.c | 1 + src/mesa/state_tracker/st_cb_bitmap.c | 1 + src/mesa/state_tracker/st_cb_drawpixels.c | 1 + 4 files changed, 5 insertions(+) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 09a8494bd3..3069b04836 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -361,6 +361,7 @@ _mesa_clone_program(GLcontext *ctx, const struct gl_program *prog) prog->NumInstructions); clone->InputsRead = prog->InputsRead; clone->OutputsWritten = prog->OutputsWritten; + clone->SamplersUsed = prog->SamplersUsed; memcpy(clone->TexturesUsed, prog->TexturesUsed, sizeof(prog->TexturesUsed)); if (prog->Parameters) @@ -537,6 +538,7 @@ _mesa_combine_programs(GLcontext *ctx, } newProg->InputsRead = progA->InputsRead | inputsB; newProg->OutputsWritten = progB->OutputsWritten; + newProg->SamplersUsed = progA->SamplersUsed | progB->SamplersUsed; } else { /* vertex program */ diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 1e3effd549..6410e7cb24 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -130,6 +130,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) ic++; fp->Base.InputsRead = (1 << FRAG_ATTRIB_TEX0); fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); + fp->Base.SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ /* MAD colorTemp, colorTemp, scale, bias; */ if (key->scaleAndBias) { diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 0872f2bd28..59f3c385df 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -148,6 +148,7 @@ make_bitmap_fragment_program(GLcontext *ctx) p->InputsRead = FRAG_BIT_TEX0; p->OutputsWritten = 0x0; + p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ stfp = (struct st_fragment_program *) p; stfp->Base.UsesKill = GL_TRUE; diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index c7796cfb6a..c57e05312a 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -212,6 +212,7 @@ make_fragment_shader_z(struct st_context *st) p->InputsRead = FRAG_BIT_TEX0 | FRAG_BIT_COL0; p->OutputsWritten = (1 << FRAG_RESULT_COLR) | (1 << FRAG_RESULT_DEPR); + p->SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ stfp = (struct st_fragment_program *) p; st_translate_fragment_program(st, stfp, NULL); -- cgit v1.2.3 From e38f677e8f5596d92a6756e13f41f6523de737c2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 16 Apr 2008 09:09:08 -0600 Subject: gallium: finish-up and fix support for GL_COLOR matrix on pixel xfer path --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 75 ++++++++++++++++++-------- src/mesa/state_tracker/st_extensions.c | 1 + 2 files changed, 54 insertions(+), 22 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 6410e7cb24..efb92b735e 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -50,6 +50,7 @@ struct state_key { GLuint scaleAndBias:1; GLuint colorMatrix:1; + GLuint colorMatrixPostScaleBias:1; #if 0 GLfloat Maps[3][256][4]; @@ -80,6 +81,9 @@ is_identity(const GLfloat m[16]) static void make_state_key(GLcontext *ctx, struct state_key *key) { + static const GLfloat zero[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + static const GLfloat one[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + memset(key, 0, sizeof(*key)); if (ctx->Pixel.RedBias != 0.0 || ctx->Pixel.RedScale != 1.0 || @@ -92,8 +96,12 @@ make_state_key(GLcontext *ctx, struct state_key *key) if (!is_identity(ctx->ColorMatrixStack.Top->m)) { key->colorMatrix = 1; } -} + if (!TEST_EQ_4V(ctx->Pixel.PostColorMatrixScale, one) || + !TEST_EQ_4V(ctx->Pixel.PostColorMatrixBias, zero)) { + key->colorMatrixPostScaleBias = 1; + } +} @@ -182,64 +190,87 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) GLint row3_p = _mesa_add_state_reference(params, row3_state); const GLuint temp = 1; - /* MOV temp, colorTemp; */ - _mesa_init_instructions(inst + ic, 1); - inst[ic].Opcode = OPCODE_MOV; - inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = temp; - inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = colorTemp; - ic++; - /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ - /* DP4 colorTemp.x, temp, matrow0; */ + /* DP4 temp.x, colorTemp, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = colorTemp; + inst[ic].DstReg.Index = temp; inst[ic].DstReg.WriteMask = WRITEMASK_X; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = temp; + inst[ic].SrcReg[0].Index = colorTemp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row0_p; ic++; - /* DP4 colorTemp.y, temp, matrow1; */ + /* DP4 temp.y, colorTemp, matrow1; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = colorTemp; + inst[ic].DstReg.Index = temp; inst[ic].DstReg.WriteMask = WRITEMASK_Y; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = temp; + inst[ic].SrcReg[0].Index = colorTemp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row1_p; ic++; - /* DP4 colorTemp.z, temp, matrow2; */ + /* DP4 temp.z, colorTemp, matrow2; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index = colorTemp; + inst[ic].DstReg.Index = temp; inst[ic].DstReg.WriteMask = WRITEMASK_Z; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = temp; + inst[ic].SrcReg[0].Index = colorTemp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row2_p; ic++; - /* DP4 colorTemp.w, temp, matrow3; */ + /* DP4 temp.w, colorTemp, matrow3; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; inst[ic].DstReg.File = PROGRAM_TEMPORARY; - inst[ic].DstReg.Index =colorTemp; + inst[ic].DstReg.Index = temp; inst[ic].DstReg.WriteMask = WRITEMASK_W; inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; - inst[ic].SrcReg[0].Index = temp; + inst[ic].SrcReg[0].Index = colorTemp; inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; inst[ic].SrcReg[1].Index = row3_p; ic++; + + /* MOV colorTemp, temp; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MOV; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = temp; + ic++; + } + + if (key->colorMatrixPostScaleBias) { + static const gl_state_index scale_state[STATE_LENGTH] = + { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; + static const gl_state_index bias_state[STATE_LENGTH] = + { STATE_INTERNAL, STATE_PT_BIAS, 0, 0, 0 }; + GLint scale_param, bias_param; + + scale_param = _mesa_add_state_reference(params, scale_state); + bias_param = _mesa_add_state_reference(params, bias_state); + + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MAD; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; + inst[ic].SrcReg[1].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[1].Index = scale_param; + inst[ic].SrcReg[2].File = PROGRAM_STATE_VAR; + inst[ic].SrcReg[2].Index = bias_param; + ic++; } /* Modify last instruction's dst reg to write to result.color */ diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 2f7ac074da..f2d40e84b3 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -164,6 +164,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.NV_blend_square = GL_TRUE; ctx->Extensions.NV_texgen_reflection = GL_TRUE; + ctx->Extensions.SGI_color_matrix = GL_TRUE; ctx->Extensions.SGIS_generate_mipmap = GL_TRUE; /* XXX temp */ /* -- cgit v1.2.3 From 4b822a101680532ce6df52904af91194b78a16ba Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 16 Apr 2008 16:52:12 -0600 Subject: gallium: implement RGBA pixel maps in the pixel transfer fragment program --- src/mesa/state_tracker/st_atom_pixeltransfer.c | 136 ++++++++++++++++++++++++- src/mesa/state_tracker/st_cb_drawpixels.c | 13 ++- src/mesa/state_tracker/st_context.h | 2 + 3 files changed, 146 insertions(+), 5 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index efb92b735e..76356bbad7 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -42,8 +42,14 @@ #include "shader/prog_print.h" #include "st_context.h" +#include "st_format.h" #include "st_program.h" +#include "st_texture.h" +#include "pipe/p_screen.h" +#include "pipe/p_context.h" +#include "pipe/p_inlines.h" +#include "util/u_pack_color.h" struct state_key @@ -51,6 +57,7 @@ struct state_key GLuint scaleAndBias:1; GLuint colorMatrix:1; GLuint colorMatrixPostScaleBias:1; + GLuint pixelMaps:1; #if 0 GLfloat Maps[3][256][4]; @@ -101,6 +108,69 @@ make_state_key(GLcontext *ctx, struct state_key *key) !TEST_EQ_4V(ctx->Pixel.PostColorMatrixBias, zero)) { key->colorMatrixPostScaleBias = 1; } + + key->pixelMaps = ctx->Pixel.MapColorFlag; +} + + +static struct pipe_texture * +create_color_map_texture(GLcontext *ctx) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_texture *pt; + enum pipe_format format; + const uint texSize = 256; /* simple, and usually perfect */ + + /* find an RGBA texture format */ + format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + + /* create texture for color map/table */ + pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, + texSize, texSize, 1, 0); + return pt; +} + + +/** + * Update the pixelmap texture with the contents of the R/G/B/A pixel maps. + */ +static void +load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) +{ + struct pipe_context *pipe = ctx->st->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *surface; + const GLuint rSize = ctx->PixelMaps.RtoR.Size; + const GLuint gSize = ctx->PixelMaps.GtoG.Size; + const GLuint bSize = ctx->PixelMaps.BtoB.Size; + const GLuint aSize = ctx->PixelMaps.AtoA.Size; + const uint texSize = pt->width[0]; + uint *dest; + uint i, j; + + surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + dest = (uint *) pipe_surface_map(surface); + + /* Pack four 1D maps into a 2D texture: + * R map is placed horizontally, indexed by S, in channel 0 + * G map is placed vertically, indexed by T, in channel 1 + * B map is placed horizontally, indexed by S, in channel 2 + * A map is placed vertically, indexed by T, in channel 3 + */ + for (i = 0; i < texSize; i++) { + for (j = 0; j < texSize; j++) { + int k = (i * texSize + j); + ubyte r = ctx->PixelMaps.RtoR.Map8[j * rSize / texSize]; + ubyte g = ctx->PixelMaps.GtoG.Map8[i * gSize / texSize]; + ubyte b = ctx->PixelMaps.BtoB.Map8[j * bSize / texSize]; + ubyte a = ctx->PixelMaps.AtoA.Map8[i * aSize / texSize]; + util_pack_color_ub(r, g, b, a, pt->format, dest + k); + } + } + + pipe_surface_unmap(surface); + pipe_surface_reference(&surface, NULL); + pipe->texture_update(pipe, pt, 0, 0x1); } @@ -113,6 +183,7 @@ make_state_key(GLcontext *ctx, struct state_key *key) static struct gl_fragment_program * get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) { + struct st_context *st = ctx->st; struct prog_instruction inst[MAX_INST]; struct gl_program_parameter_list *params; struct gl_fragment_program *fp; @@ -126,7 +197,10 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) params = _mesa_new_parameter_list(); - /* TEX colorTemp, fragment.texcoord[0], texture[0], 2D; */ + /* + * Get initial pixel color from the texture. + * TEX colorTemp, fragment.texcoord[0], texture[0], 2D; + */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_TEX; inst[ic].DstReg.File = PROGRAM_TEMPORARY; @@ -140,7 +214,6 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) fp->Base.OutputsWritten = (1 << FRAG_RESULT_COLR); fp->Base.SamplersUsed = 0x1; /* sampler 0 (bit 0) is used */ - /* MAD colorTemp, colorTemp, scale, bias; */ if (key->scaleAndBias) { static const gl_state_index scale_state[STATE_LENGTH] = { STATE_INTERNAL, STATE_PT_SCALE, 0, 0, 0 }; @@ -161,6 +234,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) scale_p = _mesa_add_state_reference(params, scale_state); bias_p = _mesa_add_state_reference(params, bias_state); + /* MAD colorTemp, colorTemp, scale, bias; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_MAD; inst[ic].DstReg.File = PROGRAM_TEMPORARY; @@ -174,6 +248,56 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) ic++; } + if (key->pixelMaps) { + const GLuint temp = 1; + + /* create the colormap/texture now if not already done */ + if (!st->pixel_xfer.pixelmap_texture) { + st->pixel_xfer.pixelmap_texture = create_color_map_texture(ctx); + } + + /* with a little effort, we can do four pixel map look-ups with + * two TEX instructions: + */ + + /* TEX temp.rg, colorTemp.rgba, texture[1], 2D; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_TEX; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = temp; + inst[ic].DstReg.WriteMask = WRITEMASK_XY; /* write R,G */ + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; + inst[ic].TexSrcUnit = 1; + inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; + ic++; + + /* TEX temp.ba, colorTemp.baba, texture[1], 2D; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_TEX; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = temp; + inst[ic].DstReg.WriteMask = WRITEMASK_ZW; /* write B,A */ + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = colorTemp; + inst[ic].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_W, + SWIZZLE_Z, SWIZZLE_W); + inst[ic].TexSrcUnit = 1; + inst[ic].TexSrcTarget = TEXTURE_2D_INDEX; + ic++; + + /* MOV colorTemp, temp; */ + _mesa_init_instructions(inst + ic, 1); + inst[ic].Opcode = OPCODE_MOV; + inst[ic].DstReg.File = PROGRAM_TEMPORARY; + inst[ic].DstReg.Index = colorTemp; + inst[ic].SrcReg[0].File = PROGRAM_TEMPORARY; + inst[ic].SrcReg[0].Index = temp; + ic++; + + fp->Base.SamplersUsed |= (1 << 1); /* sampler 1 is used */ + } + if (key->colorMatrix) { static const gl_state_index row0_state[STATE_LENGTH] = { STATE_COLOR_MATRIX, 0, 0, 0, 0 }; @@ -190,8 +314,6 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) GLint row3_p = _mesa_add_state_reference(params, row3_state); const GLuint temp = 1; - /* XXX reimplement in terms of MUL/MAD (see t_vp_build.c) */ - /* DP4 temp.x, colorTemp, matrow0; */ _mesa_init_instructions(inst + ic, 1); inst[ic].Opcode = OPCODE_DP4; @@ -316,6 +438,7 @@ get_pixel_transfer_program(GLcontext *ctx, const struct state_key *key) static void update_pixel_transfer(struct st_context *st) { + GLcontext *ctx = st->ctx; struct state_key key; struct gl_fragment_program *fp; @@ -329,6 +452,11 @@ update_pixel_transfer(struct st_context *st) &key, sizeof(key), &fp->Base); } + if (ctx->Pixel.MapColorFlag) { + load_color_map_texture(ctx, st->pixel_xfer.pixelmap_texture); + } + st->pixel_xfer.pixelmap_enabled = ctx->Pixel.MapColorFlag; + st->pixel_xfer.program = (struct st_fragment_program *) fp; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5f8c90cbba..67f468c689 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -562,6 +562,9 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, sampler.normalized_coords = 1; cso_single_sampler(cso, 0, &sampler); + if (st->pixel_xfer.pixelmap_enabled) { + cso_single_sampler(cso, 1, &sampler); + } cso_single_sampler_done(cso); } @@ -582,7 +585,15 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } /* texture state: */ - pipe->set_sampler_textures(pipe, 1, &pt); + if (st->pixel_xfer.pixelmap_enabled) { + struct pipe_texture *textures[2]; + textures[0] = pt; + textures[1] = st->pixel_xfer.pixelmap_texture; + pipe->set_sampler_textures(pipe, 2, textures); + } + else { + pipe->set_sampler_textures(pipe, 1, &pt); + } /* Compute window coords (y=0=bottom) with pixel zoom. * Recall that these coords are transformed by the current diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index d89e54c43c..ae1ba41d4f 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -138,6 +138,8 @@ struct st_context GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; GLuint combined_prog_sn; + struct pipe_texture *pixelmap_texture; + boolean pixelmap_enabled; /**< use the pixelmap texture? */ } pixel_xfer; /** for glBitmap */ -- cgit v1.2.3 From c9ed86a96483063f3d6789ed16645a3dca77d726 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 1 May 2008 11:07:21 +0100 Subject: gallium: tex surface checkpoint --- src/gallium/auxiliary/draw/draw_pipe_aaline.c | 12 ++-- src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 15 +++-- src/gallium/auxiliary/util/p_tile.c | 50 ++++++++++---- src/gallium/auxiliary/util/u_blit.c | 3 +- src/gallium/auxiliary/util/u_gen_mipmap.c | 21 ++++-- src/gallium/drivers/failover/fo_context.c | 2 +- src/gallium/drivers/i915simple/i915_screen.c | 31 +++++++++ src/gallium/drivers/i915simple/i915_surface.c | 23 +++++-- src/gallium/drivers/i915simple/i915_texture.c | 13 ++-- src/gallium/drivers/i965simple/brw_surface.c | 51 ++++++--------- src/gallium/drivers/i965simple/brw_tex_layout.c | 2 +- src/gallium/drivers/softpipe/sp_context.c | 6 +- src/gallium/drivers/softpipe/sp_draw_arrays.c | 6 +- src/gallium/drivers/softpipe/sp_flush.c | 35 +++++----- src/gallium/drivers/softpipe/sp_screen.c | 22 ++++--- src/gallium/drivers/softpipe/sp_surface.c | 23 +++++-- src/gallium/drivers/softpipe/sp_texture.c | 87 ++++++++++++++++++------- src/gallium/drivers/softpipe/sp_texture.h | 1 - src/gallium/drivers/softpipe/sp_tile_cache.c | 36 ++++++---- src/gallium/drivers/softpipe/sp_tile_cache.h | 2 +- src/gallium/include/pipe/p_context.h | 6 -- src/gallium/include/pipe/p_inlines.h | 31 ++++----- src/gallium/include/pipe/p_screen.h | 17 ++++- src/gallium/include/pipe/p_state.h | 4 ++ src/gallium/include/pipe/p_util.h | 3 + src/gallium/include/pipe/p_winsys.h | 2 +- src/gallium/winsys/xlib/xm_winsys.c | 2 + src/mesa/state_tracker/st_atom_pixeltransfer.c | 9 +-- src/mesa/state_tracker/st_cb_accum.c | 12 ++-- src/mesa/state_tracker/st_cb_bitmap.c | 23 +++++-- src/mesa/state_tracker/st_cb_drawpixels.c | 56 +++++++++------- src/mesa/state_tracker/st_cb_fbo.c | 27 +++++--- src/mesa/state_tracker/st_cb_readpixels.c | 5 +- src/mesa/state_tracker/st_cb_texture.c | 48 +++++++------- src/mesa/state_tracker/st_gen_mipmap.c | 6 +- src/mesa/state_tracker/st_texture.c | 34 ++++++---- src/mesa/state_tracker/st_texture.h | 6 +- 37 files changed, 465 insertions(+), 267 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/gallium/auxiliary/draw/draw_pipe_aaline.c b/src/gallium/auxiliary/draw/draw_pipe_aaline.c index f501b2aed4..6dc20f2c90 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aaline.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aaline.c @@ -415,8 +415,11 @@ aaline_create_texture(struct aaline_stage *aaline) assert(aaline->texture->width[level] == aaline->texture->height[level]); - surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0); - data = pipe_surface_map(surface); + /* This texture is new, no need to flush. + */ + surface = screen->get_tex_surface(screen, aaline->texture, 0, level, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + data = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); if (data == NULL) return FALSE; @@ -440,9 +443,8 @@ aaline_create_texture(struct aaline_stage *aaline) } /* unmap */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, aaline->texture, 0, (1 << level)); + screen->surface_unmap(screen, surface); + screen->tex_surface_release(screen, &surface); } return TRUE; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index c4de9d2698..3aa326acc7 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -376,8 +376,14 @@ pstip_update_texture(struct pstip_stage *pstip) uint i, j; ubyte *data; - surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0); - data = pipe_surface_map(surface); + /* XXX: want to avoid flushing just because we use stipple: + */ + pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL ); + + surface = screen->get_tex_surface(screen, pstip->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + data = screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* * Load alpha texture. @@ -399,9 +405,8 @@ pstip_update_texture(struct pstip_stage *pstip) } /* unmap */ - pipe_surface_unmap(surface); - pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pstip->texture, 0, 0x1); + screen->surface_unmap(screen, surface); + screen->tex_surface_release(screen, &surface); } diff --git a/src/gallium/auxiliary/util/p_tile.c b/src/gallium/auxiliary/util/p_tile.c index 63e1cc6013..5728757d2f 100644 --- a/src/gallium/auxiliary/util/p_tile.c +++ b/src/gallium/auxiliary/util/p_tile.c @@ -50,6 +50,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, uint x, uint y, uint w, uint h, void *p, int dst_stride) { + struct pipe_screen *screen = pipe->screen; const uint cpp = ps->cpp; const ubyte *pSrc; const uint src_stride = ps->pitch * cpp; @@ -63,7 +64,11 @@ pipe_get_tile_raw(struct pipe_context *pipe, if (pipe_clip_tile(x, y, &w, &h, ps)) return; - pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; + pSrc = (const ubyte *) screen->surface_map(screen, ps, + PIPE_BUFFER_USAGE_CPU_READ); + assert(pSrc); /* XXX: proper error handling! */ + + pSrc += (y * ps->pitch + x) * cpp; pDest = (ubyte *) p; for (i = 0; i < h; i++) { @@ -72,7 +77,7 @@ pipe_get_tile_raw(struct pipe_context *pipe, pSrc += src_stride; } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -86,6 +91,7 @@ pipe_put_tile_raw(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const void *p, int src_stride) { + struct pipe_screen *screen = pipe->screen; const uint cpp = ps->cpp; const ubyte *pSrc; const uint dst_stride = ps->pitch * cpp; @@ -100,7 +106,11 @@ pipe_put_tile_raw(struct pipe_context *pipe, return; pSrc = (const ubyte *) p; - pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp; + + pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(pDest); /* XXX: proper error handling */ + + pDest += (y * ps->pitch + x) * cpp; for (i = 0; i < h; i++) { memcpy(pDest, pSrc, w * cpp); @@ -108,7 +118,7 @@ pipe_put_tile_raw(struct pipe_context *pipe, pSrc += src_stride; } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -834,18 +844,26 @@ pipe_get_tile_z(struct pipe_context *pipe, uint x, uint y, uint w, uint h, uint *z) { + struct pipe_screen *screen = pipe->screen; const uint dstStride = w; + void *map; uint *pDest = z; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; + map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); + if (!map) { + assert(0); + return; + } + switch (ps->format) { case PIPE_FORMAT_Z32_UNORM: { const uint *pSrc - = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const uint *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); pDest += dstStride; @@ -857,7 +875,7 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_X8Z24_UNORM: { const uint *pSrc - = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const uint *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 24-bit Z to 32-bit Z */ @@ -871,7 +889,7 @@ pipe_get_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_Z16_UNORM: { const ushort *pSrc - = (const ushort *) pipe_surface_map(ps) + (y * ps->pitch + x); + = (const ushort *)map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 16-bit Z to 32-bit Z */ @@ -886,7 +904,7 @@ pipe_get_tile_z(struct pipe_context *pipe, assert(0); } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -896,17 +914,25 @@ pipe_put_tile_z(struct pipe_context *pipe, uint x, uint y, uint w, uint h, const uint *zSrc) { + struct pipe_screen *screen = pipe->screen; const uint srcStride = w; const uint *pSrc = zSrc; + void *map; uint i, j; if (pipe_clip_tile(x, y, &w, &h, ps)) return; + map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE); + if (!map) { + assert(0); + return; + } + switch (ps->format) { case PIPE_FORMAT_Z32_UNORM: { - uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + uint *pDest = (uint *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { memcpy(pDest, pSrc, 4 * w); pDest += ps->pitch; @@ -917,7 +943,7 @@ pipe_put_tile_z(struct pipe_context *pipe, case PIPE_FORMAT_S8Z24_UNORM: case PIPE_FORMAT_X8Z24_UNORM: { - uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x); + uint *pDest = (uint *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 24-bit Z (0 stencil) */ @@ -930,7 +956,7 @@ pipe_put_tile_z(struct pipe_context *pipe, break; case PIPE_FORMAT_Z16_UNORM: { - ushort *pDest = (ushort *) pipe_surface_map(ps) + (y * ps->pitch + x); + ushort *pDest = (ushort *) map + (y * ps->pitch + x); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { /* convert 32-bit Z to 16-bit Z */ @@ -945,7 +971,7 @@ pipe_put_tile_z(struct pipe_context *pipe, assert(0); } - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 9e9912c6e4..257473ab26 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -287,7 +287,8 @@ util_blit_pixels(struct blit_state *ctx, if (!tex) return; - texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0); + texSurf = screen->get_tex_surface(screen, tex, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_WRITE); /* load temp texture */ pipe->surface_copy(pipe, FALSE, diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 0348629ab8..6ed5503c9a 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -586,8 +586,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx, struct pipe_surface *srcSurf, *dstSurf; void *srcMap, *dstMap; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) @@ -626,8 +629,10 @@ make_2d_mipmap(struct gen_mipmap_state *ctx, struct pipe_surface *srcSurf, *dstSurf; ubyte *srcMap, *dstMap; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcMap = ((ubyte *) winsys->buffer_map(winsys, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) @@ -888,10 +893,14 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; + struct pipe_surface *surf = + screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_GPU_WRITE); + /* * Setup framebuffer / dest surface */ - fb.cbufs[0] = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + fb.cbufs[0] = surf; fb.width = pt->width[dstLevel]; fb.height = pt->height[dstLevel]; cso_set_framebuffer(ctx->cso, &fb); @@ -922,7 +931,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* need to signal that the texture has changed _after_ rendering to it */ - pipe->texture_update(pipe, pt, face, (1 << dstLevel)); + pipe_surface_reference( &surf, NULL ); } /* restore state we changed */ diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index cb95ba516f..014a3e31d5 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -147,8 +147,8 @@ struct pipe_context *failover_create( struct pipe_context *hw, failover->pipe.texture_create = hw->texture_create; failover->pipe.texture_release = hw->texture_release; failover->pipe.get_tex_surface = hw->get_tex_surface; -#endif failover->pipe.texture_update = hw->texture_update; +#endif failover->pipe.flush = hw->flush; diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c index 631642e1b6..dcd349e478 100644 --- a/src/gallium/drivers/i915simple/i915_screen.c +++ b/src/gallium/drivers/i915simple/i915_screen.c @@ -200,6 +200,35 @@ i915_destroy_screen( struct pipe_screen *screen ) } +static void * +i915_surface_map( struct pipe_screen *screen, + struct pipe_surface *surface, + unsigned flags ) +{ + char *map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags ); + if (map == NULL) + return NULL; + + if (surface->texture && + (flags & PIPE_BUFFER_USAGE_CPU_WRITE)) + { + /* Do something to notify contexts of a texture change. + */ + /* i915_screen(screen)->timestamp++; */ + } + + return map + surface->offset; +} + +static void +i915_surface_unmap(struct pipe_screen *screen, + struct pipe_surface *surface) +{ + screen->winsys->buffer_unmap( screen->winsys, surface->buffer ); +} + + + /** * Create a new i915_screen object */ @@ -243,6 +272,8 @@ i915_create_screen(struct pipe_winsys *winsys, uint pci_id) i915screen->screen.get_param = i915_get_param; i915screen->screen.get_paramf = i915_get_paramf; i915screen->screen.is_format_supported = i915_is_format_supported; + i915screen->screen.surface_map = i915_surface_map; + i915screen->screen.surface_unmap = i915_surface_unmap; i915_init_screen_texture_functions(&i915screen->screen); diff --git a/src/gallium/drivers/i915simple/i915_surface.c b/src/gallium/drivers/i915simple/i915_surface.c index f4fbedbe9b..98367ac073 100644 --- a/src/gallium/drivers/i915simple/i915_surface.c +++ b/src/gallium/drivers/i915simple/i915_surface.c @@ -51,17 +51,25 @@ i915_surface_copy(struct pipe_context *pipe, assert( dst->cpp == src->cpp ); if (0) { - pipe_copy_rect(pipe_surface_map(dst), + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_CPU_READ ); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe_surface_map(src), + src_map, do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } else { i915_copy_blit( i915_context(pipe), @@ -92,7 +100,10 @@ i915_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + switch (dst->cpp) { case 1: { @@ -126,7 +137,7 @@ i915_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } else { i915_fill_blit( i915_context(pipe), diff --git a/src/gallium/drivers/i915simple/i915_texture.c b/src/gallium/drivers/i915simple/i915_texture.c index c39e747705..7b9359a0fe 100644 --- a/src/gallium/drivers/i915simple/i915_texture.c +++ b/src/gallium/drivers/i915simple/i915_texture.c @@ -541,13 +541,6 @@ i915_texture_release_screen(struct pipe_screen *screen, } -static void -i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture, - uint face, uint levelsMask) -{ - /* no-op? */ -} - /* * XXX note: same as code in sp_surface.c @@ -555,7 +548,8 @@ i915_texture_update(struct pipe_context *pipe, struct pipe_texture *texture, static struct pipe_surface * i915_get_tex_surface_screen(struct pipe_screen *screen, struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) + unsigned face, unsigned level, unsigned zslice, + unsigned flags) { struct i915_texture *tex = (struct i915_texture *)pt; struct pipe_winsys *ws = screen->winsys; @@ -586,6 +580,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen, ps->height = pt->height[level]; ps->pitch = tex->pitch; ps->offset = offset; + ps->usage = flags; } return ps; } @@ -594,7 +589,7 @@ i915_get_tex_surface_screen(struct pipe_screen *screen, void i915_init_texture_functions(struct i915_context *i915) { - i915->pipe.texture_update = i915_texture_update; +// i915->pipe.texture_update = i915_texture_update; } diff --git a/src/gallium/drivers/i965simple/brw_surface.c b/src/gallium/drivers/i965simple/brw_surface.c index c99a91dcf7..3e3736b280 100644 --- a/src/gallium/drivers/i965simple/brw_surface.c +++ b/src/gallium/drivers/i965simple/brw_surface.c @@ -35,27 +35,6 @@ #include "util/p_tile.h" -/* Upload data to a rectangular sub-region. Lots of choices how to do this: - * - * - memcpy by span to current destination - * - upload data as new buffer and blit - * - * Currently always memcpy. - */ -static void -brw_surface_data(struct pipe_context *pipe, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - const void *src, unsigned src_pitch, - unsigned srcx, unsigned srcy, unsigned width, unsigned height) -{ - pipe_copy_rect(pipe_surface_map(dst) + dst->offset, - dst->cpp, dst->pitch, - dstx, dsty, width, height, src, src_pitch, srcx, srcy); - - pipe_surface_unmap(dst); -} - /* Assumes all values are within bounds -- no checking at this level - * do it higher up if required. @@ -72,17 +51,25 @@ brw_surface_copy(struct pipe_context *pipe, assert(dst->cpp == src->cpp); if (0) { - pipe_copy_rect(pipe_surface_map(dst) + dst->offset, + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_CPU_READ ); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, - dstx, dsty, - width, height, - pipe_surface_map(src) + src->offset, - do_flip ? -src->pitch : src->pitch, + dstx, dsty, + width, height, + src_map, + do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } else { brw_copy_blit(brw_context(pipe), @@ -113,7 +100,10 @@ brw_surface_fill(struct pipe_context *pipe, { if (0) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_CPU_WRITE ); + switch (dst->cpp) { case 1: { @@ -147,7 +137,7 @@ brw_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } else { brw_fill_blit(brw_context(pipe), @@ -164,7 +154,6 @@ brw_surface_fill(struct pipe_context *pipe, void brw_init_surface_functions(struct brw_context *brw) { - (void) brw_surface_data; /* silence warning */ brw->pipe.surface_copy = brw_surface_copy; brw->pipe.surface_fill = brw_surface_fill; } diff --git a/src/gallium/drivers/i965simple/brw_tex_layout.c b/src/gallium/drivers/i965simple/brw_tex_layout.c index b580f98204..ba4c4a7bcf 100644 --- a/src/gallium/drivers/i965simple/brw_tex_layout.c +++ b/src/gallium/drivers/i965simple/brw_tex_layout.c @@ -407,7 +407,7 @@ brw_get_tex_surface_screen(struct pipe_screen *screen, void brw_init_texture_functions(struct brw_context *brw) { - brw->pipe.texture_update = brw_texture_update; +// brw->pipe.texture_update = brw_texture_update; } diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index edf91ecafa..ee74826763 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -192,11 +192,11 @@ softpipe_create( struct pipe_screen *screen, * Must be before quad stage setup! */ for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) - softpipe->cbuf_cache[i] = sp_create_tile_cache(); - softpipe->zsbuf_cache = sp_create_tile_cache(); + softpipe->cbuf_cache[i] = sp_create_tile_cache( screen ); + softpipe->zsbuf_cache = sp_create_tile_cache( screen ); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - softpipe->tex_cache[i] = sp_create_tile_cache(); + softpipe->tex_cache[i] = sp_create_tile_cache( screen ); /* setup quad rendering stages */ diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c index 6c58f9909d..355c120d18 100644 --- a/src/gallium/drivers/softpipe/sp_draw_arrays.c +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -50,7 +50,7 @@ softpipe_map_constant_buffers(struct softpipe_context *sp) for (i = 0; i < 2; i++) { if (sp->constants[i].size) sp->mapped_constants[i] = ws->buffer_map(ws, sp->constants[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); } draw_set_mapped_constant_buffer(sp->draw, @@ -133,14 +133,14 @@ softpipe_draw_elements(struct pipe_context *pipe, void *buf = pipe->winsys->buffer_map(pipe->winsys, sp->vertex_buffer[i].buffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); draw_set_mapped_vertex_buffer(draw, i, buf); } /* Map index buffer, if present */ if (indexBuffer) { void *mapped_indexes = pipe->winsys->buffer_map(pipe->winsys, indexBuffer, - PIPE_BUFFER_USAGE_CPU_READ); + PIPE_BUFFER_USAGE_GPU_READ); draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); } else { diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index 0625b69099..e03994b63b 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -50,25 +50,28 @@ softpipe_flush( struct pipe_context *pipe, draw_flush(softpipe->draw); - /* - flush the quad pipeline - * - flush the texture cache - * - flush the render cache - */ + if (flags & PIPE_FLUSH_TEXTURE_CACHE) { + for (i = 0; i < softpipe->num_textures; i++) { + sp_flush_tile_cache(softpipe, softpipe->tex_cache[i]); + } + } - for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) - if (softpipe->cbuf_cache[i]) - sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]); + if (flags & PIPE_FLUSH_RENDER_CACHE) { + for (i = 0; i < softpipe->framebuffer.num_cbufs; i++) + if (softpipe->cbuf_cache[i]) + sp_flush_tile_cache(softpipe, softpipe->cbuf_cache[i]); - if (softpipe->zsbuf_cache) - sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache); + if (softpipe->zsbuf_cache) + sp_flush_tile_cache(softpipe, softpipe->zsbuf_cache); - /* Need this call for hardware buffers before swapbuffers. - * - * there should probably be another/different flush-type function - * that's called before swapbuffers because we don't always want - * to unmap surfaces when flushing. - */ - softpipe_unmap_surfaces(softpipe); + /* Need this call for hardware buffers before swapbuffers. + * + * there should probably be another/different flush-type function + * that's called before swapbuffers because we don't always want + * to unmap surfaces when flushing. + */ + softpipe_unmap_surfaces(softpipe); + } if (fence) *fence = NULL; diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 7dacb1c461..e9926bf41f 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -33,6 +33,7 @@ #include "sp_texture.h" #include "sp_winsys.h" +#include "sp_screen.h" static const char * @@ -137,6 +138,7 @@ softpipe_destroy_screen( struct pipe_screen *screen ) } + /** * Create a new pipe_screen object * Note: we're not presently subclassing pipe_screen (no softpipe_screen). @@ -144,22 +146,22 @@ softpipe_destroy_screen( struct pipe_screen *screen ) struct pipe_screen * softpipe_create_screen(struct pipe_winsys *winsys) { - struct pipe_screen *screen = CALLOC_STRUCT(pipe_screen); + struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen); if (!screen) return NULL; - screen->winsys = winsys; + screen->base.winsys = winsys; - screen->destroy = softpipe_destroy_screen; + screen->base.destroy = softpipe_destroy_screen; - screen->get_name = softpipe_get_name; - screen->get_vendor = softpipe_get_vendor; - screen->get_param = softpipe_get_param; - screen->get_paramf = softpipe_get_paramf; - screen->is_format_supported = softpipe_is_format_supported; + screen->base.get_name = softpipe_get_name; + screen->base.get_vendor = softpipe_get_vendor; + screen->base.get_param = softpipe_get_param; + screen->base.get_paramf = softpipe_get_paramf; + screen->base.is_format_supported = softpipe_is_format_supported; - softpipe_init_screen_texture_funcs(screen); + softpipe_init_screen_texture_funcs(&screen->base); - return screen; + return &screen->base; } diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c index 653449c4f1..b5cc053548 100644 --- a/src/gallium/drivers/softpipe/sp_surface.c +++ b/src/gallium/drivers/softpipe/sp_surface.c @@ -47,18 +47,27 @@ sp_surface_copy(struct pipe_context *pipe, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { assert( dst->cpp == src->cpp ); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_GPU_WRITE ); - pipe_copy_rect(pipe_surface_map(dst), + const void *src_map = pipe->screen->surface_map( pipe->screen, + src, + PIPE_BUFFER_USAGE_GPU_READ ); + + assert(src_map && dst_map); + + pipe_copy_rect(dst_map, dst->cpp, dst->pitch, dstx, dsty, width, height, - pipe_surface_map(src), + src_map, do_flip ? -(int) src->pitch : src->pitch, srcx, do_flip ? 1 - srcy - height : srcy); - pipe_surface_unmap(src); - pipe_surface_unmap(dst); + pipe->screen->surface_unmap(pipe->screen, src); + pipe->screen->surface_unmap(pipe->screen, dst); } @@ -83,7 +92,9 @@ sp_surface_fill(struct pipe_context *pipe, unsigned width, unsigned height, unsigned value) { unsigned i, j; - void *dst_map = pipe_surface_map(dst); + void *dst_map = pipe->screen->surface_map( pipe->screen, + dst, + PIPE_BUFFER_USAGE_GPU_WRITE ); assert(dst->pitch > 0); assert(width <= dst->pitch); @@ -147,7 +158,7 @@ sp_surface_fill(struct pipe_context *pipe, break; } - pipe_surface_unmap( dst ); + pipe->screen->surface_unmap(pipe->screen, dst); } diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 256586ec88..ee3fa994f9 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -40,6 +40,7 @@ #include "sp_state.h" #include "sp_texture.h" #include "sp_tile_cache.h" +#include "sp_screen.h" /* Simple, maximally packed layout. @@ -116,19 +117,10 @@ softpipe_texture_release(struct pipe_screen *screen, if (!*pt) return; - /* - DBG("%s %p refcount will be %d\n", - __FUNCTION__, (void *) *pt, (*pt)->refcount - 1); - */ if (--(*pt)->refcount <= 0) { struct softpipe_texture *spt = softpipe_texture(*pt); - /* - DBG("%s deleting %p\n", __FUNCTION__, (void *) spt); - */ - pipe_buffer_reference(screen->winsys, &spt->buffer, NULL); - FREE(spt); } *pt = NULL; @@ -138,7 +130,8 @@ softpipe_texture_release(struct pipe_screen *screen, static struct pipe_surface * softpipe_get_tex_surface(struct pipe_screen *screen, struct pipe_texture *pt, - unsigned face, unsigned level, unsigned zslice) + unsigned face, unsigned level, unsigned zslice, + unsigned usage) { struct pipe_winsys *ws = screen->winsys; struct softpipe_texture *spt = softpipe_texture(pt); @@ -157,6 +150,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, ps->height = pt->height[level]; ps->pitch = ps->width; ps->offset = spt->level_offset[level]; + ps->usage = usage; if (pt->target == PIPE_TEXTURE_CUBE || pt->target == PIPE_TEXTURE_3D) { ps->offset += ((pt->target == PIPE_TEXTURE_CUBE) ? face : zslice) * @@ -167,30 +161,74 @@ softpipe_get_tex_surface(struct pipe_screen *screen, assert(face == 0); assert(zslice == 0); } + + if (usage & (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_WRITE)) { + /* XXX if writing to the texture, invalidate the texcache entries!!! */ + assert(0); + } } return ps; } -static void -softpipe_texture_update(struct pipe_context *pipe, - struct pipe_texture *texture, - uint face, uint levelsMask) +static void +softpipe_tex_surface_release(struct pipe_screen *screen, + struct pipe_surface **s) { - struct softpipe_context *softpipe = softpipe_context(pipe); - uint unit; - for (unit = 0; unit < softpipe->num_textures; unit++) { - if (softpipe->texture[unit] == texture) { - sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]); - } + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For softpipe, nothing to do. + */ + assert ((*s)->texture); + + screen->winsys->surface_release(screen->winsys, s); +} + + +static void * +softpipe_surface_map( struct pipe_screen *screen, + struct pipe_surface *surface, + unsigned flags ) +{ + ubyte *map; + + if (flags & ~surface->usage) { + assert(0); + return NULL; + } + + map = screen->winsys->buffer_map( screen->winsys, surface->buffer, flags ); + if (map == NULL) + return NULL; + + /* May want to different things here depending on read/write nature + * of the map: + */ + if (surface->texture && + (flags & PIPE_BUFFER_USAGE_GPU_WRITE)) + { + /* Do something to notify sharing contexts of a texture change. + * In softpipe, that would mean flushing the texture cache. + */ + softpipe_screen(screen)->timestamp++; } + + return map + surface->offset; +} + + +static void +softpipe_surface_unmap(struct pipe_screen *screen, + struct pipe_surface *surface) +{ + screen->winsys->buffer_unmap( screen->winsys, surface->buffer ); } void -softpipe_init_texture_funcs( struct softpipe_context *softpipe ) +softpipe_init_texture_funcs(struct softpipe_context *sp) { - softpipe->pipe.texture_update = softpipe_texture_update; } @@ -199,5 +237,10 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; screen->texture_release = softpipe_texture_release; + screen->get_tex_surface = softpipe_get_tex_surface; + screen->tex_surface_release = softpipe_tex_surface_release; + + screen->surface_map = softpipe_surface_map; + screen->surface_unmap = softpipe_surface_unmap; } diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index a7322144e6..2ba093320d 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -61,7 +61,6 @@ softpipe_texture(struct pipe_texture *pt) extern void softpipe_init_texture_funcs( struct softpipe_context *softpipe ); - extern void softpipe_init_screen_texture_funcs(struct pipe_screen *screen); diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index a88aad5d09..a3fd375a2d 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -49,6 +49,7 @@ struct softpipe_tile_cache { + struct pipe_screen *screen; struct pipe_surface *surface; /**< the surface we're caching */ void *surface_map; struct pipe_texture *texture; /**< if caching a texture */ @@ -109,13 +110,14 @@ clear_clear_flag(uint *bitvec, int x, int y) struct softpipe_tile_cache * -sp_create_tile_cache(void) +sp_create_tile_cache( struct pipe_screen *screen ) { struct softpipe_tile_cache *tc; uint pos; tc = CALLOC_STRUCT( softpipe_tile_cache ); if (tc) { + tc->screen = screen; for (pos = 0; pos < NUM_ENTRIES; pos++) { tc->entries[pos].x = tc->entries[pos].y = -1; @@ -154,16 +156,17 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, assert(!tc->texture); if (tc->surface_map) { - /*assert(tc->surface != ps);*/ - pipe_surface_unmap(tc->surface); + tc->screen->surface_unmap(tc->screen, tc->surface); tc->surface_map = NULL; } pipe_surface_reference(&tc->surface, ps); - if (ps) { - if (tc->surface_map) - tc->surface_map = pipe_surface_map(ps); + if (tc->surface) { + if (tc->surface_map) /* XXX: this is always NULL!? */ + tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || ps->format == PIPE_FORMAT_Z16_UNORM || @@ -187,10 +190,13 @@ void sp_tile_cache_map_surfaces(struct softpipe_tile_cache *tc) { if (tc->surface && !tc->surface_map) - tc->surface_map = pipe_surface_map(tc->surface); + tc->surface_map = tc->screen->surface_map(tc->screen, tc->surface, + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ); if (tc->tex_surf && !tc->tex_surf_map) - tc->tex_surf_map = pipe_surface_map(tc->tex_surf); + tc->tex_surf_map = tc->screen->surface_map(tc->screen, tc->tex_surf, + PIPE_BUFFER_USAGE_GPU_READ); } @@ -198,12 +204,12 @@ void sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc) { if (tc->surface_map) { - pipe_surface_unmap(tc->surface); + tc->screen->surface_unmap(tc->screen, tc->surface); tc->surface_map = NULL; } if (tc->tex_surf_map) { - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); tc->tex_surf_map = NULL; } } @@ -224,7 +230,7 @@ sp_tile_cache_set_texture(struct pipe_context *pipe, pipe_texture_reference(&tc->texture, texture); if (tc->tex_surf_map) { - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); tc->tex_surf_map = NULL; } pipe_surface_reference(&tc->tex_surf, NULL); @@ -514,10 +520,12 @@ sp_get_cached_tile_tex(struct pipe_context *pipe, /* get new surface (view into texture) */ if (tc->tex_surf_map) - pipe_surface_unmap(tc->tex_surf); + tc->screen->surface_unmap(tc->screen, tc->tex_surf); - tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z); - tc->tex_surf_map = pipe_surface_map(tc->tex_surf); + tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z, + PIPE_BUFFER_USAGE_GPU_READ); + tc->tex_surf_map = screen->surface_map(screen, tc->tex_surf, + PIPE_BUFFER_USAGE_GPU_READ); tc->tex_face = face; tc->tex_level = level; diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h index 2631e29a3a..bc96c941f6 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tile_cache.h @@ -61,7 +61,7 @@ struct softpipe_cached_tile extern struct softpipe_tile_cache * -sp_create_tile_cache(void); +sp_create_tile_cache( struct pipe_screen *screen ); extern void sp_destroy_tile_cache(struct softpipe_tile_cache *tc); diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index f3a9c2cd8b..0f68f592f7 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -198,12 +198,6 @@ struct pipe_context { /*@}*/ - /** Called when texture data is changed */ - void (*texture_update)(struct pipe_context *pipe, - struct pipe_texture *texture, - uint face, uint dirtyLevelsMask); - - /** Flush rendering (flags = bitmask of PIPE_FLUSH_x tokens) */ void (*flush)( struct pipe_context *pipe, unsigned flags, diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index 8eb604e73f..592c3c87c2 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -39,20 +39,6 @@ extern "C" { #endif -static INLINE void * -pipe_surface_map(struct pipe_surface *surface) -{ - return (char *)surface->winsys->buffer_map( surface->winsys, surface->buffer, - PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_CPU_READ ) - + surface->offset; -} - -static INLINE void -pipe_surface_unmap(struct pipe_surface *surface) -{ - surface->winsys->buffer_unmap( surface->winsys, surface->buffer ); -} /** * Set 'ptr' to point to 'surf' and update reference counting. @@ -66,9 +52,20 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) if (surf) surf->refcount++; - if (*ptr /* && --(*ptr)->refcount == 0 */) { - struct pipe_winsys *winsys = (*ptr)->winsys; - winsys->surface_release(winsys, ptr); + if (*ptr) { + + /* There are currently two sorts of surfaces... This needs to be + * fixed so that all surfaces are views into a texture. + */ + if ((*ptr)->texture) { + struct pipe_screen *screen = (*ptr)->texture->screen; + screen->tex_surface_release( screen, ptr ); + } + else { + struct pipe_winsys *winsys = (*ptr)->winsys; + winsys->surface_release(winsys, ptr); + } + assert(!*ptr); } diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 26ac99d287..c080579c26 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -96,7 +96,22 @@ struct pipe_screen { struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, struct pipe_texture *texture, unsigned face, unsigned level, - unsigned zslice); + unsigned zslice, + unsigned usage ); + + /* Surfaces allocated by the above must be released here: + */ + void (*tex_surface_release)( struct pipe_screen *, + struct pipe_surface ** ); + + + void *(*surface_map)( struct pipe_screen *, + struct pipe_surface *surface, + unsigned flags ); + + void (*surface_unmap)( struct pipe_screen *, + struct pipe_surface *surface ); + }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 912d84e7b9..62b05a403b 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -273,7 +273,11 @@ struct pipe_surface unsigned pitch; /**< in pixels */ unsigned offset; /**< offset from start of buffer, in bytes */ unsigned refcount; + unsigned usage; /**< PIPE_BUFFER_USAGE_* */ + struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ + + struct pipe_texture *texture; /**< optional texture into which this is a view */ }; diff --git a/src/gallium/include/pipe/p_util.h b/src/gallium/include/pipe/p_util.h index 0e7e246666..0d8ed167b2 100644 --- a/src/gallium/include/pipe/p_util.h +++ b/src/gallium/include/pipe/p_util.h @@ -204,7 +204,10 @@ mem_dup(const void *src, uint size) #define MIN2( A, B ) ( (A)<(B) ? (A) : (B) ) #define MAX2( A, B ) ( (A)>(B) ? (A) : (B) ) +#ifndef Elements #define Elements(x) (sizeof(x)/sizeof((x)[0])) +#endif + #define Offset(TYPE, MEMBER) ((unsigned)&(((TYPE *)NULL)->MEMBER)) /** diff --git a/src/gallium/include/pipe/p_winsys.h b/src/gallium/include/pipe/p_winsys.h index 3005ec2d94..87a66b66d7 100644 --- a/src/gallium/include/pipe/p_winsys.h +++ b/src/gallium/include/pipe/p_winsys.h @@ -90,7 +90,7 @@ struct pipe_winsys void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); - + /** * Buffer management. Buffer attributes are mostly fixed over its lifetime. * diff --git a/src/gallium/winsys/xlib/xm_winsys.c b/src/gallium/winsys/xlib/xm_winsys.c index 8a89278cde..fd2f56eff2 100644 --- a/src/gallium/winsys/xlib/xm_winsys.c +++ b/src/gallium/winsys/xlib/xm_winsys.c @@ -508,6 +508,7 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys, surf->format = format; surf->cpp = pf_get_size(format); surf->pitch = round_up(width, alignment / surf->cpp); + surf->usage = flags; #ifdef GALLIUM_CELL /* XXX a bit of a hack */ height = round_up(height, TILE_SIZE); @@ -562,6 +563,7 @@ static void xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s) { struct pipe_surface *surf = *s; + assert(!surf->texture); surf->refcount--; if (surf->refcount == 0) { if (surf->buffer) diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 76356bbad7..e7186a85da 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -148,8 +148,10 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) uint *dest; uint i, j; - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); - dest = (uint *) pipe_surface_map(surface); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + dest = (uint *) screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* Pack four 1D maps into a 2D texture: * R map is placed horizontally, indexed by S, in channel 0 @@ -168,9 +170,8 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) } } - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 1636bed91a..e4ef3e16b7 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -106,13 +106,15 @@ 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; + struct pipe_screen *screen = ctx->st->pipe->screen; 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; GLvoid *map; - map = pipe_surface_map(acc_ps); + map = screen->surface_map(screen, acc_ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* note acc_strb->format might not equal acc_ps->format */ switch (acc_strb->format) { @@ -140,7 +142,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) _mesa_problem(ctx, "unexpected format in st_clear_accum_buffer()"); } - pipe_surface_unmap(acc_ps); + screen->surface_unmap(screen, acc_ps); } @@ -150,10 +152,12 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, GLint xpos, GLint ypos, GLint width, GLint height, struct st_renderbuffer *acc_strb) { + struct pipe_screen *screen = ctx->st->pipe->screen; struct pipe_surface *acc_ps = acc_strb->surface; GLvoid *map; - map = pipe_surface_map(acc_ps); + map = screen->surface_map(screen, acc_ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* note acc_strb->format might not equal acc_ps->format */ switch (acc_strb->format) { @@ -174,7 +178,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, _mesa_problem(NULL, "unexpected format in st_clear_accum_buffer()"); } - pipe_surface_unmap(acc_ps); + screen->surface_unmap(screen, acc_ps); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index ce8fefe703..873b765c2c 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -327,10 +327,11 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, return NULL; } - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); /* map texture surface */ - dest = pipe_surface_map(surface); + dest = screen->surface_map(screen, surface, PIPE_BUFFER_USAGE_CPU_WRITE); /* Put image into texture surface */ memset(dest, 0xff, height * surface->pitch); @@ -340,9 +341,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, _mesa_unmap_bitmap_pbo(ctx, unpack); /* Release surface */ - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); return pt; } @@ -544,8 +544,10 @@ reset_cache(struct st_context *st) /* Map the texture surface. * Subsequent glBitmap calls will write into the texture image. */ - cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0); - cache->buffer = pipe_surface_map(cache->surf); + cache->surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); + cache->buffer = screen->surface_map(screen, cache->surf, + PIPE_BUFFER_USAGE_CPU_WRITE); /* init image to all 0xff */ memset(cache->buffer, 0xff, BITMAP_CACHE_WIDTH * BITMAP_CACHE_HEIGHT); @@ -562,6 +564,7 @@ st_flush_bitmap_cache(struct st_context *st) if (st->ctx->DrawBuffer) { struct bitmap_cache *cache = st->bitmap.cache; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; assert(cache->xmin <= cache->xmax); /* @@ -574,12 +577,18 @@ st_flush_bitmap_cache(struct st_context *st) /* The texture surface has been mapped until now. * So unmap and release the texture surface before drawing. */ +#if 0 pipe_surface_unmap(cache->surf); pipe_surface_reference(&cache->surf, NULL); +#else + screen->surface_unmap(screen, cache->surf); + screen->tex_surface_release(screen, &cache->surf); +#endif +#if 0 /* XXX is this needed? */ pipe->texture_update(pipe, cache->texture, 0, 0x1); - +#endif draw_bitmap_quad(st->ctx, cache->xpos, cache->ypos, diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 65bfd6cfcc..9ae53c95f8 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -362,10 +362,12 @@ make_texture(struct st_context *st, /* we'll do pixel transfer in a fragment shader */ ctx->_ImageTransferState = 0x0; - surface = screen->get_tex_surface(screen, pt, 0, 0, 0); + surface = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); /* map texture surface */ - dest = pipe_surface_map(surface); + dest = screen->surface_map(screen, surface, + PIPE_BUFFER_USAGE_CPU_WRITE); /* Put image into texture surface. * Note that the image is actually going to be upside down in @@ -384,9 +386,8 @@ make_texture(struct st_context *st, unpack); /* unmap */ - pipe_surface_unmap(surface); + screen->surface_unmap(screen, surface); pipe_surface_reference(&surface, NULL); - pipe->texture_update(pipe, pt, 0, 0x1); assert(success); @@ -731,6 +732,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, { struct st_context *st = ctx->st; struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; struct pipe_surface *ps = st->state.framebuffer.zsbuf; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0 || ctx->Pixel.ZoomY != 1.0; GLint skipPixels; @@ -739,7 +741,8 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* map the stencil buffer */ - stmap = pipe_surface_map(ps); + stmap = screen->surface_map(screen, ps, + PIPE_BUFFER_USAGE_CPU_WRITE); /* if width > MAX_WIDTH, have to process image in chunks */ skipPixels = 0; @@ -796,7 +799,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, } /* unmap the stencil buffer */ - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } @@ -869,6 +872,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, GLint dstx, GLint dsty) { struct st_renderbuffer *rbDraw = st_renderbuffer(ctx->DrawBuffer->_StencilBuffer); + struct pipe_screen *screen = ctx->st->pipe->screen; struct pipe_surface *psDraw = rbDraw->surface; ubyte *drawMap; ubyte *buffer; @@ -885,7 +889,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, &ctx->DefaultPacking, buffer); /* map the stencil buffer */ - drawMap = pipe_surface_map(psDraw); + drawMap = screen->surface_map(screen, psDraw, PIPE_BUFFER_USAGE_CPU_WRITE); /* draw */ /* XXX PixelZoom not handled yet */ @@ -925,7 +929,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, free(buffer); /* unmap the stencil buffer */ - pipe_surface_unmap(psDraw); + screen->surface_unmap(screen, psDraw); } @@ -994,13 +998,14 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, if (!pt) return; - psTex = screen->get_tex_surface(screen, pt, 0, 0, 0); - if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { srcy = ctx->DrawBuffer->Height - srcy - height; } if (srcFormat == texFormat) { + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_WRITE ); + /* copy source framebuffer surface into mipmap/texture */ pipe->surface_copy(pipe, FALSE, @@ -1009,21 +1014,26 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, psRead, srcx, srcy, width, height); } - else if (type == GL_COLOR) { - /* alternate path using get/put_tile() */ - GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); + else { + psTex = screen->get_tex_surface(screen, pt, 0, 0, 0, + PIPE_BUFFER_USAGE_CPU_WRITE ); - pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); - pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); + if (type == GL_COLOR) { + /* alternate path using get/put_tile() */ + GLfloat *buf = (GLfloat *) malloc(width * height * 4 * sizeof(GLfloat)); - free(buf); - } - else { - /* GL_DEPTH */ - GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint)); - pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf); - pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf); - free(buf); + pipe_get_tile_rgba(pipe, psRead, srcx, srcy, width, height, buf); + pipe_put_tile_rgba(pipe, psTex, 0, 0, width, height, buf); + + free(buf); + } + else { + /* GL_DEPTH */ + GLuint *buf = (GLuint *) malloc(width * height * sizeof(GLuint)); + pipe_get_tile_z(pipe, psRead, srcx, srcy, width, height, buf); + pipe_put_tile_z(pipe, psTex, 0, 0, width, height, buf); + free(buf); + } } /* draw textured quad */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index fc8a5ea7f6..7fdc0bddd6 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -91,9 +91,14 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); enum pipe_format pipeFormat; - GLbitfield flags = 0x0; /* XXX needed? */ + unsigned flags = (PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ); int ret; + pipe_surface_reference( &strb->surface, NULL ); + if (!strb->surface) { /* first time surface creation */ strb->surface = pipe->winsys->surface_alloc(pipe->winsys); @@ -103,11 +108,16 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, if (!strb->surface) return GL_FALSE; } +#if 0 else if (strb->surface->buffer) { /* release/discard the old surface buffer */ pipe_reference_buffer(pipe, &strb->surface->buffer, NULL); } - +#else + else { + assert(0); + } +#endif /* Determine surface format here */ if (strb->format != PIPE_FORMAT_NONE) { assert(strb->format != 0); @@ -368,7 +378,11 @@ st_render_texture(GLcontext *ctx, strb->surface = screen->get_tex_surface(screen, pt, att->CubeMapFace, att->TextureLevel, - att->Zoffset); + att->Zoffset, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); assert(strb->surface); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_TEXTURE)); assert(screen->is_format_supported(screen, strb->surface->format, PIPE_SURFACE)); @@ -396,22 +410,19 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { + struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); assert(strb); ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); - ctx->st->pipe->texture_update(ctx->st->pipe, - st_get_texobj_texture(att->Texture), - att->CubeMapFace, 1 << att->TextureLevel); + screen->tex_surface_release( screen, &strb->surface ); /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); */ - pipe_surface_reference(&strb->surface, NULL); - _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* restore previous framebuffer state */ diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index ddbe36106c..e242195e7a 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -61,13 +61,14 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLvoid *pixels) { struct gl_framebuffer *fb = ctx->ReadBuffer; + struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(fb->_StencilBuffer); struct pipe_surface *ps = strb->surface; ubyte *stmap; GLint j; /* map the stencil buffer */ - stmap = pipe_surface_map(ps); + stmap = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ); /* width should never be > MAX_WIDTH since we did clipping earlier */ ASSERT(width <= MAX_WIDTH); @@ -124,7 +125,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ - pipe_surface_unmap(ps); + screen->surface_unmap(screen, ps); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 981246221b..05e0339e0e 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -478,7 +478,6 @@ st_TexImage(GLcontext * ctx, struct gl_texture_image *texImage, GLsizei imageSize, int compressed) { - struct pipe_context *pipe = ctx->st->pipe; struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLint postConvWidth, postConvHeight; @@ -635,7 +634,8 @@ st_TexImage(GLcontext * ctx, return; if (stImage->pt) { - texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + PIPE_BUFFER_USAGE_CPU_WRITE); dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } else { @@ -684,8 +684,9 @@ st_TexImage(GLcontext * ctx, } if (stImage->pt && i < depth) { - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i, + PIPE_BUFFER_USAGE_CPU_WRITE); src += srcImageStride; } } @@ -694,13 +695,10 @@ st_TexImage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, unpack); if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } - if (stObj->pt) - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); - if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); } @@ -793,7 +791,8 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Image is stored in hardware format in a buffer managed by the * kernel. Need to explicitly map and unmap it. */ - texImage->Data = st_texture_image_map(ctx->st, stImage, 0); + texImage->Data = st_texture_image_map(ctx->st, stImage, 0, + PIPE_BUFFER_USAGE_CPU_READ); texImage->RowStride = stImage->surface->pitch; } else { @@ -823,8 +822,9 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, } if (stImage->pt && i < depth) { - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, i, + PIPE_BUFFER_USAGE_CPU_READ); dest += dstImageStride; } } @@ -833,7 +833,7 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level, /* Unmap */ if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } } @@ -874,8 +874,6 @@ st_TexSubimage(GLcontext * ctx, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - struct pipe_context *pipe = ctx->st->pipe; - struct st_texture_object *stObj = st_texture_object(texObj); struct st_texture_image *stImage = st_texture_image(texImage); GLuint dstRowStride; GLuint srcImageStride = _mesa_image_image_stride(packing, width, height, @@ -897,7 +895,8 @@ st_TexSubimage(GLcontext * ctx, * from uploading the buffer under us. */ if (stImage->pt) { - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset, + PIPE_BUFFER_USAGE_CPU_WRITE); dstRowStride = stImage->surface->pitch * stImage->surface->cpp; } @@ -922,8 +921,9 @@ st_TexSubimage(GLcontext * ctx, if (stImage->pt && i < depth) { /* map next slice of 3D texture */ - st_texture_image_unmap(stImage); - texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i); + st_texture_image_unmap(ctx->st, stImage); + texImage->Data = st_texture_image_map(ctx->st, stImage, zoffset + i, + PIPE_BUFFER_USAGE_CPU_WRITE); src += srcImageStride; } } @@ -935,11 +935,9 @@ st_TexSubimage(GLcontext * ctx, _mesa_unmap_teximage_pbo(ctx, packing); if (stImage->pt) { - st_texture_image_unmap(stImage); + st_texture_image_unmap(ctx->st, stImage); texImage->Data = NULL; } - - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); } @@ -1058,7 +1056,8 @@ fallback_copy_texsubimage(GLcontext *ctx, src_surf = strb->surface; - dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ); + dest_surf = screen->get_tex_surface(screen, pt, face, level, destZ, + PIPE_BUFFER_USAGE_CPU_WRITE); assert(width <= MAX_WIDTH); @@ -1119,7 +1118,6 @@ do_copy_texsubimage(GLcontext *ctx, struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level); struct st_texture_image *stImage = st_texture_image(texImage); - struct st_texture_object *stObj = st_texture_object(texObj); GLenum baseFormat = texImage->InternalFormat; struct gl_framebuffer *fb = ctx->ReadBuffer; struct st_renderbuffer *strb; @@ -1157,7 +1155,8 @@ do_copy_texsubimage(GLcontext *ctx, dest_format = stImage->pt->format; dest_surface = screen->get_tex_surface(screen, stImage->pt, stImage->face, - stImage->level, destZ); + stImage->level, destZ, + PIPE_BUFFER_USAGE_CPU_WRITE); if (ctx->_ImageTransferState == 0x0 && strb->surface->buffer && @@ -1223,8 +1222,6 @@ do_copy_texsubimage(GLcontext *ctx, pipe_surface_reference(&dest_surface, NULL); - pipe->texture_update(pipe, stObj->pt, stImage->face, (1 << level)); - if (level == texObj->BaseLevel && texObj->GenerateMipmap) { ctx->Driver.GenerateMipmap(ctx, target, texObj); } @@ -1529,7 +1526,6 @@ st_finalize_texture(GLcontext *ctx, if (stImage && stObj->pt != stImage->pt) { copy_image_data_to_texture(ctx->st, stObj, level, stImage); *needFlush = GL_TRUE; - pipe->texture_update(pipe, stObj->pt, face, (1 << level)); } } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 1a0e19c2f9..cfacfdd04c 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -123,8 +123,10 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, const ubyte *srcData; ubyte *dstData; - srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice); - dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice); + srcSurf = screen->get_tex_surface(screen, pt, face, srcLevel, zslice, + PIPE_BUFFER_USAGE_CPU_READ); + dstSurf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, + PIPE_BUFFER_USAGE_CPU_WRITE); srcData = (ubyte *) pipe_buffer_map(pipe, srcSurf->buffer, PIPE_BUFFER_USAGE_CPU_READ) diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index f68bef1207..482a054f64 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -184,25 +184,30 @@ st_texture_image_offset(const struct pipe_texture * pt, */ GLubyte * st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, - GLuint zoffset) + GLuint zoffset, + GLuint flags ) { struct pipe_screen *screen = st->pipe->screen; struct pipe_texture *pt = stImage->pt; DBG("%s \n", __FUNCTION__); stImage->surface = screen->get_tex_surface(screen, pt, stImage->face, - stImage->level, zoffset); + stImage->level, zoffset, + flags); - return pipe_surface_map(stImage->surface); + return screen->surface_map(screen, stImage->surface, flags); } void -st_texture_image_unmap(struct st_texture_image *stImage) +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage) { + struct pipe_screen *screen = st->pipe->screen; + DBG("%s\n", __FUNCTION__); - pipe_surface_unmap(stImage->surface); + screen->surface_unmap(screen, stImage->surface); pipe_surface_reference(&stImage->surface, NULL); } @@ -224,12 +229,15 @@ st_surface_data(struct pipe_context *pipe, const void *src, unsigned src_pitch, unsigned srcx, unsigned srcy, unsigned width, unsigned height) { - pipe_copy_rect(pipe_surface_map(dst), + struct pipe_screen *screen = pipe->screen; + void *map = screen->surface_map(screen, dst, PIPE_BUFFER_USAGE_CPU_WRITE); + + pipe_copy_rect(map, dst->cpp, dst->pitch, dstx, dsty, width, height, src, src_pitch, srcx, srcy); - pipe_surface_unmap(dst); + screen->surface_unmap(screen, dst); } @@ -256,7 +264,8 @@ st_texture_image_data(struct pipe_context *pipe, if(dst->compressed) height /= 4; - dst_surface = screen->get_tex_surface(screen, dst, face, level, i); + dst_surface = screen->get_tex_surface(screen, dst, face, level, i, + PIPE_BUFFER_USAGE_CPU_WRITE); st_surface_data(pipe, dst_surface, 0, 0, /* dstx, dsty */ @@ -265,7 +274,7 @@ st_texture_image_data(struct pipe_context *pipe, 0, 0, /* source x, y */ dst->width[level], height); /* width, height */ - pipe_surface_reference(&dst_surface, NULL); + screen->tex_surface_release(screen, &dst_surface); srcUB += src_image_pitch * dst->cpp; } @@ -304,8 +313,11 @@ st_texture_image_copy(struct pipe_context *pipe, assert(src->width[srcLevel] == width); assert(src->height[srcLevel] == height); - dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i); - src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i); + dst_surface = screen->get_tex_surface(screen, dst, face, dstLevel, i, + PIPE_BUFFER_USAGE_GPU_WRITE); + + src_surface = screen->get_tex_surface(screen, src, face, srcLevel, i, + PIPE_BUFFER_USAGE_GPU_READ); pipe->surface_copy(pipe, FALSE, diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index 7abccb3a69..f6d5733e21 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -121,10 +121,12 @@ st_texture_match_image(const struct pipe_texture *pt, extern GLubyte * st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, - GLuint zoffset); + GLuint zoffset, + GLuint flags); extern void -st_texture_image_unmap(struct st_texture_image *stImage); +st_texture_image_unmap(struct st_context *st, + struct st_texture_image *stImage); /* Return pointers to each 2d slice within an image. Indexed by depth -- cgit v1.2.3 From 54507125e735ffa595e252282eaabf38095c21e1 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 2 May 2008 10:08:03 +0000 Subject: Some changed for non-C99 compilers --- src/mesa/state_tracker/st_atom_blend.c | 15 +++++--------- src/mesa/state_tracker/st_atom_clip.c | 15 +++++--------- src/mesa/state_tracker/st_atom_constbuf.c | 20 +++++++++--------- src/mesa/state_tracker/st_atom_depth.c | 10 ++++----- src/mesa/state_tracker/st_atom_fixedfunction.c | 10 ++++----- src/mesa/state_tracker/st_atom_framebuffer.c | 10 ++++----- src/mesa/state_tracker/st_atom_pixeltransfer.c | 10 ++++----- src/mesa/state_tracker/st_atom_rasterizer.c | 12 +++++------ src/mesa/state_tracker/st_atom_sampler.c | 15 +++++--------- src/mesa/state_tracker/st_atom_scissor.c | 15 +++++--------- src/mesa/state_tracker/st_atom_shader.c | 10 ++++----- src/mesa/state_tracker/st_atom_stipple.c | 10 ++++----- src/mesa/state_tracker/st_atom_texture.c | 15 +++++--------- src/mesa/state_tracker/st_atom_viewport.c | 10 ++++----- src/mesa/state_tracker/st_cb_clear.c | 2 +- src/mesa/state_tracker/st_draw.c | 5 +++-- src/mesa/state_tracker/st_extensions.c | 28 +++++++++++++------------- 17 files changed, 94 insertions(+), 118 deletions(-) mode change 100644 => 100755 src/mesa/state_tracker/st_atom_blend.c mode change 100644 => 100755 src/mesa/state_tracker/st_atom_clip.c mode change 100644 => 100755 src/mesa/state_tracker/st_atom_constbuf.c (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c old mode 100644 new mode 100755 index 2a0e92245c..35c09c3e08 --- a/src/mesa/state_tracker/st_atom_blend.c +++ b/src/mesa/state_tracker/st_atom_blend.c @@ -223,15 +223,10 @@ update_blend( struct st_context *st ) const struct st_tracked_state st_update_blend = { - .name = "st_update_blend", - .dirty = { - .mesa = (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ - .st = 0, + "st_update_blend", /* name */ + { /* dirty */ + (_NEW_COLOR), /* XXX _NEW_BLEND someday? */ /* mesa */ + 0, /* st */ }, - .update = update_blend + update_blend, /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_clip.c b/src/mesa/state_tracker/st_atom_clip.c old mode 100644 new mode 100755 index a6f0568660..23d709b814 --- a/src/mesa/state_tracker/st_atom_clip.c +++ b/src/mesa/state_tracker/st_atom_clip.c @@ -62,15 +62,10 @@ static void update_clip( struct st_context *st ) const struct st_tracked_state st_update_clip = { - .name = "st_update_clip", - .dirty = { - .mesa = (_NEW_TRANSFORM), - .st = 0, + "st_update_clip", /* name */ + { /* dirty */ + (_NEW_TRANSFORM), /* mesa */ + 0, /* st */ }, - .update = update_clip + update_clip /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c old mode 100644 new mode 100755 index 2b659aebbc..2856e0f0e0 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -113,12 +113,12 @@ static void update_vs_constants(struct st_context *st ) } const struct st_tracked_state st_update_vs_constants = { - .name = "st_update_vs_constants", - .dirty = { - .mesa = 0, /* set dynamically above */ - .st = ST_NEW_VERTEX_PROGRAM, + "st_update_vs_constants", /* name */ + { /* dirty */ + 0, /* set dynamically above */ /* mesa */ + ST_NEW_VERTEX_PROGRAM, /* st */ }, - .update = update_vs_constants + update_vs_constants /* update */ }; /* Fragment shader: @@ -132,11 +132,11 @@ static void update_fs_constants(struct st_context *st ) } const struct st_tracked_state st_update_fs_constants = { - .name = "st_update_fs_constants", - .dirty = { - .mesa = 0, /* set dynamically above */ - .st = ST_NEW_FRAGMENT_PROGRAM, + "st_update_fs_constants", /* name */ + { /* dirty */ + 0, /* set dynamically above */ /* mesa */ + ST_NEW_FRAGMENT_PROGRAM, /* st */ }, - .update = update_fs_constants + update_fs_constants /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index ef467582c0..0e791ceb20 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -142,10 +142,10 @@ update_depth_stencil_alpha(struct st_context *st) const struct st_tracked_state st_update_depth_stencil_alpha = { - .name = "st_update_depth_stencil", - .dirty = { - .mesa = (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), - .st = 0, + "st_update_depth_stencil", /* name */ + { /* dirty */ + (_NEW_DEPTH|_NEW_STENCIL|_NEW_COLOR), /* mesa */ + 0, /* st */ }, - .update = update_depth_stencil_alpha + update_depth_stencil_alpha /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_fixedfunction.c b/src/mesa/state_tracker/st_atom_fixedfunction.c index 3f137e1633..165567af70 100644 --- a/src/mesa/state_tracker/st_atom_fixedfunction.c +++ b/src/mesa/state_tracker/st_atom_fixedfunction.c @@ -55,12 +55,12 @@ static void update_tnl( struct st_context *st ) const struct st_tracked_state st_update_tnl = { - .name = "st_update_tnl", - .dirty = { - .mesa = TNL_FIXED_FUNCTION_STATE_FLAGS, - .st = 0 + "st_update_tnl", /* name */ + { /* dirty */ + TNL_FIXED_FUNCTION_STATE_FLAGS, /* mesa */ + 0 /* st */ }, - .update = update_tnl + update_tnl /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_framebuffer.c b/src/mesa/state_tracker/st_atom_framebuffer.c index 14eeb58cc1..0a6974d8a7 100644 --- a/src/mesa/state_tracker/st_atom_framebuffer.c +++ b/src/mesa/state_tracker/st_atom_framebuffer.c @@ -96,11 +96,11 @@ update_framebuffer_state( struct st_context *st ) const struct st_tracked_state st_update_framebuffer = { - .name = "st_update_framebuffer", - .dirty = { - .mesa = _NEW_BUFFERS, - .st = 0, + "st_update_framebuffer", /* name */ + { /* dirty */ + _NEW_BUFFERS, /* mesa */ + 0, /* st */ }, - .update = update_framebuffer_state + update_framebuffer_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 76356bbad7..999c148449 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -463,10 +463,10 @@ update_pixel_transfer(struct st_context *st) const struct st_tracked_state st_update_pixel_transfer = { - .name = "st_update_pixel_transfer", - .dirty = { - .mesa = _NEW_PIXEL | _NEW_COLOR_MATRIX, - .st = 0, + "st_update_pixel_transfer", /* name */ + { /* dirty */ + _NEW_PIXEL | _NEW_COLOR_MATRIX, /* mesa */ + 0, /* st */ }, - .update = update_pixel_transfer + update_pixel_transfer /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c index bb14cf9045..87a91d56d0 100644 --- a/src/mesa/state_tracker/st_atom_rasterizer.c +++ b/src/mesa/state_tracker/st_atom_rasterizer.c @@ -267,11 +267,11 @@ static void update_raster_state( struct st_context *st ) } const struct st_tracked_state st_update_rasterizer = { - .name = "st_update_rasterizer", - .dirty = { - .mesa = (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | - _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), - .st = 0, + "st_update_rasterizer", /* name */ + { /* dirty */ + (_NEW_LIGHT | _NEW_POLYGON | _NEW_LINE | _NEW_SCISSOR | /* mesa */ + _NEW_POINT | _NEW_BUFFERS | _NEW_MULTISAMPLE), + 0, /* st */ }, - .update = update_raster_state + update_raster_state /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 0237da3693..7515bb30cc 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -185,15 +185,10 @@ update_samplers(struct st_context *st) const struct st_tracked_state st_update_sampler = { - .name = "st_update_sampler", - .dirty = { - .mesa = _NEW_TEXTURE, - .st = 0, + "st_update_sampler", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + 0, /* st */ }, - .update = update_samplers + update_samplers /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index 59601e91a1..f5db492403 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -83,15 +83,10 @@ update_scissor( struct st_context *st ) const struct st_tracked_state st_update_scissor = { - .name = "st_update_scissor", - .dirty = { - .mesa = (_NEW_SCISSOR | _NEW_BUFFERS), - .st = 0, + "st_update_scissor", /* name */ + { /* dirty */ + (_NEW_SCISSOR | _NEW_BUFFERS), /* mesa */ + 0, /* st */ }, - .update = update_scissor + update_scissor /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index 3f5ec71112..652500f52a 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -281,10 +281,10 @@ update_linkage( struct st_context *st ) const struct st_tracked_state st_update_shader = { - .name = "st_update_shader", - .dirty = { - .mesa = 0, - .st = ST_NEW_VERTEX_PROGRAM | ST_NEW_FRAGMENT_PROGRAM + "st_update_shader", /* name */ + { /* dirty */ + 0, /* mesa */ + ST_NEW_VERTEX_PROGRAM | ST_NEW_FRAGMENT_PROGRAM /* st */ }, - .update = update_linkage + update_linkage /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_stipple.c b/src/mesa/state_tracker/st_atom_stipple.c index c91214059a..f395930ab4 100644 --- a/src/mesa/state_tracker/st_atom_stipple.c +++ b/src/mesa/state_tracker/st_atom_stipple.c @@ -54,10 +54,10 @@ update_stipple( struct st_context *st ) const struct st_tracked_state st_update_polygon_stipple = { - .name = "st_update_polygon_stipple", - .dirty = { - .mesa = (_NEW_POLYGONSTIPPLE), - .st = 0, + "st_update_polygon_stipple", /* name */ + { /* dirty */ + (_NEW_POLYGONSTIPPLE), /* mesa */ + 0, /* st */ }, - .update = update_stipple + update_stipple /* update */ }; diff --git a/src/mesa/state_tracker/st_atom_texture.c b/src/mesa/state_tracker/st_atom_texture.c index d15da5895a..f42b2f8d66 100644 --- a/src/mesa/state_tracker/st_atom_texture.c +++ b/src/mesa/state_tracker/st_atom_texture.c @@ -111,15 +111,10 @@ update_textures(struct st_context *st) const struct st_tracked_state st_update_texture = { - .name = "st_update_texture", - .dirty = { - .mesa = _NEW_TEXTURE, - .st = ST_NEW_FRAGMENT_PROGRAM, + "st_update_texture", /* name */ + { /* dirty */ + _NEW_TEXTURE, /* mesa */ + ST_NEW_FRAGMENT_PROGRAM, /* st */ }, - .update = update_textures + update_textures /* update */ }; - - - - - diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index eb3f62cfbe..4b51521470 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -82,10 +82,10 @@ update_viewport( struct st_context *st ) const struct st_tracked_state st_update_viewport = { - .name = "st_update_viewport", - .dirty = { - .mesa = _NEW_BUFFERS | _NEW_VIEWPORT, - .st = 0, + "st_update_viewport", /* name */ + { /* dirty */ + _NEW_BUFFERS | _NEW_VIEWPORT, /* mesa */ + 0, /* st */ }, - .update = update_viewport + update_viewport /* update */ }; diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index fe979f10bd..b7d7204633 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -34,8 +34,8 @@ #include "main/glheader.h" #include "main/macros.h" #include "shader/prog_instruction.h" -#include "st_atom.h" #include "st_context.h" +#include "st_atom.h" #include "st_cb_accum.h" #include "st_cb_clear.h" #include "st_cb_fbo.h" diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 0fe4d198bd..a3bffbfc95 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -35,8 +35,8 @@ #include "vbo/vbo.h" -#include "st_atom.h" #include "st_context.h" +#include "st_atom.h" #include "st_cb_bufferobjects.h" #include "st_draw.h" #include "st_program.h" @@ -549,9 +549,10 @@ st_feedback_draw_vbo(GLcontext *ctx, unsigned indexSize; struct gl_buffer_object *bufobj = ib->obj; struct st_buffer_object *stobj = st_buffer_object(bufobj); - index_buffer_handle = stobj->buffer; void *map; + index_buffer_handle = stobj->buffer; + switch (ib->type) { case GL_UNSIGNED_INT: indexSize = 4; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 260a2efe88..6f94ba39ae 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -38,17 +38,17 @@ #include "st_extensions.h" -static int min(int a, int b) +static int _min(int a, int b) { return (a < b) ? a : b; } -static int max(int a, int b) +static int _max(int a, int b) { return (a > b) ? a : b; } -static int clamp(int a, int min, int max) +static int _clamp(int a, int min, int max) { if (a < min) return min; @@ -69,42 +69,42 @@ void st_init_limits(struct st_context *st) struct gl_constants *c = &st->ctx->Const; c->MaxTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS), MAX_TEXTURE_LEVELS); c->Max3DTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS), MAX_3D_TEXTURE_LEVELS); c->MaxCubeTextureLevels - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS), MAX_CUBE_TEXTURE_LEVELS); c->MaxTextureRectSize - = min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE); + = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE); c->MaxTextureUnits = c->MaxTextureImageUnits = c->MaxTextureCoordUnits - = min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS), + = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS), MAX_TEXTURE_IMAGE_UNITS); c->MaxDrawBuffers - = clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), + = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS), 1, MAX_DRAW_BUFFERS); c->MaxLineWidth - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH)); c->MaxLineWidthAA - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_LINE_WIDTH_AA)); c->MaxPointSize - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH)); c->MaxPointSizeAA - = max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA)); + = _max(1.0, screen->get_paramf(screen, PIPE_CAP_MAX_POINT_WIDTH_AA)); c->MaxTextureMaxAnisotropy - = max(2.0, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY)); + = _max(2.0, screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_ANISOTROPY)); c->MaxTextureLodBias = screen->get_paramf(screen, PIPE_CAP_MAX_TEXTURE_LOD_BIAS); -- cgit v1.2.3 From a73ae3d5eb8419feab5aea26573aa41b72f941eb Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 2 May 2008 16:46:31 +0100 Subject: gallium: Add texture usage flags, special-case allocation of display targets For many envirionments it's necessary to allocate display targets in a window-system friendly manner. Add facilities so that a driver can tell if a texture is likely to be used to generate a display surface and if use special allocation paths if necessary. Hook up softpipe to call into the winsys->surface_alloc_storage() routine in this case, though we probably want to change that interface slightly also. --- src/gallium/drivers/softpipe/sp_texture.c | 101 ++++++++++++++++--------- src/gallium/drivers/softpipe/sp_texture.h | 2 +- src/gallium/include/pipe/p_state.h | 6 +- src/mesa/state_tracker/st_atom_pixeltransfer.c | 3 +- src/mesa/state_tracker/st_cb_bitmap.c | 6 +- src/mesa/state_tracker/st_cb_drawpixels.c | 6 +- src/mesa/state_tracker/st_cb_fbo.c | 23 ++++-- src/mesa/state_tracker/st_cb_texture.c | 10 ++- src/mesa/state_tracker/st_texture.c | 4 +- src/mesa/state_tracker/st_texture.h | 3 +- 10 files changed, 111 insertions(+), 53 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 2b31cd4f25..599ff2ac45 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -52,40 +52,87 @@ static unsigned minify( unsigned d ) } -static void -softpipe_texture_layout(struct softpipe_texture * spt) +/* Conventional allocation path for non-display textures: + */ +static boolean +softpipe_texture_layout(struct pipe_screen *screen, + struct softpipe_texture * spt) { + struct pipe_winsys *ws = screen->winsys; struct pipe_texture *pt = &spt->base; unsigned level; unsigned width = pt->width[0]; unsigned height = pt->height[0]; unsigned depth = pt->depth[0]; - spt->buffer_size = 0; + unsigned buffer_size = 0; for (level = 0; level <= pt->last_level; level++) { pt->width[level] = width; pt->height[level] = height; pt->depth[level] = depth; + spt->pitch[level] = width; - spt->level_offset[level] = spt->buffer_size; + spt->level_offset[level] = buffer_size; - spt->buffer_size += ((pt->compressed) ? MAX2(1, height/4) : height) * - ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * - width * pt->cpp; + buffer_size += (((pt->compressed) ? MAX2(1, height/4) : height) * + ((pt->target == PIPE_TEXTURE_CUBE) ? 6 : depth) * + width * pt->cpp); width = minify(width); height = minify(height); depth = minify(depth); } + + spt->buffer = ws->buffer_create(ws, 32, + PIPE_BUFFER_USAGE_PIXEL, + buffer_size); + + return spt->buffer != NULL; } + +/* Hack it up to use the old winsys->surface_alloc_storage() + * method for now: + */ +static boolean +softpipe_displaytarget_layout(struct pipe_screen *screen, + struct softpipe_texture * spt) +{ + struct pipe_winsys *ws = screen->winsys; + struct pipe_surface surf; + unsigned flags = (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE); + + + memset(&surf, 0, sizeof(surf)); + + ws->surface_alloc_storage( ws, + &surf, + spt->base.width[0], + spt->base.height[0], + spt->base.format, + flags); + + /* Now extract the goodies: + */ + spt->buffer = surf.buffer; + spt->pitch[0] = surf.pitch; + + return spt->buffer != NULL; +} + + + + + static struct pipe_texture * softpipe_texture_create(struct pipe_screen *screen, const struct pipe_texture *templat) { - struct pipe_winsys *ws = screen->winsys; struct softpipe_texture *spt = CALLOC_STRUCT(softpipe_texture); if (!spt) return NULL; @@ -94,19 +141,21 @@ softpipe_texture_create(struct pipe_screen *screen, spt->base.refcount = 1; spt->base.screen = screen; - softpipe_texture_layout(spt); - - spt->buffer = ws->buffer_create(ws, 32, - PIPE_BUFFER_USAGE_PIXEL, - spt->buffer_size); - if (!spt->buffer) { - FREE(spt); - return NULL; + if (spt->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { + if (!softpipe_displaytarget_layout(screen, spt)) + goto fail; } - + else { + if (!softpipe_texture_layout(screen, spt)) + goto fail; + } + assert(spt->base.refcount == 1); - return &spt->base; + + fail: + FREE(spt); + return NULL; } @@ -178,22 +227,6 @@ softpipe_get_tex_surface(struct pipe_screen *screen, assert(face == 0); assert(zslice == 0); } - - if (usage & (PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_GPU_WRITE)) { - /* XXX if writing to the texture, invalidate the texcache entries!!! - * - * Actually, no. Flushing dependent contexts is still done - * explicitly and separately. Hardware drivers won't insert - * FLUSH commands into a command stream at this point, - * neither should softpipe try to flush caches. - * - * Those contexts could be living in separate threads & doing - * all sorts of unrelated stuff... Context<->texture - * dependency tracking needs to happen elsewhere. - */ - /* assert(0); */ - } } return ps; } diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index 2ba093320d..779a9d8fc9 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -42,11 +42,11 @@ struct softpipe_texture struct pipe_texture base; unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; + unsigned long pitch[PIPE_MAX_TEXTURE_LEVELS]; /* The data is held here: */ struct pipe_buffer *buffer; - unsigned long buffer_size; }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 277ee4b319..d7565dff96 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -284,6 +284,10 @@ struct pipe_surface }; +#define PIPE_TEXTURE_USAGE_RENDER_TARGET 0x1 +#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* ie a backbuffer */ +#define PIPE_TEXTURE_USAGE_SAMPLER 0x4 + /** * Texture object. */ @@ -300,7 +304,7 @@ struct pipe_texture unsigned last_level:8; /**< Index of last mipmap level present/defined */ unsigned compressed:1; - unsigned usage; + unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */ /* These are also refcounted: */ diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 0c32d53c4a..e500ac8684 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -126,7 +126,8 @@ create_color_map_texture(GLcontext *ctx) /* create texture for color map/table */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, - texSize, texSize, 1, 0); + texSize, texSize, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); return pt; } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 873b765c2c..f816e59104 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -321,7 +321,8 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, * Create texture to hold bitmap pattern. */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, ctx->st->bitmap.tex_format, - 0, width, height, 1, 0); + 0, width, height, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_bitmap_pbo(ctx, unpack); return NULL; @@ -539,7 +540,8 @@ reset_cache(struct st_context *st) cache->texture = st_texture_create(st, PIPE_TEXTURE_2D, st->bitmap.tex_format, 0, BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, - 1, 0); + 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); /* Map the texture surface. * Subsequent glBitmap calls will write into the texture image. diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 9ae53c95f8..8c775ad886 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -346,7 +346,8 @@ make_texture(struct st_context *st, return NULL; pt = st_texture_create(st, PIPE_TEXTURE_2D, pipeFormat, 0, width, height, - 1, 0); + 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) { _mesa_unmap_drawpix_pbo(ctx, unpack); return NULL; @@ -994,7 +995,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, } pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, texFormat, 0, - width, height, 1, 0); + width, height, 1, 0, + PIPE_TEXTURE_USAGE_SAMPLER); if (!pt) return; diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index b174714171..21d61e2163 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -90,8 +90,8 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, { struct pipe_context *pipe = ctx->st->pipe; struct st_renderbuffer *strb = st_renderbuffer(rb); - struct pipe_texture template, *texture; + unsigned surface_usage; /* Free the old surface (and texture if we hold the last * reference): @@ -117,10 +117,15 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, template.height[0] = height; template.depth[0] = 1; template.last_level = 0; - template.usage = (PIPE_BUFFER_USAGE_CPU_WRITE | - PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_GPU_WRITE | - PIPE_BUFFER_USAGE_GPU_READ); + template.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_RENDER_TARGET); + + /* Probably need dedicated flags for surface usage too: + */ + surface_usage = (PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); texture = pipe->screen->texture_create( pipe->screen, &template ); @@ -137,11 +142,13 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, * to tell the driver to go ahead and allocate the buffer, even * if HW doesn't support the format. */ - template.usage = (PIPE_BUFFER_USAGE_CPU_READ | - PIPE_BUFFER_USAGE_CPU_WRITE); + template.tex_usage = 0; + surface_usage = (PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_CPU_WRITE); texture = pipe->screen->texture_create( pipe->screen, &template ); + } if (!texture) @@ -150,7 +157,7 @@ st_renderbuffer_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb, strb->surface = pipe->screen->get_tex_surface( pipe->screen, texture, 0, 0, 0, - template.usage ); + surface_usage ); pipe_texture_reference( &texture, NULL ); diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 4cca3364c1..06caa06e77 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -333,7 +333,9 @@ guess_and_alloc_texture(struct st_context *st, width, height, depth, - comp_byte); + comp_byte, + ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_SAMPLER )); DBG("%s - success\n", __FUNCTION__); } @@ -1501,7 +1503,11 @@ st_finalize_texture(GLcontext *ctx, firstImage->base.Width2, firstImage->base.Height2, firstImage->base.Depth2, - comp_byte); + comp_byte, + + ( PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_SAMPLER )); + if (!stObj->pt) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); return GL_FALSE; diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index d6268fc80c..2b3742d4e5 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -75,7 +75,8 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte) + GLuint compress_byte, + GLuint usage ) { struct pipe_texture pt, *newtex; struct pipe_screen *screen = st->pipe->screen; @@ -98,6 +99,7 @@ st_texture_create(struct st_context *st, pt.depth[0] = depth0; pt.compressed = compress_byte ? 1 : 0; pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format); + pt.tex_usage = usage; newtex = screen->texture_create(screen, &pt); diff --git a/src/mesa/state_tracker/st_texture.h b/src/mesa/state_tracker/st_texture.h index f6d5733e21..6a9f08ec6b 100644 --- a/src/mesa/state_tracker/st_texture.h +++ b/src/mesa/state_tracker/st_texture.h @@ -105,7 +105,8 @@ st_texture_create(struct st_context *st, GLuint width0, GLuint height0, GLuint depth0, - GLuint compress_byte); + GLuint compress_byte, + GLuint tex_usage ); /* Check if an image fits into an existing texture object. -- cgit v1.2.3 From 53174afeeb68a79e471185cb463c13ff90af698f Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sat, 31 May 2008 18:14:09 +0900 Subject: mesa: Apply MSVC portability fixes from Alan Hourihane. --- src/mesa/main/api_arrayelt.c | 96 +++++++++++++------------- src/mesa/main/api_validate.c | 2 +- src/mesa/main/context.c | 2 +- src/mesa/main/dlist.c | 2 +- src/mesa/main/drawpix.c | 2 +- src/mesa/main/framebuffer.c | 2 +- src/mesa/main/get.c | 4 +- src/mesa/main/image.c | 6 +- src/mesa/main/light.c | 2 +- src/mesa/main/mipmap.c | 2 +- src/mesa/main/pixel.c | 4 +- src/mesa/main/queryobj.c | 4 +- src/mesa/main/rastpos.c | 2 +- src/mesa/main/texenvprogram.c | 10 +-- src/mesa/shader/prog_execute.c | 6 +- src/mesa/shader/prog_statevars.c | 10 +-- src/mesa/shader/prog_uniform.c | 2 +- src/mesa/shader/shader_api.c | 6 +- src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 +- src/mesa/state_tracker/st_atom_scissor.c | 8 +-- src/mesa/state_tracker/st_atom_viewport.c | 12 ++-- src/mesa/state_tracker/st_cb_bitmap.c | 38 +++++----- src/mesa/vbo/vbo_exec_array.c | 2 +- src/mesa/vbo/vbo_split_inplace.c | 2 +- 24 files changed, 114 insertions(+), 114 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c index 72091b0789..d124c724c9 100644 --- a/src/mesa/main/api_arrayelt.c +++ b/src/mesa/main/api_arrayelt.c @@ -166,7 +166,7 @@ static void GLAPIENTRY VertexAttrib1NbvNV(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib1bvNV(GLuint index, const GLbyte *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v) @@ -176,7 +176,7 @@ static void GLAPIENTRY VertexAttrib2NbvNV(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib2bvNV(GLuint index, const GLbyte *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v) @@ -188,7 +188,7 @@ static void GLAPIENTRY VertexAttrib3NbvNV(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib3bvNV(GLuint index, const GLbyte *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v) @@ -201,7 +201,7 @@ static void GLAPIENTRY VertexAttrib4NbvNV(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib4bvNV(GLuint index, const GLbyte *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_BYTE attributes */ @@ -213,7 +213,7 @@ static void GLAPIENTRY VertexAttrib1NubvNV(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib1ubvNV(GLuint index, const GLubyte *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v) @@ -224,7 +224,7 @@ static void GLAPIENTRY VertexAttrib2NubvNV(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib2ubvNV(GLuint index, const GLubyte *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v) @@ -235,7 +235,7 @@ static void GLAPIENTRY VertexAttrib3NubvNV(GLuint index, const GLubyte *v) } static void GLAPIENTRY VertexAttrib3ubvNV(GLuint index, const GLubyte *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v) @@ -248,7 +248,7 @@ static void GLAPIENTRY VertexAttrib4NubvNV(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib4ubvNV(GLuint index, const GLubyte *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_SHORT attributes */ @@ -260,7 +260,7 @@ static void GLAPIENTRY VertexAttrib1NsvNV(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib1svNV(GLuint index, const GLshort *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v) @@ -271,7 +271,7 @@ static void GLAPIENTRY VertexAttrib2NsvNV(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib2svNV(GLuint index, const GLshort *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v) @@ -283,7 +283,7 @@ static void GLAPIENTRY VertexAttrib3NsvNV(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib3svNV(GLuint index, const GLshort *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v) @@ -296,7 +296,7 @@ static void GLAPIENTRY VertexAttrib4NsvNV(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib4svNV(GLuint index, const GLshort *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_SHORT attributes */ @@ -308,7 +308,7 @@ static void GLAPIENTRY VertexAttrib1NusvNV(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib1usvNV(GLuint index, const GLushort *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v) @@ -319,7 +319,7 @@ static void GLAPIENTRY VertexAttrib2NusvNV(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib2usvNV(GLuint index, const GLushort *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v) @@ -331,7 +331,7 @@ static void GLAPIENTRY VertexAttrib3NusvNV(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib3usvNV(GLuint index, const GLushort *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v) @@ -344,7 +344,7 @@ static void GLAPIENTRY VertexAttrib4NusvNV(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib4usvNV(GLuint index, const GLushort *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_INT attributes */ @@ -356,7 +356,7 @@ static void GLAPIENTRY VertexAttrib1NivNV(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib1ivNV(GLuint index, const GLint *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v) @@ -367,7 +367,7 @@ static void GLAPIENTRY VertexAttrib2NivNV(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib2ivNV(GLuint index, const GLint *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v) @@ -379,7 +379,7 @@ static void GLAPIENTRY VertexAttrib3NivNV(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib3ivNV(GLuint index, const GLint *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v) @@ -392,7 +392,7 @@ static void GLAPIENTRY VertexAttrib4NivNV(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib4ivNV(GLuint index, const GLint *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_INT attributes */ @@ -404,7 +404,7 @@ static void GLAPIENTRY VertexAttrib1NuivNV(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib1uivNV(GLuint index, const GLuint *v) { - CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fNV(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v) @@ -415,7 +415,7 @@ static void GLAPIENTRY VertexAttrib2NuivNV(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib2uivNV(GLuint index, const GLuint *v) { - CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v) @@ -427,7 +427,7 @@ static void GLAPIENTRY VertexAttrib3NuivNV(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib3uivNV(GLuint index, const GLuint *v) { - CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v) @@ -440,7 +440,7 @@ static void GLAPIENTRY VertexAttrib4NuivNV(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib4uivNV(GLuint index, const GLuint *v) { - CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fNV(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_FLOAT attributes */ @@ -602,7 +602,7 @@ static void GLAPIENTRY VertexAttrib1NbvARB(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib1bvARB(GLuint index, const GLbyte *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NbvARB(GLuint index, const GLbyte *v) @@ -612,7 +612,7 @@ static void GLAPIENTRY VertexAttrib2NbvARB(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib2bvARB(GLuint index, const GLbyte *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NbvARB(GLuint index, const GLbyte *v) @@ -624,7 +624,7 @@ static void GLAPIENTRY VertexAttrib3NbvARB(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib3bvARB(GLuint index, const GLbyte *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NbvARB(GLuint index, const GLbyte *v) @@ -637,7 +637,7 @@ static void GLAPIENTRY VertexAttrib4NbvARB(GLuint index, const GLbyte *v) static void GLAPIENTRY VertexAttrib4bvARB(GLuint index, const GLbyte *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_BYTE attributes */ @@ -649,7 +649,7 @@ static void GLAPIENTRY VertexAttrib1NubvARB(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib1ubvARB(GLuint index, const GLubyte *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NubvARB(GLuint index, const GLubyte *v) @@ -660,7 +660,7 @@ static void GLAPIENTRY VertexAttrib2NubvARB(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib2ubvARB(GLuint index, const GLubyte *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NubvARB(GLuint index, const GLubyte *v) @@ -671,7 +671,7 @@ static void GLAPIENTRY VertexAttrib3NubvARB(GLuint index, const GLubyte *v) } static void GLAPIENTRY VertexAttrib3ubvARB(GLuint index, const GLubyte *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NubvARB(GLuint index, const GLubyte *v) @@ -684,7 +684,7 @@ static void GLAPIENTRY VertexAttrib4NubvARB(GLuint index, const GLubyte *v) static void GLAPIENTRY VertexAttrib4ubvARB(GLuint index, const GLubyte *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_SHORT attributes */ @@ -696,7 +696,7 @@ static void GLAPIENTRY VertexAttrib1NsvARB(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib1svARB(GLuint index, const GLshort *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NsvARB(GLuint index, const GLshort *v) @@ -707,7 +707,7 @@ static void GLAPIENTRY VertexAttrib2NsvARB(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib2svARB(GLuint index, const GLshort *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NsvARB(GLuint index, const GLshort *v) @@ -719,7 +719,7 @@ static void GLAPIENTRY VertexAttrib3NsvARB(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib3svARB(GLuint index, const GLshort *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NsvARB(GLuint index, const GLshort *v) @@ -732,7 +732,7 @@ static void GLAPIENTRY VertexAttrib4NsvARB(GLuint index, const GLshort *v) static void GLAPIENTRY VertexAttrib4svARB(GLuint index, const GLshort *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_SHORT attributes */ @@ -744,7 +744,7 @@ static void GLAPIENTRY VertexAttrib1NusvARB(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib1usvARB(GLuint index, const GLushort *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NusvARB(GLuint index, const GLushort *v) @@ -755,7 +755,7 @@ static void GLAPIENTRY VertexAttrib2NusvARB(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib2usvARB(GLuint index, const GLushort *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NusvARB(GLuint index, const GLushort *v) @@ -767,7 +767,7 @@ static void GLAPIENTRY VertexAttrib3NusvARB(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib3usvARB(GLuint index, const GLushort *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NusvARB(GLuint index, const GLushort *v) @@ -780,7 +780,7 @@ static void GLAPIENTRY VertexAttrib4NusvARB(GLuint index, const GLushort *v) static void GLAPIENTRY VertexAttrib4usvARB(GLuint index, const GLushort *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_INT attributes */ @@ -792,7 +792,7 @@ static void GLAPIENTRY VertexAttrib1NivARB(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib1ivARB(GLuint index, const GLint *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NivARB(GLuint index, const GLint *v) @@ -803,7 +803,7 @@ static void GLAPIENTRY VertexAttrib2NivARB(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib2ivARB(GLuint index, const GLint *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NivARB(GLuint index, const GLint *v) @@ -815,7 +815,7 @@ static void GLAPIENTRY VertexAttrib3NivARB(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib3ivARB(GLuint index, const GLint *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NivARB(GLuint index, const GLint *v) @@ -828,7 +828,7 @@ static void GLAPIENTRY VertexAttrib4NivARB(GLuint index, const GLint *v) static void GLAPIENTRY VertexAttrib4ivARB(GLuint index, const GLint *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_UNSIGNED_INT attributes */ @@ -840,7 +840,7 @@ static void GLAPIENTRY VertexAttrib1NuivARB(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib1uivARB(GLuint index, const GLuint *v) { - CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, v[0])); + CALL_VertexAttrib1fARB(GET_DISPATCH(), (index, (GLfloat)v[0])); } static void GLAPIENTRY VertexAttrib2NuivARB(GLuint index, const GLuint *v) @@ -851,7 +851,7 @@ static void GLAPIENTRY VertexAttrib2NuivARB(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib2uivARB(GLuint index, const GLuint *v) { - CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, v[0], v[1])); + CALL_VertexAttrib2fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1])); } static void GLAPIENTRY VertexAttrib3NuivARB(GLuint index, const GLuint *v) @@ -863,7 +863,7 @@ static void GLAPIENTRY VertexAttrib3NuivARB(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib3uivARB(GLuint index, const GLuint *v) { - CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, v[0], v[1], v[2])); + CALL_VertexAttrib3fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2])); } static void GLAPIENTRY VertexAttrib4NuivARB(GLuint index, const GLuint *v) @@ -876,7 +876,7 @@ static void GLAPIENTRY VertexAttrib4NuivARB(GLuint index, const GLuint *v) static void GLAPIENTRY VertexAttrib4uivARB(GLuint index, const GLuint *v) { - CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, v[0], v[1], v[2], v[3])); + CALL_VertexAttrib4fARB(GET_DISPATCH(), (index, (GLfloat)v[0], (GLfloat)v[1], (GLfloat)v[2], (GLfloat)v[3])); } /* GL_FLOAT attributes */ diff --git a/src/mesa/main/api_validate.c b/src/mesa/main/api_validate.c index 64ab324af2..9144b4bc66 100644 --- a/src/mesa/main/api_validate.c +++ b/src/mesa/main/api_validate.c @@ -87,7 +87,7 @@ _mesa_validate_DrawElements(GLcontext *ctx, indexBytes = count * sizeof(GLushort); } - if (indexBytes > ctx->Array.ElementArrayBufferObj->Size) { + if (indexBytes > (GLuint) ctx->Array.ElementArrayBufferObj->Size) { _mesa_warning(ctx, "glDrawElements index out of buffer bounds"); return GL_FALSE; } diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 2158eb6873..0053180000 100755 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1532,7 +1532,7 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer, * if the DRIdrawable changes, and everything relies on them. * This is a bit messy (same as needed in _mesa_BindFramebufferEXT) */ - int i; + unsigned int i; GLenum buffers[MAX_DRAW_BUFFERS]; _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer); diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index 13ebd4dd0d..f933580b2d 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -5069,7 +5069,7 @@ save_Indexfv(const GLfloat * v) static void GLAPIENTRY save_EdgeFlag(GLboolean x) { - save_Attr1fNV(VERT_ATTRIB_EDGEFLAG, x ? 1.0 : 0.0); + save_Attr1fNV(VERT_ATTRIB_EDGEFLAG, x ? (GLfloat)1.0 : (GLfloat)0.0); } static void GLAPIENTRY diff --git a/src/mesa/main/drawpix.c b/src/mesa/main/drawpix.c index fa422bb3c7..016ddd0a81 100644 --- a/src/mesa/main/drawpix.c +++ b/src/mesa/main/drawpix.c @@ -377,7 +377,7 @@ _mesa_Bitmap( GLsizei width, GLsizei height, if (ctx->RenderMode == GL_RENDER) { /* Truncate, to satisfy conformance tests (matches SGI's OpenGL). */ - const GLfloat epsilon = 0.0001; + const GLfloat epsilon = (const GLfloat)0.0001; GLint x = IFLOOR(ctx->Current.RasterPos[0] + epsilon - xorig); GLint y = IFLOOR(ctx->Current.RasterPos[1] + epsilon - yorig); diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index c9b30d3252..894d99afd2 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -67,7 +67,7 @@ compute_depth_max(struct gl_framebuffer *fb) fb->_DepthMaxF = (GLfloat) fb->_DepthMax; /* Minimum resolvable depth value, for polygon offset */ - fb->_MRD = 1.0 / fb->_DepthMaxF; + fb->_MRD = (GLfloat)1.0 / fb->_DepthMaxF; } diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index eb81ee4a52..ee48b78318 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -2124,7 +2124,7 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params ) params[0] = (GLfloat)(ctx->DrawBuffer->Visual.depthBits); break; case GL_DEPTH_CLEAR_VALUE: - params[0] = ctx->Depth.Clear; + params[0] = (GLfloat)ctx->Depth.Clear; break; case GL_DEPTH_FUNC: params[0] = ENUM_TO_FLOAT(ctx->Depth.Func); @@ -2914,7 +2914,7 @@ _mesa_GetFloatv( GLenum pname, GLfloat *params ) GLuint i, n = _mesa_get_compressed_formats(ctx, formats, GL_FALSE); ASSERT(n <= 100); for (i = 0; i < n; i++) - params[i] = ENUM_TO_INT(formats[i]); + params[i] = (GLfloat)(ENUM_TO_INT(formats[i])); } break; case GL_ARRAY_ELEMENT_LOCK_FIRST_EXT: diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index 76e105e65e..285c8346a5 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -1169,7 +1169,7 @@ _mesa_apply_stencil_transfer_ops(const GLcontext *ctx, GLuint n, GLuint mask = ctx->PixelMaps.StoS.Size - 1; GLuint i; for (i = 0; i < n; i++) { - stencil[i] = ctx->PixelMaps.StoS.Map[ stencil[i] & mask ]; + stencil[i] = (GLstencil)ctx->PixelMaps.StoS.Map[ stencil[i] & mask ]; } } } @@ -3680,7 +3680,7 @@ _mesa_unpack_stencil_span( const GLcontext *ctx, GLuint n, const GLuint mask = ctx->PixelMaps.StoS.Size - 1; GLuint i; for (i = 0; i < n; i++) { - indexes[i] = ctx->PixelMaps.StoS.Map[ indexes[i] & mask ]; + indexes[i] = (GLuint)ctx->PixelMaps.StoS.Map[ indexes[i] & mask ]; } } @@ -4035,7 +4035,7 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, if (needClamp) { GLuint i; for (i = 0; i < n; i++) { - depthValues[i] = CLAMP(depthValues[i], 0.0, 1.0); + depthValues[i] = (GLfloat)CLAMP(depthValues[i], 0.0, 1.0); } } diff --git a/src/mesa/main/light.c b/src/mesa/main/light.c index f9715b4865..f37d1f216f 100644 --- a/src/mesa/main/light.c +++ b/src/mesa/main/light.c @@ -1119,7 +1119,7 @@ compute_light_positions( GLcontext *ctx ) } else { /* positional light w/ homogeneous coordinate, divide by W */ - GLfloat wInv = 1.0 / light->_Position[3]; + GLfloat wInv = (GLfloat)1.0 / light->_Position[3]; light->_Position[0] *= wInv; light->_Position[1] *= wInv; light->_Position[2] *= wInv; diff --git a/src/mesa/main/mipmap.c b/src/mesa/main/mipmap.c index d3d1958951..061378f3b7 100644 --- a/src/mesa/main/mipmap.c +++ b/src/mesa/main/mipmap.c @@ -292,7 +292,7 @@ do_row(GLenum datatype, GLuint comps, GLint srcWidth, GLfloat *dst = (GLfloat *) dstRow; for (i = j = 0, k = k0; i < (GLuint) dstWidth; i++, j += colStride, k += colStride) { - dst[i] = rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4; + dst[i] = (GLfloat)(rowA[j] / 4 + rowA[k] / 4 + rowB[j] / 4 + rowB[k] / 4); } } diff --git a/src/mesa/main/pixel.c b/src/mesa/main/pixel.c index 0e9915dd38..7eeae05dbd 100644 --- a/src/mesa/main/pixel.c +++ b/src/mesa/main/pixel.c @@ -304,7 +304,7 @@ store_pixelmap(GLcontext *ctx, GLenum map, GLsizei mapsize, /* special case */ ctx->PixelMaps.StoS.Size = mapsize; for (i = 0; i < mapsize; i++) { - ctx->PixelMaps.StoS.Map[i] = IROUND(values[i]); + ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]); } break; case GL_PIXEL_MAP_I_TO_I: @@ -1142,7 +1142,7 @@ _mesa_lookup_rgba_ubyte(const struct gl_color_table *table, GLuint n, GLubyte rgba[][4]) { const GLubyte *lut = table->TableUB; - const GLfloat scale = (GLfloat) (table->Size - 1) / 255.0; + const GLfloat scale = (GLfloat) (table->Size - 1) / (GLfloat)255.0; GLuint i; if (!table->TableUB || table->Size == 0) diff --git a/src/mesa/main/queryobj.c b/src/mesa/main/queryobj.c index e30f5480da..a1e32e70ba 100644 --- a/src/mesa/main/queryobj.c +++ b/src/mesa/main/queryobj.c @@ -382,7 +382,7 @@ _mesa_GetQueryObjectivARB(GLuint id, GLenum pname, GLint *params) *params = 0x7fffffff; } else { - *params = q->Result; + *params = (GLint)q->Result; } break; case GL_QUERY_RESULT_AVAILABLE_ARB: @@ -422,7 +422,7 @@ _mesa_GetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params) *params = 0xffffffff; } else { - *params = q->Result; + *params = (GLuint)q->Result; } break; case GL_QUERY_RESULT_AVAILABLE_ARB: diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c index ee163e0c71..f0500083ec 100644 --- a/src/mesa/main/rastpos.c +++ b/src/mesa/main/rastpos.c @@ -63,7 +63,7 @@ rasterpos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) void GLAPIENTRY _mesa_RasterPos2d(GLdouble x, GLdouble y) { - rasterpos(x, y, 0.0F, 1.0F); + rasterpos((GLfloat)x, (GLfloat)y, (GLfloat)0.0, (GLfloat)1.0); } void GLAPIENTRY diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 644b1f39c7..6877ef96f2 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -904,14 +904,14 @@ emit_texenv(struct texenv_fragment_program *p, GLuint unit) */ if (alpha_shift || rgb_shift) { if (rgb_shift == alpha_shift) { - shift = register_scalar_const(p, 1<File == PROGRAM_CONSTANT || source->File == PROGRAM_STATE_VAR); params = machine->CurProgram->Parameters; - if (reg < 0 || reg >= params->NumParameters) + if (reg < 0 || reg >= (GLint)params->NumParameters) return ZeroVec; else return params->ParameterValues[reg]; @@ -227,7 +227,7 @@ fetch_vector4_deriv(GLcontext * ctx, const struct gl_program_machine *machine, char xOrY, GLfloat result[4]) { - if (source->File == PROGRAM_INPUT && source->Index < machine->NumDeriv) { + if (source->File == PROGRAM_INPUT && source->Index < (GLint)machine->NumDeriv) { const GLint col = machine->CurElement; const GLfloat w = machine->Attribs[FRAG_ATTRIB_WPOS][col][3]; const GLfloat invQ = 1.0f / w; @@ -506,7 +506,7 @@ _mesa_execute_program(GLcontext * ctx, { const GLuint numInst = program->NumInstructions; const GLuint maxExec = 10000; - GLint pc, numExec = 0; + GLuint pc, numExec = 0; machine->CurProgram = program; diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c index 44fbfdcd04..8f48155825 100644 --- a/src/mesa/shader/prog_statevars.c +++ b/src/mesa/shader/prog_statevars.c @@ -250,7 +250,7 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], value[1] = ctx->Fog.Start; value[2] = ctx->Fog.End; value[3] = (ctx->Fog.End == ctx->Fog.Start) - ? 1.0 : 1.0F / (ctx->Fog.End - ctx->Fog.Start); + ? 1.0 : (GLfloat)(1.0 / (ctx->Fog.End - ctx->Fog.Start)); return; case STATE_CLIPPLANE: { @@ -411,7 +411,7 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], if (texObj) { struct gl_texture_image *texImage = texObj->Image[0][0]; ASSIGN_4V(value, 1.0 / texImage->Width, - 1.0 / texImage->Height, + (GLfloat)(1.0 / texImage->Height), 0.0, 1.0); } } @@ -426,10 +426,10 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[], * exp2: 2^-((density/(ln(2)^2) * fogcoord)^2) */ value[0] = (ctx->Fog.End == ctx->Fog.Start) - ? 1.0 : -1.0F / (ctx->Fog.End - ctx->Fog.Start); + ? 1.0 : (GLfloat)(-1.0F / (ctx->Fog.End - ctx->Fog.Start)); value[1] = ctx->Fog.End * -value[0]; - value[2] = ctx->Fog.Density * ONE_DIV_LN2; - value[3] = ctx->Fog.Density * ONE_DIV_SQRT_LN2; + value[2] = (GLfloat)(ctx->Fog.Density * ONE_DIV_LN2); + value[3] = (GLfloat)(ctx->Fog.Density * ONE_DIV_SQRT_LN2); return; case STATE_LIGHT_SPOT_DIR_NORMALIZED: { diff --git a/src/mesa/shader/prog_uniform.c b/src/mesa/shader/prog_uniform.c index 20e004b350..d96a916533 100644 --- a/src/mesa/shader/prog_uniform.c +++ b/src/mesa/shader/prog_uniform.c @@ -135,7 +135,7 @@ _mesa_longest_uniform_name(const struct gl_uniform_list *list) GLuint i; for (i = 0; i < list->NumUniforms; i++) { GLuint len = _mesa_strlen(list->Uniforms[i].Name); - if (len > max) + if (len > (GLuint)max) max = len; } return max; diff --git a/src/mesa/shader/shader_api.c b/src/mesa/shader/shader_api.c index 24ab7568d6..856179e1d5 100644 --- a/src/mesa/shader/shader_api.c +++ b/src/mesa/shader/shader_api.c @@ -719,7 +719,7 @@ _mesa_get_attached_shaders(GLcontext *ctx, GLuint program, GLsizei maxCount, struct gl_shader_program *shProg = _mesa_lookup_shader_program(ctx, program); if (shProg) { - GLint i; + GLuint i; for (i = 0; i < maxCount && i < shProg->NumShaders; i++) { obj[i] = shProg->Shaders[i]->Name; } @@ -893,7 +893,7 @@ _mesa_get_uniformfv(GLcontext *ctx, GLuint program, GLint location, = _mesa_lookup_shader_program(ctx, program); if (shProg) { if (location < shProg->Uniforms->NumUniforms) { - GLint progPos, i; + GLuint progPos, i; const struct gl_program *prog = NULL; progPos = shProg->Uniforms->Uniforms[location].VertPos; @@ -1111,7 +1111,7 @@ set_program_uniform(GLcontext *ctx, struct gl_program *program, GLint location, } else { /* ordinary uniform variable */ - GLint k, i; + GLuint k, i; if (count * elems > program->Parameters->Parameters[location].Size) { _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(count too large)"); diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index e500ac8684..e4de875e8c 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -77,7 +77,7 @@ is_identity(const GLfloat m[16]) GLuint i; for (i = 0; i < 16; i++) { const int row = i % 4, col = i / 4; - const float val = (row == col); + const float val = (GLfloat)(row == col); if (m[i] != val) return GL_FALSE; } diff --git a/src/mesa/state_tracker/st_atom_scissor.c b/src/mesa/state_tracker/st_atom_scissor.c index f5db492403..3fd59e1945 100644 --- a/src/mesa/state_tracker/st_atom_scissor.c +++ b/src/mesa/state_tracker/st_atom_scissor.c @@ -52,14 +52,14 @@ update_scissor( struct st_context *st ) scissor.maxy = fb->Height; if (st->ctx->Scissor.Enabled) { - if (st->ctx->Scissor.X > scissor.minx) + if ((GLuint)st->ctx->Scissor.X > scissor.minx) scissor.minx = st->ctx->Scissor.X; - if (st->ctx->Scissor.Y > scissor.miny) + if ((GLuint)st->ctx->Scissor.Y > scissor.miny) scissor.miny = st->ctx->Scissor.Y; - if (st->ctx->Scissor.X + st->ctx->Scissor.Width < scissor.maxx) + if ((GLuint)st->ctx->Scissor.X + st->ctx->Scissor.Width < scissor.maxx) scissor.maxx = st->ctx->Scissor.X + st->ctx->Scissor.Width; - if (st->ctx->Scissor.Y + st->ctx->Scissor.Height < scissor.maxy) + if ((GLuint)st->ctx->Scissor.Y + st->ctx->Scissor.Height < scissor.maxy) scissor.maxy = st->ctx->Scissor.Y + st->ctx->Scissor.Height; /* check for null space */ diff --git a/src/mesa/state_tracker/st_atom_viewport.c b/src/mesa/state_tracker/st_atom_viewport.c index 4b51521470..b105909e96 100644 --- a/src/mesa/state_tracker/st_atom_viewport.c +++ b/src/mesa/state_tracker/st_atom_viewport.c @@ -49,7 +49,7 @@ update_viewport( struct st_context *st ) */ if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP) { yScale = -1; - yBias = ctx->DrawBuffer->Height ; + yBias = (GLfloat)ctx->DrawBuffer->Height; } else { yScale = 1.0; @@ -59,12 +59,12 @@ update_viewport( struct st_context *st ) /* _NEW_VIEWPORT */ { - GLfloat x = ctx->Viewport.X; - GLfloat y = ctx->Viewport.Y; + GLfloat x = (GLfloat)ctx->Viewport.X; + GLfloat y = (GLfloat)ctx->Viewport.Y; GLfloat z = ctx->Viewport.Near; - GLfloat half_width = ctx->Viewport.Width / 2.0; - GLfloat half_height = ctx->Viewport.Height / 2.0; - GLfloat half_depth = (ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; + GLfloat half_width = (GLfloat)ctx->Viewport.Width / 2.0; + GLfloat half_height = (GLfloat)ctx->Viewport.Height / 2.0; + GLfloat half_depth = (GLfloat)(ctx->Viewport.Far - ctx->Viewport.Near) / 2.0; st->state.viewport.scale[0] = half_width; st->state.viewport.scale[1] = half_height * yScale; diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 593938f8cf..9763eebe54 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -360,18 +360,18 @@ setup_bitmap_vertex_data(struct st_context *st, { struct pipe_context *pipe = st->pipe; const struct gl_framebuffer *fb = st->ctx->DrawBuffer; - const GLfloat fb_width = fb->Width; - const GLfloat fb_height = fb->Height; - const GLfloat x0 = x; - const GLfloat x1 = x + width; - const GLfloat y0 = y; - const GLfloat y1 = y + height; - const GLfloat sLeft = 0.0F, sRight = 1.0F; - const GLfloat tTop = 0.0, tBot = 1.0 - tTop; - const GLfloat clip_x0 = x0 / fb_width * 2.0 - 1.0; - const GLfloat clip_y0 = y0 / fb_height * 2.0 - 1.0; - const GLfloat clip_x1 = x1 / fb_width * 2.0 - 1.0; - const GLfloat clip_y1 = y1 / fb_height * 2.0 - 1.0; + const GLfloat fb_width = (GLfloat)fb->Width; + const GLfloat fb_height = (GLfloat)fb->Height; + const GLfloat x0 = (GLfloat)x; + const GLfloat x1 = (GLfloat)(x + width); + const GLfloat y0 = (GLfloat)y; + const GLfloat y1 = (GLfloat)(y + height); + const GLfloat sLeft = (GLfloat)0.0, sRight = (GLfloat)1.0; + const GLfloat tTop = (GLfloat)0.0, tBot = (GLfloat)1.0 - tTop; + const GLfloat clip_x0 = (GLfloat)(x0 / fb_width * 2.0 - 1.0); + const GLfloat clip_y0 = (GLfloat)(y0 / fb_height * 2.0 - 1.0); + const GLfloat clip_x1 = (GLfloat)(x1 / fb_width * 2.0 - 1.0); + const GLfloat clip_y1 = (GLfloat)(y1 / fb_height * 2.0 - 1.0); GLuint i; void *buf; @@ -444,8 +444,8 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, * it up into chunks. */ maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); - assert(width <= maxSize); - assert(height <= maxSize); + assert(width <= (GLsizei)maxSize); + assert(height <= (GLsizei)maxSize); cso_save_rasterizer(cso); cso_save_samplers(cso); @@ -488,15 +488,15 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, { const struct gl_framebuffer *fb = st->ctx->DrawBuffer; const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); - const float width = fb->Width; - const float height = fb->Height; + const GLfloat width = (GLfloat)fb->Width; + const GLfloat height = (GLfloat)fb->Height; struct pipe_viewport_state vp; vp.scale[0] = 0.5 * width; - vp.scale[1] = height * (invert ? -0.5 : 0.5); + vp.scale[1] = (GLfloat)(height * (invert ? -0.5 : 0.5)); vp.scale[2] = 1.0; vp.scale[3] = 1.0; - vp.translate[0] = 0.5 * width; - vp.translate[1] = 0.5 * height; + vp.translate[0] = (GLfloat)(0.5 * width); + vp.translate[1] = (GLfloat)(0.5 * height); vp.translate[2] = 0.0; vp.translate[3] = 0.0; cso_set_viewport(cso, &vp); diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c index a52521db64..dbee2188ee 100644 --- a/src/mesa/vbo/vbo_exec_array.c +++ b/src/mesa/vbo/vbo_exec_array.c @@ -41,7 +41,7 @@ static void get_minmax_index( GLuint count, GLuint type, GLuint *min_index, GLuint *max_index) { - GLint i; + GLuint i; switch(type) { case GL_UNSIGNED_INT: { diff --git a/src/mesa/vbo/vbo_split_inplace.c b/src/mesa/vbo/vbo_split_inplace.c index 958afccd0c..fbc856e93b 100644 --- a/src/mesa/vbo/vbo_split_inplace.c +++ b/src/mesa/vbo/vbo_split_inplace.c @@ -58,7 +58,7 @@ struct split_context { static void flush_vertex( struct split_context *split ) { - GLint min_index, max_index; + GLuint min_index, max_index; if (!split->dstprim_nr) return; -- cgit v1.2.3 From 8aafc03b260ab8923f1b373f7effa75bcdb40a72 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Sat, 19 Jul 2008 12:04:37 +0900 Subject: gallium: Finer grained is_format_supported. --- src/gallium/auxiliary/util/u_blit.c | 12 ++- src/gallium/auxiliary/util/u_gen_mipmap.c | 3 +- src/gallium/drivers/cell/ppu/cell_screen.c | 24 ++--- src/gallium/drivers/i915simple/i915_screen.c | 18 ++-- src/gallium/drivers/i965simple/brw_screen.c | 5 +- src/gallium/drivers/softpipe/sp_screen.c | 26 +++--- src/gallium/include/pipe/p_defines.h | 7 +- src/gallium/include/pipe/p_screen.h | 9 +- src/gallium/state_trackers/python/gallium.i | 15 ++- src/gallium/state_trackers/python/samples/tri.py | 8 +- src/gallium/state_trackers/python/tests/texture.py | 13 ++- src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 +- src/mesa/state_tracker/st_cb_bitmap.c | 3 +- src/mesa/state_tracker/st_cb_drawpixels.c | 9 +- src/mesa/state_tracker/st_cb_texture.c | 8 +- src/mesa/state_tracker/st_extensions.c | 14 ++- src/mesa/state_tracker/st_format.c | 101 +++++++++++---------- src/mesa/state_tracker/st_format.h | 2 +- src/mesa/state_tracker/st_gen_mipmap.c | 3 +- src/mesa/state_tracker/st_texture.c | 3 +- 20 files changed, 158 insertions(+), 127 deletions(-) (limited to 'src/mesa/state_tracker/st_atom_pixeltransfer.c') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 3dc9fdd11e..ae087df4cf 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -307,8 +307,10 @@ util_blit_pixels(struct blit_state *ctx, dstY1 = tmp; } - assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE)); - assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE)); + assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); if(dst->format == src->format && (dstX1 - dstX0) == srcW && (dstY1 - dstY0) == srcH) { /* FIXME: this will most surely fail for overlapping rectangles */ @@ -319,7 +321,8 @@ util_blit_pixels(struct blit_state *ctx, return; } - assert(screen->is_format_supported(screen, dst->format, PIPE_SURFACE)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); /* * XXX for now we're always creating a temporary texture. @@ -449,7 +452,8 @@ util_blit_pixels_tex(struct blit_state *ctx, t0 = srcY0 / (float)tex->height[0]; t1 = srcY1 / (float)tex->height[0]; - assert(screen->is_format_supported(screen, dst->format, PIPE_SURFACE)); + assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)); /* save state (restored below) */ cso_save_blend(ctx->cso); diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 5313a8008a..4999822068 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -858,7 +858,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, uint zslice = 0; /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, PIPE_SURFACE)) { + if (!screen->is_format_supported(screen, pt->format, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel); return; } diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index 5198b51441..cf9b68b695 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -115,23 +115,17 @@ cell_get_paramf(struct pipe_screen *screen, int param) static boolean cell_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { - switch (type) { - case PIPE_TEXTURE: - /* cell supports most texture formats, XXX for now anyway */ - if (format == PIPE_FORMAT_DXT5_RGBA || - format == PIPE_FORMAT_R8G8B8A8_SRGB) - return FALSE; - else - return TRUE; - case PIPE_SURFACE: - /* cell supports all (off-screen) surface formats, XXX for now */ - return TRUE; - default: - assert(0); + /* cell supports most formats, XXX for now anyway */ + if (format == PIPE_FORMAT_DXT5_RGBA || + format == PIPE_FORMAT_R8G8B8A8_SRGB) return FALSE; - } + else + return TRUE; } diff --git a/src/gallium/drivers/i915simple/i915_screen.c b/src/gallium/drivers/i915simple/i915_screen.c index ba8f183bdf..4b1b8af7da 100644 --- a/src/gallium/drivers/i915simple/i915_screen.c +++ b/src/gallium/drivers/i915simple/i915_screen.c @@ -148,7 +148,10 @@ i915_get_paramf(struct pipe_screen *screen, int param) static boolean i915_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { static const enum pipe_format tex_supported[] = { PIPE_FORMAT_R8G8B8A8_UNORM, @@ -173,17 +176,10 @@ i915_is_format_supported( struct pipe_screen *screen, const enum pipe_format *list; uint i; - switch (type) { - case PIPE_TEXTURE: - list = tex_supported; - break; - case PIPE_SURFACE: + if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) list = surface_supported; - break; - default: - assert(0); - return FALSE; - } + else + list = tex_supported; for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) { if (list[i] == format) diff --git a/src/gallium/drivers/i965simple/brw_screen.c b/src/gallium/drivers/i965simple/brw_screen.c index b700f7e4f5..6d8f24d1c4 100644 --- a/src/gallium/drivers/i965simple/brw_screen.c +++ b/src/gallium/drivers/i965simple/brw_screen.c @@ -136,7 +136,10 @@ brw_get_paramf(struct pipe_screen *screen, int param) static boolean brw_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { #if 0 /* XXX: This is broken -- rewrite if still needed. */ diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index f6193bfaf9..3f9d4b0ed3 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -115,23 +115,19 @@ softpipe_get_paramf(struct pipe_screen *screen, int param) */ static boolean softpipe_is_format_supported( struct pipe_screen *screen, - enum pipe_format format, uint type ) + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { - switch (type) { - case PIPE_TEXTURE: - case PIPE_SURFACE: - switch(format) { - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - return FALSE; - default: - return TRUE; - } - default: - assert(0); + switch(format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT5_RGBA: return FALSE; + default: + return TRUE; } } diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index bc4d7c845a..b1d100ef53 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -172,11 +172,8 @@ enum pipe_texture_target { #define PIPE_TEXTURE_USAGE_DEPTH_STENCIL 0x8 #define PIPE_TEXTURE_USAGE_SAMPLER 0x10 -/** - * Surfaces, textures, etc. (others may be added) - */ -#define PIPE_TEXTURE 1 -#define PIPE_SURFACE 2 /**< user-created surfaces */ +#define PIPE_TEXTURE_GEOM_NON_SQUARE 0x1 +#define PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO 0x2 /** diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index cc8430dae1..b15affef7a 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -77,11 +77,14 @@ struct pipe_screen { /** * Check if the given pipe_format is supported as a texture or * drawing surface. - * \param type one of PIPE_TEXTURE, PIPE_SURFACE + * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_* + * \param flags bitmask of PIPE_TEXTURE_GEOM_* */ boolean (*is_format_supported)( struct pipe_screen *, - enum pipe_format format, - uint type ); + enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ); /** * Create a new texture object, using the given template info. diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index c08ac87aca..8d8b762ea5 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -158,8 +158,15 @@ struct st_context { * drawing surface. * \param type one of PIPE_TEXTURE, PIPE_SURFACE */ - int is_format_supported( enum pipe_format format, unsigned type ) { - return $self->screen->is_format_supported( $self->screen, format, type); + int is_format_supported( enum pipe_format format, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags ) { + return $self->screen->is_format_supported( $self->screen, + format, + target, + tex_usage, + geom_flags ); } struct st_context * @@ -175,7 +182,7 @@ struct st_context { unsigned depth = 1, unsigned last_level = 0, enum pipe_texture_target target = PIPE_TEXTURE_2D, - unsigned usage = 0 + unsigned tex_usage = 0 ) { struct pipe_texture templat; memset(&templat, 0, sizeof(templat)); @@ -186,7 +193,7 @@ struct st_context { templat.depth[0] = depth; templat.last_level = last_level; templat.target = target; - templat.tex_usage = usage; + templat.tex_usage = tex_usage; return $self->screen->texture_create($self->screen, &templat); } diff --git a/src/gallium/state_trackers/python/samples/tri.py b/src/gallium/state_trackers/python/samples/tri.py index 3665922929..1271c67627 100644 --- a/src/gallium/state_trackers/python/samples/tri.py +++ b/src/gallium/state_trackers/python/samples/tri.py @@ -140,9 +140,11 @@ def test(dev): ctx.set_clip(clip) # framebuffer - cbuf = dev.texture_create(PIPE_FORMAT_X8R8G8B8_UNORM, - width, height, - usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET) + cbuf = dev.texture_create( + PIPE_FORMAT_X8R8G8B8_UNORM, + width, height, + tex_usage=PIPE_TEXTURE_USAGE_DISPLAY_TARGET, + ) _cbuf = cbuf.get_surface(usage = PIPE_BUFFER_USAGE_GPU_READ|PIPE_BUFFER_USAGE_GPU_WRITE) fb = Framebuffer() fb.width = width diff --git a/src/gallium/state_trackers/python/tests/texture.py b/src/gallium/state_trackers/python/tests/texture.py index 16ad78c8aa..b2ca9f416f 100644 --- a/src/gallium/state_trackers/python/tests/texture.py +++ b/src/gallium/state_trackers/python/tests/texture.py @@ -136,7 +136,7 @@ class TextureTest(TestCase): level = self.level zslice = self.zslice - if not dev.is_format_supported(format, PIPE_TEXTURE): + if not dev.is_format_supported(format, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER, 0): raise TestSkip ctx = self.dev.context_create() @@ -199,6 +199,7 @@ class TextureTest(TestCase): height = height, depth = depth, last_level = last_level, + tex_usage = PIPE_TEXTURE_USAGE_SAMPLER, ) expected_rgba = FloatArray(height*width*4) @@ -212,10 +213,12 @@ class TextureTest(TestCase): ctx.set_sampler_texture(0, texture) # framebuffer - cbuf_tex = dev.texture_create(PIPE_FORMAT_A8R8G8B8_UNORM, - width, - height, - usage = PIPE_TEXTURE_USAGE_RENDER_TARGET) + cbuf_tex = dev.texture_create( + PIPE_FORMAT_A8R8G8B8_UNORM, + width, + height, + tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET, + ) cbuf = cbuf_tex.get_surface(usage = PIPE_BUFFER_USAGE_GPU_WRITE|PIPE_BUFFER_USAGE_GPU_READ) fb = Framebuffer() diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index e4de875e8c..a357b71677 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -122,7 +122,7 @@ create_color_map_texture(GLcontext *ctx) const uint texSize = 256; /* simple, and usually perfect */ /* find an RGBA texture format */ - format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + format = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_SAMPLER); /* create texture for color map/table */ pt = st_texture_create(ctx->st, PIPE_TEXTURE_2D, format, 0, diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index de86832342..d5696a909f 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -746,7 +746,8 @@ st_init_bitmap(struct st_context *st) st->bitmap.rasterizer.bypass_vs = 1; /* find a usable texture format */ - if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; } else { diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 2ebfcaf82b..db0c9fbd09 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -995,18 +995,21 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, srcFormat = rbRead->texture->format; - if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, srcFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { texFormat = srcFormat; } else { /* srcFormat can't be used as a texture format */ if (type == GL_DEPTH) { - texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE); + texFormat = st_choose_format(pipe, GL_DEPTH_COMPONENT, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_DEPTH_STENCIL); assert(texFormat != PIPE_FORMAT_NONE); /* XXX no depth texture formats??? */ } else { /* default color format */ - texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE); + texFormat = st_choose_format(pipe, GL_RGBA, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER); assert(texFormat != PIPE_FORMAT_NONE); } } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index de782e8232..1f94a0b9ef 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -1210,9 +1210,13 @@ do_copy_texsubimage(GLcontext *ctx, use_fallback = GL_FALSE; } else if (screen->is_format_supported(screen, strb->surface->format, - PIPE_TEXTURE) && + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, + 0) && screen->is_format_supported(screen, dest_surface->format, - PIPE_SURFACE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET, + 0)) { boolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP); int srcY0, srcY1; if (do_flip) { diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index d804d2b453..cacf972a1b 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -213,18 +213,24 @@ void st_init_extensions(struct st_context *st) } if (screen->is_format_supported(screen, PIPE_FORMAT_R8G8B8A8_SRGB, - PIPE_TEXTURE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.EXT_texture_sRGB = GL_TRUE; } #if 01 if (screen->is_format_supported(screen, PIPE_FORMAT_DXT5_RGBA, - PIPE_TEXTURE)) { + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE; } #endif - if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, PIPE_TEXTURE) || - screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, PIPE_TEXTURE)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0) || + screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, + PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER, 0)) { ctx->Extensions.MESA_ycbcr_texture = GL_TRUE; } diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 50a06868df..b6d97ef659 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -281,7 +281,10 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) * Find an RGBA format supported by the context/winsys. */ static enum pipe_format -default_rgba_format(struct pipe_screen *screen, uint type) +default_rgba_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { static const enum pipe_format colorFormats[] = { PIPE_FORMAT_A8R8G8B8_UNORM, @@ -291,7 +294,7 @@ default_rgba_format(struct pipe_screen *screen, uint type) }; uint i; for (i = 0; i < Elements(colorFormats); i++) { - if (screen->is_format_supported( screen, colorFormats[i], type )) { + if (screen->is_format_supported( screen, colorFormats[i], target, tex_usage, geom_flags )) { return colorFormats[i]; } } @@ -303,13 +306,16 @@ default_rgba_format(struct pipe_screen *screen, uint type) * Search list of formats for first RGBA format with >8 bits/channel. */ static enum pipe_format -default_deep_rgba_format(struct pipe_screen *screen, uint type) +default_deep_rgba_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { - if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, type)) { + if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, target, tex_usage, geom_flags)) { return PIPE_FORMAT_R16G16B16A16_SNORM; } - if (type == PIPE_TEXTURE) - return default_rgba_format(screen, type); + if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) + return default_rgba_format(screen, target, tex_usage, geom_flags); else return PIPE_FORMAT_NONE; } @@ -319,7 +325,10 @@ default_deep_rgba_format(struct pipe_screen *screen, uint type) * Find an Z format supported by the context/winsys. */ static enum pipe_format -default_depth_format(struct pipe_screen *screen, uint type) +default_depth_format(struct pipe_screen *screen, + enum pipe_texture_target target, + unsigned tex_usage, + unsigned geom_flags) { static const enum pipe_format zFormats[] = { PIPE_FORMAT_Z16_UNORM, @@ -329,7 +338,7 @@ default_depth_format(struct pipe_screen *screen, uint type) }; uint i; for (i = 0; i < Elements(zFormats); i++) { - if (screen->is_format_supported( screen, zFormats[i], type )) { + if (screen->is_format_supported( screen, zFormats[i], target, tex_usage, geom_flags )) { return zFormats[i]; } } @@ -343,12 +352,10 @@ default_depth_format(struct pipe_screen *screen, uint type) */ enum pipe_format st_choose_format(struct pipe_context *pipe, GLint internalFormat, - uint surfType) + enum pipe_texture_target target, unsigned tex_usage) { struct pipe_screen *screen = pipe->screen; - - assert(surfType == PIPE_SURFACE || - surfType == PIPE_TEXTURE); + unsigned geom_flags = 0; switch (internalFormat) { case 4: @@ -360,38 +367,38 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGBA16: - if (surfType == PIPE_SURFACE) - return default_deep_rgba_format( screen, surfType ); + if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) + return default_deep_rgba_format( screen, target, tex_usage, geom_flags ); else - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGBA4: case GL_RGBA2: - if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A4R4G4B4_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB5_A1: - if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A1R5G5B5_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_RGB5: case GL_RGB4: case GL_R3_G3_B2: - if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A1R5G5B5_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_R5G6B5_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_ALPHA: case GL_ALPHA4: @@ -399,9 +406,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_ALPHA12: case GL_ALPHA16: case GL_COMPRESSED_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case 1: case GL_LUMINANCE: @@ -410,9 +417,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12: case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: - if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_L8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_L8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case 2: case GL_LUMINANCE_ALPHA: @@ -423,9 +430,9 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_LUMINANCE12_ALPHA12: case GL_LUMINANCE16_ALPHA16: case GL_COMPRESSED_LUMINANCE_ALPHA: - if (screen->is_format_supported( screen, PIPE_FORMAT_A8L8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_A8L8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_A8L8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_INTENSITY: case GL_INTENSITY4: @@ -433,17 +440,17 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, case GL_INTENSITY12: case GL_INTENSITY16: case GL_COMPRESSED_INTENSITY: - if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_I8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_I8_UNORM; - return default_rgba_format( screen, surfType ); + return default_rgba_format( screen, target, tex_usage, geom_flags ); case GL_YCBCR_MESA: if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR, - PIPE_TEXTURE)) { + target, tex_usage, geom_flags)) { return PIPE_FORMAT_YCBCR; } if (screen->is_format_supported(screen, PIPE_FORMAT_YCBCR_REV, - PIPE_TEXTURE)) { + target, tex_usage, geom_flags)) { return PIPE_FORMAT_YCBCR_REV; } return PIPE_FORMAT_NONE; @@ -472,40 +479,40 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, #endif case GL_DEPTH_COMPONENT16: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z16_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z16_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT24: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT32: - if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z32_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: - return default_depth_format( screen, surfType ); + return default_depth_format( screen, target, tex_usage, geom_flags ); case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: case GL_STENCIL_INDEX4_EXT: case GL_STENCIL_INDEX8_EXT: case GL_STENCIL_INDEX16_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; case GL_DEPTH_STENCIL_EXT: case GL_DEPTH24_STENCIL8_EXT: - if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_S8Z24_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_S8Z24_UNORM; - if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, surfType )) + if (screen->is_format_supported( screen, PIPE_FORMAT_Z24S8_UNORM, target, tex_usage, geom_flags )) return PIPE_FORMAT_Z24S8_UNORM; return PIPE_FORMAT_NONE; @@ -521,7 +528,8 @@ st_choose_format(struct pipe_context *pipe, GLint internalFormat, enum pipe_format st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) { - return st_choose_format(pipe, internalFormat, PIPE_SURFACE); + return st_choose_format(pipe, internalFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_RENDER_TARGET); } @@ -587,7 +595,8 @@ st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat, (void) format; (void) type; - pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE); + pFormat = st_choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE_2D, + PIPE_TEXTURE_USAGE_SAMPLER); if (pFormat == PIPE_FORMAT_NONE) return NULL; diff --git a/src/mesa/state_tracker/st_format.h b/src/mesa/state_tracker/st_format.h index ff0fd042db..3f5ac3201b 100644 --- a/src/mesa/state_tracker/st_format.h +++ b/src/mesa/state_tracker/st_format.h @@ -65,7 +65,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat); extern enum pipe_format st_choose_format(struct pipe_context *pipe, GLint internalFormat, - uint surfType); + enum pipe_texture_target target, unsigned tex_usage); extern enum pipe_format st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat); diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 2fc00df429..6db9bc0dd5 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -86,7 +86,8 @@ st_render_mipmap(struct st_context *st, assert(target != GL_TEXTURE_3D); /* not done yet */ /* check if we can render in the texture's format */ - if (!screen->is_format_supported(screen, pt->format, PIPE_SURFACE)) { + if (!screen->is_format_supported(screen, pt->format, target, + PIPE_TEXTURE_USAGE_RENDER_TARGET, 0)) { return FALSE; } diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index 8222826e7a..3e5054ecd2 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -88,7 +88,8 @@ st_texture_create(struct st_context *st, _mesa_lookup_enum_by_nr(format), last_level); assert(format); - assert(screen->is_format_supported(screen, format, PIPE_TEXTURE)); + assert(screen->is_format_supported(screen, format, target, + PIPE_TEXTURE_USAGE_SAMPLER, 0)); memset(&pt, 0, sizeof(pt)); pt.target = target; -- cgit v1.2.3