
GPU Computing 143
G
y
-1
N
y
=G
y
*T
y
threads
0
g
y
N
x
=G
x
*T
x
threads
0
g
x
G
x
-1
T
y
-1
0
t
y
0
t
x
T
x
-1
(T
x
*g
x
+t
x
, T
y
*g
y
+t
y
)
Base index of upper left
corner is (N
x
*g
x
, N
y
*g
y
)
FIGURE 4.8: An illustration of Equation (4.22) that relates the dispatch
thread ID to the group ID and the group thread ID.
t as an int2 for convenience. Notice that output is a 2D texture. This compute
shader has no need for texture sampling, so we can look up the texture values
directly without sampling. The
operator[] provides the direct lookup and it
expects a 2-tuple for the index. Because
t is already a 2-tuple, I can use it as
is. However, if I had declared
int3 t, then I would need to perform the lo ...