-
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: main
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.
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.
In #792, I have explicitly noted that these maybe aren't 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. |
80ab368
to
362c85d
Compare
Assuming we didn't yet race on #793, is it safe to start working on factoring out the false-positives from Regarding the points above:
All in all, mostly guesses and "it's probably unsafe in some way anyway" 😬 Footnotes
|
362c85d
to
278051c
Compare
The new `Metal4` types inherit a lot of functions from older Metal versions that need to be annotated to not be unsafe, so that they can be more trivially called.
278051c
to
c6bba00
Compare
I won't be touching it yet, and I'll let you know if I want to. I have assigned you to the issue to hopefully make this clear. In #792, I've marked
There's two sides to this:
I was mostly worried about it from the CPU side, but I think that the bytes of Re uninitialized state in shader code, I think we can mostly ignore it. For example, writing an uninitialized struct to a buffer is technically UB, but on the CPU side, we don't really care, we'd just observe one of two things:
Pretty sure Assuming that's the case, when writing a
Moved to #792 (comment).
I think I've handled that by marking all resources as
I guess we have a choice between:
I feel like making
Well, much more informed guesses than mine, so definitely appreciated! |
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?