/****************************************************************************
-* Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
+* Copyright (C) 2014-2016 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "common/os.h"
#include <assert.h>
-#include <vector>
+#include <algorithm>
-#include "common/simdintrin.h"
+#include "common/intrin.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
/// @param pDstHotTile - pointer to the hot tile surface
typedef void(SWR_API *PFN_LOAD_TILE)(HANDLE hPrivateContext, SWR_FORMAT dstFormat,
SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
- uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, BYTE *pDstHotTile);
+ uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pDstHotTile);
//////////////////////////////////////////////////////////////////////////
/// @brief Function signature for store hot tiles
/// @param pSrcHotTile - pointer to the hot tile surface
typedef void(SWR_API *PFN_STORE_TILE)(HANDLE hPrivateContext, SWR_FORMAT srcFormat,
SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
- uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, BYTE *pSrcHotTile);
+ uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pSrcHotTile);
+//////////////////////////////////////////////////////////////////////////
/// @brief Function signature for clearing from the hot tiles clear value
/// @param hPrivateContext - handle to private data
/// @param renderTargetIndex - render target to store, can be color, depth or stencil
/// @param x - destination x coordinate
/// @param y - destination y coordinate
+/// @param renderTargetArrayIndex - render target array offset from arrayIndex
/// @param pClearColor - pointer to the hot tile's clear value
typedef void(SWR_API *PFN_CLEAR_TILE)(HANDLE hPrivateContext,
SWR_RENDERTARGET_ATTACHMENT rtIndex,
- uint32_t x, uint32_t y, const float* pClearColor);
+ uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, const float* pClearColor);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Callback to allow driver to update their copy of streamout write offset.
+/// This is call is made for any draw operation that has streamout enabled
+/// and has updated the write offset.
+/// @param hPrivateContext - handle to private data
+/// @param soBufferSlot - buffer slot for write offset
+/// @param soWriteOffset - update value for so write offset.
+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
/////////////////////////////////////////////////////////////////////////
struct SWR_CREATECONTEXT_INFO
{
- DRIVER_TYPE driver;
-
// External functions (e.g. sampler) need per draw context state.
// Use SwrGetPrivateContextState() to access private state.
uint32_t privateStateSize;
- // Tile manipulation functions
- PFN_LOAD_TILE pfnLoadTile;
- PFN_STORE_TILE pfnStoreTile;
- PFN_CLEAR_TILE pfnClearTile;
+ // Callback functions
+ 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
// 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;
};
//////////////////////////////////////////////////////////////////////////
/// @brief Create SWR Context.
/// @param pCreateInfo - pointer to creation info.
-HANDLE SWR_API SwrCreateContext(
+SWR_FUNC(HANDLE, SwrCreateContext,
SWR_CREATECONTEXT_INFO* pCreateInfo);
//////////////////////////////////////////////////////////////////////////
/// @brief Destroys SWR Context.
/// @param hContext - Handle passed back from SwrCreateContext
-void SWR_API SwrDestroyContext(
+SWR_FUNC(void, SwrDestroyContext,
HANDLE hContext);
//////////////////////////////////////////////////////////////////////////
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pOutputStateBlock - Memory block to receive API state data
/// @param memSize - Size of memory pointed to by pOutputStateBlock
-void SWR_API SwrSaveState(
+SWR_FUNC(void, SwrSaveState,
HANDLE hContext,
void* pOutputStateBlock,
size_t memSize);
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pStateBlock - Memory block to read API state data from
/// @param memSize - Size of memory pointed to by pStateBlock
-void SWR_API SwrRestoreState(
+SWR_FUNC(void, SwrRestoreState,
HANDLE hContext,
const void* pStateBlock,
size_t memSize);
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnFunc - pointer to callback function,
/// @param userData - user data to pass back
-void SWR_API SwrSync(
+SWR_FUNC(void, SwrSync,
HANDLE hContext,
PFN_CALLBACK_FUNC pfnFunc,
uint64_t userData,
uint64_t userData2,
- uint64_t userData3 = 0);
+ uint64_t userData3);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Stall cmd. Stalls the backend until all previous work has been completed.
+/// Frontend work can continue to make progress
+/// @param hContext - Handle passed back from SwrCreateContext
+SWR_FUNC(void, SwrStallBE,
+ HANDLE hContext);
//////////////////////////////////////////////////////////////////////////
/// @brief Blocks until all rendering has been completed.
/// @param hContext - Handle passed back from SwrCreateContext
-void SWR_API SwrWaitForIdle(
+SWR_FUNC(void, SwrWaitForIdle,
+ HANDLE hContext);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Blocks until all FE rendering has been completed.
+/// @param hContext - Handle passed back from SwrCreateContext
+SWR_FUNC(void, SwrWaitForIdleFE,
HANDLE hContext);
//////////////////////////////////////////////////////////////////////////
/// @param hContext - Handle passed back from SwrCreateContext
/// @param numBuffers - Number of vertex buffer state descriptors.
/// @param pVertexBuffers - Array of vertex buffer state descriptors.
-void SWR_API SwrSetVertexBuffers(
+SWR_FUNC(void, SwrSetVertexBuffers,
HANDLE hContext,
uint32_t numBuffers,
const SWR_VERTEX_BUFFER_STATE* pVertexBuffers);
/// @brief Set index buffer
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pIndexBuffer - Index buffer.
-void SWR_API SwrSetIndexBuffer(
+SWR_FUNC(void, SwrSetIndexBuffer,
HANDLE hContext,
const SWR_INDEX_BUFFER_STATE* pIndexBuffer);
/// @brief Set fetch shader pointer.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnFetchFunc - Pointer to shader.
-void SWR_API SwrSetFetchFunc(
+SWR_FUNC(void, SwrSetFetchFunc,
HANDLE hContext,
PFN_FETCH_FUNC pfnFetchFunc);
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnSoFunc - Pointer to shader.
/// @param streamIndex - specifies stream
-void SWR_API SwrSetSoFunc(
+SWR_FUNC(void, SwrSetSoFunc,
HANDLE hContext,
PFN_SO_FUNC pfnSoFunc,
uint32_t streamIndex);
/// @brief Set streamout state
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pSoState - Pointer to streamout state.
-void SWR_API SwrSetSoState(
+SWR_FUNC(void, SwrSetSoState,
HANDLE hContext,
SWR_STREAMOUT_STATE* pSoState);
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pSoBuffer - Pointer to streamout buffer.
/// @param slot - Slot to bind SO buffer to.
-void SWR_API SwrSetSoBuffers(
+SWR_FUNC(void, SwrSetSoBuffers,
HANDLE hContext,
SWR_STREAMOUT_BUFFER* pSoBuffer,
uint32_t slot);
/// @brief Set vertex shader pointer.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnVertexFunc - Pointer to shader.
-void SWR_API SwrSetVertexFunc(
+SWR_FUNC(void, SwrSetVertexFunc,
HANDLE hContext,
PFN_VERTEX_FUNC pfnVertexFunc);
/// @brief Set frontend state.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state
-void SWR_API SwrSetFrontendState(
+SWR_FUNC(void, SwrSetFrontendState,
HANDLE hContext,
SWR_FRONTEND_STATE *pState);
/// @brief Set geometry shader state.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state
-void SWR_API SwrSetGsState(
+SWR_FUNC(void, SwrSetGsState,
HANDLE hContext,
SWR_GS_STATE *pState);
/// @brief Set geometry shader
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to geometry shader function
-void SWR_API SwrSetGsFunc(
+SWR_FUNC(void, SwrSetGsFunc,
HANDLE hContext,
PFN_GS_FUNC pfnGsFunc);
//////////////////////////////////////////////////////////////////////////
/// @brief Set compute shader
/// @param hContext - Handle passed back from SwrCreateContext
-/// @param pState - Pointer to compute shader function
+/// @param pfnCsFunc - Pointer to compute shader function
/// @param totalThreadsInGroup - product of thread group dimensions.
-void SWR_API SwrSetCsFunc(
+/// @param totalSpillFillSize - size in bytes needed for spill/fill.
+/// @param scratchSpaceSizePerInstance - size of the scratch space needed per simd instance
+/// @param numInstances - number of simd instances that are run per execution of the shader
+SWR_FUNC(void, SwrSetCsFunc,
HANDLE hContext,
PFN_CS_FUNC pfnCsFunc,
- uint32_t totalThreadsInGroup);
+ uint32_t totalThreadsInGroup,
+ uint32_t totalSpillFillSize,
+ uint32_t scratchSpaceSizePerInstance,
+ uint32_t numInstances
+ );
//////////////////////////////////////////////////////////////////////////
/// @brief Set tessellation state.
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state
-void SWR_API SwrSetTsState(
+SWR_FUNC(void, SwrSetTsState,
HANDLE hContext,
SWR_TS_STATE *pState);
/// @brief Set hull shader
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnFunc - Pointer to shader function
-void SWR_API SwrSetHsFunc(
+SWR_FUNC(void, SwrSetHsFunc,
HANDLE hContext,
PFN_HS_FUNC pfnFunc);
/// @brief Set domain shader
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pfnFunc - Pointer to shader function
-void SWR_API SwrSetDsFunc(
+SWR_FUNC(void, SwrSetDsFunc,
HANDLE hContext,
PFN_DS_FUNC pfnFunc);
/// @brief Set depth stencil state
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state.
-void SWR_API SwrSetDepthStencilState(
+SWR_FUNC(void, SwrSetDepthStencilState,
HANDLE hContext,
SWR_DEPTH_STENCIL_STATE *pState);
/// @brief Set backend state
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state.
-void SWR_API SwrSetBackendState(
+SWR_FUNC(void, SwrSetBackendState,
HANDLE hContext,
SWR_BACKEND_STATE *pState);
+//////////////////////////////////////////////////////////////////////////
+/// @brief Set depth bounds state
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param pState - Pointer to state.
+SWR_FUNC(void, SwrSetDepthBoundsState,
+ HANDLE hContext,
+ SWR_DEPTH_BOUNDS_STATE *pState);
+
//////////////////////////////////////////////////////////////////////////
/// @brief Set pixel shader state
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state.
-void SWR_API SwrSetPixelShaderState(
+SWR_FUNC(void, SwrSetPixelShaderState,
HANDLE hContext,
SWR_PS_STATE *pState);
/// @brief Set blend state
/// @param hContext - Handle passed back from SwrCreateContext
/// @param pState - Pointer to state.
-void SWR_API SwrSetBlendState(
+SWR_FUNC(void, SwrSetBlendState,
HANDLE hContext,
SWR_BLEND_STATE *pState);
/// @param hContext - Handle passed back from SwrCreateContext
/// @param renderTarget - render target index
/// @param pfnBlendFunc - function pointer
-void SWR_API SwrSetBlendFunc(
+SWR_FUNC(void, SwrSetBlendFunc,
HANDLE hContext,
uint32_t renderTarget,
PFN_BLEND_JIT_FUNC pfnBlendFunc);
-//////////////////////////////////////////////////////////////////////////
-/// @brief Set linkage mask
-/// @param hContext - Handle passed back from SwrCreateContext
-/// @param mask - Specifies which vertex outputs are are needed by PS.
-/// @param pMap - (Optional)Linkage map to specify where FE attributes are
-/// gathered from to supply PS attribute values. The length
-/// of the map buffer needs to match the number of set bits
-/// in "mask".
-void SWR_API SwrSetLinkage(
- HANDLE hContext,
- uint32_t mask,
- const uint8_t* pMap);
-
//////////////////////////////////////////////////////////////////////////
/// @brief SwrDraw
/// @param hContext - Handle passed back from SwrCreateContext
/// @param topology - Specifies topology for draw.
/// @param startVertex - Specifies start vertex in vertex buffer for draw.
/// @param primCount - Number of vertices.
-void SWR_API SwrDraw(
+SWR_FUNC(void, SwrDraw,
HANDLE hContext,
PRIMITIVE_TOPOLOGY topology,
uint32_t startVertex,
/// @param numInstances - How many instances to render.
/// @param startVertex - Specifies start vertex for draw. (vertex data)
/// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
-void SWR_API SwrDrawInstanced(
+SWR_FUNC(void, SwrDrawInstanced,
HANDLE hContext,
PRIMITIVE_TOPOLOGY topology,
uint32_t numVertsPerInstance,
/// @param numIndices - Number of indices to read sequentially from index buffer.
/// @param indexOffset - Starting index into index buffer.
/// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
-void SWR_API SwrDrawIndexed(
+SWR_FUNC(void, SwrDrawIndexed,
HANDLE hContext,
PRIMITIVE_TOPOLOGY topology,
uint32_t numIndices,
/// @param indexOffset - Starting index into index buffer.
/// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
/// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
-void SWR_API SwrDrawIndexedInstanced(
+SWR_FUNC(void, SwrDrawIndexedInstanced,
HANDLE hContext,
PRIMITIVE_TOPOLOGY topology,
uint32_t numIndices,
/// @brief SwrInvalidateTiles
/// @param hContext - Handle passed back from SwrCreateContext
/// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
-void SWR_API SwrInvalidateTiles(
+/// @param invalidateRect - The pixel-coordinate rectangle to invalidate. This will be expanded to
+/// be hottile size-aligned.
+SWR_FUNC(void, 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 - The pixel-coordinate rectangle to discard. Only fully-covered hottiles will be
+/// discarded.
+SWR_FUNC(void, SwrDiscardRect,
+ HANDLE hContext,
+ uint32_t attachmentMask,
+ const SWR_RECT& rect);
//////////////////////////////////////////////////////////////////////////
/// @brief SwrDispatch
/// @param threadGroupCountX - Number of thread groups dispatched in X direction
/// @param threadGroupCountY - Number of thread groups dispatched in Y direction
/// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
-void SWR_API SwrDispatch(
+SWR_FUNC(void, SwrDispatch,
HANDLE hContext,
uint32_t threadGroupCountX,
uint32_t threadGroupCountY,
};
/// @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(
+SWR_FUNC(void, SwrStoreTiles,
HANDLE hContext,
- SWR_RENDERTARGET_ATTACHMENT attachment,
- SWR_TILE_STATE postStoreTileState);
+ uint32_t attachmentMask,
+ SWR_TILE_STATE postStoreTileState,
+ const SWR_RECT& storeRect);
-void SWR_API SwrClearRenderTarget(
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear
+/// @param renderTargetArrayIndex - the RT array index to clear
+/// @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
+SWR_FUNC(void, SwrClearRenderTarget,
HANDLE hContext,
- uint32_t clearMask,
+ uint32_t attachmentMask,
+ uint32_t renderTargetArrayIndex,
const float clearColor[4],
float z,
- BYTE stencil);
+ uint8_t stencil,
+ const SWR_RECT& clearRect);
-void SWR_API SwrSetRastState(
+//////////////////////////////////////////////////////////////////////////
+/// @brief SwrSetRastState
+/// @param hContext - Handle passed back from SwrCreateContext
+/// @param pRastState - New SWR_RASTSTATE used for SwrDraw* commands
+SWR_FUNC(void, SwrSetRastState,
HANDLE hContext,
const SWR_RASTSTATE *pRastState);
/// @param numViewports - number of viewports passed in
/// @param pViewports - Specifies extents of viewport.
/// @param pMatrices - If not specified then SWR computes a default one.
-void SWR_API SwrSetViewports(
+SWR_FUNC(void, SwrSetViewports,
HANDLE hContext,
uint32_t numViewports,
const SWR_VIEWPORT* pViewports,
- const SWR_VIEWPORT_MATRIX* pMatrices);
+ const SWR_VIEWPORT_MATRICES* pMatrices);
//////////////////////////////////////////////////////////////////////////
/// @brief SwrSetScissorRects
/// @param hContext - Handle passed back from SwrCreateContext
/// @param numScissors - number of scissors passed in
/// @param pScissors - array of scissors
-void SWR_API SwrSetScissorRects(
+SWR_FUNC(void, 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
/// @note Client needs to resend private state prior to each draw call.
/// Also, SWR is responsible for the private state memory.
/// @param hContext - Handle passed back from SwrCreateContext
-VOID* SWR_API SwrGetPrivateContextState(
+SWR_FUNC(void*, SwrGetPrivateContextState,
HANDLE hContext);
//////////////////////////////////////////////////////////////////////////
/// @param hContext - Handle passed back from SwrCreateContext
/// @param size - Size of allocation
/// @param align - Alignment needed for allocation.
-VOID* SWR_API SwrAllocDrawContextMemory(
+SWR_FUNC(void*, SwrAllocDrawContextMemory,
HANDLE hContext,
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.
+/// @brief Enables stats counting
/// @param hContext - Handle passed back from SwrCreateContext
-/// @param pStats - SWR will fill this out for caller.
-void SWR_API SwrGetStats(
+/// @param enable - If true then counts are incremented.
+SWR_FUNC(void, SwrEnableStatsFE,
HANDLE hContext,
- SWR_STATS* pStats);
+ bool enable);
//////////////////////////////////////////////////////////////////////////
/// @brief Enables stats counting
/// @param hContext - Handle passed back from SwrCreateContext
/// @param enable - If true then counts are incremented.
-void SWR_API SwrEnableStats(
+SWR_FUNC(void, SwrEnableStatsBE,
HANDLE hContext,
bool enable);
//////////////////////////////////////////////////////////////////////////
/// @brief Mark end of frame - used for performance profiling
/// @param hContext - Handle passed back from SwrCreateContext
-void SWR_API SwrEndFrame(
+SWR_FUNC(void, SwrEndFrame,
HANDLE hContext);
-#endif//__SWR_API_H__
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Initialize swr backend and memory internal tables
+SWR_FUNC(void, SwrInit);
+
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Loads a full hottile from a render surface
+/// @param hPrivateContext - Handle to private DC
+/// @param dstFormat - Format for hot tile.
+/// @param renderTargetIndex - Index to src render target
+/// @param x, y - Coordinates to raster tile.
+/// @param pDstHotTile - Pointer to Hot Tile
+SWR_FUNC(void, SwrLoadHotTile,
+ const SWR_SURFACE_STATE *pSrcSurface,
+ SWR_FORMAT dstFormat,
+ SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
+ uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
+ uint8_t *pDstHotTile);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Deswizzles and stores a full hottile to a render surface
+/// @param hPrivateContext - Handle to private DC
+/// @param srcFormat - Format for hot tile.
+/// @param renderTargetIndex - Index to destination render target
+/// @param x, y - Coordinates to raster tile.
+/// @param pSrcHotTile - Pointer to Hot Tile
+SWR_FUNC(void, SwrStoreHotTileToSurface,
+ SWR_SURFACE_STATE *pDstSurface,
+ SWR_FORMAT srcFormat,
+ SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
+ uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
+ uint8_t *pSrcHotTile);
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Writes clear color to every pixel of a render surface
+/// @param hPrivateContext - Handle to private DC
+/// @param renderTargetIndex - Index to destination render target
+/// @param x, y - Coordinates to raster tile.
+/// @param pClearColor - Pointer to clear color
+SWR_FUNC(void, SwrStoreHotTileClear,
+ SWR_SURFACE_STATE *pDstSurface,
+ SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
+ uint32_t x,
+ uint32_t y,
+ uint32_t renderTargetArrayIndex,
+ const float* pClearColor);
+
+struct SWR_INTERFACE
+{
+ PFNSwrCreateContext pfnSwrCreateContext;
+ PFNSwrDestroyContext pfnSwrDestroyContext;
+ PFNSwrSaveState pfnSwrSaveState;
+ PFNSwrRestoreState pfnSwrRestoreState;
+ PFNSwrSync pfnSwrSync;
+ PFNSwrStallBE pfnSwrStallBE;
+ PFNSwrWaitForIdle pfnSwrWaitForIdle;
+ PFNSwrWaitForIdleFE pfnSwrWaitForIdleFE;
+ PFNSwrSetVertexBuffers pfnSwrSetVertexBuffers;
+ PFNSwrSetIndexBuffer pfnSwrSetIndexBuffer;
+ PFNSwrSetFetchFunc pfnSwrSetFetchFunc;
+ PFNSwrSetSoFunc pfnSwrSetSoFunc;
+ PFNSwrSetSoState pfnSwrSetSoState;
+ PFNSwrSetSoBuffers pfnSwrSetSoBuffers;
+ PFNSwrSetVertexFunc pfnSwrSetVertexFunc;
+ PFNSwrSetFrontendState pfnSwrSetFrontendState;
+ PFNSwrSetGsState pfnSwrSetGsState;
+ PFNSwrSetGsFunc pfnSwrSetGsFunc;
+ PFNSwrSetCsFunc pfnSwrSetCsFunc;
+ PFNSwrSetTsState pfnSwrSetTsState;
+ PFNSwrSetHsFunc pfnSwrSetHsFunc;
+ PFNSwrSetDsFunc pfnSwrSetDsFunc;
+ PFNSwrSetDepthStencilState pfnSwrSetDepthStencilState;
+ PFNSwrSetBackendState pfnSwrSetBackendState;
+ PFNSwrSetDepthBoundsState pfnSwrSetDepthBoundsState;
+ PFNSwrSetPixelShaderState pfnSwrSetPixelShaderState;
+ PFNSwrSetBlendState pfnSwrSetBlendState;
+ PFNSwrSetBlendFunc pfnSwrSetBlendFunc;
+ PFNSwrDraw pfnSwrDraw;
+ PFNSwrDrawInstanced pfnSwrDrawInstanced;
+ PFNSwrDrawIndexed pfnSwrDrawIndexed;
+ PFNSwrDrawIndexedInstanced pfnSwrDrawIndexedInstanced;
+ PFNSwrInvalidateTiles pfnSwrInvalidateTiles;
+ PFNSwrDiscardRect pfnSwrDiscardRect;
+ PFNSwrDispatch pfnSwrDispatch;
+ PFNSwrStoreTiles pfnSwrStoreTiles;
+ PFNSwrClearRenderTarget pfnSwrClearRenderTarget;
+ PFNSwrSetRastState pfnSwrSetRastState;
+ PFNSwrSetViewports pfnSwrSetViewports;
+ PFNSwrSetScissorRects pfnSwrSetScissorRects;
+ PFNSwrGetPrivateContextState pfnSwrGetPrivateContextState;
+ PFNSwrAllocDrawContextMemory pfnSwrAllocDrawContextMemory;
+ PFNSwrEnableStatsFE pfnSwrEnableStatsFE;
+ PFNSwrEnableStatsBE pfnSwrEnableStatsBE;
+ PFNSwrEndFrame pfnSwrEndFrame;
+ PFNSwrInit pfnSwrInit;
+ PFNSwrLoadHotTile pfnSwrLoadHotTile;
+ PFNSwrStoreHotTileToSurface pfnSwrStoreHotTileToSurface;
+ PFNSwrStoreHotTileClear pfnSwrStoreHotTileClear;
+};
+
+extern "C" {
+typedef void (SWR_API * PFNSwrGetInterface)(SWR_INTERFACE &out_funcs);
+SWR_VISIBLE void SWR_API SwrGetInterface(SWR_INTERFACE &out_funcs);
+}
+
+#endif