[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 14:21:56 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.
v2: check for support in the cso context
---
src/gallium/auxiliary/cso_cache/cso_context.c | 17 ++++++++++++++++-
src/gallium/auxiliary/util/u_blit.c | 6 ++++++
src/gallium/auxiliary/util/u_gen_mipmap.c | 3 +++
src/mesa/state_tracker/st_cb_bitmap.c | 5 +++++
src/mesa/state_tracker/st_cb_clear.c | 3 +++
src/mesa/state_tracker/st_cb_drawpixels.c | 4 ++++
src/mesa/state_tracker/st_cb_drawtex.c | 3 +++
src/mesa/state_tracker/st_extensions.c | 3 ++-
8 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index b91fe1a..d1b4dc2 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -78,6 +78,8 @@ struct cso_context {
struct pipe_context *pipe;
struct cso_cache *cache;
+ boolean has_geometry_shader;
+
struct sampler_info fragment_samplers;
struct sampler_info vertex_samplers;
@@ -270,6 +272,11 @@ struct cso_context *cso_create_context( struct pipe_context *pipe )
/* Enable for testing: */
if (0) cso_set_maximum_cache_size( ctx->cache, 4 );
+ if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
+ PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
+ ctx->has_geometry_shader = TRUE;
+ }
+
return ctx;
out:
@@ -785,7 +792,7 @@ void cso_restore_stencil_ref(struct cso_context *ctx)
enum pipe_error cso_set_geometry_shader_handle(struct cso_context *ctx,
void *handle)
{
- if (ctx->geometry_shader != handle) {
+ if (ctx->has_geometry_shader && ctx->geometry_shader != handle) {
ctx->geometry_shader = handle;
ctx->pipe->bind_gs_state(ctx->pipe, handle);
}
@@ -804,12 +811,20 @@ void cso_delete_geometry_shader(struct cso_context *ctx, void *handle)
void cso_save_geometry_shader(struct cso_context *ctx)
{
+ if (!ctx->has_geometry_shader) {
+ return;
+ }
+
assert(!ctx->geometry_shader_saved);
ctx->geometry_shader_saved = ctx->geometry_shader;
}
void cso_restore_geometry_shader(struct cso_context *ctx)
{
+ if (!ctx->has_geometry_shader) {
+ return;
+ }
+
if (ctx->geometry_shader_saved != ctx->geometry_shader) {
ctx->pipe->bind_gs_state(ctx->pipe, ctx->geometry_shader_saved);
ctx->geometry_shader = ctx->geometry_shader_saved;
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c
index 87530e9..6a4324b 100644
--- a/src/gallium/auxiliary/util/u_blit.c
+++ b/src/gallium/auxiliary/util/u_blit.c
@@ -531,6 +531,7 @@ 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);
+ 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 +575,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
set_fragment_shader(ctx, writemask);
}
set_vertex_shader(ctx);
+ cso_set_geometry_shader_handle(ctx->cso, NULL);
/* drawing dest */
memset(&fb, 0, sizeof(fb));
@@ -612,6 +614,7 @@ 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);
+ 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 +722,7 @@ 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);
+ 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 +758,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
/* shaders */
set_fragment_shader(ctx, TGSI_WRITEMASK_XYZW);
set_vertex_shader(ctx);
+ cso_set_geometry_shader_handle(ctx->cso, NULL);
/* drawing dest */
memset(&fb, 0, sizeof(fb));
@@ -788,6 +793,7 @@ 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);
+ 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..436a0e42 100644
--- a/src/gallium/auxiliary/util/u_gen_mipmap.c
+++ b/src/gallium/auxiliary/util/u_gen_mipmap.c
@@ -1561,6 +1561,7 @@ 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);
+ cso_save_geometry_shader(ctx->cso);
cso_save_viewport(ctx->cso);
cso_save_clip(ctx->cso);
cso_save_vertex_elements(ctx->cso);
@@ -1574,6 +1575,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
set_fragment_shader(ctx, type);
set_vertex_shader(ctx);
+ cso_set_geometry_shader_handle(ctx->cso, NULL);
/* init framebuffer state */
memset(&fb, 0, sizeof(fb));
@@ -1682,6 +1684,7 @@ 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);
+ 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..1a8854b 100644
--- a/src/mesa/state_tracker/st_cb_bitmap.c
+++ b/src/mesa/state_tracker/st_cb_bitmap.c
@@ -480,6 +480,7 @@ 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);
+ cso_save_geometry_shader(cso);
cso_save_vertex_elements(cso);
cso_save_vertex_buffers(cso);
@@ -493,6 +494,9 @@ 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 */
+ cso_set_geometry_shader_handle(cso, NULL);
+
/* user samplers, plus our bitmap sampler */
{
struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
@@ -556,6 +560,7 @@ 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);
+ 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..19a87aa 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -246,6 +246,7 @@ 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);
+ cso_save_geometry_shader(st->cso_context);
cso_save_vertex_elements(st->cso_context);
cso_save_vertex_buffers(st->cso_context);
@@ -321,6 +322,7 @@ clear_with_quad(struct gl_context *ctx,
cso_set_clip(st->cso_context, &st->clear.clip);
set_fragment_shader(st);
set_vertex_shader(st);
+ cso_set_geometry_shader_handle(st->cso_context, NULL);
if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
st_translate_color(ctx->Color.ClearColor.f,
@@ -340,6 +342,7 @@ 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);
+ 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..1c44d0d 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -671,6 +671,7 @@ 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);
+ cso_save_geometry_shader(cso);
cso_save_vertex_elements(cso);
cso_save_vertex_buffers(cso);
if (write_stencil) {
@@ -720,6 +721,8 @@ 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 */
+ cso_set_geometry_shader_handle(cso, NULL);
/* texture sampling state: */
{
@@ -789,6 +792,7 @@ 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);
+ 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..eff1950 100644
--- a/src/mesa/state_tracker/st_cb_drawtex.c
+++ b/src/mesa/state_tracker/st_cb_drawtex.c
@@ -230,6 +230,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
cso_save_viewport(cso);
cso_save_vertex_shader(cso);
+ cso_save_geometry_shader(cso);
cso_save_vertex_elements(cso);
cso_save_vertex_buffers(cso);
@@ -238,6 +239,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
semantic_names, semantic_indexes);
cso_set_vertex_shader_handle(cso, vs);
}
+ cso_set_geometry_shader_handle(cso, NULL);
for (i = 0; i < numAttribs; i++) {
velements[i].src_offset = i * 4 * sizeof(float);
@@ -278,6 +280,7 @@ st_DrawTex(struct gl_context *ctx, GLfloat x, GLfloat y, GLfloat z,
/* restore state */
cso_restore_viewport(cso);
cso_restore_vertex_shader(cso);
+ cso_restore_geometry_shader(cso);
cso_restore_vertex_elements(cso);
cso_restore_vertex_buffers(cso);
}
diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
index af8cc04..3563e1d 100644
--- a/src/mesa/state_tracker/st_extensions.c
+++ b/src/mesa/state_tracker/st_extensions.c
@@ -555,7 +555,8 @@ 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;
#endif
--
1.7.4.1
More information about the mesa-dev
mailing list