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 3c5eaf7d61c87d2ab22fd7e1d498a6390096b95e..9ee96a062004c80c2f0eaa818e44f72c86a66762 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 bde468c64fe964127ee9805751d7912681374a94..3bba6d1a8930674a2303ee6c35c151dc0a0de92a 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 5313e5e6532af0974cdc278fb8f34fb722fe1f4b..a05061765efebbf9317ac0b1c3f52882368f61b6 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 0d9f0091895f69acbfea5744b95b351fb8458db5..7af1944f82cf4662d8676b6d14d8d54d5f7e7f4f 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);