avoiding bounding box computation

I'm creating a SCNGeometry from Metal buffers. I'd like those buffers to be MTLResourceStorageModePrivate for best performanice.


However if I sent them to private, I get a crash:

 -[MTLToolsResource validateCPUWriteable]:96: failed assertion `resourceOptions (0x20) specify MTLResourceStorageModePrivate, which is not CPU accessible.' 


This is happening because SceneKit is calculating bounding boxes. The stack trace:

  * frame #0: 0x00007fff50653fce libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x000000010113b1c4 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x00007fff505b032a libsystem_c.dylib`abort + 127
    frame #3: 0x00007fff50578380 libsystem_c.dylib`__assert_rtn + 320
    frame #4: 0x00007fff2d4b2f9d Metal`MTLReportFailure + 778
    frame #5: 0x00007fff4412d174 MetalTools`-[MTLDebugBuffer contents] + 55
    frame #6: 0x00007fff345be047 SceneKit`C3DDataFromMTLBuffer + 38
    frame #7: 0x00007fff345f14c4 SceneKit`C3DMeshSourceGetContent + 33
    frame #8: 0x00007fff346a4854 SceneKit`C3DMeshGetBoundingBox + 76
    frame #9: 0x00007fff345973a6 SceneKit`__C3DComputeLocalBoundingBox + 177
    frame #10: 0x00007fff3459490b SceneKit`C3DNodeBoundingBoxDidUpdate + 29
    frame #11: 0x00007fff34586248 SceneKit`C3DNodeSetGeometry + 419
    frame #12: 0x00007fff344e00c3 SceneKit`C3DTransactionFlush + 2600
    frame #13: 0x00007fff346eba01 SceneKit`-[SCNView drawForMetalBackingLayer] + 59
    frame #14: 0x00007fff340d852f QuartzCore`display_callback(void*, void*) + 50
    frame #15: 0x00007fff340d84a7 QuartzCore`CA::DispatchGroup::dispatch(bool) + 71
    frame #16: 0x00000001010bbf1f libdispatch.dylib`_dispatch_client_callout + 8
    frame #17: 0x00000001010c9da4 libdispatch.dylib`_dispatch_queue_override_invoke + 1387
    frame #18: 0x00000001010bdd77 libdispatch.dylib`_dispatch_root_queue_drain + 723
    frame #19: 0x00000001010bda50 libdispatch.dylib`_dispatch_worker_thread3 + 116
    frame #20: 0x00000001011381d2 libsystem_pthread.dylib`_pthread_wqthread + 1387
    frame #21: 0x0000000101137c55 libsystem_pthread.dylib`start_wqthread + 13


Is there a way I can avoid bounding box computation? I know a good bounding box for the Node ahead of time.


I've tried calling setBoundingBoxMin:max on the node, but that doesn't prevent bounding box computation.

Accepted Reply

Turns out I needed to set the bounding box on the SCNGeometry, not the SCNNode containing it.

Replies

Turns out I needed to set the bounding box on the SCNGeometry, not the SCNNode containing it.