intel: add identifier for debug purposes
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Tue, 24 Dec 2019 00:40:26 +0000 (02:40 +0200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 20 May 2020 15:58:22 +0000 (15:58 +0000)
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3203>

src/intel/Android.dev.mk
src/intel/dev/gen_debug.c
src/intel/dev/gen_debug.h

index 4f14b0362d7ae6280370ed57476c70be6200fc20..5c7ddd4d35eb5078f789578e9ae8797d9f38402a 100644 (file)
@@ -29,7 +29,12 @@ LOCAL_MODULE := libmesa_intel_dev
 
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
-LOCAL_C_INCLUDES := $(MESA_TOP)/include
+LOCAL_STATIC_LIBRARIES := \
+       libmesa_git_sha1
+
+LOCAL_C_INCLUDES := \
+       $(MESA_TOP)/include \
+       $(MESA_TOP)/src
 
 LOCAL_SRC_FILES := $(DEV_FILES)
 
index 4e610dc4169c0fbd6503fef2626c47f9177af13c..d8651390c476a106e449676b26308f95e8da480a 100644 (file)
  * miscellaneous debugging code.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "dev/gen_debug.h"
+#include "git_sha1.h"
 #include "util/macros.h"
 #include "util/debug.h"
 #include "c11/threads.h"
@@ -123,3 +126,96 @@ brw_process_intel_debug_variable(void)
    call_once(&process_intel_debug_variable_flag,
              brw_process_intel_debug_variable_once);
 }
+
+static uint64_t debug_identifier[4] = {
+   0xffeeddccbbaa9988,
+   0x7766554433221100,
+   0xffeeddccbbaa9988,
+   0x7766554433221100,
+};
+
+void *
+intel_debug_identifier(void)
+{
+   return debug_identifier;
+}
+
+uint32_t
+intel_debug_identifier_size(void)
+{
+   return sizeof(debug_identifier);
+}
+
+uint32_t
+intel_debug_write_identifiers(void *_output,
+                              uint32_t output_size,
+                              const char *driver_name)
+{
+   void *output = _output, *output_end = _output + output_size;
+
+   assert(output_size > intel_debug_identifier_size());
+
+   memcpy(output, intel_debug_identifier(), intel_debug_identifier_size());
+   output += intel_debug_identifier_size();
+
+   for (uint32_t id = GEN_DEBUG_BLOCK_TYPE_DRIVER; id < GEN_DEBUG_BLOCK_TYPE_MAX; id++) {
+      switch (id) {
+      case GEN_DEBUG_BLOCK_TYPE_DRIVER: {
+         struct gen_debug_block_driver driver_desc = {
+            .base = {
+               .type = id,
+            },
+         };
+         int len = snprintf(output + sizeof(driver_desc),
+                            output_end - (output + sizeof(driver_desc)),
+                            "%s " PACKAGE_VERSION " build " MESA_GIT_SHA1,
+                            driver_name);
+         driver_desc.base.length = sizeof(driver_desc) + len + 1;
+         memcpy(output, &driver_desc, sizeof(driver_desc));
+         output += driver_desc.base.length;
+         break;
+      }
+
+      default:
+         unreachable("Missing identifier write");
+      }
+
+      assert(output < output_end);
+   }
+
+   struct gen_debug_block_base end = {
+      .type = GEN_DEBUG_BLOCK_TYPE_END,
+      .length = sizeof(end),
+   };
+   memcpy(output, &end, sizeof(end));
+   output += sizeof(end);
+
+   assert(output < output_end);
+
+   /* Return the how many bytes where written, so that the rest of the buffer
+    * can be used for other things.
+    */
+   return output - _output;
+}
+
+void *
+intel_debug_get_identifier_block(void *_buffer,
+                                 uint32_t buffer_size,
+                                 enum gen_debug_block_type type)
+{
+   void *buffer = _buffer + intel_debug_identifier_size(),
+      *end_buffer = _buffer + buffer_size;
+
+   while (buffer < end_buffer) {
+      struct gen_debug_block_base *item = buffer;
+
+      if (item->type == type)
+         return item;
+      if (item->type == GEN_DEBUG_BLOCK_TYPE_END)
+         return NULL;
+
+      buffer += item->length;
+   }
+
+   return NULL;
+}
index aff96ae3fa24df19eebab8ce7b2bb05fcf03f0c4..687bedb1a42297d48f87c216acee1f69199f024e 100644 (file)
@@ -123,6 +123,42 @@ extern uint64_t intel_debug_flag_for_shader_stage(gl_shader_stage stage);
 
 extern void brw_process_intel_debug_variable(void);
 
+/* Below is a list of structure located in the identifier buffer. The driver
+ * can fill those in for debug purposes.
+ */
+
+enum gen_debug_block_type {
+   /* End of the debug blocks */
+   GEN_DEBUG_BLOCK_TYPE_END = 1,
+
+   /* Driver identifier (struct gen_debug_block_driver) */
+   GEN_DEBUG_BLOCK_TYPE_DRIVER,
+
+   /* Internal, never to be written out */
+   GEN_DEBUG_BLOCK_TYPE_MAX,
+};
+
+struct gen_debug_block_base {
+   uint32_t type; /* enum gen_debug_block_type */
+   uint32_t length; /* inclusive of this structure size */
+};
+
+struct gen_debug_block_driver {
+   struct gen_debug_block_base base;
+   uint8_t description[];
+};
+
+extern void *intel_debug_identifier(void);
+extern uint32_t intel_debug_identifier_size(void);
+
+extern uint32_t intel_debug_write_identifiers(void *output,
+                                              uint32_t output_size,
+                                              const char *driver_name);
+
+extern void *intel_debug_get_identifier_block(void *buffer,
+                                              uint32_t buffer_size,
+                                              enum gen_debug_block_type type);
+
 #ifdef __cplusplus
 }
 #endif