1 module metal.commandbuffer; 2 3 version(D_ObjectiveC): 4 extern(Objective-C): 5 6 import metal.metal; 7 import metal.rendercommandencoder; 8 9 ///Options for reporting errors from a command buffer. 10 enum MTLCommandBufferErrorOption : NSUInteger 11 { 12 ///An option that clears a command buffer’s error options. 13 None = 0, 14 ///An option that instructs a command buffer to save additional details about a GPU runtime error. 15 EncoderExecutionStatus = 1 << 0 16 } 17 18 ///A configuration that customizes the behavior for a new command buffer. 19 extern class MTLCommandBufferDescriptor : NSObject 20 { 21 ///A Boolean value that indicates whether the command buffer the descriptor creates maintains strong references to the resources it uses. 22 @selector("retainedResources") 23 BOOL retainedResources(); 24 @selector("setRetainedResources:") 25 BOOL retainedResources(BOOL); 26 27 ///The reporting configuration that indicates which information the GPU driver stores in a command buffer’s error property. 28 @selector("errorOptions") 29 MTLCommandBufferErrorOption errorOptions(); 30 31 @selector("setErrorOptions:") 32 MTLCommandBufferErrorOption errorOptions(MTLCommandBufferErrorOption); 33 } 34 35 ///The discrete states for a command buffer that represent its life cycle stages. 36 enum MTLCommandBufferStatus : NSUInteger 37 { 38 ///A command buffer’s initial state, which indicates its command queue isn’t reserving a place for it. 39 NotEnqueued = 0, 40 ///A command buffer’s second state, which indicates its command queue is reserving a place for it. 41 Enqueued = 1, 42 ///A command buffer’s third state, which indicates the command queue is preparing to schedule the command buffer by resolving its dependencies. 43 Committed = 2, 44 ///A command buffer’s fourth state, which indicates the command buffer has its resources ready and is waiting for the GPU to run its commands. 45 Scheduled = 3, 46 ///A command buffer’s successful, final state, which indicates the GPU finished running the command buffer’s commands without any problems. 47 Completed = 4, 48 ///A command buffer’s unsuccessful, final state, which indicates the GPU stopped running the buffer’s commands because of a runtime issue. 49 Error = 5 50 } 51 52 ///A completion handler signature a GPU device calls when it finishes scheduling a command buffer, or when the GPU finishes running it. 53 alias MTLCommandBufferHandler = extern(C) void function(MTLCommandBuffer); 54 55 ///A container that stores a sequence of GPU commands that you encode into it. 56 extern interface MTLCommandBuffer 57 { 58 ///Encodes a command into the command buffer that pauses the GPU from running subsequent passes until the event equals or exceeds a value. 59 @selector("encodeWaitForEvent:value:") 60 void encodeWaitForEvent(MTLEvent event, ulong value); 61 62 ///Encodes a command into the command buffer that pauses the GPU from running subsequent passes until the event equals or exceeds a value. 63 @selector("encodeSignalEvent:value:") 64 void encodeSignalEvent(MTLEvent event, ulong value); 65 66 ///Presents a drawable as early as possible. 67 @selector("presentDrawable:") 68 void presentDrawable(MTLDrawable drawable); 69 70 ///Presents a drawable at a specific time. 71 @selector("presentDrawable:atTime:") 72 void presentDrawable(MTLDrawable drawable, CFTimeInterval presentationTime); 73 74 ///Presents a drawable after the system presents the previous drawable for an amount of time. 75 @selector("presentDrawable:afterMinimumDuration:") 76 void presentDrawableAfterMinimumDuration(MTLDrawable drawable, CFTimeInterval duration); 77 78 ///Registers a completion handler the GPU device calls immediately after it schedules the command buffer to run on the GPU. 79 @selector("addScheduleHandler:") 80 void addScheduleHandler(MTLCommandBufferHandler); 81 82 ///Registers a completion handler the GPU device calls immediately after the GPU finishes running the commands in the command buffer. 83 @selector("addCompletedHandler:") 84 void addCompletedHandler(MTLCommandBufferHandler); 85 86 ///Reserves the next available place for the command buffer in its command queue. 87 @selector("enqueue") 88 void enqueue(); 89 90 ///Submits the command buffer to run on the GPU. 91 @selector("commit") 92 void commit(); 93 94 ///Synchronously waits for the command queue to schedule the buffer, which can block the current thread’s execution. 95 @selector("waitUntilScheduled") 96 void waitUntilScheduled(); 97 98 ///Synchronously waits for the GPU to finish running the command buffer, which can block the current thread’s execution. 99 @selector("waitUntilCompleted") 100 void waitUntilCompleted(); 101 102 ///The command buffer’s current state. 103 @selector("status") 104 MTLCommandBufferStatus status(); 105 106 @selector("renderCommandEncoderWithDescriptor:") 107 MTLRenderCommandEncoder renderCommandEncoderWithDescriptor(MTLRenderPassDescriptor renderPassDescriptor); 108 109 ///A string to help identify this object 110 @selector("label") 111 NSString label(); 112 @selector("setLabel:") 113 NSString label(NSString); 114 }