@ -36,7 +36,7 @@ import (
// GPUFamily represents the functionality for families of GPUs.
//
// Reference: https://developer.apple.com/documentation/metal/mtlgpufamily
// Reference: https://developer.apple.com/documentation/metal/mtlgpufamily ?language=objc.
type GPUFamily int
const (
@ -54,7 +54,7 @@ const (
// FeatureSet defines a specific platform, hardware, and software configuration.
//
// Reference: https://developer.apple.com/documentation/metal/mtlfeatureset .
// Reference: https://developer.apple.com/documentation/metal/mtlfeatureset ?language=objc .
type FeatureSet uint16
const (
@ -92,7 +92,7 @@ const (
// TextureType defines The dimension of each image, including whether multiple images are arranged into an array or
// a cube.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexturetype
// Reference: https://developer.apple.com/documentation/metal/mtltexturetype ?language=objc.
type TextureType uint16
const (
@ -102,7 +102,7 @@ const (
// PixelFormat defines data formats that describe the organization
// and characteristics of individual pixels in a texture.
//
// Reference: https://developer.apple.com/documentation/metal/mtlpixelformat .
// Reference: https://developer.apple.com/documentation/metal/mtlpixelformat ?language=objc .
type PixelFormat uint16
// The data formats that describe the organization and characteristics
@ -117,7 +117,7 @@ const (
// PrimitiveType defines geometric primitive types for drawing commands.
//
// Reference: https://developer.apple.com/documentation/metal/mtlprimitivetype .
// Reference: https://developer.apple.com/documentation/metal/mtlprimitivetype ?language=objc .
type PrimitiveType uint8
// Geometric primitive types for drawing commands.
@ -132,7 +132,7 @@ const (
// LoadAction defines actions performed at the start of a rendering pass
// for a render command encoder.
//
// Reference: https://developer.apple.com/documentation/metal/mtlloadaction .
// Reference: https://developer.apple.com/documentation/metal/mtlloadaction ?language=objc .
type LoadAction uint8
// Actions performed at the start of a rendering pass for a render command encoder.
@ -145,7 +145,7 @@ const (
// StoreAction defines actions performed at the end of a rendering pass
// for a render command encoder.
//
// Reference: https://developer.apple.com/documentation/metal/mtlstoreaction .
// Reference: https://developer.apple.com/documentation/metal/mtlstoreaction ?language=objc .
type StoreAction uint8
// Actions performed at the end of a rendering pass for a render command encoder.
@ -160,7 +160,7 @@ const (
// StorageMode defines the memory location and access permissions of a resource.
//
// Reference: https://developer.apple.com/documentation/metal/mtlstoragemode .
// Reference: https://developer.apple.com/documentation/metal/mtlstoragemode ?language=objc .
type StorageMode uint8
const (
@ -189,7 +189,7 @@ const (
// ResourceOptions defines optional arguments used to create
// and influence behavior of buffer and texture objects.
//
// Reference: https://developer.apple.com/documentation/metal/mtlresourceoptions .
// Reference: https://developer.apple.com/documentation/metal/mtlresourceoptions ?language=objc .
type ResourceOptions uint16
const (
@ -237,7 +237,7 @@ const (
// CPUCacheMode is the CPU cache mode that defines the CPU mapping of a resource.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcpucachemode .
// Reference: https://developer.apple.com/documentation/metal/mtlcpucachemode ?language=objc .
type CPUCacheMode uint8
const (
@ -252,7 +252,7 @@ const (
// IndexType is the index type for an index buffer that references vertices of geometric primitives.
//
// Reference: https://developer.apple.com/documentation/metal/mtlstoragemode
// Reference: https://developer.apple.com/documentation/metal/mtlstoragemode ?language=objc
type IndexType uint8
const (
@ -358,7 +358,7 @@ const (
// Resource represents a memory allocation for storing specialized data
// that is accessible to the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtlresource .
// Reference: https://developer.apple.com/documentation/metal/mtlresource ?language=objc .
type Resource interface {
// resource returns the underlying id<MTLResource> pointer.
resource ( ) unsafe . Pointer
@ -366,7 +366,7 @@ type Resource interface {
// RenderPipelineDescriptor configures new RenderPipelineState objects.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinedescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinedescriptor ?language=objc .
type RenderPipelineDescriptor struct {
// VertexFunction is a programmable function that processes individual vertices in a rendering pass.
VertexFunction Function
@ -384,7 +384,7 @@ type RenderPipelineDescriptor struct {
// RenderPipelineColorAttachmentDescriptor describes a color render target that specifies
// the color configuration and color operations associated with a render pipeline.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinecolorattachmentdescriptor ?language=objc .
type RenderPipelineColorAttachmentDescriptor struct {
// PixelFormat is the pixel format of the color attachment's texture.
PixelFormat PixelFormat
@ -404,7 +404,7 @@ type RenderPipelineColorAttachmentDescriptor struct {
// RenderPassDescriptor describes a group of render targets that serve as
// the output destination for pixels generated by a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassdescriptor ?language=objc .
type RenderPassDescriptor struct {
// ColorAttachments is array of state information for attachments that store color data.
ColorAttachments [ 1 ] RenderPassColorAttachmentDescriptor
@ -416,7 +416,7 @@ type RenderPassDescriptor struct {
// RenderPassColorAttachmentDescriptor describes a color render target that serves
// as the output destination for color pixels generated by a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpasscolorattachmentdescriptor ?language=objc .
type RenderPassColorAttachmentDescriptor struct {
RenderPassAttachmentDescriptor
ClearColor ClearColor
@ -425,7 +425,7 @@ type RenderPassColorAttachmentDescriptor struct {
// RenderPassStencilAttachment describes a stencil render target that serves as the output
// destination for stencil pixels generated by a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassstencilattachmentdescriptor ?language=objc.
type RenderPassStencilAttachment struct {
RenderPassAttachmentDescriptor
}
@ -433,7 +433,7 @@ type RenderPassStencilAttachment struct {
// RenderPassAttachmentDescriptor describes a render target that serves
// as the output destination for pixels generated by a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpassattachmentdescriptor ?language=objc .
type RenderPassAttachmentDescriptor struct {
LoadAction LoadAction
StoreAction StoreAction
@ -442,14 +442,14 @@ type RenderPassAttachmentDescriptor struct {
// ClearColor is an RGBA value used for a color pixel.
//
// Reference: https://developer.apple.com/documentation/metal/mtlclearcolor .
// Reference: https://developer.apple.com/documentation/metal/mtlclearcolor ?language=objc .
type ClearColor struct {
Red , Green , Blue , Alpha float64
}
// TextureDescriptor configures new Texture objects.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexturedescriptor .
// Reference: https://developer.apple.com/documentation/metal/mtltexturedescriptor ?language=objc .
type TextureDescriptor struct {
TextureType TextureType
PixelFormat PixelFormat
@ -462,7 +462,7 @@ type TextureDescriptor struct {
// Device is abstract representation of the GPU that
// serves as the primary interface for a Metal app.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice .
// Reference: https://developer.apple.com/documentation/metal/mtldevice ?language=objc .
type Device struct {
device objc . ID
@ -568,7 +568,7 @@ var (
// CreateSystemDefaultDevice returns the preferred system default Metal device.
//
// Reference: https://developer.apple.com/documentation/metal/1433401-mtlcreatesystemdefaultdevice .
// Reference: https://developer.apple.com/documentation/metal/1433401-mtlcreatesystemdefaultdevice ?language=objc .
func CreateSystemDefaultDevice ( ) ( Device , error ) {
metal , err := purego . Dlopen ( "/System/Library/Frameworks/Metal.framework/Metal" , purego . RTLD_LAZY | purego . RTLD_GLOBAL )
if err != nil {
@ -608,37 +608,36 @@ func (d Device) Device() unsafe.Pointer { return *(*unsafe.Pointer)(unsafe.Point
// RespondsToSelector returns a Boolean value that indicates whether the receiver implements or inherits a method that can respond to a specified message.
//
// Reference: https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418583-respondstoselector
// Reference: https://developer.apple.com/documentation/objectivec/1418956-nsobject/1418583-respondstoselector ?language=objc.
func ( d Device ) RespondsToSelector ( sel objc . SEL ) bool {
return d . device . Send ( sel_respondsToSelector , sel ) != 0
}
// SupportsFamily returns a Boolean value that indicates whether the GPU device supports the feature set of a specific GPU family.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/3143473-supportsfamily
// Reference: https://developer.apple.com/documentation/metal/mtldevice/3143473-supportsfamily ?language=objc.
func ( d Device ) SupportsFamily ( gpuFamily GPUFamily ) bool {
return d . device . Send ( sel_supportsFamily , uintptr ( gpuFamily ) ) != 0
}
// SupportsFeatureSet reports whether device d supports feature set fs.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433418-supportsfeatureset .
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433418-supportsfeatureset ?language=objc .
func ( d Device ) SupportsFeatureSet ( fs FeatureSet ) bool {
return d . device . Send ( sel_supportsFeatureSet , uintptr ( fs ) ) != 0
}
// MakeCommandQueue creates a serial command submission queue .
// NewCommandQueue creates a queue you use to submit rendering and computation commands to a GPU .
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433388- makecommandqueue .
func ( d Device ) Make CommandQueue( ) CommandQueue {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433388- newcommandqueue?language=objc .
func ( d Device ) New CommandQueue( ) CommandQueue {
return CommandQueue { d . device . Send ( sel_newCommandQueue ) }
}
// MakeLibrary creates a new library that contains
// the functions stored in the specified source string.
// NewLibraryWithSource synchronously creates a Metal library instance by compiling the functions in a source string.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433431- makelibrary .
func ( d Device ) MakeLibrary ( source string , opt CompileOptions ) ( Library , error ) {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433431- newlibrarywithsource?language=objc .
func ( d Device ) NewLibraryWithSource ( source string , opt CompileOptions ) ( Library , error ) {
var err cocoa . NSError
l := d . device . Send (
sel_newLibraryWithSource_options_error ,
@ -653,10 +652,10 @@ func (d Device) MakeLibrary(source string, opt CompileOptions) (Library, error)
return Library { l } , nil
}
// MakeLibraryWithData creates a Metal library instance from a data instance that contains the functions in a precompiled Metal library.
// NewLibraryWithData Creates a Metal library instance that contains the functions in a precompiled Metal library.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433391- makelibrary
func ( d Device ) Make LibraryWithData( buffer [ ] byte ) ( Library , error ) {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433391- newlibrarywithdata?language=objc.
func ( d Device ) New LibraryWithData( buffer [ ] byte ) ( Library , error ) {
defer runtime . KeepAlive ( buffer )
data := dispatchDataCreate ( unsafe . Pointer ( & buffer [ 0 ] ) , uint ( len ( buffer ) ) , 0 , 0 )
@ -674,10 +673,10 @@ func (d Device) MakeLibraryWithData(buffer []byte) (Library, error) {
return Library { l } , nil
}
// MakeRenderPipelineState creates a render pipeline state object .
// NewRenderPipelineStateWithDescriptor synchronously creates a render pipeline state .
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433369- makerenderpipelinestate .
func ( d Device ) MakeRenderPipelineState ( rpd RenderPipelineDescriptor ) ( RenderPipelineState , error ) {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433369- newrenderpipelinestatewithdescri?language=objc .
func ( d Device ) NewRenderPipelineStateWithDescriptor ( rpd RenderPipelineDescriptor ) ( RenderPipelineState , error ) {
renderPipelineDescriptor := objc . ID ( class_MTLRenderPipelineDescriptor ) . Send ( sel_new )
renderPipelineDescriptor . Send ( sel_setVertexFunction , rpd . VertexFunction . function )
renderPipelineDescriptor . Send ( sel_setFragmentFunction , rpd . FragmentFunction . function )
@ -705,26 +704,24 @@ func (d Device) MakeRenderPipelineState(rpd RenderPipelineDescriptor) (RenderPip
return RenderPipelineState { renderPipelineState } , nil
}
// MakeBufferWithBytes allocates a new buffer of a given length
// and initializes its contents by copying existing data into it.
// NewBufferWithBytes allocates a new buffer of a given length and initializes its contents by copying existing data into it.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433429- makebuffer .
func ( d Device ) Make BufferWithBytes( bytes unsafe . Pointer , length uintptr , opt ResourceOptions ) Buffer {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433429- newbufferwithbytes?language=objc .
func ( d Device ) New BufferWithBytes( bytes unsafe . Pointer , length uintptr , opt ResourceOptions ) Buffer {
return Buffer { d . device . Send ( sel_newBufferWithBytes_length_options , bytes , length , uintptr ( opt ) ) }
}
// Make BufferWithLength allocates a new zero-filled buffer of a given length.
// New BufferWithLength allocates a new zero-filled buffer of a given length.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433375-newbufferwithlength
func ( d Device ) Make BufferWithLength( length uintptr , opt ResourceOptions ) Buffer {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433375-newbufferwithlength ?language=objc.
func ( d Device ) New BufferWithLength( length uintptr , opt ResourceOptions ) Buffer {
return Buffer { d . device . Send ( sel_newBufferWithLength_options , length , uintptr ( opt ) ) }
}
// MakeTexture creates a texture object with privately owned storage
// that contains texture state.
// NewTextureWithDescriptor creates a new texture instance.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433425- maketexture .
func ( d Device ) MakeTexture ( td TextureDescriptor ) Texture {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433425- newtexturewithdescriptor?language=objc .
func ( d Device ) NewTextureWithDescriptor ( td TextureDescriptor ) Texture {
textureDescriptor := objc . ID ( class_MTLTextureDescriptor ) . Send ( sel_new )
textureDescriptor . Send ( sel_setTextureType , uintptr ( td . TextureType ) )
textureDescriptor . Send ( sel_setPixelFormat , uintptr ( td . PixelFormat ) )
@ -739,10 +736,10 @@ func (d Device) MakeTexture(td TextureDescriptor) Texture {
}
}
// MakeDepthStencilState creates a new object that contains depth and stencil test stat e.
// NewDepthStencilStateWithDescriptor creates a depth-stencil state instanc e.
//
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433412- makedepthstencilstate
func ( d Device ) MakeDepthStencilState ( dsd DepthStencilDescriptor ) DepthStencilState {
// Reference: https://developer.apple.com/documentation/metal/mtldevice/1433412- newdepthstencilstatewithdescript?language=objc.
func ( d Device ) NewDepthStencilStateWithDescriptor ( dsd DepthStencilDescriptor ) DepthStencilState {
depthStencilDescriptor := objc . ID ( class_MTLDepthStencilDescriptor ) . Send ( sel_new )
backFaceStencil := depthStencilDescriptor . Send ( sel_backFaceStencil )
backFaceStencil . Send ( sel_setStencilFailureOperation , uintptr ( dsd . BackFaceStencil . StencilFailureOperation ) )
@ -764,14 +761,14 @@ func (d Device) MakeDepthStencilState(dsd DepthStencilDescriptor) DepthStencilSt
// CompileOptions specifies optional compilation settings for
// the graphics or compute functions within a library.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcompileoptions .
// Reference: https://developer.apple.com/documentation/metal/mtlcompileoptions ?language=objc .
type CompileOptions struct {
// TODO.
}
// Drawable is a displayable resource that can be rendered or written to.
//
// Reference: https://developer.apple.com/documentation/metal/mtldrawable .
// Reference: https://developer.apple.com/documentation/metal/mtldrawable ?language=objc .
type Drawable interface {
// Drawable returns the underlying id<MTLDrawable> pointer.
Drawable ( ) unsafe . Pointer
@ -780,7 +777,7 @@ type Drawable interface {
// CommandQueue is a queue that organizes the order
// in which command buffers are executed by the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandqueue .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandqueue ?language=objc .
type CommandQueue struct {
commandQueue objc . ID
}
@ -789,17 +786,17 @@ func (cq CommandQueue) Release() {
cq . commandQueue . Send ( sel_release )
}
// MakeCommandBuffer creates a command buffer .
// CommandBuffer returns a command buffer from the command queue that maintains strong references to resources .
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandqueue/1508686- make commandbuffer.
func ( cq CommandQueue ) Make CommandBuffer( ) CommandBuffer {
// Reference: https://developer.apple.com/documentation/metal/mtlcommandqueue/1508686- commandbuffer?language=objc .
func ( cq CommandQueue ) CommandBuffer( ) CommandBuffer {
return CommandBuffer { cq . commandQueue . Send ( sel_commandBuffer ) }
}
// CommandBuffer is a container that stores encoded commands
// that are committed to and executed by the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer ?language=objc .
type CommandBuffer struct {
commandBuffer objc . ID
}
@ -814,44 +811,43 @@ func (cb CommandBuffer) Release() {
// Status returns the current stage in the lifetime of the command buffer.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443048-status
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443048-status ?language=objc.
func ( cb CommandBuffer ) Status ( ) CommandBufferStatus {
return CommandBufferStatus ( cb . commandBuffer . Send ( sel_status ) )
}
// PresentDrawable registers a drawable presentation to occur as soon as possible.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443029-presentdrawable .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443029-presentdrawable ?language=objc .
func ( cb CommandBuffer ) PresentDrawable ( d Drawable ) {
cb . commandBuffer . Send ( sel_presentDrawable , d . Drawable ( ) )
}
// Commit commits this command buffer for execution as soon as possible.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443003-commit .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443003-commit ?language=objc .
func ( cb CommandBuffer ) Commit ( ) {
cb . commandBuffer . Send ( sel_commit )
}
// WaitUntilCompleted waits for the execution of this command buffer to complete.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443039-waituntilcompleted .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443039-waituntilcompleted ?language=objc .
func ( cb CommandBuffer ) WaitUntilCompleted ( ) {
cb . commandBuffer . Send ( sel_waitUntilCompleted )
}
// WaitUntilScheduled blocks execution of the current thread until the command buffer is scheduled.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443036-waituntilscheduled .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443036-waituntilscheduled ?language=objc .
func ( cb CommandBuffer ) WaitUntilScheduled ( ) {
cb . commandBuffer . Send ( sel_waitUntilScheduled )
}
// MakeRenderCommandEncoder creates an encoder object that can
// encode graphics rendering commands into this command buffer.
// RenderCommandEncoderWithDescriptor creates a render command encoder from a descriptor.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1442999- make rendercommandencoder.
func ( cb CommandBuffer ) Make RenderCommandEncoder( rpd RenderPassDescriptor ) RenderCommandEncoder {
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1442999- rendercommandencoderwithdescript?language=objc .
func ( cb CommandBuffer ) RenderCommandEncoderWithDescripto r( rpd RenderPassDescriptor ) RenderCommandEncoder {
var renderPassDescriptor = objc . ID ( class_MTLRenderPassDescriptor ) . Send ( sel_new )
var colorAttachments0 = renderPassDescriptor . Send ( sel_colorAttachments ) . Send ( sel_objectAtIndexedSubscript , 0 )
colorAttachments0 . Send ( sel_setLoadAction , int ( rpd . ColorAttachments [ 0 ] . LoadAction ) )
@ -872,11 +868,11 @@ func (cb CommandBuffer) MakeRenderCommandEncoder(rpd RenderPassDescriptor) Rende
return RenderCommandEncoder { CommandEncoder { rce } }
}
// Make BlitCommandEncoder creates an encoder object that can encode
// BlitCommandEncoder creates an encoder object that can encode
// memory operation (blit) commands into this command buffer.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443001-makeblitcommandencoder .
func ( cb CommandBuffer ) Make BlitCommandEncoder( ) BlitCommandEncoder {
// Reference: https://developer.apple.com/documentation/metal/mtlcommandbuffer/1443001-makeblitcommandencoder ?language=objc .
func ( cb CommandBuffer ) BlitCommandEncoder( ) BlitCommandEncoder {
ce := cb . commandBuffer . Send ( sel_blitCommandEncoder )
return BlitCommandEncoder { CommandEncoder { ce } }
}
@ -884,14 +880,14 @@ func (cb CommandBuffer) MakeBlitCommandEncoder() BlitCommandEncoder {
// CommandEncoder is an encoder that writes sequential GPU commands
// into a command buffer.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommand encoder.
// Reference: https://developer.apple.com/documentation/metal/mtlcommand buffer/1443001-blitcommand encoder?language=objc .
type CommandEncoder struct {
commandEncoder objc . ID
}
// EndEncoding declares that all command generation from this encoder is completed.
//
// Reference: https://developer.apple.com/documentation/metal/mtlcommandencoder/1458038-endencoding .
// Reference: https://developer.apple.com/documentation/metal/mtlcommandencoder/1458038-endencoding ?language=objc .
func ( ce CommandEncoder ) EndEncoding ( ) {
ce . commandEncoder . Send ( sel_endEncoding )
}
@ -899,7 +895,7 @@ func (ce CommandEncoder) EndEncoding() {
// RenderCommandEncoder is an encoder that specifies graphics-rendering commands
// and executes graphics functions.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder .
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder ?language=objc .
type RenderCommandEncoder struct {
CommandEncoder
}
@ -910,7 +906,7 @@ func (rce RenderCommandEncoder) Release() {
// SetRenderPipelineState sets the current render pipeline state object.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515811-setrenderpipelinestate .
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515811-setrenderpipelinestate ?language=objc .
func ( rce RenderCommandEncoder ) SetRenderPipelineState ( rps RenderPipelineState ) {
rce . commandEncoder . Send ( sel_setRenderPipelineState , rps . renderPipelineState )
}
@ -925,7 +921,7 @@ func (rce RenderCommandEncoder) SetViewport(viewport Viewport) {
// SetScissorRect sets the scissor rectangle for a fragment scissor test.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515583-setscissorrect
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515583-setscissorrect ?language=objc.
func ( rce RenderCommandEncoder ) SetScissorRect ( scissorRect ScissorRect ) {
inv := cocoa . NSInvocation_invocationWithMethodSignature ( cocoa . NSMethodSignature_signatureWithObjCTypes ( "v@:{MTLScissorRect=qqqq}" ) )
inv . SetTarget ( rce . commandEncoder )
@ -937,14 +933,14 @@ func (rce RenderCommandEncoder) SetScissorRect(scissorRect ScissorRect) {
// SetVertexBuffer sets a buffer for the vertex shader function at an index
// in the buffer argument table with an offset that specifies the start of the data.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515829-setvertexbuffer .
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515829-setvertexbuffer ?language=objc .
func ( rce RenderCommandEncoder ) SetVertexBuffer ( buf Buffer , offset , index int ) {
rce . commandEncoder . Send ( sel_setVertexBuffer_offset_atIndex , buf . buffer , offset , index )
}
// SetVertexBytes sets a block of data for the vertex function.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515846-setvertexbytes .
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515846-setvertexbytes ?language=objc .
func ( rce RenderCommandEncoder ) SetVertexBytes ( bytes unsafe . Pointer , length uintptr , index int ) {
rce . commandEncoder . Send ( sel_setVertexBytes_length_atIndex , bytes , length , index )
}
@ -955,7 +951,7 @@ func (rce RenderCommandEncoder) SetFragmentBytes(bytes unsafe.Pointer, length ui
// SetFragmentTexture sets a texture for the fragment function at an index in the texture argument table.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515390-setfragmenttexture
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515390-setfragmenttexture ?language=objc.
func ( rce RenderCommandEncoder ) SetFragmentTexture ( texture Texture , index int ) {
rce . commandEncoder . Send ( sel_setFragmentTexture_atIndex , texture . texture , index )
}
@ -966,7 +962,7 @@ func (rce RenderCommandEncoder) SetBlendColor(red, green, blue, alpha float32) {
// SetDepthStencilState sets the depth and stencil test state.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1516119-setdepthstencilstate
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1516119-setdepthstencilstate ?language=objc.
func ( rce RenderCommandEncoder ) SetDepthStencilState ( depthStencilState DepthStencilState ) {
rce . commandEncoder . Send ( sel_setDepthStencilState , depthStencilState . depthStencilState )
}
@ -974,7 +970,7 @@ func (rce RenderCommandEncoder) SetDepthStencilState(depthStencilState DepthSten
// DrawPrimitives renders one instance of primitives using vertex data
// in contiguous array elements.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1516326-drawprimitives .
// Reference: https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1516326-drawprimitives ?language=objc .
func ( rce RenderCommandEncoder ) DrawPrimitives ( typ PrimitiveType , vertexStart , vertexCount int ) {
rce . commandEncoder . Send ( sel_drawPrimitives_vertexStart_vertexCount , uintptr ( typ ) , vertexStart , vertexCount )
}
@ -991,7 +987,7 @@ func (rce RenderCommandEncoder) DrawIndexedPrimitives(typ PrimitiveType, indexCo
// BlitCommandEncoder is an encoder that specifies resource copy
// and resource synchronization commands.
//
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder .
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder ?language=objc .
type BlitCommandEncoder struct {
CommandEncoder
}
@ -999,7 +995,7 @@ type BlitCommandEncoder struct {
// Synchronize flushes any copy of the specified resource from its corresponding
// Device caches and, if needed, invalidates any CPU caches.
//
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400775-synchronize .
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400775-synchronize ?language=objc .
func ( bce BlitCommandEncoder ) Synchronize ( resource Resource ) {
if runtime . GOOS == "ios" {
return
@ -1007,6 +1003,9 @@ func (bce BlitCommandEncoder) Synchronize(resource Resource) {
bce . commandEncoder . Send ( sel_synchronizeResource , resource . resource ( ) )
}
// SynchronizeTexture encodes a command that synchronizes a part of the CPU’ s copy of a texture so that it matches the GPU’ s copy.
//
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400757-synchronizetexture?language=objc.
func ( bce BlitCommandEncoder ) SynchronizeTexture ( texture Texture , slice int , level int ) {
if runtime . GOOS == "ios" {
return
@ -1014,6 +1013,9 @@ func (bce BlitCommandEncoder) SynchronizeTexture(texture Texture, slice int, lev
bce . commandEncoder . Send ( sel_synchronizeTexture_slice_level , texture . texture , slice , level )
}
// CopyFromTexture encodes a command that copies image data from a texture’ s slice into another slice.
//
// Reference: https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400754-copyfromtexture?language=objc.
func ( bce BlitCommandEncoder ) CopyFromTexture ( sourceTexture Texture , sourceSlice int , sourceLevel int , sourceOrigin Origin , sourceSize Size , destinationTexture Texture , destinationSlice int , destinationLevel int , destinationOrigin Origin ) {
inv := cocoa . NSInvocation_invocationWithMethodSignature ( cocoa . NSMethodSignature_signatureWithObjCTypes ( "v@:@QQ{MTLOrigin=qqq}{MTLSize=qqq}@QQ{MTLOrigin=qqq}" ) )
inv . SetTarget ( bce . commandEncoder )
@ -1032,15 +1034,15 @@ func (bce BlitCommandEncoder) CopyFromTexture(sourceTexture Texture, sourceSlice
// Library is a collection of compiled graphics or compute functions.
//
// Reference: https://developer.apple.com/documentation/metal/mtllibrary .
// Reference: https://developer.apple.com/documentation/metal/mtllibrary ?language=objc .
type Library struct {
library objc . ID
}
// MakeFunction returns a pre-compiled, non-specialized function.
// NewFunctionWithName returns a pre-compiled, non-specialized function.
//
// Reference: https://developer.apple.com/documentation/metal/mtllibrary/1515524- makefunction .
func ( l Library ) MakeFunction ( name string ) ( Function , error ) {
// Reference: https://developer.apple.com/documentation/metal/mtllibrary/1515524- newfunctionwithname?language=objc .
func ( l Library ) NewFunctionWithName ( name string ) ( Function , error ) {
f := l . library . Send ( sel_newFunctionWithName ,
cocoa . NSString_alloc ( ) . InitWithUTF8String ( name ) . ID ,
)
@ -1057,7 +1059,7 @@ func (l Library) Release() {
// Texture is a memory allocation for storing formatted
// image data that is accessible to the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexture .
// Reference: https://developer.apple.com/documentation/metal/mtltexture ?language=objc .
type Texture struct {
texture objc . ID
}
@ -1068,7 +1070,9 @@ func NewTexture(texture objc.ID) Texture {
}
// resource implements the Resource interface.
func ( t Texture ) resource ( ) unsafe . Pointer { return * ( * unsafe . Pointer ) ( unsafe . Pointer ( & t . texture ) ) }
func ( t Texture ) resource ( ) unsafe . Pointer {
return * ( * unsafe . Pointer ) ( unsafe . Pointer ( & t . texture ) )
}
func ( t Texture ) Release ( ) {
t . texture . Send ( sel_release )
@ -1077,7 +1081,7 @@ func (t Texture) Release() {
// GetBytes copies a block of pixels from the storage allocation of texture
// slice zero into system memory at a specified address.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515751-getbytes .
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515751-getbytes ?language=objc .
func ( t Texture ) GetBytes ( pixelBytes * byte , bytesPerRow uintptr , region Region , level int ) {
inv := cocoa . NSInvocation_invocationWithMethodSignature ( cocoa . NSMethodSignature_signatureWithObjCTypes ( "v@:^vQ{MTLRegion={MTLOrigin=qqq}{MTLSize=qqq}}Q" ) )
inv . SetTarget ( t . texture )
@ -1091,7 +1095,7 @@ func (t Texture) GetBytes(pixelBytes *byte, bytesPerRow uintptr, region Region,
// ReplaceRegion copies a block of pixels from the caller's pointer into the storage allocation for slice 0 of a texture.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515464-replaceregion
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515464-replaceregion ?language=objc.
func ( t Texture ) ReplaceRegion ( region Region , level int , pixelBytes unsafe . Pointer , bytesPerRow int ) {
inv := cocoa . NSInvocation_invocationWithMethodSignature ( cocoa . NSMethodSignature_signatureWithObjCTypes ( "v@:{MTLRegion={MTLOrigin=qqq}{MTLSize=qqq}}Q^vQ" ) )
inv . SetTarget ( t . texture )
@ -1105,14 +1109,14 @@ func (t Texture) ReplaceRegion(region Region, level int, pixelBytes unsafe.Point
// Width is the width of the texture image for the base level mipmap, in pixels.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515339-width
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515339-width ?language=objc.
func ( t Texture ) Width ( ) int {
return int ( t . texture . Send ( sel_width ) )
}
// Height is the height of the texture image for the base level mipmap, in pixels.
//
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515938-height
// Reference: https://developer.apple.com/documentation/metal/mtltexture/1515938-height ?language=objc.
func ( t Texture ) Height ( ) int {
return int ( t . texture . Send ( sel_height ) )
}
@ -1120,13 +1124,19 @@ func (t Texture) Height() int {
// Buffer is a memory allocation for storing unformatted data
// that is accessible to the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtlbuffer .
// Reference: https://developer.apple.com/documentation/metal/mtlbuffer ?language=objc .
type Buffer struct {
buffer objc . ID
}
func ( b Buffer ) resource ( ) unsafe . Pointer { return * ( * unsafe . Pointer ) ( unsafe . Pointer ( & b . buffer ) ) }
// resource implements the Resource interface.
func ( b Buffer ) resource ( ) unsafe . Pointer {
return * ( * unsafe . Pointer ) ( unsafe . Pointer ( & b . buffer ) )
}
// Length returns the logical size of the buffer, in bytes.
//
// Reference: https://developer.apple.com/documentation/metal/mtlbuffer/1515373-length?language=objc.
func ( b Buffer ) Length ( ) uintptr {
return uintptr ( b . buffer . Send ( sel_length ) )
}
@ -1147,13 +1157,9 @@ func (b Buffer) Release() {
b . buffer . Send ( sel_release )
}
func ( b Buffer ) Native ( ) unsafe . Pointer {
return * ( * unsafe . Pointer ) ( unsafe . Pointer ( & b . buffer ) )
}
// Function represents a programmable graphics or compute function executed by the GPU.
//
// Reference: https://developer.apple.com/documentation/metal/mtlfunction .
// Reference: https://developer.apple.com/documentation/metal/mtlfunction?language=objc.
type Function struct {
function objc . ID
}
@ -1165,7 +1171,7 @@ func (f Function) Release() {
// RenderPipelineState contains the graphics functions
// and configuration state used in a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinestate .
// Reference: https://developer.apple.com/documentation/metal/mtlrenderpipelinestate ?language=objc .
type RenderPipelineState struct {
renderPipelineState objc . ID
}
@ -1177,7 +1183,7 @@ func (r RenderPipelineState) Release() {
// Region is a rectangular block of pixels in an image or texture,
// defined by its upper-left corner and its size.
//
// Reference: https://developer.apple.com/documentation/metal/mtlregion .
// Reference: https://developer.apple.com/documentation/metal/mtlregion ?language=objc .
type Region struct {
Origin Origin // The location of the upper-left corner of the block.
Size Size // The size of the block.
@ -1186,25 +1192,36 @@ type Region struct {
// Origin represents the location of a pixel in an image or texture relative
// to the upper-left corner, whose coordinates are (0, 0).
//
// Reference: https://developer.apple.com/documentation/metal/mtlorigin.
type Origin struct { X , Y , Z int }
// Reference: https://developer.apple.com/documentation/metal/mtlorigin?language=objc.
type Origin struct {
X int
Y int
Z int
}
// Size represents the set of dimensions that declare the size of an object,
// such as an image, texture, threadgroup, or grid.
//
// Reference: https://developer.apple.com/documentation/metal/mtlsize.
type Size struct { Width , Height , Depth int }
// Reference: https://developer.apple.com/documentation/metal/mtlsize?language=objc.
type Size struct {
Width int
Height int
Depth int
}
// RegionMake2D returns a 2D, rectangular region for image or texture data.
//
// Reference: https://developer.apple.com/documentation/metal/1515675-mtlregionmake2d.
// Reference: https://developer.apple.com/documentation/metal/1515675-mtlregionmake2d ?language=objc .
func RegionMake2D ( x , y , width , height int ) Region {
return Region {
Origin : Origin { x, y, 0 } ,
Size : Size { width, height, 1 } ,
Origin : Origin { X: x, Y: y, Z : 0 } ,
Size : Size { Width: width, Height: height, Depth : 1 } ,
}
}
// Viewport is a 3D rectangular region for the viewport clipping.
//
// Reference: https://developer.apple.com/documentation/metal/mtlviewport?language=objc.
type Viewport struct {
OriginX float64
OriginY float64
@ -1214,9 +1231,9 @@ type Viewport struct {
ZFar float64
}
// ScissorRect represent s a rectangle for the scissor fragment test.
// ScissorRect i s a rectangle for the scissor fragment test.
//
// Reference: https://developer.apple.com/documentation/metal/mtlscissorrect
// Reference: https://developer.apple.com/documentation/metal/mtlscissorrect ?language=objc.
type ScissorRect struct {
X int
Y int
@ -1226,7 +1243,7 @@ type ScissorRect struct {
// DepthStencilState is a depth and stencil state object that specifies the depth and stencil configuration and operations used in a render pass.
//
// Reference: https://developer.apple.com/documentation/metal/mtldepthstencilstate
// Reference: https://developer.apple.com/documentation/metal/mtldepthstencilstate ?language=objc.
type DepthStencilState struct {
depthStencilState objc . ID
}
@ -1237,7 +1254,7 @@ func (d DepthStencilState) Release() {
// DepthStencilDescriptor is an object that configures new MTLDepthStencilState objects.
//
// Reference: https://developer.apple.com/documentation/metal/mtldepthstencildescriptor
// Reference: https://developer.apple.com/documentation/metal/mtldepthstencildescriptor ?language=objc.
type DepthStencilDescriptor struct {
// BackFaceStencil is the stencil descriptor for back-facing primitives.
BackFaceStencil StencilDescriptor
@ -1248,7 +1265,7 @@ type DepthStencilDescriptor struct {
// StencilDescriptor is an object that defines the front-facing or back-facing stencil operations of a depth and stencil state object.
//
// Reference: https://developer.apple.com/documentation/metal/mtlstencildescriptor
// Reference: https://developer.apple.com/documentation/metal/mtlstencildescriptor ?language=objc.
type StencilDescriptor struct {
// StencilFailureOperation is the operation that is performed to update the values in the stencil attachment when the stencil test fails.
StencilFailureOperation StencilOperation