Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014 Broadcom
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  */
  23.  
  24. #include "util/u_math.h"
  25. #include "util/macros.h"
  26. #include "vc4_context.h"
  27.  
  28. #define dump_VC4_PACKET_LINE_WIDTH dump_float
  29. #define dump_VC4_PACKET_POINT_SIZE dump_float
  30.  
  31. static void
  32. dump_float(void *cl, uint32_t offset, uint32_t hw_offset)
  33. {
  34.         void *f = cl + offset;
  35.  
  36.         fprintf(stderr, "0x%08x 0x%08x:      %f (0x%08x)\n",
  37.                 offset, hw_offset, *(float *)f, *(uint32_t *)f);
  38. }
  39.  
  40. static void
  41. dump_VC4_PACKET_BRANCH_TO_SUB_LIST(void *cl, uint32_t offset, uint32_t hw_offset)
  42. {
  43.         uint32_t *addr = cl + offset;
  44.  
  45.         fprintf(stderr, "0x%08x 0x%08x:      addr 0x%08x\n",
  46.                 offset, hw_offset, *addr);
  47. }
  48.  
  49. static void
  50. dump_VC4_PACKET_STORE_TILE_BUFFER_GENERAL(void *cl, uint32_t offset, uint32_t hw_offset)
  51. {
  52.         uint8_t *bytes = cl + offset;
  53.         uint32_t *addr = cl + offset + 2;
  54.  
  55.         const char *fullvg = "";
  56.         const char *fullzs = "";
  57.         const char *fullcolor = "";
  58.         const char *buffer = "???";
  59.  
  60.         switch ((bytes[0] & 0x7)){
  61.         case 0:
  62.                 buffer = "none";
  63.                 break;
  64.         case 1:
  65.                 buffer = "color";
  66.                 break;
  67.         case 2:
  68.                 buffer = "zs";
  69.                 break;
  70.         case 3:
  71.                 buffer = "z";
  72.                 break;
  73.         case 4:
  74.                 buffer = "vgmask";
  75.                 break;
  76.         case 5:
  77.                 buffer = "full";
  78.                 if (*addr & (1 << 0))
  79.                         fullcolor = " !color";
  80.                 if (*addr & (1 << 1))
  81.                         fullzs = " !zs";
  82.                 if (*addr & (1 << 2))
  83.                         fullvg = " !vgmask";
  84.                 break;
  85.         }
  86.  
  87.         const char *tiling = "???";
  88.         switch ((bytes[0] >> 4) & 7) {
  89.         case 0:
  90.                 tiling = "linear";
  91.                 break;
  92.         case 1:
  93.                 tiling = "T";
  94.                 break;
  95.         case 2:
  96.                 tiling = "LT";
  97.                 break;
  98.         }
  99.  
  100.         const char *format = "???";
  101.         switch (bytes[1] & 3) {
  102.         case 0:
  103.                 format = "RGBA8888";
  104.                 break;
  105.         case 1:
  106.                 format = "BGR565_DITHER";
  107.                 break;
  108.         case 2:
  109.                 format = "BGR565";
  110.                 break;
  111.         }
  112.  
  113.         fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s\n",
  114.                 offset + 0, hw_offset + 0, bytes[0],
  115.                 buffer, tiling);
  116.  
  117.         fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
  118.                 offset + 1, hw_offset + 1, bytes[1],
  119.                 format);
  120.  
  121.         fprintf(stderr, "0x%08x 0x%08x:      addr 0x%08x %s%s%s%s\n",
  122.                 offset + 2, hw_offset + 2, *addr & ~15,
  123.                 fullcolor, fullzs, fullvg,
  124.                 (*addr & (1 << 3)) ? " EOF" : "");
  125. }
  126.  
  127. static void
  128. dump_VC4_PACKET_FLAT_SHADE_FLAGS(void *cl, uint32_t offset, uint32_t hw_offset)
  129. {
  130.         uint32_t *bits = cl + offset;
  131.  
  132.         fprintf(stderr, "0x%08x 0x%08x:      bits 0x%08x\n",
  133.                 offset, hw_offset, *bits);
  134. }
  135.  
  136. static void
  137. dump_VC4_PACKET_VIEWPORT_OFFSET(void *cl, uint32_t offset, uint32_t hw_offset)
  138. {
  139.         uint16_t *o = cl + offset;
  140.  
  141.         fprintf(stderr, "0x%08x 0x%08x:      %f, %f (0x%04x, 0x%04x)\n",
  142.                 offset, hw_offset,
  143.                 o[0] / 16.0, o[1] / 16.0,
  144.                 o[0], o[1]);
  145. }
  146.  
  147. static void
  148. dump_VC4_PACKET_CLIPPER_XY_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
  149. {
  150.         uint32_t *scale = cl + offset;
  151.  
  152.         fprintf(stderr, "0x%08x 0x%08x:      %f, %f (%f, %f, 0x%08x, 0x%08x)\n",
  153.                 offset, hw_offset,
  154.                 uif(scale[0]) / 16.0, uif(scale[1]) / 16.0,
  155.                 uif(scale[0]), uif(scale[1]),
  156.                 scale[0], scale[1]);
  157. }
  158.  
  159. static void
  160. dump_VC4_PACKET_CLIPPER_Z_SCALING(void *cl, uint32_t offset, uint32_t hw_offset)
  161. {
  162.         uint32_t *translate = cl + offset;
  163.         uint32_t *scale = cl + offset + 8;
  164.  
  165.         fprintf(stderr, "0x%08x 0x%08x:      %f, %f (0x%08x, 0x%08x)\n",
  166.                 offset, hw_offset,
  167.                 uif(translate[0]), uif(translate[1]),
  168.                 translate[0], translate[1]);
  169.  
  170.         fprintf(stderr, "0x%08x 0x%08x:      %f, %f (0x%08x, 0x%08x)\n",
  171.                 offset + 8, hw_offset + 8,
  172.                 uif(scale[0]), uif(scale[1]),
  173.                 scale[0], scale[1]);
  174. }
  175.  
  176. static void
  177. dump_VC4_PACKET_TILE_RENDERING_MODE_CONFIG(void *cl, uint32_t offset, uint32_t hw_offset)
  178. {
  179.         uint32_t *render_offset = cl + offset;
  180.         uint16_t *shorts = cl + offset + 4;
  181.         uint8_t *bytes = cl + offset + 8;
  182.  
  183.         fprintf(stderr, "0x%08x 0x%08x:       color offset 0x%08x\n",
  184.                 offset, hw_offset,
  185.                 *render_offset);
  186.  
  187.         fprintf(stderr, "0x%08x 0x%08x:       width %d\n",
  188.                 offset + 4, hw_offset + 4,
  189.                 shorts[0]);
  190.  
  191.         fprintf(stderr, "0x%08x 0x%08x:       height %d\n",
  192.                 offset + 6, hw_offset + 6,
  193.                 shorts[1]);
  194.  
  195.         const char *format = "???";
  196.         switch ((bytes[0] >> 2) & 3) {
  197.         case 0:
  198.                 format = "BGR565_DITHERED";
  199.                 break;
  200.         case 1:
  201.                 format = "RGBA8888";
  202.                 break;
  203.         case 2:
  204.                 format = "BGR565";
  205.                 break;
  206.         }
  207.         if (shorts[2] & VC4_RENDER_CONFIG_TILE_BUFFER_64BIT)
  208.                 format = "64bit";
  209.  
  210.         const char *tiling = "???";
  211.         switch ((bytes[0] >> 6) & 3) {
  212.         case 0:
  213.                 tiling = "linear";
  214.                 break;
  215.         case 1:
  216.                 tiling = "T";
  217.                 break;
  218.         case 2:
  219.                 tiling = "LT";
  220.                 break;
  221.         }
  222.  
  223.         fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s %s %s\n",
  224.                 offset + 8, hw_offset + 8,
  225.                 bytes[0],
  226.                 format, tiling,
  227.                 (bytes[0] & VC4_RENDER_CONFIG_MS_MODE_4X) ? "ms" : "ss");
  228.  
  229.         const char *earlyz = "";
  230.         if (bytes[1] & (1 << 3)) {
  231.                 earlyz = "early_z disabled";
  232.         } else {
  233.                 if (bytes[1] & (1 << 2))
  234.                         earlyz = "early_z >";
  235.                 else
  236.                         earlyz = "early_z <";
  237.         }
  238.  
  239.         fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
  240.                 offset + 9, hw_offset + 9,
  241.                 bytes[1],
  242.                 earlyz);
  243. }
  244.  
  245. static void
  246. dump_VC4_PACKET_TILE_COORDINATES(void *cl, uint32_t offset, uint32_t hw_offset)
  247. {
  248.         uint8_t *tilecoords = cl + offset;
  249.  
  250.         fprintf(stderr, "0x%08x 0x%08x:      %d, %d\n",
  251.                 offset, hw_offset, tilecoords[0], tilecoords[1]);
  252. }
  253.  
  254. static void
  255. dump_VC4_PACKET_GEM_HANDLES(void *cl, uint32_t offset, uint32_t hw_offset)
  256. {
  257.         uint32_t *handles = cl + offset;
  258.  
  259.         fprintf(stderr, "0x%08x 0x%08x:      handle 0: %d, handle 1: %d\n",
  260.                 offset, hw_offset, handles[0], handles[1]);
  261. }
  262.  
  263. #define PACKET_DUMP(name, size) [name] = { #name, size, dump_##name }
  264. #define PACKET(name, size) [name] = { #name, size, NULL }
  265.  
  266. static const struct packet_info {
  267.         const char *name;
  268.         uint8_t size;
  269.         void (*dump_func)(void *cl, uint32_t offset, uint32_t hw_offset);
  270. } packet_info[] = {
  271.         PACKET(VC4_PACKET_HALT, 1),
  272.         PACKET(VC4_PACKET_NOP, 1),
  273.  
  274.         PACKET(VC4_PACKET_FLUSH, 1),
  275.         PACKET(VC4_PACKET_FLUSH_ALL, 1),
  276.         PACKET(VC4_PACKET_START_TILE_BINNING, 1),
  277.         PACKET(VC4_PACKET_INCREMENT_SEMAPHORE, 1),
  278.         PACKET(VC4_PACKET_WAIT_ON_SEMAPHORE, 1),
  279.  
  280.         PACKET(VC4_PACKET_BRANCH, 5),
  281.         PACKET_DUMP(VC4_PACKET_BRANCH_TO_SUB_LIST, 5),
  282.  
  283.         PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER, 1),
  284.         PACKET(VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF, 1),
  285.         PACKET(VC4_PACKET_STORE_FULL_RES_TILE_BUFFER, 5),
  286.         PACKET(VC4_PACKET_LOAD_FULL_RES_TILE_BUFFER, 5),
  287.         PACKET_DUMP(VC4_PACKET_STORE_TILE_BUFFER_GENERAL, 7),
  288.         PACKET(VC4_PACKET_LOAD_TILE_BUFFER_GENERAL, 7),
  289.  
  290.         PACKET(VC4_PACKET_GL_INDEXED_PRIMITIVE, 14),
  291.         PACKET(VC4_PACKET_GL_ARRAY_PRIMITIVE, 10),
  292.  
  293.         PACKET(VC4_PACKET_COMPRESSED_PRIMITIVE, 48),
  294.         PACKET(VC4_PACKET_CLIPPED_COMPRESSED_PRIMITIVE, 49),
  295.  
  296.         PACKET(VC4_PACKET_PRIMITIVE_LIST_FORMAT, 2),
  297.  
  298.         PACKET(VC4_PACKET_GL_SHADER_STATE, 5),
  299.         PACKET(VC4_PACKET_NV_SHADER_STATE, 5),
  300.         PACKET(VC4_PACKET_VG_SHADER_STATE, 5),
  301.  
  302.         PACKET(VC4_PACKET_CONFIGURATION_BITS, 4),
  303.         PACKET_DUMP(VC4_PACKET_FLAT_SHADE_FLAGS, 5),
  304.         PACKET_DUMP(VC4_PACKET_POINT_SIZE, 5),
  305.         PACKET_DUMP(VC4_PACKET_LINE_WIDTH, 5),
  306.         PACKET(VC4_PACKET_RHT_X_BOUNDARY, 3),
  307.         PACKET(VC4_PACKET_DEPTH_OFFSET, 5),
  308.         PACKET(VC4_PACKET_CLIP_WINDOW, 9),
  309.         PACKET_DUMP(VC4_PACKET_VIEWPORT_OFFSET, 5),
  310.         PACKET(VC4_PACKET_Z_CLIPPING, 9),
  311.         PACKET_DUMP(VC4_PACKET_CLIPPER_XY_SCALING, 9),
  312.         PACKET_DUMP(VC4_PACKET_CLIPPER_Z_SCALING, 9),
  313.  
  314.         PACKET(VC4_PACKET_TILE_BINNING_MODE_CONFIG, 16),
  315.         PACKET_DUMP(VC4_PACKET_TILE_RENDERING_MODE_CONFIG, 11),
  316.         PACKET(VC4_PACKET_CLEAR_COLORS, 14),
  317.         PACKET_DUMP(VC4_PACKET_TILE_COORDINATES, 3),
  318.  
  319.         PACKET_DUMP(VC4_PACKET_GEM_HANDLES, 9),
  320. };
  321.  
  322. void
  323. vc4_dump_cl(void *cl, uint32_t size, bool is_render)
  324. {
  325.         uint32_t offset = 0, hw_offset = 0;
  326.         uint8_t *cmds = cl;
  327.  
  328.         while (offset < size) {
  329.                 uint8_t header = cmds[offset];
  330.  
  331.                 if (header > ARRAY_SIZE(packet_info) ||
  332.                     !packet_info[header].name) {
  333.                         fprintf(stderr, "0x%08x 0x%08x: Unknown packet 0x%02x (%d)!\n",
  334.                                 offset, hw_offset, header, header);
  335.                         return;
  336.                 }
  337.  
  338.                 const struct packet_info *p = packet_info + header;
  339.                 fprintf(stderr, "0x%08x 0x%08x: 0x%02x %s\n",
  340.                         offset,
  341.                         header != VC4_PACKET_GEM_HANDLES ? hw_offset : 0,
  342.                         header, p->name);
  343.  
  344.                 if (offset + p->size <= size &&
  345.                     p->dump_func) {
  346.                         p->dump_func(cmds, offset + 1, hw_offset + 1);
  347.                 } else {
  348.                         for (uint32_t i = 1; i < p->size; i++) {
  349.                                 if (offset + i >= size) {
  350.                                         fprintf(stderr, "0x%08x 0x%08x: CL overflow!\n",
  351.                                                 offset + i, hw_offset + i);
  352.                                         return;
  353.                                 }
  354.                                 fprintf(stderr, "0x%08x 0x%08x: 0x%02x\n",
  355.                                         offset + i,
  356.                                         header != VC4_PACKET_GEM_HANDLES ? hw_offset + i : 0,
  357.                                         cmds[offset + i]);
  358.                         }
  359.                 }
  360.  
  361.                 switch (header) {
  362.                 case VC4_PACKET_HALT:
  363.                 case VC4_PACKET_STORE_MS_TILE_BUFFER_AND_EOF:
  364.                         return;
  365.                 default:
  366.                         break;
  367.                 }
  368.  
  369.                 offset += p->size;
  370.                 if (header != VC4_PACKET_GEM_HANDLES)
  371.                         hw_offset += p->size;
  372.         }
  373. }
  374.  
  375.