#Is generic code called from bursted generic job burst compiled ?
1 messages · Page 1 of 1 (latest)
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
Alright thank you!
(That's what I was planning to do 🙂 )
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?
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
Ok thank you I will try 🙂
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
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 😦
yes, that would work fine. it just has to be mentioned out loud in code somewhere