diff --git a/pxr/imaging/hgiMetal/indirectCommandEncoder.mm b/pxr/imaging/hgiMetal/indirectCommandEncoder.mm index 2ed2074837..760cd9c8a7 100644 --- a/pxr/imaging/hgiMetal/indirectCommandEncoder.mm +++ b/pxr/imaging/hgiMetal/indirectCommandEncoder.mm @@ -627,12 +627,15 @@ void _SetArg( for (const HgiBufferBindDesc &buffer : resourceBindings->GetDescriptor().buffers) { if (buffer.resourceType == HgiBindResourceTypeTessFactors) { - HgiMetalBuffer* mtlBuffer = - static_cast(buffer.buffers[0].Get()); - [function.argumentEncoder setBuffer:mtlBuffer->GetBufferId() - offset:buffer.offsets[0] - atIndex:ArgIndex_PatchFactorsBuffer]; - usedExplicitTessFactorBuffer = true; + if (buffer.buffers[0]) { + HgiMetalBuffer* mtlBuffer = + static_cast(buffer.buffers[0].Get()); + + [function.argumentEncoder setBuffer:mtlBuffer->GetBufferId() + offset:buffer.offsets[0] + atIndex:ArgIndex_PatchFactorsBuffer]; + usedExplicitTessFactorBuffer = true; + } } } if (pipelineDesc.primitiveType == HgiPrimitiveTypePatchList && @@ -665,13 +668,15 @@ void _SetArg( uint32_t index = 0; for (auto const& binding : bindings) { - HgiMetalBuffer* mtlBuffer = - static_cast(binding.buffer.Get()); - [function.argumentEncoder setBuffer:mtlBuffer->GetBufferId() - offset:binding.byteOffset - atIndex:ArgIndex_Buffers + index]; - [encoder useResource:mtlBuffer->GetBufferId() - usage:(MTLResourceUsageRead | MTLResourceUsageWrite)]; + if (binding.buffer) { + HgiMetalBuffer* mtlBuffer = + static_cast(binding.buffer.Get()); + [function.argumentEncoder setBuffer:mtlBuffer->GetBufferId() + offset:binding.byteOffset + atIndex:ArgIndex_Buffers + index]; + [encoder useResource:mtlBuffer->GetBufferId() + usage:(MTLResourceUsageRead | MTLResourceUsageWrite)]; + } index++; } diff --git a/pxr/imaging/hgiMetal/stepFunctions.mm b/pxr/imaging/hgiMetal/stepFunctions.mm index 4bb930611c..e719c0d3bf 100644 --- a/pxr/imaging/hgiMetal/stepFunctions.mm +++ b/pxr/imaging/hgiMetal/stepFunctions.mm @@ -73,18 +73,20 @@ HgiMetalStepFunctions::Bind(HgiVertexBufferBindingVector const &bindings) { for (HgiVertexBufferBinding const &binding : bindings) { - HgiBufferDesc const& desc = binding.buffer->GetDescriptor(); + if (binding.buffer) { + HgiBufferDesc const& desc = binding.buffer->GetDescriptor(); - TF_VERIFY(desc.usage & HgiBufferUsageVertex); + TF_VERIFY(desc.usage & HgiBufferUsageVertex); - for (auto & stepFunction : _vertexBufferDescs) { - if (stepFunction.bindingIndex == binding.index) { - stepFunction.byteOffset = binding.byteOffset; + for (auto & stepFunction : _vertexBufferDescs) { + if (stepFunction.bindingIndex == binding.index) { + stepFunction.byteOffset = binding.byteOffset; + } } - } - for (auto & stepFunction : _patchBaseDescs) { - if (stepFunction.bindingIndex == binding.index) { - stepFunction.byteOffset = binding.byteOffset; + for (auto & stepFunction : _patchBaseDescs) { + if (stepFunction.bindingIndex == binding.index) { + stepFunction.byteOffset = binding.byteOffset; + } } } }