问题
I want to use groupshared
memory in a DirectX Compute Shader to reduce global memory bandwidth and hopefully improve performance. My input data is a Texture2D
and I can access it using 2D indexing like so:
Input[threadID.xy]
I would like to have a 2D array of shared memory for caching portions of the input data, so I tried the obvious:
groupshared float SharedInput[32, 32];
It won't compile. The error message says syntax error: unexpected token ','
.
Is there any way to have a 2D array of shared memory? If not, what's a good technique for working with 2D data stored in a 1D array of shared memory?
回答1:
groupshared
arrays cannot be indexed with multi-dimensional indexing. The closest you can get is an array of arrays where each dimension is indexed independently.
groupshared float SharedInput[32][32];
It's not as nice as multi-dimensional indexing, but at least you don't have to compute a linear index manually.
来源:https://stackoverflow.com/questions/16046293/do-directx-compute-shaders-support-2d-arrays-in-shared-memory