initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,69 @@
using Unity.Collections;
using System.Runtime.CompilerServices;
namespace SLZ.CustomStaticBatching
{
public interface IGenericInt<T>
{
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ToInt(T value);
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T ToType(int other);
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Add(T value, int other);
}
public struct GenericInt32 : IGenericInt<int>
{
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ToInt(int value)
{
return value;
}
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ToType(int value)
{
return value;
}
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int Add(int value, int other)
{
return value + other;
}
}
public struct GenericInt16 : IGenericInt<ushort>
{
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ToInt(ushort value)
{
return (int)value;
}
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort ToType(int value)
{
return (ushort)value;
}
//[BurstCompatible]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ushort Add(ushort value, int other)
{
return (ushort)(value + other);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f74d73f918268d842a6bff9fc2b0dd2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;
using UnityEngine;
namespace SLZ.CustomStaticBatching
{
[Serializable]
public struct CombineRendererSettings
{
public PackedChannel.VtxFormats[] GetVertexFormats()
{
PackedChannel.VtxFormats[] outp = new PackedChannel.VtxFormats[serializedVtxFormats.Length];
for (int i = 0; i < serializedVtxFormats.Length; i++)
{
outp[i] = (PackedChannel.VtxFormats)serializedVtxFormats[i];
}
return outp;
}
public byte[] serializedVtxFormats;
public bool allow32bitIdx;
public int maxCombined32Idx;
public bool splitMultiMaterialMeshes;
public bool[] altStream;
public CombineRendererSettings(bool initialize)
{
serializedVtxFormats = new byte[PackedChannel.NUM_VTX_CHANNELS];
if (initialize)
{
for (int i = 0; i < PackedChannel.NUM_VTX_CHANNELS; i++)
{
serializedVtxFormats[i] = (byte)PackedChannel.VtxFormats.Float32;
}
}
altStream = new bool[PackedChannel.NUM_VTX_CHANNELS];
allow32bitIdx = true;
splitMultiMaterialMeshes = false;
maxCombined32Idx = 1 << 23;
}
}
public interface ICSBIndexer
{
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dc800bc209466954eb0c07b6362f6bfa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
namespace SLZ.CustomStaticBatching
{
/// <summary>
/// Bit-packed information about a single attribute channel in a vertex buffer. Maps to a single UInt,
/// Needs to be kept in sync with the Job and compute shader used for combining.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 4)]
public struct PackedChannel
{
[FieldOffset(0)]
public UInt32 packedData;
[FieldOffset(0)]
public byte dimension;
[FieldOffset(1)]
public byte format;
[FieldOffset(2)]
public byte offset;
[FieldOffset(3)]
public byte stream;
public override string ToString()
{
return string.Format("Dimension {0}, Format {1}, Offset {2}, Channel {3}, Packed: 0x{3}", (int)dimension, (int)format, (int)offset, packedData.ToString("X8"));
}
// Maximum number of vertex attributes in a mesh
public const int NUM_VTX_CHANNELS = 12;
/// <summary>
/// Supported vertex formats. This is hard-coded into the compute shader used for combining, so don't just go adding formats to this list!
/// Only commonly used floating point formats are here. There's no logical way to choose a format for the combined mesh's channels if the
/// channel is integer on one mesh and floating point on another. Which format do you choose? Cast int to float or treat the bytes of the
/// int as a float? You can losslessly store the bytes of an int32 in a float, but it'll get garbled if the output channel is compressed
/// to half. Also what if the int is less than 32 bits? You can't put a short or char into a half or unorm, as those will get converted to
/// float by the GPU. I'm not supporting 16 bit normalized formats to cut down on shader complexity. Just use half precision instead.
/// These need to be in order of increasing precision such that each format can be safely contained in the next format.
/// </summary>
[Serializable]
public enum VtxFormats : byte
{
[UnityEngine. HideInInspector]
Invalid = 0,
UNorm8 = 1,
SNorm8 = 2,
Float16 = 3,
Float32 = 4,
}
/// <summary>
/// Maps each VtxFormat enum to the number of bytes in that format
/// </summary>
public static ReadOnlySpan<byte> VtxFmtToBytes => new byte[5] { 0, 1, 1, 2, 4 };
/// <summary>
/// Maps a VtxFormats enum value to a VertexAttributeFormat enum value
/// </summary>
public static ReadOnlySpan<VertexAttributeFormat> ToUnityFormatLUT => new VertexAttributeFormat[5] {
VertexAttributeFormat.Float32,
VertexAttributeFormat.UNorm8,
VertexAttributeFormat.SNorm8,
VertexAttributeFormat.Float16,
VertexAttributeFormat.Float32,
};
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33937365e94434c4992b189f6b5e2f47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,18 @@
{
"name": "SLZ.CustomStaticBatching.Common",
"rootNamespace": "",
"references": [
"GUID:2665a8d13d1b3f18800f46e256720795",
"GUID:e0cd26848372d4e5c891c569017e11f1",
"GUID:d8b63aba1907145bea998dd612889d6b"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b3170da2b0ad74e4aad542674030756e
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: