[Mesa-dev] [PATCH 1/2] st/mesa: set geometry shader to NULL when doing internal drawing

Marek Olšák maraeo at gmail.com
Fri Nov 4 10:13:50 PDT 2011


The code expects the geometry shader to be NULL.
We don't have geometry shaders now, but it's good to be prepared.
---
 src/gallium/auxiliary/util/u_blit.c       |   25 +++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_gen_mipmap.c |   16 ++++++++++++++++
 src/mesa/state_tracker/st_cb_bitmap.c     |   11 +++++++++++
 src/mesa/state_tracker/st_cb_clear.c      |    9 +++++++++
 src/mesa/state_tracker/st_cb_drawpixels.c |   10 ++++++++++
 src/mesa/state_tracker/st_cb_drawtex.c    |    9 +++++++++
 src/mesa/state_tracker/st_context.h       |    1 +
 src/mesa/state_tracker/st_extensions.c    |    4 +++-
 8 files changed, 84 insertions(+), 1 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 87530e9..190e93f 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -66,6 +66,8 @@ struct blit_state
    struct pipe_vertex_element velem[2];
    enum pipe_texture_target internal_target;
 
+   boolean has_geometry_shader;
+
    void *vs;
    void *fs[TGSI_WRITEMASK_XYZW + 1];
    void *fs_depth;
@@ -142,6 +144,11 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso)
    else
       ctx->internal_target = PIPE_TEXTURE_RECT;
 
+   if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
+                                PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+      ctx->has_geometry_shader = TRUE;
+   }
+
    return ctx;
 }
 
@@ -531,6 +538,9 @@ util_blit_pixels_writemask(struct blit_state *ctx,
    cso_save_framebuffer(ctx->cso);
    cso_save_fragment_shader(ctx->cso);
    cso_save_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_save_geometry_shader(ctx->cso);
+   }
    cso_save_clip(ctx->cso);
    cso_save_vertex_elements(ctx->cso);
    cso_save_vertex_buffers(ctx->cso);
@@ -574,6 +584,9 @@ util_blit_pixels_writemask(struct blit_state *ctx,
       set_fragment_shader(ctx, writemask);
    }
    set_vertex_shader(ctx);
+   if (ctx->has_geometry_shader) {
+      cso_set_geometry_shader_handle(ctx->cso, NULL);
+   }
 
    /* drawing dest */
    memset(&fb, 0, sizeof(fb));
@@ -612,6 +625,9 @@ util_blit_pixels_writemask(struct blit_state *ctx,
    cso_restore_framebuffer(ctx->cso);
    cso_restore_fragment_shader(ctx->cso);
    cso_restore_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_restore_geometry_shader(ctx->cso);
+   }
    cso_restore_clip(ctx->cso);
    cso_restore_vertex_elements(ctx->cso);
    cso_restore_vertex_buffers(ctx->cso);
@@ -719,6 +735,9 @@ util_blit_pixels_tex(struct blit_state *ctx,
    cso_save_framebuffer(ctx->cso);
    cso_save_fragment_shader(ctx->cso);
    cso_save_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_save_geometry_shader(ctx->cso);
+   }
    cso_save_clip(ctx->cso);
    cso_save_vertex_elements(ctx->cso);
    cso_save_vertex_buffers(ctx->cso);
@@ -754,6 +773,9 @@ util_blit_pixels_tex(struct blit_state *ctx,
    /* shaders */
    set_fragment_shader(ctx, TGSI_WRITEMASK_XYZW);
    set_vertex_shader(ctx);
+   if (ctx->has_geometry_shader) {
+      cso_set_geometry_shader_handle(ctx->cso, NULL);
+   }
 
    /* drawing dest */
    memset(&fb, 0, sizeof(fb));
@@ -788,6 +810,9 @@ util_blit_pixels_tex(struct blit_state *ctx,
    cso_restore_framebuffer(ctx->cso);
    cso_restore_fragment_shader(ctx->cso);
    cso_restore_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_restore_geometry_shader(ctx->cso);
+   }
    cso_restore_clip(ctx->cso);
    cso_restore_vertex_elements(ctx->cso);
    cso_restore_vertex_buffers(ctx->cso);
diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c
index 4a16624..92302f5 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -66,6 +66,8 @@ struct gen_mipmap_state
    struct pipe_clip_state clip;
    struct pipe_vertex_element velem[2];
 
+   boolean has_geometry_shader;
+
    void *vs;
    void *fs[TGSI_TEXTURE_COUNT]; /**< Not all are used, but simplifies code */
 
@@ -1308,6 +1310,11 @@ util_create_gen_mipmap(struct pipe_context *pipe,
       ctx->vertices[i][1][3] = 1.0f; /* q */
    }
 
+   if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
+                                PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+      ctx->has_geometry_shader = TRUE;
+   }
+
    /* Note: the actual vertex buffer is allocated as needed below */
 
    return ctx;
@@ -1561,6 +1568,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_save_framebuffer(ctx->cso);
    cso_save_fragment_shader(ctx->cso);
    cso_save_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_save_geometry_shader(ctx->cso);
+   }
    cso_save_viewport(ctx->cso);
    cso_save_clip(ctx->cso);
    cso_save_vertex_elements(ctx->cso);
@@ -1574,6 +1584,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
 
    set_fragment_shader(ctx, type);
    set_vertex_shader(ctx);
+   if (ctx->has_geometry_shader) {
+      cso_set_geometry_shader_handle(ctx->cso, NULL);
+   }
 
    /* init framebuffer state */
    memset(&fb, 0, sizeof(fb));
@@ -1682,6 +1695,9 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
    cso_restore_framebuffer(ctx->cso);
    cso_restore_fragment_shader(ctx->cso);
    cso_restore_vertex_shader(ctx->cso);
