#Make BlobAssetStore Burst Compatible (with simple source code fix)

1 messages · Page 1 of 1 (latest)

wicked matrix
#

BlobAssetStore.TryAdd is not burst compatible because of typeof(T), specifically the following code

internal static uint ComputeTypeHash(Type type)
{
    return (uint)type.GetHashCode();
}

internal static Hash128 ComputeKeyAndTypeHash(Hash128 key, Type type)
{
    return new Hash128(math.hashwide(new uint4x2 { c0 = key.Value, c1 = new uint4(ComputeTypeHash(type))}));
}

But you already have a burst compatible Type hashing function and switching that now allows TryAdd to be used in burst

internal static uint ComputeTypeHash<T>()
{
    return (uint)BurstRuntime.GetHashCode32<T>();
}

internal static Hash128 ComputeKeyAndTypeHash<T>(Hash128 key)
{
    return new Hash128(math.hashwide(new uint4x2 { c0 = key.Value, c1 = new uint4(ComputeTypeHash<T>())}));
}

Full source change to fix issue https://github.com/tertle/com.unity.entities/commit/0c5504e8ad9f9f4de1e360c6ee60833e43574a8e

As far as I'm aware this should be a non-breaking change but will allow the use of TryAdd in burst compiled baking systems.

zinc niche
#

applying this change as we speak

zinc niche
#

landed in a branch that should mean it arrives in the release after next. the upcoming release is most of the way through testing and so it's more annoying to land things there