Skip to content

Commit

Permalink
Adapt to strongly-typed id.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Mar 6, 2023
1 parent b1c2543 commit fabf905
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ version = "1.2.0"

[[deps.ObjectiveC]]
deps = ["Lazy", "MacroTools"]
git-tree-sha1 = "e76cdd9b10873ac33830ccb59c826d4e22e575e6"
git-tree-sha1 = "83ef9f60ccd5174ba74281fa4ac1a735a10cefc1"
repo-rev = "tb/modernize"
repo-url = "https://github.com/JuliaInterop/ObjectiveC.jl"
uuid = "e86c9b32-1129-44ac-8ea0-90d5bb39ded9"
Expand Down
44 changes: 22 additions & 22 deletions lib/cmt/libcmt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,31 +749,31 @@ struct MtMPSMatrixMultiplication
end

function mtErrorCode(err)
ccall((:mtErrorCode, libcmt), NsInteger, (id,), err)
ccall((:mtErrorCode, libcmt), NsInteger, (id{NSError},), err)
end

function mtErrorDomain(err)
ccall((:mtErrorDomain, libcmt), Cstring, (id,), err)
ccall((:mtErrorDomain, libcmt), Cstring, (id{NSError},), err)
end

function mtErrorUserInfo(err)
ccall((:mtErrorUserInfo, libcmt), Cstring, (id,), err)
ccall((:mtErrorUserInfo, libcmt), Cstring, (id{NSError},), err)
end

function mtErrorLocalizedDescription(err)
ccall((:mtErrorLocalizedDescription, libcmt), Cstring, (id,), err)
ccall((:mtErrorLocalizedDescription, libcmt), Cstring, (id{NSError},), err)
end

function mtErrorLocalizedRecoveryOptions(err, count, options)
ccall((:mtErrorLocalizedRecoveryOptions, libcmt), Ptr{Cstring}, (id, Ptr{Csize_t}, Ptr{Cstring}), err, count, options)
ccall((:mtErrorLocalizedRecoveryOptions, libcmt), Ptr{Cstring}, (id{NSError}, Ptr{Csize_t}, Ptr{Cstring}), err, count, options)
end

function mtErrorLocalizedRecoverySuggestion(err)
ccall((:mtErrorLocalizedRecoverySuggestion, libcmt), Cstring, (id,), err)
ccall((:mtErrorLocalizedRecoverySuggestion, libcmt), Cstring, (id{NSError},), err)
end

function mtErrorLocalizedFailureReason(err)
ccall((:mtErrorLocalizedFailureReason, libcmt), Cstring, (id,), err)
ccall((:mtErrorLocalizedFailureReason, libcmt), Cstring, (id{NSError},), err)
end

@cenum MtPixelFormat::UInt32 begin
Expand Down Expand Up @@ -1156,15 +1156,15 @@ function mtComputePipelineDescriptorSupportAddingBinaryFunctions(desc)
end

function mtNewComputePipelineStateWithFunction(device, fun, error)
ccall((:mtNewComputePipelineStateWithFunction, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, Ptr{id}), device, fun, error)
ccall((:mtNewComputePipelineStateWithFunction, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, Ptr{id{NSError}}), device, fun, error)
end

function mtNewComputePipelineStateWithFunctionReflection(device, fun, opt, reflection, error)
ccall((:mtNewComputePipelineStateWithFunctionReflection, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{id}), device, fun, opt, reflection, error)
ccall((:mtNewComputePipelineStateWithFunctionReflection, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtFunction}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{id{NSError}}), device, fun, opt, reflection, error)
end

function mtNewComputePipelineStateWithDescriptor(device, desc, opt, reflection, error)
ccall((:mtNewComputePipelineStateWithDescriptor, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtComputePipelineDescriptor}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{id}), device, desc, opt, reflection, error)
ccall((:mtNewComputePipelineStateWithDescriptor, libcmt), Ptr{MtComputePipelineState}, (Ptr{MtDevice}, Ptr{MtComputePipelineDescriptor}, MtPipelineOption, Ptr{Ptr{MtComputePipelineReflection}}, Ptr{id{NSError}}), device, desc, opt, reflection, error)
end

