swr: [rasterizer core] fix comment typo
[mesa.git] / src / gallium / drivers / swr / rasterizer / core / api.h
index b45d4498ea0634f4599adb98a9428f0e97e351df..fc66cfd0d07ac3b0d1bc13b452b8bd9050e71df2 100644 (file)
 #include "common/os.h"
 
 #include <assert.h>
-#include <vector>
+#include <algorithm>
 
 #include "common/simdintrin.h"
 #include "common/formats.h"
-#include "core/utils.h"
 #include "core/state.h"
 
-///@todo place all the API functions into the 'swr' namespace.
-
 typedef void(SWR_API *PFN_CALLBACK_FUNC)(uint64_t data, uint64_t data2, uint64_t data3);
 
+//////////////////////////////////////////////////////////////////////////
+/// @brief Rectangle structure
+struct SWR_RECT
+{
+    int32_t xmin; ///< inclusive
+    int32_t ymin; ///< inclusive
+    int32_t xmax; ///< exclusive
+    int32_t ymax; ///< exclusive 
+
+    bool operator == (const SWR_RECT& rhs)
+    {
+        return (this->ymin == rhs.ymin &&
+            this->ymax == rhs.ymax &&
+            this->xmin == rhs.xmin &&
+            this->xmax == rhs.xmax);
+    }
+
+    bool operator != (const SWR_RECT& rhs)
+    {
+        return !(*this == rhs);
+    }
+
+    SWR_RECT& Intersect(const SWR_RECT& other)
+    {
+        this->xmin = std::max(this->xmin, other.xmin);
+        this->ymin = std::max(this->ymin, other.ymin);
+        this->xmax = std::min(this->xmax, other.xmax);
+        this->ymax = std::min(this->ymax, other.ymax);
+
+        if (xmax - xmin < 0 ||
+            ymax - ymin < 0)
+        {
+            // Zero area
+            ymin = ymax = xmin = xmax = 0;
+        }
+
+        return *this;
+    }
+    SWR_RECT& operator &= (const SWR_RECT& other)
+    {
+        return Intersect(other);
+    }
+
+    SWR_RECT& Union(const SWR_RECT& other)
+    {
+        this->xmin = std::min(this->xmin, other.xmin);
+        this->ymin = std::min(this->ymin, other.ymin);
+        this->xmax = std::max(this->xmax, other.xmax);
+        this->ymax = std::max(this->ymax, other.ymax);
+
+        return *this;
+    }
+
+    SWR_RECT& operator |= (const SWR_RECT& other)
+    {
+        return Union(other);
+    }
+
+    void Translate(int32_t x, int32_t y)
+    {
+        xmin += x;
+        ymin += y;
+        xmax += x;
+        ymax += y;
+    }
+};
+
 //////////////////////////////////////////////////////////////////////////
 /// @brief Function signature for load hot tiles
 /// @param hPrivateContext - handle to private data
