•
threadgroup
(see section 4.2.2)
•
threadgroup_imageblock
(see section 4.2.3)
•
constant
(see section 4.2.4)
•
thread
(see section 4.2.5)
All arguments to a graphics or kernel function that are a pointer or reference to a type must be
declared with an address space attribute. For graphics functions, an argument that is a pointer
or reference to a type must be declared in the
device
or
constant
address space. For kernel
functions, an argument that is a pointer or reference to a type must be declared in the
device
,
threadgroup
,
threadgroup_imageblock
, or
constant
address space. The following example
introduces the use of several address space attributes. (The
threadgroup
attribute is
supported here for the pointer
l_data
only if
foo
is called by a kernel function, as detailed in
section 4.2.2.)
void foo(device int *g_data,
threadgroup int *l_data,
constant float *c_data)
{…}
The address space for a variable at program scope must be
constant
.
Any variable that is a pointer or reference must be declared with one of the address space
attributes discussed in this section. If an address space attribute is missing on a pointer or
reference type declaration, a compilation error occurs.
4.2.1
device Address Space
The
device
address space name refers to buffer memory objects allocated from the device
memory pool that are both readable and writeable.
A buffer memory object can be declared as a pointer or reference to a scalar, vector or user-
defined struct. The actual size of the buffer memory object is determined when the memory
object is allocated via appropriate Metal API calls in the host code.
Some examples are:
// an array of a float vector with 4
components
device float4 *color;
struct Foo {
float a[3];
int b[2];
}
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page of
55
174