Do DirectX Compute Shaders support 2D arrays in shared memory?

…衆ロ難τιáo~ 提交于 2020-01-15 10:18:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!