Update rendering architecture and resource management
Added a new `Ref<T>` struct for reference semantics. Added the `RenderGraph` system for managing rendering passes. Added the `RenderTexture` class for encapsulating GPU resources. Added `GraphicsBuffer` class for effective GPU resource management. Changed `CommandList` methods from public to internal for visibility control. Changed `IRenderPass` interface from internal to public for accessibility. Changed `GetData<T>()` in `ComponentObject.cs` to return `CompRef<T>`. Changed `GetComponent<T>()` in `EntityManager.cs` to return `CompRef<T>`. Changed `GetSingleton<T>()` in `World.cs` to use `CompRef<T>`. Changed `IQueryTypeParameter` to use `CompRef<T>` for consistency. Changed `QueryItem<T0>` and related structs to use `CompRef<T>`. Changed `Material` class to support bindless textures. Changed `Shader` class to support bindless rendering. Changed `Mesh` class to support bindless vertex and index buffer access. Updated documentation to reflect the new bindless rendering architecture.
This commit is contained in:
@@ -192,18 +192,18 @@ public readonly struct EntityManager : IDisposable
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the component to retrieve.</typeparam>
|
||||
/// <param name="entity">The entity whose component is to be retrieved.</param>
|
||||
/// <returns>A <see cref="Ref{T}"/> to the component, or a null reference if the component does not exist.</returns>
|
||||
/// <returns>A <see cref="CompRef{T}"/> to the component, or a null reference if the component does not exist.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Ref<T> GetComponent<T>(Entity entity)
|
||||
public readonly CompRef<T> GetComponent<T>(Entity entity)
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
if (_world.ComponentStorage.TryGetPool<T>(out var pool) && pool.Has(entity))
|
||||
{
|
||||
return new Ref<T>(ref pool.GetRef(entity));
|
||||
return new CompRef<T>(ref pool.GetRef(entity));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Ref<T>(ref Unsafe.NullRef<T>(), false);
|
||||
return new CompRef<T>(ref Unsafe.NullRef<T>(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ public interface IQueryTypeParameter
|
||||
{
|
||||
}
|
||||
|
||||
public ref struct Ref<T> : IQueryTypeParameter
|
||||
public ref struct CompRef<T> : IQueryTypeParameter
|
||||
where T : IComponentData
|
||||
{
|
||||
internal ref T _value;
|
||||
@@ -30,13 +30,13 @@ public ref struct Ref<T> : IQueryTypeParameter
|
||||
init;
|
||||
}
|
||||
|
||||
public Ref(ref T value, bool isValid)
|
||||
public CompRef(ref T value, bool isValid)
|
||||
{
|
||||
_value = ref value;
|
||||
IsValid = isValid;
|
||||
}
|
||||
|
||||
public Ref(ref T value) : this(ref value, true)
|
||||
public CompRef(ref T value) : this(ref value, true)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,10 @@ public readonly struct QueryItem<T0>
|
||||
public ref T0 Component0 => ref _pool0.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0)
|
||||
{
|
||||
entity = _entity;
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
@@ -49,10 +50,12 @@ public readonly struct QueryItem<T0, T1>
|
||||
public ref T1 Component1 => ref _pool1.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,10 +82,13 @@ public readonly struct QueryItem<T0, T1, T2>
|
||||
public ref T2 Component2 => ref _pool2.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,10 +118,14 @@ public readonly struct QueryItem<T0, T1, T2, T3>
|
||||
public ref T3 Component3 => ref _pool3.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2, out CompRef<T3> c3)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
c3 = new (ref _pool3.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,10 +158,15 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4>
|
||||
public ref T4 Component4 => ref _pool4.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2, out CompRef<T3> c3, out CompRef<T4> c4)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
c3 = new (ref _pool3.GetRef(_entity));
|
||||
c4 = new (ref _pool4.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,10 +202,16 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5>
|
||||
public ref T5 Component5 => ref _pool5.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2, out CompRef<T3> c3, out CompRef<T4> c4, out CompRef<T5> c5)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
c3 = new (ref _pool3.GetRef(_entity));
|
||||
c4 = new (ref _pool4.GetRef(_entity));
|
||||
c5 = new (ref _pool5.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,10 +250,17 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6>
|
||||
public ref T6 Component6 => ref _pool6.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2, out CompRef<T3> c3, out CompRef<T4> c4, out CompRef<T5> c5, out CompRef<T6> c6)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
c3 = new (ref _pool3.GetRef(_entity));
|
||||
c4 = new (ref _pool4.GetRef(_entity));
|
||||
c5 = new (ref _pool5.GetRef(_entity));
|
||||
c6 = new (ref _pool6.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,10 +302,18 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6, T7>
|
||||
public ref T7 Component7 => ref _pool7.GetRef(_entity);
|
||||
|
||||
// Deconstruct into tuple-like values
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6, out Ref<T7> c7)
|
||||
public void Deconstruct(out Entity entity, out CompRef<T0> c0, out CompRef<T1> c1, out CompRef<T2> c2, out CompRef<T3> c3, out CompRef<T4> c4, out CompRef<T5> c5, out CompRef<T6> c6, out CompRef<T7> c7)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));c7 = new (ref _pool7.GetRef(_entity));
|
||||
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
c1 = new (ref _pool1.GetRef(_entity));
|
||||
c2 = new (ref _pool2.GetRef(_entity));
|
||||
c3 = new (ref _pool3.GetRef(_entity));
|
||||
c4 = new (ref _pool4.GetRef(_entity));
|
||||
c5 = new (ref _pool5.GetRef(_entity));
|
||||
c6 = new (ref _pool6.GetRef(_entity));
|
||||
c7 = new (ref _pool7.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,16 +20,10 @@ var deconstructParams = Enumerable.Range(0, arity)
|
||||
.Select(i => {
|
||||
var name = $"c{i}";
|
||||
return arity == 1
|
||||
? $"out Ref<T0> {name}"
|
||||
: $"out Ref<T{i}> {name}";
|
||||
? $"out CompRef<T0> {name}"
|
||||
: $"out CompRef<T{i}> {name}";
|
||||
})
|
||||
.Aggregate((a, b) => a + ", " + b);
|
||||
var deconstructAssigns = Enumerable.Range(0, arity)
|
||||
.Select(i => {
|
||||
var name = $"c{i}";
|
||||
return $"{name} = new (ref _pool{i}.GetRef(_entity));";
|
||||
})
|
||||
.Aggregate((a, b) => a + b);
|
||||
#>
|
||||
public readonly struct QueryItem<<#= generics #>>
|
||||
<#= restrictions #>
|
||||
@@ -57,7 +51,10 @@ public readonly struct QueryItem<<#= generics #>>
|
||||
public void Deconstruct(out Entity entity, <#= deconstructParams #>)
|
||||
{
|
||||
entity = _entity;
|
||||
<#= deconstructAssigns #>
|
||||
|
||||
<# for (int i = 0; i < arity; i++){ #>
|
||||
c<#= i #> = new (ref _pool<#= i #>.GetRef(_entity));
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,11 +68,11 @@ public partial class World : IDisposable, IEquatable<World>
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Ref<T> GetSingleton<T>()
|
||||
public CompRef<T> GetSingleton<T>()
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
ref var component = ref CollectionsMarshal.GetValueRefOrAddDefault(SingletonContainer<T>.container, _id, out _);
|
||||
return new Ref<T>(ref component);
|
||||
return new CompRef<T>(ref component);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
Reference in New Issue
Block a user