mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 15:16:16 +00:00
Fix a DrawElements bug in the Metal backend.
The indexOffset of the draw was not being used. It must be included in the indexBufferOffset. Renamed indexBufferOffset -> indexBufferBaseOffset. Add a DrawElements test which exercises zero and non-zero index offsets.
This commit is contained in:
committed by
Corentin Wallez
parent
a5aacc9cad
commit
8c231b6990
@@ -167,7 +167,7 @@ namespace backend { namespace metal {
|
||||
ComputePipeline* lastComputePipeline = nullptr;
|
||||
RenderPipeline* lastRenderPipeline = nullptr;
|
||||
id<MTLBuffer> indexBuffer = nil;
|
||||
uint32_t indexBufferOffset = 0;
|
||||
uint32_t indexBufferBaseOffset = 0;
|
||||
|
||||
CurrentEncoders encoders;
|
||||
encoders.device = mDevice;
|
||||
@@ -304,6 +304,7 @@ namespace backend { namespace metal {
|
||||
|
||||
case Command::DrawElements: {
|
||||
DrawElementsCmd* draw = mCommands.NextCommand<DrawElementsCmd>();
|
||||
size_t formatSize = IndexFormatSize(lastRenderPipeline->GetIndexFormat());
|
||||
|
||||
ASSERT(encoders.render);
|
||||
[encoders.render
|
||||
@@ -311,7 +312,7 @@ namespace backend { namespace metal {
|
||||
indexCount:draw->indexCount
|
||||
indexType:lastRenderPipeline->GetMTLIndexType()
|
||||
indexBuffer:indexBuffer
|
||||
indexBufferOffset:indexBufferOffset
|
||||
indexBufferOffset:indexBufferBaseOffset + draw->firstIndex * formatSize
|
||||
instanceCount:draw->instanceCount
|
||||
baseVertex:0
|
||||
baseInstance:draw->firstInstance];
|
||||
@@ -526,7 +527,7 @@ namespace backend { namespace metal {
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
auto b = ToBackend(cmd->buffer.Get());
|
||||
indexBuffer = b->GetMTLBuffer();
|
||||
indexBufferOffset = cmd->offset;
|
||||
indexBufferBaseOffset = cmd->offset;
|
||||
} break;
|
||||
|
||||
case Command::SetVertexBuffers: {
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace backend { namespace opengl {
|
||||
PipelineBase* lastPipeline = nullptr;
|
||||
PipelineGL* lastGLPipeline = nullptr;
|
||||
RenderPipeline* lastRenderPipeline = nullptr;
|
||||
uint32_t indexBufferOffset = 0;
|
||||
uint32_t indexBufferBaseOffset = 0;
|
||||
|
||||
PersistentPipelineState persistentPipelineState;
|
||||
persistentPipelineState.SetDefaultState();
|
||||
@@ -505,7 +505,7 @@ namespace backend { namespace opengl {
|
||||
lastRenderPipeline->GetGLPrimitiveTopology(), draw->indexCount,
|
||||
formatType,
|
||||
reinterpret_cast<void*>(draw->firstIndex * formatSize +
|
||||
indexBufferOffset),
|
||||
indexBufferBaseOffset),
|
||||
draw->instanceCount, draw->firstInstance);
|
||||
} else {
|
||||
// This branch is only needed on OpenGL < 4.2
|
||||
@@ -513,7 +513,7 @@ namespace backend { namespace opengl {
|
||||
lastRenderPipeline->GetGLPrimitiveTopology(), draw->indexCount,
|
||||
formatType,
|
||||
reinterpret_cast<void*>(draw->firstIndex * formatSize +
|
||||
indexBufferOffset),
|
||||
indexBufferBaseOffset),
|
||||
draw->instanceCount);
|
||||
}
|
||||
} break;
|
||||
@@ -635,7 +635,7 @@ namespace backend { namespace opengl {
|
||||
|
||||
case Command::SetIndexBuffer: {
|
||||
SetIndexBufferCmd* cmd = mCommands.NextCommand<SetIndexBufferCmd>();
|
||||
indexBufferOffset = cmd->offset;
|
||||
indexBufferBaseOffset = cmd->offset;
|
||||
inputBuffers.OnSetIndexBuffer(cmd->buffer.Get());
|
||||
} break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user