Generating an identical struct layout between CPU and GPU - trying to remember an obscure API

I remember reading about an obscure Unity feature that allows a struct to be declared in C#, and an identically layed out mirror struct declaration is automatically created in a shader. I now cannot find reference to that feature. I’m about 80% certain that I didn’t imagine it.

Does anybody know what I’m thinking of? Could somebody please point me to the API?

Thanks.

GenerateHLSL attribute is a function in the SRP core package.

If you need to include array to the struct, HDRP’s ShaderVariablesGlobal.cs is a good sample( but set value to the array on C# is a little tricky).

2 Likes

Ah, thank you! This is what I saw before, but I had forgotten that it was SRP specific so I didn’t look there.