[Mesa-dev] Mesa (master): u_blitter: don' t create integer vertex elements unless shader supports them
Brian Paul
brianp at vmware.com
Mon Oct 10 07:24:02 PDT 2011
On 10/09/2011 09:36 AM, Dave Airlie wrote:
> Module: Mesa
> Branch: master
> Commit: dd20256a1c1566f11e1fa970028f3bb4f05445b7
> URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dd20256a1c1566f11e1fa970028f3bb4f05445b7
>
> Author: Dave Airlie<airlied at redhat.com>
> Date: Sun Oct 9 16:35:28 2011 +0100
>
> u_blitter: don't create integer vertex elements unless shader supports them
>
> Should fix https://bugs.freedesktop.org/show_bug.cgi?id=41613
>
> We don't want to create these vertex elements unless the pipe driver
> vertex stage can handle integers.
>
> Signed-off-by: Dave Airlie<airlied at redhat.com>
>
> ---
>
> src/gallium/auxiliary/util/u_blitter.c | 49 +++++++++++++++++++-------------
> 1 files changed, 29 insertions(+), 20 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
> index 1f8b679..73d1af0 100644
> --- a/src/gallium/auxiliary/util/u_blitter.c
> +++ b/src/gallium/auxiliary/util/u_blitter.c
> @@ -109,6 +109,7 @@ struct blitter_context_priv
> unsigned dst_height;
>
> boolean has_geometry_shader;
> + boolean vertex_has_integers;
> };
>
> static void blitter_draw_rectangle(struct blitter_context *blitter,
> @@ -152,6 +153,9 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
> ctx->has_geometry_shader =
> pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
> PIPE_SHADER_CAP_MAX_INSTRUCTIONS)> 0;
> + ctx->vertex_has_integers =
> + pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
> + PIPE_SHADER_CAP_INTEGERS);
>
> /* blend state objects */
> memset(&blend, 0, sizeof(blend));
> @@ -211,27 +215,30 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
> }
> ctx->velem_state = pipe->create_vertex_elements_state(pipe, 2,&velem[0]);
>
> - memset(&velem[0], 0, sizeof(velem[0]) * 2);
> - for (i = 0; i< 2; i++) {
> - velem[i].src_offset = i * 4 * sizeof(float);
> - if (i == 0) {
> - velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
> - } else {
> - velem[i].src_format = PIPE_FORMAT_R32G32B32A32_SINT;
> + if (ctx->vertex_has_integers) {
> + memset(&velem[0], 0, sizeof(velem[0]) * 2);
> + for (i = 0; i< 2; i++) {
> + velem[i].src_offset = i * 4 * sizeof(float);
> + if (i == 0) {
> + velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
> + } else {
> + velem[i].src_format = PIPE_FORMAT_R32G32B32A32_SINT;
> + }
> }
I realize that the current code uses a loop here, but it seems like
overkill. This seems simpler:
memset(velem, 0, sizeof(velem));
velem[0].src_offset = 0;
velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
velem[1].src_offset = 4 * sizeof(float);
velem[1].src_format = PIPE_FORMAT_R32G32B32A32_SINT;
It's about half the LOC and is easier to read.
Same thing below.
> - }
> - ctx->velem_sint_state = pipe->create_vertex_elements_state(pipe, 2,&velem[0]);
> -
> - memset(&velem[0], 0, sizeof(velem[0]) * 2);
> - for (i = 0; i< 2; i++) {
> - velem[i].src_offset = i * 4 * sizeof(float);
> - if (i == 0) {
> - velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
> - } else {
> - velem[i].src_format = PIPE_FORMAT_R32G32B32A32_UINT;
> + ctx->velem_sint_state = pipe->create_vertex_elements_state(pipe, 2,&velem[0]);
> +
> + memset(&velem[0], 0, sizeof(velem[0]) * 2);
> + for (i = 0; i< 2; i++) {
> + velem[i].src_offset = i * 4 * sizeof(float);
> + if (i == 0) {
> + velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
> + } else {
> + velem[i].src_format = PIPE_FORMAT_R32G32B32A32_UINT;
> + }
> }
> + ctx->velem_uint_state = pipe->create_vertex_elements_state(pipe, 2,&velem[0]);
> }
> - ctx->velem_uint_state = pipe->create_vertex_elements_state(pipe, 2,&velem[0]);
> +
> /* fragment shaders are created on-demand */
>
> /* vertex shader */
> @@ -274,8 +281,10 @@ void util_blitter_destroy(struct blitter_context *blitter)
> pipe->delete_rasterizer_state(pipe, ctx->rs_state);
> pipe->delete_vs_state(pipe, ctx->vs);
> pipe->delete_vertex_elements_state(pipe, ctx->velem_state);
> - pipe->delete_vertex_elements_state(pipe, ctx->velem_sint_state);
> - pipe->delete_vertex_elements_state(pipe, ctx->velem_uint_state);
> + if (ctx->vertex_has_integers) {
> + pipe->delete_vertex_elements_state(pipe, ctx->velem_sint_state);
> + pipe->delete_vertex_elements_state(pipe, ctx->velem_uint_state);
> + }
>
> for (i = 0; i< PIPE_MAX_TEXTURE_TYPES; i++) {
> if (ctx->fs_texfetch_col[i])
>
-Brian
More information about the mesa-dev
mailing list