summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2015-08-09 14:16:30 -0700
committerEric Anholt <eric@anholt.net>2015-12-11 17:03:03 -0800
commit38c770ec29d937cbb05f5a164efb2691199d40f7 (patch)
tree19898448cd1b3137460fd7efa551cd629adef96d
parentd8450616d9eb681876ba58bc9d1831b96467aaa1 (diff)
vc4: Add debug dumping of MSAA surfaces.
(cherry picked from commit a69ac4e89c1c3edc33eb4e9361229a3f25de3ee6)
-rw-r--r--src/gallium/drivers/vc4/kernel/vc4_packet.h2
-rw-r--r--src/gallium/drivers/vc4/vc4_resource.c149
2 files changed, 145 insertions, 6 deletions
diff --git a/src/gallium/drivers/vc4/kernel/vc4_packet.h b/src/gallium/drivers/vc4/kernel/vc4_packet.h
index 9c12d331f61..8e4fd364ece 100644
--- a/src/gallium/drivers/vc4/kernel/vc4_packet.h
+++ b/src/gallium/drivers/vc4/kernel/vc4_packet.h
@@ -123,6 +123,8 @@ enum vc4_packet {
/* Number of multisamples supported. */
#define VC4_MAX_SAMPLES 4
+/* Size of a full resolution color or Z tile buffer load/store. */
+#define VC4_TILE_BUFFER_SIZE (64 * 64 * 4)
#define VC4_MASK(high, low) (((1 << ((high) - (low) + 1)) - 1) << (low))
/* Using the GNU statement expression extension */
diff --git a/src/gallium/drivers/vc4/vc4_resource.c b/src/gallium/drivers/vc4/vc4_resource.c
index 43d9ca81bf0..90f8f31f08f 100644
--- a/src/gallium/drivers/vc4/vc4_resource.c
+++ b/src/gallium/drivers/vc4/vc4_resource.c
@@ -507,13 +507,9 @@ vc4_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurf)
FREE(psurf);
}
-/** Debug routine to dump the contents of an 8888 surface to the console */
-void
-vc4_dump_surface(struct pipe_surface *psurf)
+static void
+vc4_dump_surface_non_msaa(struct pipe_surface *psurf)
{
- if (!psurf)
- return;
-
struct pipe_resource *prsc = psurf->texture;
struct vc4_resource *rsc = vc4_resource(prsc);
uint32_t *map = vc4_bo_map(rsc->bo);
@@ -607,6 +603,147 @@ vc4_dump_surface(struct pipe_surface *psurf)
}
}
+static uint32_t
+vc4_surface_msaa_get_sample(struct pipe_surface *psurf,
+ uint32_t x, uint32_t y, uint32_t sample)
+{
+ struct pipe_resource *prsc = psurf->texture;
+ struct vc4_resource *rsc = vc4_resource(prsc);
+ uint32_t tile_w = 32, tile_h = 32;
+ uint32_t tiles_w = DIV_ROUND_UP(psurf->width, 32);
+
+ uint32_t tile_x = x / tile_w;
+ uint32_t tile_y = y / tile_h;
+ uint32_t *tile = (vc4_bo_map(rsc->bo) +
+ VC4_TILE_BUFFER_SIZE * (tile_y * tiles_w + tile_x));
+ uint32_t subtile_x = x % tile_w;
+ uint32_t subtile_y = y % tile_h;
+
+ uint32_t quad_samples = VC4_MAX_SAMPLES * 4;
+ uint32_t tile_stride = quad_samples * tile_w / 2;
+
+ return *((uint32_t *)tile +
+ (subtile_y >> 1) * tile_stride +
+ (subtile_x >> 1) * quad_samples +
+ ((subtile_y & 1) << 1) +
+ (subtile_x & 1) +
+ sample);
+}
+
+static void
+vc4_dump_surface_msaa_char(struct pipe_surface *psurf,
+ uint32_t start_x, uint32_t start_y,
+ uint32_t w, uint32_t h)
+{
+ bool all_same_color = true;
+ uint32_t all_pix = 0;
+
+ for (int y = start_y; y < start_y + h; y++) {
+ for (int x = start_x; x < start_x + w; x++) {
+ for (int s = 0; s < VC4_MAX_SAMPLES; s++) {
+ uint32_t pix = vc4_surface_msaa_get_sample(psurf,
+ x, y,
+ s);
+ if (x == start_x && y == start_y)
+ all_pix = pix;
+ else if (all_pix != pix)
+ all_same_color = false;
+ }
+ }
+ }
+ if (all_same_color) {
+ static const struct {
+ uint32_t val;
+ const char *c;
+ } named_colors[] = {
+ { 0xff000000, "█" },
+ { 0x00000000, "█" },
+ { 0xffff0000, "r" },
+ { 0xff00ff00, "g" },
+ { 0xff0000ff, "b" },
+ { 0xffffffff, "w" },
+ };
+ int i;
+ for (i = 0; i < ARRAY_SIZE(named_colors); i++) {
+ if (named_colors[i].val == all_pix) {
+ fprintf(stderr, "%s",
+ named_colors[i].c);
+ return;
+ }
+ }
+ fprintf(stderr, "x");
+ } else {
+ fprintf(stderr, ".");
+ }
+}
+
+static void
+vc4_dump_surface_msaa(struct pipe_surface *psurf)
+{
+ uint32_t tile_w = 32, tile_h = 32;
+ uint32_t tiles_w = DIV_ROUND_UP(psurf->width, tile_w);
+ uint32_t tiles_h = DIV_ROUND_UP(psurf->height, tile_h);
+ uint32_t char_w = 140, char_h = 60;
+ uint32_t char_w_per_tile = char_w / tiles_w - 1;
+ uint32_t char_h_per_tile = char_h / tiles_h - 1;
+ uint32_t found_colors[10];
+ uint32_t num_found_colors = 0;
+
+ fprintf(stderr, "Surface: %dx%d (%dx MSAA)\n",
+ psurf->width, psurf->height, psurf->texture->nr_samples);
+
+ for (int x = 0; x < (char_w_per_tile + 1) * tiles_w; x++)
+ fprintf(stderr, "-");
+ fprintf(stderr, "\n");
+
+ for (int ty = 0; ty < psurf->height; ty += tile_h) {
+ for (int y = 0; y < char_h_per_tile; y++) {
+
+ for (int tx = 0; tx < psurf->width; tx += tile_w) {
+ for (int x = 0; x < char_w_per_tile; x++) {
+ uint32_t bx1 = (x * tile_w /
+ char_w_per_tile);
+ uint32_t bx2 = ((x + 1) * tile_w /
+ char_w_per_tile);
+ uint32_t by1 = (y * tile_h /
+ char_h_per_tile);
+ uint32_t by2 = ((y + 1) * tile_h /
+ char_h_per_tile);
+
+ vc4_dump_surface_msaa_char(psurf,
+ tx + bx1,
+ ty + by1,
+ bx2 - bx1,
+ by2 - by1);
+ }
+ fprintf(stderr, "|");
+ }
+ fprintf(stderr, "\n");
+ }
+
+ for (int x = 0; x < (char_w_per_tile + 1) * tiles_w; x++)
+ fprintf(stderr, "-");
+ fprintf(stderr, "\n");
+ }
+
+ for (int i = 0; i < num_found_colors; i++) {
+ fprintf(stderr, "color %d: 0x%08x\n", i, found_colors[i]);
+ }
+}
+
+/** Debug routine to dump the contents of an 8888 surface to the console */
+void
+vc4_dump_surface(struct pipe_surface *psurf)
+{
+ if (!psurf)
+ return;
+
+ if (psurf->texture->nr_samples)
+ vc4_dump_surface_msaa(psurf);
+ else
+ vc4_dump_surface_non_msaa(psurf);
+}
+
static void
vc4_flush_resource(struct pipe_context *pctx, struct pipe_resource *resource)
{