c0862bc5ad905e80d3f27ee5b75843b822c190c2
2 * Copyright © 2020 Google, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 static bool bin_debug
= false;
28 #define BIN_DEBUG bin_debug
30 #include "freedreno_gmem.c"
32 /* NOTE, non-interesting gmem keys (ie. things that are small enough to fit
33 * in a single bin) are commented out, but retained for posterity.
35 static const struct gmem_key keys
[] = {
37 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
38 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
39 // { .minx=0, .miny=0, .width=64, .height=64, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
40 // { .minx=0, .miny=0, .width=32, .height=32, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
41 // { .minx=0, .miny=0, .width=16, .height=16, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
42 // { .minx=0, .miny=0, .width=8, .height=8, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
43 // { .minx=0, .miny=0, .width=4, .height=4, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
44 // { .minx=0, .miny=0, .width=2, .height=2, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
45 // { .minx=0, .miny=0, .width=1, .height=1, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
46 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=4, .cbuf_cpp
= {4,4,4,4,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
47 // { .minx=0, .miny=0, .width=64, .height=64, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {2,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
48 { .minx
=0, .miny
=0, .width
=1024, .height
=1024, .gmem_page_align
=1, .nr_cbufs
=0, .cbuf_cpp
= {0,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {2,0,}},
49 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=0, .cbuf_cpp
= {0,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
50 { .minx
=0, .miny
=0, .width
=960, .height
=540, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
51 { .minx
=0, .miny
=0, .width
=480, .height
=270, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
52 // { .minx=0, .miny=0, .width=240, .height=135, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
53 // { .minx=0, .miny=0, .width=120, .height=67, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {4,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
56 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
57 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
58 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {2,0,}},
59 { .minx
=0, .miny
=0, .width
=960, .height
=540, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {2,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {2,0,}},
60 { .minx
=0, .miny
=0, .width
=1024, .height
=1024, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {2,0,}},
61 // { .minx=0, .miny=0, .width=64, .height=64, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {2,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
64 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
65 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {2,0,}},
66 { .minx
=0, .miny
=0, .width
=810, .height
=810, .gmem_page_align
=1, .nr_cbufs
=2, .cbuf_cpp
= {4,4,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
67 // { .minx=0, .miny=0, .width=405, .height=405, .gmem_page_align=1, .nr_cbufs=1, .cbuf_cpp = {2,0,0,0,0,0,0,0,}, .zsbuf_cpp = {0,0,}},
68 { .minx
=0, .miny
=0, .width
=405, .height
=405, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {8,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
69 { .minx
=0, .miny
=0, .width
=810, .height
=810, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {8,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
70 { .minx
=0, .miny
=0, .width
=810, .height
=810, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
71 { .minx
=0, .miny
=0, .width
=810, .height
=810, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
72 { .minx
=0, .miny
=0, .width
=960, .height
=540, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {2,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
73 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {8,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
74 { .minx
=0, .miny
=0, .width
=960, .height
=540, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {8,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {0,0,}},
75 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=2, .cbuf_cpp
= {4,4,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
76 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {8,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
77 { .minx
=0, .miny
=0, .width
=1920, .height
=1080, .gmem_page_align
=1, .nr_cbufs
=1, .cbuf_cpp
= {4,0,0,0,0,0,0,0,}, .zsbuf_cpp
= {4,0,}},
85 uint32_t num_vsc_pipes
;
86 uint8_t gmem_page_align
;
87 uint32_t gmemsize_bytes
;
90 #define SZ_128K 0x00020000
91 #define SZ_256K 0x00040000
92 #define SZ_512K 0x00080000
93 #define SZ_1M 0x00100000
95 /* keep sorted by gpu name: */
96 static const struct gpu_info gpu_infos
[] = {
97 { "a306", 307, 32, 32, 8, 4, SZ_128K
},
98 { "a405", 405, 32, 32, 8, 4, SZ_256K
},
99 { "a530", 530, 64, 32, 16, 4, SZ_1M
},
100 { "a618", 618, 32, 32, 32, 1, SZ_512K
},
101 { "a630", 630, 32, 32, 32, 1, SZ_1M
},
105 static const struct option opts
[] = {
106 { .name
= "gpu", .has_arg
= 1, NULL
, 'g' },
107 { .name
= "help", .has_arg
= 0, NULL
, 'h' },
108 { .name
= "verbose", .has_arg
= 0, NULL
, 'v' },
115 fprintf(stderr
, "Usage:\n\n"
116 "\tgmemtool [-hv] [-g GPU]\n\n"
118 "\t-g, --gpu=GPU - use GMEM size/alignment/etc settings for the specified GPU\n"
119 "\t-h, --help - this usage message\n"
120 "\t-v, --verbose - dump more verbose output\n"
123 fprintf(stderr
, "Where GPU is one of:\n");
124 for (int i
= 0; i
< ARRAY_SIZE(gpu_infos
); i
++)
125 fprintf(stderr
, "\t%s\n", gpu_infos
[i
].name
);
130 main(int argc
, char **argv
)
132 const char *gpu_name
= "a630";
135 while ((c
= getopt_long(argc
, argv
, "g:hv", opts
, NULL
)) != -1) {
149 const struct gpu_info
*gpu_info
= NULL
;
151 for (int i
= 0; i
< ARRAY_SIZE(gpu_infos
); i
++) {
152 if (strcmp(gpu_name
, gpu_infos
[i
].name
) == 0) {
153 gpu_info
= &gpu_infos
[i
];
159 printf("unrecognized gpu name: %s\n", gpu_name
);
163 /* Setup a fake screen with enough GMEM related configuration
164 * to make gmem_stateobj_init() happy:
166 struct fd_screen screen
= {
167 .gpu_id
= gpu_info
->gpu_id
,
168 .gmem_alignw
= gpu_info
->gmem_alignw
,
169 .gmem_alignh
= gpu_info
->gmem_alignh
,
170 .num_vsc_pipes
= gpu_info
->num_vsc_pipes
,
171 .gmemsize_bytes
= gpu_info
->gmemsize_bytes
,
174 /* And finally run thru all the GMEM keys: */
175 for (int i
= 0; i
< ARRAY_SIZE(keys
); i
++) {
176 struct gmem_key key
= keys
[i
];
177 key
.gmem_page_align
= gpu_info
->gmem_page_align
;
178 struct fd_gmem_stateobj
*gmem
= gmem_stateobj_init(&screen
, &key
);
179 dump_gmem_state(gmem
);
181 assert((gmem
->bin_w
* gmem
->nbins_x
) >= key
.width
);
182 assert((gmem
->bin_h
* gmem
->nbins_y
) >= key
.height
);