diff options
Diffstat (limited to 'src/gallium/auxiliary/util/u_blitter.h')
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.h | 139 |
1 files changed, 102 insertions, 37 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index f6e3ce4874e..f9f96f25c77 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -27,6 +27,8 @@ #ifndef U_BLITTER_H #define U_BLITTER_H +#include "util/u_framebuffer.h" +#include "util/u_inlines.h" #include "util/u_memory.h" #include "pipe/p_state.h" @@ -38,9 +40,48 @@ extern "C" { struct pipe_context; +enum blitter_attrib_type { + UTIL_BLITTER_ATTRIB_NONE, + UTIL_BLITTER_ATTRIB_COLOR, + UTIL_BLITTER_ATTRIB_TEXCOORD +}; + struct blitter_context { + /** + * Draw a rectangle. + * + * \param x1 An X coordinate of the top-left corner. + * \param y1 A Y coordinate of the top-left corner. + * \param x2 An X coordinate of the bottom-right corner. + * \param y2 A Y coordinate of the bottom-right corner. + * \param depth A depth which the rectangle is rendered at. + * + * \param type Semantics of the attributes "attrib". + * If type is UTIL_BLITTER_ATTRIB_NONE, ignore them. + * If type is UTIL_BLITTER_ATTRIB_COLOR, the attributes + * make up a constant RGBA color, and should go to the COLOR0 + * varying slot of a fragment shader. + * If type is UTIL_BLITTER_ATTRIB_TEXCOORD, {a1, a2} and + * {a3, a4} specify top-left and bottom-right texture + * coordinates of the rectangle, respectively, and should go + * to the GENERIC0 varying slot of a fragment shader. + * + * \param attrib See type. + * + * \note A driver may optionally override this callback to implement + * a specialized hardware path for drawing a rectangle, e.g. using + * a rectangular point sprite. + */ + void (*draw_rectangle)(struct blitter_context *blitter, + unsigned x1, unsigned y1, unsigned x2, unsigned y2, + float depth, + enum blitter_attrib_type type, + const float attrib[4]); + /* Private members, really. */ + struct pipe_context *pipe; /**< pipe context */ + void *saved_blend_state; /**< blend state */ void *saved_dsa_state; /**< depth stencil alpha state */ void *saved_velem_state; /**< vertex elements state */ @@ -72,6 +113,15 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe); */ void util_blitter_destroy(struct blitter_context *blitter); +/** + * Return the pipe context associated with a blitter context. + */ +static INLINE +struct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter) +{ + return blitter->pipe; +} + /* * These CSOs must be saved before any of the following functions is called: * - blend state @@ -112,52 +162,56 @@ void util_blitter_clear(struct blitter_context *blitter, * - fragment sampler states * - fragment sampler textures */ -void util_blitter_copy(struct blitter_context *blitter, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - struct pipe_surface *src, - unsigned srcx, unsigned srcy, - unsigned width, unsigned height, - boolean ignore_stencil); +void util_blitter_copy_region(struct blitter_context *blitter, + struct pipe_resource *dst, + struct pipe_subresource subdst, + unsigned dstx, unsigned dsty, unsigned dstz, + struct pipe_resource *src, + struct pipe_subresource subsrc, + unsigned srcx, unsigned srcy, unsigned srcz, + unsigned width, unsigned height, + boolean ignore_stencil); /** - * Fill a region of a surface with a constant value. - * - * If the surface cannot be rendered to or it's a depth-stencil format, - * a software fallback path is taken. + * Clear a region of a (color) surface to a constant value. * * These states must be saved in the blitter in addition to the state objects * already required to be saved: * - framebuffer state */ -void util_blitter_fill(struct blitter_context *blitter, - struct pipe_surface *dst, - unsigned dstx, unsigned dsty, - unsigned width, unsigned height, - unsigned value); +void util_blitter_clear_render_target(struct blitter_context *blitter, + struct pipe_surface *dst, + const float *rgba, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); /** - * Copy all pixels from one surface to another. + * Clear a region of a depth-stencil surface, both stencil and depth + * or only one of them if this is a combined depth-stencil surface. * - * The rules are the same as in util_blitter_copy with the addition that - * surfaces must have the same size. + * These states must be saved in the blitter in addition to the state objects + * already required to be saved: + * - framebuffer state */ -static INLINE -void util_blitter_copy_surface(struct blitter_context *blitter, - struct pipe_surface *dst, - struct pipe_surface *src, - boolean ignore_stencil) -{ - assert(dst->width == src->width && dst->height == src->height); - - util_blitter_copy(blitter, dst, 0, 0, src, 0, 0, src->width, src->height, - ignore_stencil); -} - +void util_blitter_clear_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dst, + unsigned clear_flags, + double depth, + unsigned stencil, + unsigned dstx, unsigned dsty, + unsigned width, unsigned height); + +void util_blitter_flush_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *dstsurf); + +void util_blitter_custom_depth_stencil(struct blitter_context *blitter, + struct pipe_surface *zsurf, + struct pipe_surface *cbsurf, + void *dsa_stage, float depth); /* The functions below should be used to save currently bound constant state * objects inside a driver. The objects are automatically restored at the end - * of the util_blitter_{clear, fill, copy, copy_surface} functions and then + * of the util_blitter_{clear, copy_region, fill_region} functions and then * forgotten. * * CSOs not listed here are not affected by util_blitter. */ @@ -213,9 +267,10 @@ void util_blitter_save_vertex_shader(struct blitter_context *blitter, static INLINE void util_blitter_save_framebuffer(struct blitter_context *blitter, - struct pipe_framebuffer_state *state) + const struct pipe_framebuffer_state *state) { - blitter->saved_fb_state = *state; + blitter->saved_fb_state.nr_cbufs = 0; /* It's ~0 now, meaning it's unsaved. */ + util_copy_framebuffer_state(&blitter->saved_fb_state, state); } static INLINE @@ -250,12 +305,13 @@ util_blitter_save_fragment_sampler_views(struct blitter_context *blitter, int num_views, struct pipe_sampler_view **views) { + unsigned i; assert(num_views <= Elements(blitter->saved_sampler_views)); blitter->saved_num_sampler_views = num_views; - memcpy(blitter->saved_sampler_views, - views, - num_views * sizeof(struct pipe_sampler_view *)); + for (i = 0; i < num_views; i++) + pipe_sampler_view_reference(&blitter->saved_sampler_views[i], + views[i]); } static INLINE void @@ -263,9 +319,18 @@ util_blitter_save_vertex_buffers(struct blitter_context *blitter, int num_vertex_buffers, struct pipe_vertex_buffer *vertex_buffers) { + unsigned i; assert(num_vertex_buffers <= Elements(blitter->saved_vertex_buffers)); blitter->saved_num_vertex_buffers = num_vertex_buffers; + + for (i = 0; i < num_vertex_buffers; i++) { + if (vertex_buffers[i].buffer) { + pipe_resource_reference(&blitter->saved_vertex_buffers[i].buffer, + vertex_buffers[i].buffer); + } + } + memcpy(blitter->saved_vertex_buffers, vertex_buffers, num_vertex_buffers * sizeof(struct pipe_vertex_buffer)); |