Mesa (main): amd/addrlib: expose CMASK address equations to drivers on GFX9

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 3 07:24:06 UTC 2021


Module: Mesa
Branch: main
Commit: 96e12644f3a8e7bd594ba9177630810420e7c36c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=96e12644f3a8e7bd594ba9177630810420e7c36c

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Fri Jul 30 13:41:30 2021 +0200

amd/addrlib: expose CMASK address equations to drivers on GFX9

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Acked-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12140>

---

 src/amd/addrlib/inc/addrinterface.h      | 12 +++++++++
 src/amd/addrlib/src/gfx9/gfx9addrlib.cpp | 44 ++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/src/amd/addrlib/inc/addrinterface.h b/src/amd/addrlib/inc/addrinterface.h
index c7c73b1401d..3601a530f69 100644
--- a/src/amd/addrlib/inc/addrinterface.h
+++ b/src/amd/addrlib/inc/addrinterface.h
@@ -2994,6 +2994,18 @@ typedef struct _ADDR2_COMPUTE_CMASK_INFO_OUTPUT
     UINT_32    metaBlkNumPerSlice;  ///< Number of metablock within one slice
 
     ADDR2_META_MIP_INFO* pMipInfo;  ///< CMASK mip information
+
+    /* The equation for doing CMASK address computations in shaders. */
+    union {
+       /* This is chip-specific, and it varies with:
+        * - resource type
+        * - swizzle_mode
+        * - bpp
+        * - pipe_aligned
+        * - rb_aligned
+        */
+       struct gfx9_addr_meta_equation gfx9;
+    } equation;
 } ADDR2_COMPUTE_CMASK_INFO_OUTPUT;
 
 /**
diff --git a/src/amd/addrlib/src/gfx9/gfx9addrlib.cpp b/src/amd/addrlib/src/gfx9/gfx9addrlib.cpp
index da1711a949a..ca3d29c2391 100644
--- a/src/amd/addrlib/src/gfx9/gfx9addrlib.cpp
+++ b/src/amd/addrlib/src/gfx9/gfx9addrlib.cpp
@@ -350,6 +350,50 @@ ADDR_E_RETURNCODE Gfx9Lib::HwlComputeCmaskInfo(
 
     pOut->metaBlkNumPerSlice = numMetaBlkX * numMetaBlkY;
 
+    // Get the CMASK address equation (copied from CmaskAddrFromCoord)
+    UINT_32 fmaskBpp              = GetFmaskBpp(1, 1);
+    UINT_32 fmaskElementBytesLog2 = Log2(fmaskBpp >> 3);
+    UINT_32 metaBlkWidthLog2      = Log2(pOut->metaBlkWidth);
+    UINT_32 metaBlkHeightLog2     = Log2(pOut->metaBlkHeight);
+
+    MetaEqParams metaEqParams = {0, fmaskElementBytesLog2, 0, pIn->cMaskFlags,
+                                Gfx9DataFmask, pIn->swizzleMode, pIn->resourceType,
+                                metaBlkWidthLog2, metaBlkHeightLog2, 0, 3, 3, 0};
+
+    CoordEq *eq = (CoordEq *)((Gfx9Lib *)this)->GetMetaEquation(metaEqParams);
+
+    // Generate the CMASK address equation.
+    pOut->equation.gfx9.num_bits = Min(32u, eq->getsize());
+    bool checked = false;
+    for (unsigned b = 0; b < pOut->equation.gfx9.num_bits; b++) {
+       CoordTerm &bit = (*eq)[b];
+
+       unsigned c;
+       for (c = 0; c < bit.getsize(); c++) {
+          Coordinate &coord = bit[c];
+          pOut->equation.gfx9.bit[b].coord[c].dim = coord.getdim();
+          pOut->equation.gfx9.bit[b].coord[c].ord = coord.getord();
+       }
+       for (; c < 5; c++)
+          pOut->equation.gfx9.bit[b].coord[c].dim = 5; /* meaning invalid */
+    }
+
+    // Reduce num_bits because DIM_M fills the rest of the bits monotonically.
+    for (int b = pOut->equation.gfx9.num_bits - 1; b >= 1; b--) {
+       CoordTerm &prev = (*eq)[b - 1];
+       CoordTerm &cur = (*eq)[b];
+
+       if (cur.getsize() == 1 && cur[0].getdim() == DIM_M &&
+          prev.getsize() == 1 && prev[0].getdim() == DIM_M &&
+          prev[0].getord() + 1 == cur[0].getord())
+          pOut->equation.gfx9.num_bits = b;
+       else
+          break;
+    }
+
+    pOut->equation.gfx9.numPipeBits = GetPipeLog2ForMetaAddressing(pIn->cMaskFlags.pipeAligned,
+                                                                   pIn->swizzleMode);
+
     return ADDR_OK;
 }
 



More information about the mesa-commit mailing list