const SWR_FORMAT_INFO &swr_desc = GetFormatInfo(
mesa_to_swr_format(attribs[i].src_format));
velems->stream_pitch[attribs[i].vertex_buffer_index] += swr_desc.Bpp;
+
+ if (attribs[i].instance_divisor != 0) {
+ velems->instanced_bufs |= 1U << attribs[i].vertex_buffer_index;
+ uint32_t *min_instance_div =
+ &velems->min_instance_div[attribs[i].vertex_buffer_index];
+ if (!*min_instance_div ||
+ attribs[i].instance_divisor < *min_instance_div)
+ *min_instance_div = attribs[i].instance_divisor;
+ }
}
}
return need_fence;
}
+static inline void
+swr_user_vbuf_range(const struct pipe_draw_info *info,
+ const struct swr_vertex_element_state *velems,
+ const struct pipe_vertex_buffer *vb,
+ uint32_t i,
+ uint32_t *totelems,
+ uint32_t *base,
+ uint32_t *size)
+{
+ /* FIXME: The size is too large - we don't access the full extra stride. */
+ unsigned elems;
+ if (velems->instanced_bufs & (1U << i)) {
+ elems = info->instance_count / velems->min_instance_div[i] + 1;
+ *totelems = info->start_instance + elems;
+ *base = info->start_instance * vb->stride;
+ *size = elems * vb->stride;
+ } else if (vb->stride) {
+ elems = info->max_index - info->min_index + 1;
+ *totelems = info->max_index + 1;
+ *base = info->min_index * vb->stride;
+ *size = elems * vb->stride;
+ } else {
+ *totelems = 1;
+ *base = 0;
+ *size = velems->stream_pitch[i];
+ }
+}
+
void
swr_update_derived(struct pipe_context *pipe,
const struct pipe_draw_info *p_draw_info)
/* Set vertex & index buffers */
/* (using draw info if called by swr_draw_vbo) */
if (ctx->dirty & SWR_NEW_VERTEX) {
- uint32_t size, pitch, max_vertex, partial_inbounds, scratch_total;
- const uint8_t *p_data;
+ uint32_t scratch_total;
uint8_t *scratch = NULL;
/* If being called by swr_draw_vbo, copy draw details */
if (!vb->user_buffer)
continue;
- if (vb->stride) {
- size = (info.max_index - info.min_index + 1) * vb->stride;
- } else {
- /* pitch = 0, means constant value
- * set size to 1 vertex */
- size = ctx->velems->stream_pitch[i];
- }
-
+ uint32_t elems, base, size;
+ swr_user_vbuf_range(&info, ctx->velems, vb, i, &elems, &base, &size);
scratch_total += AlignUp(size, 4);
}
/* vertex buffers */
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;
+ const uint8_t *p_data;
struct pipe_vertex_buffer *vb = &ctx->vertex_buffer[i];
pitch = vb->stride;
* size is based on buffer->width0 rather than info.max_index
* to prevent having to validate VBO on each draw */
size = vb->buffer->width0;
- max_vertex = size / pitch;
+ elems = size / pitch;
partial_inbounds = size % pitch;
p_data = swr_resource_data(vb->buffer) + vb->buffer_offset;
* revalidate on each draw */
post_update_dirty_flags |= SWR_NEW_VERTEX;
- if (pitch) {
- size = (info.max_index - info.min_index + 1) * pitch;
- } else {
- /* pitch = 0, means constant value
- * set size to 1 vertex */
- size = ctx->velems->stream_pitch[i];
- }
-
- max_vertex = info.max_index + 1;
+ uint32_t base;
+ swr_user_vbuf_range(&info, ctx->velems, vb, i, &elems, &base, &size);
partial_inbounds = 0;
/* Copy only needed vertices to scratch space */
size = AlignUp(size, 4);
- const void *ptr = (const uint8_t *) vb->user_buffer
- + info.min_index * pitch;
+ const void *ptr = (const uint8_t *) vb->user_buffer + base;
memcpy(scratch, ptr, size);
ptr = scratch;
scratch += size;
- p_data = (const uint8_t *)ptr - info.min_index * pitch;
+ p_data = (const uint8_t *)ptr - base;
}
swrVertexBuffers[i] = {0};
swrVertexBuffers[i].pitch = pitch;
swrVertexBuffers[i].pData = p_data;
swrVertexBuffers[i].size = size;
- swrVertexBuffers[i].maxVertex = max_vertex;
+ swrVertexBuffers[i].maxVertex = elems;
swrVertexBuffers[i].partialInboundsSize = partial_inbounds;
}
/* index buffer, if required (info passed in by swr_draw_vbo) */
SWR_FORMAT index_type = R32_UINT; /* Default for non-indexed draws */
if (info.indexed) {
+ const uint8_t *p_data;
+ uint32_t size, pitch;
struct pipe_index_buffer *ib = &ctx->index_buffer;
pitch = ib->index_size ? ib->index_size : sizeof(uint32_t);