DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

[HLSL 2021] Setter array subscript operator overload

Open tomjohnstone opened this issue 3 years ago • 1 comments
trafficstars

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];
  };
};

tomjohnstone avatar Mar 21 '22 22:03 tomjohnstone

Running into the same issue about a year later. How can we assign to the subscript operator?

natevm avatar Oct 08 '22 19:10 natevm

Unfortunately, this is not currently possible due to lack of reference support in HLSL. It is something we want to improve in later versions.

pow2clk avatar Nov 28 '22 20:11 pow2clk

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.

llvm-beanz avatar Jun 30 '23 15:06 llvm-beanz