Jason Leach Jason Leach - 5 months ago 28
iOS Question

What are Apple's Metal (Metal Shader Language) texture coordinates?

In iOS or OS/X what texture coordinates are used in Metal Shader Language kernel function? For example, given an

MTLTexture
and
uint2 gid[[thread_position_in_grid]]
Is
gid.x
and
gid.y
between 0..1 (x and y are floats) or 0..
inTexture.get_width()
(x and y are integers).

Thanks in Advance

Answer

thread_position_in_grid is an index (an integer) in the grid that takes values in the ranges you specify in dispatchThreadgroups:threadsPerThreadgroup:. It's up to you to decide how many thread groups you want, and how many threads per group.

In the following sample code you can see that threadsPerGroup.width * numThreadgroups.width == inputImage.width and threadsPerGroup.height * numThreadgroups.height == inputImage.height. In this case, a position in the grid will thus be a non-normalized (integer) pixel coordinate.

Comments