Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/memory/tilingtraits.h
4574 views
/****************************************************************************1* Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* @file tilingtraits.h23*24* @brief Tiling traits.25*26******************************************************************************/27#pragma once2829#include "core/state.h"30#include "common/intrin.h"3132template<SWR_TILE_MODE mode, int>33struct TilingTraits34{35static const SWR_TILE_MODE TileMode{ mode };36static UINT GetCu() { SWR_NOT_IMPL; return 0; }37static UINT GetCv() { SWR_NOT_IMPL; return 0; }38static UINT GetCr() { SWR_NOT_IMPL; return 0; }39static UINT GetTileIDShift() { SWR_NOT_IMPL; return 0; }4041/// @todo correct pdep shifts for all rastertile dims. Unused for now42static UINT GetPdepX() { SWR_NOT_IMPL; return 0x37; }43static UINT GetPdepY() { SWR_NOT_IMPL; return 0xC8; }44};4546template<int X> struct TilingTraits <SWR_TILE_NONE, X>47{48static const SWR_TILE_MODE TileMode{ SWR_TILE_NONE };49static UINT GetCu() { return 0; }50static UINT GetCv() { return 0; }51static UINT GetCr() { return 0; }52static UINT GetTileIDShift() { return 0; }53static UINT GetPdepX() { return 0x00; }54static UINT GetPdepY() { return 0x00; }55};5657template<> struct TilingTraits <SWR_TILE_SWRZ, 8>58{59static const SWR_TILE_MODE TileMode{ SWR_TILE_SWRZ };60static UINT GetCu() { return KNOB_TILE_X_DIM_SHIFT; }61static UINT GetCv() { return KNOB_TILE_Y_DIM_SHIFT; }62static UINT GetCr() { return 0; }63static UINT GetTileIDShift() { return KNOB_TILE_X_DIM_SHIFT + KNOB_TILE_Y_DIM_SHIFT; }6465/// @todo correct pdep shifts for all rastertile dims. Unused for now66static UINT GetPdepX() { SWR_NOT_IMPL; return 0x00; }67static UINT GetPdepY() { SWR_NOT_IMPL; return 0x00; }68};6970template<> struct TilingTraits <SWR_TILE_SWRZ, 32>71{72static const SWR_TILE_MODE TileMode{ SWR_TILE_SWRZ };73static UINT GetCu() { return KNOB_TILE_X_DIM_SHIFT + 2; }74static UINT GetCv() { return KNOB_TILE_Y_DIM_SHIFT; }75static UINT GetCr() { return 0; }76static UINT GetTileIDShift() { return KNOB_TILE_X_DIM_SHIFT + KNOB_TILE_Y_DIM_SHIFT + 2; }7778static UINT GetPdepX() { return 0x37; }79static UINT GetPdepY() { return 0xC8; }80};8182template<> struct TilingTraits <SWR_TILE_SWRZ, 128>83{84static const SWR_TILE_MODE TileMode{ SWR_TILE_SWRZ };85static UINT GetCu() { return KNOB_TILE_X_DIM_SHIFT + 4; }86static UINT GetCv() { return KNOB_TILE_Y_DIM_SHIFT; }87static UINT GetCr() { return 0; }88static UINT GetTileIDShift() { return KNOB_TILE_X_DIM_SHIFT + KNOB_TILE_Y_DIM_SHIFT + 4; }8990/// @todo correct pdep shifts for all rastertile dims. Unused for now91static UINT GetPdepX() { SWR_NOT_IMPL; return 0x37; }92static UINT GetPdepY() { SWR_NOT_IMPL; return 0xC8; }93};9495// y-major tiling layout unaffected by element size96template<int X> struct TilingTraits <SWR_TILE_MODE_YMAJOR, X>97{98static const SWR_TILE_MODE TileMode{ SWR_TILE_MODE_YMAJOR };99static UINT GetCu() { return 7; }100static UINT GetCv() { return 5; }101static UINT GetCr() { return 0; }102static UINT GetTileIDShift() { return 12; }103104static UINT GetPdepX() { return 0xe0f; }105static UINT GetPdepY() { return 0x1f0; }106};107108// x-major tiling layout unaffected by element size109template<int X> struct TilingTraits <SWR_TILE_MODE_XMAJOR, X>110{111static const SWR_TILE_MODE TileMode{ SWR_TILE_MODE_XMAJOR };112static UINT GetCu() { return 9; }113static UINT GetCv() { return 3; }114static UINT GetCr() { return 0; }115static UINT GetTileIDShift() { return 12; }116117static UINT GetPdepX() { return 0x1ff; }118static UINT GetPdepY() { return 0xe00; }119};120121template<int X> struct TilingTraits <SWR_TILE_MODE_WMAJOR, X>122{123static const SWR_TILE_MODE TileMode{ SWR_TILE_MODE_WMAJOR };124static UINT GetCu() { return 6; }125static UINT GetCv() { return 6; }126static UINT GetCr() { return 0; }127static UINT GetTileIDShift() { return 12; }128129static UINT GetPdepX() { return 0xe15; }130static UINT GetPdepY() { return 0x1ea; }131};132133//////////////////////////////////////////////////////////////////////////134/// @brief Computes the tileID for 2D tiled surfaces135/// @param pitch - surface pitch in bytes136/// @param tileX - x offset in tiles137/// @param tileY - y offset in tiles138template<typename TTraits>139INLINE UINT ComputeTileOffset2D(UINT pitch, UINT tileX, UINT tileY)140{141UINT tileID = tileY * (pitch >> TTraits::GetCu()) + tileX;142return tileID << TTraits::GetTileIDShift();143}144145//////////////////////////////////////////////////////////////////////////146/// @brief Computes the tileID for 3D tiled surfaces147/// @param qpitch - surface qpitch in rows148/// @param pitch - surface pitch in bytes149/// @param tileX - x offset in tiles150/// @param tileY - y offset in tiles151/// @param tileZ - y offset in tiles152template<typename TTraits>153INLINE UINT ComputeTileOffset3D(UINT qpitch, UINT pitch, UINT tileX, UINT tileY, UINT tileZ)154{155UINT tileID = (tileZ * (qpitch >> TTraits::GetCv()) + tileY) * (pitch >> TTraits::GetCu()) + tileX;156return tileID << TTraits::GetTileIDShift();157}158159//////////////////////////////////////////////////////////////////////////160/// @brief Computes the byte offset for 2D tiled surfaces161/// @param pitch - surface pitch in bytes162/// @param x - x offset in bytes163/// @param y - y offset in rows164template<typename TTraits>165INLINE UINT ComputeOffset2D(UINT pitch, UINT x, UINT y)166{167UINT tileID = ComputeTileOffset2D<TTraits>(pitch, x >> TTraits::GetCu(), y >> TTraits::GetCv());168UINT xSwizzle = pdep_u32(x, TTraits::GetPdepX());169UINT ySwizzle = pdep_u32(y, TTraits::GetPdepY());170return (tileID | xSwizzle | ySwizzle);171}172173#if KNOB_ARCH <= KNOB_ARCH_AVX174//////////////////////////////////////////////////////////////////////////175/// @brief Computes the byte offset for 2D tiled surfaces. Specialization176/// for tile-y surfaces that uses bit twiddling instead of pdep emulation.177/// @param pitch - surface pitch in bytes178/// @param x - x offset in bytes179/// @param y - y offset in rows180template<>181INLINE UINT ComputeOffset2D<TilingTraits<SWR_TILE_MODE_YMAJOR, 32> >(UINT pitch, UINT x, UINT y)182{183typedef TilingTraits<SWR_TILE_MODE_YMAJOR, 32> TTraits;184185UINT tileID = ComputeTileOffset2D<TTraits>(pitch, x >> TTraits::GetCu(), y >> TTraits::GetCv());186UINT xSwizzle = ((x << 5) & 0xe00) | (x & 0xf);187UINT ySwizzle = (y << 4) & 0x1f0;188return (tileID | xSwizzle | ySwizzle);189}190#endif191192//////////////////////////////////////////////////////////////////////////193/// @brief Computes the byte offset for 3D tiled surfaces194/// @param qpitch - depth pitch in rows195/// @param pitch - surface pitch in bytes196/// @param x - x offset in bytes197/// @param y - y offset in rows198/// @param z - y offset in slices199template<typename TTraits>200INLINE UINT ComputeOffset3D(UINT qpitch, UINT pitch, UINT x, UINT y, UINT z)201{202UINT tileID = ComputeTileOffset3D<TTraits>(qpitch, pitch, x >> TTraits::GetCu(), y >> TTraits::GetCv(), z >> TTraits::GetCr());203UINT xSwizzle = pdep_u32(x, TTraits::GetPdepX());204UINT ySwizzle = pdep_u32(y, TTraits::GetPdepY());205return (tileID | xSwizzle | ySwizzle);206}207208209