Metal includes the following per-sample functions in Table 27.
get_num_samples
and
get_sample_position
return the number of samples for the color attachment and the sample
offsets for a given sample index. For example, for transparency super-sampling, these functions
can be used to shade per-fragment but do the alpha test per-sample.
Table 27 Samples Fragment Functions in the Metal Standard Library
5.9.1.3
Fragment Functions – Flow Control
The Metal function in Table 28 is used to terminate a fragment.
Table 28 Fragment Flow Control Function in the Metal Standard Library
NOTE:
• Writes to a buffer or texture from a fragment thread before
discard_fragment
is
called are not discarded.
• Multiple fragment threads or helper threads associated with a fragment thread
execute together to compute derivatives. If any (but not all) of these threads
executes the
discard_fragment
function, the behavior of any following derivative
computations (explicit or implicit) is undefined.
5.10 Texture Functions
The texture member functions are categorized into: sample from a texture, sample compare
from a texture, read (sampler-less read) from a texture, gather from a texture, gather compare
from a texture, write to a texture, texture query and texture fence functions.
These are defined in the header
.
Built-in fragment functions
Description
uint get_num_samples()
Returns the number of samples for the
multisampled color attachment.
float2 get_sample_position(uint
indx)
Returns the normalized sample offset (x, y) for a
given sample index
indx
. Values of x and y are
in [0.0 … 1.0).
Built-in fragment functions
Description
void discard_fragment(void)
Marks the current fragment as being
terminated, and the output of the fragment
function for this fragment is discarded.
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page
of
120
174
The texture
sample
,
sample_compare
,
gather
and
gather_compare
functions take an
offset
argument for a 2D texture, 2D texture array and 3D texture. The
offset
is an integer value that
is applied to the texture coordinate before looking up each pixel. This integer value can be in the
range -8 to +7. The default value is 0.
Overloaded variants of texture
sample
and
sample_compare
functions for a 2D texture, 2D
texture array, 3D texture, and cube are available and allow the texture to be sampled using a
bias that is applied to a mip-level before sampling or with user-provided gradients in the x and y
direction.
NOTE:
• The texture
sample
,
sample_compare
,
gather
and
gather_compare
functions
require that the texture is declared with the
sample
access attribute.
• The texture
sample_compare
and
gather_compare
functions are only available for
depth texture types.
• The texture
read
functions require that the texture is declared with the
sample
,
read
or
read_write
access attribute.
• The texture
write
functions require that the texture is declared with the
write
or
read_write
access attribute.
• The
sample
and
sample_compare
functions that do not take an explicit LOD or
gradients and the
gather
and
gather_compare
functions when called from kernel
or vertex functions assume an implicit LOD of 0.
• For the
gather
and
gather_compare
functions, the four samples that would
contribute to filtering are placed into xyzw in counter clockwise order starting
with the sample to the lower left of the queried location. This is the same as
nearest sampling with un-normalized texture coordinate deltas at the following
locations: (-,+), (+,+),(+,-),(-,-), where the magnitude of the deltas are always
half a texel.
5.10.1
1D Texture
The following member functions can be used to sample from a 1D texture.
T
v
sample(sampler s, float coord) const
T
v
is a 4-component vector type based on the templated type used to declare the texture
type. If T is float, T
v
is float4. If T is half, T
v
is half4. If T is int, T
v
is int4. If T is uint, T
v
is uint4. If T
is short, T
v
is short4 and if T is ushort, T
v
is ushort4.
The following member functions can be used to perform sampler-less reads from a 1D texture.
Mipmaps are not supported for 1D textures, so
lod
must be 0.
T
v
read(uint coord, uint lod = 0) const
T
v
read(ushort coord, ushort lod = 0) const
2017-9-12 | Copyright © 2017 Apple Inc. All Rights Reserved.
Page
of
121
174
Dostları ilə paylaş: |