~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/freedreno/decode/scripts/texturator-to-unit-test-5xx.lua

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
local posix = require "posix"
3
 
 
4
 
io.write("Analyzing Data...\n")
5
 
 
6
 
local r = rnn.init("a530")
7
 
local found_tex = 0
8
 
 
9
 
local allblits = {}
10
 
local nallblits = 0
11
 
 
12
 
function get_first_blit(base, width, height)
13
 
  local first_blit = nil
14
 
 
15
 
  for n = 0,nallblits-1 do
16
 
    local blit = allblits[n]
17
 
    if blit.base == base and blit.width == width and blit.height == height then
18
 
      if not first_blit or blit.addr < first_blit.addr then
19
 
        first_blit = blit
20
 
      end
21
 
    end
22
 
  end
23
 
 
24
 
  return first_blit
25
 
end
26
 
 
27
 
function minify(val, lvls)
28
 
  val = val >> lvls
29
 
  if val < 1 then
30
 
    return 1
31
 
  end
32
 
  return val
33
 
end
34
 
 
35
 
function printf(fmt, ...)
36
 
  return io.write(string.format(fmt, ...))
37
 
end
38
 
 
39
 
function start_cmdstream(name)
40
 
  io.write("Parsing " .. name .. "\n")
41
 
  allblits = {}
42
 
  nallblits = 0
43
 
end
44
 
 
45
 
function CP_EVENT_WRITE(pkt, size)
46
 
  if tostring(pkt[0].EVENT) ~= "BLIT" then
47
 
    return
48
 
  end
49
 
 
50
 
  local blit = {}
51
 
 
52
 
  blit.width   = r.RB_RESOLVE_CNTL_2.X + 1
53
 
  blit.height  = r.RB_RESOLVE_CNTL_2.Y + 1
54
 
  blit.pitch   = r.RB_BLIT_DST_PITCH
55
 
  blit.addr    = r.RB_BLIT_DST_LO | (r.RB_BLIT_DST_HI << 32)
56
 
  blit.base    = bos.base(blit.addr)
57
 
  blit.ubwc_addr = r.RB_BLIT_FLAG_DST_LO | (r.RB_BLIT_FLAG_DST_HI << 32)
58
 
  blit.ubwc_base = bos.base(blit.ubwc_addr)
59
 
  blit.ubwc_pitch = r.RB_BLIT_FLAG_DST_PITCH
60
 
  blit.endaddr = 0  -- filled in later
