Inherits MaskedOcclusionCulling.
Classes | |
struct | ZTile |
Public Member Functions | |
MaskedOcclusionCullingPrivate (pfnAlignedAlloc alignedAlloc, pfnAlignedFree alignedFree) | |
void | SetResolution (unsigned int width, unsigned int height) override |
Sets the resolution of the hierarchical depth buffer. This function will re-allocate the current depth buffer (if present). The contents of the buffer is undefined until ClearBuffer() is called. | |
void | GetResolution (unsigned int &width, unsigned int &height) const override |
Gets the resolution of the hierarchical depth buffer. | |
void | ComputeBinWidthHeight (unsigned int nBinsW, unsigned int nBinsH, unsigned int &outBinWidth, unsigned int &outBinHeight) override |
Returns the tile size for the current implementation. | |
void | SetNearClipPlane (float nearDist) override |
Sets the distance for the near clipping plane. Default is nearDist = 0. | |
float | GetNearClipPlane () const override |
Gets the distance for the near clipping plane. | |
void | ClearBuffer () override |
Clears the hierarchical depth buffer. | |
void | MergeBuffer (MaskedOcclusionCulling *BufferB) override |
Merge a second hierarchical depth buffer into the main buffer. | |
FORCE_INLINE int | ClipPolygon (__m128 *outVtx, __m128 *inVtx, const __m128 &plane, int n) const |
template<ClipPlanes CLIP_PLANE> | |
void | TestClipPlane (__mw *vtxX, __mw *vtxY, __mw *vtxW, unsigned int &straddleMask, unsigned int &triMask, ClipPlanes clipPlaneMask) |
FORCE_INLINE void | ClipTriangleAndAddToBuffer (__mw *vtxX, __mw *vtxY, __mw *vtxW, __m128 *clippedTrisBuffer, int &clipWriteIdx, unsigned int &triMask, unsigned int triClipMask, ClipPlanes clipPlaneMask) |
FORCE_INLINE void | TransformVerts (__mw *vtxX, __mw *vtxY, __mw *vtxW, const float *modelToClipMatrix) |
FORCE_INLINE void | ProjectVertices (__mw *pVtxX, __mw *pVtxY, __mw *pVtxZ, const __mw *vtxX, const __mw *vtxY, const __mw *vtxW) |
FORCE_INLINE void | GatherVerticesFast (__mw *vtxX, __mw *vtxY, __mw *vtxW, const float *inVtx, const unsigned int *inTrisPtr, int numLanes) |
FORCE_INLINE void | ComputeBoundingBox (__mwi &bbminX, __mwi &bbminY, __mwi &bbmaxX, __mwi &bbmaxY, const __mw *vX, const __mw *vY, const ScissorRect *scissor) |
FORCE_INLINE void | SortVertices (__mw *vX, __mw *vY) |
FORCE_INLINE int | CullBackfaces (__mw *pVtxX, __mw *pVtxY, __mw *pVtxZ, const __mw &ccwMask, BackfaceWinding bfWinding) |
FORCE_INLINE void | ComputeDepthPlane (const __mw *pVtxX, const __mw *pVtxY, const __mw *pVtxZ, __mw &zPixelDx, __mw &zPixelDy) const |
FORCE_INLINE void | UpdateTileQuick (int tileIdx, const __mwi &coverage, const __mw &zTriv) |
FORCE_INLINE void | UpdateTileAccurate (int tileIdx, const __mwi &coverage, const __mw &zTriv) |
template<int TEST_Z, int NRIGHT, int NLEFT> | |
FORCE_INLINE int | TraverseScanline (int leftOffset, int rightOffset, int tileIdx, int rightEvent, int leftEvent, const __mwi *events, const __mw &zTriMin, const __mw &zTriMax, const __mw &iz0, float zx) |
template<int TEST_Z, int TIGHT_TRAVERSAL, int MID_VTX_RIGHT> | |
FORCE_INLINE int | RasterizeTriangle (unsigned int triIdx, int bbWidth, int tileRowIdx, int tileMidRowIdx, int tileEndRowIdx, const __mwi *eventStart, const __mwi *slope, const __mwi *slopeTileDelta, const __mw &zTriMin, const __mw &zTriMax, __mw &z0, float zx, float zy) |
template<bool TEST_Z> | |
FORCE_INLINE int | RasterizeTriangleBatch (__mw pVtxX[3], __mw pVtxY[3], __mw pVtxZ[3], unsigned int triMask, const ScissorRect *scissor) |
template<int TEST_Z, int FAST_GATHER> | |
FORCE_INLINE CullingResult | RenderTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) |
Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values. | |
CullingResult | RenderTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override |
Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values. | |
CullingResult | TestTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override |
This function is similar to RenderTriangles(), but performs an occlusion query instead and does not update the hierarchical z buffer. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible. | |
CullingResult | TestRect (float xmin, float ymin, float xmax, float ymax, float wmin) const override |
Occlusion query for a rectangle with a given depth. The rectangle is given in normalized device coordinates where (x,y) coordinates between [-1,1] map to the visible screen area. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible. | |
template<bool FAST_GATHER> | |
FORCE_INLINE void | BinTriangles (const float *inVtx, const unsigned int *inTris, int nTris, TriList *triLists, unsigned int nBinsW, unsigned int nBinsH, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) |
Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example) | |
void | BinTriangles (const float *inVtx, const unsigned int *inTris, int nTris, TriList *triLists, unsigned int nBinsW, unsigned int nBinsH, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override |
Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example) | |
template<int FAST_GATHER> | |
void | GatherTransformClip (int &clipHead, int &clipTail, int &numLanes, int nTris, int &triIndex, __mw *vtxX, __mw *vtxY, __mw *vtxW, const float *inVtx, const unsigned int *&inTrisPtr, const VertexLayout &vtxLayout, const float *modelToClipMatrix, __m128 *clipTriBuffer, unsigned int &triMask, ClipPlanes clipPlaneMask) |
void | RenderTrilist (const TriList &triList, const ScissorRect *scissor) override |
Renders all occluder triangles in a trilist. This function can be used in combination with BinTriangles() to create a threded (binning) rasterizer. The bins can be processed independently by different threads without risking writing to overlapping memory regions. | |
MaskedOcclusionCulling::Implementation | GetImplementation () override |
Returns the implementation (CPU instruction set) version of this object. | |
void | ComputePixelDepthBuffer (float *depthData, bool flipY) override |
Creates a per-pixel depth buffer from the hierarchical z buffer representation. Intended for visualizing the hierarchical depth buffer for debugging. The buffer is written in scanline order, from the top to bottom (D3D) or bottom to top (OGL) of the surface. See the USE_D3D define. | |
OcclusionCullingStatistics | GetStatistics () override |
Fetch occlusion culling statistics, returns zeroes if ENABLE_STATS define is not defined. The statistics can be used for profiling or debugging. | |
![]() | |
void | GetAllocFreeCallback (pfnAlignedAlloc &allocCallback, pfnAlignedFree &freeCallback) |
Get used memory alloc/free callbacks. | |
Public Attributes | |
__mw | mHalfWidth |
__mw | mHalfHeight |
__mw | mCenterX |
__mw | mCenterY |
__m128 | mCSFrustumPlanes [5] |
__m128 | mIHalfSize |
__m128 | mICenter |
__m128i | mIScreenSize |
float | mNearDist |
int | mWidth |
int | mHeight |
int | mTilesWidth |
int | mTilesHeight |
ZTile * | mMaskedHiZBuffer |
ScissorRect | mFullscreenScissor |
Additional Inherited Members | |
![]() | |
enum | Implementation { SSE2 = 0 , SSE41 = 1 , AVX2 = 2 , AVX512 = 3 } |
enum | BackfaceWinding { BACKFACE_NONE = 0 , BACKFACE_CW = 1 , BACKFACE_CCW = 2 } |
enum | CullingResult { VISIBLE = 0x0 , OCCLUDED = 0x1 , VIEW_CULLED = 0x3 } |
enum | ClipPlanes { CLIP_PLANE_NONE = 0x00 , CLIP_PLANE_NEAR = 0x01 , CLIP_PLANE_LEFT = 0x02 , CLIP_PLANE_RIGHT = 0x04 , CLIP_PLANE_BOTTOM = 0x08 , CLIP_PLANE_TOP = 0x10 , CLIP_PLANE_SIDES = (CLIP_PLANE_LEFT | CLIP_PLANE_RIGHT | CLIP_PLANE_BOTTOM | CLIP_PLANE_TOP) , CLIP_PLANE_ALL = (CLIP_PLANE_LEFT | CLIP_PLANE_RIGHT | CLIP_PLANE_BOTTOM | CLIP_PLANE_TOP | CLIP_PLANE_NEAR) } |
typedef void *(*) | pfnAlignedAlloc(size_t alignment, size_t size) |
typedef void(*) | pfnAlignedFree(void *ptr) |
![]() | |
static MaskedOcclusionCulling * | Create (Implementation RequestedSIMD=AVX512) |
Creates a new object with default state, no z buffer attached/allocated. | |
static MaskedOcclusionCulling * | Create (Implementation RequestedSIMD, pfnAlignedAlloc alignedAlloc, pfnAlignedFree alignedFree) |
Creates a new object with default state, no z buffer attached/allocated. | |
static void | Destroy (MaskedOcclusionCulling *moc) |
Destroys an object and frees the z buffer memory. Note that you cannot use the delete operator, and should rather use this function to free up memory. | |
static void | TransformVertices (const float *mtx, const float *inVtx, float *xfVtx, unsigned int nVtx, const VertexLayout &vtxLayout=VertexLayout(12, 4, 8)) |
Utility function for transforming vertices and outputting them to an (x,y,z,w) format suitable for the occluder rasterization and occludee testing functions. | |
![]() | |
![]() | |
pfnAlignedAlloc | mAlignedAllocCallback |
pfnAlignedFree | mAlignedFreeCallback |
OcclusionCullingStatistics | mStats |
|
inlinevirtual |
Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)
inVtx | Pointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout. |
inTris | Pointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array. |
nTris | The number of triangles to render (inTris must contain atleast 3*nTris entries) |
triLists | Pointer to an array of TriList objects with one TriList object per bin. If a triangle overlaps a bin, it will be written to the corresponding trilist. Note that this method appends the triangles to the current list, to start writing from the beginning of the list, set triList.mTriIdx = 0 |
nBinsW | Number of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
nBinsH | Number of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
modelToClipMatrix | all vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped |
clipPlaneMask | A mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses. |
vtxLayout | A struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible. |
bfWinding | Sets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be binned / rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)
inVtx | Pointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout. |
inTris | Pointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array. |
nTris | The number of triangles to render (inTris must contain atleast 3*nTris entries) |
triLists | Pointer to an array of TriList objects with one TriList object per bin. If a triangle overlaps a bin, it will be written to the corresponding trilist. Note that this method appends the triangles to the current list, to start writing from the beginning of the list, set triList.mTriIdx = 0 |
nBinsW | Number of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
nBinsH | Number of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
modelToClipMatrix | all vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped |
clipPlaneMask | A mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses. |
vtxLayout | A struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible. |
bfWinding | Sets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be binned / rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Clears the hierarchical depth buffer.
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Returns the tile size for the current implementation.
nBinsW | Number of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
nBinsH | Number of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins. |
outBinWidth | Output: The width of the single bin in pixels (except for the rightmost bin width, which is extended to resolution width) |
outBinHeight | Output: The height of the single bin in pixels (except for the bottommost bin height, which is extended to resolution height) |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Creates a per-pixel depth buffer from the hierarchical z buffer representation. Intended for visualizing the hierarchical depth buffer for debugging. The buffer is written in scanline order, from the top to bottom (D3D) or bottom to top (OGL) of the surface. See the USE_D3D define.
depthData | Pointer to memory where the per-pixel depth data is written. Must hold storage for atleast width*height elements as set by setResolution. |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Returns the implementation (CPU instruction set) version of this object.
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Gets the distance for the near clipping plane.
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Gets the resolution of the hierarchical depth buffer.
witdh | Output: The width of the buffer in pixels |
height | Output: The height of the buffer in pixels |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Fetch occlusion culling statistics, returns zeroes if ENABLE_STATS define is not defined. The statistics can be used for profiling or debugging.
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Merge a second hierarchical depth buffer into the main buffer.
Implements MaskedOcclusionCulling.
|
inlinevirtual |
Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.
This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.
inVtx | Pointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout. |
inTris | Pointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array. |
nTris | The number of triangles to render (inTris must contain atleast 3*nTris entries) |
modelToClipMatrix | all vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped |
bfWinding | Sets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry |
clipPlaneMask | A mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses. |
vtxLayout | A struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible. |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.
This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.
inVtx | Pointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout. |
inTris | Pointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array. |
nTris | The number of triangles to render (inTris must contain atleast 3*nTris entries) |
modelToClipMatrix | all vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped |
bfWinding | Sets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry |
clipPlaneMask | A mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses. |
vtxLayout | A struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible. |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Renders all occluder triangles in a trilist. This function can be used in combination with BinTriangles() to create a threded (binning) rasterizer. The bins can be processed independently by different threads without risking writing to overlapping memory regions.
triLists | A triangle list, filled using the BinTriangles() function that is to be rendered. |
scissor | A scissor box limiting the rendering region to the bin. The size of each bin must be a multiple of 32x8 pixels due to implementation constraints. For a render target with (width, height) resolution and (nBinsW, nBinsH) bins, the size of a bin is: binWidth = (width / nBinsW) - (width / nBinsW) % 32; binHeight = (height / nBinsH) - (height / nBinsH) % 8; The last row and column of tiles have a different size: lastColBinWidth = width - (nBinsW-1)*binWidth; lastRowBinHeight = height - (nBinsH-1)*binHeight; |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Sets the distance for the near clipping plane. Default is nearDist = 0.
nearDist | The distance to the near clipping plane, given as clip space w |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Sets the resolution of the hierarchical depth buffer. This function will re-allocate the current depth buffer (if present). The contents of the buffer is undefined until ClearBuffer() is called.
witdh | The width of the buffer in pixels, must be a multiple of 8 |
height | The height of the buffer in pixels, must be a multiple of 4 |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
Occlusion query for a rectangle with a given depth. The rectangle is given in normalized device coordinates where (x,y) coordinates between [-1,1] map to the visible screen area. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
xmin | NDC coordinate of the left side of the rectangle. |
ymin | NDC coordinate of the bottom side of the rectangle. |
xmax | NDC coordinate of the right side of the rectangle. |
ymax | NDC coordinate of the top side of the rectangle. |
ymax | NDC coordinate of the top side of the rectangle. |
wmin | Clip space W coordinate for the rectangle. |
Implements MaskedOcclusionCulling.
|
inlineoverridevirtual |
This function is similar to RenderTriangles(), but performs an occlusion query instead and does not update the hierarchical z buffer. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.
inVtx | Pointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout. |
inTris | Pointer to an array of triangle indices. Each triangle is created from three indices consecutively fetched from the array. |
nTris | The number of triangles to render (inTris must contain atleast 3*nTris entries) |
modelToClipMatrix | all vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped |
bfWinding | Sets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be occlusion tested. You may use BACKFACE_NONE to disable culling for double sided geometry |
clipPlaneMask | A mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses. |
vtxLayout | A struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible. |
Implements MaskedOcclusionCulling.