Path: blob/21.2-virgl/src/freedreno/decode/scripts/tex3d-layout.lua
4573 views
-- Parse logs from test-quad-textured-3d.c to exctract layer/level1-- offsets2--3-- We figure out the offsets from blits, but there may be some4-- unrelated blits. So just save all of them until we find the5-- texture state for the 3d texture. This gives us the base6-- address, and the miplevel #0 width/height/depth. Then work7-- backwards from there finding the blits to the same dst buffer8-- and deducing the miplevel from the minified dimensions910local posix = require "posix"1112io.write("Analyzing Data...\n")1314local allblits = {}15local nallblits = 016local r = rnn.init("a630")1718function minify(val, lvls)19val = val >> lvls20if val < 1 then21return 122end23return val24end2526function printf(fmt, ...)27return io.write(string.format(fmt, ...))28end2930function start_cmdstream(name)31io.write("Parsing " .. name .. "\n")32allblits = {}33nallblits = 034end3536function draw(primtype, nindx)37if primtype ~= "BLIT_OP_SCALE" then38return39end4041-- Just in case, filter out anything that isn't starting42-- at 0,043if r.GRAS_2D_DST_TL.X ~= 0 or r.GRAS_2D_DST_TL.Y ~= 0 then44return45end4647local blit = {}4849blit.width = r.GRAS_2D_DST_BR.X + 150blit.height = r.GRAS_2D_DST_BR.Y + 151blit.pitch = r.RB_2D_DST_SIZE.PITCH52blit.addr = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)53blit.base = bos.base(blit.addr)54blit.endaddr = 0 -- filled in later55--printf("Found blit: 0x%x (0x%x)\n", blit.addr, blit.base)5657allblits[nallblits] = blit58nallblits = nallblits + 159end6061function A6XX_TEX_CONST(pkt, size)62-- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we63-- are looking for64if pkt[5].DEPTH <= 1 then65return66end6768local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)69local width0 = pkt[1].WIDTH70local height0 = pkt[1].HEIGHT71local depth0 = pkt[5].DEPTH7273printf("Found texture state: %ux%ux%u (MIN_LAYERSZ=0x%x)\n",74width0, height0, depth0, pkt[3].MIN_LAYERSZ)7576-- Note that in some case the texture has some extra page or so77-- at the beginning:78local basebase = bos.base(base)79printf("base: 0x%x (0x%x)\n", base, basebase)8081-- see if we can find the associated blits.. The blob always seems to82-- start from the lower (larger) mipmap levels and layers, so we don't83-- need to sort by dst address. Also, while we are at it, fill in the84-- end-addr (at least for everything but the last blit)85local blits = {}86local nblits = 087local lastblit = nil88for n = 0,nallblits-1 do89local blit = allblits[n]90--printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)91if blit.base == basebase and blit.addr >= base then92blits[nblits] = blit93nblits = nblits + 194if lastblit then95lastblit.endaddr = blit.addr96end97lastblit = blit98end99end100101-- now go thru the relevant blits and print out interesting details102local level = 0103local layer = 0104local w = width0 -- track current width/height to detect changing105local h = height0 -- mipmap level106for n = 0,nblits-1 do107local blit = blits[n]108--printf("%u: %ux%u, addr=%x\n", n, blit.width, blit.height, blit.addr)109if w ~= blit.width or h ~= blit.height then110level = level + 1111layer = 0112113if blit.width ~= minify(w, 1) or blit.height ~= minify(h, 1) then114printf("I am confused! %ux%u vs %ux%u\n", blit.width, blit.height, minify(w, 1), minify(h, 1))115printf("addr=%x\n", blit.addr)116--return117end118119w = blit.width120h = blit.height121end122123printf("level=%u, layer=%u, sz=%ux%u, pitch=%u, offset=0x%x, addr=%x",124level, layer, w, h, blit.pitch, blit.addr - base, blit.addr)125if blit.endaddr ~= 0 then126local layersz = blit.endaddr - blit.addr127local alignedheight = layersz / blit.pitch128printf(", layersz=0x%x, alignedheight=%f", layersz, alignedheight)129end130printf("\n")131132layer = layer + 1133end134printf("\n\n")135end136137138139