From 6b7c04e046d97bd08401123977a046398563bb87 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 15 Apr 2022 11:33:28 +0100 Subject: [PATCH] Improve utilities --- .../{block_literal.odin => NSBlock.odin} | 20 +++++++++++++++---- vendor/darwin/Metal/MetalClasses.odin | 2 ++ vendor/darwin/Metal/MetalProcedures.odin | 5 +++++ 3 files changed, 23 insertions(+), 4 deletions(-) rename vendor/darwin/Foundation/{block_literal.odin => NSBlock.odin} (74%) diff --git a/vendor/darwin/Foundation/block_literal.odin b/vendor/darwin/Foundation/NSBlock.odin similarity index 74% rename from vendor/darwin/Foundation/block_literal.odin rename to vendor/darwin/Foundation/NSBlock.odin index 19e9782e4..67ab502e8 100644 --- a/vendor/darwin/Foundation/block_literal.odin +++ b/vendor/darwin/Foundation/NSBlock.odin @@ -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) +} diff --git a/vendor/darwin/Metal/MetalClasses.odin b/vendor/darwin/Metal/MetalClasses.odin index c30fde95c..075aae545 100644 --- a/vendor/darwin/Metal/MetalClasses.odin +++ b/vendor/darwin/Metal/MetalClasses.odin @@ -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) diff --git a/vendor/darwin/Metal/MetalProcedures.odin b/vendor/darwin/Metal/MetalProcedures.odin index b76c7f541..ca8fb1aea 100644 --- a/vendor/darwin/Metal/MetalProcedures.odin +++ b/vendor/darwin/Metal/MetalProcedures.odin @@ -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() } \ No newline at end of file