@@ -88,8 +152,41 @@ typedef void(SWR_API *PFN_CLEAR_TILE)(HANDLE hPrivateContext,
 typedef void(SWR_API *PFN_UPDATE_SO_WRITE_OFFSET)(HANDLE hPrivateContext,
     uint32_t soBufferSlot, uint32_t soWriteOffset);
 
+//////////////////////////////////////////////////////////////////////////
+/// @brief Callback to allow driver to update their copy of stats.
+/// @param hPrivateContext - handle to private data
+/// @param pStats - pointer to draw stats
+typedef void(SWR_API *PFN_UPDATE_STATS)(HANDLE hPrivateContext,
+    const SWR_STATS* pStats);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Callback to allow driver to update their copy of FE stats.
+/// @note Its optimal to have a separate callback for FE stats since
+///       there is only one DC per FE thread. This means we do not have
+///       to sum up the stats across all of the workers.
+/// @param hPrivateContext - handle to private data
+/// @param pStats - pointer to draw stats
+typedef void(SWR_API *PFN_UPDATE_STATS_FE)(HANDLE hPrivateContext,
+    const SWR_STATS_FE* pStats);
+
+//////////////////////////////////////////////////////////////////////////
+/// BucketManager
+/// Forward Declaration (see rdtsc_buckets.h for full definition)
+/////////////////////////////////////////////////////////////////////////
 class BucketManager;
 
+//////////////////////////////////////////////////////////////////////////
+/// SWR_THREADING_INFO
+/////////////////////////////////////////////////////////////////////////
+struct SWR_THREADING_INFO
+{
+    uint32_t    MAX_WORKER_THREADS;
+    uint32_t    MAX_NUMA_NODES;
+    uint32_t    MAX_CORES_PER_NUMA_NODE;
+    uint32_t    MAX_THREADS_PER_CORE;
+    bool        SINGLE_THREADED;
+};
+
 //////////////////////////////////////////////////////////////////////////
 /// SWR_CREATECONTEXT_INFO
 /////////////////////////////////////////////////////////////////////////
@@ -102,10 +199,12 @@ struct SWR_CREATECONTEXT_INFO
     uint32_t privateStateSize;
 
     // Callback functions
-    PFN_LOAD_TILE pfnLoadTile;
-    PFN_STORE_TILE pfnStoreTile;
-    PFN_CLEAR_TILE pfnClearTile;
-    PFN_UPDATE_SO_WRITE_OFFSET pfnUpdateSoWriteOffset;
+    PFN_LOAD_TILE               pfnLoadTile;
+    PFN_STORE_TILE              pfnStoreTile;
+    PFN_CLEAR_TILE              pfnClearTile;
+    PFN_UPDATE_SO_WRITE_OFFSET  pfnUpdateSoWriteOffset;
+    PFN_UPDATE_STATS            pfnUpdateStats;
+    PFN_UPDATE_STATS_FE         pfnUpdateStatsFE;
 
     // Pointer to rdtsc buckets mgr returned to the caller.
     // Only populated when KNOB_ENABLE_RDTSC is set
@@ -113,17 +212,9 @@ struct SWR_CREATECONTEXT_INFO
 
     // Output: size required memory passed to for SwrSaveState / SwrRestoreState
     size_t  contextSaveSize;
-};
 
-//////////////////////////////////////////////////////////////////////////
-/// SWR_RECT
-/////////////////////////////////////////////////////////////////////////
-struct SWR_RECT
-{
-    uint32_t left;
-    uint32_t right;
-    uint32_t top;
-    uint32_t bottom;
+    // Input (optional): Threading info that overrides any set KNOB values.
+    SWR_THREADING_INFO* pThreadInfo;
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -321,6 +412,14 @@ void SWR_API SwrSetBackendState(
     HANDLE hContext,
     SWR_BACKEND_STATE *pState);
 
+//////////////////////////////////////////////////////////////////////////
+/// @brief Set depth bounds state
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param pState - Pointer to state.
+void SWR_API SwrSetDepthBoundsState(
+    HANDLE hContext,
+    SWR_DEPTH_BOUNDS_STATE *pState);
+
 //////////////////////////////////////////////////////////////////////////
 /// @brief Set pixel shader state
 /// @param hContext - Handle passed back from SwrCreateContext
@@ -411,19 +510,23 @@ void SWR_API SwrDrawIndexedInstanced(
 /// @brief SwrInvalidateTiles
 /// @param hContext - Handle passed back from SwrCreateContext
 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
+/// @param invalidateRect - The pixel-coordinate rectangle to invalidate.  This will be expanded to
+///                         be hottile size-aligned.
 void SWR_API SwrInvalidateTiles(
     HANDLE hContext,
-    uint32_t attachmentMask);
+    uint32_t attachmentMask,
+    const SWR_RECT& invalidateRect);
 
 //////////////////////////////////////////////////////////////////////////
 /// @brief SwrDiscardRect
 /// @param hContext - Handle passed back from SwrCreateContext
 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
-/// @param rect - if rect is all zeros, the entire attachment surface will be discarded
+/// @param rect - The pixel-coordinate rectangle to discard.  Only fully-covered hottiles will be
+///               discarded.
 void SWR_API SwrDiscardRect(
     HANDLE hContext,
     uint32_t attachmentMask,
-    SWR_RECT rect);
+    const SWR_RECT& rect);
 
 //////////////////////////////////////////////////////////////////////////
 /// @brief SwrDispatch
