radeonsi: If pixel shader compilation fails, use a dummy shader.
authorMichel Dänzer <michel.daenzer@amd.com>
Wed, 8 Aug 2012 13:35:42 +0000 (15:35 +0200)
committerMichel Dänzer <michel@daenzer.net>
Wed, 8 Aug 2012 13:33:38 +0000 (15:33 +0200)
Otherwise we're likely to hang the GPU.

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/radeonsi/radeonsi_pipe.c
src/gallium/drivers/radeonsi/radeonsi_pipe.h
src/gallium/drivers/radeonsi/radeonsi_shader.c
src/gallium/drivers/radeonsi/si_state_draw.c

index 3c5eaf7..9ee96a0 100644 (file)
@@ -37,6 +37,7 @@
 #include "util/u_pack_color.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
+#include "util/u_simple_shaders.h"
 #include "util/u_upload_mgr.h"
 #include "vl/vl_decoder.h"
 #include "vl/vl_video_buffer.h"
@@ -171,6 +172,9 @@ static void r600_destroy_context(struct pipe_context *context)
 {
        struct r600_context *rctx = (struct r600_context *)context;
 
+       if (rctx->dummy_pixel_shader) {
+               rctx->context.delete_fs_state(&rctx->context, rctx->dummy_pixel_shader);
+       }
        rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush);
        util_unreference_framebuffer_state(&rctx->framebuffer);
 
@@ -251,6 +255,12 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void
 
        r600_get_backend_mask(rctx); /* this emits commands and must be last */
 
+       rctx->dummy_pixel_shader =
+               util_make_fragment_cloneinput_shader(&rctx->context, 0,
+                                                    TGSI_SEMANTIC_GENERIC,
+                                                    TGSI_INTERPOLATE_CONSTANT);
+       rctx->context.bind_fs_state(&rctx->context, rctx->dummy_pixel_shader);
+
        return &rctx->context;
 }
 
index bde468c..3bba6d1 100644 (file)
@@ -206,6 +206,10 @@ struct r600_context {
        struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
        unsigned                nr_vertex_buffers;
 
+       /* With rasterizer discard, there doesn't have to be a pixel shader.
+        * In that case, we bind this one: */
+       struct si_pipe_shader   *dummy_pixel_shader;
+
        /* SI state handling */
        union si_state  queued;
        union si_state  emitted;
index 5313e5e..a050617 100644 (file)
@@ -627,7 +627,10 @@ int si_pipe_shader_create(
                tgsi_dump(shader->tokens, 0);
        }
 
-       lp_build_tgsi_llvm(bld_base, shader->tokens);
+       if (!lp_build_tgsi_llvm(bld_base, shader->tokens)) {
+               fprintf(stderr, "Failed to translate shader from TGSI to LLVM\n");
+               return -EINVAL;
+       }
 
        radeon_llvm_finalize_module(&si_shader_ctx.radeon_bld);
 
index 0d9f009..7af1944 100644 (file)
@@ -373,6 +373,13 @@ static void si_update_derived_state(struct r600_context *rctx)
        if (!rctx->ps_shader->bo) {
                si_pipe_shader_ps(ctx, rctx->ps_shader);
        }
+       if (!rctx->ps_shader->bo) {
+               if (!rctx->dummy_pixel_shader->bo)
+                       si_pipe_shader_ps(ctx, rctx->dummy_pixel_shader);
+
+               if (rctx->dummy_pixel_shader->pm4)
+                       si_pm4_bind_state(rctx, vs, rctx->dummy_pixel_shader->pm4);
+       }
 
        if (rctx->shader_dirty) {
                si_update_spi_map(rctx);