use location numbers for vertex input attributes, instead of name-based binding.

- add 'location' named field to buffer and mesh vertex format tables, replaces 'name' field.
- location numbers are expected to match 'layout (location = #)' qualifiers in vertex inputs in shader code.
- deprecate vertex inputs in shader code that don't have layout location qualifiers.
- love's default vertex attributes use location 0 for position, 1 for texcoord, and 2 for color.
- add new variants of Mesh:attachAttribute, setAttributeEnabled, and isAttributeEnabled which take location numbers instead of names.

Improves draw performance in vulkan and metal backends.
This commit is contained in:
Sasha Szpakowski
2024-09-07 18:06:03 -03:00
parent c7b4ebbc55
commit 50ff1e4d2b
31 changed files with 683 additions and 258 deletions
+12 -8
View File
@@ -882,15 +882,17 @@ id<MTLRenderPipelineState> Shader::getCachedRenderPipeline(graphics::Graphics *g
auto formatdesc = Metal::convertPixelFormat(device, format);
attachment.pixelFormat = formatdesc.format;
if (key.blend.enable && gfx->isPixelFormatSupported(format, PIXELFORMATUSAGEFLAGS_BLEND))
BlendState blend = BlendState::fromKey(key.blendStateKey);
if (blend.enable && gfx->isPixelFormatSupported(format, PIXELFORMATUSAGEFLAGS_BLEND))
{
attachment.blendingEnabled = YES;
attachment.sourceRGBBlendFactor = getMTLBlendFactor(key.blend.srcFactorRGB);
attachment.destinationRGBBlendFactor = getMTLBlendFactor(key.blend.dstFactorRGB);
attachment.rgbBlendOperation = getMTLBlendOperation(key.blend.operationRGB);
attachment.sourceAlphaBlendFactor = getMTLBlendFactor(key.blend.srcFactorA);
attachment.destinationAlphaBlendFactor = getMTLBlendFactor(key.blend.dstFactorA);
attachment.alphaBlendOperation = getMTLBlendOperation(key.blend.operationA);
attachment.sourceRGBBlendFactor = getMTLBlendFactor(blend.srcFactorRGB);
attachment.destinationRGBBlendFactor = getMTLBlendFactor(blend.dstFactorRGB);
attachment.rgbBlendOperation = getMTLBlendOperation(blend.operationRGB);
attachment.sourceAlphaBlendFactor = getMTLBlendFactor(blend.srcFactorA);
attachment.destinationAlphaBlendFactor = getMTLBlendFactor(blend.dstFactorA);
attachment.alphaBlendOperation = getMTLBlendOperation(blend.operationA);
}
MTLColorWriteMask writeMask = MTLColorWriteMaskNone;
@@ -923,8 +925,10 @@ id<MTLRenderPipelineState> Shader::getCachedRenderPipeline(graphics::Graphics *g
}
}
VertexAttributes attributes;
gfx->findVertexAttributes(key.vertexAttributesID, attributes);
MTLVertexDescriptor *vertdesc = [MTLVertexDescriptor vertexDescriptor];
const auto &attributes = key.vertexAttributes;
for (const auto &pair : this->attributes)
{