function mtComputePipelineDevice(pip)
Expand Down Expand Up @@ -1276,7 +1276,7 @@ function mtNewFunctionWithName(lib, name)
end

function mtNewFunctionWithNameConstantValues(lib, name, constantValues, error)
ccall((:mtNewFunctionWithNameConstantValues, libcmt), Ptr{MtFunction}, (Ptr{MtLibrary}, Cstring, Ptr{MtFunctionConstantValues}, Ptr{id}), lib, name, constantValues, error)
ccall((:mtNewFunctionWithNameConstantValues, libcmt), Ptr{MtFunction}, (Ptr{MtLibrary}, Cstring, Ptr{MtFunctionConstantValues}, Ptr{id{NSError}}), lib, name, constantValues, error)
end

function mtFunctionDevice(fun)
Expand Down Expand Up @@ -1328,19 +1328,19 @@ function mtNewDefaultLibrary(device)
end

function mtNewLibraryWithFile(device, filepath, error)
ccall((:mtNewLibraryWithFile, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{id}), device, filepath, error)
ccall((:mtNewLibraryWithFile, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{id{NSError}}), device, filepath, error)
end

function mtNewLibraryWithURL(device, url, error)
ccall((:mtNewLibraryWithURL, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{id}), device, url, error)
ccall((:mtNewLibraryWithURL, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{id{NSError}}), device, url, error)
end

function mtNewLibraryWithSource(device, source, Opts, error)
ccall((:mtNewLibraryWithSource, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{MtCompileOptions}, Ptr{id}), device, source, Opts, error)
ccall((:mtNewLibraryWithSource, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Cstring, Ptr{MtCompileOptions}, Ptr{id{NSError}}), device, source, Opts, error)
end

function mtNewLibraryWithData(device, buffer, size, error)
ccall((:mtNewLibraryWithData, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Ptr{Cvoid}, Csize_t, Ptr{id}), device, buffer, size, error)
ccall((:mtNewLibraryWithData, libcmt), Ptr{MtLibrary}, (Ptr{MtDevice}, Ptr{Cvoid}, Csize_t, Ptr{id{NSError}}), device, buffer, size, error)
end

function mtLibraryDevice(lib)
Expand Down Expand Up @@ -1372,7 +1372,7 @@ function mtBinaryArchiveDescriptorURLSet(desc, path)
end

function mtNewBinaryArchiveWithDescriptor(device, desc, error)
ccall((:mtNewBinaryArchiveWithDescriptor, libcmt), Ptr{MtBinaryArchive}, (Ptr{MtDevice}, Ptr{MtBinaryArchiveDescriptor}, Ptr{id}), device, desc, error)
ccall((:mtNewBinaryArchiveWithDescriptor, libcmt), Ptr{MtBinaryArchive}, (Ptr{MtDevice}, Ptr{MtBinaryArchiveDescriptor}, Ptr{id{NSError}}), device, desc, error)
end

function mtBinaryArchiveDevice(bin)
Expand All @@ -1388,15 +1388,15 @@ function mtBinaryArchiveLabelSet(bin, label)
end

function mtBinaryArchiveAddComputePipelineFunctions(bin, desc, error)
ccall((:mtBinaryArchiveAddComputePipelineFunctions, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtComputePipelineDescriptor}, Ptr{id}), bin, desc, error)
ccall((:mtBinaryArchiveAddComputePipelineFunctions, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtComputePipelineDescriptor}, Ptr{id{NSError}}), bin, desc, error)
end

function mtBinaryArchiveAddFunction(bin, desc, lib, error)
ccall((:mtBinaryArchiveAddFunction, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtFunctionDescriptor}, Ptr{MtLibrary}, Ptr{id}), bin, desc, lib, error)
ccall((:mtBinaryArchiveAddFunction, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Ptr{MtFunctionDescriptor}, Ptr{MtLibrary}, Ptr{id{NSError}}), bin, desc, lib, error)
end

