Path: blob/21.2-virgl/src/freedreno/decode/scripts/texturator-to-unit-test-5xx.lua
4573 views
-- Parse logs from https://github.com/freedreno/freedreno/1-- test-texturator.c to generate a src/freedreno/fdl/fd5_layout_test.c2-- block. We figure out the offsets from blits, but there may be some3-- unrelated blits. So just save all of them until we find the4-- texture state. This gives us the base address, and the miplevel #05-- width/height/depth. Then work backwards from there finding the6-- blits to the same dst buffer and deducing the miplevel from the7-- minified dimensions89local posix = require "posix"1011io.write("Analyzing Data...\n")1213local r = rnn.init("a530")14local found_tex = 01516local allblits = {}17local nallblits = 01819function get_first_blit(base, width, height)20local first_blit = nil2122for n = 0,nallblits-1 do23local blit = allblits[n]24if blit.base == base and blit.width == width and blit.height == height then25if not first_blit or blit.addr < first_blit.addr then26first_blit = blit27end28end29end3031return first_blit32end3334function minify(val, lvls)35val = val >> lvls36if val < 1 then37return 138end39return val40end4142function printf(fmt, ...)43return io.write(string.format(fmt, ...))44end4546function start_cmdstream(name)47io.write("Parsing " .. name .. "\n")48allblits = {}49nallblits = 050end5152-- Record texture upload blits done through CP_EVENT_WRITE53function CP_EVENT_WRITE(pkt, size)54if tostring(pkt[0].EVENT) ~= "BLIT" then55return56end5758local blit = {}5960blit.width = r.RB_RESOLVE_CNTL_2.X + 161blit.height = r.RB_RESOLVE_CNTL_2.Y + 162blit.pitch = r.RB_BLIT_DST_PITCH63blit.addr = r.RB_BLIT_DST_LO | (r.RB_BLIT_DST_HI << 32)64blit.base = bos.base(blit.addr)65blit.ubwc_addr = r.RB_BLIT_FLAG_DST_LO | (r.RB_BLIT_FLAG_DST_HI << 32)66blit.ubwc_base = bos.base(blit.ubwc_addr)67blit.ubwc_pitch = r.RB_BLIT_FLAG_DST_PITCH68blit.endaddr = 0 -- filled in later69printf("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)7071allblits[nallblits] = blit72nallblits = nallblits + 173end7475function CP_BLIT(pkt, size)76-- Just in case, filter out anything that isn't starting77-- at 0,078if pkt[1].SRC_X1 ~= 0 or pkt[1].SRC_Y1 ~= 0 then79return80end8182local blit = {}8384blit.width = pkt[2].SRC_X2 + 185blit.height = pkt[2].SRC_Y2 + 186blit.pitch = r.RB_2D_DST_SIZE.PITCH87blit.addr = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)88blit.base = bos.base(blit.addr)89blit.ubwc_addr = r.RB_2D_DST_FLAGS_LO | (r.RB_2D_DST_FLAGS_HI << 32)90blit.ubwc_base = bos.base(blit.ubwc_addr)91blit.ubwc_pitch = r.RB_2D_DST_FLAGS_PITCH92blit.endaddr = 0 -- filled in later93printf("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)9495allblits[nallblits] = blit96nallblits = nallblits + 197end9899function A5XX_TEX_CONST(pkt, size)100-- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we101-- are looking for102103local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)104-- UBWC base on a5xx seems to be at the start of each miplevel, followed by pixels105-- somewhere past that.106local ubwc_base = base107local width0 = pkt[1].WIDTH108local height0 = pkt[1].HEIGHT109local depth0 = pkt[5].DEPTH110111if (found_tex ~= 0) then112return113end114found_tex = 1115116printf("Found texture state:\n %ux%ux%u (%s, %s, UBWC=%s)\n",117width0, height0, depth0, pkt[0].FMT, pkt[0].TILE_MODE, tostring(pkt[3].FLAG))118119-- Note that in some case the texture has some extra page or so120-- at the beginning:121local basebase = bos.base(base)122printf("base: 0x%x (0x%x)\n", base, basebase)123printf("ubwcbase: 0x%x (0x%x)\n", ubwc_base, bos.base(ubwc_base))124125-- see if we can find the associated blits.. The blob always seems to126-- start from the lower (larger) mipmap levels and layers, so we don't127-- need to sort by dst address. Also, while we are at it, fill in the128-- end-addr (at least for everything but the last blit)129local blits = {}130local nblits = 0131local lastblit = nil132for n = 0,nallblits-1 do133local blit = allblits[n]134--printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)135if blit.base == basebase and blit.addr >= base then136blits[nblits] = blit137nblits = nblits + 1138if lastblit then139lastblit.endaddr = blit.addr140end141lastblit = blit142end143end144145printf(" {\n")146printf(" .format = %s,\n", pkt[0].FMT)147if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then148printf(" .is_3d = true,\n")149end150151printf(" .layout = {\n")152printf(" .tile_mode = %s,\n", pkt[0].TILE_MODE)153printf(" .ubwc = %s,\n", tostring(pkt[3].FLAG))154155if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then156printf(" .width0 = %d, .height0 = %d, .depth0 = %d,\n", width0, height0, depth0)157else158printf(" .width0 = %d, .height0 = %d,\n", width0, height0)159end160161printf(" .slices = {\n")162local w = 0163local h = 0164local level = 0165repeat166local w = minify(width0, level)167local h = minify(height0, level)168local blit = get_first_blit(basebase, w, h)169if blit then170printf(" { .offset = %d, .pitch = %u },\n",171blit.addr - base,172blit.pitch);173end174level = level + 1175until w == 1 and h == 1176printf(" },\n")177178if pkt[3].FLAG then179printf(" .ubwc_slices = {\n")180level = 0181repeat182local w = minify(width0, level)183local h = minify(height0, level)184local blit = get_first_blit(basebase, w, h)185if blit then186printf(" { .offset = %d, .pitch = %u },\n",187blit.ubwc_addr - ubwc_base,188blit.ubwc_pitch);189end190level = level + 1191until w == 1 and h == 1192printf(" },\n")193end194195printf(" },\n")196printf(" },\n")197printf("\n\n")198end199200201202