#Is generic code called from bursted generic job burst compiled ?

1 messages · Page 1 of 1 (latest)

solar otter
#

Hello!
I was thinking of making a generic job to support a few different structs that all implement an interface.
If I call a method defined in the interface from within the job, will the method be burst compiled or not?
And if not, is there a way to burst compile it?

blissful oracle
#

burst will refuse to compile things that are the type of an interface, e.g. IMyInterface x, because interface-typed values box.

BUT! If you instead use a constraint, like T x where T : IMyInterface, it will work fine.

also note that you may need to do [assembly: RegisterGenericJobType(typeof(YourGenericJob<YourSpecificT>))] to schedule said generic job from a bursted context

solar otter
#

But I'm still wondering, how can burst know what method it should compile? Will it check all structs that implement the interface and burst compile each of their function?

blissful oracle
#

i don't totally remember what happens for builds, but in the editor it just compiles it on the fly when the specific version of that job is scheduled

#

in builds if you did the register generic job thing it knows to compile it for that reason

#

but i honestly forget how or if it knows without that

#

you could use the [BurstDiscard] trick in builds to see if it's really bursted

solar otter
#

Ok thank you I will try 🙂

blissful oracle
#

also if you explicitly mention YourGenericJob<YourSpecificT> somewhere in code, it knows about it because it'll appear in the metadata for the assembly

#

but if it never sees it mentioned explicitly i'm not sure what happens exactly

solar otter
#

I would like to make the type be a choice from a setting in the game or something like that but I haven't found a way to do that yet.
So for now the job is created with an explicit type and it looks like the method is indeed burst compiled 🙂

#

What if I make a lot of if / else and use explicit types but in those if / else ?
For example I would have :
if(type == TypeEnum.Type1) MyJob<Type1> = new MyJob<Type1> ...
else if(type == ...
Would Burst understand it has to compile all the options?

#

It seems like a very bad way to do it but I don't have any better idea 😦

blissful oracle
#

yes, that would work fine. it just has to be mentioned out loud in code somewhere