#Calling Burst Compiled code form Mono

1 messages · Page 1 of 1 (latest)

mellow coral
#

Let's say I have this method:

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int2 QuantizeToCell(float2 point, float2 cellSize) => (int2)math.floor(point * cellSize);

When i call this method from a monobehaviour, what happens? Does it run the c#? Does it switch to burst and run that? Does it only run burst code when called from a bursted job?

This is a simple operation, so I wonder if switching to burst and back is more expensive than running this in only c#, so would I need to make two methods and tag one with a burst discard?

wild yew
#

Burst compiled its own dll

#

Your call is replaced by a call to the burst compiled method

#

If you're within burst context , a compiled method or job, why method you call is always burst compiled

#

You don't need the attribute on every method

#

And yes calling this from mono would probably be slower than not burst compiling it

#

The tiny overhead would be bigger than any benefit

#

As for burst discard, forget it exists

#

It does not do what you think it does

mellow coral
wild yew
#

No

#

It deletes the method

#

It's like you select the method, and press delete on your keyboard, it will not run

#

It doesn't just let you escape burst and call it as a mono

mellow coral
#

ah, so it compiles it then removes it from the dll, so a call to that would error out?

#

i feel like you just said what i said in a different way haha

mellow coral
#

i didnt think the burst dll would try to go back to mono to call it lol

wild yew
#

Ok, that's what most people think it does

#

But it's also why it has minimal to no uses

#

It's really only good pattern is detecting if you're in burst or not

mellow coral
#

also my burst compile attribute is on the method because this is in a static class, not a job. I'm pretty sure burst can compile static methods in a struct or static class if there's no managed objects right?

#

I would basically do this:

[BurstCompile]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int2 QuantizeToCellBurst(float2 point, float2 cellSize) => (int2)math.floor(point * cellSize);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int2 QuantizeToCell(float2 point, float2 cellSize) => (int2)math.floor(point * cellSize);

And I think that would be fine then?

wild yew
#

It can but if you call it from a job or any other busted context it'll be burst compiled anyway

#

Like I'm not sure the point of your 2 methods

#

Just call the bottom one in all cases

#

It'll be bursted from jobs

mellow coral
#

I call this method a lot in both burst and mono

#

ah

wild yew
#

You can't escape burst (without magic)

#

So any code you call from burst has to be burst compiled as well

mellow coral
#

I was concerned that when it was automatically burst compiled it would cause all calls to it to go to the burst dll

wild yew
#

It doesn't need an attribute

#

But all burst code is also mono compiled

#

(you can turn off burst at any time)

mellow coral
#

yea

wild yew
#

In fact even in a build, if you delete the burst dll your game will run normally

#

Just not with burst

mellow coral
#

so as long as there's no burstcompile attribute, calls to the method wouldn't go to burst unless called from burst?

mellow coral
#

ah ok nice thank you.

#

Is there a page on this in the documentation for burst? I couldn't find one lol

#

(I will definitely forget details again in the future since I dont use burst a lot)

mellow coral
dense jacinth
mellow coral
#

what you just described is switching from mono context to burst context

dense jacinth
#

for me, switching from mono to burst or mono to il2cpp means going into project settings and changing the scripting backend, but writing a bursted method is not switching at all

mellow coral
#

idk what you're talking about man. When the executing thread goes into the burst dll, it's described in the documentation (or perhaps people describe it as that) as switching to burst context.

candid bear
#

I don't think there is any document page details about this effect, especially the burst dll. Until now it's all informal knowledge floating around this community.