bindVertexStage method
Binds this material's vertex-stage uniforms to vertexShader, called by
the encoder only when it used a material-supplied vertex shader (see
materialVertexShader). The base implementation is a no-op; a material
with vertex-stage parameters binds them here.
Implementation
@override
void bindVertexStage(
gpu.RenderPass pass,
gpu.Shader vertexShader,
TransientWriter transientsBuffer,
) {
// The generated vertex variant declares the same MaterialParams block as
// the fragment shader, so a parameter reads the same value in both stages.
// The variant's keep-alive references the block (see
// MATERIAL_PARAMS_KEEP_ALIVE in the emitter) so it survives compilation
// even when Vertex() reads no parameter; binding an optimized-out block
// crashes the Metal backend.
parameters.bindUniformBlock(pass, vertexShader, transientsBuffer);
// Bind the keep-alive block (name must match kVertexKeepAliveBlock in the
// emitter) to zero: the generated shader multiplies the mesh inputs by it
// so the optimizer cannot strip a declared attribute when a Vertex() hook
// replaces the outputs, and zero makes it invisible.
pass.bindUniform(
vertexShader.getUniformSlot('VertexKeepAlive'),
transientsBuffer.emplace(_zeroKeepAlive),
);
}