1 -- Parse logs from https://github.com/freedreno/freedreno/
2 -- test-texturator.c to generate a src/freedreno/fdl/fd5_layout_test.c
3 -- block. We figure out the offsets from blits, but there may be some
4 -- unrelated blits. So just save all of them until we find the
5 -- texture state. This gives us the base address, and the miplevel #0
6 -- width/height/depth. Then work backwards from there finding the
7 -- blits to the same dst buffer and deducing the miplevel from the
10 local posix = require "posix"
12 io.write("Analyzing Data...\n")
14 local r = rnn.init("a530")
20 function get_first_blit(base, width, height)
21 local first_blit = nil
23 for n = 0,nallblits-1 do
24 local blit = allblits[n]
25 if blit.base == base and blit.width == width and blit.height == height then
26 if not first_blit or blit.addr < first_blit.addr then
35 function minify(val, lvls)
43 function printf(fmt, ...)
44 return io.write(string.format(fmt, ...))
47 function start_cmdstream(name)
48 io.write("Parsing " .. name .. "\n")
53 -- Record texture upload blits done through CP_EVENT_WRITE
54 function CP_EVENT_WRITE(pkt, size)
55 if tostring(pkt[0].EVENT) ~= "BLIT" then
61 blit.width = r.RB_RESOLVE_CNTL_2.X + 1
62 blit.height = r.RB_RESOLVE_CNTL_2.Y + 1
63 blit.pitch = r.RB_BLIT_DST_PITCH
64 blit.addr = r.RB_BLIT_DST_LO | (r.RB_BLIT_DST_HI << 32)
65 blit.base = bos.base(blit.addr)
66 blit.ubwc_addr = r.RB_BLIT_FLAG_DST_LO | (r.RB_BLIT_FLAG_DST_HI << 32)
67 blit.ubwc_base = bos.base(blit.ubwc_addr)
68 blit.ubwc_pitch = r.RB_BLIT_FLAG_DST_PITCH
69 blit.endaddr = 0 -- filled in later
70 printf("Found event blit: 0x%x (0x%x) %dx%d UBWC 0x%x (0x%x) tiled %s\n", blit.addr, blit.base, blit.width, blit.height, blit.ubwc_addr, blit.ubwc_base, r.RB_RESOLVE_CNTL_3.TILED)
72 allblits[nallblits] = blit
73 nallblits = nallblits + 1
76 function CP_BLIT(pkt, size)
77 -- Just in case, filter out anything that isn't starting
79 if pkt[1].SRC_X1 ~= 0 or pkt[1].SRC_Y1 ~= 0 then
85 blit.width = pkt[2].SRC_X2 + 1
86 blit.height = pkt[2].SRC_Y2 + 1
87 blit.pitch = r.RB_2D_DST_SIZE.PITCH
88 blit.addr = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)
89 blit.base = bos.base(blit.addr)
90 blit.ubwc_addr = r.RB_2D_DST_FLAGS_LO | (r.RB_2D_DST_FLAGS_HI << 32)
91 blit.ubwc_base = bos.base(blit.ubwc_addr)
92 blit.ubwc_pitch = r.RB_2D_DST_FLAGS_PITCH
93 blit.endaddr = 0 -- filled in later
94 printf("Found cp blit: 0x%x (0x%x) %dx%d UBWC 0x%x (0x%x) %s\n", blit.addr, blit.base, blit.width, blit.height, blit.ubwc_addr, blit.ubwc_base, r.RB_2D_DST_INFO.TILE_MODE)
96 allblits[nallblits] = blit
97 nallblits = nallblits + 1
100 function A5XX_TEX_CONST(pkt, size)
101 -- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we
104 local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)
105 -- UBWC base on a5xx seems to be at the start of each miplevel, followed by pixels
106 -- somewhere past that.
107 local ubwc_base = base
108 local width0 = pkt[1].WIDTH
109 local height0 = pkt[1].HEIGHT
110 local depth0 = pkt[5].DEPTH
112 if (found_tex ~= 0) then
117 printf("Found texture state:\n %ux%ux%u (%s, %s, UBWC=%s)\n",
118 width0, height0, depth0, pkt[0].FMT, pkt[0].TILE_MODE, tostring(pkt[3].FLAG))
120 -- Note that in some case the texture has some extra page or so
122 local basebase = bos.base(base)
123 printf("base: 0x%x (0x%x)\n", base, basebase)
124 printf("ubwcbase: 0x%x (0x%x)\n", ubwc_base, bos.base(ubwc_base))
126 -- see if we can find the associated blits.. The blob always seems to
127 -- start from the lower (larger) mipmap levels and layers, so we don't
128 -- need to sort by dst address. Also, while we are at it, fill in the
129 -- end-addr (at least for everything but the last blit)
133 for n = 0,nallblits-1 do
134 local blit = allblits[n]
135 --printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)
136 if blit.base == basebase and blit.addr >= base then
140 lastblit.endaddr = blit.addr
147 printf(" .format = %s,\n", pkt[0].FMT)
148 if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then
149 printf(" .is_3d = true,\n")
152 printf(" .layout = {\n")
153 printf(" .tile_mode = %s,\n", pkt[0].TILE_MODE)
154 printf(" .ubwc = %s,\n", tostring(pkt[3].FLAG))
156 if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then
157 printf(" .width0 = %d, .height0 = %d, .depth0 = %d,\n", width0, height0, depth0)
159 printf(" .width0 = %d, .height0 = %d,\n", width0, height0)
162 printf(" .slices = {\n")
167 local w = minify(width0, level)
168 local h = minify(height0, level)
169 local blit = get_first_blit(basebase, w, h)
171 printf(" { .offset = %d, .pitch = %u },\n",
176 until w == 1 and h == 1
180 printf(" .ubwc_slices = {\n")
183 local w = minify(width0, level)
184 local h = minify(height0, level)
185 local blit = get_first_blit(basebase, w, h)
187 printf(" { .offset = %d, .pitch = %u },\n",
188 blit.ubwc_addr - ubwc_base,
192 until w == 1 and h == 1