Skip to content

Commit f1fc3f6

Browse files
committed
Metal: Misc non-unsafe translation fixes
1 parent a63e4ef commit f1fc3f6

File tree

4 files changed

+109
-6
lines changed

4 files changed

+109
-6
lines changed

crates/dispatch2/src/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum_with_val! {
4444
#[allow(missing_docs)] // TODO
4545
pub const QOS_MIN_RELATIVE_PRIORITY: i32 = -15;
4646

47-
/// Error returned by [DispatchObject::set_qos_class_floor].
47+
/// Error returned by [`DispatchObject::set_qos_class_floor()`].
4848
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
4949
#[non_exhaustive]
5050
pub enum QualityOfServiceClassFloorError {

framework-crates/objc2-metal/src/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use objc2_foundation::NSArray;
1010
/// application based on whatever criteria it deems appropriate.
1111
///
1212
/// On iOS, tvOS and visionOS, this API returns an array containing the same
13-
/// device that MTLCreateSystemDefaultDevice would have returned, or an empty
13+
/// device that [`MTLCreateSystemDefaultDevice()`] would have returned, or an empty
1414
/// array if it would have failed.
1515
#[inline]
1616
pub extern "C-unwind" fn MTLCopyAllDevices() -> Retained<NSArray<ProtocolObject<dyn MTLDevice>>> {

framework-crates/objc2-metal/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//!
1212
//! [apple-doc]: https://developer.apple.com/documentation/xcode/validating-your-apps-metal-api-usage/.
1313
//!
14-
//! NOTE: To use [`MTLCreateSystemDefaultDevice`] you need to link to
14+
//! NOTE: To use [`MTLCreateSystemDefaultDevice()`] you need to link to
1515
//! `CoreGraphics`, this can be done by using `objc2-core-graphics`, or by
1616
//! doing:
1717
//! ```rust

framework-crates/objc2-metal/translation-config.toml

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class.MTLInstanceAccelerationStructureDescriptor.methods."setInstancedAccelerati
5959
class.MTLInstanceAccelerationStructureDescriptor.methods."setInstanceCount:".unsafe = false
6060
class.MTLInstanceAccelerationStructureDescriptor.methods."setInstanceDescriptorBuffer:".unsafe = false
6161

62+
protocol.MTLAccelerationStructureCommandEncoder.methods."updateFence:".unsafe = false
63+
protocol.MTLAccelerationStructureCommandEncoder.methods."waitForFence:".unsafe = false
6264
protocol.MTLAccelerationStructureCommandEncoder.methods."buildAccelerationStructure:descriptor:scratchBuffer:scratchBufferOffset:".unsafe = false
6365
protocol.MTLAccelerationStructureCommandEncoder.methods."writeCompactedAccelerationStructureSize:toBuffer:offset:".unsafe = false
6466
protocol.MTLAccelerationStructureCommandEncoder.methods."copyAndCompactAccelerationStructure:toAccelerationStructure:".unsafe = false
@@ -99,11 +101,19 @@ class.MTLArgument.methods.textureType.unsafe = false
99101
class.MTLArgument.methods.textureDataType.unsafe = false
100102

101103
class.MTLArgumentDescriptor.methods.argumentDescriptor.unsafe = false
104+
class.MTLArgumentDescriptor.methods.dataType.unsafe = false
102105
class.MTLArgumentDescriptor.methods."setDataType:".unsafe = false
106+
class.MTLArgumentDescriptor.methods.index.unsafe = false
103107
class.MTLArgumentDescriptor.methods."setIndex:".unsafe = false
108+
class.MTLArgumentDescriptor.methods.arrayLength.unsafe = false
109+
class.MTLArgumentDescriptor.methods.access.unsafe = false
104110
class.MTLArgumentDescriptor.methods."setAccess:".unsafe = false
105111
# class.MTLArgumentDescriptor.methods."setArrayLength:".unsafe = false
112+
class.MTLArgumentDescriptor.methods.textureType.unsafe = false
106113
class.MTLArgumentDescriptor.methods."setTextureType:".unsafe = false
114+
class.MTLArgumentDescriptor.methods.constantBlockAlignment.unsafe = false
115+
class.MTLArgumentDescriptor.methods."setConstantBlockAlignment:".unsafe = false
116+
class.MTLArgumentDescriptor.methods.new.unsafe = false
107117

108118
protocol.MTLBuffer.methods.length.unsafe = false
109119
protocol.MTLBuffer.methods.contents.unsafe = false
@@ -125,6 +135,7 @@ class.MTLCaptureDescriptor.methods."setOutputURL:".unsafe = false
125135
protocol.MTLCaptureScope.methods.beginScope.unsafe = false
126136
protocol.MTLCaptureScope.methods.endScope.unsafe = false
127137
protocol.MTLCaptureScope.methods.label.unsafe = false
138+
protocol.MTLCaptureScope.methods."setLabel:".unsafe = false
128139

129140
# Note: MTLCaptureManager is not documented thread-safe, so
130141
# +sharedCaptureManager is not safe either, since we do interior mutation here.
@@ -140,31 +151,58 @@ class.MTLCaptureManager.methods.defaultCaptureScope.unsafe = false
140151
class.MTLCaptureManager.methods."setDefaultCaptureScope:".unsafe = false
141152
class.MTLCaptureManager.methods.isCapturing.unsafe = false
142153

154+
protocol.MTLCommandBuffer.methods.device.unsafe = false
155+
protocol.MTLCommandBuffer.methods.commandQueue.unsafe = false
156+
protocol.MTLCommandBuffer.methods.retainedReferences.unsafe = false
157+
protocol.MTLCommandBuffer.methods.errorOptions.unsafe = false
143158
protocol.MTLCommandBuffer.methods.label.unsafe = false
144159
protocol.MTLCommandBuffer.methods."setLabel:".unsafe = false
160+
protocol.MTLCommandBuffer.methods.kernelStartTime.unsafe = false
161+
protocol.MTLCommandBuffer.methods.kernelEndTime.unsafe = false
162+
protocol.MTLCommandBuffer.methods.logs.unsafe = false
163+
protocol.MTLCommandBuffer.methods.GPUStartTime.unsafe = false
164+
protocol.MTLCommandBuffer.methods.GPUEndTime.unsafe = false
145165
protocol.MTLCommandBuffer.methods.enqueue.unsafe = false
146166
protocol.MTLCommandBuffer.methods.commit.unsafe = false
147167
protocol.MTLCommandBuffer.methods."presentDrawable:".unsafe = false
168+
# protocol.MTLCommandBuffer.methods."presentDrawable:atTime:".unsafe = false
169+
# protocol.MTLCommandBuffer.methods."presentDrawable:afterMinimumDuration:".unsafe = false
148170
protocol.MTLCommandBuffer.methods.waitUntilScheduled.unsafe = false
149171
# TODO once blocks are better
150172
# protocol.MTLCommandBuffer.methods."addCompletedHandler:".unsafe = false
173+
protocol.MTLCommandBuffer.methods.waitUntilCompleted.unsafe = false
151174
protocol.MTLCommandBuffer.methods.status.unsafe = false
175+
protocol.MTLCommandBuffer.methods.error.unsafe = false
152176
protocol.MTLCommandBuffer.methods.blitCommandEncoder.unsafe = false
153177
protocol.MTLCommandBuffer.methods."renderCommandEncoderWithDescriptor:".unsafe = false
178+
protocol.MTLCommandBuffer.methods."computeCommandEncoderWithDescriptor:".unsafe = false
179+
protocol.MTLCommandBuffer.methods."blitCommandEncoderWithDescriptor:".unsafe = false
154180
protocol.MTLCommandBuffer.methods.computeCommandEncoder.unsafe = false
155181
protocol.MTLCommandBuffer.methods."computeCommandEncoderWithDispatchType:".unsafe = false
156182
protocol.MTLCommandBuffer.methods."encodeWaitForEvent:value:".unsafe = false
157183
protocol.MTLCommandBuffer.methods."encodeSignalEvent:value:".unsafe = false
158184
protocol.MTLCommandBuffer.methods."parallelRenderCommandEncoderWithDescriptor:".unsafe = false
185+
protocol.MTLCommandBuffer.methods.resourceStateCommandEncoder.unsafe = false
186+
protocol.MTLCommandBuffer.methods."resourceStateCommandEncoderWithDescriptor:".unsafe = false
159187
protocol.MTLCommandBuffer.methods.accelerationStructureCommandEncoder.unsafe = false
188+
protocol.MTLCommandBuffer.methods."accelerationStructureCommandEncoderWithDescriptor:".unsafe = false
160189
protocol.MTLCommandBuffer.methods."pushDebugGroup:".unsafe = false
161190
protocol.MTLCommandBuffer.methods.popDebugGroup.unsafe = false
191+
protocol.MTLCommandBuffer.methods."useResidencySet:".unsafe = false
192+
# protocol.MTLCommandBuffer.methods."useResidencySets:count:".unsafe = false
162193

163194
protocol.MTLCommandQueue.methods.label.unsafe = false
164195
protocol.MTLCommandQueue.methods."setLabel:".unsafe = false
165196
protocol.MTLCommandQueue.methods.device.unsafe = false
166197
protocol.MTLCommandQueue.methods.commandBuffer.unsafe = false
167-
198+
protocol.MTLCommandQueue.methods."commandBufferWithDescriptor:".unsafe = false
199+
protocol.MTLCommandQueue.methods.commandBufferWithUnretainedReferences.unsafe = false
200+
protocol.MTLCommandQueue.methods."addResidencySet:".unsafe = false
201+
# protocol.MTLCommandQueue.methods."addResidencySets:count:".unsafe = false
202+
protocol.MTLCommandQueue.methods."removeResidencySet:".unsafe = false
203+
# protocol.MTLCommandQueue.methods."removeResidencySets:count:".unsafe = false
204+
205+
class.MTLStencilDescriptor.methods.new.unsafe = false
168206
class.MTLStencilDescriptor.methods.stencilCompareFunction.unsafe = false
169207
class.MTLStencilDescriptor.methods."setStencilCompareFunction:".unsafe = false
170208
class.MTLStencilDescriptor.methods.stencilFailureOperation.unsafe = false
@@ -178,6 +216,7 @@ class.MTLStencilDescriptor.methods."setReadMask:".unsafe = false
178216
class.MTLStencilDescriptor.methods.writeMask.unsafe = false
179217
class.MTLStencilDescriptor.methods."setWriteMask:".unsafe = false
180218

219+
class.MTLDepthStencilDescriptor.methods.new.unsafe = false
181220
class.MTLDepthStencilDescriptor.methods.depthCompareFunction.unsafe = false
182221
class.MTLDepthStencilDescriptor.methods."setDepthCompareFunction:".unsafe = false
183222
class.MTLDepthStencilDescriptor.methods.isDepthWriteEnabled.unsafe = false
@@ -248,14 +287,19 @@ protocol.MTLDevice.methods."newBinaryArchiveWithDescriptor:error:".unsafe = fals
248287
protocol.MTLDevice.methods.supportsRaytracing.unsafe = false
249288
protocol.MTLDevice.methods."accelerationStructureSizesWithDescriptor:".unsafe = false
250289
protocol.MTLDevice.methods."newAccelerationStructureWithSize:".unsafe = false
290+
protocol.MTLDevice.methods."newAccelerationStructureWithDescriptor:".unsafe = false
291+
protocol.MTLDevice.methods."heapAccelerationStructureSizeAndAlign:size:".unsafe = false
292+
protocol.MTLDevice.methods."heapAccelerationStructureSizeAndAlign:descriptor:".unsafe = false
251293
protocol.MTLDevice.methods.supportsFunctionPointers.unsafe = false
252294

253295
protocol.MTLDrawable.methods.present.unsafe = false
254296
protocol.MTLDrawable.methods.drawableID.unsafe = false
255297

298+
protocol.MTLCommandEncoder.methods.device.unsafe = false
256299
protocol.MTLCommandEncoder.methods.label.unsafe = false
257300
protocol.MTLCommandEncoder.methods."setLabel:".unsafe = false
258301
protocol.MTLCommandEncoder.methods.endEncoding.unsafe = false
302+
protocol.MTLCommandEncoder.methods."barrierAfterQueueStages:beforeStages:".unsafe = false
259303
protocol.MTLCommandEncoder.methods."insertDebugSignpost:".unsafe = false
260304
protocol.MTLCommandEncoder.methods."pushDebugGroup:".unsafe = false
261305
protocol.MTLCommandEncoder.methods.popDebugGroup.unsafe = false
@@ -282,15 +326,26 @@ protocol.MTLRenderCommandEncoder.methods."setDepthStencilState:".unsafe = false
282326
protocol.MTLRenderCommandEncoder.methods."setStencilReferenceValue:".unsafe = false
283327
protocol.MTLRenderCommandEncoder.methods."setStencilFrontReferenceValue:backReferenceValue:".unsafe = false
284328
protocol.MTLRenderCommandEncoder.methods."setVisibilityResultMode:offset:".unsafe = false
329+
protocol.MTLRenderCommandEncoder.methods."setDepthStoreAction:".unsafe = false
330+
protocol.MTLRenderCommandEncoder.methods."setStencilStoreAction:".unsafe = false
331+
protocol.MTLRenderCommandEncoder.methods."setDepthStoreActionOptions:".unsafe = false
332+
protocol.MTLRenderCommandEncoder.methods."setStencilStoreActionOptions:".unsafe = false
285333
# drawPrimitives:...
286334
# ...
287335
protocol.MTLRenderCommandEncoder.methods."updateFence:afterStages:".unsafe = false
288336
protocol.MTLRenderCommandEncoder.methods."waitForFence:beforeStages:".unsafe = false
337+
protocol.MTLRenderCommandEncoder.methods."setTessellationFactorScale:".unsafe = false
338+
protocol.MTLRenderCommandEncoder.methods.tileWidth.unsafe = false
339+
protocol.MTLRenderCommandEncoder.methods.tileHeight.unsafe = false
289340
# setThreadgroupMemoryLength:offset:atIndex:
290341
protocol.MTLRenderCommandEncoder.methods."useResource:usage:".unsafe = false
291342
protocol.MTLRenderCommandEncoder.methods."useResource:usage:stages:".unsafe = false
292343
protocol.MTLRenderCommandEncoder.methods."useHeap:".unsafe = false
293344
protocol.MTLRenderCommandEncoder.methods."useHeap:stages:".unsafe = false
345+
# executeCommandsInBuffer:withRange:
346+
# executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:
347+
protocol.MTLRenderCommandEncoder.methods."memoryBarrierWithScope:afterStages:beforeStages:".unsafe = false
348+
# sampleCountersInBuffer:atSampleIndex:withBarrier: is the GPU-based sample indes OOB sound?
294349

295350
# TODO: Verify out-of-bounds access is sound.
296351
protocol.MTLBlitCommandEncoder.methods."synchronizeResource:".unsafe = false
@@ -302,17 +357,28 @@ protocol.MTLBlitCommandEncoder.methods."waitForFence:".unsafe = false
302357
protocol.MTLBlitCommandEncoder.methods."optimizeContentsForGPUAccess:".unsafe = false
303358
# optimizeContentsForGPUAccess:slice:level:
304359

360+
protocol.MTLComputeCommandEncoder.methods.dispatchType.unsafe = false
305361
# TODO: Verify out-of-bounds access is sound.
306362
protocol.MTLComputeCommandEncoder.methods."setComputePipelineState:".unsafe = false
307363
# setBuffer:...
308364
# setIntersectionFunctionTable:atBufferIndex:
365+
# protocol.MTLComputeCommandEncoder.methods."setThreadGroupMemoryLength:atIndex:".unsafe = false
366+
protocol.MTLComputeCommandEncoder.methods."setImageBlockWidth:Height:".unsafe = false
367+
protocol.MTLComputeCommandEncoder.methods."setStageInRegion:".unsafe = false
368+
# TODO: OOB offset?
369+
protocol.MTLComputeCommandEncoder.methods."setStageInRegionWithIndirectBuffer:indirectBufferOffset:".unsafe = false
309370
protocol.MTLComputeCommandEncoder.methods."dispatchThreadgroups:threadsPerThreadgroup:".unsafe = false
310371
# dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:
311372
protocol.MTLComputeCommandEncoder.methods."dispatchThreads:threadsPerThreadgroup:".unsafe = false
312373
protocol.MTLComputeCommandEncoder.methods."updateFence:".unsafe = false
313374
protocol.MTLComputeCommandEncoder.methods."waitForFence:".unsafe = false
314375
protocol.MTLComputeCommandEncoder.methods."useResource:usage:".unsafe = false
315376
protocol.MTLComputeCommandEncoder.methods."useHeap:".unsafe = false
377+
# TODO: GPU-side range?
378+
# protocol.MTLComputeCommandEncoder.methods."executeCommandsInBuffer:withRange:".unsafe = false
379+
# protocol.MTLComputeCommandEncoder.methods."executeCommandsInBuffer:indirectBuffer:indirectBufferOffset:".unsafe = false
380+
protocol.MTLComputeCommandEncoder.methods."memoryBarrierWithScope:".unsafe = false
381+
# sampleCountersInBuffer:atSampleIndex:withBarrier: is the GPU-based sample indes OOB sound?
316382

317383
# TODO: Verify out-of-bounds access is sound.
318384
protocol.MTLArgumentEncoder.methods.encodedLength.unsafe = false
@@ -349,8 +415,12 @@ protocol.MTLHeap.methods."newTextureWithDescriptor:".unsafe = false
349415
protocol.MTLHeap.methods."setPurgeableState:".unsafe = false
350416
# TODO: type
351417
# TODO: Verify that offset out-of-bounds is sound.
352-
# newBufferWithLength:options:offset:
353-
# newTextureWithDescriptor:offset:
418+
protocol.MTLHeap.methods."newBufferWithLength:options:offset:".unsafe = false
419+
protocol.MTLHeap.methods."newTextureWithDescriptor:offset:".unsafe = false
420+
protocol.MTLHeap.methods."newAccelerationStructureWithSize:".unsafe = false
421+
protocol.MTLHeap.methods."newAccelerationStructureWithSize:offset:".unsafe = false
422+
protocol.MTLHeap.methods."newAccelerationStructureWithDescriptor:".unsafe = false
423+
protocol.MTLHeap.methods."newAccelerationStructureWithDescriptor:offset:".unsafe = false
354424

355425
class.MTLIndirectCommandBufferDescriptor.methods.commandTypes.unsafe = false
356426
class.MTLIndirectCommandBufferDescriptor.methods."setCommandTypes:".unsafe = false
@@ -529,6 +599,20 @@ class.MTLRenderPassSampleBufferAttachmentDescriptor.methods.startOfFragmentSampl
529599
class.MTLRenderPassSampleBufferAttachmentDescriptor.methods.endOfFragmentSampleIndex.unsafe = false
530600
# setEndOfFragmentSampleIndex:
531601

602+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.new.unsafe = false
603+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.sampleBuffer.unsafe = false
604+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods."setSampleBuffer:".unsafe = false
605+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.startOfEncoderSampleIndex.unsafe = false
606+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods."setStartOfEncoderSampleIndex:".unsafe = false
607+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods.endOfEncoderSampleIndex.unsafe = false
608+
class.MTLBlitPassSampleBufferAttachmentDescriptor.methods."setEndOfEncoderSampleIndex:".unsafe = false
609+
610+
class.MTLBlitPassSampleBufferAttachmentDescriptorArray.methods.new.unsafe = false
611+
612+
class.MTLBlitPassDescriptor.methods.new.unsafe = false
613+
class.MTLBlitPassDescriptor.methods.blitPassDescriptor.unsafe = false
614+
class.MTLBlitPassDescriptor.methods.sampleBufferAttachments.unsafe = false
615+
532616
# TODO: Verify that index out-of-bounds is sound.
533617
class.MTLRenderPassDescriptor.methods.renderPassDescriptor.unsafe = false
534618
class.MTLRenderPassDescriptor.methods.colorAttachments.unsafe = false
@@ -558,6 +642,25 @@ class.MTLRenderPassDescriptor.methods.rasterizationRateMap.unsafe = false
558642
class.MTLRenderPassDescriptor.methods."setRasterizationRateMap:".unsafe = false
559643
class.MTLRenderPassDescriptor.methods.sampleBufferAttachments.unsafe = false
560644

645+
class.MTLResidencySetDescriptor.methods.label.unsafe = false
646+
class.MTLResidencySetDescriptor.methods."setLabel:".unsafe = false
647+
class.MTLResidencySetDescriptor.methods.initialCapacity.unsafe = false
648+
class.MTLResidencySetDescriptor.methods."setInitialCapacity:".unsafe = false
649+
650+
protocol.MTLResidencySet.methods.device.unsafe = false
651+
protocol.MTLResidencySet.methods.label.unsafe = false
652+
protocol.MTLResidencySet.methods."setLabel:".unsafe = false
653+
protocol.MTLResidencySet.methods.allocatedSize.unsafe = false
654+
protocol.MTLResidencySet.methods.requestResidency.unsafe = false
655+
protocol.MTLResidencySet.methods.endResidency.unsafe = false
656+
protocol.MTLResidencySet.methods."addAllocation:".unsafe = false
657+
protocol.MTLResidencySet.methods."removeAllocation:".unsafe = false
658+
protocol.MTLResidencySet.methods.removeAllAllocations.unsafe = false
659+
protocol.MTLResidencySet.methods."containsAllocation:".unsafe = false
660+
protocol.MTLResidencySet.methods.allAllocations.unsafe = false
661+
protocol.MTLResidencySet.methods.allocationCount.unsafe = false
662+
protocol.MTLResidencySet.methods.commit.unsafe = false
663+
561664
protocol.MTLResource.methods.label.unsafe = false
562665
protocol.MTLResource.methods."setLabel:".unsafe = false
563666
protocol.MTLResource.methods.device.unsafe = false

0 commit comments

Comments
 (0)