DirectXShaderCompiler
DirectXShaderCompiler copied to clipboard
[HLSL 2021] Setter array subscript operator overload
Hi,
How can I implement a setter array subscript operator overload? A getter works like this but doesn't require references like C does.
Thanks, Tom
struct MyArray {
float4 A[MAX_SIZE];
float4 operator[](int ix) {
if (ix >= MAX_SIZE)
return 0.0;
return A[ix];
};
};
Running into the same issue about a year later. How can we assign to the subscript operator?
Unfortunately, this is not currently possible due to lack of reference support in HLSL. It is something we want to improve in later versions.
This is caused by broken behavior in DXC's overload resolution. We have a bunch of related issues that will need to be addressed in order to support this planned fix for HLSL 202x.
That feature is effectively going to result in us adopting C++ overload rules completely for HLSL, which should solve this and related issues.