Improve utilities

This commit is contained in:
gingerBill
2022-04-15 11:33:28 +01:00
parent cfeb16f917
commit 6b7c04e046
3 changed files with 23 additions and 4 deletions
@@ -34,8 +34,9 @@ global_block_descriptor := Block_Descriptor{
@(objc_class="NSConcreteGlobalBlock")
Block :: struct {using _: Object}
@(objc_type=Block, objc_name="create", objc_is_class_method=true)
Block_create :: proc "c" (user_data: rawptr, user_proc: proc "c" (user_data: rawptr)) -> ^Block {
@(private="file")
Block_createInternal :: proc "c" (is_global: bool, user_data: rawptr, user_proc: proc "c" (user_data: rawptr)) -> ^Block {
// Set to true on blocks that have captures (and thus are not true
// global blocks) but are known not to escape for various other
// reasons. For backward compatibility with old runtimes, whenever
@@ -55,13 +56,24 @@ Block_create :: proc "c" (user_data: rawptr, user_proc: proc "c" (user_data: raw
cls := intrinsics.objc_find_class("NSConcreteGlobalBlock")
bl := (^Internal_Block_Literal)(AllocateObject(cls, extraBytes, nil))
bl.isa = cls
bl.flags = BLOCK_IS_GLOBAL
bl.flags = BLOCK_IS_GLOBAL if is_global else 0
bl.invoke = proc "c" (bl: ^Internal_Block_Literal) {
bl.user_proc(bl.user_data)
}
bl.descriptor = &global_block_descriptor
bl.user_proc = user_proc
bl.user_data = user_data
return auto_cast bl
}
@(objc_type=Block, objc_name="createGlobal", objc_is_class_method=true)
Block_createGlobal :: proc "c" (user_data: rawptr, user_proc: proc "c" (user_data: rawptr)) -> ^Block {
return Block_createInternal(true, user_data, user_proc)
}
@(objc_type=Block, objc_name="createLocal", objc_is_class_method=true)
Block_createLocal :: proc "c" (user_data: rawptr, user_proc: proc "c" (user_data: rawptr)) -> ^Block {
return Block_createInternal(false, user_data, user_proc)
}
+2
View File
@@ -6588,6 +6588,7 @@ Device_newHeap :: #force_inline proc(self: ^Device, descriptor: ^HeapDescriptor)
Device_newIndirectCommandBuffer :: #force_inline proc(self: ^Device, descriptor: ^IndirectCommandBufferDescriptor, maxCount: NS.UInteger, options: ResourceOptions) -> ^IndirectCommandBuffer {
return msgSend(^IndirectCommandBuffer, self, "newIndirectCommandBufferWithDescriptor:maxCommandCount:options:", descriptor, maxCount, options)
}
@(objc_type=Device, objc_name="newLibraryWithData")
Device_newLibraryWithData :: #force_inline proc(self: ^Device, data: dispatch_data_t) -> (library: ^Library, error: ^NS.Error) {
library = msgSend(^Library, self, "newLibraryWithData:error:", data, &error)
@@ -6626,6 +6627,7 @@ Device_newLibrary :: proc{
Device_newRasterizationRateMap :: #force_inline proc(self: ^Device, descriptor: ^RasterizationRateMapDescriptor) -> ^RasterizationRateMap {
return msgSend(^RasterizationRateMap, self, "newRasterizationRateMapWithDescriptor:", descriptor)
}
@(objc_type=Device, objc_name="newRenderPipelineStateWithDescriptorWithCompletionHandler")
Device_newRenderPipelineStateWithDescriptorWithCompletionHandler :: #force_inline proc(self: ^Device, descriptor: ^RenderPipelineDescriptor, completionHandler: NewRenderPipelineStateCompletionHandler) -> ^RenderPipelineState {
return msgSend(^RenderPipelineState, self, "newRenderPipelineStateWithDescriptor:completionHandler:", descriptor, completionHandler)
+5
View File
@@ -11,4 +11,9 @@ foreign Metal {
CopyAllDevicesWithObserver :: proc(observer: ^id, handler: DeviceNotificationHandler) -> ^NS.Array ---
CreateSystemDefaultDevice :: proc() -> ^Device ---
RemoveDeviceObserver :: proc(observer: id) ---
}
new :: proc($T: typeid) -> ^T where intrinsics.type_is_subtype_of(T, NS.Object) {
return T.alloc()->init()
}