/** Constant state objects */
struct pipe_blend_state *blend;
- struct pipe_sampler_state *fragment_samplers[PIPE_MAX_SAMPLERS];
- struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
- struct pipe_sampler_state *geometry_samplers[PIPE_MAX_GEOMETRY_SAMPLERS];
+ struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
struct pipe_depth_stencil_alpha_state *depth_stencil;
struct pipe_rasterizer_state *rasterizer;
struct sp_fragment_shader *fs;
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
- struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
- struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
- struct pipe_sampler_view *geometry_sampler_views[PIPE_MAX_GEOMETRY_SAMPLERS];
+ struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_GEOMETRY_SAMPLERS];
+
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
struct pipe_index_buffer index_buffer;
struct pipe_query_data_so_statistics so_stats;
unsigned num_primitives_generated;
- unsigned num_fragment_samplers;
- unsigned num_fragment_sampler_views;
- unsigned num_vertex_samplers;
- unsigned num_vertex_sampler_views;
- unsigned num_geometry_samplers;
- unsigned num_geometry_sampler_views;
+ unsigned num_samplers[PIPE_SHADER_TYPES];
+ unsigned num_sampler_views[PIPE_SHADER_TYPES];
+
unsigned num_vertex_buffers;
unsigned dirty; /**< Mask of SP_NEW_x flags */
/** TGSI exec things */
struct {
- struct sp_sampler_variant *geom_samplers_list[PIPE_MAX_GEOMETRY_SAMPLERS];
- struct sp_sampler_variant *vert_samplers_list[PIPE_MAX_VERTEX_SAMPLERS];
- struct sp_sampler_variant *frag_samplers_list[PIPE_MAX_SAMPLERS];
+ struct sp_sampler_variant *samplers_list[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
} tgsi;
struct tgsi_exec_machine *fs_machine;
assert(num <= PIPE_MAX_SAMPLERS);
/* Check for no-op */
- if (num == softpipe->num_fragment_samplers &&
- !memcmp(softpipe->fragment_samplers, sampler, num * sizeof(void *)))
+ if (num == softpipe->num_samplers[PIPE_SHADER_FRAGMENT] &&
+ !memcmp(softpipe->samplers[PIPE_SHADER_FRAGMENT], sampler, num * sizeof(void *)))
return;
draw_flush(softpipe->draw);
for (i = 0; i < num; ++i)
- softpipe->fragment_samplers[i] = sampler[i];
+ softpipe->samplers[PIPE_SHADER_FRAGMENT][i] = sampler[i];
for (i = num; i < PIPE_MAX_SAMPLERS; ++i)
- softpipe->fragment_samplers[i] = NULL;
+ softpipe->samplers[PIPE_SHADER_FRAGMENT][i] = NULL;
- softpipe->num_fragment_samplers = num;
+ softpipe->num_samplers[PIPE_SHADER_FRAGMENT] = num;
softpipe->dirty |= SP_NEW_SAMPLER;
}
assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS);
/* Check for no-op */
- if (num_samplers == softpipe->num_vertex_samplers &&
- !memcmp(softpipe->vertex_samplers, samplers, num_samplers * sizeof(void *)))
+ if (num_samplers == softpipe->num_samplers[PIPE_SHADER_VERTEX] &&
+ !memcmp(softpipe->samplers[PIPE_SHADER_VERTEX], samplers, num_samplers * sizeof(void *)))
return;
draw_flush(softpipe->draw);
for (i = 0; i < num_samplers; ++i)
- softpipe->vertex_samplers[i] = samplers[i];
+ softpipe->samplers[PIPE_SHADER_VERTEX][i] = samplers[i];
for (i = num_samplers; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
- softpipe->vertex_samplers[i] = NULL;
+ softpipe->samplers[PIPE_SHADER_VERTEX][i] = NULL;
- softpipe->num_vertex_samplers = num_samplers;
+ softpipe->num_samplers[PIPE_SHADER_VERTEX] = num_samplers;
draw_set_samplers(softpipe->draw,
- softpipe->vertex_samplers,
- softpipe->num_vertex_samplers);
+ softpipe->samplers[PIPE_SHADER_VERTEX],
+ softpipe->num_samplers[PIPE_SHADER_VERTEX]);
softpipe->dirty |= SP_NEW_SAMPLER;
}
assert(num_samplers <= PIPE_MAX_GEOMETRY_SAMPLERS);
/* Check for no-op */
- if (num_samplers == softpipe->num_geometry_samplers &&
- !memcmp(softpipe->geometry_samplers, samplers, num_samplers * sizeof(void *)))
+ if (num_samplers == softpipe->num_samplers[PIPE_SHADER_GEOMETRY] &&
+ !memcmp(softpipe->samplers[PIPE_SHADER_GEOMETRY], samplers, num_samplers * sizeof(void *)))
return;
draw_flush(softpipe->draw);
for (i = 0; i < num_samplers; ++i)
- softpipe->geometry_samplers[i] = samplers[i];
- for (i = num_samplers; i < PIPE_MAX_GEOMETRY_SAMPLERS; ++i)
- softpipe->geometry_samplers[i] = NULL;
+ softpipe->samplers[PIPE_SHADER_GEOMETRY][i] = samplers[i];
+ for (i = num_samplers; i < PIPE_MAX_SAMPLERS; ++i)
+ softpipe->samplers[PIPE_SHADER_GEOMETRY][i] = NULL;
- softpipe->num_geometry_samplers = num_samplers;
+ softpipe->num_samplers[PIPE_SHADER_GEOMETRY] = num_samplers;
softpipe->dirty |= SP_NEW_SAMPLER;
}
assert(num <= PIPE_MAX_SAMPLERS);
/* Check for no-op */
- if (num == softpipe->num_fragment_sampler_views &&
- !memcmp(softpipe->fragment_sampler_views, views,
+ if (num == softpipe->num_sampler_views[PIPE_SHADER_FRAGMENT] &&
+ !memcmp(softpipe->sampler_views[PIPE_SHADER_FRAGMENT], views,
num * sizeof(struct pipe_sampler_view *)))
return;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
- pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], view);
+ pipe_sampler_view_reference(&softpipe->sampler_views[PIPE_SHADER_FRAGMENT][i], view);
sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i], view);
}
- softpipe->num_fragment_sampler_views = num;
+ softpipe->num_sampler_views[PIPE_SHADER_FRAGMENT] = num;
softpipe->dirty |= SP_NEW_TEXTURE;
}
assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
/* Check for no-op */
- if (num == softpipe->num_vertex_sampler_views &&
- !memcmp(softpipe->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) {
+ if (num == softpipe->num_sampler_views[PIPE_SHADER_VERTEX] &&
+ !memcmp(softpipe->sampler_views[PIPE_SHADER_VERTEX],
+ views, num * sizeof(struct pipe_sampler_view *))) {
return;
}
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
- pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view);
+ pipe_sampler_view_reference(&softpipe->sampler_views[PIPE_SHADER_VERTEX][i], view);
sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_VERTEX][i], view);
}
- softpipe->num_vertex_sampler_views = num;
+ softpipe->num_sampler_views[PIPE_SHADER_VERTEX] = num;
draw_set_sampler_views(softpipe->draw,
- softpipe->vertex_sampler_views,
- softpipe->num_vertex_sampler_views);
+ softpipe->sampler_views[PIPE_SHADER_VERTEX],
+ softpipe->num_sampler_views[PIPE_SHADER_VERTEX]);
softpipe->dirty |= SP_NEW_TEXTURE;
}
assert(num <= PIPE_MAX_GEOMETRY_SAMPLERS);
/* Check for no-op */
- if (num == softpipe->num_geometry_sampler_views &&
- !memcmp(softpipe->geometry_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) {
+ if (num == softpipe->num_sampler_views[PIPE_SHADER_GEOMETRY] &&
+ !memcmp(softpipe->sampler_views[PIPE_SHADER_GEOMETRY], views, num * sizeof(struct pipe_sampler_view *))) {
return;
}
for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) {
struct pipe_sampler_view *view = i < num ? views[i] : NULL;
- pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], view);
+ pipe_sampler_view_reference(&softpipe->sampler_views[PIPE_SHADER_GEOMETRY][i], view);
sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i], view);
}
- softpipe->num_geometry_sampler_views = num;
+ softpipe->num_sampler_views[PIPE_SHADER_GEOMETRY] = num;
softpipe->dirty |= SP_NEW_TEXTURE;
}
}
-void
-softpipe_reset_sampler_variants(struct softpipe_context *softpipe)
+/**
+ * Reset the sampler variants for a shader stage (vert, frag, geom).
+ */
+static void
+reset_sampler_variants(struct softpipe_context *softpipe,
+ unsigned shader,
+ unsigned tgsi_shader,
+ int max_sampler)
{
int i;
+ for (i = 0; i <= max_sampler; i++) {
+ if (softpipe->samplers[shader][i]) {
+ softpipe->tgsi.samplers_list[shader][i] =
+ get_sampler_variant(i,
+ sp_sampler(softpipe->samplers[shader][i]),
+ softpipe->sampler_views[shader][i],
+ tgsi_shader);
+
+ sp_sampler_variant_bind_view(softpipe->tgsi.samplers_list[shader][i],
+ softpipe->tex_cache[shader][i],
+ softpipe->sampler_views[shader][i]);
+ }
+ }
+}
+
+
+void
+softpipe_reset_sampler_variants(struct softpipe_context *softpipe)
+{
/* It's a bit hard to build these samplers ahead of time -- don't
* really know which samplers are going to be used for vertex and
* fragment programs.
*/
- for (i = 0; i <= softpipe->vs->max_sampler; i++) {
- if (softpipe->vertex_samplers[i]) {
- softpipe->tgsi.vert_samplers_list[i] =
- get_sampler_variant( i,
- sp_sampler(softpipe->vertex_samplers[i]),
- softpipe->vertex_sampler_views[i],
- TGSI_PROCESSOR_VERTEX );
-
- sp_sampler_variant_bind_view( softpipe->tgsi.vert_samplers_list[i],
- softpipe->tex_cache[PIPE_SHADER_VERTEX][i],
- softpipe->vertex_sampler_views[i] );
- }
- }
- if (softpipe->gs) {
- for (i = 0; i <= softpipe->gs->max_sampler; i++) {
- if (softpipe->geometry_samplers[i]) {
- softpipe->tgsi.geom_samplers_list[i] =
- get_sampler_variant(
- i,
- sp_sampler(softpipe->geometry_samplers[i]),
- softpipe->geometry_sampler_views[i],
- TGSI_PROCESSOR_GEOMETRY );
-
- sp_sampler_variant_bind_view(
- softpipe->tgsi.geom_samplers_list[i],
- softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i],
- softpipe->geometry_sampler_views[i] );
- }
- }
- }
+ /* XXX note: PIPE_SHADER_x != TGSI_PROCESSOR_x (fix that someday) */
+ reset_sampler_variants(softpipe,
+ PIPE_SHADER_VERTEX,
+ TGSI_PROCESSOR_VERTEX,
+ softpipe->vs->max_sampler);
- for (i = 0; i <= softpipe->fs_variant->info.file_max[TGSI_FILE_SAMPLER]; i++) {
- if (softpipe->fragment_samplers[i]) {
- assert(softpipe->fragment_sampler_views[i]->texture);
- softpipe->tgsi.frag_samplers_list[i] =
- get_sampler_variant( i,
- sp_sampler(softpipe->fragment_samplers[i]),
- softpipe->fragment_sampler_views[i],
- TGSI_PROCESSOR_FRAGMENT );
-
- sp_sampler_variant_bind_view( softpipe->tgsi.frag_samplers_list[i],
- softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i],
- softpipe->fragment_sampler_views[i] );
- }
+ reset_sampler_variants(softpipe,
+ PIPE_SHADER_FRAGMENT,
+ TGSI_PROCESSOR_FRAGMENT,
+ softpipe->fs_variant->info.file_max[TGSI_FILE_SAMPLER]);
+
+ if (softpipe->gs) {
+ reset_sampler_variants(softpipe,
+ PIPE_SHADER_GEOMETRY,
+ TGSI_PROCESSOR_GEOMETRY,
+ softpipe->gs->max_sampler);
}
}
+
static void
softpipe_delete_sampler_state(struct pipe_context *pipe,
void *sampler)