Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top