0

In a DirectCompute shader, having a function taking an string type argument, how to access individual characters ?

Example:

uint TestFunc(string S, uint I)
{
    return uint(S[I]);
}

The compiler complain about S[I]: "error X3121: array, matrix, vector, or indexable object type expected in index expression".

Any idea?

fpiette
  • 11,983
  • 1
  • 24
  • 46

1 Answers1

0

From MS docs:

HLSL also supports a string type, which is an ASCII string. There are no operations or states that accept strings, but effects can query string parameters and annotations.

Strings exist in HLSL, but there’s very little you can do with them. Depending on your needs, you might want to pass the string to the shader as an array of instead of a string, or as a RWStructuredBuffer of bytes, then perform the conversion to/from ASCII.

kefren
  • 1,042
  • 7
  • 12
  • The strings are to be generated and handled by the shader. Currently I'm using uint arrays instead of strings. But it not very much better since HLSL doesn't seems to accept function with unspecified array size.(See related question https://stackoverflow.com/questions/57605109/directx-compute-shader-how-to-write-a-function-with-variable-array-size-argumen?noredirect=1#comment101684236_57605109 ) – fpiette Aug 23 '19 at 05:38