Value* startVertexOffset = MUL(Z_EXT(startOffset, mInt64Ty), stride);
+ Value *minVertex = NULL;
+ Value *minVertexOffset = NULL;
+ if (fetchState.bPartialVertexBuffer) {
+ // fetch min index for low bounds checking
+ minVertex = GEP(streams, {C(ied.StreamIndex), C(SWR_VERTEX_BUFFER_STATE_minVertex)});
+ minVertex = LOAD(minVertex);
+ if (!fetchState.bDisableIndexOOBCheck) {
+ minVertexOffset = MUL(Z_EXT(minVertex, mInt64Ty), stride);
+ }
+ }
+
// Load from the stream.
for(uint32_t lane = 0; lane < mVWidth; ++lane)
{
// Get index
Value* index = VEXTRACT(vCurIndices, C(lane));
+
+ if (fetchState.bPartialVertexBuffer) {
+ // clamp below minvertex
+ Value *isBelowMin = ICMP_SLT(index, minVertex);
+ index = SELECT(isBelowMin, minVertex, index);
+ }
+
index = Z_EXT(index, mInt64Ty);
Value* offset = MUL(index, stride);
offset = ADD(offset, startVertexOffset);
if (!fetchState.bDisableIndexOOBCheck) {
- // check for out of bound access, including partial OOB, and mask them to 0
+ // check for out of bound access, including partial OOB, and replace them with minVertex
Value *endOffset = ADD(offset, C((int64_t)info.Bpp));
Value *oob = ICMP_ULE(endOffset, size);
- offset = SELECT(oob, offset, ConstantInt::get(mInt64Ty, 0));
+ if (fetchState.bPartialVertexBuffer) {
+ offset = SELECT(oob, offset, minVertexOffset);
+ } else {
+ offset = SELECT(oob, offset, ConstantInt::get(mInt64Ty, 0));
+ }
}
Value* pointer = GEP(stream, offset);
Value *maxVertex = GEP(streams, {C(ied.StreamIndex), C(SWR_VERTEX_BUFFER_STATE_maxVertex)});
maxVertex = LOAD(maxVertex);
+ Value *minVertex = NULL;
+ if (fetchState.bPartialVertexBuffer) {
+ // min vertex index for low bounds OOB checking
+ minVertex = GEP(streams, {C(ied.StreamIndex), C(SWR_VERTEX_BUFFER_STATE_minVertex)});
+ minVertex = LOAD(minVertex);
+ }
+
Value *vCurIndices;
Value *startOffset;
if(ied.InstanceEnable)
// if we have a start offset, subtract from max vertex. Used for OOB check
maxVertex = SUB(Z_EXT(maxVertex, mInt64Ty), Z_EXT(startOffset, mInt64Ty));
- Value* neg = ICMP_SLT(maxVertex, C((int64_t)0));
+ Value* maxNeg = ICMP_SLT(maxVertex, C((int64_t)0));
// if we have a negative value, we're already OOB. clamp at 0.
- maxVertex = SELECT(neg, C(0), TRUNC(maxVertex, mInt32Ty));
+ maxVertex = SELECT(maxNeg, C(0), TRUNC(maxVertex, mInt32Ty));
+
+ if (fetchState.bPartialVertexBuffer) {
+ // similary for min vertex
+ minVertex = SUB(Z_EXT(minVertex, mInt64Ty), Z_EXT(startOffset, mInt64Ty));
+ Value *minNeg = ICMP_SLT(minVertex, C((int64_t)0));
+ minVertex = SELECT(minNeg, C(0), TRUNC(minVertex, mInt32Ty));
+ }
// Load the in bounds size of a partially valid vertex
Value *partialInboundsSize = GEP(streams, {C(ied.StreamIndex), C(SWR_VERTEX_BUFFER_STATE_partialInboundsSize)});
Value* vMaxVertex = VBROADCAST(maxVertex);
Value* vPartialOOBMask = ICMP_EQ(vCurIndices, vMaxVertex);
- // are vertices are fully in bounds?
- Value* vGatherMask = ICMP_ULT(vCurIndices, vMaxVertex);
+ // are vertices fully in bounds?
+ Value* vMaxGatherMask = ICMP_ULT(vCurIndices, vMaxVertex);
+
+ Value *vGatherMask;
+ if (fetchState.bPartialVertexBuffer) {
+ // are vertices below minVertex limit?
+ Value *vMinVertex = VBROADCAST(minVertex);
+ Value *vMinGatherMask = ICMP_UGE(vCurIndices, vMinVertex);
+
+ // only fetch lanes that pass both tests
+ vGatherMask = AND(vMaxGatherMask, vMinGatherMask);
+ } else {
+ vGatherMask = vMaxGatherMask;
+ }
// blend in any partially OOB indices that have valid elements
vGatherMask = SELECT(vPartialOOBMask, vElementInBoundsMask, vGatherMask);
SWR_VERTEX_BUFFER_STATE swrVertexBuffers[PIPE_MAX_ATTRIBS];
for (UINT i = 0; i < ctx->num_vertex_buffers; i++) {
uint32_t size, pitch, elems, partial_inbounds;
+ uint32_t min_vertex_index;
const uint8_t *p_data;
struct pipe_vertex_buffer *vb = &ctx->vertex_buffer[i];
size = vb->buffer->width0;
elems = size / pitch;
partial_inbounds = size % pitch;
+ min_vertex_index = 0;
p_data = swr_resource_data(vb->buffer) + vb->buffer_offset;
} else {
uint32_t base;
swr_user_vbuf_range(&info, ctx->velems, vb, i, &elems, &base, &size);
partial_inbounds = 0;
+ min_vertex_index = info.min_index;
/* Copy only needed vertices to scratch space */
size = AlignUp(size, 4);
swrVertexBuffers[i].pitch = pitch;
swrVertexBuffers[i].pData = p_data;
swrVertexBuffers[i].size = size;
+ swrVertexBuffers[i].minVertex = min_vertex_index;
swrVertexBuffers[i].maxVertex = elems;
swrVertexBuffers[i].partialInboundsSize = partial_inbounds;
}