From 96e12644f3a8e7bd594ba9177630810420e7c36c Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 30 Jul 2021 13:41:30 +0200 Subject: [PATCH] amd/addrlib: expose CMASK address equations to drivers on GFX9 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Samuel Pitoiset Acked-by: Marek Olšák Part-of: --- 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 c7c73b1..3601a53 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 da1711a..ca3d29c 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; } -- 2.7.4