i915g: Enable dumping of fragment shaders under I915_DEBUG=fs.
authorEmma Anholt <emma@anholt.net>
Sun, 27 Jun 2021 20:47:51 +0000 (13:47 -0700)
committerEmma Anholt <emma@anholt.net>
Mon, 28 Jun 2021 21:58:28 +0000 (14:58 -0700)
Probably the most common thing I want to debug in this driver, and we
didn't have a good option for it.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11617>

src/gallium/drivers/i915/i915_debug.c
src/gallium/drivers/i915/i915_debug.h
src/gallium/drivers/i915/i915_debug_fp.c
src/gallium/drivers/i915/i915_fpc_translate.c

index e2d271e..47d0f3c 100644 (file)
@@ -42,6 +42,7 @@ static const struct debug_named_value i915_debug_options[] = {
    {"flush", DBG_FLUSH, "Flushing information"},
    {"texture", DBG_TEXTURE, "Texture information"},
    {"constants", DBG_CONSTANTS, "Constant buffers"},
+   {"fs", DBG_FS, "Dump fragment shaders"},
    DEBUG_NAMED_VALUE_END};
 
 unsigned i915_debug = 0;
index 30b0f9c..8195832 100644 (file)
@@ -44,6 +44,7 @@ struct i915_winsys_batchbuffer;
 #define DBG_FLUSH     0x8
 #define DBG_TEXTURE   0x10
 #define DBG_CONSTANTS 0x20
+#define DBG_FS        0x40
 
 extern unsigned i915_debug;
 
index 628db70..fcada72 100644 (file)
@@ -277,5 +277,4 @@ i915_disassemble_program(const unsigned *program, unsigned sz)
    }
 
    mesa_logi("\t\tEND");
-   mesa_logi("\t\t");
 }
index 1fc5ab1..5bfbbc8 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdarg.h>
 
 #include "i915_context.h"
+#include "i915_debug.h"
 #include "i915_debug_private.h"
 #include "i915_fpc.h"
 #include "i915_reg.h"
@@ -35,6 +36,7 @@
 #include "pipe/p_shader_tokens.h"
 #include "tgsi/tgsi_dump.h"
 #include "tgsi/tgsi_parse.h"
+#include "util/log.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
@@ -1046,9 +1048,10 @@ i915_translate_fragment_program(struct i915_context *i915,
    const struct tgsi_token *tokens = fs->state.tokens;
    struct i915_token_list *i_tokens;
 
-#if 0
-   tgsi_dump(tokens, 0);
-#endif
+   if (I915_DBG_ON(DBG_FS)) {
+      mesa_logi("TGSI fragment shader:");
+      tgsi_dump(tokens, 0);
+   }
 
    /* hw doesn't seem to like empty frag programs, even when the depth write
     * fixup gets emitted below - may that one is fishy, too? */
@@ -1067,8 +1070,18 @@ i915_translate_fragment_program(struct i915_context *i915,
    i915_fini_compile(i915, p);
    i915_optimize_free(i_tokens);
 
-#if 0
-   /* XXX: The disasm wants the concatenation of the decl and program. */
-   i915_disassemble_program(fs->program, fs->program_len);
-#endif
+   if (I915_DBG_ON(DBG_FS)) {
+      mesa_logi("i915 fragment shader with %d constants%s", fs->num_constants,
+                fs->num_constants ? ":" : "");
+
+      for (int i = 0; i < I915_MAX_CONSTANT; i++) {
+         if (fs->constant_flags[i] &&
+             fs->constant_flags[i] != I915_CONSTFLAG_USER) {
+            mesa_logi("\t\tC[%d] = { %f, %f, %f, %f }", i, fs->constants[i][0],
+                      fs->constants[i][1], fs->constants[i][2],
+                      fs->constants[i][3]);
+         }
+      }
+      i915_disassemble_program(fs->program, fs->program_len);
+   }
 }