-
Notifications
You must be signed in to change notification settings - Fork 63
Metal: Misc non-unsafe
translation fixes
#773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.startOfEncoderSampleIndex.unsafe = false | ||
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods."setStartOfEncoderSampleIndex:".unsafe = false | ||
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.endOfEncoderSampleIndex.unsafe = false | ||
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods."setEndOfEncoderSampleIndex:".unsafe = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More controversial examples of "safe integers" that are most likely only used to index on the GPU... And maybe validated to fit within the length of the currently bounds sample buffer?
MTLRenderPassSampleBufferAttachmentDescriptor
doesn't mark the setters safe for example.
protocol.MTLAccelerationStructureCommandEncoder.methods."buildAccelerationStructure:descriptor:scratchBuffer:scratchBufferOffset:".unsafe = false | ||
protocol.MTLAccelerationStructureCommandEncoder.methods."refitAccelerationStructure:descriptor:destination:scratchBuffer:scratchBufferOffset:".unsafe = false | ||
protocol.MTLAccelerationStructureCommandEncoder.methods."refitAccelerationStructure:descriptor:destination:scratchBuffer:scratchBufferOffset:options:".unsafe = false | ||
protocol.MTLAccelerationStructureCommandEncoder.methods."copyAccelerationStructure:toAccelerationStructure:".unsafe = false | ||
protocol.MTLAccelerationStructureCommandEncoder.methods."writeCompactedAccelerationStructureSize:toBuffer:offset:".unsafe = false | ||
protocol.MTLAccelerationStructureCommandEncoder.methods."writeCompactedAccelerationStructureSize:toBuffer:offset:sizeDataType:".unsafe = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is quite strange to already see some of these functions that take buffer offsets being marked safe... While not marking all variants as safe.
Pretty sure these are bounds-checked internally. I'll try to add a test that they are.
What do you think @cwfitzgerald? Should methods that may cause the GPU to execute an out-of-bounds operation be considered UB in I'm somewhat leaning towards "yes", but it might not actually be a problem if Metal internally ensures that such accesses cannot touch the data of other applications using the GPU? I.e. if all accesses are sandboxed anyhow? |
I guess my problem here is a lack of understanding of how Metal works. As I understand it, if we are to map safety concerns in normal CPU code to safety concerns when interfacing with the GPU, it would be:
Maybe one of you could help clarify these? |
Practically, I think we should be able to mark most descriptor methods as safe. |
Draft until this becomes more complete, and while I figure out the correct semantics.
Obvious things that should remain
unsafe
:Things that are dubious:
sampleCountersInBuffer:atSampleIndex:withBarrier:
, and also all the calls that set resources on encoders and argument buffers likesetBuffer:offset:atIndex:
.executeCommandsInBuffer:withRange:
.executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:
(note thatMTLBuffer newTextureWithDescriptor:offset:bytesPerRow:
was marked safe).Here I am not sure if Rust's safety model should extend to the GPU, if at least CPU-side encoding is fully safe. It would be more convenient to not have to wrap them in
unsafe
on the call-side.Things that seem obviously safe to me:
Option
to handle nullability?