function mtBinaryArchiveSerialize(bin, path, error)
ccall((:mtBinaryArchiveSerialize, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Cstring, Ptr{id}), bin, path, error)
ccall((:mtBinaryArchiveSerialize, libcmt), Cvoid, (Ptr{MtBinaryArchive}, Cstring, Ptr{id{NSError}}), bin, path, error)
end

function mtBufferContents(buf)
Expand Down Expand Up @@ -1686,7 +1686,7 @@ function mtSetFunc(pipDesc, func, functype)
end

function mtNewRenderState(device, pipDesc, error)
ccall((:mtNewRenderState, libcmt), Ptr{MtRenderPipeline}, (Ptr{MtDevice}, Ptr{MtRenderDesc}, Ptr{id}), device, pipDesc, error)
ccall((:mtNewRenderState, libcmt), Ptr{MtRenderPipeline}, (Ptr{MtDevice}, Ptr{MtRenderDesc}, Ptr{id{NSError}}), device, pipDesc, error)
end

function mtColorPixelFormat(renderdesc, index, pixelFormat)
Expand Down Expand Up @@ -1876,7 +1876,7 @@ function mtCommandBufferErrorOptions(cmdb)
end

function mtCommandBufferError(cmdb)
ccall((:mtCommandBufferError, libcmt), id, (Ptr{MtCommandBuffer},), cmdb)
ccall((:mtCommandBufferError, libcmt), id{NSError}, (Ptr{MtCommandBuffer},), cmdb)
end

function mtCommandBufferKernelStartTime(cmdb)
Expand Down Expand Up @@ -2384,7 +2384,7 @@ function mtSupportsDestination(manager, destination)
end

function mtStartCaptureWithDescriptor(manager, descriptor, error)
ccall((:mtStartCaptureWithDescriptor, libcmt), Bool, (Ptr{MtCaptureManager}, Ptr{MtCaptureDescriptor}, Ptr{id}), manager, descriptor, error)
ccall((:mtStartCaptureWithDescriptor, libcmt), Bool, (Ptr{MtCaptureManager}, Ptr{MtCaptureDescriptor}, Ptr{id{NSError}}), manager, descriptor, error)
end

function mtStopCapture(manager)
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/MTL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ include("helpers.jl")
# high-level wrappers
include("size.jl")
include("storage_type.jl")
include("resource.jl")
include("device.jl")
include("resource.jl")
include("compile-opts.jl")
include("library.jl")
include("function.jl")
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export MTLBuffer, device, contents, alloc, free, handle
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtBuffer}}, obj::MTLBuffer) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLBuffer(ptr::Ptr{MtBuffer}) = MTLBuffer(reinterpret(id, ptr))
MTLBuffer(ptr::Ptr{MtBuffer}) = MTLBuffer(reinterpret(id{MTLBuffer}, ptr))


## properties
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/command_buf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function Base.getproperty(o::MtlCommandBuffer, f::Symbol)
mtCommandBufferStatus(o)
elseif f === :error
ptr = mtCommandBufferError(o)
ptr == C_NULL ? nothing : NSError(ptr)
ptr == nil ? nothing : NSError(ptr)
elseif f === :errorOptions
mtCommandBufferErrorOptions(o)
elseif f === :kernelStartTime
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/compile-opts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export MTLCompileOptions
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtCompileOptions}}, obj::MTLCompileOptions) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLCompileOptions(ptr::Ptr{MtCompileOptions}) = MTLCompileOptions(reinterpret(id, ptr))
MTLCompileOptions(ptr::Ptr{MtCompileOptions}) = MTLCompileOptions(reinterpret(id{MTLCompileOptions}, ptr))

