Skip to content

Commit 6c2606d

Browse files
committed
Fork a copy of tex3d-layout to parse texturator output.
1 parent cb73acd commit 6c2606d

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed
+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
-- Parse logs from https://github.com/freedreno/freedreno/
2+
-- test-texturator.c to generate a src/freedreno/fdl/fd6_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
8+
-- minified dimensions
9+
10+
local posix = require "posix"
11+
12+
io.write("Analyzing Data...\n")
13+
14+
local allblits = {}
15+
local nallblits = 0
16+
local r = rnn.init("a630")
17+
local found_tex = 0
18+
19+
function minify(val, lvls)
20+
val = val >> lvls
21+
if val < 1 then
22+
return 1
23+
end
24+
return val
25+
end
26+
27+
function printf(fmt, ...)
28+
return io.write(string.format(fmt, ...))
29+
end
30+
31+
function start_cmdstream(name)
32+
io.write("Parsing " .. name .. "\n")
33+
allblits = {}
34+
nallblits = 0
35+
end
36+
37+
function draw(primtype, nindx)
38+
if primtype ~= "BLIT_OP_SCALE" then
39+
return
40+
end
41+
42+
-- Just in case, filter out anything that isn't starting
43+
-- at 0,0
44+
if r.GRAS_2D_DST_TL.X ~= 0 or r.GRAS_2D_DST_TL.Y ~= 0 then
45+
return
46+
end
47+
48+
local blit = {}
49+
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.ubwc_addr = r.RB_2D_DST_FLAGS_LO | (r.RB_2D_DST_FLAGS_HI << 32)
56+
blit.ubwc_base = bos.base(blit.uwbc_addr)
57+
blit.ubwc_pitch = r.RB_2D_DST_FLAGS_PITCH.PITCH
58+
blit.endaddr = 0 -- filled in later
59+
printf("Found blit: 0x%x (0x%x) %dx%d\n", blit.addr, blit.base, blit.width, blit.height)
60+
61+
allblits[nallblits] = blit
62+
nallblits = nallblits + 1
63+
end
64+
65+
function A6XX_TEX_CONST(pkt, size)
66+
-- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we
67+
-- are looking for
68+
69+
local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)
70+
local ubwc_base = pkt[7].FLAG_LO | (pkt[8].FLAG_HI << 32)
71+
local width0 = pkt[1].WIDTH
72+
local height0 = pkt[1].HEIGHT
73+
local depth0 = pkt[5].DEPTH
74+
75+
if (found_tex ~= 0) then
76+
return
77+
end
78+
found_tex = 1
79+
80+
printf("Found texture state:\n %ux%ux%u (%s, %s, MIN_LAYERSZ=0x%x, TILE_ALL=%s, UBWC=%s FLAG_LOG2=%ux%u)\n",
81+
width0, height0, depth0, pkt[0].FMT, pkt[0].TILE_MODE, pkt[3].MIN_LAYERSZ, tostring(pkt[3].TILE_ALL), tostring(pkt[3].FLAG), pkt[10].FLAG_BUFFER_LOGW, pkt[10].FLAG_BUFFER_LOGH)
82+
83+
-- Note that in some case the texture has some extra page or so
84+
-- at the beginning:
85+
local basebase = bos.base(base)
86+
printf("base: 0x%x (0x%x)\n", base, basebase)
87+
printf("ubwcbase: 0x%x (0x%x)\n", ubwc_base, bos.base(ubwc_base))
88+
89+
-- see if we can find the associated blits.. The blob always seems to
90+
-- start from the lower (larger) mipmap levels and layers, so we don't
91+
-- need to sort by dst address. Also, while we are at it, fill in the
92+
-- end-addr (at least for everything but the last blit)
93+
local blits = {}
94+
local nblits = 0
95+
local lastblit = nil
96+
for n = 0,nallblits-1 do
97+
local blit = allblits[n]
98+
--printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)
99+
if blit.base == basebase and blit.addr >= base then
100+
blits[nblits] = blit
101+
nblits = nblits + 1
102+
if lastblit then
103+
lastblit.endaddr = blit.addr
104+
end
105+
lastblit = blit
106+
end
107+
end
108+
109+
-- now go thru the relevant blits and print out interesting details
110+
local level = 0
111+
local layer = 0
112+
local w = width0 -- track current width/height to detect changing
113+
local h = height0 -- mipmap level
114+
115+
printf(" {\n")
116+
printf(" .format = %s,\n", pkt[0].FMT)
117+
118+
printf(" .layout = {\n")
119+
printf(" .tile_mode = %s,\n", pkt[0].TILE_MODE)
120+
printf(" .ubwc = %s,\n", tostring(pkt[3].FLAG))
121+
printf(" .width0 = %d, .height0 = %d,\n", width0, height0)
122+
printf(" .slices = {\n")
123+
for n = 0,nblits-1 do
124+
local blit = blits[n]
125+
--printf("%u: %ux%u, addr=%x\n", n, blit.width, blit.height, blit.addr)
126+
if w ~= blit.width or h ~= blit.height then
127+
level = level + 1
128+
layer = 0
129+
130+
131+
if blit.width ~= minify(w, 1) or blit.height ~= minify(h, 1) then
132+
printf("I am confused! %ux%u vs %ux%u\n", blit.width, blit.height, minify(w, 1), minify(h, 1))
133+
printf("addr=%x\n", blit.addr)
134+
--return
135+
end
136+
137+
w = blit.width
138+
h = blit.height
139+
end
140+
141+
printf(" { .offset = %d, .pitch = %u },\n",
142+
blit.addr - base,
143+
blit.pitch
144+
);
145+
146+
layer = layer + 1
147+
end
148+
printf(" },\n")
149+
150+
layer = 0
151+
level = 0
152+
w = width0
153+
h = height0
154+
155+
printf(" .ubwc_slices = {\n")
156+
for n = 0,nblits-1 do
157+
local blit = blits[n]
158+
--printf("%u: %ux%u, addr=%x\n", n, blit.width, blit.height, blit.addr)
159+
if w ~= blit.width or h ~= blit.height then
160+
level = level + 1
161+
layer = 0
162+
163+
if blit.width ~= minify(w, 1) or blit.height ~= minify(h, 1) then
164+
printf("I am confused! %ux%u vs %ux%u\n", blit.width, blit.height, minify(w, 1), minify(h, 1))
165+
printf("addr=%x\n", blit.addr)
166+
--return
167+
end
168+
169+
w = blit.width
170+
h = blit.height
171+
end
172+
173+
printf(" { .offset = %d, .pitch = %u },\n",
174+
blit.ubwc_addr - ubwc_base,
175+
blit.ubwc_pitch
176+
);
177+
178+
layer = layer + 1
179+
end
180+
181+
printf(" },\n")
182+
printf(" },\n")
183+
printf(" },\n")
184+
printf("\n\n")
185+
end
186+

0 commit comments

Comments
 (0)