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

AppendStructuredBuffer #321

Open
Vilo176 opened this issue Jul 10, 2022 · 8 comments
Open

AppendStructuredBuffer #321

Vilo176 opened this issue Jul 10, 2022 · 8 comments
Labels
proposal 💡 A proposal for a new feature

Comments

@Vilo176
Copy link

Vilo176 commented Jul 10, 2022

Hi Friends,

I have a shader that perfoms a calculation on 3 axis.

For each tuple (ThreadIds.X, ThreadIds.Y, ThreadIds.Z), the shader makes several tests to find matching indexed objects.
So, I have to store a list of int for each cell (X,Y,Z).

One way could have been to use a fixed sizes multi-dimensional ReadWriteBuffer, which doesn't seams to exists.
Another way could have been to use a HLSL AppendStructuredBuffer (with T = struct { ... }), but I don't know how to do it since CompSharp does not allow this type for now.

Any advice ?
Thanks ;-)

@Vilo176 Vilo176 added proposal 💡 A proposal for a new feature untriaged 🧰 A new issue that needs initial triage labels Jul 10, 2022
@Sergio0694
Copy link
Owner

I'm not sure I fully understand your issue, can you elaborate a bit more maybe show a small code sample..? If you're dispatching a shader on 3 axes and for each one you need to store an int value with the result of the computation for that (X, Y, Z) tuple, can't you use a ReadWriteTexture3D<int> and have each shader invocation write the result for that tuple there? Or, even just a ReadWriteBuffer<int> and then you'd calculate the right offset to write the result at yourself. Would that not work?

@Sergio0694 Sergio0694 added needs author feedback 📝 This issue needs more info from the author and removed untriaged 🧰 A new issue that needs initial triage labels Jul 10, 2022
@Vilo176
Copy link
Author

Vilo176 commented Jul 10, 2022

Hi Sergio,

You are not far from it : for each (x, y, z) I have to store an array of int (from 0 to several tenth of values), representing the indexes of the matching objects for that tuple (actually triangles that are cutted by the cell at xyz).

@Sergio0694
Copy link
Owner

I see. Unfortunately I don't really see a way to implement this as a built-in buffer type. The buffer types ComputeSharp exposes are just mapping the real HLSL buffer types, but there's no type like this. In your scenario, you might need to allocate a 3D texture with a depth of the maximum possible number of matches for each item, and then have each tuple write to the right location. This might end up using too memory though, so you might need to find an alternative solution.

@Sergio0694 Sergio0694 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2022
@Sergio0694 Sergio0694 removed the needs author feedback 📝 This issue needs more info from the author label Aug 18, 2022
@Vilo176
Copy link
Author

Vilo176 commented Aug 18, 2022

Yes indeed, memory consumption would explose.
Why couldn't "AppendStructuredBuffer" be a good candidate ?

@Sergio0694
Copy link
Owner

Because there's no data type in HLSL that represents that. All resource types in ComputeSharp directly map to existing HLSL data types, it's not possible to just "create a new type". GPUs don't work like normal CPUs, and unfortunately this means you can't just easily create a data structure like that. You might be able to create something like this, but it'd be a custom-built thing with specific logic to support this, and it would need to be structured quite differently. And most importantly, you can't allocate new memory from a shader, which means you'd necessarily need to have an upper bound of maximum values to discover/set.

@Vilo176
Copy link
Author

Vilo176 commented Aug 18, 2022

@Sergio0694
Copy link
Owner

Uuuh... I had completely missed those two new buffer types 👀
Reopening this for tracking, yeah if those exist in HLSL it would be nice to add support for them in the future.
Not for 2.0 at this point, but for a future release for sure. Thank you! 😄

@Sergio0694 Sergio0694 reopened this Aug 18, 2022
@Avid29
Copy link
Contributor

Avid29 commented Jan 28, 2024

Any updates here?

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

3 participants