r600g/sb: use source bytecode in case of optimization errors
authorVadim Girlin <vadimgirlin@gmail.com>
Tue, 23 Apr 2013 06:34:00 +0000 (10:34 +0400)
committerVadim Girlin <vadimgirlin@gmail.com>
Tue, 30 Apr 2013 17:50:47 +0000 (21:50 +0400)
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/sb/sb_bc.h
src/gallium/drivers/r600/sb/sb_context.cpp
src/gallium/drivers/r600/sb/sb_core.cpp

index 8f6d59b3e6aca2842ab2bbc28d0d9933423cfd74..4991fb28165c63973ebccca8cab92fdf38f3bac4 100644 (file)
@@ -72,6 +72,7 @@ static const struct debug_named_value debug_options[] = {
        { "sbdry", DBG_SB_DRY_RUN, "Don't use optimized bytecode (just print the dumps)" },
        { "sbstat", DBG_SB_STAT, "Print optimization statistics for shaders" },
        { "sbdump", DBG_SB_DUMP, "Print IR dumps after some optimization passes" },
+       { "sbnofallback", DBG_SB_NO_FALLBACK, "Abort on errors instead of fallback" },
 
        DEBUG_NAMED_VALUE_END /* must be last */
 };
index 322989a839d9130ebdaa5fba220ac2777d8cdb92..61e2022a4a13453efd48ae6a478018653d761174 100644 (file)
@@ -263,6 +263,7 @@ typedef boolean (*r600g_dma_blit_t)(struct pipe_context *ctx,
 #define DBG_SB_DRY_RUN (1 << 23)
 #define DBG_SB_STAT            (1 << 24)
 #define DBG_SB_DUMP            (1 << 25)
+#define DBG_SB_NO_FALLBACK     (1 << 26)
 
 struct r600_tiling_info {
        unsigned num_channels;
index be68f9fd9251dbbe7f01baaf20e9c5f0ed5a0de4..459dcac13cebb0ac3916017b2d493618ff15d849 100644 (file)
@@ -478,6 +478,7 @@ public:
        static unsigned dump_stat;
 
        static unsigned dry_run;
+       static unsigned no_fallback;
 
        static unsigned dskip_start;
        static unsigned dskip_end;
index 7a259828d080afa86d4166061ada0007a931afcd..034631376b5a54ade73ba82459c0e0a8c86aee1d 100644 (file)
@@ -31,6 +31,7 @@ namespace r600_sb {
 unsigned sb_context::dump_pass = 0;
 unsigned sb_context::dump_stat = 0;
 unsigned sb_context::dry_run = 0;
+unsigned sb_context::no_fallback = 0;
 
 unsigned sb_context::dskip_start = 0;
 unsigned sb_context::dskip_end = 0;
index aec838dcacbe7c36822ba700d520383d558a4284..bc200a4c9b6214ce00881bf8fa31c01644522777 100644 (file)
@@ -65,6 +65,7 @@ sb_context *r600_sb_context_create(struct r600_context *rctx) {
        sb_context::dump_pass = df & DBG_SB_DUMP;
        sb_context::dump_stat = df & DBG_SB_STAT;
        sb_context::dry_run = df & DBG_SB_DRY_RUN;
+       sb_context::no_fallback = df & DBG_SB_NO_FALLBACK;
 
        sb_context::dskip_start = debug_get_num_option("R600_SB_DSKIP_START", 0);
        sb_context::dskip_end = debug_get_num_option("R600_SB_DSKIP_END", 0);
@@ -96,6 +97,15 @@ int r600_sb_bytecode_process(struct r600_context *rctx,
                time_start = os_time_get_nano();
        }
 
+       SB_DUMP_STAT( cerr << "\nsb: shader " << shader_id << "\n"; );
+
+       bc_parser parser(*ctx, bc, pshader, dump_source_bytecode, optimize);
+
+       if ((r = parser.parse())) {
+               assert(0);
+               return r;
+       }
+
        /* skip some shaders (use shaders from default backend)
         * dskip_start - range start, dskip_end - range_end,
         * e.g. start = 5, end = 6 means shaders 5 & 6
@@ -116,15 +126,6 @@ int r600_sb_bytecode_process(struct r600_context *rctx,
                }
        }
 
-       SB_DUMP_STAT( cerr << "\nsb: shader " << shader_id << "\n"; );
-
-       bc_parser parser(*ctx, bc, pshader, dump_source_bytecode, optimize);
-
-       if ((r = parser.parse())) {
-               assert(0);
-               return r;
-       }
-
        shader *sh = parser.get_shader();
        SB_DUMP_PASS( cerr << "\n\n###### after parse\n"; sh->dump_ir(); );
 
@@ -136,8 +137,17 @@ int r600_sb_bytecode_process(struct r600_context *rctx,
 #define SB_RUN_PASS(n, dump) \
        do { \
                r = n(*sh).run(); \
+               if (r) { \
+                       cerr << "sb: error (" << r << ") in the " << #n << " pass.\n"; \
+                       if (sb_context::no_fallback) \
+                               return r; \
+                       cerr << "sb: using unoptimized bytecode...\n"; \
+                       delete sh; \
+                       return 0; \
+               } \
                if (dump) { \
-                       SB_DUMP_PASS( cerr << "\n\n###### after " << #n << "\n"; sh->dump_ir();); \
+                       SB_DUMP_PASS( cerr << "\n\n###### after " << #n << "\n"; \
+                               sh->dump_ir();); \
                } \
                assert(!r); \
        } while (0)
@@ -175,7 +185,7 @@ int r600_sb_bytecode_process(struct r600_context *rctx,
        // container nodes in the correct locations for code placement
        sh->create_bbs();
 
-       SB_RUN_PASS(gcm,                                0);
+       SB_RUN_PASS(gcm,                                1);
 
        sh->compute_interferences = true;
        SB_RUN_PASS(liveness,                   0);