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

Is it possible to pass one custom struct to another? #415

Open
Valks opened this issue Oct 23, 2022 · 0 comments
Open

Is it possible to pass one custom struct to another? #415

Valks opened this issue Oct 23, 2022 · 0 comments
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage

Comments

@Valks
Copy link

Valks commented Oct 23, 2022

I'm trying to port some C# code to work on the GPU with the hope of coming up with solutions to all the porting problems I'll encounter when I tackle the code I want to run on the GPU.

Some issues I've overcome easily, i.e. Enums (still, it would be awesome if it wasn't necessary to convert to ints). Others are a little harder, i.e. a way to handle strings (I have a plan in mind using an ArrayPool approach and storing the values in a unit array, wish shaders supported byte arrays).

The one I'm stuck on though is passing a struct to another, i.e.

[AutoConstructor]
public partial struct Runner
{
  private ReadWriteBuffer<SecondaryStruct> secondaryBuffer;
}

public struct SecondaryStruct
{
  private Runner runner;

  public void Init(Runner runner)
  {
    this.runner = runner;
  }
}

I get a warning:

CS8377 The type 'SecondaryStruct' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'ReadWriteBuffer<T>' ComputeShaderTest

Is there a way to work around this issue? i.e. somehow make Runner a global variable that I can access within SecondaryStruct?

By the way, an amazing library you and everyone who has contributed have put together here. Thanks for all the hard effort that you've put into it.

@Valks Valks added question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage labels Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage
Projects
None yet
Development

No branches or pull requests

1 participant