<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Reviewed-by: Tim Rowley <<a href="mailto:timothy.o.rowley@intel.com" class="">timothy.o.rowley@intel.com</a>>
<div class=""><br class="">
<div style="">
<blockquote type="cite" class="">
<div class="">On Nov 17, 2016, at 6:51 PM, Ilia Mirkin <<a href="mailto:imirkin@alum.mit.edu" class="">imirkin@alum.mit.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Currently clears only operate on the 0th array index (ignoring surface<br class="">
layout parameters). Instead normalize to take a RTAI like all the<br class="">
load/store tile logic does, and use ComputeSurfaceAddress to properly<br class="">
take the surface state's lod/array index into account.<br class="">
---<br class="">
src/gallium/drivers/swr/rasterizer/core/api.cpp      |  3 +++<br class="">
src/gallium/drivers/swr/rasterizer/core/api.h        |  5 ++++-<br class="">
src/gallium/drivers/swr/rasterizer/core/backend.cpp  | 20 ++++++++++----------<br class="">
src/gallium/drivers/swr/rasterizer/core/context.h    |  1 +<br class="">
.../drivers/swr/rasterizer/memory/ClearTile.cpp      | 20 +++++++++++++-------<br class="">
src/gallium/drivers/swr/swr_clear.cpp                |  2 +-<br class="">
src/gallium/drivers/swr/swr_memory.h                 |  4 +++-<br class="">
7 files changed, 35 insertions(+), 20 deletions(-)<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/core/api.cpp b/src/gallium/drivers/swr/rasterizer/core/api.cpp<br class="">
index 6ade65a..383a7ad 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/core/api.cpp<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/core/api.cpp<br class="">
@@ -1476,6 +1476,7 @@ void SWR_API SwrStoreTiles(<br class="">
/// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil<br class="">
/// @param hContext - Handle passed back from SwrCreateContext<br class="">
/// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear<br class="">
+/// @param renderTargetArrayIndex - the RT array index to clear<br class="">
/// @param clearColor - color use for clearing render targets<br class="">
/// @param z - depth value use for clearing depth buffer<br class="">
/// @param stencil - stencil value used for clearing stencil buffer<br class="">
@@ -1483,6 +1484,7 @@ void SWR_API SwrStoreTiles(<br class="">
void SWR_API SwrClearRenderTarget(<br class="">
    HANDLE hContext,<br class="">
    uint32_t attachmentMask,<br class="">
+    uint32_t renderTargetArrayIndex,<br class="">
    const float clearColor[4],<br class="">
    float z,<br class="">
    uint8_t stencil,<br class="">
@@ -1503,6 +1505,7 @@ void SWR_API SwrClearRenderTarget(<br class="">
    pDC->FeWork.desc.clear.rect = clearRect;<br class="">
    pDC->FeWork.desc.clear.rect &= g_MaxScissorRect;<br class="">
    pDC->FeWork.desc.clear.attachmentMask = attachmentMask;<br class="">
+    pDC->FeWork.desc.clear.renderTargetArrayIndex = renderTargetArrayIndex;<br class="">
    pDC->FeWork.desc.clear.clearDepth = z;<br class="">
    pDC->FeWork.desc.clear.clearRTColor[0] = clearColor[0];<br class="">
    pDC->FeWork.desc.clear.clearRTColor[1] = clearColor[1];<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/core/api.h b/src/gallium/drivers/swr/rasterizer/core/api.h<br class="">
index 1a41637..d0f29dd 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/core/api.h<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/core/api.h<br class="">
@@ -137,10 +137,11 @@ typedef void(SWR_API *PFN_STORE_TILE)(HANDLE hPrivateContext, SWR_FORMAT srcForm<br class="">
/// @param renderTargetIndex - render target to store, can be color, depth or stencil<br class="">
/// @param x - destination x coordinate<br class="">
/// @param y - destination y coordinate<br class="">
+/// @param renderTargetArrayIndex - render target array offset from arrayIndex<br class="">
/// @param pClearColor - pointer to the hot tile's clear value<br class="">
typedef void(SWR_API *PFN_CLEAR_TILE)(HANDLE hPrivateContext,<br class="">
    SWR_RENDERTARGET_ATTACHMENT rtIndex,<br class="">
-    uint32_t x, uint32_t y, const float* pClearColor);<br class="">
+    uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, const float* pClearColor);<br class="">
<br class="">
//////////////////////////////////////////////////////////////////////////<br class="">
/// @brief Callback to allow driver to update their copy of streamout write offset.<br class="">
@@ -559,6 +560,7 @@ void SWR_API SwrStoreTiles(<br class="">
/// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil<br class="">
/// @param hContext - Handle passed back from SwrCreateContext<br class="">
/// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear<br class="">
+/// @param renderTargetArrayIndex - the RT array index to clear<br class="">
/// @param clearColor - color use for clearing render targets<br class="">
/// @param z - depth value use for clearing depth buffer<br class="">
/// @param stencil - stencil value used for clearing stencil buffer<br class="">
@@ -566,6 +568,7 @@ void SWR_API SwrStoreTiles(<br class="">
void SWR_API SwrClearRenderTarget(<br class="">
    HANDLE hContext,<br class="">
    uint32_t attachmentMask,<br class="">
+    uint32_t renderTargetArrayIndex,<br class="">
    const float clearColor[4],<br class="">
    float z,<br class="">
    uint8_t stencil,<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/core/backend.cpp b/src/gallium/drivers/swr/rasterizer/core/backend.cpp<br class="">
index 45eff15..c45c0a7 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/core/backend.cpp<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/core/backend.cpp<br class="">
@@ -37,7 +37,7 @@<br class="">
<br class="">
#include <algorithm><br class="">
<br class="">
-typedef void(*PFN_CLEAR_TILES)(DRAW_CONTEXT*, SWR_RENDERTARGET_ATTACHMENT rt, uint32_t, DWORD[4], const SWR_RECT& rect);<br class="">
+typedef void(*PFN_CLEAR_TILES)(DRAW_CONTEXT*, SWR_RENDERTARGET_ATTACHMENT rt, uint32_t, uint32_t, DWORD[4], const SWR_RECT& rect);<br class="">
static PFN_CLEAR_TILES sClearTilesTable[NUM_SWR_FORMATS];<br class="">
<br class="">
//////////////////////////////////////////////////////////////////////////<br class="">
@@ -134,7 +134,7 @@ void ClearRasterTile(uint8_t *pTileBuffer, simd16vector &value)<br class="">
<br class="">
#endif<br class="">
template<SWR_FORMAT format><br class="">
-INLINE void ClearMacroTile(DRAW_CONTEXT *pDC, SWR_RENDERTARGET_ATTACHMENT rt, uint32_t macroTile, DWORD clear[4], const SWR_RECT& rect)<br class="">
+INLINE void ClearMacroTile(DRAW_CONTEXT *pDC, SWR_RENDERTARGET_ATTACHMENT rt, uint32_t macroTile, uint32_t renderTargetArrayIndex, DWORD clear[4], const SWR_RECT& rect)<br class="">
{<br class="">
    // convert clear color to hottile format<br class="">
    // clear color is in RGBA float/uint32<br class="">
@@ -204,7 +204,7 @@ INLINE void ClearMacroTile(DRAW_CONTEXT *pDC, SWR_RENDERTARGET_ATTACHMENT rt, ui<br class="">
    const uint32_t macroTileRowStep = (KNOB_MACROTILE_X_DIM / KNOB_TILE_X_DIM) * rasterTileStep;<br class="">
    const uint32_t pitch = (FormatTraits<format>::bpp * KNOB_MACROTILE_X_DIM / 8);<br class="">
<br class="">
-    HOTTILE *pHotTile = pDC->pContext->pHotTileMgr->GetHotTile(pDC->pContext, pDC, macroTile, rt, true, numSamples);<br class="">
+    HOTTILE *pHotTile = pDC->pContext->pHotTileMgr->GetHotTile(pDC->pContext, pDC, macroTile, rt, true, numSamples, renderTargetArrayIndex);<br class="">
    uint32_t rasterTileStartOffset = (ComputeTileOffset2D< TilingTraits<SWR_TILE_SWRZ, FormatTraits<format>::bpp > >(pitch, clearTile.xmin, clearTile.ymin)) * numSamples;<br class="">
    uint8_t* pRasterTileRow = pHotTile->pBuffer + rasterTileStartOffset; //(ComputeTileOffset2D< TilingTraits<SWR_TILE_SWRZ, FormatTraits<format>::bpp > >(pitch, x, y)) * numSamples;<br class="">
<br class="">
@@ -249,7 +249,7 @@ void ProcessClearBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, vo<br class="">
            {<br class="">
                mask &= ~(1 << rt);<br class="">
<br class="">
-                HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, (SWR_RENDERTARGET_ATTACHMENT)rt, true, numSamples);<br class="">
+                HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, (SWR_RENDERTARGET_ATTACHMENT)rt, true, numSamples, pClear->renderTargetArrayIndex);<br class="">
<br class="">
                // All we want to do here is to mark the hot tile as being in a "needs clear" state.<br class="">
                pHotTile->clearData[0] = *(DWORD*)&(pClear->clearRTColor[0]);<br class="">
@@ -262,14 +262,14 @@ void ProcessClearBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, vo<br class="">
<br class="">
        if (pClear->attachmentMask & SWR_ATTACHMENT_DEPTH_BIT)<br class="">
        {<br class="">
-            HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, SWR_ATTACHMENT_DEPTH, true, numSamples);<br class="">
+            HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, SWR_ATTACHMENT_DEPTH, true, numSamples, pClear->renderTargetArrayIndex);<br class="">
            pHotTile->clearData[0] = *(DWORD*)&pClear->clearDepth;<br class="">
            pHotTile->state = HOTTILE_CLEAR;<br class="">
        }<br class="">
<br class="">
        if (pClear->attachmentMask & SWR_ATTACHMENT_STENCIL_BIT)<br class="">
        {<br class="">
-            HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, SWR_ATTACHMENT_STENCIL, true, numSamples);<br class="">
+            HOTTILE *pHotTile = pContext->pHotTileMgr->GetHotTile(pContext, pDC, macroTile, SWR_ATTACHMENT_STENCIL, true, numSamples, pClear->renderTargetArrayIndex);<br class="">
<br class="">
            pHotTile->clearData[0] = *(DWORD*)&pClear->clearStencil;<br class="">
            pHotTile->state = HOTTILE_CLEAR;<br class="">
@@ -300,7 +300,7 @@ void ProcessClearBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, vo<br class="">
            {<br class="">
                mask &= ~(1 << rt);<br class="">
<br class="">
-                pfnClearTiles(pDC, (SWR_RENDERTARGET_ATTACHMENT)rt, macroTile, clearData, pClear->rect);<br class="">
+                pfnClearTiles(pDC, (SWR_RENDERTARGET_ATTACHMENT)rt, macroTile, pClear->renderTargetArrayIndex, clearData, pClear->rect);<br class="">
            }<br class="">
        }<br class="">
<br class="">
@@ -311,7 +311,7 @@ void ProcessClearBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, vo<br class="">
            PFN_CLEAR_TILES pfnClearTiles = sClearTilesTable[KNOB_DEPTH_HOT_TILE_FORMAT];<br class="">
            SWR_ASSERT(pfnClearTiles != nullptr);<br class="">
<br class="">
-            pfnClearTiles(pDC, SWR_ATTACHMENT_DEPTH, macroTile, clearData, pClear->rect);<br class="">
+            pfnClearTiles(pDC, SWR_ATTACHMENT_DEPTH, macroTile, pClear->renderTargetArrayIndex, clearData, pClear->rect);<br class="">
        }<br class="">
<br class="">
        if (pClear->attachmentMask & SWR_ATTACHMENT_STENCIL_BIT)<br class="">
@@ -321,7 +321,7 @@ void ProcessClearBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile, vo<br class="">
            clearData[0] = *(DWORD*)&value;<br class="">
            PFN_CLEAR_TILES pfnClearTiles = sClearTilesTable[KNOB_STENCIL_HOT_TILE_FORMAT];<br class="">
<br class="">
-            pfnClearTiles(pDC, SWR_ATTACHMENT_STENCIL, macroTile, clearData, pClear->rect);<br class="">
+            pfnClearTiles(pDC, SWR_ATTACHMENT_STENCIL, macroTile, pClear->renderTargetArrayIndex, clearData, pClear->rect);<br class="">
        }<br class="">
<br class="">
        AR_END(BEClear, 1);<br class="">
@@ -364,7 +364,7 @@ void ProcessStoreTileBE(DRAW_CONTEXT *pDC, uint32_t workerId, uint32_t macroTile<br class="">
            PFN_CLEAR_TILES pfnClearTiles = sClearTilesTable[srcFormat];<br class="">
            SWR_ASSERT(pfnClearTiles != nullptr);<br class="">
<br class="">
-            pfnClearTiles(pDC, attachment, macroTile, pHotTile->clearData, pDesc->rect);<br class="">
+            pfnClearTiles(pDC, attachment, macroTile, pHotTile->renderTargetArrayIndex, pHotTile->clearData, pDesc->rect);<br class="">
        }<br class="">
<br class="">
        if (pHotTile->state == HOTTILE_DIRTY || pDesc->postStoreTileState == (SWR_TILE_STATE)HOTTILE_DIRTY)<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/core/context.h b/src/gallium/drivers/swr/rasterizer/core/context.h<br class="">
index 21ea827..6e596b4 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/core/context.h<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/core/context.h<br class="">
@@ -104,6 +104,7 @@ struct CLEAR_DESC<br class="">
{<br class="">
    SWR_RECT rect;<br class="">
    uint32_t attachmentMask;<br class="">
+    uint32_t renderTargetArrayIndex;<br class="">
    float clearRTColor[4];  // RGBA_32F<br class="">
    float clearDepth;   // [0..1]<br class="">
    uint8_t clearStencil;<br class="">
diff --git a/src/gallium/drivers/swr/rasterizer/memory/ClearTile.cpp b/src/gallium/drivers/swr/rasterizer/memory/ClearTile.cpp<br class="">
index d001cb6..717d12c 100644<br class="">
--- a/src/gallium/drivers/swr/rasterizer/memory/ClearTile.cpp<br class="">
+++ b/src/gallium/drivers/swr/rasterizer/memory/ClearTile.cpp<br class="">
@@ -33,7 +33,7 @@<br class="">
#include "memory/tilingtraits.h"<br class="">
#include "memory/Convert.h"<br class="">
<br class="">
-typedef void(*PFN_STORE_TILES_CLEAR)(const float*, SWR_SURFACE_STATE*, UINT, UINT);<br class="">
+typedef void(*PFN_STORE_TILES_CLEAR)(const float*, SWR_SURFACE_STATE*, UINT, UINT, uint32_t);<br class="">
<br class="">
//////////////////////////////////////////////////////////////////////////<br class="">
/// Clear Raster Tile Function Tables.<br class="">
@@ -57,11 +57,16 @@ struct StoreRasterTileClear<br class="">
        const uint8_t* dstFormattedColor,<br class="">
        UINT dstBytesPerPixel,<br class="">
        SWR_SURFACE_STATE* pDstSurface,<br class="">
-        UINT x, UINT y) // (x, y) pixel coordinate to start of raster tile.<br class="">
+        UINT x, UINT y, // (x, y) pixel coordinate to start of raster tile.<br class="">
+        uint32_t renderTargetArrayIndex)<br class="">
    {<br class="">
        // Compute destination address for raster tile.<br class="">
-        uint8_t* pDstTile = (uint8_t*)pDstSurface->pBaseAddress +<br class="">
-            (y * pDstSurface->pitch) + (x * dstBytesPerPixel);<br class="">
+        uint8_t* pDstTile = (uint8_t*)ComputeSurfaceAddress<false, false>(<br class="">
+                x, y, pDstSurface->arrayIndex + renderTargetArrayIndex,<br class="">
+                pDstSurface->arrayIndex + renderTargetArrayIndex,<br class="">
+                0, // sampleNum<br class="">
+                pDstSurface->lod,<br class="">
+                pDstSurface);<br class="">
<br class="">
        // start of first row<br class="">
        uint8_t* pDst = pDstTile;<br class="">
@@ -106,7 +111,7 @@ struct StoreMacroTileClear<br class="">
    static void StoreClear(<br class="">
        const float *pColor,<br class="">
        SWR_SURFACE_STATE* pDstSurface,<br class="">
-        UINT x, UINT y)<br class="">
+        UINT x, UINT y, uint32_t renderTargetArrayIndex)<br class="">
    {<br class="">
        UINT dstBytesPerPixel = (FormatTraits<DstFormat>::bpp / 8);<br class="">
<br class="">
@@ -129,7 +134,7 @@ struct StoreMacroTileClear<br class="">
        {<br class="">
            for (UINT col = 0; col < KNOB_MACROTILE_X_DIM; col += KNOB_TILE_X_DIM)<br class="">
            {<br class="">
-                StoreRasterTileClear<SrcFormat, DstFormat>::StoreClear(dstFormattedColor, dstBytesPerPixel, pDstSurface, (x + col), (y + row));<br class="">
+                StoreRasterTileClear<SrcFormat, DstFormat>::StoreClear(dstFormattedColor, dstBytesPerPixel, pDstSurface, (x + col), (y + row), renderTargetArrayIndex);<br class="">
            }<br class="">
        }<br class="">
    }<br class="">
@@ -146,6 +151,7 @@ void StoreHotTileClear(<br class="">
    SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,<br class="">
    UINT x,<br class="">
    UINT y,<br class="">
+    uint32_t renderTargetArrayIndex,<br class="">
    const float* pClearColor)<br class="">
{<br class="">
    PFN_STORE_TILES_CLEAR pfnStoreTilesClear = NULL;<br class="">
@@ -167,7 +173,7 @@ void StoreHotTileClear(<br class="">
    /// @todo Once all formats are supported then if check can go away. This is to help us near term to make progress.<br class="">
    if (pfnStoreTilesClear != NULL)<br class="">
    {<br class="">
-        pfnStoreTilesClear(pClearColor, pDstSurface, x, y);<br class="">
+        pfnStoreTilesClear(pClearColor, pDstSurface, x, y, renderTargetArrayIndex);<br class="">
    }<br class="">
}<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/swr_clear.cpp b/src/gallium/drivers/swr/swr_clear.cpp<br class="">
index 0101b4b..25f066e 100644<br class="">
--- a/src/gallium/drivers/swr/swr_clear.cpp<br class="">
+++ b/src/gallium/drivers/swr/swr_clear.cpp<br class="">
@@ -60,7 +60,7 @@ swr_clear(struct pipe_context *pipe,<br class="">
#endif<br class="">
<br class="">
   swr_update_draw_context(ctx);<br class="">
-   SwrClearRenderTarget(ctx->swrContext, clearMask, color->f, depth, stencil,<br class="">
+   SwrClearRenderTarget(ctx->swrContext, clearMask, 0, color->f, depth, stencil,<br class="">
                        ctx->swr_scissor);<br class="">
}<br class="">
<br class="">
diff --git a/src/gallium/drivers/swr/swr_memory.h b/src/gallium/drivers/swr/swr_memory.h<br class="">
index 9ef468a..b8ce27f 100644<br class="">
--- a/src/gallium/drivers/swr/swr_memory.h<br class="">
+++ b/src/gallium/drivers/swr/swr_memory.h<br class="">
@@ -42,6 +42,7 @@ void StoreHotTileClear(<br class="">
    SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,<br class="">
    UINT x,<br class="">
    UINT y,<br class="">
+    uint32_t renderTargetArrayIndex,<br class="">
    const float* pClearColor);<br class="">
<br class="">
INLINE void<br class="">
@@ -77,13 +78,14 @@ swr_StoreHotTileClear(HANDLE hPrivateContext,<br class="">
                      SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,<br class="">
                      UINT x,<br class="">
                      UINT y,<br class="">
+                      uint32_t renderTargetArrayIndex,<br class="">
                      const float* pClearColor)<br class="">
{<br class="">
   // Grab destination surface state from private context<br class="">
   swr_draw_context *pDC = (swr_draw_context*)hPrivateContext;<br class="">
   SWR_SURFACE_STATE *pDstSurface = &pDC->renderTargets[renderTargetIndex];<br class="">
<br class="">
-   StoreHotTileClear(pDstSurface, renderTargetIndex, x, y, pClearColor);<br class="">
+   StoreHotTileClear(pDstSurface, renderTargetIndex, x, y, renderTargetArrayIndex, pClearColor);<br class="">
}<br class="">
<br class="">
void InitSimLoadTilesTable();<br class="">
-- <br class="">
2.7.3<br class="">
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>