@@ -448,16 +551,31 @@ enum SWR_TILE_STATE
 /// @todo Add a good description for what attachments are and when and why you would use the different SWR_TILE_STATEs.
 void SWR_API SwrStoreTiles(
     HANDLE hContext,
-    SWR_RENDERTARGET_ATTACHMENT attachment,
-    SWR_TILE_STATE postStoreTileState);
+    uint32_t attachmentMask,
+    SWR_TILE_STATE postStoreTileState,
+    const SWR_RECT& storeRect);
 
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param clearMask - combination of SWR_CLEAR_COLOR / SWR_CLEAR_DEPTH / SWR_CLEAR_STENCIL flags (or SWR_CLEAR_NONE)
+/// @param clearColor - color use for clearing render targets
+/// @param z - depth value use for clearing depth buffer
+/// @param stencil - stencil value used for clearing stencil buffer
+/// @param clearRect - The pixel-coordinate rectangle to clear in all cleared buffers
 void SWR_API SwrClearRenderTarget(
     HANDLE hContext,
     uint32_t clearMask,
     const float clearColor[4],
     float z,
-    uint8_t stencil);
+    uint8_t stencil,
+    const SWR_RECT& clearRect);
 
+//////////////////////////////////////////////////////////////////////////
+/// @brief SwrSetRastState
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param pRastState - New SWR_RASTSTATE used for SwrDraw* commands
 void SWR_API SwrSetRastState(
     HANDLE hContext,
     const SWR_RASTSTATE *pRastState);
@@ -472,7 +590,7 @@ void SWR_API SwrSetViewports(
     HANDLE hContext,
     uint32_t numViewports,
     const SWR_VIEWPORT* pViewports,
-    const SWR_VIEWPORT_MATRIX* pMatrices);
+    const SWR_VIEWPORT_MATRICES* pMatrices);
 
 //////////////////////////////////////////////////////////////////////////
 /// @brief SwrSetScissorRects
@@ -482,7 +600,7 @@ void SWR_API SwrSetViewports(
 void SWR_API SwrSetScissorRects(
     HANDLE hContext,
     uint32_t numScissors,
-    const BBOX* pScissors);
+    const SWR_RECT* pScissors);
 
 //////////////////////////////////////////////////////////////////////////
 /// @brief Returns a pointer to the private context state for the current
@@ -508,17 +626,6 @@ VOID* SWR_API SwrAllocDrawContextMemory(
     uint32_t size,
     uint32_t align);
 
-//////////////////////////////////////////////////////////////////////////
-/// @brief Returns pointer to SWR stats.
-/// @note The counters are incremented by multiple threads.
-///       When calling this, you need to ensure all previous operations
-///       have completed.
-/// @param hContext - Handle passed back from SwrCreateContext
-/// @param pStats - SWR will fill this out for caller.
-void SWR_API SwrGetStats(
-    HANDLE hContext,
-    SWR_STATS* pStats);
-
 //////////////////////////////////////////////////////////////////////////
 /// @brief Enables stats counting
 /// @param hContext - Handle passed back from SwrCreateContext
@@ -532,4 +639,5 @@ void SWR_API SwrEnableStats(
 /// @param hContext - Handle passed back from SwrCreateContext
 void SWR_API SwrEndFrame(
     HANDLE hContext);
+
 #endif//__SWR_API_H__