Instance Method

constantData(at:)

Returns a pointer for an inlined constant data argument in the argument buffer.

Required.

Declaration

func constantData(at index: Int) -> UnsafeMutableRawPointer

Parameters

index

The index of the inlined constant data argument within the argument buffer. This value corresponds to either the index ID of a Metal shading language declaration or the index field of a MTLArgumentDescriptor object.

Discussion

Constants declared contiguously in the Metal shading language (in an array or struct) are contiguous in memory. You can encode contiguous ranges of inlined constant data through a pointer to the first constant.

To encode inlined constant data into the argument buffer, perform a memory copy operation from your data’s source pointer to the returned destination pointer.

Listing 1

Encoding inlined constant data

let sourceConstants: [SourceConstants] = [
    // Inlined constant data
    /* ... */
]
let destinationPointer = abEncoder.constantData(: 0)
destinationPointer.copyBytes(from: sourceConstants, count: MemoryLayout<SourceConstants>.size)

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software