1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2020 Google LLC 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "freedreno_layout.h" 25bf215546Sopenharmony_ci#include "fd_layout_test.h" 26bf215546Sopenharmony_ci#include "adreno_common.xml.h" 27bf215546Sopenharmony_ci#include "adreno_pm4.xml.h" 28bf215546Sopenharmony_ci#include "a6xx.xml.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include <stdio.h> 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_cibool 33bf215546Sopenharmony_cifdl_test_layout(const struct testcase *testcase, int gpu_id) 34bf215546Sopenharmony_ci{ 35bf215546Sopenharmony_ci struct fdl_layout layout = { 36bf215546Sopenharmony_ci .ubwc = testcase->layout.ubwc, 37bf215546Sopenharmony_ci .tile_mode = testcase->layout.tile_mode, 38bf215546Sopenharmony_ci .tile_all = testcase->layout.tile_all, 39bf215546Sopenharmony_ci }; 40bf215546Sopenharmony_ci bool ok = true; 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci int max_size = MAX2(testcase->layout.width0, testcase->layout.height0); 43bf215546Sopenharmony_ci int mip_levels = 1; 44bf215546Sopenharmony_ci while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) { 45bf215546Sopenharmony_ci mip_levels++; 46bf215546Sopenharmony_ci max_size = u_minify(max_size, 1); 47bf215546Sopenharmony_ci } 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci if (gpu_id >= 600) { 50bf215546Sopenharmony_ci fdl6_layout(&layout, testcase->format, 51bf215546Sopenharmony_ci MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0, 52bf215546Sopenharmony_ci MAX2(testcase->layout.height0, 1), 53bf215546Sopenharmony_ci MAX2(testcase->layout.depth0, 1), mip_levels, 54bf215546Sopenharmony_ci MAX2(testcase->array_size, 1), testcase->is_3d, NULL); 55bf215546Sopenharmony_ci } else { 56bf215546Sopenharmony_ci assert(gpu_id >= 500); 57bf215546Sopenharmony_ci fdl5_layout(&layout, testcase->format, 58bf215546Sopenharmony_ci MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0, 59bf215546Sopenharmony_ci MAX2(testcase->layout.height0, 1), 60bf215546Sopenharmony_ci MAX2(testcase->layout.depth0, 1), mip_levels, 61bf215546Sopenharmony_ci MAX2(testcase->array_size, 1), testcase->is_3d); 62bf215546Sopenharmony_ci } 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci /* fdl lays out UBWC data before the color data, while all we have 65bf215546Sopenharmony_ci * recorded in this testcase are the color offsets (other than the UBWC 66bf215546Sopenharmony_ci * buffer sharing test). Shift the fdl layout down so we can compare 67bf215546Sopenharmony_ci * color offsets. 68bf215546Sopenharmony_ci */ 69bf215546Sopenharmony_ci if (layout.ubwc && !testcase->layout.slices[0].offset) { 70bf215546Sopenharmony_ci for (int l = 1; l < mip_levels; l++) 71bf215546Sopenharmony_ci layout.slices[l].offset -= layout.slices[0].offset; 72bf215546Sopenharmony_ci layout.slices[0].offset = 0; 73bf215546Sopenharmony_ci } 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_ci for (int l = 0; l < mip_levels; l++) { 76bf215546Sopenharmony_ci if (layout.slices[l].offset != testcase->layout.slices[l].offset) { 77bf215546Sopenharmony_ci fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n", 78bf215546Sopenharmony_ci util_format_short_name(testcase->format), layout.width0, 79bf215546Sopenharmony_ci layout.height0, layout.depth0, layout.nr_samples, l, 80bf215546Sopenharmony_ci layout.slices[l].offset, testcase->layout.slices[l].offset); 81bf215546Sopenharmony_ci ok = false; 82bf215546Sopenharmony_ci } 83bf215546Sopenharmony_ci if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) { 84bf215546Sopenharmony_ci fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n", 85bf215546Sopenharmony_ci util_format_short_name(testcase->format), layout.width0, 86bf215546Sopenharmony_ci layout.height0, layout.depth0, layout.nr_samples, l, 87bf215546Sopenharmony_ci fdl_pitch(&layout, l), testcase->layout.slices[l].pitch); 88bf215546Sopenharmony_ci ok = false; 89bf215546Sopenharmony_ci } 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci /* Test optional requirement of the slice size. Important for testing 3D 92bf215546Sopenharmony_ci * layouts. 93bf215546Sopenharmony_ci */ 94bf215546Sopenharmony_ci if (testcase->layout.slices[l].size0 && layout.slices[l].size0 != 95bf215546Sopenharmony_ci testcase->layout.slices[l].size0) { 96bf215546Sopenharmony_ci fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: slice size %d != %d\n", 97bf215546Sopenharmony_ci util_format_short_name(testcase->format), layout.width0, 98bf215546Sopenharmony_ci layout.height0, layout.depth0, layout.nr_samples, l, 99bf215546Sopenharmony_ci layout.slices[l].size0, 100bf215546Sopenharmony_ci testcase->layout.slices[l].size0); 101bf215546Sopenharmony_ci ok = false; 102bf215546Sopenharmony_ci } 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci if (layout.ubwc_slices[l].offset != 105bf215546Sopenharmony_ci testcase->layout.ubwc_slices[l].offset) { 106bf215546Sopenharmony_ci fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n", 107bf215546Sopenharmony_ci util_format_short_name(testcase->format), layout.width0, 108bf215546Sopenharmony_ci layout.height0, layout.depth0, layout.nr_samples, l, 109bf215546Sopenharmony_ci layout.ubwc_slices[l].offset, 110bf215546Sopenharmony_ci testcase->layout.ubwc_slices[l].offset); 111bf215546Sopenharmony_ci ok = false; 112bf215546Sopenharmony_ci } 113bf215546Sopenharmony_ci if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) { 114bf215546Sopenharmony_ci fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n", 115bf215546Sopenharmony_ci util_format_short_name(testcase->format), layout.width0, 116bf215546Sopenharmony_ci layout.height0, layout.depth0, layout.nr_samples, l, 117bf215546Sopenharmony_ci fdl_ubwc_pitch(&layout, l), 118bf215546Sopenharmony_ci testcase->layout.ubwc_slices[l].pitch); 119bf215546Sopenharmony_ci ok = false; 120bf215546Sopenharmony_ci } 121bf215546Sopenharmony_ci } 122bf215546Sopenharmony_ci 123bf215546Sopenharmony_ci if (!ok) { 124bf215546Sopenharmony_ci fdl_dump_layout(&layout); 125bf215546Sopenharmony_ci fprintf(stderr, "\n"); 126bf215546Sopenharmony_ci } 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci return ok; 129bf215546Sopenharmony_ci} 130