Path: blob/21.2-virgl/src/freedreno/decode/scripts/sanity-a6xx.lua
4573 views
-- Parse cmdstream dump and check for common errors1-- 1) Check for overflowing HLSQ_xS_CNTL.CONSTLEN2-- 2) Check for constant uploades that overwrite each other. The3-- range checking is reset on each draw, since it is a valid4-- use-case to do partial constant upload. But if we see two5-- CP_LOAD_STATE* that overwrite the same range of constants6-- within the same draw, that is almost certainly unintentional.7--8-- TODO add more checks9-- TODO maybe some parts could be shared across10-- different generations1112--local posix = require "posix"1314function printf(fmt, ...)15return io.write(string.format(fmt, ...))16end1718function dbg(fmt, ...)19--printf(fmt, ...)20end2122stages = {23"SB6_VS_SHADER",24"SB6_HS_SHADER",25"SB6_DS_SHADER",26"SB6_GS_SHADER",27"SB6_FS_SHADER",28"SB6_CS_SHADER",29}3031-- maps shader stage to HLSQ_xS_CNTL register name:32cntl_regs = {33["SB6_VS_SHADER"] = "HLSQ_VS_CNTL",34["SB6_HS_SHADER"] = "HLSQ_HS_CNTL",35["SB6_DS_SHADER"] = "HLSQ_DS_CNTL",36["SB6_GS_SHADER"] = "HLSQ_GS_CNTL",37["SB6_FS_SHADER"] = "HLSQ_FS_CNTL",38["SB6_CS_SHADER"] = "HLSQ_CS_CNTL",39}4041-- initialize constant updated ranges:42-- constranges[stagename] -> table of offsets that have been uploaded43constranges = {}44function reset_constranges()45for i,stage in ipairs(stages) do46constranges[stage] = {}47end48end4950reset_constranges()5152printf("Checking cmdstream...\n")5354local r = rnn.init("a630")5556function draw(primtype, nindx)57printf("draw!\n")58-- reset ranges of uploaded consts on each draw:59reset_constranges()60end6162function CP_LOAD_STATE6(pkt, size)63if tostring(pkt[0].STATE_TYPE) ~= "ST6_CONSTANTS" then64return65end66dbg("got CP_LOAD_STATE6\n")67stage = tostring(pkt[0].STATE_BLOCK)68max = pkt[0].DST_OFF + pkt[0].NUM_UNIT69cntl_reg = cntl_regs[stage]70dbg("looking for %s.. max=%d vs %d\n", cntl_reg, max, r[cntl_reg].CONSTLEN)71if max > r[cntl_reg].CONSTLEN then72printf("ERROR: invalid max constant offset for stage %s: %d vs %d\n", stage, max, r[cntl_reg].CONSTLEN)73end7475end767778