Skip to content

Commit 975c24f

Browse files
authored
Minor improvements to Mesh binding (#1323)
Improve mesh binding in metal renderer to support multiple mesh geometry and prevent repeated binding.
1 parent 8ede55a commit 975c24f

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

source/MaterialXRenderMsl/MslMaterial.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
}
129129

130130
_glProgram->bind(MTL(renderCmdEncoder));
131-
if (_boundMesh && mesh->getName() != _boundMesh->getName())
131+
if (_boundMesh && mesh != _boundMesh)
132132
{
133133
_glProgram->unbindGeometry();
134134
}

source/MaterialXRenderMsl/MslPipelineStateObject.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ class MX_RENDERMSL_API MslProgram
313313
// Metal Device Object
314314
id<MTLDevice> _device = nil;
315315

316+
// Currently bound mesh
317+
MeshPtr _boundMesh = nullptr;
318+
316319
bool _alphaBlendingEnabled = false;
317320

318321
float _time = 0.0f;

source/MaterialXRenderMsl/MslPipelineStateObject.mm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,6 @@ int GetStrideOfMetalType(MTLDataType type)
347347

348348
// Bind based on inputs found
349349
bindViewInformation(cam);
350-
if(geometryHandler)
351-
{
352-
for (const auto& mesh : geometryHandler->getMeshes())
353-
{
354-
bindMesh(renderCmdEncoder, mesh);
355-
}
356-
}
357-
358350
bindTimeAndFrame();
359351
bindLighting(lightHandler, imageHandler);
360352
bindTextures(renderCmdEncoder, lightHandler, imageHandler);
@@ -468,6 +460,12 @@ int GetStrideOfMetalType(MTLDataType type)
468460
throw ExceptionRenderError(errorType, errors);
469461
}
470462

463+
if (_boundMesh && mesh != _boundMesh)
464+
{
465+
unbindGeometry();
466+
}
467+
_boundMesh = mesh;
468+
471469
MslProgram::InputMap foundList;
472470
const MslProgram::InputMap& attributeList = getAttributesList();
473471

source/MaterialXRenderMsl/MslRenderer.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@
233233
// Draw all the partitions of all the meshes in the handler
234234
for (const auto& mesh : _geometryHandler->getMeshes())
235235
{
236+
_program->bindMesh(renderCmdEncoder, mesh);
237+
236238
for (size_t i = 0; i < mesh->getPartitionCount(); i++)
237239
{
238240
auto part = mesh->getPartition(i);

0 commit comments

Comments
 (0)