Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal: Bind index buffer with offset #96349

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/metal/metal_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class API_AVAILABLE(macos(11.0), ios(14.0)) MDCommandBuffer {
id<MTLRenderCommandEncoder> encoder = nil;
id<MTLBuffer> __unsafe_unretained index_buffer = nil; // Buffer is owned by RDD.
MTLIndexType index_type = MTLIndexTypeUInt16;
uint32_t index_offset = 0;
LocalVector<id<MTLBuffer> __unsafe_unretained> vertex_buffers;
LocalVector<NSUInteger> vertex_offsets;
// clang-format off
Expand Down
8 changes: 6 additions & 2 deletions drivers/metal/metal_objects.mm
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@

render.index_buffer = rid::get(p_buffer);
render.index_type = p_format == RDD::IndexBufferFormat::INDEX_BUFFER_FORMAT_UINT16 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32;
render.index_offset = p_offset;
}

void MDCommandBuffer::render_draw_indexed(uint32_t p_index_count,
Expand All @@ -729,13 +730,16 @@

id<MTLRenderCommandEncoder> enc = render.encoder;

uint32_t index_offset = render.index_offset;
index_offset += p_first_index * (render.index_type == MTLIndexTypeUInt16 ? sizeof(uint16_t) : sizeof(uint32_t));

[enc drawIndexedPrimitives:render.pipeline->raster_state.render_primitive
indexCount:p_index_count
indexType:render.index_type
indexBuffer:render.index_buffer
indexBufferOffset:p_vertex_offset
indexBufferOffset:index_offset
instanceCount:p_instance_count
baseVertex:p_first_index
baseVertex:p_vertex_offset
baseInstance:p_first_instance];
}

Expand Down
Loading