Commit 18308802 authored by Keith Whitwell's avatar Keith Whitwell
Browse files

Merge branch 'gallium-sampler-view' into gallium-resources

Conflicts:
	src/gallium/include/pipe/p_context.h
	src/mesa/state_tracker/st_atom_texture.c
	src/mesa/state_tracker/st_cb_bitmap.c
	src/mesa/state_tracker/st_cb_drawpixels.c
	src/mesa/state_tracker/st_cb_texture.c
	src/mesa/state_tracker/st_context.c
	src/mesa/state_tracker/st_context.h
	src/mesa/state_tracker/st_texture.h
parents 90b4045f 47bfbd45
......@@ -119,6 +119,7 @@ C_SOURCES = \
util/u_mm.c \
util/u_rect.c \
util/u_ringbuffer.c \
util/u_sampler.c \
util/u_simple_shaders.c \
util/u_snprintf.c \
util/u_surface.c \
......@@ -126,12 +127,13 @@ C_SOURCES = \
util/u_tile.c \
util/u_timed_winsys.c \
util/u_upload_mgr.c \
util/u_simple_screen.c \
vl/vl_bitstream_parser.c \
vl/vl_mpeg12_mc_renderer.c \
vl/vl_compositor.c \
vl/vl_csc.c \
vl/vl_shader_build.c \
util/u_simple_screen.c
# Disabling until pipe-video branch gets merged in
#vl/vl_bitstream_parser.c \
#vl/vl_mpeg12_mc_renderer.c \
#vl/vl_compositor.c \
#vl/vl_csc.c \
#vl/vl_shader_build.c \
target-helpers/wrap_screen.c
GALLIVM_SOURCES = \
......
......@@ -162,6 +162,7 @@ source = [
'util/u_mm.c',
'util/u_rect.c',
'util/u_ringbuffer.c',
'util/u_sampler.c',
'util/u_simple_shaders.c',
'util/u_snprintf.c',
'util/u_surface.c',
......@@ -170,11 +171,12 @@ source = [
'util/u_timed_winsys.c',
'util/u_upload_mgr.c',
'util/u_simple_screen.c',
'vl/vl_bitstream_parser.c',
'vl/vl_mpeg12_mc_renderer.c',
'vl/vl_compositor.c',
'vl/vl_csc.c',
'vl/vl_shader_build.c',
# Disabling until pipe-video branch gets merged in
#'vl/vl_bitstream_parser.c',
#'vl/vl_mpeg12_mc_renderer.c',
#'vl/vl_compositor.c',
#'vl/vl_csc.c',
#'vl/vl_shader_build.c',
'target-helpers/wrap_screen.c',
]
......
......@@ -37,7 +37,9 @@
#include "pipe/p_state.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "tgsi/tgsi_parse.h"
#include "cso_cache/cso_context.h"
......@@ -70,16 +72,20 @@ struct cso_context {
void *vertex_samplers_saved[PIPE_MAX_VERTEX_SAMPLERS];
struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
uint nr_fragment_sampler_views;
struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
uint nr_textures;
struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS];
uint nr_vertex_textures;
uint nr_vertex_sampler_views;
struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
uint nr_textures_saved;
struct pipe_texture *textures_saved[PIPE_MAX_SAMPLERS];
uint nr_fragment_sampler_views_saved;
struct pipe_sampler_view *fragment_sampler_views_saved[PIPE_MAX_SAMPLERS];
uint nr_vertex_textures_saved;
struct pipe_texture *vertex_textures_saved[PIPE_MAX_SAMPLERS];
uint nr_vertex_sampler_views_saved;
struct pipe_sampler_view *vertex_sampler_views_saved[PIPE_MAX_VERTEX_SAMPLERS];
/** Current and saved state.
* The saved state is used as a 1-deep stack.
......@@ -295,11 +301,13 @@ void cso_release_all( struct cso_context *ctx )
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->textures[i], NULL);
pipe_texture_reference(&ctx->textures_saved[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i], NULL);
}
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
pipe_texture_reference(&ctx->vertex_textures_saved[i], NULL);
pipe_sampler_view_reference(&ctx->vertex_sampler_views[i], NULL);
pipe_sampler_view_reference(&ctx->vertex_sampler_views_saved[i], NULL);
}
free_framebuffer_state(&ctx->fb);
......@@ -624,12 +632,27 @@ enum pipe_error cso_set_sampler_textures( struct cso_context *ctx,
ctx->nr_textures = count;
for (i = 0; i < count; i++)
for (i = 0; i < count; i++) {
struct pipe_sampler_view templ, *view;
u_sampler_view_default_template(&templ,
textures[i],
textures[i]->format);
view = ctx->pipe->create_sampler_view(ctx->pipe,
textures[i],
&templ);
pipe_texture_reference(&ctx->textures[i], textures[i]);
for ( ; i < PIPE_MAX_SAMPLERS; i++)
pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], view);
}
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->textures[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL);
}
ctx->pipe->set_fragment_sampler_textures(ctx->pipe, count, textures);
ctx->pipe->set_fragment_sampler_views(ctx->pipe,
count,
ctx->fragment_sampler_views);
return PIPE_OK;
}
......@@ -641,7 +664,11 @@ void cso_save_sampler_textures( struct cso_context *ctx )
ctx->nr_textures_saved = ctx->nr_textures;
for (i = 0; i < ctx->nr_textures; i++) {
assert(!ctx->textures_saved[i]);
assert(!ctx->fragment_sampler_views_saved[i]);
pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]);
pipe_sampler_view_reference(&ctx->fragment_sampler_views_saved[i],
ctx->fragment_sampler_views[i]);
}
}
......@@ -655,75 +682,24 @@ void cso_restore_sampler_textures( struct cso_context *ctx )
pipe_texture_reference(&ctx->textures[i], NULL);
ctx->textures[i] = ctx->textures_saved[i];
ctx->textures_saved[i] = NULL;
}
for ( ; i < PIPE_MAX_SAMPLERS; i++)
pipe_texture_reference(&ctx->textures[i], NULL);
ctx->pipe->set_fragment_sampler_textures(ctx->pipe, ctx->nr_textures, ctx->textures);
ctx->nr_textures_saved = 0;
}
enum pipe_error
cso_set_vertex_sampler_textures(struct cso_context *ctx,
uint count,
struct pipe_texture **textures)
{
uint i;
ctx->nr_vertex_textures = count;
for (i = 0; i < count; i++) {
pipe_texture_reference(&ctx->vertex_textures[i], textures[i]);
}
for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL);
ctx->fragment_sampler_views[i] = ctx->fragment_sampler_views_saved[i];
ctx->fragment_sampler_views_saved[i] = NULL;
}
ctx->pipe->set_vertex_sampler_textures(ctx->pipe, count, textures);
return PIPE_OK;
}
void
cso_save_vertex_sampler_textures(struct cso_context *ctx)
{
uint i;
ctx->nr_vertex_textures_saved = ctx->nr_vertex_textures;
for (i = 0; i < ctx->nr_vertex_textures; i++) {
assert(!ctx->vertex_textures_saved[i]);
pipe_texture_reference(&ctx->vertex_textures_saved[i], ctx->vertex_textures[i]);
}
}
void
cso_restore_vertex_sampler_textures(struct cso_context *ctx)
{
uint i;
ctx->nr_vertex_textures = ctx->nr_vertex_textures_saved;
for (i = 0; i < ctx->nr_vertex_textures; i++) {
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
ctx->vertex_textures[i] = ctx->vertex_textures_saved[i];
ctx->vertex_textures_saved[i] = NULL;
}
for ( ; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->vertex_textures[i], NULL);
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&ctx->textures[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_sampler_views[i], NULL);
}
ctx->pipe->set_vertex_sampler_textures(ctx->pipe,
ctx->nr_vertex_textures,
ctx->vertex_textures);
ctx->pipe->set_fragment_sampler_views(ctx->pipe,
ctx->nr_textures,
ctx->fragment_sampler_views);
ctx->nr_vertex_textures_saved = 0;
ctx->nr_textures_saved = 0;
}
enum pipe_error cso_set_depth_stencil_alpha(struct cso_context *ctx,
const struct pipe_depth_stencil_alpha_state *templ)
{
......@@ -1261,3 +1237,122 @@ void cso_restore_vertex_elements(struct cso_context *ctx)
}
ctx->velements_saved = NULL;
}
/* fragment sampler view state */
void
cso_set_fragment_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views)
{
uint i;
for (i = 0; i < count; i++) {
pipe_sampler_view_reference(&cso->fragment_sampler_views[i], views[i]);
}
for (; i < cso->nr_fragment_sampler_views; i++) {
pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL);
}
cso->pipe->set_fragment_sampler_views(cso->pipe,
MAX2(count, cso->nr_fragment_sampler_views),
cso->fragment_sampler_views);
cso->nr_fragment_sampler_views = count;
}
void
cso_save_fragment_sampler_views(struct cso_context *cso)
{
uint i;
cso->nr_fragment_sampler_views_saved = cso->nr_fragment_sampler_views;
for (i = 0; i < cso->nr_fragment_sampler_views; i++) {
assert(!cso->fragment_sampler_views_saved[i]);
pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i],
cso->fragment_sampler_views[i]);
}
}
void
cso_restore_fragment_sampler_views(struct cso_context *cso)
{
uint i;
for (i = 0; i < cso->nr_fragment_sampler_views_saved; i++) {
pipe_sampler_view_reference(&cso->fragment_sampler_views[i], cso->fragment_sampler_views_saved[i]);
pipe_sampler_view_reference(&cso->fragment_sampler_views_saved[i], NULL);
}
for (; i < cso->nr_fragment_sampler_views; i++) {
pipe_sampler_view_reference(&cso->fragment_sampler_views[i], NULL);
}
cso->pipe->set_fragment_sampler_views(cso->pipe,
MAX2(cso->nr_fragment_sampler_views, cso->nr_fragment_sampler_views_saved),
cso->fragment_sampler_views);
cso->nr_fragment_sampler_views = cso->nr_fragment_sampler_views_saved;
cso->nr_fragment_sampler_views_saved = 0;
}
/* vertex sampler view state */
void
cso_set_vertex_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views)
{
uint i;
for (i = 0; i < count; i++) {
pipe_sampler_view_reference(&cso->vertex_sampler_views[i], views[i]);
}
for (; i < cso->nr_vertex_sampler_views; i++) {
pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL);
}
cso->pipe->set_vertex_sampler_views(cso->pipe,
MAX2(count, cso->nr_vertex_sampler_views),
cso->vertex_sampler_views);
cso->nr_vertex_sampler_views = count;
}
void
cso_save_vertex_sampler_views(struct cso_context *cso)
{
uint i;
cso->nr_vertex_sampler_views_saved = cso->nr_vertex_sampler_views;
for (i = 0; i < cso->nr_vertex_sampler_views; i++) {
assert(!cso->vertex_sampler_views_saved[i]);
pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i],
cso->vertex_sampler_views[i]);
}
}
void
cso_restore_vertex_sampler_views(struct cso_context *cso)
{
uint i;
for (i = 0; i < cso->nr_vertex_sampler_views_saved; i++) {
pipe_sampler_view_reference(&cso->vertex_sampler_views[i], cso->vertex_sampler_views_saved[i]);
pipe_sampler_view_reference(&cso->vertex_sampler_views_saved[i], NULL);
}
for (; i < cso->nr_vertex_sampler_views; i++) {
pipe_sampler_view_reference(&cso->vertex_sampler_views[i], NULL);
}
cso->pipe->set_vertex_sampler_views(cso->pipe,
MAX2(cso->nr_vertex_sampler_views, cso->nr_vertex_sampler_views_saved),
cso->vertex_sampler_views);
cso->nr_vertex_sampler_views = cso->nr_vertex_sampler_views_saved;
cso->nr_vertex_sampler_views_saved = 0;
}
......@@ -111,17 +111,6 @@ void cso_save_sampler_textures( struct cso_context *cso );
void cso_restore_sampler_textures( struct cso_context *cso );
enum pipe_error
cso_set_vertex_sampler_textures(struct cso_context *cso,
uint count,
struct pipe_texture **textures);
void
cso_save_vertex_sampler_textures(struct cso_context *cso);
void
cso_restore_vertex_sampler_textures(struct cso_context *cso);
enum pipe_error cso_set_vertex_elements(struct cso_context *ctx,
unsigned count,
const struct pipe_vertex_element *states);
......@@ -198,6 +187,34 @@ void
cso_restore_clip(struct cso_context *cso);
/* fragment sampler view state */
void
cso_set_fragment_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views);
void
cso_save_fragment_sampler_views(struct cso_context *cso);
void
cso_restore_fragment_sampler_views(struct cso_context *cso);
/* vertex sampler view state */
void
cso_set_vertex_sampler_views(struct cso_context *cso,
uint count,
struct pipe_sampler_view **views);
void
cso_save_vertex_sampler_views(struct cso_context *cso);
void
cso_restore_vertex_sampler_views(struct cso_context *cso);
#ifdef __cplusplus
}
#endif
......
......@@ -40,6 +40,7 @@
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_dump.h"
......@@ -88,8 +89,9 @@ struct aaline_stage
void *sampler_cso;
struct pipe_texture *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_textures;
uint num_sampler_views;
/*
......@@ -98,7 +100,7 @@ struct aaline_stage
struct aaline_fragment_shader *fs;
struct {
void *sampler[PIPE_MAX_SAMPLERS];
struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
} state;
/*
......@@ -111,8 +113,9 @@ struct aaline_stage
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned,
void **);
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
struct pipe_texture **);
void (*driver_set_sampler_views)(struct pipe_context *,
unsigned,
struct pipe_sampler_view **);
struct pipe_context *pipe;
};
......@@ -394,6 +397,7 @@ aaline_create_texture(struct aaline_stage *aaline)
struct pipe_context *pipe = aaline->pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_texture texTemp;
struct pipe_sampler_view viewTempl;
uint level;
memset(&texTemp, 0, sizeof(texTemp));
......@@ -408,6 +412,16 @@ aaline_create_texture(struct aaline_stage *aaline)
if (!aaline->texture)
return FALSE;
u_sampler_view_default_template(&viewTempl,
aaline->texture,
aaline->texture->format);
aaline->sampler_view = pipe->create_sampler_view(pipe,
aaline->texture,
&viewTempl);
if (!aaline->sampler_view) {
return FALSE;
}
/* Fill in mipmap images.
* Basically each level is solid opaque, except for the outermost
* texels which are zero. Special case the 1x1 and 2x2 levels.
......@@ -669,16 +683,16 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header)
/* how many samplers? */
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
num_samplers = MAX2(aaline->num_textures, aaline->num_samplers);
num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers);
num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1);
aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso;
pipe_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit],
aaline->texture);
pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit],
aaline->sampler_view);
draw->suspend_flushing = TRUE;
aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler);
aaline->driver_set_sampler_textures(pipe, num_samplers, aaline->state.texture);
aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views);
draw->suspend_flushing = FALSE;
/* now really draw first line */
......@@ -702,8 +716,9 @@ aaline_flush(struct draw_stage *stage, unsigned flags)
aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs);
aaline->driver_bind_sampler_states(pipe, aaline->num_samplers,
aaline->state.sampler);
aaline->driver_set_sampler_textures(pipe, aaline->num_textures,
aaline->state.texture);
aaline->driver_set_sampler_views(pipe,
aaline->num_sampler_views,
aaline->state.sampler_views);
draw->suspend_flushing = FALSE;
draw->extra_shader_outputs.slot = 0;
......@@ -724,7 +739,7 @@ aaline_destroy(struct draw_stage *stage)
uint i;
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&aaline->state.texture[i], NULL);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
}
if (aaline->sampler_cso)
......@@ -733,6 +748,10 @@ aaline_destroy(struct draw_stage *stage)
if (aaline->texture)
pipe_texture_reference(&aaline->texture, NULL);
if (aaline->sampler_view) {
pipe_sampler_view_reference(&aaline->sampler_view, NULL);
}
draw_free_temp_verts( stage );
FREE( stage );
......@@ -844,23 +863,24 @@ aaline_bind_sampler_states(struct pipe_context *pipe,
static void
aaline_set_sampler_textures(struct pipe_context *pipe,
unsigned num, struct pipe_texture **texture)
aaline_set_sampler_views(struct pipe_context *pipe,
unsigned num,
struct pipe_sampler_view **views)
{
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
uint i;
/* save current */
for (i = 0; i < num; i++) {
pipe_texture_reference(&aaline->state.texture[i], texture[i]);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]);
}
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
pipe_texture_reference(&aaline->state.texture[i], NULL);
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
}
aaline->num_textures = num;
aaline->num_sampler_views = num;
/* pass-through */
aaline->driver_set_sampler_textures(aaline->pipe, num, texture);
aaline->driver_set_sampler_views(aaline->pipe, num, views);
}
......@@ -898,7 +918,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
aaline->driver_delete_fs_state = pipe->delete_fs_state;
aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
aaline->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views;
/* override the driver's functions */
pipe->create_fs_state = aaline_create_fs_state;
......@@ -906,7 +926,7 @@ draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe)
pipe->delete_fs_state = aaline_delete_fs_state;
pipe->bind_fragment_sampler_states = aaline_bind_sampler_states;
pipe->set_fragment_sampler_textures = aaline_set_sampler_textures;
pipe->set_fragment_sampler_views = aaline_set_sampler_views;
/* Install once everything is known to be OK:
*/
......
......@@ -42,6 +42,7 @@
#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_sampler.h"
#include "tgsi/tgsi_transform.h"
#include "tgsi/tgsi_dump.h"
......@@ -75,8 +76,9 @@ struct pstip_stage
void *sampler_cso;
struct pipe_texture *texture;
struct pipe_sampler_view *sampler_view;
uint num_samplers;
uint num_textures;
uint num_sampler_views;
/*
* Currently bound state
......@@ -84,7 +86,7 @@ struct pstip_stage
struct pstip_fragment_shader *fs;
struct {
void *samplers[PIPE_MAX_SAMPLERS];
struct pipe_texture *textures[PIPE_MAX_SAMPLERS];
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
const struct pipe_poly_stipple *stipple;
} state;