diff options
Diffstat (limited to 'src/gallium/drivers/failover')
-rw-r--r-- | src/gallium/drivers/failover/fo_context.c | 36 | ||||
-rw-r--r-- | src/gallium/drivers/failover/fo_context.h | 23 | ||||
-rw-r--r-- | src/gallium/drivers/failover/fo_state.c | 202 | ||||
-rw-r--r-- | src/gallium/drivers/failover/fo_state_emit.c | 34 |
4 files changed, 185 insertions, 110 deletions
diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c index 2ccc5d3e605..9515cd8938c 100644 --- a/src/gallium/drivers/failover/fo_context.c +++ b/src/gallium/drivers/failover/fo_context.c @@ -27,7 +27,6 @@ #include "pipe/p_defines.h" -#include "util/u_simple_screen.h" #include "util/u_memory.h" #include "pipe/p_context.h" @@ -40,7 +39,7 @@ static void failover_destroy( struct pipe_context *pipe ) { struct failover_context *failover = failover_context( pipe ); - free( failover ); + FREE( failover ); } @@ -52,8 +51,9 @@ void failover_fail_over( struct failover_context *failover ) static void failover_draw_elements( struct pipe_context *pipe, - struct pipe_buffer *indexBuffer, + struct pipe_resource *indexResource, unsigned indexSize, + int indexBias, unsigned prim, unsigned start, unsigned count) @@ -71,8 +71,9 @@ static void failover_draw_elements( struct pipe_context *pipe, */ if (failover->mode == FO_HW) { failover->hw->draw_elements( failover->hw, - indexBuffer, + indexResource, indexSize, + indexBias, prim, start, count ); @@ -88,8 +89,9 @@ static void failover_draw_elements( struct pipe_context *pipe, } failover->sw->draw_elements( failover->sw, - indexBuffer, + indexResource, indexSize, + indexBias, prim, start, count ); @@ -106,30 +108,19 @@ static void failover_draw_elements( struct pipe_context *pipe, static void failover_draw_arrays( struct pipe_context *pipe, unsigned prim, unsigned start, unsigned count) { - failover_draw_elements(pipe, NULL, 0, prim, start, count); + failover_draw_elements(pipe, NULL, 0, 0, prim, start, count); } static unsigned int -failover_is_texture_referenced( struct pipe_context *_pipe, - struct pipe_texture *texture, - unsigned face, unsigned level) +failover_is_resource_referenced( struct pipe_context *_pipe, + struct pipe_resource *resource, + unsigned face, unsigned level) { struct failover_context *failover = failover_context( _pipe ); struct pipe_context *pipe = (failover->mode == FO_HW) ? failover->hw : failover->sw; - return pipe->is_texture_referenced(pipe, texture, face, level); -} - -static unsigned int -failover_is_buffer_referenced( struct pipe_context *_pipe, - struct pipe_buffer *buf) -{ - struct failover_context *failover = failover_context( _pipe ); - struct pipe_context *pipe = (failover->mode == FO_HW) ? - failover->hw : failover->sw; - - return pipe->is_buffer_referenced(pipe, buf); + return pipe->is_resource_referenced(pipe, resource, face, level); } struct pipe_context *failover_create( struct pipe_context *hw, @@ -176,8 +167,7 @@ struct pipe_context *failover_create( struct pipe_context *hw, #endif failover->pipe.flush = hw->flush; - failover->pipe.is_texture_referenced = failover_is_texture_referenced; - failover->pipe.is_buffer_referenced = failover_is_buffer_referenced; + failover->pipe.is_resource_referenced = failover_is_resource_referenced; failover->dirty = 0; diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h index bb1a168ea7a..88ae5ad60d5 100644 --- a/src/gallium/drivers/failover/fo_context.h +++ b/src/gallium/drivers/failover/fo_context.h @@ -47,7 +47,7 @@ #define FO_NEW_ALPHA_TEST 0x100 #define FO_NEW_DEPTH_STENCIL 0x200 #define FO_NEW_SAMPLER 0x400 -#define FO_NEW_TEXTURE 0x800 +#define FO_NEW_SAMPLER_VIEW 0x800 #define FO_NEW_VERTEX 0x2000 #define FO_NEW_VERTEX_SHADER 0x4000 #define FO_NEW_BLEND_COLOR 0x8000 @@ -65,6 +65,13 @@ struct fo_state { void *sw_state; void *hw_state; }; + +struct fo_sampler_view { + struct pipe_sampler_view base; + struct pipe_sampler_view *sw; + struct pipe_sampler_view *hw; +}; + struct failover_context { struct pipe_context pipe; /**< base class */ @@ -78,6 +85,7 @@ struct failover_context { const struct fo_state *rasterizer; const struct fo_state *fragment_shader; const struct fo_state *vertex_shader; + const struct fo_state *vertex_elements; struct pipe_blend_color blend_color; struct pipe_stencil_ref stencil_ref; @@ -85,26 +93,25 @@ struct failover_context { struct pipe_framebuffer_state framebuffer; 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_buffers[PIPE_MAX_ATTRIBS]; - struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; uint num_vertex_buffers; - uint num_vertex_elements; void *sw_sampler_state[PIPE_MAX_SAMPLERS]; void *hw_sampler_state[PIPE_MAX_SAMPLERS]; void *sw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; void *hw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS]; + struct fo_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; + struct fo_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; + unsigned num_fragment_sampler_views; + unsigned num_vertex_sampler_views; + unsigned dirty; unsigned num_samplers; unsigned num_vertex_samplers; - unsigned num_textures; - unsigned num_vertex_textures; unsigned mode; struct pipe_context *hw; @@ -127,7 +134,7 @@ failover_context( struct pipe_context *pipe ) void failover_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *buf); + struct pipe_resource *resource); #endif /* FO_CONTEXT_H */ diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c index 970606a3f50..272e683067e 100644 --- a/src/gallium/drivers/failover/fo_state.c +++ b/src/gallium/drivers/failover/fo_state.c @@ -29,6 +29,7 @@ */ #include "util/u_inlines.h" +#include "util/u_memory.h" #include "fo_context.h" @@ -53,7 +54,7 @@ static void * failover_create_blend_state( struct pipe_context *pipe, const struct pipe_blend_state *blend ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_blend_state(failover->sw, blend); @@ -85,7 +86,7 @@ failover_delete_blend_state( struct pipe_context *pipe, failover->hw->delete_blend_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); } static void @@ -129,7 +130,7 @@ static void * failover_create_depth_stencil_state(struct pipe_context *pipe, const struct pipe_depth_stencil_alpha_state *templ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_depth_stencil_alpha_state(failover->sw, templ); @@ -161,7 +162,7 @@ failover_delete_depth_stencil_state(struct pipe_context *pipe, failover->hw->delete_depth_stencil_alpha_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); } static void @@ -181,7 +182,7 @@ static void * failover_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_fs_state(failover->sw, templ); @@ -212,14 +213,14 @@ failover_delete_fs_state(struct pipe_context *pipe, failover->hw->delete_fs_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); } static void * failover_create_vs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_vs_state(failover->sw, templ); @@ -252,12 +253,55 @@ failover_delete_vs_state(struct pipe_context *pipe, failover->hw->delete_vs_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); +} + + + +static void * +failover_create_vertex_elements_state( struct pipe_context *pipe, + unsigned count, + const struct pipe_vertex_element *velems ) +{ + struct fo_state *state = MALLOC(sizeof(struct fo_state)); + struct failover_context *failover = failover_context(pipe); + + state->sw_state = failover->sw->create_vertex_elements_state(failover->sw, count, velems); + state->hw_state = failover->hw->create_vertex_elements_state(failover->hw, count, velems); + + return state; +} + +static void +failover_bind_vertex_elements_state(struct pipe_context *pipe, + void *velems ) +{ + struct failover_context *failover = failover_context(pipe); + struct fo_state *state = (struct fo_state*)velems; + + failover->vertex_elements = state; + failover->dirty |= FO_NEW_VERTEX_ELEMENT; + failover->sw->bind_vertex_elements_state( failover->sw, velems ); + failover->hw->bind_vertex_elements_state( failover->hw, velems ); +} + +static void +failover_delete_vertex_elements_state( struct pipe_context *pipe, + void *velems ) +{ + struct fo_state *state = (struct fo_state*)velems; + struct failover_context *failover = failover_context(pipe); + + failover->sw->delete_vertex_elements_state(failover->sw, state->sw_state); + failover->hw->delete_vertex_elements_state(failover->hw, state->hw_state); + state->sw_state = 0; + state->hw_state = 0; + FREE(state); } static void failover_set_polygon_stipple( struct pipe_context *pipe, - const struct pipe_poly_stipple *stipple ) + const struct pipe_poly_stipple *stipple ) { struct failover_context *failover = failover_context(pipe); @@ -272,7 +316,7 @@ static void * failover_create_rasterizer_state(struct pipe_context *pipe, const struct pipe_rasterizer_state *templ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_rasterizer_state(failover->sw, templ); @@ -305,7 +349,7 @@ failover_delete_rasterizer_state(struct pipe_context *pipe, failover->hw->delete_rasterizer_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); } @@ -326,7 +370,7 @@ static void * failover_create_sampler_state(struct pipe_context *pipe, const struct pipe_sampler_state *templ) { - struct fo_state *state = malloc(sizeof(struct fo_state)); + struct fo_state *state = MALLOC(sizeof(struct fo_state)); struct failover_context *failover = failover_context(pipe); state->sw_state = failover->sw->create_sampler_state(failover->sw, templ); @@ -400,64 +444,100 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler) failover->hw->delete_sampler_state(failover->hw, state->hw_state); state->sw_state = 0; state->hw_state = 0; - free(state); + FREE(state); } +static struct pipe_sampler_view * +failover_create_sampler_view(struct pipe_context *pipe, + struct pipe_resource *texture, + const struct pipe_sampler_view *templ) +{ + struct fo_sampler_view *view = MALLOC(sizeof(struct fo_sampler_view)); + struct failover_context *failover = failover_context(pipe); + + view->sw = failover->sw->create_sampler_view(failover->sw, texture, templ); + view->hw = failover->hw->create_sampler_view(failover->hw, texture, templ); + + view->base = *templ; + view->base.reference.count = 1; + view->base.texture = NULL; + pipe_resource_reference(&view->base.texture, texture); + view->base.context = pipe; + + return &view->base; +} + +static void +failover_sampler_view_destroy(struct pipe_context *pipe, + struct pipe_sampler_view *view) +{ + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)view; + struct failover_context *failover = failover_context(pipe); + + failover->sw->sampler_view_destroy(failover->sw, fo_view->sw); + failover->hw->sampler_view_destroy(failover->hw, fo_view->hw); + + pipe_resource_reference(&fo_view->base.texture, NULL); + FREE(fo_view); +} + static void -failover_set_fragment_sampler_textures(struct pipe_context *pipe, - unsigned num, - struct pipe_texture **texture) +failover_set_fragment_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_SAMPLERS]; uint i; assert(num <= PIPE_MAX_SAMPLERS); /* Check for no-op */ - if (num == failover->num_textures && - !memcmp(failover->texture, texture, num * sizeof(struct pipe_texture *))) + if (num == failover->num_fragment_sampler_views && + !memcmp(failover->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) return; - for (i = 0; i < num; i++) - pipe_texture_reference((struct pipe_texture **) &failover->texture[i], - texture[i]); - for (i = num; i < failover->num_textures; i++) - pipe_texture_reference((struct pipe_texture **) &failover->texture[i], - NULL); - failover->dirty |= FO_NEW_TEXTURE; - failover->num_textures = num; - failover->sw->set_fragment_sampler_textures( failover->sw, num, texture ); - failover->hw->set_fragment_sampler_textures( failover->hw, num, texture ); + for (i = 0; i < num; i++) { + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; + } + for (i = num; i < failover->num_fragment_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; + failover->num_fragment_sampler_views = num; + failover->hw->set_fragment_sampler_views(failover->hw, num, hw_views); } static void -failover_set_vertex_sampler_textures(struct pipe_context *pipe, - unsigned num_textures, - struct pipe_texture **textures) +failover_set_vertex_sampler_views(struct pipe_context *pipe, + unsigned num, + struct pipe_sampler_view **views) { struct failover_context *failover = failover_context(pipe); + struct pipe_sampler_view *hw_views[PIPE_MAX_VERTEX_SAMPLERS]; uint i; - assert(num_textures <= PIPE_MAX_VERTEX_SAMPLERS); + assert(num <= PIPE_MAX_VERTEX_SAMPLERS); /* Check for no-op */ - if (num_textures == failover->num_vertex_textures && - !memcmp(failover->vertex_textures, textures, num_textures * sizeof(struct pipe_texture *))) { + if (num == failover->num_vertex_sampler_views && + !memcmp(failover->vertex_sampler_views, views, num * sizeof(struct pipe_sampler_view *))) { return; } - for (i = 0; i < num_textures; i++) { - pipe_texture_reference((struct pipe_texture **)&failover->vertex_textures[i], - textures[i]); - } - for (i = num_textures; i < failover->num_vertex_textures; i++) { - pipe_texture_reference((struct pipe_texture **)&failover->vertex_textures[i], - NULL); + for (i = 0; i < num; i++) { + struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i]; + + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], views[i]); + hw_views[i] = fo_view->hw; } - failover->dirty |= FO_NEW_TEXTURE; - failover->num_vertex_textures = num_textures; - failover->sw->set_vertex_sampler_textures(failover->sw, num_textures, textures); - failover->hw->set_vertex_sampler_textures(failover->hw, num_textures, textures); + for (i = num; i < failover->num_vertex_sampler_views; i++) + pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], NULL); + failover->dirty |= FO_NEW_SAMPLER_VIEW; + failover->num_vertex_sampler_views = num; + failover->hw->set_vertex_sampler_views(failover->hw, num, hw_views); } @@ -490,34 +570,18 @@ failover_set_vertex_buffers(struct pipe_context *pipe, } -static void -failover_set_vertex_elements(struct pipe_context *pipe, - unsigned count, - const struct pipe_vertex_element *vertex_elements) -{ - struct failover_context *failover = failover_context(pipe); - - memcpy(failover->vertex_elements, vertex_elements, - count * sizeof(vertex_elements[0])); - - failover->dirty |= FO_NEW_VERTEX_ELEMENT; - failover->num_vertex_elements = count; - failover->sw->set_vertex_elements( failover->sw, count, vertex_elements ); - failover->hw->set_vertex_elements( failover->hw, count, vertex_elements ); -} - void failover_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index, - struct pipe_buffer *buf) + struct pipe_resource *res) { struct failover_context *failover = failover_context(pipe); assert(shader < PIPE_SHADER_TYPES); assert(index == 0); - failover->sw->set_constant_buffer(failover->sw, shader, index, buf); - failover->hw->set_constant_buffer(failover->hw, shader, index, buf); + failover->sw->set_constant_buffer(failover->sw, shader, index, res); + failover->hw->set_constant_buffer(failover->hw, shader, index, res); } @@ -543,6 +607,9 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.create_vs_state = failover_create_vs_state; failover->pipe.bind_vs_state = failover_bind_vs_state; failover->pipe.delete_vs_state = failover_delete_vs_state; + failover->pipe.create_vertex_elements_state = failover_create_vertex_elements_state; + failover->pipe.bind_vertex_elements_state = failover_bind_vertex_elements_state; + failover->pipe.delete_vertex_elements_state = failover_delete_vertex_elements_state; failover->pipe.set_blend_color = failover_set_blend_color; failover->pipe.set_stencil_ref = failover_set_stencil_ref; @@ -550,10 +617,11 @@ failover_init_state_functions( struct failover_context *failover ) failover->pipe.set_framebuffer_state = failover_set_framebuffer_state; failover->pipe.set_polygon_stipple = failover_set_polygon_stipple; failover->pipe.set_scissor_state = failover_set_scissor_state; - failover->pipe.set_fragment_sampler_textures = failover_set_fragment_sampler_textures; - failover->pipe.set_vertex_sampler_textures = failover_set_vertex_sampler_textures; + failover->pipe.set_fragment_sampler_views = failover_set_fragment_sampler_views; + failover->pipe.set_vertex_sampler_views = failover_set_vertex_sampler_views; failover->pipe.set_viewport_state = failover_set_viewport_state; failover->pipe.set_vertex_buffers = failover_set_vertex_buffers; - failover->pipe.set_vertex_elements = failover_set_vertex_elements; failover->pipe.set_constant_buffer = failover_set_constant_buffer; + failover->pipe.create_sampler_view = failover_create_sampler_view; + failover->pipe.sampler_view_destroy = failover_sampler_view_destroy; } diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c index 5c000808425..42bd6929a7f 100644 --- a/src/gallium/drivers/failover/fo_state_emit.c +++ b/src/gallium/drivers/failover/fo_state_emit.c @@ -81,6 +81,10 @@ failover_state_emit( struct failover_context *failover ) failover->sw->bind_vs_state( failover->sw, failover->vertex_shader->sw_state ); + if (failover->dirty & FO_NEW_VERTEX_ELEMENT) + failover->sw->bind_vertex_elements_state( failover->sw, + failover->vertex_elements->sw_state ); + if (failover->dirty & FO_NEW_STIPPLE) failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple ); @@ -102,12 +106,24 @@ failover_state_emit( struct failover_context *failover ) failover->sw_vertex_sampler_state); } - if (failover->dirty & FO_NEW_TEXTURE) { - failover->sw->set_fragment_sampler_textures( failover->sw, failover->num_textures, - failover->texture ); - failover->sw->set_vertex_sampler_textures(failover->sw, - failover->num_vertex_textures, - failover->vertex_textures); + if (failover->dirty & FO_NEW_SAMPLER_VIEW) { + struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS]; + struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS]; + uint i; + + for (i = 0; i < failover->num_fragment_sampler_views; i++) { + fragment_views[i] = failover->fragment_sampler_views[i]->sw; + } + failover->sw->set_fragment_sampler_views(failover->sw, + failover->num_fragment_sampler_views, + fragment_views); + + for (i = 0; i < failover->num_vertex_sampler_views; i++) { + vertex_views[i] = failover->vertex_sampler_views[i]->sw; + } + failover->sw->set_vertex_sampler_views(failover->sw, + failover->num_vertex_sampler_views, + vertex_views); } if (failover->dirty & FO_NEW_VERTEX_BUFFER) { @@ -116,11 +132,5 @@ failover_state_emit( struct failover_context *failover ) failover->vertex_buffers ); } - if (failover->dirty & FO_NEW_VERTEX_ELEMENT) { - failover->sw->set_vertex_elements( failover->sw, - failover->num_vertex_elements, - failover->vertex_elements ); - } - failover->dirty = 0; } |