diff options
author | Marek Olšák <[email protected]> | 2011-12-15 18:42:21 +0100 |
---|---|---|
committer | Christoph Bumiller <[email protected]> | 2011-12-15 18:51:48 +0100 |
commit | 861a029ddb31e91bb4d8e18ab708d0d172f63aad (patch) | |
tree | a938450d80ee5dbda670f7fe37bb51b10c1982c4 /src/gallium/include/pipe | |
parent | 4f4a1be2009863ea34a69b22f58aa1ca08cd710f (diff) |
gallium: interface changes necessary to implement transform feedback (v5)
Namely:
- EXT_transform_feedback
- ARB_transform_feedback2
- ARB_transform_feedback_instanced
The old interface was not useful for OpenGL and had to be reworked.
This interface was originally designed for OpenGL, but additional
changes have been made in order to make st/d3d1x support easier.
The most notable change is the stream-out info must be linked
with a vertex or geometry shader and cannot be set independently.
This is due to limitations of existing hardware (special shader
instructions must be used to write into stream-out buffers),
and it's also how OpenGL works (stream outputs must be specified
prior to linking shaders).
Other than that, each stream output buffer has a "view" into it that
internally maintains the number of bytes which have been written
into it. (one buffer can be bound in several different transform
feedback objects in OpenGL, so we must be able to have several views
around) The set_stream_output_targets function contains a parameter
saying whether new data should be appended or not.
Also, the view can optionally be used to provide the vertex
count for draw_vbo. Note that the count is supposed to be stored
in device memory and the CPU never gets to know its value.
OpenGL way | Gallium way
------------------------------------
BeginTF = set_so_targets(append_bitmask = 0)
PauseTF = set_so_targets(num_targets = 0)
ResumeTF = set_so_targets(append_bitmask = ~0)
EndTF = set_so_targets(num_targets = 0)
DrawTF = use pipe_draw_info::count_from_stream_output
v2: * removed the reset_stream_output_targets function
* added a parameter append_bitmask to set_stream_output_targets,
each bit specifies whether new data should be appended to each
buffer or not.
v3: * added PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME for ARB_tfb2,
note that the draw-auto subset is always required (for d3d10),
only the pause/resume functionality is limited if the CAP is not
advertised
v4: * update gallium/docs
v5: * compactified struct pipe_stream_output_info, updated dump/trace
Diffstat (limited to 'src/gallium/include/pipe')
-rw-r--r-- | src/gallium/include/pipe/p_context.h | 38 | ||||
-rw-r--r-- | src/gallium/include/pipe/p_defines.h | 10 | ||||
-rw-r--r-- | src/gallium/include/pipe/p_state.h | 85 |
3 files changed, 95 insertions, 38 deletions
diff --git a/src/gallium/include/pipe/p_context.h b/src/gallium/include/pipe/p_context.h index b2d5f9543e6..de79a9bfff1 100644 --- a/src/gallium/include/pipe/p_context.h +++ b/src/gallium/include/pipe/p_context.h @@ -56,7 +56,7 @@ struct pipe_sampler_view; struct pipe_scissor_state; struct pipe_shader_state; struct pipe_stencil_ref; -struct pipe_stream_output_state; +struct pipe_stream_output_target; struct pipe_surface; struct pipe_vertex_buffer; struct pipe_vertex_element; @@ -86,11 +86,6 @@ struct pipe_context { /*@{*/ void (*draw_vbo)( struct pipe_context *pipe, const struct pipe_draw_info *info ); - - /** - * Draw the stream output buffer at index 0 - */ - void (*draw_stream_output)( struct pipe_context *pipe, unsigned mode ); /*@}*/ /** @@ -179,11 +174,6 @@ struct pipe_context { void (*bind_vertex_elements_state)(struct pipe_context *, void *); void (*delete_vertex_elements_state)(struct pipe_context *, void *); - void * (*create_stream_output_state)(struct pipe_context *, - const struct pipe_stream_output_state *); - void (*bind_stream_output_state)(struct pipe_context *, void *); - void (*delete_stream_output_state)(struct pipe_context*, void*); - /*@}*/ /** @@ -237,12 +227,26 @@ struct pipe_context { void (*set_index_buffer)( struct pipe_context *pipe, const struct pipe_index_buffer * ); - void (*set_stream_output_buffers)(struct pipe_context *, - struct pipe_resource **buffers, - int *offsets, /*array of offsets - from the start of each - of the buffers */ - int num_buffers); + /*@}*/ + + /** + * Stream output functions. + */ + /*@{*/ + + struct pipe_stream_output_target *(*create_stream_output_target)( + struct pipe_context *, + struct pipe_resource *, + unsigned buffer_offset, + unsigned buffer_size); + + void (*stream_output_target_destroy)(struct pipe_context *, + struct pipe_stream_output_target *); + + void (*set_stream_output_targets)(struct pipe_context *, + unsigned num_targets, + struct pipe_stream_output_target **targets, + unsigned append_bitmask); /*@}*/ diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 30f1d7fb964..800a04cd8f0 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -438,7 +438,7 @@ enum pipe_cap { PIPE_CAP_TEXTURE_MIRROR_CLAMP = 25, PIPE_CAP_BLEND_EQUATION_SEPARATE = 28, PIPE_CAP_SM3 = 29, /*< Shader Model, supported */ - PIPE_CAP_STREAM_OUTPUT = 30, + PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS = 30, PIPE_CAP_PRIMITIVE_RESTART = 31, /** Maximum texture image units accessible from vertex and fragment shaders * combined */ @@ -466,8 +466,12 @@ enum pipe_cap { PIPE_CAP_MAX_TEXEL_OFFSET = 51, PIPE_CAP_CONDITIONAL_RENDER = 52, PIPE_CAP_TEXTURE_BARRIER = 53, - PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS = 54, /* temporary */ - PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS = 55 /* temporary */ + PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_ATTRIBS = 54, + PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS = 55, + PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS = 56, + PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME = 57, + PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS = 58, /* temporary */ + PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS = 59 /* temporary */ }; /** diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 37e0679e15f..f943ca58b88 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -121,6 +121,12 @@ struct pipe_rasterizer_state */ unsigned gl_rasterization_rules:1; + /** + * When true, rasterization is disabled and no pixels are written. + * This only makes sense with the Stream Out functionality. + */ + unsigned rasterizer_discard:1; + unsigned line_stipple_factor:8; /**< [1..256] actually */ unsigned line_stipple_pattern:16; @@ -164,9 +170,30 @@ struct pipe_clip_state }; +/** + * Stream output for vertex transform feedback. + */ +struct pipe_stream_output_info +{ + unsigned num_outputs; + /** stride for an entire vertex, only used if all output_buffers are 0 */ + unsigned stride; + /** + * Array of stream outputs, in the order they are to be written in. + * Selected components are tightly packed into the output buffer. + */ + struct { + unsigned register_index:8; /**< 0 to PIPE_MAX_SHADER_OUTPUTS */ + unsigned register_mask:4; /**< TGSI_WRITEMASK_x */ + unsigned output_buffer:4; /**< 0 to PIPE_MAX_SO_BUFFERS */ + } output[PIPE_MAX_SHADER_OUTPUTS]; +}; + + struct pipe_shader_state { const struct tgsi_token *tokens; + struct pipe_stream_output_info stream_output; }; @@ -375,24 +402,6 @@ struct pipe_resource /** - * Stream output for vertex transform feedback. - */ -struct pipe_stream_output_state -{ - /** number of the output buffer to insert each element into */ - int output_buffer[PIPE_MAX_SHADER_OUTPUTS]; - /** which register to grab each output from */ - int register_index[PIPE_MAX_SHADER_OUTPUTS]; - /** TGSI_WRITEMASK signifying which components to output */ - ubyte register_mask[PIPE_MAX_SHADER_OUTPUTS]; - /** number of outputs */ - int num_outputs; - /** stride for an entire vertex, only used if all output_buffers are 0 */ - unsigned stride; -}; - - -/** * Transfer object. For data transfer to/from a resource. */ struct pipe_transfer @@ -422,6 +431,30 @@ struct pipe_vertex_buffer /** + * A stream output target. The structure specifies the range vertices can + * be written to. + * + * In addition to that, the structure should internally maintain the offset + * into the buffer, which should be incremented everytime something is written + * (appended) to it. The internal offset is buffer_offset + how many bytes + * have been written. The internal offset can be stored on the device + * and the CPU actually doesn't have to query it. + * + * Use PIPE_QUERY_SO_STATISTICS to know how many primitives have + * actually been written. + */ +struct pipe_stream_output_target +{ + struct pipe_reference reference; + struct pipe_resource *buffer; /**< buffer into which this is a target view */ + struct pipe_context *context; /**< context this view belongs to */ + + unsigned buffer_offset; /**< offset where data should be written, in bytes */ + unsigned buffer_size; /**< how much data is allowed to be written */ +}; + + +/** * Information to describe a vertex attribute (position, color, etc) */ struct pipe_vertex_element @@ -481,6 +514,22 @@ struct pipe_draw_info */ boolean primitive_restart; unsigned restart_index; + + /** + * Stream output target. If not NULL, it's used to provide the 'count' + * parameter based on the number vertices captured by the stream output + * stage. (or generally, based on the number of bytes captured) + * + * Only 'mode', 'start_instance', and 'instance_count' are taken into + * account, all the other variables from pipe_draw_info are ignored. + * + * 'start' is implicitly 0 and 'count' is set as discussed above. + * The draw command is non-indexed. + * + * Note that this only provides the count. The vertex buffers must + * be set via set_vertex_buffers manually. + */ + struct pipe_stream_output_target *count_from_stream_output; }; |