diff options
Diffstat (limited to 'src/mesa')
22 files changed, 650 insertions, 456 deletions
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 6a8cba4d8a..800f6ee9a3 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -307,7 +307,7 @@ test_attachment_completeness(const GLcontext *ctx, GLenum format, /* OK */ } else if (ctx->Extensions.EXT_packed_depth_stencil && - att->Renderbuffer->_BaseFormat == GL_DEPTH_STENCIL_EXT) { + texImage->TexFormat->BaseFormat == GL_DEPTH_STENCIL_EXT) { /* OK */ } else { diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 9e5169eff1..b60b9656c6 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.5.3 + * Version: 7.1 * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2008 Brian Paul 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"), @@ -35,6 +35,7 @@ #include "shader/grammar/grammar_mesa.h" #include "arbprogparse.h" #include "program.h" +#include "programopt.h" #include "prog_parameter.h" #include "prog_statevars.h" #include "context.h" @@ -633,6 +634,41 @@ program_error(GLcontext *ctx, GLint position, const char *descrip) } +/** + * As above, but with an extra string parameter for more info. + */ +static void +program_error2(GLcontext *ctx, GLint position, const char *descrip, + const char *var) +{ + if (descrip) { + const char *prefix = "glProgramString(", *suffix = ")"; + char *str = (char *) _mesa_malloc(_mesa_strlen(descrip) + + _mesa_strlen(": ") + + _mesa_strlen(var) + + _mesa_strlen(prefix) + + _mesa_strlen(suffix) + 1); + if (str) { + _mesa_sprintf(str, "%s%s: %s%s", prefix, descrip, var, suffix); + _mesa_error(ctx, GL_INVALID_OPERATION, str); + _mesa_free(str); + } + } + { + char *str = (char *) _mesa_malloc(_mesa_strlen(descrip) + + _mesa_strlen(": ") + + _mesa_strlen(var) + 1); + if (str) { + _mesa_sprintf(str, "%s: %s", descrip, var); + } + _mesa_set_program_error(ctx, position, str); + if (str) { + _mesa_free(str); + } + } +} + + /** * constructs an integer from 4 GLubytes in LE format @@ -1226,10 +1262,10 @@ parse_state_single_item (GLcontext * ctx, const GLubyte ** inst, state_tokens[1] = coord; /* EYE or OBJECT */ - type = *(*inst++); + type = *(*inst)++; /* 0 - s, 1 - t, 2 - r, 3 - q */ - coord = *(*inst++); + coord = *(*inst)++; if (type == TEX_GEN_EYE) { switch (coord) { @@ -1245,6 +1281,9 @@ parse_state_single_item (GLcontext * ctx, const GLubyte ** inst, case COMPONENT_W: state_tokens[2] = STATE_TEXGEN_EYE_Q; break; + default: + _mesa_problem(ctx, "bad texgen component in " + "parse_state_single_item()"); } } else { @@ -1261,6 +1300,9 @@ parse_state_single_item (GLcontext * ctx, const GLubyte ** inst, case COMPONENT_W: state_tokens[2] = STATE_TEXGEN_OBJECT_Q; break; + default: + _mesa_problem(ctx, "bad texgen component in " + "parse_state_single_item()"); } } } @@ -1283,7 +1325,7 @@ parse_state_single_item (GLcontext * ctx, const GLubyte ** inst, break; case STATE_POINT: - switch (*(*inst++)) { + switch (*(*inst)++) { case POINT_SIZE: state_tokens[0] = STATE_POINT_SIZE; break; @@ -1685,18 +1727,14 @@ parse_attrib (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head struct arb_program *Program) { GLuint found; - char *error_msg; struct var_cache *attrib_var; attrib_var = parse_string (inst, vc_head, Program, &found); Program->Position = parse_position (inst); if (found) { - error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) attrib_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - attrib_var->name); - program_error(ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) attrib_var->name); return 1; } @@ -1729,7 +1767,7 @@ parse_param_elements (GLcontext * ctx, const GLubyte ** inst, { GLint idx; GLuint err = 0; - gl_state_index state_tokens[STATE_LENGTH]; + gl_state_index state_tokens[STATE_LENGTH] = {0, 0, 0, 0, 0}; GLfloat const_values[4]; switch (*(*inst)++) { @@ -1876,12 +1914,9 @@ parse_param (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, Program->Position = parse_position (inst); if (found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) param_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - param_var->name); - program_error (ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) param_var->name); return 1; } @@ -1976,12 +2011,9 @@ parse_temp (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, temp_var = parse_string (inst, vc_head, Program, &found); Program->Position = parse_position (inst); if (found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - temp_var->name); - program_error(ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) temp_var->name); return 1; } @@ -2022,12 +2054,9 @@ parse_output (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head output_var = parse_string (inst, vc_head, Program, &found); Program->Position = parse_position (inst); if (found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) output_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - output_var->name); - program_error (ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) output_var->name); return 1; } @@ -2053,12 +2082,9 @@ parse_alias (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, Program->Position = parse_position (inst); if (found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - temp_var->name); - program_error(ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) temp_var->name); return 1; } @@ -2068,12 +2094,9 @@ parse_alias (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_head, if (!found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); - _mesa_sprintf (error_msg, "Alias value %s is not defined", - temp_var->alias_binding->name); - program_error (ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Undefined alias value", + (char *) temp_var->alias_binding->name); return 1; } @@ -2096,12 +2119,9 @@ parse_address (GLcontext * ctx, const GLubyte ** inst, struct var_cache **vc_hea temp_var = parse_string (inst, vc_head, Program, &found); Program->Position = parse_position (inst); if (found) { - char *error_msg = (char *) - _mesa_malloc (_mesa_strlen ((char *) temp_var->name) + 40); - _mesa_sprintf (error_msg, "Duplicate Variable Declaration: %s", - temp_var->name); - program_error (ctx, Program->Position, error_msg); - _mesa_free (error_msg); + program_error2(ctx, Program->Position, + "Duplicate variable declaration", + (char *) temp_var->name); return 1; } @@ -2454,8 +2474,9 @@ parse_src_reg (GLcontext * ctx, const GLubyte ** inst, Program->Position = parse_position (inst); if (!found) { - program_error(ctx, Program->Position, - "2: Undefined variable"); /* src->name */ + program_error2(ctx, Program->Position, + "Undefined variable", + (char *) src->name); return 1; } @@ -2562,23 +2583,24 @@ parse_src_reg (GLcontext * ctx, const GLubyte ** inst, return 0; } + /** - * Parse fragment program vector source register. + * Parse vertex/fragment program vector source register. */ static GLuint -parse_fp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, - struct arb_program *program, - struct prog_src_register *reg) +parse_vector_src_reg(GLcontext *ctx, const GLubyte **inst, + struct var_cache **vc_head, + struct arb_program *program, + struct prog_src_register *reg) { enum register_file file; GLint index; - GLboolean negate; + GLubyte negateMask; GLubyte swizzle[4]; GLboolean isRelOffset; /* Grab the sign */ - negate = (parse_sign (inst) == -1) ? 0xf : 0x0; + negateMask = (parse_sign (inst) == -1) ? NEGATE_XYZW : NEGATE_NONE; /* And the src reg */ if (parse_src_reg(ctx, inst, vc_head, program, &file, &index, &isRelOffset)) @@ -2589,66 +2611,66 @@ parse_fp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst, reg->File = file; reg->Index = index; - reg->NegateBase = negate; reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], swizzle[2], swizzle[3]); + reg->NegateBase = negateMask; + reg->RelAddr = isRelOffset; return 0; } /** - * Parse fragment program destination register. - * \return 1 if error, 0 if no error. + * Parse vertex/fragment program scalar source register. */ -static GLuint -parse_fp_dst_reg(GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, struct arb_program *Program, - struct prog_dst_register *reg ) +static GLuint +parse_scalar_src_reg(GLcontext *ctx, const GLubyte **inst, + struct var_cache **vc_head, + struct arb_program *program, + struct prog_src_register *reg) { - GLint mask; - GLuint idx; enum register_file file; + GLint index; + GLubyte negateMask; + GLubyte swizzle[4]; + GLboolean isRelOffset; - if (parse_masked_dst_reg (ctx, inst, vc_head, Program, &file, &idx, &mask)) + /* Grab the sign */ + negateMask = (parse_sign (inst) == -1) ? NEGATE_XYZW : NEGATE_NONE; + + /* And the src reg */ + if (parse_src_reg(ctx, inst, vc_head, program, &file, &index, &isRelOffset)) return 1; + /* finally, the swizzle */ + parse_swizzle_mask(inst, swizzle, 1); + reg->File = file; - reg->Index = idx; - reg->WriteMask = mask; + reg->Index = index; + reg->Swizzle = (swizzle[0] << 0); + reg->NegateBase = negateMask; + reg->RelAddr = isRelOffset; return 0; } /** - * Parse fragment program scalar src register. + * Parse vertex/fragment program destination register. * \return 1 if error, 0 if no error. */ -static GLuint -parse_fp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, - struct arb_program *Program, - struct prog_src_register *reg ) +static GLuint +parse_dst_reg(GLcontext * ctx, const GLubyte ** inst, + struct var_cache **vc_head, struct arb_program *program, + struct prog_dst_register *reg ) { - enum register_file File; - GLint Index; - GLubyte Negate; - GLubyte Swizzle[4]; - GLboolean IsRelOffset; - - /* Grab the sign */ - Negate = (parse_sign (inst) == -1) ? 0x1 : 0x0; + GLint mask; + GLuint idx; + enum register_file file; - /* And the src reg */ - if (parse_src_reg (ctx, inst, vc_head, Program, &File, &Index, &IsRelOffset)) + if (parse_masked_dst_reg (ctx, inst, vc_head, program, &file, &idx, &mask)) return 1; - /* finally, the swizzle */ - parse_swizzle_mask(inst, Swizzle, 1); - - reg->File = File; - reg->Index = Index; - reg->NegateBase = Negate; - reg->Swizzle = (Swizzle[0] << 0); - + reg->File = file; + reg->Index = idx; + reg->WriteMask = mask; return 0; } @@ -2729,10 +2751,10 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; - if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) return 1; break; @@ -2782,10 +2804,10 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; - if (parse_fp_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) + if (parse_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) return 1; break; @@ -2798,11 +2820,11 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg(ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &fp->DstReg)) return 1; for (a = 0; a < 2; a++) { - if (parse_fp_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) + if (parse_scalar_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) return 1; } break; @@ -2883,10 +2905,10 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; for (a = 0; a < 2; a++) { - if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) return 1; } break; @@ -2912,11 +2934,11 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; for (a = 0; a < 3; a++) { - if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[a])) return 1; } break; @@ -2929,7 +2951,7 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, fp->Opcode = OPCODE_SWZ; break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; { @@ -2972,10 +2994,10 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_fp_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) + if (parse_dst_reg (ctx, inst, vc_head, Program, &fp->DstReg)) return 1; - if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) return 1; /* texImageUnit */ @@ -3047,7 +3069,7 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, case OP_TEX_KIL: Program->UsesKill = 1; - if (parse_fp_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &fp->SrcReg[0])) return 1; fp->Opcode = OPCODE_KIL; break; @@ -3059,23 +3081,6 @@ parse_fp_instruction (GLcontext * ctx, const GLubyte ** inst, return 0; } -static GLuint -parse_vp_dst_reg(GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, struct arb_program *Program, - struct prog_dst_register *reg ) -{ - GLint mask; - GLuint idx; - enum register_file file; - - if (parse_masked_dst_reg(ctx, inst, vc_head, Program, &file, &idx, &mask)) - return 1; - - reg->File = file; - reg->Index = idx; - reg->WriteMask = mask; - return 0; -} /** * Handle the parsing out of a masked address register @@ -3107,71 +3112,6 @@ parse_vp_address_reg (GLcontext * ctx, const GLubyte ** inst, return 0; } -/** - * Parse vertex program vector source register. - */ -static GLuint -parse_vp_vector_src_reg(GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, - struct arb_program *program, - struct prog_src_register *reg ) -{ - enum register_file file; - GLint index; - GLubyte negateMask; - GLubyte swizzle[4]; - GLboolean isRelOffset; - - /* Grab the sign */ - negateMask = (parse_sign (inst) == -1) ? 0xf : 0x0; - - /* And the src reg */ - if (parse_src_reg (ctx, inst, vc_head, program, &file, &index, &isRelOffset)) - return 1; - - /* finally, the swizzle */ - parse_swizzle_mask(inst, swizzle, 4); - - reg->File = file; - reg->Index = index; - reg->Swizzle = MAKE_SWIZZLE4(swizzle[0], swizzle[1], - swizzle[2], swizzle[3]); - reg->NegateBase = negateMask; - reg->RelAddr = isRelOffset; - return 0; -} - - -static GLuint -parse_vp_scalar_src_reg (GLcontext * ctx, const GLubyte ** inst, - struct var_cache **vc_head, - struct arb_program *Program, - struct prog_src_register *reg ) -{ - enum register_file File; - GLint Index; - GLubyte Negate; - GLubyte Swizzle[4]; - GLboolean IsRelOffset; - - /* Grab the sign */ - Negate = (parse_sign (inst) == -1) ? 0x1 : 0x0; - - /* And the src reg */ - if (parse_src_reg (ctx, inst, vc_head, Program, &File, &Index, &IsRelOffset)) - return 1; - - /* finally, the swizzle */ - parse_swizzle_mask(inst, Swizzle, 1); - - reg->File = File; - reg->Index = Index; - reg->Swizzle = (Swizzle[0] << 0); - reg->NegateBase = Negate; - reg->RelAddr = IsRelOffset; - return 0; -} - /** * This is a big mother that handles getting opcodes into the instruction @@ -3209,7 +3149,7 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, vp->DstReg.File = PROGRAM_ADDRESS; /* Get a scalar src register */ - if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) + if (parse_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) return 1; break; @@ -3233,10 +3173,10 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; - if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) return 1; break; @@ -3261,10 +3201,10 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, vp->Opcode = OPCODE_RSQ; break; } - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; - if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) + if (parse_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[0])) return 1; break; @@ -3274,11 +3214,11 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, vp->Opcode = OPCODE_POW; break; } - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; for (a = 0; a < 2; a++) { - if (parse_vp_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) + if (parse_scalar_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) return 1; } break; @@ -3322,11 +3262,11 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, vp->Opcode = OPCODE_XPD; break; } - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; for (a = 0; a < 2; a++) { - if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) return 1; } break; @@ -3338,11 +3278,11 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, break; } - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; for (a = 0; a < 3; a++) { - if (parse_vp_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) + if (parse_vector_src_reg(ctx, inst, vc_head, Program, &vp->SrcReg[a])) return 1; } break; @@ -3360,7 +3300,7 @@ parse_vp_instruction (GLcontext * ctx, const GLubyte ** inst, enum register_file file; GLint index; - if (parse_vp_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) + if (parse_dst_reg(ctx, inst, vc_head, Program, &vp->DstReg)) return 1; if (parse_src_reg(ctx, inst, vc_head, Program, &file, &index, &relAddr)) @@ -3794,11 +3734,11 @@ _mesa_parse_arb_program(GLcontext *ctx, GLenum target, int line, col; char *s; fprintf(stderr, "program: %s\n", (char *) strz); - fprintf(stderr, "Error Pos: %d\n", ctx->program.ErrorPos); - s = (char *) _mesa_find_line_column(strz, strz+ctx->program.ErrorPos, + fprintf(stderr, "Error Pos: %d\n", ctx->Program.ErrorPos); + s = (char *) _mesa_find_line_column(strz, strz+ctx->Program.ErrorPos, &line, &col); fprintf(stderr, "line %d col %d: %s\n", line, col, s); - } while (0) + } while (0); #endif _mesa_free(strz); @@ -3929,6 +3869,16 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target, _mesa_free_parameter_list(program->Base.Parameters); program->Base.Parameters = ap.Base.Parameters; + /* Append fog instructions now if the program has "OPTION ARB_fog_exp" + * or similar. We used to leave this up to drivers, but it appears + * there's no hardware that wants to do fog in a discrete stage separate + * from the fragment shader. + */ + if (program->FogOption != GL_NONE) { + _mesa_append_fog_code(ctx, program); + program->FogOption = GL_NONE; + } + #if DEBUG_FP _mesa_printf("____________Fragment program %u ________\n", program->Base.ID); _mesa_print_program(&program->Base); @@ -3952,7 +3902,7 @@ _mesa_parse_arb_vertex_program(GLcontext *ctx, GLenum target, ASSERT(target == GL_VERTEX_PROGRAM_ARB); if (!_mesa_parse_arb_program(ctx, target, (const GLubyte*) str, len, &ap)) { - /* Error in the program. Just return. */ + _mesa_error(ctx, GL_INVALID_OPERATION, "glProgramString(bad program)"); return; } diff --git a/src/mesa/shader/prog_parameter.c b/src/mesa/shader/prog_parameter.c index bb964274b9..4eb7313bec 100644 --- a/src/mesa/shader/prog_parameter.c +++ b/src/mesa/shader/prog_parameter.c @@ -387,7 +387,7 @@ sizeof_state_reference(const GLint *stateTokens) * PARAM ambient = state.material.front.ambient; * * \param paramList the parameter list - * \param state an array of 6 (STATE_LENGTH) state tokens + * \param stateTokens an array of 5 (STATE_LENGTH) state tokens * \return index of the new parameter. */ GLint diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index 39c4ca1dd5..09a8494bd3 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -426,6 +426,7 @@ replace_registers(struct prog_instruction *inst, GLuint numInst, { GLuint i, j; for (i = 0; i < numInst; i++) { + /* src regs */ for (j = 0; j < _mesa_num_inst_src_regs(inst->Opcode); j++) { if (inst[i].SrcReg[j].File == oldFile && inst[i].SrcReg[j].Index == oldIndex) { @@ -433,6 +434,11 @@ replace_registers(struct prog_instruction *inst, GLuint numInst, inst[i].SrcReg[j].Index = newIndex; } } + /* dst reg */ + if (inst[i].DstReg.File == oldFile && inst[i].DstReg.Index == oldIndex) { + inst[i].DstReg.File = newFile; + inst[i].DstReg.Index = newIndex; + } } } @@ -504,12 +510,25 @@ _mesa_combine_programs(GLcontext *ctx, newFprog->UsesKill = fprogA->UsesKill || fprogB->UsesKill; - /* connect color outputs/inputs */ + /* Connect color outputs of fprogA to color inputs of fprogB, via a + * new temporary register. + */ if ((progA->OutputsWritten & (1 << FRAG_RESULT_COLR)) && (progB->InputsRead & (1 << FRAG_ATTRIB_COL0))) { + GLint tempReg = _mesa_find_free_register(newProg, PROGRAM_TEMPORARY); + if (!tempReg) { + _mesa_problem(ctx, "No free temp regs found in " + "_mesa_combine_programs(), using 31"); + tempReg = 31; + } + /* replace writes to result.color[0] with tempReg */ + replace_registers(newInst, lenA, + PROGRAM_OUTPUT, FRAG_RESULT_COLR, + PROGRAM_TEMPORARY, tempReg); + /* replace reads from input.color[0] with tempReg */ replace_registers(newInst + lenA, lenB, PROGRAM_INPUT, FRAG_ATTRIB_COL0, - PROGRAM_OUTPUT, FRAG_RESULT_COLR); + PROGRAM_TEMPORARY, tempReg); } inputsB = progB->InputsRead; diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 0e22a2fa6e..18063adc79 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -32,6 +32,7 @@ #include "pipe/p_defines.h" #include "st_context.h" #include "st_atom.h" +#include "st_cb_bitmap.h" #include "st_program.h" @@ -147,6 +148,13 @@ void st_validate_state( struct st_context *st ) struct st_state_flags *state = &st->dirty; GLuint i; + /* The bitmap cache is immune to pixel unpack changes. + * Note that GLUT makes several calls to glPixelStore for each + * bitmap char it draws so this is an important check. + */ + if (state->mesa & ~_NEW_PACKUNPACK) + st_flush_bitmap_cache(st); + check_program_state( st ); if (state->st == 0) diff --git a/src/mesa/state_tracker/st_atom_depth.c b/src/mesa/state_tracker/st_atom_depth.c index 827ad3b548..03057e37fa 100644 --- a/src/mesa/state_tracker/st_atom_depth.c +++ b/src/mesa/state_tracker/st_atom_depth.c @@ -105,7 +105,7 @@ update_depth_stencil_alpha(struct st_context *st) st->ctx->Query.CurrentOcclusionObject->Active) dsa->depth.occlusion_count = 1; - if (st->ctx->Stencil.Enabled) { + if (st->ctx->Stencil.Enabled && st->ctx->Visual.stencilBits > 0) { dsa->stencil[0].enabled = 1; dsa->stencil[0].func = st_compare_func_to_pipe(st->ctx->Stencil.Function[0]); dsa->stencil[0].fail_op = gl_stencil_op_to_pipe(st->ctx->Stencil.FailFunc[0]); @@ -125,6 +125,9 @@ update_depth_stencil_alpha(struct st_context *st) dsa->stencil[1].value_mask = st->ctx->Stencil.ValueMask[1] & 0xff; dsa->stencil[1].write_mask = st->ctx->Stencil.WriteMask[1] & 0xff; } + else { + dsa->stencil[1] = dsa->stencil[0]; + } } if (st->ctx->Color.AlphaEnabled) { diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index 5787a7492c..5dd242ac66 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -167,7 +167,6 @@ update_samplers(struct st_context *st) /* only care about ARB_shadow, not SGI shadow */ if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) { - sampler->compare = 1; sampler->compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE; sampler->compare_func = st_compare_func_to_pipe(texobj->CompareFunc); diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index f1fddc4e02..a623d0bcc0 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -214,7 +214,7 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value) const GLint height = ctx->DrawBuffer->_Ymax - ypos; /* make sure color bufs aren't cached */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); switch (op) { case GL_ADD: diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index 6e59439874..ec56b25f7c 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -60,6 +60,33 @@ /** + * The bitmap cache attempts to accumulate multiple glBitmap calls in a + * buffer which is then rendered en mass upon a flush, state change, etc. + * A wide, short buffer is used to target the common case of a series + * of glBitmap calls being used to draw text. + */ +static GLboolean UseBitmapCache = GL_TRUE; + + +#define BITMAP_CACHE_WIDTH 512 +#define BITMAP_CACHE_HEIGHT 32 + +struct bitmap_cache +{ + /** Window pos to render the cached image */ + GLint xpos, ypos; + /** Bounds of region used in window coords */ + GLint xmin, ymin, xmax, ymax; + struct pipe_texture *texture; + GLboolean empty; + /** An I8 texture image: */ + GLubyte buffer[BITMAP_CACHE_HEIGHT][BITMAP_CACHE_WIDTH]; +}; + + + + +/** * Make fragment program for glBitmap: * Sample the texture and kill the fragment if the bit is 0. * This program will be combined with the user's fragment program. @@ -326,7 +353,7 @@ setup_bitmap_vertex_data(struct st_context *st, const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP); const GLfloat x0 = x; const GLfloat x1 = x + width; - const GLfloat y0 = invert ? (fb->Height - y - height) : y; + const GLfloat y0 = invert ? ((int) fb->Height - y - height) : y; const GLfloat y1 = invert ? (y0 + height) : y + height; const GLfloat bias = st->bitmap_texcoord_bias; const GLfloat xBias = bias / (x1-x0); @@ -390,16 +417,18 @@ setup_bitmap_vertex_data(struct st_context *st, static void draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, GLsizei width, GLsizei height, - struct pipe_texture *pt, - struct st_fragment_program *stfp) + struct pipe_texture *pt) { struct st_context *st = ctx->st; struct pipe_context *pipe = ctx->st->pipe; struct cso_context *cso = ctx->st->cso_context; + struct st_fragment_program *stfp; GLuint maxSize; + stfp = combined_bitmap_fragment_program(ctx); + /* limit checks */ - /* XXX if DrawPixels image is larger than max texture size, break + /* XXX if the bitmap is larger than the max texture size, break * it up into chunks. */ maxSize = 1 << (pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1); @@ -466,16 +495,215 @@ draw_bitmap_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z, } +static void +reset_cache(struct st_context *st) +{ + memset(st->bitmap.cache->buffer, 0, sizeof(st->bitmap.cache->buffer)); + st->bitmap.cache->empty = GL_TRUE; + + st->bitmap.cache->xmin = 1000000; + st->bitmap.cache->xmax = -1000000; + st->bitmap.cache->ymin = 1000000; + st->bitmap.cache->ymax = -1000000; +} + static void +init_bitmap_cache(struct st_context *st) +{ + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + enum pipe_format format; + + st->bitmap.cache = CALLOC_STRUCT(bitmap_cache); + if (!st->bitmap.cache) + return; + + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_U_I8, PIPE_TEXTURE)) { + format = PIPE_FORMAT_U_I8; + } + else { + /* XXX support more formats */ + assert(0); + } + + st->bitmap.cache->texture + = st_texture_create(st, PIPE_TEXTURE_2D, format, 0, + BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, 1, 0); + if (!st->bitmap.cache->texture) { + FREE(st->bitmap.cache); + st->bitmap.cache = NULL; + return; + } + + reset_cache(st); +} + + +/** + * If there's anything in the bitmap cache, draw/flush it now. + */ +void +st_flush_bitmap_cache(struct st_context *st) +{ + if (!st->bitmap.cache->empty) { + struct bitmap_cache *cache = st->bitmap.cache; + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + struct pipe_surface *surf; + void *dest; + + assert(cache->xmin <= cache->xmax); + /* + printf("flush size %d x %d at %d, %d\n", + cache->xmax - cache->xmin, + cache->ymax - cache->ymin, + cache->xpos, cache->ypos); + */ + + /* update the texture map image */ + surf = screen->get_tex_surface(screen, cache->texture, 0, 0, 0); + dest = pipe_surface_map(surf); + memcpy(dest, cache->buffer, sizeof(cache->buffer)); + pipe_surface_unmap(surf); + pipe_surface_reference(&surf, NULL); + + pipe->texture_update(pipe, cache->texture, 0, 0x1); + + draw_bitmap_quad(st->ctx, + cache->xpos, + cache->ypos, + st->ctx->Current.RasterPos[2], + BITMAP_CACHE_WIDTH, BITMAP_CACHE_HEIGHT, + cache->texture); + + reset_cache(st); + } +} + + +/** + * Try to accumulate this glBitmap call in the bitmap cache. + * \return GL_TRUE for success, GL_FALSE if bitmap is too large, etc. + */ +static GLboolean +accum_bitmap(struct st_context *st, + GLint x, GLint y, GLsizei width, GLsizei height, + const struct gl_pixelstore_attrib *unpack, + const GLubyte *bitmap ) +{ + struct bitmap_cache *cache = st->bitmap.cache; + int row, col; + int px = -999, py; + + if (width > BITMAP_CACHE_WIDTH || + height > BITMAP_CACHE_HEIGHT) + return GL_FALSE; /* too big to cache */ + + if (!cache->empty) { + px = x - cache->xpos; /* pos in buffer */ + py = y - cache->ypos; + if (px < 0 || px + width > BITMAP_CACHE_WIDTH || + py < 0 || py + height > BITMAP_CACHE_HEIGHT) { + /* This bitmap would extend beyond cache bounds, + * so flush and continue. + */ + st_flush_bitmap_cache(st); + } + } + + if (cache->empty) { + /* Initialize. Center bitmap vertically in the buffer. */ + px = 0; + py = (BITMAP_CACHE_HEIGHT - height) / 2; + cache->xpos = x; + cache->ypos = y - py; + cache->empty = GL_FALSE; + } + + assert(px != -999); + + if (x < cache->xmin) + cache->xmin = x; + if (y < cache->ymin) + cache->ymin = y; + if (x + width > cache->xmax) + cache->xmax = x + width; + if (y + height > cache->ymax) + cache->ymax = y + height; + + /* XXX try to combine this code with code in make_bitmap_texture() */ +#define SET_PIXEL(COL, ROW) \ + cache->buffer[py + (ROW)][px + (COL)] = 0xff; + + for (row = 0; row < height; row++) { + const GLubyte *src = (const GLubyte *) _mesa_image_address2d(unpack, + bitmap, width, height, GL_COLOR_INDEX, GL_BITMAP, row, 0); + + if (unpack->LsbFirst) { + /* Lsb first */ + GLubyte mask = 1U << (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 128U) { + src++; + mask = 1U; + } + else { + mask = mask << 1; + } + } + + /* get ready for next row */ + if (mask != 1) + src++; + } + else { + /* Msb first */ + GLubyte mask = 128U >> (unpack->SkipPixels & 0x7); + for (col = 0; col < width; col++) { + + if (*src & mask) { + SET_PIXEL(col, row); + } + + if (mask == 1U) { + src++; + mask = 128U; + } + else { + mask = mask >> 1; + } + } + + /* get ready for next row */ + if (mask != 128) + src++; + } + + } /* row */ + + return GL_TRUE; /* accumulated */ +} + + + +/** + * Called via ctx->Driver.Bitmap() + */ +static void st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { - struct st_fragment_program *stfp; struct st_context *st = ctx->st; struct pipe_texture *pt; - stfp = combined_bitmap_fragment_program(ctx); + st_validate_state(st); if (!st->bitmap.vs) { /* create pass-through vertex shader now */ @@ -485,28 +713,40 @@ st_Bitmap(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, const uint semantic_indexes[] = { 0, 0, 0 }; st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, semantic_names, - semantic_indexes); + semantic_indexes, + &st->bitmap.vert_shader); } - st_validate_state(st); + if (UseBitmapCache && accum_bitmap(st, x, y, width, height, unpack, bitmap)) + return; pt = make_bitmap_texture(ctx, width, height, unpack, bitmap); if (pt) { + assert(pt->target == PIPE_TEXTURE_2D); draw_bitmap_quad(ctx, x, y, ctx->Current.RasterPos[2], - width, height, - pt, stfp); + width, height, pt); pipe_texture_reference(&pt, NULL); } } - -void st_init_bitmap_functions(struct dd_function_table *functions) +/** Per-context init */ +void +st_init_bitmap_functions(struct dd_function_table *functions) { functions->Bitmap = st_Bitmap; } +/** Per-context init */ +void +st_init_bitmap(struct st_context *st) +{ + init_bitmap_cache(st); +} + + +/** Per-context tear-down */ void st_destroy_bitmap(struct st_context *st) { @@ -524,9 +764,15 @@ st_destroy_bitmap(struct st_context *st) pipe->delete_vs_state(pipe, st->bitmap.vs); st->bitmap.vs = NULL; } + if (st->bitmap.vbuf) { pipe->winsys->buffer_destroy(pipe->winsys, st->bitmap.vbuf); st->bitmap.vbuf = NULL; } -} + if (st->bitmap.cache) { + pipe_texture_release(&st->bitmap.cache->texture); + FREE(st->bitmap.cache); + st->bitmap.cache = NULL; + } +} diff --git a/src/mesa/state_tracker/st_cb_bitmap.h b/src/mesa/state_tracker/st_cb_bitmap.h index ac19e0ebb1..aae11d34c9 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.h +++ b/src/mesa/state_tracker/st_cb_bitmap.h @@ -33,9 +33,14 @@ extern void st_init_bitmap_functions(struct dd_function_table *functions); +extern void +st_init_bitmap(struct st_context *st); extern void st_destroy_bitmap(struct st_context *st); +extern void +st_flush_bitmap_cache(struct st_context *st); + #endif /* ST_CB_BITMAP_H */ diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 5ca15df602..ec8d3e1022 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -251,7 +251,7 @@ clear_with_quad(GLcontext *ctx, /* fragment shader state: color pass-through program */ if (!st->clear.fs) { - st->clear.fs = util_make_fragment_passthrough_shader(pipe); + st->clear.fs = util_make_fragment_passthrough_shader(pipe, &st->clear.frag_shader); } pipe->bind_fs_state(pipe, st->clear.fs); @@ -264,7 +264,8 @@ clear_with_quad(GLcontext *ctx, const uint semantic_indexes[] = { 0, 0 }; st->clear.vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, - semantic_indexes); + semantic_indexes, + &st->clear.vert_shader); } pipe->bind_vs_state(pipe, st->clear.vs); #endif diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 0a2d37c117..43cc21d1fb 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -114,6 +114,12 @@ combined_drawpix_fragment_program(GLcontext *ctx) _mesa_clone_program(ctx, &st->pixel_xfer.program->Base.Base); } else { +#if 0 + printf("Base program:\n"); + _mesa_print_program(&st->fp->Base.Base); + printf("DrawPix program:\n"); + _mesa_print_program(&st->pixel_xfer.program->Base.Base); +#endif stfp = (struct st_fragment_program *) _mesa_combine_programs(ctx, &st->pixel_xfer.program->Base.Base, @@ -731,7 +737,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, GLint skipPixels; ubyte *stmap; - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* map the stencil buffer */ stmap = pipe_surface_map(ps); @@ -946,7 +952,7 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, enum pipe_format srcFormat, texFormat; /* make sure rendering has completed */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); st_validate_state(st); diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 5384252a8e..ec7788923a 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -366,7 +366,7 @@ st_finish_render_texture(GLcontext *ctx, assert(strb); - ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE); + ctx->st->pipe->flush(ctx->st->pipe, PIPE_FLUSH_RENDER_CACHE, NULL); /* printf("FINISH RENDER TO TEXTURE surf=%p\n", strb->surface); diff --git a/src/mesa/state_tracker/st_cb_flush.c b/src/mesa/state_tracker/st_cb_flush.c index dbec993f1b..e321b401e2 100644 --- a/src/mesa/state_tracker/st_cb_flush.c +++ b/src/mesa/state_tracker/st_cb_flush.c @@ -35,6 +35,7 @@ #include "main/macros.h" #include "main/context.h" #include "st_context.h" +#include "st_cb_bitmap.h" #include "st_cb_flush.h" #include "st_cb_fbo.h" #include "st_public.h" @@ -43,19 +44,23 @@ #include "pipe/p_winsys.h" -void st_flush( struct st_context *st, uint pipeFlushFlags ) +void st_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ) { FLUSH_VERTICES(st->ctx, 0); - st->pipe->flush( st->pipe, pipeFlushFlags ); + st_flush_bitmap_cache(st); + + st->pipe->flush( st->pipe, pipeFlushFlags, fence ); } -static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) +static void st_gl_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ) { GLframebuffer *fb = st->ctx->DrawBuffer; - FLUSH_VERTICES(st->ctx, 0); + st_flush( st, pipeFlushFlags, fence ); if (!fb) return; @@ -80,15 +85,6 @@ static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) = st_renderbuffer(fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer); struct pipe_surface *front_surf = strb->surface; - /* If we aren't rendering to the frontbuffer, this is a noop. - * This should be uncontroversial for glFlush, though people may - * feel more strongly about glFinish. - * - * Additionally, need to make sure that the frontbuffer_dirty - * flag really gets set on frontbuffer rendering. - */ - st->pipe->flush( st->pipe, pipeFlushFlags ); - /* Hook for copying "fake" frontbuffer if necessary: */ st->pipe->winsys->flush_frontbuffer( st->pipe->winsys, front_surf, @@ -103,7 +99,18 @@ static void st_gl_flush( struct st_context *st, uint pipeFlushFlags ) */ static void st_glFlush(GLcontext *ctx) { - st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE); + st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL); +} + + +void st_finish( struct st_context *st ) +{ + struct pipe_fence_handle *fence; + + st_gl_flush(st, PIPE_FLUSH_RENDER_CACHE, &fence); + + st->pipe->winsys->fence_finish(st->pipe->winsys, fence, 0); + st->pipe->winsys->fence_reference(st->pipe->winsys, &fence, NULL); } @@ -112,7 +119,7 @@ static void st_glFlush(GLcontext *ctx) */ static void st_glFinish(GLcontext *ctx) { - st_gl_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_WAIT); + st_finish( ctx->st ); } diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 4cf9adcd28..e9fcdf69a1 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -160,7 +160,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, return; /* make sure rendering has completed */ - pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE); + pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL); if (format == GL_STENCIL_INDEX) { st_read_stencil_pixels(ctx, x, y, width, height, type, pack, dest); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 7c18386575..a20195f2de 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -95,12 +95,21 @@ st_create_context_priv( GLcontext *ctx, struct pipe_context *pipe ) st->draw = draw_create(); /* for selection/feedback */ + /* Disable draw options that might convert points/lines to tris, etc. + * as that would foul-up feedback/selection mode. + */ + draw_wide_line_threshold(st->draw, 1000.0f); + draw_wide_point_threshold(st->draw, 1000.0f); + draw_enable_line_stipple(st->draw, FALSE); + draw_enable_point_sprites(st->draw, FALSE); + st->dirty.mesa = ~0; st->dirty.st = ~0; st->cso_context = cso_create_context(pipe); st_init_atoms( st ); + st_init_bitmap(st); st_init_draw( st ); st_init_generate_mipmap(st); st_init_blit(st); diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 2d37086799..85e3d47e1a 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -42,6 +42,7 @@ struct cso_cache; struct cso_blend; struct gen_mipmap_state; struct blit_state; +struct bitmap_cache; #define ST_NEW_MESA 0x1 /* Mesa state has changed */ @@ -147,13 +148,17 @@ struct st_context struct st_fragment_program *program; /**< bitmap tex/kil program */ GLuint user_prog_sn; /**< user fragment program serial no. */ struct st_fragment_program *combined_prog; + struct pipe_shader_state vert_shader; void *vs; float vertices[4][3][4]; /**< vertex pos + color + texcoord */ struct pipe_buffer *vbuf; + struct bitmap_cache *cache; } bitmap; /** for glClear */ struct { + struct pipe_shader_state vert_shader; + struct pipe_shader_state frag_shader; void *vs; void *fs; float vertices[4][2][4]; /**< vertex pos + color */ diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index 20af90df7d..f0f62246dd 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -210,6 +210,7 @@ st_draw_vbo(GLcontext *ctx, const struct pipe_shader_state *vs; struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; GLuint attr; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; /* sanity check for pointer arithmetic below */ assert(sizeof(arrays[0]->Ptr[0]) == 1); @@ -226,7 +227,6 @@ st_draw_vbo(GLcontext *ctx, for (attr = 0; attr < vp->num_inputs; attr++) { const GLuint mesaAttr = vp->index_to_input[attr]; struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - struct pipe_vertex_element velement; if (bufobj && bufobj->Name) { /* Attribute data is in a VBO. @@ -239,8 +239,8 @@ st_draw_vbo(GLcontext *ctx, vbuffer[attr].buffer = NULL; pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ - velement.src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; - assert(velement.src_offset <= 2048); /* 11-bit field */ + velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; + assert(velements[attr].src_offset <= 2048); /* 11-bit field */ } else { /* attribute data is in user-space memory, not a VBO */ @@ -259,24 +259,24 @@ st_draw_vbo(GLcontext *ctx, (void *) arrays[mesaAttr]->Ptr, bytes); vbuffer[attr].buffer_offset = 0; - velement.src_offset = 0; + velements[attr].src_offset = 0; } /* common-case setup */ vbuffer[attr].pitch = arrays[mesaAttr]->StrideB; /* in bytes */ vbuffer[attr].max_index = max_index; - velement.vertex_buffer_index = attr; - velement.nr_components = arrays[mesaAttr]->Size; - velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, - arrays[mesaAttr]->Size, - arrays[mesaAttr]->Normalized); - assert(velement.src_format); - - /* tell pipe about this attribute */ - pipe->set_vertex_buffer(pipe, attr, &vbuffer[attr]); - pipe->set_vertex_element(pipe, attr, &velement); + velements[attr].vertex_buffer_index = attr; + velements[attr].nr_components = arrays[mesaAttr]->Size; + velements[attr].src_format + = pipe_vertex_format(arrays[mesaAttr]->Type, + arrays[mesaAttr]->Size, + arrays[mesaAttr]->Normalized); + assert(velements[attr].src_format); } + pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); + pipe->set_vertex_elements(pipe, vp->num_inputs, velements); + /* do actual drawing */ if (ib) { @@ -336,8 +336,8 @@ st_draw_vbo(GLcontext *ctx, for (attr = 0; attr < vp->num_inputs; attr++) { pipe_buffer_reference(winsys, &vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); - pipe->set_vertex_buffer(pipe, attr, &vbuffer[attr]); } + pipe->set_vertex_buffers(pipe, vp->num_inputs, vbuffer); } @@ -362,7 +362,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, struct pipe_context *pipe = ctx->st->pipe; struct pipe_buffer *vbuf; struct pipe_vertex_buffer vbuffer; - struct pipe_vertex_element velement; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; unsigned i; assert(numAttribs > 0); @@ -393,16 +393,16 @@ st_draw_vertices(GLcontext *ctx, unsigned prim, vbuffer.buffer = vbuf; vbuffer.pitch = numAttribs * 4 * sizeof(float); /* vertex size */ vbuffer.buffer_offset = 0; - pipe->set_vertex_buffer(pipe, 0, &vbuffer); + pipe->set_vertex_buffers(pipe, 1, &vbuffer); /* tell pipe about the vertex attributes */ for (i = 0; i < numAttribs; i++) { - velement.src_offset = i * 4 * sizeof(GLfloat); - velement.vertex_buffer_index = 0; - velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - velement.nr_components = 4; - pipe->set_vertex_element(pipe, i, &velement); + velements[i].src_offset = i * 4 * sizeof(GLfloat); + velements[i].vertex_buffer_index = 0; + velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + velements[i].nr_components = 4; } + pipe->set_vertex_elements(pipe, numAttribs, velements); /* draw */ pipe->draw_arrays(pipe, prim, 0, numVertex); @@ -470,7 +470,8 @@ st_feedback_draw_vbo(GLcontext *ctx, const struct st_vertex_program *vp; const struct pipe_shader_state *vs; struct pipe_buffer *index_buffer_handle = 0; - struct pipe_vertex_buffer vbuffer[PIPE_MAX_SHADER_INPUTS]; + struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS]; + struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; GLuint attr, i; ubyte *mapped_constants; @@ -505,7 +506,6 @@ st_feedback_draw_vbo(GLcontext *ctx, for (attr = 0; attr < vp->num_inputs; attr++) { const GLuint mesaAttr = vp->index_to_input[attr]; struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - struct pipe_vertex_element velement; void *map; if (bufobj && bufobj->Name) { @@ -516,10 +516,10 @@ st_feedback_draw_vbo(GLcontext *ctx, struct st_buffer_object *stobj = st_buffer_object(bufobj); assert(stobj->buffer); - vbuffer[attr].buffer = NULL; - pipe_buffer_reference(winsys, &vbuffer[attr].buffer, stobj->buffer); - vbuffer[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ - velement.src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; + vbuffers[attr].buffer = NULL; + pipe_buffer_reference(winsys, &vbuffers[attr].buffer, stobj->buffer); + vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ + velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } else { /* attribute data is in user-space memory, not a VBO */ @@ -528,35 +528,39 @@ st_feedback_draw_vbo(GLcontext *ctx, * (max_index + 1)); /* wrap user data */ - vbuffer[attr].buffer + vbuffers[attr].buffer = winsys->user_buffer_create(winsys, (void *) arrays[mesaAttr]->Ptr, bytes); - vbuffer[attr].buffer_offset = 0; - velement.src_offset = 0; + vbuffers[attr].buffer_offset = 0; + velements[attr].src_offset = 0; } /* common-case setup */ - vbuffer[attr].pitch = arrays[mesaAttr]->StrideB; /* in bytes */ - vbuffer[attr].max_index = max_index; - velement.vertex_buffer_index = attr; - velement.nr_components = arrays[mesaAttr]->Size; - velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, + vbuffers[attr].pitch = arrays[mesaAttr]->StrideB; /* in bytes */ + vbuffers[attr].max_index = max_index; + velements[attr].vertex_buffer_index = attr; + velements[attr].nr_components = arrays[mesaAttr]->Size; + velements[attr].src_format = pipe_vertex_format(arrays[mesaAttr]->Type, arrays[mesaAttr]->Size, arrays[mesaAttr]->Normalized); - assert(velement.src_format); + assert(velements[attr].src_format); /* tell draw about this attribute */ +#if 0 draw_set_vertex_buffer(draw, attr, &vbuffer[attr]); - draw_set_vertex_element(draw, attr, &velement); +#endif /* map the attrib buffer */ map = pipe->winsys->buffer_map(pipe->winsys, - vbuffer[attr].buffer, + vbuffers[attr].buffer, PIPE_BUFFER_USAGE_CPU_READ); draw_set_mapped_vertex_buffer(draw, attr, map); } + draw_set_vertex_buffers(draw, vp->num_inputs, vbuffers); + draw_set_vertex_elements(draw, vp->num_inputs, velements); + if (ib) { unsigned indexSize; struct gl_buffer_object *bufobj = ib->obj; @@ -606,7 +610,7 @@ st_feedback_draw_vbo(GLcontext *ctx, /* * unmap vertex/index buffers */ - for (i = 0; i < PIPE_ATTRIB_MAX; i++) { + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->vertex_buffer[i].buffer) { pipe->winsys->buffer_unmap(pipe->winsys, draw->vertex_buffer[i].buffer); diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 9aeda65a5c..cb6fa9a573 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -271,6 +271,10 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) return PIPE_FORMAT_U_I8; case MESA_FORMAT_Z16: return PIPE_FORMAT_Z16_UNORM; + case MESA_FORMAT_Z32: + return PIPE_FORMAT_Z32_UNORM; + case MESA_FORMAT_Z24_S8: + return PIPE_FORMAT_Z24S8_UNORM; default: assert(0); return 0; @@ -281,7 +285,7 @@ st_mesa_format_to_pipe_format(GLuint mesaFormat) * Find an RGBA format supported by the context/winsys. */ static GLuint -default_rgba_format(struct pipe_context *pipe, uint type) +default_rgba_format(struct pipe_screen *screen, uint type) { static const enum pipe_format colorFormats[] = { PIPE_FORMAT_A8R8G8B8_UNORM, @@ -289,7 +293,6 @@ default_rgba_format(struct pipe_context *pipe, uint type) PIPE_FORMAT_R8G8B8A8_UNORM, PIPE_FORMAT_R5G6B5_UNORM }; - struct pipe_screen *screen = pipe->screen; uint i; for (i = 0; i < Elements(colorFormats); i++) { if (screen->is_format_supported( screen, colorFormats[i], type )) { @@ -304,9 +307,8 @@ default_rgba_format(struct pipe_context *pipe, uint type) * Search list of formats for first RGBA format with >8 bits/channel. */ static GLuint -default_deep_rgba_format(struct pipe_context *pipe, uint type) +default_deep_rgba_format(struct pipe_screen *screen, uint type) { - struct pipe_screen *screen = pipe->screen; if (screen->is_format_supported(screen, PIPE_FORMAT_R16G16B16A16_SNORM, type)) { return PIPE_FORMAT_R16G16B16A16_SNORM; } @@ -318,7 +320,7 @@ default_deep_rgba_format(struct pipe_context *pipe, uint type) * Find an Z format supported by the context/winsys. */ static GLuint -default_depth_format(struct pipe_context *pipe, uint type) +default_depth_format(struct pipe_screen *screen, uint type) { static const enum pipe_format zFormats[] = { PIPE_FORMAT_Z16_UNORM, @@ -326,7 +328,6 @@ default_depth_format(struct pipe_context *pipe, uint type) PIPE_FORMAT_S8Z24_UNORM, PIPE_FORMAT_Z24S8_UNORM }; - struct pipe_screen *screen = pipe->screen; uint i; for (i = 0; i < Elements(zFormats); i++) { if (screen->is_format_supported( screen, zFormats[i], type )) { @@ -338,15 +339,16 @@ default_depth_format(struct pipe_context *pipe, uint type) /** - * Choose the PIPE_FORMAT_ to use for user-created renderbuffers. - * - * \return PIPE_FORMAT_NONE if error/problem. + * Given an OpenGL internalFormat value for a texture or surface, return + * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match. */ -enum pipe_format -st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) +static enum pipe_format +choose_format(struct pipe_context *pipe, GLint internalFormat, uint surfType) { struct pipe_screen *screen = pipe->screen; - uint surfType = PIPE_SURFACE; + + assert(surfType == PIPE_SURFACE || + surfType == PIPE_TEXTURE); switch (internalFormat) { case 4: @@ -358,26 +360,26 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) case GL_RGBA8: case GL_RGB10_A2: case GL_RGBA12: - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_RGBA16: - return default_deep_rgba_format( pipe, surfType ); + return default_deep_rgba_format( screen, surfType ); case GL_RGBA4: case GL_RGBA2: if (screen->is_format_supported( screen, PIPE_FORMAT_A4R4G4B4_UNORM, surfType )) return PIPE_FORMAT_A4R4G4B4_UNORM; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_RGB5_A1: if (screen->is_format_supported( screen, PIPE_FORMAT_A1R5G5B5_UNORM, surfType )) return PIPE_FORMAT_A1R5G5B5_UNORM; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_RGB8: case GL_RGB10: case GL_RGB12: case GL_RGB16: - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_RGB5: case GL_RGB4: @@ -386,7 +388,7 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) return PIPE_FORMAT_A1R5G5B5_UNORM; if (screen->is_format_supported( screen, PIPE_FORMAT_R5G6B5_UNORM, surfType )) return PIPE_FORMAT_R5G6B5_UNORM; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_ALPHA: case GL_ALPHA4: @@ -396,7 +398,7 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) case GL_COMPRESSED_ALPHA: if (screen->is_format_supported( screen, PIPE_FORMAT_U_A8, surfType )) return PIPE_FORMAT_U_A8; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case 1: case GL_LUMINANCE: @@ -406,8 +408,8 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) case GL_LUMINANCE16: case GL_COMPRESSED_LUMINANCE: if (screen->is_format_supported( screen, PIPE_FORMAT_U_L8, surfType )) - return PIPE_FORMAT_U_A8; - return default_rgba_format( pipe, surfType ); + return PIPE_FORMAT_U_L8; + return default_rgba_format( screen, surfType ); case 2: case GL_LUMINANCE_ALPHA: @@ -420,7 +422,7 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) case GL_COMPRESSED_LUMINANCE_ALPHA: if (screen->is_format_supported( screen, PIPE_FORMAT_U_A8_L8, surfType )) return PIPE_FORMAT_U_A8_L8; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); case GL_INTENSITY: case GL_INTENSITY4: @@ -430,32 +432,32 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) case GL_COMPRESSED_INTENSITY: if (screen->is_format_supported( screen, PIPE_FORMAT_U_I8, surfType )) return PIPE_FORMAT_U_I8; - return default_rgba_format( pipe, surfType ); + return default_rgba_format( screen, surfType ); -#if 0 - /* not supported for renderbuffers */ case GL_YCBCR_MESA: return PIPE_FORMAT_NONE; - case GL_COMPRESSED_RGB_FXT1_3DFX: - return &_mesa_texformat_rgb_fxt1; - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return &_mesa_texformat_rgba_fxt1; case GL_RGB_S3TC: case GL_RGB4_S3TC: case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: - return &_mesa_texformat_rgb_dxt1; + return PIPE_FORMAT_DXT1_RGB; case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: - return &_mesa_texformat_rgba_dxt1; + return PIPE_FORMAT_DXT1_RGBA; case GL_RGBA_S3TC: case GL_RGBA4_S3TC: case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: - return &_mesa_texformat_rgba_dxt3; + return PIPE_FORMAT_DXT3_RGBA; case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: - return &_mesa_texformat_rgba_dxt5; + return PIPE_FORMAT_DXT5_RGBA; + +#if 0 + case GL_COMPRESSED_RGB_FXT1_3DFX: + return PIPE_FORMAT_RGB_FXT1; + case GL_COMPRESSED_RGBA_FXT1_3DFX: + return PIPE_FORMAT_RGB_FXT1; #endif case GL_DEPTH_COMPONENT16: @@ -473,7 +475,7 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) return PIPE_FORMAT_Z32_UNORM; /* fall-through */ case GL_DEPTH_COMPONENT: - return default_depth_format( pipe, surfType ); + return default_depth_format( screen, surfType ); case GL_STENCIL_INDEX: case GL_STENCIL_INDEX1_EXT: @@ -502,155 +504,79 @@ st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) } - -/* It works out that this function is fine for all the supported - * hardware. However, there is still a need to map the formats onto - * hardware descriptors. - */ -/* Note that the i915 can actually support many more formats than - * these if we take the step of simply swizzling the colors - * immediately after sampling... +/** + * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces. */ -const struct gl_texture_format * -st_ChooseTextureFormat(GLcontext * ctx, GLint internalFormat, - GLenum format, GLenum type) +enum pipe_format +st_choose_renderbuffer_format(struct pipe_context *pipe, GLint internalFormat) { -#if 0 - struct intel_context *intel = intel_context(ctx); - const GLboolean do32bpt = (intel->intelScreen->front.cpp == 4); -#else - const GLboolean do32bpt = 1; -#endif - - (void) ctx; - - switch (internalFormat) { - case 4: - case GL_RGBA: - case GL_COMPRESSED_RGBA: - if (format == GL_BGRA) { - if (type == GL_UNSIGNED_BYTE || type == GL_UNSIGNED_INT_8_8_8_8_REV) { - return &_mesa_texformat_argb8888; - } - else if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { - return &_mesa_texformat_argb4444; - } - else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { - return &_mesa_texformat_argb1555; - } - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; - - case 3: - case GL_RGB: - case GL_COMPRESSED_RGB: - if (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) { - return &_mesa_texformat_rgb565; - } - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_rgb565; - - case GL_RGBA8: - case GL_RGB10_A2: - case GL_RGBA12: - case GL_RGBA16: - return do32bpt ? &_mesa_texformat_argb8888 : &_mesa_texformat_argb4444; + return choose_format(pipe, internalFormat, PIPE_SURFACE); +} - case GL_RGBA4: - case GL_RGBA2: - return &_mesa_texformat_argb4444; - case GL_RGB5_A1: - return &_mesa_texformat_argb1555; - - case GL_RGB8: - case GL_RGB10: - case GL_RGB12: - case GL_RGB16: +static const struct gl_texture_format * +translate_gallium_format_to_mesa_format(enum pipe_format format) +{ + switch (format) { + case PIPE_FORMAT_A8R8G8B8_UNORM: return &_mesa_texformat_argb8888; - - case GL_RGB5: - case GL_RGB4: - case GL_R3_G3_B2: + case PIPE_FORMAT_A1R5G5B5_UNORM: + return &_mesa_texformat_argb1555; + case PIPE_FORMAT_A4R4G4B4_UNORM: + return &_mesa_texformat_argb4444; + case PIPE_FORMAT_R5G6B5_UNORM: return &_mesa_texformat_rgb565; - - case GL_ALPHA: - case GL_ALPHA4: - case GL_ALPHA8: - case GL_ALPHA12: - case GL_ALPHA16: - case GL_COMPRESSED_ALPHA: + case PIPE_FORMAT_U_A8_L8: + return &_mesa_texformat_al88; + case PIPE_FORMAT_U_A8: return &_mesa_texformat_a8; - - case 1: - case GL_LUMINANCE: - case GL_LUMINANCE4: - case GL_LUMINANCE8: - case GL_LUMINANCE12: - case GL_LUMINANCE16: - case GL_COMPRESSED_LUMINANCE: + case PIPE_FORMAT_U_L8: return &_mesa_texformat_l8; - - case 2: - case GL_LUMINANCE_ALPHA: - case GL_LUMINANCE4_ALPHA4: - case GL_LUMINANCE6_ALPHA2: - case GL_LUMINANCE8_ALPHA8: - case GL_LUMINANCE12_ALPHA4: - case GL_LUMINANCE12_ALPHA12: - case GL_LUMINANCE16_ALPHA16: - case GL_COMPRESSED_LUMINANCE_ALPHA: - return &_mesa_texformat_al88; - - case GL_INTENSITY: - case GL_INTENSITY4: - case GL_INTENSITY8: - case GL_INTENSITY12: - case GL_INTENSITY16: - case GL_COMPRESSED_INTENSITY: + case PIPE_FORMAT_U_I8: return &_mesa_texformat_i8; - - case GL_YCBCR_MESA: - if (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE) - return &_mesa_texformat_ycbcr; - else - return &_mesa_texformat_ycbcr_rev; - - case GL_COMPRESSED_RGB_FXT1_3DFX: - return &_mesa_texformat_rgb_fxt1; - case GL_COMPRESSED_RGBA_FXT1_3DFX: - return &_mesa_texformat_rgba_fxt1; - - case GL_RGB_S3TC: - case GL_RGB4_S3TC: - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: + case PIPE_FORMAT_Z16_UNORM: + return &_mesa_texformat_z16; + case PIPE_FORMAT_Z32_UNORM: + return &_mesa_texformat_z32; + case PIPE_FORMAT_S8Z24_UNORM: + /* XXX fallthrough OK? */ + case PIPE_FORMAT_Z24S8_UNORM: + return &_mesa_texformat_z24_s8; + case PIPE_FORMAT_YCBCR: + return &_mesa_texformat_ycbcr; + case PIPE_FORMAT_YCBCR_REV: + return &_mesa_texformat_ycbcr_rev; + case PIPE_FORMAT_DXT1_RGB: return &_mesa_texformat_rgb_dxt1; - - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: + case PIPE_FORMAT_DXT1_RGBA: return &_mesa_texformat_rgba_dxt1; - - case GL_RGBA_S3TC: - case GL_RGBA4_S3TC: - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: + case PIPE_FORMAT_DXT3_RGBA: return &_mesa_texformat_rgba_dxt3; - - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: + case PIPE_FORMAT_DXT5_RGBA: return &_mesa_texformat_rgba_dxt5; + /* XXX add additional cases */ + default: + assert(0); + return NULL; + } +} - case GL_DEPTH_COMPONENT: - case GL_DEPTH_COMPONENT16: - case GL_DEPTH_COMPONENT24: - case GL_DEPTH_COMPONENT32: - return &_mesa_texformat_z16; - case GL_DEPTH_STENCIL_EXT: - case GL_DEPTH24_STENCIL8_EXT: - return &_mesa_texformat_z24_s8; +/** + * Called via ctx->Driver.chooseTextureFormat(). + */ +const struct gl_texture_format * +st_ChooseTextureFormat(GLcontext *ctx, GLint internalFormat, + GLenum format, GLenum type) +{ + enum pipe_format pFormat; - default: - fprintf(stderr, "unexpected texture format %s in %s\n", - _mesa_lookup_enum_by_nr(internalFormat), __FUNCTION__); + (void) format; + (void) type; + + pFormat = choose_format(ctx->st->pipe, internalFormat, PIPE_TEXTURE); + if (pFormat == PIPE_FORMAT_NONE) return NULL; - } - return NULL; /* never get here */ + return translate_gallium_format_to_mesa_format(pFormat); } diff --git a/src/mesa/state_tracker/st_framebuffer.c b/src/mesa/state_tracker/st_framebuffer.c index d46a9178b1..075e9d1bd6 100644 --- a/src/mesa/state_tracker/st_framebuffer.c +++ b/src/mesa/state_tracker/st_framebuffer.c @@ -186,7 +186,8 @@ st_notify_swapbuffers(struct st_framebuffer *stfb) if (ctx && ctx->DrawBuffer == &stfb->Base) { st_flush( ctx->st, - PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_SWAPBUFFERS); + PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_SWAPBUFFERS, + NULL ); } } diff --git a/src/mesa/state_tracker/st_public.h b/src/mesa/state_tracker/st_public.h index 3c397b126a..9d88ce9764 100644 --- a/src/mesa/state_tracker/st_public.h +++ b/src/mesa/state_tracker/st_public.h @@ -45,6 +45,7 @@ struct st_context; struct st_framebuffer; struct pipe_context; +struct pipe_fence_handle; struct pipe_surface; @@ -78,7 +79,9 @@ void st_make_current(struct st_context *st, struct st_framebuffer *draw, struct st_framebuffer *read); -void st_flush( struct st_context *st, uint pipeFlushFlags ); +void st_flush( struct st_context *st, uint pipeFlushFlags, + struct pipe_fence_handle **fence ); +void st_finish( struct st_context *st ); void st_notify_swapbuffers(struct st_framebuffer *stfb); void st_notify_swapbuffers_complete(struct st_framebuffer *stfb); diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index cbc6f84998..8e3235cc99 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -30,6 +30,8 @@ #include "st_texture.h" #include "enums.h" +#undef Elements /* fix re-defined macro warning */ + #include "pipe/p_state.h" #include "pipe/p_context.h" #include "pipe/p_defines.h" |