+ /*
+ * Order sections so that the hardware context section is visited by the
+ * decoder before other command buffers. This will allow the decoder to see
+ * persistent state that was set before the current batch.
+ */
+ qsort(sections, num_sections, sizeof(sections[0]), qsort_hw_context_first);
+
+ for (int s = 0; s < num_sections; s++) {
+ if (strcmp(sections[s].buffer_name, "ring buffer") != 0)
+ continue;
+ if (ring_head == UINT32_MAX) {
+ ring_head = 0;
+ ring_tail = UINT32_MAX;
+ }
+ if (ring_tail == UINT32_MAX)
+ ring_tail = (ring_head - sizeof(uint32_t)) %
+ (sections[s].dword_count * sizeof(uint32_t));
+ if (ring_head > ring_tail) {
+ size_t total_size = sections[s].dword_count * sizeof(uint32_t) -
+ ring_head + ring_tail;
+ size_t size1 = total_size - ring_tail;
+ uint32_t *new_data = calloc(total_size, 1);
+ memcpy(new_data, (uint8_t *)sections[s].data + ring_head, size1);
+ memcpy((uint8_t *)new_data + size1, sections[s].data, ring_tail);
+ free(sections[s].data);
+ sections[s].data = new_data;
+ ring_head = 0;
+ ring_tail = total_size;
+ ring_wraps = true;
+ }
+ sections[s].data_offset = ring_head;
+ sections[s].dword_count = (ring_tail - ring_head) / sizeof(uint32_t);
+ }
+
+ for (int s = 0; s < num_sections; s++) {
+ if (sections[s].dword_count * 4 > intel_debug_identifier_size() &&
+ memcmp(sections[s].data, intel_debug_identifier(),
+ intel_debug_identifier_size()) == 0) {
+ const struct gen_debug_block_driver *driver_desc =
+ intel_debug_get_identifier_block(sections[s].data,
+ sections[s].dword_count * 4,
+ GEN_DEBUG_BLOCK_TYPE_DRIVER);
+ if (driver_desc) {
+ printf("Driver identifier: %s\n",
+ (const char *) driver_desc->description);
+ }
+ break;
+ }
+ }
+