1-- Parse logs from test-quad-textured-3d.c to exctract layer/level 2-- offsets 3-- 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 10 11local posix = require "posix" 12 13io.write("Analyzing Data...\n") 14 15local allblits = {} 16local nallblits = 0 17local r = rnn.init("a630") 18 19function minify(val, lvls) 20 val = val >> lvls 21 if val < 1 then 22 return 1 23 end 24 return val 25end 26 27function printf(fmt, ...) 28 return io.write(string.format(fmt, ...)) 29end 30 31function start_cmdstream(name) 32 io.write("Parsing " .. name .. "\n") 33 allblits = {} 34 nallblits = 0 35end 36 37function 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.endaddr = 0 -- filled in later 56 --printf("Found blit: 0x%x (0x%x)\n", blit.addr, blit.base) 57 58 allblits[nallblits] = blit 59 nallblits = nallblits + 1 60end 61 62function A6XX_TEX_CONST(pkt, size) 63 -- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we 64 -- are looking for 65 if pkt[5].DEPTH <= 1 then 66 return 67 end 68 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 73 74 printf("Found texture state: %ux%ux%u (MIN_LAYERSZ=0x%x)\n", 75 width0, height0, depth0, pkt[3].MIN_LAYERSZ) 76 77 -- Note that in some case the texture has some extra page or so 78 -- at the beginning: 79 local basebase = bos.base(base) 80 printf("base: 0x%x (0x%x)\n", base, basebase) 81 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) 86 local blits = {} 87 local nblits = 0 88 local lastblit = nil 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 93 blits[nblits] = blit 94 nblits = nblits + 1 95 if lastblit then 96 lastblit.endaddr = blit.addr 97 end 98 lastblit = blit 99 end 100 end 101 102 -- now go thru the relevant blits and print out interesting details 103 local level = 0 104 local layer = 0 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 111 level = level + 1 112 layer = 0 113 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) 117 --return 118 end 119 120 w = blit.width 121 h = blit.height 122 end 123 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) 130 end 131 printf("\n") 132 133 layer = layer + 1 134 end 135 printf("\n\n") 136end 137 138