st/mesa: merge fragment/vertex sampler update code
Reviewed-by: José Fonseca <jfonseca@vmware.com>
This commit is contained in:
@@ -195,88 +195,82 @@ convert_sampler(struct st_context *st,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the gallium driver's sampler state for fragment, vertex or
|
||||
* geometry shader stage.
|
||||
*/
|
||||
static void
|
||||
update_vertex_samplers(struct st_context *st)
|
||||
update_shader_samplers(struct st_context *st,
|
||||
unsigned shader_stage,
|
||||
const struct gl_program *prog,
|
||||
unsigned max_units,
|
||||
struct pipe_sampler_state *samplers,
|
||||
unsigned *num_samplers)
|
||||
{
|
||||
const struct gl_context *ctx = st->ctx;
|
||||
struct gl_vertex_program *vprog = ctx->VertexProgram._Current;
|
||||
GLuint su;
|
||||
GLuint samplers_used = vprog->Base.SamplersUsed;
|
||||
const GLuint old_max = st->state.num_vertex_samplers;
|
||||
GLuint unit;
|
||||
GLbitfield samplers_used;
|
||||
const GLuint old_max = *num_samplers;
|
||||
|
||||
if (st->state.num_vertex_samplers == 0 && vprog->Base.SamplersUsed == 0)
|
||||
samplers_used = prog->SamplersUsed;
|
||||
|
||||
if (*num_samplers == 0 && samplers_used == 0x0)
|
||||
return;
|
||||
|
||||
st->state.num_vertex_samplers = 0;
|
||||
*num_samplers = 0;
|
||||
|
||||
/* loop over sampler units (aka tex image units) */
|
||||
for (su = 0; su < ctx->Const.MaxVertexTextureImageUnits; su++, samplers_used >>= 1) {
|
||||
struct pipe_sampler_state *sampler = st->state.vertex_samplers + su;
|
||||
for (unit = 0; unit < max_units; unit++, samplers_used >>= 1) {
|
||||
struct pipe_sampler_state *sampler = samplers + unit;
|
||||
|
||||
if (samplers_used & 1) {
|
||||
GLuint texUnit = vprog->Base.SamplerUnits[su];
|
||||
const GLuint texUnit = prog->SamplerUnits[unit];
|
||||
|
||||
convert_sampler(st, sampler, texUnit);
|
||||
|
||||
st->state.num_vertex_samplers = su + 1;
|
||||
*num_samplers = unit + 1;
|
||||
|
||||
cso_single_sampler(st->cso_context, PIPE_SHADER_VERTEX, su, sampler);
|
||||
cso_single_sampler(st->cso_context, shader_stage, unit, sampler);
|
||||
}
|
||||
else if (samplers_used != 0 || su < old_max) {
|
||||
cso_single_sampler(st->cso_context, PIPE_SHADER_VERTEX, su, NULL);
|
||||
} else {
|
||||
/* if we've reset all the old samplers and we have no more new ones */
|
||||
break;
|
||||
else if (samplers_used != 0 || unit < old_max) {
|
||||
cso_single_sampler(st->cso_context, shader_stage, unit, NULL);
|
||||
}
|
||||
}
|
||||
cso_single_sampler_done(st->cso_context, PIPE_SHADER_VERTEX);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_fragment_samplers(struct st_context *st)
|
||||
{
|
||||
const struct gl_context *ctx = st->ctx;
|
||||
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
|
||||
GLuint su;
|
||||
GLuint samplers_used = fprog->Base.SamplersUsed;
|
||||
const GLuint old_max = st->state.num_fragment_samplers;
|
||||
|
||||
if (st->state.num_fragment_samplers == 0 && fprog->Base.SamplersUsed == 0)
|
||||
return;
|
||||
|
||||
st->state.num_fragment_samplers = 0;
|
||||
|
||||
/* loop over sampler units (aka tex image units) */
|
||||
for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++, samplers_used >>= 1) {
|
||||
struct pipe_sampler_state *sampler = st->state.fragment_samplers + su;
|
||||
|
||||
if (samplers_used & 1) {
|
||||
GLuint texUnit = fprog->Base.SamplerUnits[su];
|
||||
|
||||
convert_sampler(st, sampler, texUnit);
|
||||
|
||||
st->state.num_fragment_samplers = su + 1;
|
||||
|
||||
cso_single_sampler(st->cso_context, PIPE_SHADER_FRAGMENT, su, sampler);
|
||||
}
|
||||
else if (samplers_used != 0 || su < old_max) {
|
||||
cso_single_sampler(st->cso_context, PIPE_SHADER_FRAGMENT, su, NULL);
|
||||
} else {
|
||||
else {
|
||||
/* if we've reset all the old samplers and we have no more new ones */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cso_single_sampler_done(st->cso_context, PIPE_SHADER_FRAGMENT);
|
||||
cso_single_sampler_done(st->cso_context, shader_stage);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_samplers(struct st_context *st)
|
||||
{
|
||||
update_fragment_samplers(st);
|
||||
update_vertex_samplers(st);
|
||||
const struct gl_context *ctx = st->ctx;
|
||||
|
||||
update_shader_samplers(st,
|
||||
PIPE_SHADER_FRAGMENT,
|
||||
&ctx->FragmentProgram._Current->Base,
|
||||
ctx->Const.MaxTextureImageUnits,
|
||||
st->state.fragment_samplers,
|
||||
&st->state.num_fragment_samplers);
|
||||
|
||||
update_shader_samplers(st,
|
||||
PIPE_SHADER_VERTEX,
|
||||
&ctx->VertexProgram._Current->Base,
|
||||
ctx->Const.MaxVertexTextureImageUnits,
|
||||
st->state.vertex_samplers,
|
||||
&st->state.num_vertex_samplers);
|
||||
|
||||
/*
|
||||
update_shader_samplers(st,
|
||||
PIPE_SHADER_GEOMETRY,
|
||||
&ctx->GeometryProgram._Current->Base,
|
||||
ctx->Const.MaxGeometryTextureImageUnits,
|
||||
st->state.geometry_samplers,
|
||||
&st->state.num_geometry_samplers);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user