Path: blob/21.2-virgl/src/freedreno/decode/scripts/texturator-to-unit-test.lua
4573 views
-- Parse logs from https://github.com/freedreno/freedreno/1-- test-texturator.c to generate a src/freedreno/fdl/fd6_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("a630")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 = 050end5152function draw(primtype, nindx)53local blit = {}5455local type = "???";56if primtype == "BLIT_OP_SCALE" then57-- Just in case, filter out anything that isn't starting58-- at 0,059if r.GRAS_2D_DST_TL.X ~= 0 or r.GRAS_2D_DST_TL.Y ~= 0 then60return61end6263blit.width = r.GRAS_2D_DST_BR.X + 164blit.height = r.GRAS_2D_DST_BR.Y + 165blit.pitch = r.RB_2D_DST_PITCH66blit.addr = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)67blit.ubwc_addr = r.RB_2D_DST_FLAGS_LO | (r.RB_2D_DST_FLAGS_HI << 32)68blit.ubwc_pitch = r.RB_2D_DST_FLAGS_PITCH69type="blit";70else71blit.width = r.GRAS_SC_WINDOW_SCISSOR_BR.X + 172blit.height = r.GRAS_SC_WINDOW_SCISSOR_BR.Y + 173blit.pitch = r.RB_MRT[0].PITCH74blit.addr = r.RB_MRT[0].BASE_LO | (r.RB_MRT[0].BASE_HI << 32);75blit.ubwc_addr = r.RB_MRT_FLAG_BUFFER[0].ADDR_LO | (r.RB_MRT_FLAG_BUFFER[0].ADDR_HI << 32)76blit.ubwc_pitch = r.RB_MRT_FLAG_BUFFER[0].PITCH.PITCH77type="draw"78end79blit.base = bos.base(blit.addr)80blit.ubwc_base = bos.base(blit.uwbc_addr)81blit.endaddr = 0 -- filled in later8283printf("Found %s: 0x%x/%d (0x%x) %dx%d UBWC 0x%x/%d (0x%x)\n",84type, blit.addr, blit.pitch, blit.base, blit.width, blit.height, blit.ubwc_addr, blit.ubwc_pitch, blit.ubwc_base)8586allblits[nallblits] = blit87nallblits = nallblits + 188end8990function A6XX_TEX_CONST(pkt, size)91-- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we92-- are looking for9394local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)95local ubwc_base = pkt[7].FLAG_LO | (pkt[8].FLAG_HI << 32)96local width0 = pkt[1].WIDTH97local height0 = pkt[1].HEIGHT98local depth0 = pkt[5].DEPTH99100if (found_tex ~= 0) then101return102end103found_tex = 1104105printf("Found texture state:\n %ux%ux%u (%s, %s, MIN_LAYERSZ=0x%x, TILE_ALL=%s, UBWC=%s FLAG_LOG2=%ux%u %s)\n",106width0, 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, tostring(pkt[0].SAMPLES))107108-- Note that in some case the texture has some extra page or so109-- at the beginning:110local basebase = bos.base(base)111printf("base: 0x%x (0x%x)\n", base, basebase)112printf("ubwcbase: 0x%x (0x%x)\n", ubwc_base, bos.base(ubwc_base))113114-- see if we can find the associated blits.. The blob always seems to115-- start from the lower (larger) mipmap levels and layers, so we don't116-- need to sort by dst address. Also, while we are at it, fill in the117-- end-addr (at least for everything but the last blit)118local blits = {}119local nblits = 0120local lastblit = nil121for n = 0,nallblits-1 do122local blit = allblits[n]123--printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)124if blit.base == basebase and blit.addr >= base then125blits[nblits] = blit126nblits = nblits + 1127if lastblit then128lastblit.endaddr = blit.addr129end130lastblit = blit131end132end133134printf(" {\n")135printf(" .format = %s,\n", pkt[0].FMT)136if (tostring(pkt[2].TYPE) == "A6XX_TEX_3D") then137printf(" .is_3d = true,\n")138end139140printf(" .layout = {\n")141printf(" .tile_mode = %s,\n", pkt[0].TILE_MODE)142printf(" .ubwc = %s,\n", tostring(pkt[3].FLAG))143144if (tostring(pkt[0].SAMPLES) == "MSAA_ONE") then145-- Ignore it, 1 is the default146elseif (tostring(pkt[0].SAMPLES) == "MSAA_TWO") then147printf(" .nr_samples = 2,\n")148elseif (tostring(pkt[0].SAMPLES) == "MSAA_FOUR") then149printf(" .nr_samples = 4,\n")150else151printf(" .nr_samples = XXX,\n")152end153154if (tostring(pkt[2].TYPE) == "A6XX_TEX_3D") then155printf(" .width0 = %d, .height0 = %d, .depth = %d,\n", width0, height0, depth0)156else157printf(" .width0 = %d, .height0 = %d,\n", width0, height0)158end159160printf(" .slices = {\n")161local w = 0162local h = 0163local level = 0164repeat165local w = minify(width0, level)166local h = minify(height0, level)167local blit = get_first_blit(basebase, w, h)168if blit then169printf(" { .offset = %d, .pitch = %u },\n",170blit.addr - base,171blit.pitch);172end173level = level + 1174until w == 1 and h == 1175printf(" },\n")176177if pkt[3].FLAG then178printf(" .ubwc_slices = {\n")179level = 0180repeat181local w = minify(width0, level)182local h = minify(height0, level)183local blit = get_first_blit(basebase, w, h)184if blit then185printf(" { .offset = %d, .pitch = %u },\n",186blit.ubwc_addr - ubwc_base,187blit.ubwc_pitch);188end189level = level + 1190until w == 1 and h == 1191printf(" },\n")192end193194printf(" },\n")195printf(" },\n")196printf("\n\n")197end198199200201