forked from Misaki/GhostEngine
Improve the usability of Result<T, E> and add new job schedule method to EntityQuery.
Added implicate conversion to Result<T, E> and RefResult<T, E>; Added new ScheduleChunkParallel in EntityQuery; Remove Ghost.SparseEntity from solution file. It's now completlty replaced by Ghost.Entities;
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Ghost.Core;
|
||||
using Ghost.Graphics.RHI;
|
||||
using Misaki.HighPerformance.LowLevel;
|
||||
using Misaki.HighPerformance.LowLevel.Buffer;
|
||||
using Misaki.HighPerformance.LowLevel.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -83,15 +84,15 @@ public struct Material : IResourceReleasable, IHandleType
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly unsafe Result<T, ResultStatus> GetPropertyCache<T>()
|
||||
public readonly unsafe Result<T, ErrorStatus> GetPropertyCache<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
if (sizeof(T) != _cBufferCache.Size)
|
||||
{
|
||||
return Result.Create(default(T), ResultStatus.InvalidArgument);
|
||||
return ErrorStatus.InvalidArgument;
|
||||
}
|
||||
|
||||
return Result.Create(*(T*)_cBufferCache.CpuData.GetUnsafePtr(), ResultStatus.Success);
|
||||
return *(T*)_cBufferCache.CpuData.GetUnsafePtr();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -106,28 +107,28 @@ public struct Material : IResourceReleasable, IHandleType
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly unsafe ResultStatus SetPropertyCache<T>(ref readonly T data)
|
||||
public readonly unsafe ErrorStatus SetPropertyCache<T>(ref readonly T data)
|
||||
where T : unmanaged
|
||||
{
|
||||
if (sizeof(T) != _cBufferCache.Size)
|
||||
{
|
||||
return ResultStatus.InvalidArgument;
|
||||
return ErrorStatus.InvalidArgument;
|
||||
}
|
||||
|
||||
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
||||
return ResultStatus.Success;
|
||||
return ErrorStatus.None;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly unsafe ResultStatus SetRawPropertyCache(ReadOnlySpan<byte> data)
|
||||
public readonly unsafe ErrorStatus SetRawPropertyCache(ReadOnlySpan<byte> data)
|
||||
{
|
||||
if (data.Length != _cBufferCache.Size)
|
||||
{
|
||||
return ResultStatus.InvalidArgument;
|
||||
return ErrorStatus.InvalidArgument;
|
||||
}
|
||||
|
||||
Unsafe.WriteUnaligned(_cBufferCache.CpuData.GetUnsafePtr(), data);
|
||||
return ResultStatus.Success;
|
||||
return ErrorStatus.None;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -49,7 +49,7 @@ public readonly unsafe ref struct RenderingContext
|
||||
CommandBufferType.Graphics => _engine.Device.GraphicsQueue,
|
||||
CommandBufferType.Compute => _engine.Device.ComputeQueue,
|
||||
CommandBufferType.Copy => _engine.Device.CopyQueue,
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
_ => throw new InvalidOperationException("Unknown command buffer type."),
|
||||
};
|
||||
|
||||
queue.Submit(commandBuffer);
|
||||
@@ -123,8 +123,8 @@ public readonly unsafe ref struct RenderingContext
|
||||
localToWorld = localToWorld,
|
||||
worldBoundsMin = meshData.BoundingBox.Min,
|
||||
worldBoundsMax = meshData.BoundingBox.Max,
|
||||
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()).GetValueOrThrow(ResultStatus.Success),
|
||||
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()).GetValueOrThrow(ResultStatus.Success),
|
||||
vertexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.VertexBuffer.AsResource()).GetValueOrThrow(),
|
||||
indexBuffer = _engine.ResourceDatabase.GetBindlessIndex(meshData.IndexBuffer.AsResource()).GetValueOrThrow(),
|
||||
};
|
||||
|
||||
var bufferHandle = meshData.ObjectDataBuffer.AsResource();
|
||||
@@ -147,7 +147,7 @@ public readonly unsafe ref struct RenderingContext
|
||||
where T : unmanaged
|
||||
{
|
||||
var desc = ResourceDatabase.GetResourceDescription(texture.AsResource())
|
||||
.GetValueOrThrow(ResultStatus.Success);
|
||||
.GetValueOrThrow();
|
||||
|
||||
if (data.Length * sizeof(T) != desc.TextureDescription.GetTotalBytes())
|
||||
{
|
||||
@@ -180,7 +180,7 @@ public readonly unsafe ref struct RenderingContext
|
||||
var shader = ResourceDatabase.GetShaderReference(materialRef.Shader);
|
||||
|
||||
var keyResult = shader.TryGetPassKey(passName, out var passIndex);
|
||||
if (keyResult.Status != ResultStatus.Success)
|
||||
if (keyResult.Error != ErrorStatus.None)
|
||||
{
|
||||
throw new Exception(keyResult.ToString());
|
||||
}
|
||||
@@ -208,4 +208,4 @@ public readonly unsafe ref struct RenderingContext
|
||||
var threadGroupCountX = ((uint)meshRef.IndexCount + numThreadsX - 1) / numThreadsX;
|
||||
_directCmd.DispatchMesh(threadGroupCountX, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,17 +101,17 @@ public class Shader : IResourceReleasable, IIdentifierType
|
||||
return ref _passes[index];
|
||||
}
|
||||
|
||||
public RefResult<ShaderPass, ResultStatus> TryGetPassKey(string passName, out int passIndex)
|
||||
public RefResult<ShaderPass, ErrorStatus> TryGetPassKey(string passName, out int passIndex)
|
||||
{
|
||||
var index = _passLookup.GetValueOrDefault(passName, -1);
|
||||
if (index == -1)
|
||||
{
|
||||
passIndex = -1;
|
||||
return Result.CreateRef(ref Unsafe.NullRef<ShaderPass>(), ResultStatus.NotFound);
|
||||
return ErrorStatus.NotFound;
|
||||
}
|
||||
|
||||
passIndex = index;
|
||||
return Result.CreateRef(ref _passes[index], ResultStatus.Success);
|
||||
return RefResult<ShaderPass, ErrorStatus>.Success(ref _passes[index]);
|
||||
}
|
||||
|
||||
void IResourceReleasable.ReleaseResource(IResourceDatabase database)
|
||||
|
||||
Reference in New Issue
Block a user