llvmpipe: Port vertex sampler support from softpipe.
Just enough boilerplate code to avoid segfaulting.
This commit is contained in:
@@ -118,6 +118,11 @@ static void llvmpipe_destroy( struct pipe_context *pipe )
|
||||
pipe_texture_reference(&llvmpipe->texture[i], NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
lp_destroy_tex_tile_cache(llvmpipe->vertex_tex_cache[i]);
|
||||
pipe_texture_reference(&llvmpipe->vertex_textures[i], NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < Elements(llvmpipe->constants); i++) {
|
||||
if (llvmpipe->constants[i].buffer) {
|
||||
pipe_buffer_reference(&llvmpipe->constants[i].buffer, NULL);
|
||||
@@ -145,6 +150,11 @@ llvmpipe_is_texture_referenced( struct pipe_context *pipe,
|
||||
llvmpipe->framebuffer.zsbuf->texture == texture)
|
||||
return PIPE_REFERENCED_FOR_WRITE;
|
||||
}
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
if (llvmpipe->vertex_tex_cache[i] &&
|
||||
llvmpipe->vertex_tex_cache[i]->texture == texture)
|
||||
return PIPE_REFERENCED_FOR_READ;
|
||||
}
|
||||
|
||||
return PIPE_UNREFERENCED;
|
||||
}
|
||||
@@ -181,6 +191,7 @@ llvmpipe_create( struct pipe_screen *screen )
|
||||
|
||||
llvmpipe->pipe.create_sampler_state = llvmpipe_create_sampler_state;
|
||||
llvmpipe->pipe.bind_fragment_sampler_states = llvmpipe_bind_sampler_states;
|
||||
llvmpipe->pipe.bind_vertex_sampler_states = llvmpipe_bind_vertex_sampler_states;
|
||||
llvmpipe->pipe.delete_sampler_state = llvmpipe_delete_sampler_state;
|
||||
|
||||
llvmpipe->pipe.create_depth_stencil_alpha_state = llvmpipe_create_depth_stencil_state;
|
||||
@@ -206,6 +217,7 @@ llvmpipe_create( struct pipe_screen *screen )
|
||||
llvmpipe->pipe.set_polygon_stipple = llvmpipe_set_polygon_stipple;
|
||||
llvmpipe->pipe.set_scissor_state = llvmpipe_set_scissor_state;
|
||||
llvmpipe->pipe.set_fragment_sampler_textures = llvmpipe_set_sampler_textures;
|
||||
llvmpipe->pipe.set_vertex_sampler_textures = llvmpipe_set_vertex_sampler_textures;
|
||||
llvmpipe->pipe.set_viewport_state = llvmpipe_set_viewport_state;
|
||||
|
||||
llvmpipe->pipe.set_vertex_buffers = llvmpipe_set_vertex_buffers;
|
||||
@@ -234,13 +246,15 @@ llvmpipe_create( struct pipe_screen *screen )
|
||||
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++)
|
||||
llvmpipe->tex_cache[i] = lp_create_tex_tile_cache( screen );
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
|
||||
llvmpipe->vertex_tex_cache[i] = lp_create_tex_tile_cache(screen);
|
||||
|
||||
|
||||
/* vertex shader samplers */
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
llvmpipe->tgsi.vert_samplers[i].base.get_samples = lp_get_samples;
|
||||
llvmpipe->tgsi.vert_samplers[i].processor = TGSI_PROCESSOR_VERTEX;
|
||||
llvmpipe->tgsi.vert_samplers[i].cache = llvmpipe->tex_cache[i];
|
||||
llvmpipe->tgsi.vert_samplers[i].cache = llvmpipe->vertex_tex_cache[i];
|
||||
llvmpipe->tgsi.vert_samplers_list[i] = &llvmpipe->tgsi.vert_samplers[i];
|
||||
}
|
||||
|
||||
@@ -260,7 +274,7 @@ llvmpipe_create( struct pipe_screen *screen )
|
||||
goto fail;
|
||||
|
||||
draw_texture_samplers(llvmpipe->draw,
|
||||
PIPE_MAX_SAMPLERS,
|
||||
PIPE_MAX_VERTEX_SAMPLERS,
|
||||
(struct tgsi_sampler **)
|
||||
llvmpipe->tgsi.vert_samplers_list);
|
||||
|
||||
|
@@ -55,6 +55,7 @@ struct llvmpipe_context {
|
||||
/** Constant state objects */
|
||||
const struct pipe_blend_state *blend;
|
||||
const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_sampler_state *vertex_samplers[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
const struct pipe_depth_stencil_alpha_state *depth_stencil;
|
||||
const struct pipe_rasterizer_state *rasterizer;
|
||||
struct lp_fragment_shader *fs;
|
||||
@@ -68,12 +69,15 @@ struct llvmpipe_context {
|
||||
struct pipe_poly_stipple poly_stipple;
|
||||
struct pipe_scissor_state scissor;
|
||||
struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
|
||||
struct pipe_texture *vertex_textures[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
struct pipe_viewport_state viewport;
|
||||
struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
|
||||
struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
|
||||
|
||||
unsigned num_samplers;
|
||||
unsigned num_textures;
|
||||
unsigned num_vertex_samplers;
|
||||
unsigned num_vertex_textures;
|
||||
unsigned num_vertex_elements;
|
||||
unsigned num_vertex_buffers;
|
||||
|
||||
@@ -136,6 +140,7 @@ struct llvmpipe_context {
|
||||
|
||||
unsigned tex_timestamp;
|
||||
struct llvmpipe_tex_tile_cache *tex_cache[PIPE_MAX_SAMPLERS];
|
||||
struct llvmpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS];
|
||||
|
||||
unsigned no_rast : 1;
|
||||
|
||||
|
@@ -59,7 +59,9 @@ llvmpipe_get_param(struct pipe_screen *screen, int param)
|
||||
case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
|
||||
return PIPE_MAX_SAMPLERS;
|
||||
case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
|
||||
return 0;
|
||||
return PIPE_MAX_VERTEX_SAMPLERS;
|
||||
case PIPE_CAP_MAX_COMBINED_SAMPLERS:
|
||||
return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
|
||||
case PIPE_CAP_NPOT_TEXTURES:
|
||||
return 1;
|
||||
case PIPE_CAP_TWO_SIDED_STENCIL:
|
||||
|
@@ -126,6 +126,10 @@ void *
|
||||
llvmpipe_create_sampler_state(struct pipe_context *,
|
||||
const struct pipe_sampler_state *);
|
||||
void llvmpipe_bind_sampler_states(struct pipe_context *, unsigned, void **);
|
||||
void
|
||||
llvmpipe_bind_vertex_sampler_states(struct pipe_context *,
|
||||
unsigned num_samplers,
|
||||
void **samplers);
|
||||
void llvmpipe_delete_sampler_state(struct pipe_context *, void *);
|
||||
|
||||
void *
|
||||
@@ -172,6 +176,11 @@ void llvmpipe_set_sampler_textures( struct pipe_context *,
|
||||
unsigned num,
|
||||
struct pipe_texture ** );
|
||||
|
||||
void
|
||||
llvmpipe_set_vertex_sampler_textures(struct pipe_context *,
|
||||
unsigned num_textures,
|
||||
struct pipe_texture **);
|
||||
|
||||
void llvmpipe_set_viewport_state( struct pipe_context *,
|
||||
const struct pipe_viewport_state * );
|
||||
|
||||
|
@@ -198,10 +198,14 @@ update_tgsi_samplers( struct llvmpipe_context *llvmpipe )
|
||||
unsigned i;
|
||||
|
||||
/* vertex shader samplers */
|
||||
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
|
||||
llvmpipe->tgsi.vert_samplers[i].sampler = llvmpipe->sampler[i];
|
||||
llvmpipe->tgsi.vert_samplers[i].texture = llvmpipe->texture[i];
|
||||
llvmpipe->tgsi.frag_samplers[i].base.get_samples = lp_get_samples;
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
llvmpipe->tgsi.vert_samplers[i].sampler = llvmpipe->vertex_samplers[i];
|
||||
llvmpipe->tgsi.vert_samplers[i].texture = llvmpipe->vertex_textures[i];
|
||||
llvmpipe->tgsi.vert_samplers[i].base.get_samples = lp_get_samples;
|
||||
}
|
||||
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
lp_tex_tile_cache_validate_texture( llvmpipe->vertex_tex_cache[i] );
|
||||
}
|
||||
|
||||
/* fragment shader samplers */
|
||||
|
@@ -77,6 +77,34 @@ llvmpipe_bind_sampler_states(struct pipe_context *pipe,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_bind_vertex_sampler_states(struct pipe_context *pipe,
|
||||
unsigned num_samplers,
|
||||
void **samplers)
|
||||
{
|
||||
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
||||
unsigned i;
|
||||
|
||||
assert(num_samplers <= PIPE_MAX_VERTEX_SAMPLERS);
|
||||
|
||||
/* Check for no-op */
|
||||
if (num_samplers == llvmpipe->num_vertex_samplers &&
|
||||
!memcmp(llvmpipe->vertex_samplers, samplers, num_samplers * sizeof(void *)))
|
||||
return;
|
||||
|
||||
draw_flush(llvmpipe->draw);
|
||||
|
||||
for (i = 0; i < num_samplers; ++i)
|
||||
llvmpipe->vertex_samplers[i] = samplers[i];
|
||||
for (i = num_samplers; i < PIPE_MAX_VERTEX_SAMPLERS; ++i)
|
||||
llvmpipe->vertex_samplers[i] = NULL;
|
||||
|
||||
llvmpipe->num_vertex_samplers = num_samplers;
|
||||
|
||||
llvmpipe->dirty |= LP_NEW_SAMPLER;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_set_sampler_textures(struct pipe_context *pipe,
|
||||
unsigned num, struct pipe_texture **texture)
|
||||
@@ -116,6 +144,37 @@ llvmpipe_set_sampler_textures(struct pipe_context *pipe,
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_set_vertex_sampler_textures(struct pipe_context *pipe,
|
||||
unsigned num_textures,
|
||||
struct pipe_texture **textures)
|
||||
{
|
||||
struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
|
||||
uint i;
|
||||
|
||||
assert(num_textures <= PIPE_MAX_VERTEX_SAMPLERS);
|
||||
|
||||
/* Check for no-op */
|
||||
if (num_textures == llvmpipe->num_vertex_textures &&
|
||||
!memcmp(llvmpipe->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) {
|
||||
return;
|
||||
}
|
||||
|
||||
draw_flush(llvmpipe->draw);
|
||||
|
||||
for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) {
|
||||
struct pipe_texture *tex = i < num_textures ? textures[i] : NULL;
|
||||
|
||||
pipe_texture_reference(&llvmpipe->vertex_textures[i], tex);
|
||||
lp_tex_tile_cache_set_texture(llvmpipe->vertex_tex_cache[i], tex);
|
||||
}
|
||||
|
||||
llvmpipe->num_vertex_textures = num_textures;
|
||||
|
||||
llvmpipe->dirty |= LP_NEW_TEXTURE;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
llvmpipe_delete_sampler_state(struct pipe_context *pipe,
|
||||
void *sampler)
|
||||
|
Reference in New Issue
Block a user