17ec681f3Smrg/*
27ec681f3Smrg * Copyright © 2020 Google LLC
37ec681f3Smrg *
47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg * to deal in the Software without restriction, including without limitation
77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg * The above copyright notice and this permission notice (including the next
127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg * Software.
147ec681f3Smrg *
157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg * IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#include "freedreno_layout.h"
257ec681f3Smrg#include "fd_layout_test.h"
267ec681f3Smrg#include "adreno_common.xml.h"
277ec681f3Smrg#include "adreno_pm4.xml.h"
287ec681f3Smrg#include "a6xx.xml.h"
297ec681f3Smrg
307ec681f3Smrg#include <stdio.h>
317ec681f3Smrg
327ec681f3Smrgbool
337ec681f3Smrgfdl_test_layout(const struct testcase *testcase, int gpu_id)
347ec681f3Smrg{
357ec681f3Smrg   struct fdl_layout layout = {
367ec681f3Smrg      .ubwc = testcase->layout.ubwc,
377ec681f3Smrg      .tile_mode = testcase->layout.tile_mode,
387ec681f3Smrg   };
397ec681f3Smrg   bool ok = true;
407ec681f3Smrg
417ec681f3Smrg   int max_size = MAX2(testcase->layout.width0, testcase->layout.height0);
427ec681f3Smrg   int mip_levels = 1;
437ec681f3Smrg   while (max_size > 1 && testcase->layout.slices[mip_levels].pitch) {
447ec681f3Smrg      mip_levels++;
457ec681f3Smrg      max_size = u_minify(max_size, 1);
467ec681f3Smrg   }
477ec681f3Smrg
487ec681f3Smrg   if (gpu_id >= 600) {
497ec681f3Smrg      fdl6_layout(&layout, testcase->format,
507ec681f3Smrg                  MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
517ec681f3Smrg                  MAX2(testcase->layout.height0, 1),
527ec681f3Smrg                  MAX2(testcase->layout.depth0, 1), mip_levels,
537ec681f3Smrg                  MAX2(testcase->array_size, 1), testcase->is_3d, NULL);
547ec681f3Smrg   } else {
557ec681f3Smrg      assert(gpu_id >= 500);
567ec681f3Smrg      fdl5_layout(&layout, testcase->format,
577ec681f3Smrg                  MAX2(testcase->layout.nr_samples, 1), testcase->layout.width0,
587ec681f3Smrg                  MAX2(testcase->layout.height0, 1),
597ec681f3Smrg                  MAX2(testcase->layout.depth0, 1), mip_levels,
607ec681f3Smrg                  MAX2(testcase->array_size, 1), testcase->is_3d);
617ec681f3Smrg   }
627ec681f3Smrg
637ec681f3Smrg   /* fdl lays out UBWC data before the color data, while all we have
647ec681f3Smrg    * recorded in this testcase are the color offsets (other than the UBWC
657ec681f3Smrg    * buffer sharing test).  Shift the fdl layout down so we can compare
667ec681f3Smrg    * color offsets.
677ec681f3Smrg    */
687ec681f3Smrg   if (layout.ubwc && !testcase->layout.slices[0].offset) {
697ec681f3Smrg      for (int l = 1; l < mip_levels; l++)
707ec681f3Smrg         layout.slices[l].offset -= layout.slices[0].offset;
717ec681f3Smrg      layout.slices[0].offset = 0;
727ec681f3Smrg   }
737ec681f3Smrg
747ec681f3Smrg   for (int l = 0; l < mip_levels; l++) {
757ec681f3Smrg      if (layout.slices[l].offset != testcase->layout.slices[l].offset) {
767ec681f3Smrg         fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: offset 0x%x != 0x%x\n",
777ec681f3Smrg                 util_format_short_name(testcase->format), layout.width0,
787ec681f3Smrg                 layout.height0, layout.depth0, layout.nr_samples, l,
797ec681f3Smrg                 layout.slices[l].offset, testcase->layout.slices[l].offset);
807ec681f3Smrg         ok = false;
817ec681f3Smrg      }
827ec681f3Smrg      if (fdl_pitch(&layout, l) != testcase->layout.slices[l].pitch) {
837ec681f3Smrg         fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: pitch %d != %d\n",
847ec681f3Smrg                 util_format_short_name(testcase->format), layout.width0,
857ec681f3Smrg                 layout.height0, layout.depth0, layout.nr_samples, l,
867ec681f3Smrg                 fdl_pitch(&layout, l), testcase->layout.slices[l].pitch);
877ec681f3Smrg         ok = false;
887ec681f3Smrg      }
897ec681f3Smrg
907ec681f3Smrg      if (layout.ubwc_slices[l].offset !=
917ec681f3Smrg          testcase->layout.ubwc_slices[l].offset) {
927ec681f3Smrg         fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC offset 0x%x != 0x%x\n",
937ec681f3Smrg                 util_format_short_name(testcase->format), layout.width0,
947ec681f3Smrg                 layout.height0, layout.depth0, layout.nr_samples, l,
957ec681f3Smrg                 layout.ubwc_slices[l].offset,
967ec681f3Smrg                 testcase->layout.ubwc_slices[l].offset);
977ec681f3Smrg         ok = false;
987ec681f3Smrg      }
997ec681f3Smrg      if (fdl_ubwc_pitch(&layout, l) != testcase->layout.ubwc_slices[l].pitch) {
1007ec681f3Smrg         fprintf(stderr, "%s %dx%dx%d@%dx lvl%d: UBWC pitch %d != %d\n",
1017ec681f3Smrg                 util_format_short_name(testcase->format), layout.width0,
1027ec681f3Smrg                 layout.height0, layout.depth0, layout.nr_samples, l,
1037ec681f3Smrg                 fdl_ubwc_pitch(&layout, l),
1047ec681f3Smrg                 testcase->layout.ubwc_slices[l].pitch);
1057ec681f3Smrg         ok = false;
1067ec681f3Smrg      }
1077ec681f3Smrg   }
1087ec681f3Smrg
1097ec681f3Smrg   if (!ok)
1107ec681f3Smrg      fprintf(stderr, "\n");
1117ec681f3Smrg
1127ec681f3Smrg   return ok;
1137ec681f3Smrg}
114