diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index eb2efc8..0efa553 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1346,6 +1346,8 @@ struct gl_sampler_object /** Is the texture object complete with respect to this sampler? */ GLboolean _CompleteTexture; + + GLuint Generation; }; diff --git a/src/mesa/main/samplerobj.c b/src/mesa/main/samplerobj.c index f7774fd..5c065c4 100644 --- a/src/mesa/main/samplerobj.c +++ b/src/mesa/main/samplerobj.c @@ -135,6 +135,7 @@ _mesa_init_sampler_object(struct gl_sampler_object *sampObj, GLuint name) sampObj->sRGBDecode = GL_DECODE_EXT; sampObj->CubeMapSeamless = GL_FALSE; sampObj->DepthMode = 0; + sampObj->Generation = 0; } @@ -734,6 +735,7 @@ _mesa_SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param) break; case GL_TRUE: /* state change - we do nothing special at this time */ + sampObj->Generation++; break; case INVALID_PNAME: _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterf(pname=%s)\n", @@ -823,6 +825,7 @@ _mesa_SamplerParameteriv(GLuint sampler, GLenum pname, const GLint *params) break; case GL_TRUE: /* state change - we do nothing special at this time */ + sampObj->Generation++; break; case INVALID_PNAME: _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameteriv(pname=%s)\n", @@ -907,6 +910,7 @@ _mesa_SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *params) break; case GL_TRUE: /* state change - we do nothing special at this time */ + sampObj->Generation++; break; case INVALID_PNAME: _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterfv(pname=%s)\n", @@ -989,6 +993,7 @@ _mesa_SamplerParameterIiv(GLuint sampler, GLenum pname, const GLint *params) break; case GL_TRUE: /* state change - we do nothing special at this time */ + sampObj->Generation++; break; case INVALID_PNAME: _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIiv(pname=%s)\n", @@ -1072,6 +1077,7 @@ _mesa_SamplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *params) break; case GL_TRUE: /* state change - we do nothing special at this time */ + sampObj->Generation++; break; case INVALID_PNAME: _mesa_error(ctx, GL_INVALID_ENUM, "glSamplerParameterIuiv(pname=%s)\n", diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c index 4b9dcb5..dc01e4d 100644 --- a/src/mesa/main/texparam.c +++ b/src/mesa/main/texparam.c @@ -613,6 +613,8 @@ _mesa_TexParameterf(GLenum target, GLenum pname, GLfloat param) } } + if (need_update) + texObj->Sampler.Generation++; if (ctx->Driver.TexParameter && need_update) { ctx->Driver.TexParameter(ctx, target, texObj, pname, ¶m); } @@ -673,6 +675,8 @@ _mesa_TexParameterfv(GLenum target, GLenum pname, const GLfloat *params) need_update = set_tex_parameterf(ctx, texObj, pname, params); } + if (need_update) + texObj->Sampler.Generation++; if (ctx->Driver.TexParameter && need_update) { ctx->Driver.TexParameter(ctx, target, texObj, pname, params); } @@ -716,6 +720,8 @@ _mesa_TexParameteri(GLenum target, GLenum pname, GLint param) } } + if (need_update) + texObj->Sampler.Generation++; if (ctx->Driver.TexParameter && need_update) { GLfloat fparam = (GLfloat) param; ctx->Driver.TexParameter(ctx, target, texObj, pname, &fparam); @@ -765,6 +771,8 @@ _mesa_TexParameteriv(GLenum target, GLenum pname, const GLint *params) /* this will generate an error if pname is illegal */ need_update = set_tex_parameteri(ctx, texObj, pname, params); } + if (need_update) + texObj->Sampler.Generation++; if (ctx->Driver.TexParameter && need_update) { GLfloat fparams[4]; @@ -801,6 +809,7 @@ _mesa_TexParameterIiv(GLenum target, GLenum pname, const GLint *params) FLUSH_VERTICES(ctx, _NEW_TEXTURE); /* set the integer-valued border color */ COPY_4V(texObj->Sampler.BorderColor.i, params); + texObj->Sampler.Generation++; break; default: _mesa_TexParameteriv(target, pname, params); @@ -831,6 +840,7 @@ _mesa_TexParameterIuiv(GLenum target, GLenum pname, const GLuint *params) FLUSH_VERTICES(ctx, _NEW_TEXTURE); /* set the unsigned integer-valued border color */ COPY_4V(texObj->Sampler.BorderColor.ui, params); + texObj->Sampler.Generation++; break; default: _mesa_TexParameteriv(target, pname, (const GLint *) params); diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index ccbd548..25cff41 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -127,12 +127,13 @@ static void convert_sampler(struct st_context *st, struct gl_texture_object *texobj; struct gl_sampler_object *msamp; + msamp = _mesa_get_samplerobj(st->ctx, texUnit); + texobj = st->ctx->Texture.Unit[texUnit]._Current; if (!texobj) { texobj = st_get_default_texture(st); } - msamp = _mesa_get_samplerobj(st->ctx, texUnit); sampler->wrap_s = gl_wrap_xlate(msamp->WrapS); sampler->wrap_t = gl_wrap_xlate(msamp->WrapT); sampler->wrap_r = gl_wrap_xlate(msamp->WrapR); @@ -225,21 +226,34 @@ update_fragment_samplers(struct st_context *st) { struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; GLuint su; - + static int num_calls, num_avoids; st->state.num_samplers = 0; + // num_calls++; /* loop over sampler units (aka tex image units) */ for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { struct pipe_sampler_state *sampler = st->state.samplers + su; - memset(sampler, 0, sizeof(*sampler)); - if (fprog->Base.SamplersUsed & (1 << su)) { GLuint texUnit; + GLboolean need_update = GL_TRUE; + struct gl_sampler_object *msamp; texUnit = fprog->Base.SamplerUnits[su]; + msamp = _mesa_get_samplerobj(st->ctx, texUnit); - convert_sampler(st, sampler, texUnit); + if (st->state.mesa_sampler[su] == msamp) + if (st->state.sampler_generation[su] == msamp->Generation) { + need_update = GL_FALSE; + // num_avoids++; + } + + if (need_update) { + memset(sampler, 0, sizeof(*sampler)); + convert_sampler(st, sampler, texUnit); + st->state.mesa_sampler[su] = msamp; + st->state.sampler_generation[su] = msamp->Generation; + } st->state.num_samplers = su + 1; @@ -249,10 +263,15 @@ update_fragment_samplers(struct st_context *st) else { /*printf("%s su=%u null\n", __FUNCTION__, su);*/ cso_single_sampler(st->cso_context, su, NULL); + st->state.mesa_sampler[su] = NULL; + st->state.sampler_generation[su] = 0; } } cso_single_sampler_done(st->cso_context); + + // if (!(num_calls % 100)) + // fprintf(stderr,"num calls %d %d\n", num_calls, num_avoids); } static void diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index c6fc318..c6f4a5e 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -89,7 +89,11 @@ struct st_context struct pipe_blend_state blend; struct pipe_depth_stencil_alpha_state depth_stencil; struct pipe_rasterizer_state rasterizer; + GLuint sampler_generation[PIPE_MAX_SAMPLERS]; + struct gl_sampler_object *mesa_sampler[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; + GLuint vretex_sampler_generation[PIPE_MAX_SAMPLERS]; + struct gl_sampler_object *mesa_vertex_sampler[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS]; struct pipe_clip_state clip; struct {