61
 
  printf("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)
62
 
 
63
 
  allblits[nallblits] = blit
64
 
  nallblits = nallblits + 1
65
 
end
66
 
 
67
 
function CP_BLIT(pkt, size)
68
 
  -- Just in case, filter out anything that isn't starting
69
 
  -- at 0,0
70
 
  if pkt[1].SRC_X1 ~= 0 or pkt[1].SRC_Y1 ~= 0 then
71
 
    return
72
 
  end
73
 
 
74
 
  local blit = {}
75
 
 
76
 
  blit.width   = pkt[2].SRC_X2 + 1
77
 
  blit.height  = pkt[2].SRC_Y2 + 1
78
 
  blit.pitch   = r.RB_2D_DST_SIZE.PITCH
79
 
  blit.addr    = r.RB_2D_DST_LO | (r.RB_2D_DST_HI << 32)
80
 
  blit.base    = bos.base(blit.addr)
81
 
  blit.ubwc_addr = r.RB_2D_DST_FLAGS_LO | (r.RB_2D_DST_FLAGS_HI << 32)
82
 
  blit.ubwc_base = bos.base(blit.ubwc_addr)
83
 
  blit.ubwc_pitch = r.RB_2D_DST_FLAGS_PITCH
84
 
  blit.endaddr = 0  -- filled in later
85
 
  printf("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)
86
 
 
87
 
  allblits[nallblits] = blit
88
 
  nallblits = nallblits + 1
89
 
end
90
 
 
91
 
function A5XX_TEX_CONST(pkt, size)
92
 
  -- ignore any texture state w/ DEPTH=1, these aren't the 3d tex state we
93
 
  -- are looking for
94
 
 
95
 
  local base = pkt[4].BASE_LO | (pkt[5].BASE_HI << 32)
96
 
  -- UBWC base on a5xx seems to be at the start of each miplevel, followed by pixels
97
 
  -- somewhere past that.
98
 
  local ubwc_base = base
99
 
  local width0  = pkt[1].WIDTH
100
 
  local height0 = pkt[1].HEIGHT
101
 
  local depth0  = pkt[5].DEPTH
102
 
 
103
 
  if (found_tex ~= 0) then
104
 
    return
105
 
  end
106
 
  found_tex = 1
107
 
 
108
 
  printf("Found texture state:\n  %ux%ux%u (%s, %s, UBWC=%s)\n",
109
 
         width0, height0, depth0, pkt[0].FMT, pkt[0].TILE_MODE, tostring(pkt[3].FLAG))
110
 
 
111
 
  -- Note that in some case the texture has some extra page or so
112
 
  -- at the beginning:
113
 
  local basebase = bos.base(base)
114
 
  printf("base: 0x%x (0x%x)\n", base, basebase)
115
 
  printf("ubwcbase: 0x%x (0x%x)\n", ubwc_base, bos.base(ubwc_base))
116
 
 
117
 
  -- see if we can find the associated blits..  The blob always seems to
118
 
  -- start from the lower (larger) mipmap levels and layers, so we don't
119
 
  -- need to sort by dst address.  Also, while we are at it, fill in the
120
 
  -- end-addr (at least for everything but the last blit)
121
 
  local blits = {}
122
 
  local nblits = 0
123
 
  local lastblit = nil
124
 
  for n = 0,nallblits-1 do
125
 
    local blit = allblits[n]
126
 
    --printf("blit addr: 0x%x (0x%x)\n", blit.addr, blit.base)
127
 
    if blit.base == basebase and blit.addr >= base then
128
 
      blits[nblits] = blit
129
 
      nblits = nblits + 1
130
 
      if lastblit then
131
 
        lastblit.endaddr = blit.addr
132
 
      end
133
 
      lastblit = blit
134
 
    end
135
 
  end
136
 
 
137
 
  printf("      {\n")
138
 
  printf("              .format = %s,\n", pkt[0].FMT)
139
 
  if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then
140
 
    printf("            .is_3d = true,\n")
141
 
  end
142
 
 
143
 
  printf("              .layout = {\n")
144
 
  printf("                      .tile_mode = %s,\n", pkt[0].TILE_MODE)
145
 
  printf("                      .ubwc = %s,\n", tostring(pkt[3].FLAG))
146
 
 
147
 
  if (tostring(pkt[2].TYPE) == "A5XX_TEX_3D") then
148
 
    printf("                    .width0 = %d, .height0 = %d, .depth0 = %d,\n", width0, height0, depth0)
149
 
  else
150
 
    printf("                    .width0 = %d, .height0 = %d,\n", width0, height0)
151
 
  end
152
 
 
153
 
  printf("                      .slices = {\n")
154
 
  local w = 0
155
 
  local h = 0
156
 
  local level = 0
157
 
  repeat
158
 
    local w = minify(width0, level)
159
 
    local h = minify(height0, level)
160
 
    local blit = get_first_blit(basebase, w, h)
161
 
    if blit then
162
 
      printf("                          { .offset = %d, .pitch = %u },\n",
163
 
          blit.addr - base,
164
 
          blit.pitch);
165
 
    end
166
 
    level = level + 1
167
 
  until w == 1 and h == 1
168
 
  printf("                      },\n")
169
 
 
170
 
  if pkt[3].FLAG then
171
 
    printf("                    .ubwc_slices = {\n")
172
 
    level = 0
173
 
    repeat
174
 
      local w = minify(width0, level)
175
 
      local h = minify(height0, level)
176
 
      local blit = get_first_blit(basebase, w, h)
177
 
      if blit then
178
 
        printf("                                { .offset = %d, .pitch = %u },\n",
179
 
            blit.ubwc_addr - ubwc_base,
180
 
            blit.ubwc_pitch);
181
 
      end
182
 
      level = level + 1
183
 
    until w == 1 and h == 1
184
 
    printf("                    },\n")
185
 
  end
186
 
 
187
 
  printf("              },\n")
188
 
  printf("      },\n")
189
 
  printf("\n\n")
190
 
end
191