aboutsummaryrefslogtreecommitdiffstats
path: root/src/freedreno/decode/scripts/sanity-a6xx.lua
blob: 68e4c73c4f0e11510b2996c67ffd7bbd2b474b82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
-- Parse cmdstream dump and check for common errors
--  1) Check for overflowing HLSQ_xS_CNTL.CONSTLEN
--  2) Check for constant uploades that overwrite each other.  The
--     range checking is reset on  each draw, since it is a valid
--     use-case to do partial constant upload.  But if we see two
--     CP_LOAD_STATE* that overwrite the same range of constants
--     within the same draw, that is almost certainly unintentional.
--
-- TODO add more checks
-- TODO maybe some parts could be shared across
--      different generations

--local posix = require "posix"

function printf(fmt, ...)
	return io.write(string.format(fmt, ...))
end

function dbg(fmt, ...)
	--printf(fmt, ...)
end

stages = {
	"SB6_VS_SHADER",
	"SB6_HS_SHADER",
	"SB6_DS_SHADER",
	"SB6_GS_SHADER",
	"SB6_FS_SHADER",
	"SB6_CS_SHADER",
}

-- maps shader stage to HLSQ_xS_CNTL register name:
cntl_regs = {
	["SB6_VS_SHADER"] = "HLSQ_VS_CNTL",
	["SB6_HS_SHADER"] = "HLSQ_HS_CNTL",
	["SB6_DS_SHADER"] = "HLSQ_DS_CNTL",
	["SB6_GS_SHADER"] = "HLSQ_GS_CNTL",
	["SB6_FS_SHADER"] = "HLSQ_FS_CNTL",
	["SB6_CS_SHADER"] = "HLSQ_CS_CNTL",
}

-- initialize constant updated ranges:
--   constranges[stagename] -> table of offsets that have been uploaded
constranges = {}
function reset_constranges()
	for i,stage in ipairs(stages) do
		constranges[stage] = {}
	end
end

reset_constranges()

printf("Checking cmdstream...\n")

local r = rnn.init("a630")

function draw(primtype, nindx)
	printf("draw!\n")
	-- reset ranges of uploaded consts on each draw:
	reset_constranges()
end

function CP_LOAD_STATE6(pkt, size)
	if tostring(pkt[0].STATE_TYPE) ~= "ST6_CONSTANTS" then
		return
	end
	dbg("got CP_LOAD_STATE6\n")
	stage = tostring(pkt[0].STATE_BLOCK)
	max = pkt[0].DST_OFF + pkt[0].NUM_UNIT
	cntl_reg = cntl_regs[stage]
	dbg("looking for %s.. max=%d vs %d\n", cntl_reg, max, r[cntl_reg].CONSTLEN)
	if max > r[cntl_reg].CONSTLEN then
		printf("ERROR: invalid max constant offset for stage %s: %d vs %d\n", stage, max, r[cntl_reg].CONSTLEN)
	end

end