+   if (ctx->has_geometry_shader) {
+      cso_restore_geometry_shader(ctx->cso);
+   }
    cso_restore_viewport(ctx->cso);
    cso_restore_clip(ctx->cso);
    cso_restore_vertex_elements(ctx->cso);
diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
index beb5e7c..307d1eb 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -480,6 +480,9 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_save_viewport(cso);
    cso_save_fragment_shader(cso);
    cso_save_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_save_geometry_shader(cso);
+   }
    cso_save_vertex_elements(cso);
    cso_save_vertex_buffers(cso);
 
@@ -493,6 +496,11 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    /* vertex shader state: position + texcoord pass-through */
    cso_set_vertex_shader_handle(cso, st->bitmap.vs);
 
+   /* geometry shader state: disabled */
+   if (st->has_geometry_shader) {
+      cso_set_geometry_shader_handle(cso, NULL);
+   }
+
    /* user samplers, plus our bitmap sampler */
    {
       struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
@@ -556,6 +564,9 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_restore_viewport(cso);
    cso_restore_fragment_shader(cso);
    cso_restore_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_restore_geometry_shader(cso);
+   }
    cso_restore_vertex_elements(cso);
    cso_restore_vertex_buffers(cso);
 }
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index 83802a5..99d05dc 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -246,6 +246,9 @@ clear_with_quad(struct gl_context *ctx,
    cso_save_clip(st->cso_context);
    cso_save_fragment_shader(st->cso_context);
    cso_save_vertex_shader(st->cso_context);
+   if (st->has_geometry_shader) {
+      cso_save_geometry_shader(st->cso_context);
+   }
    cso_save_vertex_elements(st->cso_context);
    cso_save_vertex_buffers(st->cso_context);
 
@@ -321,6 +324,9 @@ clear_with_quad(struct gl_context *ctx,
    cso_set_clip(st->cso_context, &st->clear.clip);
    set_fragment_shader(st);
    set_vertex_shader(st);
+   if (st->has_geometry_shader) {
+      cso_set_geometry_shader_handle(st->cso_context, NULL);
+   }
 
    if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
       st_translate_color(ctx->Color.ClearColor.f,
@@ -340,6 +346,9 @@ clear_with_quad(struct gl_context *ctx,
    cso_restore_clip(st->cso_context);
    cso_restore_fragment_shader(st->cso_context);
    cso_restore_vertex_shader(st->cso_context);
+   if (st->has_geometry_shader) {
+      cso_restore_geometry_shader(st->cso_context);
+   }
    cso_restore_vertex_elements(st->cso_context);
    cso_restore_vertex_buffers(st->cso_context);
 }
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 89e0a73..f77ac4c 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -671,6 +671,9 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_save_fragment_sampler_views(cso);
    cso_save_fragment_shader(cso);
    cso_save_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_save_geometry_shader(cso);
+   }
    cso_save_vertex_elements(cso);
    cso_save_vertex_buffers(cso);
    if (write_stencil) {
@@ -720,6 +723,10 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    /* vertex shader state: position + texcoord pass-through */
    cso_set_vertex_shader_handle(cso, driver_vp);
 
+   /* geometry shader state: disabled */
+   if (st->has_geometry_shader) {
+      cso_set_geometry_shader_handle(cso, NULL);
+   }
 
    /* texture sampling state: */
    {
@@ -789,6 +796,9 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_restore_fragment_sampler_views(cso);
    cso_restore_fragment_shader(cso);
    cso_restore_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_restore_geometry_shader(cso);
+   }
    cso_restore_vertex_elements(cso);
    cso_restore_vertex_buffers(cso);
    if (write_stencil) {
diff --git a/src/mesa/state_tracker/st_cb_drawtex.c b/src/mesa/state_tracker/st_cb_drawtex.c
index 86ceb9d..8047ad9 100644
--- a/src/mesa/state_tracker/st_cb_drawtex.c
+++ b/src/mesa/state_tracker/st_cb_drawtex.c
@@ -230,6 +230,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
 
    cso_save_viewport(cso);
    cso_save_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_save_geometry_shader(cso);
+   }
    cso_save_vertex_elements(cso);
    cso_save_vertex_buffers(cso);
 
@@ -238,6 +241,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
                                semantic_names, semantic_indexes);
       cso_set_vertex_shader_handle(cso, vs);
    }
+   if (st->has_geometry_shader) {
+      cso_set_geometry_shader_handle(cso, NULL);
+   }
 
    for (i = 0; i < numAttribs; i++) {
       velements[i].src_offset = i * 4 * sizeof(float);
@@ -278,6 +284,9 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
    /* restore state */
    cso_restore_viewport(cso);
    cso_restore_vertex_shader(cso);
+   if (st->has_geometry_shader) {
+      cso_restore_geometry_shader(cso);
+   }
    cso_restore_vertex_elements(cso);
    cso_restore_vertex_buffers(cso);
 }
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index c607809..53bc917 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -77,6 +77,7 @@ struct st_context
    struct draw_stage *rastpos_stage;  /**< For glRasterPos */
    GLboolean sw_primitive_restart;
 
+   boolean has_geometry_shader;
 
    /* On old libGL's for linux we need to invalidate the drawables
     * on glViewpport calls, this is set via a option.
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index af8cc04..9f98938 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -555,9 +555,11 @@ void st_init_extensions(struct st_context *st)
       ctx->Extensions.ARB_vertex_type_2_10_10_10_rev = GL_TRUE;
    }
 
-   if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+   if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY,
+                                PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
       ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
+      st->has_geometry_shader = TRUE;
 #endif
    }
 
-- 
1.7.4.1



More information about the mesa-dev mailing list