2

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?

shoelzer
  • 10,648
  • 2
  • 28
  • 49
  • Have you tried [][]? Even DX9c HLSL supports it, so with some imagination, compute shaders should do too. – Orwell Apr 16 '13 at 20:24
  • I have not tried `[][]`. That would make an array of arrays, which is different than a 2D array. Indexing wouldn't be as nice as 2D indexing, but better than linear indexing. I wonder if there's any performance difference compared to one linear array? – shoelzer Apr 16 '13 at 20:35

1 Answers1

3

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.

shoelzer
  • 10,648
  • 2
  • 28
  • 49