Skip to content

Commit

Permalink
Merge pull request #2401 from jonny-apple/jon/dev/step_func_null_poin…
Browse files Browse the repository at this point in the history
…ter_check

APPLE: Buffer binding null pointer checks

(Internal change: 2275438)
  • Loading branch information
pixar-oss committed May 15, 2023
2 parents 91101b5 + 44b6643 commit babb27b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
31 changes: 18 additions & 13 deletions pxr/imaging/hgiMetal/indirectCommandEncoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,15 @@ void _SetArg(
for (const HgiBufferBindDesc &buffer :
resourceBindings->GetDescriptor().buffers) {
if (buffer.resourceType == HgiBindResourceTypeTessFactors) {
HgiMetalBuffer* mtlBuffer =
static_cast<HgiMetalBuffer*>(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<HgiMetalBuffer*>(buffer.buffers[0].Get());

[function.argumentEncoder setBuffer:mtlBuffer->GetBufferId()
offset:buffer.offsets[0]
atIndex:ArgIndex_PatchFactorsBuffer];
usedExplicitTessFactorBuffer = true;
}
}
}
if (pipelineDesc.primitiveType == HgiPrimitiveTypePatchList &&
Expand Down Expand Up @@ -665,13 +668,15 @@ void _SetArg(
uint32_t index = 0;

for (auto const& binding : bindings) {
HgiMetalBuffer* mtlBuffer =
static_cast<HgiMetalBuffer*>(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<HgiMetalBuffer*>(binding.buffer.Get());
[function.argumentEncoder setBuffer:mtlBuffer->GetBufferId()
offset:binding.byteOffset
atIndex:ArgIndex_Buffers + index];
[encoder useResource:mtlBuffer->GetBufferId()
usage:(MTLResourceUsageRead | MTLResourceUsageWrite)];
}
index++;
}

Expand Down
20 changes: 11 additions & 9 deletions pxr/imaging/hgiMetal/stepFunctions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down

0 comments on commit babb27b

Please sign in to comment.