1 -- Parse logs from test-quad-textured-3d.c to exctract layer/level
4 -- We figure out the offsets from blits, but there may be some
5 -- unrelated blits. So just save all of them until we find the
6 -- texture state for the 3d texture. This gives us the base
7 -- address, and the miplevel #0 width/height/depth. Then work
8 -- backwards from there finding the blits to the same dst buffer
9 -- and deducing the miplevel from the minified dimensions
11 local posix = require "posix"
13 io.write("Analyzing Data...\n")
17 local r = rnn.init("a630")
19 function minify(val, lvls)
27 function printf(fmt, ...)
28 return io.write(string.format(fmt, ...))
31 function start_cmdstream(name)
32 io.write("Parsing " .. name .. "\n")
37 function draw(primtype, nindx)
38 if primtype ~= "BLIT_OP_SCALE" then
42 -- Just in case, filter out anything that isn't starting
44 if r.GRAS_2D_DST_TL.X ~= 0 or r.GRAS_2D_DST_TL.Y ~= 0 then
50 blit.width = r.GRAS_2D_DST_BR.X + 1
51 blit.height = r.GRAS_2D_DST_BR.Y + 1
52 blit.pitch = r.RB_2D_DST_SIZE.PITCH
53 blit.addr = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)
54 blit.base = bos.base(blit.addr)
55 blit.endaddr = 0 -- filled in later
56 --printf("Found blit: 0x%x (0x%x)\n", blit.addr, blit.base)
58 allblits[nallblits] = blit
59 nallblits = nallblits + 1
62 function A6XX_TEX_CONST(pkt, size)
63 -- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we
65 if pkt[5].DEPTH <= 1 then
69 local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)
70 local width0 = pkt[1].WIDTH
71 local height0 = pkt[1].HEIGHT
72 local depth0 = pkt[5].DEPTH
74 printf("Found texture state: %ux%ux%u (MIN_LAYERSZ=0x%x)\n",
75 width0, height0, depth0, pkt[3].MIN_LAYERSZ)
77 -- Note that in some case the texture has some extra page or so
79 local basebase = bos.base(base)
80 printf("base: 0x%x (0x%x)\n", base, basebase)
82 -- see if we can find the associated blits.. The blob always seems to
83 -- start from the lower (larger) mipmap levels and layers, so we don't
84 -- need to sort by dst address. Also, while we are at it, fill in the
85 -- end-addr (at least for everything but the last blit)
89 for n = 0,nallblits-1 do
90 local blit = allblits[n]
91 --printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)
92 if blit.base == basebase and blit.addr >= base then
96 lastblit.endaddr = blit.addr
102 -- now go thru the relevant blits and print out interesting details
105 local w = width0 -- track current width/height to detect changing
106 local h = height0 -- mipmap level
107 for n = 0,nblits-1 do
108 local blit = blits[n]
109 --printf("%u: %ux%u, addr=%x\n", n, blit.width, blit.height, blit.addr)
110 if w ~= blit.width or h ~= blit.height then
114 if blit.width ~= minify(w, 1) or blit.height ~= minify(h, 1) then
115 printf("I am confused! %ux%u vs %ux%u\n", blit.width, blit.height, minify(w, 1), minify(h, 1))
116 printf("addr=%x\n", blit.addr)
124 printf("level=%u, layer=%u, sz=%ux%u, pitch=%u, offset=0x%x, addr=%x",
125 level, layer, w, h, blit.pitch, blit.addr - base, blit.addr)
126 if blit.endaddr ~= 0 then
127 local layersz = blit.endaddr - blit.addr
128 local alignedheight = layersz / blit.pitch
129 printf(", layersz=0x%x, alignedheight=%f", layersz, alignedheight)