function MTLCompileOptions()
handle = @objc [MTLCompileOptions new]::id{MTLCompileOptions}
Expand Down
9 changes: 5 additions & 4 deletions lib/mtl/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ export MTLDevice, devices
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtDevice}}, obj::MTLDevice) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLDevice(ptr::Ptr{MtDevice}) = MTLDevice(reinterpret(id, ptr))
MTLDevice(ptr::Ptr{MtDevice}) = MTLDevice(reinterpret(id{MTLDevice}, ptr))

MTLCreateSystemDefaultDevice() = MTLDevice(ccall(:MTLCreateSystemDefaultDevice, id, ()))
MTLCreateSystemDefaultDevice() =
MTLDevice(ccall(:MTLCreateSystemDefaultDevice, id{MTLDevice}, ()))

"""
devices()
Get an iterator for the compute devices.
"""
function devices()
list = NSArray(ccall(:MTLCopyAllDevices, id, ()))
MTLDevice.(collect(list))
list = NSArray(ccall(:MTLCopyAllDevices, id{NSArray}, ()))
[reinterpret(MTLDevice, dev) for dev in list]
end

"""
Expand Down
4 changes: 2 additions & 2 deletions lib/mtl/events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ end
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtEvent}}, obj::Union{MTLEvent,MTLSharedEvent}) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLEvent(ptr::Ptr{MtEvent}) = MTLEvent(reinterpret(id, ptr))
MTLEvent(ptr::Ptr{MtEvent}) = MTLEvent(reinterpret(id{MTLEvent}, ptr))
Base.unsafe_convert(T::Type{Ptr{MtSharedEvent}}, obj::MTLSharedEvent) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLSharedEvent(ptr::Ptr{MtSharedEvent}) = MTLSharedEvent(reinterpret(id, ptr))
MTLSharedEvent(ptr::Ptr{MtSharedEvent}) = MTLSharedEvent(reinterpret(id{MTLSharedEvent}, ptr))


## properties
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/fences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtFence}}, obj::MTLFence) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLFence(ptr::Ptr{MtFence}) = MTLFence(reinterpret(id, ptr))
MTLFence(ptr::Ptr{MtFence}) = MTLFence(reinterpret(id{MTLFence}, ptr))


## properties
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ error[] != nil && throw(NSError(error[]))
"""
macro mtlthrows(error, fun)
expr = quote
$error = Ref{id}(nil)
$error = Ref{id{NSError}}(nil)
result = $fun
if $error[] != nil
throw(NSError($(error)[]))
Expand Down
4 changes: 2 additions & 2 deletions lib/mtl/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function Base.getproperty(desc::MtlCaptureDescriptor, f::Symbol)
ptr == C_NULL && return nothing
if desc.cap_obj_type == MtCaptureDescriptorCaptureObjectTypeDevice
# XXX: temporary hack while we migrate away from cmt
MTLDevice(reinterpret(id, ptr))
MTLDevice(reinterpret(id{MTLDevice}, ptr))
else
obj_enum_to_jl_typ[desc.cap_obj_type](ptr)
end
Expand Down Expand Up @@ -267,7 +267,7 @@ function startCapture(manager::MtlCaptureManager, desc::MtlCaptureDescriptor)
throw(ArgumentError("`dir` keyword argument to @profile should not be an existing directory"))
end

_errptr = Ref{id}(nil)
_errptr = Ref{id{NSError}}(nil)
success = mtStartCaptureWithDescriptor(manager.handle, desc.handle, _errptr)
success || throw(NSError(_errptr[]))
return
Expand Down
2 changes: 1 addition & 1 deletion lib/mtl/resource.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export MTLResource
# compatibility with cmt
Base.unsafe_convert(T::Type{Ptr{MtResource}}, obj::MTLResource) =
reinterpret(T, Base.unsafe_convert(id, obj))
MTLResource(ptr::Ptr{MtResource}) = MTLResource(reinterpret(id, ptr))
MTLResource(ptr::Ptr{MtResource}) = MTLResource(reinterpret(id{MTLResource}, ptr))


## properties
Expand Down

0 comments on commit fabf905

Please sign in to comment.