Is it possible to pass one custom struct to another?

Open
#415 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
20/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
csharp

Research direction

The issue names no repository file, test, or entry point. Start by tracing the ReadWriteBuffer constraint and shader struct handling; done means establishing whether nested structs with Runner references are supported and documenting a confirmed workaround or limitation.

Written by the indexing model from the issue text.

Description

question :question: untriaged :toolbox:

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.

Dominant language
C#
Stars
3.2k
Forks
148
Avg merge
4h 32m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Sergio0694/ComputeSharp

All issues in Sergio0694/ComputeSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.