Skip to content

Commit

Permalink
Fix, allow missing bone indices vertex attribute in Metal driver (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado authored Sep 18, 2019
1 parent 020e9e5 commit 5d725f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,9 @@
withRange:bufferRange];

// Bind the zero buffer, used for missing vertex attributes.
static const char bytes[4] = { 0 };
static const char bytes[16] = { 0 };
[mContext->currentCommandEncoder setVertexBytes:bytes
length:4
length:16
atIndex:(VERTEX_BUFFER_START + ZERO_VERTEX_BUFFER)];

MetalIndexBuffer* indexBuffer = primitive->indexBuffer;
Expand Down
12 changes: 10 additions & 2 deletions filament/backend/src/metal/MetalHandles.mm
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,24 @@ static inline MTLStorageMode getMetalStorageMode(TextureUsage usage) {
uint32_t bufferIndex = 0;
for (uint32_t attributeIndex = 0; attributeIndex < attributeCount; attributeIndex++) {
if (!(enabledAttributes & (1U << attributeIndex))) {
// TODO: all vertex attributes are vec4 (vector of floats), except for
// mesh_bone_indices, which is a uvec4 (vector of unsigned integers).
// We must use the correct format, but ideally the Metal driver should not need to know
// this.
const auto boneIndicesLocation = 5; // VertexAttribute::BONE_INDICES
const MTLVertexFormat format = attributeIndex == boneIndicesLocation ?
MTLVertexFormatUInt4 : MTLVertexFormatFloat4;

// If the attribute is not enabled, bind it to the zero buffer. It's a Metal error for a
// shader to read from missing vertex attributes.
vertexDescription.attributes[attributeIndex] = {
.format = MTLVertexFormatChar4,
.format = format,
.buffer = ZERO_VERTEX_BUFFER,
.offset = 0
};
vertexDescription.layouts[ZERO_VERTEX_BUFFER] = {
.step = MTLVertexStepFunctionConstant,
.stride = 4
.stride = 16
};
continue;
}
Expand Down

0 comments on commit 5d725f6

Please sign in to comment.