X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_atom_sampler.c;h=94231cf1946f2975b4217f0314516d2f512cf003;hb=8498cb4a45e8ed53a2ee2b35d3c2cbb9963e1756;hp=ec2bab20b54693db97a4140e35b63467b01a8cae;hpb=877128505431adaf817dc8069172ebe4a1cdf5d8;p=mesa.git diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c index ec2bab20b54..94231cf1946 100644 --- a/src/mesa/state_tracker/st_atom_sampler.c +++ b/src/mesa/state_tracker/st_atom_sampler.c @@ -36,6 +36,7 @@ #include "main/mtypes.h" #include "main/glformats.h" #include "main/samplerobj.h" +#include "main/teximage.h" #include "main/texobj.h" #include "st_context.h" @@ -133,7 +134,6 @@ convert_sampler(struct st_context *st, const struct gl_texture_object *texobj; struct gl_context *ctx = st->ctx; struct gl_sampler_object *msamp; - const struct gl_texture_image *teximg; GLenum texBaseFormat; texobj = ctx->Texture.Unit[texUnit]._Current; @@ -141,8 +141,7 @@ convert_sampler(struct st_context *st, texobj = _mesa_get_fallback_texture(ctx, TEXTURE_2D_INDEX); } - teximg = texobj->Image[0][texobj->BaseLevel]; - texBaseFormat = teximg ? teximg->_BaseFormat : GL_RGBA; + texBaseFormat = _mesa_texture_base_format(texobj); msamp = _mesa_get_samplerobj(ctx, texUnit); @@ -160,11 +159,8 @@ convert_sampler(struct st_context *st, sampler->lod_bias = ctx->Texture.Unit[texUnit].LodBias + msamp->LodBias; - sampler->min_lod = CLAMP(msamp->MinLod, - 0.0f, - (GLfloat) texobj->MaxLevel - texobj->BaseLevel); - sampler->max_lod = MIN2((GLfloat) texobj->MaxLevel - texobj->BaseLevel, - msamp->MaxLod); + sampler->min_lod = MAX2(msamp->MinLod, 0.0f); + sampler->max_lod = msamp->MaxLod; if (sampler->max_lod < sampler->min_lod) { /* The GL spec doesn't seem to specify what to do in this case. * Swap the values. @@ -182,15 +178,27 @@ convert_sampler(struct st_context *st, msamp->BorderColor.ui[3]) { const struct st_texture_object *stobj = st_texture_object_const(texobj); const GLboolean is_integer = texobj->_IsIntegerFormat; + const struct pipe_sampler_view *sv = NULL; union pipe_color_union border_color; + GLuint i; + + /* Just search for the first used view. We can do this because the + swizzle is per-texture, not per context. */ + /* XXX: clean that up to not use the sampler view at all */ + for (i = 0; i < stobj->num_sampler_views; ++i) { + if (stobj->sampler_views[i]) { + sv = stobj->sampler_views[i]; + break; + } + } - if (st->apply_texture_swizzle_to_border_color && stobj->sampler_view) { + if (st->apply_texture_swizzle_to_border_color && sv) { const unsigned char swz[4] = { - stobj->sampler_view->swizzle_r, - stobj->sampler_view->swizzle_g, - stobj->sampler_view->swizzle_b, - stobj->sampler_view->swizzle_a, + sv->swizzle_r, + sv->swizzle_g, + sv->swizzle_b, + sv->swizzle_a, }; st_translate_color(&msamp->BorderColor, @@ -237,11 +245,12 @@ update_shader_samplers(struct st_context *st, GLuint unit; GLbitfield samplers_used; const GLuint old_max = *num_samplers; + const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS]; samplers_used = prog->SamplersUsed; if (*num_samplers == 0 && samplers_used == 0x0) - return; + return; *num_samplers = 0; @@ -253,13 +262,11 @@ update_shader_samplers(struct st_context *st, const GLuint texUnit = prog->SamplerUnits[unit]; convert_sampler(st, sampler, texUnit); - + states[unit] = sampler; *num_samplers = unit + 1; - - cso_single_sampler(st->cso_context, shader_stage, unit, sampler); } else if (samplers_used != 0 || unit < old_max) { - cso_single_sampler(st->cso_context, shader_stage, unit, NULL); + states[unit] = NULL; } else { /* if we've reset all the old samplers and we have no more new ones */ @@ -267,7 +274,7 @@ update_shader_samplers(struct st_context *st, } } - cso_single_sampler_done(st->cso_context, shader_stage); + cso_set_samplers(st->cso_context, shader_stage, *num_samplers, states); } @@ -298,6 +305,22 @@ update_samplers(struct st_context *st) st->state.samplers[PIPE_SHADER_GEOMETRY], &st->state.num_samplers[PIPE_SHADER_GEOMETRY]); } + if (ctx->TessCtrlProgram._Current) { + update_shader_samplers(st, + PIPE_SHADER_TESS_CTRL, + &ctx->TessCtrlProgram._Current->Base, + ctx->Const.Program[MESA_SHADER_TESS_CTRL].MaxTextureImageUnits, + st->state.samplers[PIPE_SHADER_TESS_CTRL], + &st->state.num_samplers[PIPE_SHADER_TESS_CTRL]); + } + if (ctx->TessEvalProgram._Current) { + update_shader_samplers(st, + PIPE_SHADER_TESS_EVAL, + &ctx->TessEvalProgram._Current->Base, + ctx->Const.Program[MESA_SHADER_TESS_EVAL].MaxTextureImageUnits, + st->state.samplers[PIPE_SHADER_TESS_EVAL], + &st->state.num_samplers[PIPE_SHADER_TESS_EVAL]); + } }