Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed size array support #125

Open
sselecirPyM opened this issue Jun 3, 2021 · 7 comments
Open

Fixed size array support #125

sselecirPyM opened this issue Jun 3, 2021 · 7 comments
Labels
proposal 💡 A proposal for a new feature

Comments

@sselecirPyM
Copy link

As far as I know, hlsl supports fixed-size arrays. Are there any plans to support the use of fixed-size arrays in shaders?

@Sergio0694 Sergio0694 added the proposal 💡 A proposal for a new feature label Jul 14, 2021
@Sergio0694
Copy link
Owner

This is something I want to add, but need support for fixed size arrays added to C# first.
They've prototyped it in last year's hackathon, but hasn't made it to an official C# release yet.
Unfortunately I don't see this happening before at least C# 13. Will leave this open to track it though 🙂

@sselecirPyM
Copy link
Author

You can support only new T[constant] statements. Or Span variable= stackalloc T[constant].

@harrison314
Copy link

You can support only new T[constant] statements. Or Span variable= stackalloc T[constant].

Or use Hlsl intrinsics eg. float[] array = Hlsl.AllocConstSizeFloatArray(32);

@rickbrew
Copy link
Collaborator

rickbrew commented Jan 4, 2024

Could also permit InlineArray-esque syntax, e.g.

[HlslArray(100)]
private struct Float4Len100 { public float4 element0; }

public float4 Execute()
{
    Float4Len100 array = default;
    for (int i = 0; i < 100; ++i) { array[i] = (float4)i; }
    ...
}

It's kind of ugly, but this way we don't have to wait 5 years for whatever support might be hopefully added to C#. And if/when the right syntax does come along, just switch over to that and nuke the old syntax.

This would unlock a lot of potential, the lack of this is currently limiting what I can do quite severely!

@luoluo39
Copy link

luoluo39 commented Apr 7, 2024

Could also permit InlineArray-esque syntax, e.g.

I can see no reason not to support System.Runtime.CompilerServices.InlineArray, which already met our needs.
implement something similar by ourselves will bring some syntax noise and a lot of extra work to do.

@rickbrew
Copy link
Collaborator

rickbrew commented Apr 7, 2024

I can see no reason not to support System.Runtime.CompilerServices.InlineArray,

As @Sergio0694 explained it to me on Discord, it will still require an additional attribute so that the source generator knows when to kick in. So it would be

[InlineArray(100)]
[HlslArray]
private struct Float4Len100 { public float4 element0; }

And there is quite a bit of work in the generator that would be needed to enable all of this. Don't worry, I've been lobbying @Sergio0694 for this quite a bit -- he definitely knows how important this is :)

There's also the matter of how to unify this across other arrays in other contexts, or other array-like-things such as groupshared and RWStructuredBuffer<T> (e.g. resource textures). Or if that's even necessary / important.

@Sergio0694
Copy link
Owner

Could you folks link any shaders here that do use fixed size arrays? I'm thinking about the implementation here, and I'd like to double check that against some real world code to make sure that it work work fine in those scenarios. Thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal 💡 A proposal for a new feature
Projects
None yet
Development

No branches or pull requests

5 participants