feat(rhi)!: refactor resource handles to GPUTexture/GPUBuffer

Refactored all graphics resource handles to use Handle<GPUTexture> and Handle<GPUBuffer> instead of Handle<Texture> and Handle<GraphicsBuffer>. Updated all APIs, interfaces, and implementations to use the new types, including ICommandBuffer, IResourceAllocator, ISwapChain, IRenderOutput, IRenderGraphBuilder, and related classes. Introduced TempJobAllocator for frame-latency-aware allocations. Updated ResourceHandleExtensions for new conversions. Performed minor code cleanups and removed the empty ClusterLod.cs file.

BREAKING CHANGE: All usages of Handle<Texture> and Handle<GraphicsBuffer> are replaced with Handle<GPUTexture> and Handle<GPUBuffer>. This affects all APIs and resource management code. Callers must update their code to use the new handle types.
This commit is contained in:
2026-03-30 21:27:16 +09:00
parent b28b32f502
commit 89e6c68f2a
32 changed files with 447 additions and 270 deletions

View File

@@ -54,12 +54,12 @@ public class TextureAsset : Asset
internal const string _TYPE_ID = "0906F4EB-C3F0-431B-BCEA-132C88AB0C3F";
internal static readonly Guid s_typeGuid = Guid.Parse(_TYPE_ID);
private readonly Handle<Texture> _texture;
private readonly Handle<GPUTexture> _texture;
public override Guid TypeID => s_typeGuid;
public Handle<Texture> Texture => _texture;
public Handle<GPUTexture> Texture => _texture;
public TextureAsset(Guid id, Guid[] dependencies, IAssetSettings? settings, Handle<Texture> texture)
public TextureAsset(Guid id, Guid[] dependencies, IAssetSettings? settings, Handle<GPUTexture> texture)
: base(id, dependencies, settings)
{
_texture = texture;

View File

@@ -9,7 +9,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<IsAotCompatible>True</IsAotCompatible>
<DefineConstants>$(DefineConstants);ENABLE_DEBUG_LAYER</DefineConstants>
<DefineConstants>$(DefineConstants);MHP_ENABLE_SAFETY_CHECKS</DefineConstants>
<IsTrimmable>True</IsTrimmable>
</PropertyGroup>
@@ -19,9 +19,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Misaki.HighPerformance" Version="1.0.5" />
<PackageReference Include="Misaki.HighPerformance.Jobs" Version="1.5.3" />
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.5.4">
<PackageReference Include="Misaki.HighPerformance" Version="1.0.6" />
<PackageReference Include="Misaki.HighPerformance.Jobs" Version="1.5.5" />
<PackageReference Include="Misaki.HighPerformance.LowLevel" Version="1.6.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@@ -0,0 +1,164 @@
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Utilities;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Ghost.Core;
public unsafe partial struct TempJobAllocator
{
private static TempJobAllocator* _pAllocator;
public static AllocationHandle AllocationHandle => _pAllocator->Handle;
internal static void Initialize(nuint capacity)
{
Debug.Assert(_pAllocator == null, "TempJobAllocator is already initialized.");
_pAllocator = (TempJobAllocator*)Malloc((nuint)sizeof(TempJobAllocator));
}
internal static void Dispose()
{
if (_pAllocator == null)
{
return;
}
for (var i = 0; i < _FRAME_LATENCY; i++)
{
_pAllocator->_pArena[i].Dispose();
}
MemoryUtility.Free(_pAllocator->_pArena);
MemoryUtility.Free(_pAllocator);
_pAllocator = null;
}
}
public unsafe partial struct TempJobAllocator : IAllocator
{
private const int _FRAME_LATENCY = 4;
private const int _MAGIC_ID = -559038737;
private VirtualArena* _pArena;
private int _currentFrameCount;
private int _currentFrameIndex;
private fixed int _allocationsPerFrame[_FRAME_LATENCY];
private MemoryHandle _memoryHandle;
private AllocationHandle _handle;
public readonly AllocationHandle Handle => _handle;
internal TempJobAllocator(void* pSelf, nuint capacity)
{
var memoryHandle = default(MemoryHandle);
_pArena = (VirtualArena*)Malloc((nuint)(sizeof(VirtualArena) * _FRAME_LATENCY));
_currentFrameCount = 0;
_currentFrameIndex = 0;
_memoryHandle = memoryHandle;
for (var i = 0; i < _FRAME_LATENCY; i++)
{
_pArena[i] = new VirtualArena(capacity);
_allocationsPerFrame[i] = 0;
}
_handle = new AllocationHandle
{
State = Unsafe.AsPointer(ref this),
Alloc = &Allocate,
Realloc = &Reallocate,
Free = &Free,
#if MHP_ENABLE_SAFETY_CHECKS
IsValid = &IsValid,
#else
IsValid = null,
#endif
};
}
private static void* Allocate(void* instance, nuint size, nuint alignment, AllocationOption allocationOption
#if MHP_ENABLE_SAFETY_CHECKS
, MemoryHandle* pHandle
#endif
)
{
var pSelf = (TempJobAllocator*)instance;
var pCurrentArena = pSelf->_pArena + pSelf->_currentFrameIndex;
var ptr = pCurrentArena->Allocate(size, alignment, allocationOption);
if (ptr == null)
{
#if MHP_ENABLE_SAFETY_CHECKS
*pHandle = MemoryHandle.Invalid;
#endif
return null;
}
Interlocked.Increment(ref pSelf->_allocationsPerFrame[pSelf->_currentFrameIndex]);
#if MHP_ENABLE_SAFETY_CHECKS
*pHandle = new MemoryHandle(_MAGIC_ID, pSelf->_currentFrameCount);
#endif
return ptr;
}
private static void* Reallocate(void* instance, void* ptr, nuint oldSize, nuint newSize, nuint alignment, AllocationOption allocationOption
#if MHP_ENABLE_SAFETY_CHECKS
, MemoryHandle* pHandle
#endif
)
{
if (ptr == null)
{
return Allocate(instance, newSize, alignment, allocationOption
#if MHP_ENABLE_SAFETY_CHECKS
, pHandle
#endif
);
}
var pSelf = (TempJobAllocator*)instance;
var pCurrentArena = pSelf->_pArena + pSelf->_currentFrameIndex;
var newPtr = pCurrentArena->Allocate(newSize, alignment, allocationOption);
if (newPtr == null)
{
return null;
}
MemCpy(ptr, newPtr, Math.Min(oldSize, newSize));
return newPtr;
}
private static void Free(void* instance, void* ptr
#if MHP_ENABLE_SAFETY_CHECKS
, MemoryHandle handle
#endif
)
{
var pSelf = (TempJobAllocator*)instance;
Interlocked.Decrement(ref pSelf->_allocationsPerFrame[pSelf->_currentFrameIndex]);
}
#if MHP_ENABLE_SAFETY_CHECKS
private static bool IsValid(void* instance, MemoryHandle handle)
{
var pSelf = (TempJobAllocator*)instance;
return handle.ID == _MAGIC_ID && handle.Generation > pSelf->_currentFrameCount - _FRAME_LATENCY;
}
#endif
public int AdvanceFrame()
{
var allocations = Interlocked.Exchange(ref _allocationsPerFrame[_currentFrameIndex], 0);
_currentFrameCount++;
_currentFrameIndex = _currentFrameCount % _FRAME_LATENCY;
(_pArena + _currentFrameIndex)->Reset();
return allocations;
}
}

View File

@@ -24,8 +24,8 @@ public unsafe struct Camera : IComponent
public int swapChainIndex; // The index of the swap chain to render to. -1 means render to rt only.
public int priority;
public Handle<Texture> colorTarget;
public Handle<Texture> depthTarget;
public Handle<GPUTexture> colorTarget;
public Handle<GPUTexture> depthTarget;
// TODO: Add more render targets like motion vector, etc.
// Custim render function. If it's not null, the render system will call this function instead of the default render pipeline.

View File

@@ -1,3 +1,4 @@
using Ghost.Core;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Collections;
using System.Runtime.CompilerServices;
@@ -57,7 +58,7 @@ public unsafe partial struct EntityQuery
throw new InvalidOperationException("The World has no JobScheduler assigned.");
}
var chunkInfos = new UnsafeList<ChunkInfo>(_matchingArchetypes.Count * 2, JobScheduler.TempAllocatorHandle);
var chunkInfos = new UnsafeList<ChunkInfo>(_matchingArchetypes.Count * 2, TempJobAllocator.AllocationHandle);
foreach (var archID in _matchingArchetypes)
{

View File

@@ -1107,14 +1107,14 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -1248,18 +1248,18 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -1415,22 +1415,22 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -1608,26 +1608,26 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -1827,30 +1827,30 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -2072,34 +2072,34 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -2343,38 +2343,38 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)
@@ -2640,42 +2640,42 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices0 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices0 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices1 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices1 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices2 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices2 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices3 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices3 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices4 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices4 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices5 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices5 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices6 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices6 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var offsets7 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets7 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices7 = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets7 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets7 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices7 = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
// Iterate the Query's matching archetypes
foreach (var archID in _matchingArchetypes)

View File

@@ -137,15 +137,15 @@ public unsafe partial struct EntityQuery
}
// 1. Flatten the World
var chunks = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, JobScheduler.TempAllocatorHandle);
var chunkEntityCounts = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var entityOffsets = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var chunks = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkVersions = new UnsafeList<IntPtr>(128, TempJobAllocator.AllocationHandle);
var chunkEntityCounts = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var entityOffsets = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
<# for (var j = 0; j < i; j++){ #>
var offsets<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var bitsOffsets<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var versionIndices<#= j #> = new UnsafeList<int>(128, JobScheduler.TempAllocatorHandle);
var offsets<#= j #> = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var bitsOffsets<#= j #> = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
var versionIndices<#= j #> = new UnsafeList<int>(128, TempJobAllocator.AllocationHandle);
<# } #>
// Iterate the Query's matching archetypes

View File

@@ -307,7 +307,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->Barrier(groupCount, groups);
}
public void SetRenderTargets(ReadOnlySpan<Handle<Texture>> renderTargets, Handle<Texture> depthTarget)
public void SetRenderTargets(ReadOnlySpan<Handle<GPUTexture>> renderTargets, Handle<GPUTexture> depthTarget)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -360,7 +360,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->OMSetRenderTargets(rtvCount, pRtvHandles, FALSE, pDsvHandle);
}
public void ClearRenderTargetView(Handle<Texture> renderTarget, Color128 clearColor)
public void ClearRenderTargetView(Handle<GPUTexture> renderTarget, Color128 clearColor)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -385,7 +385,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->ClearRenderTargetView(cpuHandle, (float*)&clearColor, 0, null);
}
public void ClearDepthStencilView(Handle<Texture> depthStencil, bool inlcudeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0)
public void ClearDepthStencilView(Handle<GPUTexture> depthStencil, bool inlcudeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -631,7 +631,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->SetPipelineState(psor.Value);
}
public void SetConstantBufferView(uint slot, Handle<GraphicsBuffer> buffer)
public void SetConstantBufferView(uint slot, Handle<RHI.GPUBuffer> buffer)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -647,7 +647,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->SetGraphicsRootConstantBufferView(slot, resource.Get()->GetGPUVirtualAddress());
}
public void SetVertexBuffer(uint slot, Handle<GraphicsBuffer> buffer, ulong offset = 0)
public void SetVertexBuffer(uint slot, Handle<RHI.GPUBuffer> buffer, ulong offset = 0)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -677,7 +677,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
pNativeObject->IASetVertexBuffers(slot, 1, &vbView);
}
public void SetIndexBuffer(Handle<GraphicsBuffer> buffer, IndexType type, ulong offset = 0)
public void SetIndexBuffer(Handle<RHI.GPUBuffer> buffer, IndexType type, ulong offset = 0)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -817,7 +817,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
throw new NotImplementedException();
}
public void ExecuteIndirect(Handle<GraphicsBuffer> argumentBuffer, ulong argumentOffset, Handle<GraphicsBuffer> countBuffer, ulong countBufferOffset)
public void ExecuteIndirect(Handle<RHI.GPUBuffer> argumentBuffer, ulong argumentOffset, Handle<RHI.GPUBuffer> countBuffer, ulong countBufferOffset)
{
throw new NotImplementedException();
@@ -841,7 +841,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
}
public void UploadBuffer<T>(Handle<GraphicsBuffer> buffer, params ReadOnlySpan<T> data)
public void UploadBuffer<T>(Handle<RHI.GPUBuffer> buffer, params ReadOnlySpan<T> data)
where T : unmanaged
{
static void Map(T* pData, nuint size, ulong offset, SharedPtr<ID3D12Resource> resource)
@@ -891,7 +891,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
}
}
public void UploadTexture(Handle<Texture> texture, params ReadOnlySpan<SubResourceData> subresources)
public void UploadTexture(Handle<GPUTexture> texture, params ReadOnlySpan<SubResourceData> subresources)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -932,7 +932,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
d3d12Subresources);
}
public void CopyBuffer(Handle<GraphicsBuffer> dst, Handle<GraphicsBuffer> src, ulong dstOffset = 0, ulong srcOffset = 0, ulong numBytes = 0)
public void CopyBuffer(Handle<RHI.GPUBuffer> dst, Handle<RHI.GPUBuffer> src, ulong dstOffset = 0, ulong srcOffset = 0, ulong numBytes = 0)
{
AssertNotDisposed();
ThrowIfNotRecording();
@@ -991,7 +991,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object<ID3D12GraphicsCommandList
&& desc1.SampleDesc.Count == desc2.SampleDesc.Count;
}
public void CopyTexture(Handle<Texture> dst, TextureRegion? dstRegion, Handle<Texture> src, TextureRegion? srcRegion)
public void CopyTexture(Handle<GPUTexture> dst, TextureRegion? dstRegion, Handle<GPUTexture> src, TextureRegion? srcRegion)
{
AssertNotDisposed();
ThrowIfNotRecording();

View File

@@ -454,7 +454,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
private readonly D3D12PipelineLibrary _pipelineLibrary;
// TODO: We should use ring buffer pool in d3d12ma for upload buffer.
private readonly Handle<GraphicsBuffer> _uploadBatch;
private readonly Handle<RHI.GPUBuffer> _uploadBatch;
private ulong _uploadBatchOffset;
private bool _disposed;
@@ -600,7 +600,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
return TrackAllocation(alloc, barrierData, ResourceViewGroup.Invalid, default, name, false);
}
public Handle<Texture> CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default)
public Handle<GPUTexture> CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default)
{
Debug.Assert(!_disposed);
@@ -633,7 +633,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
#if DEBUG
ThrowIfFailed(hr);
#endif
return Handle<Texture>.Invalid;
return Handle<GPUTexture>.Invalid;
}
var isTemp = options.AllocationType == ResourceAllocationType.Temporary;
@@ -698,7 +698,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
return resource.AsTexture();
}
public Handle<Texture> CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default)
public Handle<GPUTexture> CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default)
{
Debug.Assert(!_disposed);
@@ -706,7 +706,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
return CreateTexture(in textureDesc, name, options);
}
public Handle<GraphicsBuffer> CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default)
public Handle<RHI.GPUBuffer> CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default)
{
Debug.Assert(!_disposed);
CheckBufferSize(desc.Size);
@@ -748,7 +748,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
#if DEBUG
ThrowIfFailed(hr);
#endif
return Handle<GraphicsBuffer>.Invalid;
return Handle<RHI.GPUBuffer>.Invalid;
}
var isTemp = options.AllocationType == ResourceAllocationType.Temporary;
@@ -808,7 +808,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator
return resource.AsGraphicsBuffer();
}
public Handle<GraphicsBuffer> CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset)
public Handle<RHI.GPUBuffer> CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset)
{
if (sizeInBytes <= _MAX_RESOURCE_SIZE_TO_FIT_IN_UPLOAD_BATCH && sizeInBytes + _uploadBatchOffset <= _UPLOAD_BATCH_SIZE)
{

View File

@@ -99,7 +99,6 @@ internal class D3D12ResourceDatabase : IResourceDatabase
private readonly D3D12DescriptorAllocator _descriptorAllocator;
// TODO: Change AOS to SOA?
private UnsafeSlotMap<ResourceRecord> _resources;
private UnsafeHashMap<SamplerDesc, Identifier<Sampler>> _samplers;
#if DEBUG || GHOST_EDITOR

View File

@@ -19,7 +19,7 @@ internal unsafe class DXGISwapChain : ISwapChain
private readonly D3D12RenderDevice _device;
private UniquePtr<IDXGISwapChain4> _swapChain;
private UnsafeArray<Handle<Texture>> _backBuffers;
private UnsafeArray<Handle<GPUTexture>> _backBuffers;
private readonly object? _compositionSurface;
@@ -117,7 +117,7 @@ internal unsafe class DXGISwapChain : ISwapChain
var pSfwapChain = CreateSwapChain(device, desc, bufferCount);
_swapChain.Attach(pSfwapChain);
_backBuffers = new UnsafeArray<Handle<Texture>>((int)bufferCount, Allocator.Persistent);
_backBuffers = new UnsafeArray<Handle<GPUTexture>>((int)bufferCount, Allocator.Persistent);
Width = desc.Width;
Height = desc.Height;
@@ -166,14 +166,14 @@ internal unsafe class DXGISwapChain : ISwapChain
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Handle<Texture> GetCurrentBackBuffer()
public Handle<GPUTexture> GetCurrentBackBuffer()
{
Debug.Assert(!_disposed);
return _backBuffers[_swapChain.Get()->GetCurrentBackBufferIndex()];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ReadOnlySpan<Handle<Texture>> GetBackBuffers()
public ReadOnlySpan<Handle<GPUTexture>> GetBackBuffers()
{
Debug.Assert(!_disposed);
return _backBuffers.AsSpan();

View File

@@ -292,12 +292,12 @@ public struct RenderDesc
}
// The "Target" (Where to write pixels)
public Handle<Texture> Target
public Handle<GPUTexture> Target
{
get; set;
}
public Handle<Texture> DepthTarget
public Handle<GPUTexture> DepthTarget
{
get; set;
}
@@ -377,7 +377,7 @@ public struct SubResourceData
public struct PassRenderTargetDesc
{
public Handle<Texture> Texture
public Handle<GPUTexture> Texture
{
get; set;
}
@@ -407,7 +407,7 @@ public struct PassRenderTargetDesc
public struct PassDepthStencilDesc
{
public Handle<Texture> Texture
public Handle<GPUTexture> Texture
{
get; set;
}

View File

@@ -63,14 +63,14 @@ public interface ICommandBuffer : IDisposable
/// <param name="renderTargets">A read-only span of handles to textures that will be used as render targets.
/// The order of handles determines the order in which render targets are bound.</param>
/// <param name="depthTarget">A handle to the texture to be used as the depth Target. Specify a invalid handle if no depth Target is required.</param>
void SetRenderTargets(ReadOnlySpan<Handle<Texture>> renderTargets, Handle<Texture> depthTarget);
void SetRenderTargets(ReadOnlySpan<Handle<GPUTexture>> renderTargets, Handle<GPUTexture> depthTarget);
/// <summary>
/// Clears the specified render target to a given color.
/// </summary>
/// <param name="renderTarget">A handle to the render target texture to be cleared. Must reference a valid render target.</param>
/// <param name="clearColor">The color value used to clear the render target. Specifies the RGBA components to fill the target.</param>
void ClearRenderTargetView(Handle<Texture> renderTarget, Color128 clearColor);
void ClearRenderTargetView(Handle<GPUTexture> renderTarget, Color128 clearColor);
/// <summary>
/// Clears the specified depth-stencil view by resetting its depth and/or stencil values.
@@ -80,7 +80,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="includeStencil">A value indicating whether the stencil component should be cleared.</param>
/// <param name="clearDepth">The value to which the depth buffer will be set. Typically ranges from 0.0f (nearest) to 1.0f (farthest).</param>
/// <param name="clearStencil">The value to which the stencil buffer will be set. Must be a valid stencil value supported by the format.</param>
void ClearDepthStencilView(Handle<Texture> depthStencil, bool inlcludeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0);
void ClearDepthStencilView(Handle<GPUTexture> depthStencil, bool inlcludeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0);
/// <summary>
/// Begins a render pass with the specified render Target
@@ -112,7 +112,7 @@ public interface ICommandBuffer : IDisposable
/// </summary>
/// <param name="slot">The zero-based index of the slot to bind the constant buffer view to.</param>
/// <param name="buffer">A graphics buffer to use as the constant buffer view.</param>
void SetConstantBufferView(uint slot, Handle<GraphicsBuffer> buffer);
void SetConstantBufferView(uint slot, Handle<GPUBuffer> buffer);
/// <summary>
/// Binds a vertex buffer to the specified slot for subsequent draw calls.
@@ -120,7 +120,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="slot">The vertex buffer slot to bind to.</param>
/// <param name="buffer">The handle to the graphics buffer containing vertex data.</param>
/// <param name="offset">The Offset in bytes from the start of the buffer.</param>
void SetVertexBuffer(uint slot, Handle<GraphicsBuffer> buffer, ulong offset = 0);
void SetVertexBuffer(uint slot, Handle<GPUBuffer> buffer, ulong offset = 0);
/// <summary>
/// Binds an index buffer for indexed drawing.
@@ -128,7 +128,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="buffer">The handle to the graphics buffer containing index data.</param>
/// <param name="type">The space of indices (e.g., 16-bit or 32-bit).</param>
/// <param name="offset">The Offset in bytes from the start of the buffer.</param>
void SetIndexBuffer(Handle<GraphicsBuffer> buffer, IndexType type, ulong offset = 0);
void SetIndexBuffer(Handle<GPUBuffer> buffer, IndexType type, ulong offset = 0);
/// <summary>
/// Sets the primitive topology to be used for subsequent drawing operations.
@@ -192,7 +192,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="buffer">A handle to the buffer that will receive the uploaded data.</param>
/// <param name="data">A read-only span containing the data to upload to the buffer. The span must contain elements of space
/// <typeparamref name="T"/>.</param>
void UploadBuffer<T>(Handle<GraphicsBuffer> buffer, params ReadOnlySpan<T> data)
void UploadBuffer<T>(Handle<GPUBuffer> buffer, params ReadOnlySpan<T> data)
where T : unmanaged;
/// <summary>
@@ -201,7 +201,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="texture">The texture resource to which the subresource data will be uploaded. Must be a valid, initialized texture handle.</param>
/// <param name="subresources">A reference to the structure containing the subresource data to upload. The data must match the Format and layout expected by the texture.</param>
/// Must be greater than zero and not exceed the remaining subresources in the texture.</param>
void UploadTexture(Handle<Texture> texture, params ReadOnlySpan<SubResourceData> subresources);
void UploadTexture(Handle<GPUTexture> texture, params ReadOnlySpan<SubResourceData> subresources);
/// <summary>
/// Copies a specified number of bytes from the source graphics buffer to the destination graphics buffer.
@@ -211,7 +211,7 @@ public interface ICommandBuffer : IDisposable
/// <param name="destOffset">The byte Offset in the destination buffer at which to begin writing. Must be zero or greater.</param>
/// <param name="srcOffset">The byte Offset in the source buffer at which to begin reading. Must be zero or greater.</param>
/// <param name="numBytes">The number of bytes to copy. If zero, copies the remaining bytes from the source buffer starting at <paramref name="srcOffset"/>.</param>
void CopyBuffer(Handle<GraphicsBuffer> dest, Handle<GraphicsBuffer> src, ulong destOffset = 0, ulong srcOffset = 0, ulong numBytes = 0);
void CopyBuffer(Handle<GPUBuffer> dest, Handle<GPUBuffer> src, ulong destOffset = 0, ulong srcOffset = 0, ulong numBytes = 0);
/// <summary>
/// Copies a region of a source texture to a destination texture. The source and destination regions can be specified to copy a subset of the textures, or the entire textures if the regions are null.
@@ -220,5 +220,5 @@ public interface ICommandBuffer : IDisposable
/// <param name="dstRegion">The region of the destination texture to copy to. If null, the entire texture will be used.</param>
/// <param name="src">The handle to the source texture from which data will be read.</param>
/// <param name="srcRegion">The region of the source texture to copy from. If null, the entire texture will be used.</param>
void CopyTexture(Handle<Texture> dst, TextureRegion? dstRegion, Handle<Texture> src, TextureRegion? srcRegion);
void CopyTexture(Handle<GPUTexture> dst, TextureRegion? dstRegion, Handle<GPUTexture> src, TextureRegion? srcRegion);
}

View File

@@ -18,7 +18,7 @@ public interface IRenderOutput
/// Gets a handle to the current render target texture.
/// </summary>
/// <returns>A handle to the texture that is currently set as the render target.</returns>
Handle<Texture> GetRenderTarget();
Handle<GPUTexture> GetRenderTarget();
/// <summary>
/// Begins a rendering operation using the specified command buffer. Typically this will include resource barriers,

View File

@@ -98,7 +98,7 @@ public interface IResourceAllocator : IDisposable
/// <param name="name">Debug name of the resource</param>
/// <param name="options">Additional options of the resource allocation</param>
/// <returns>An <see cref="Handle{Texture}"/> point to the resource</returns>
Handle<Texture> CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default);
Handle<GPUTexture> CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default);
/// <summary>
/// Creates a render Target for off-screen rendering
@@ -107,7 +107,7 @@ public interface IResourceAllocator : IDisposable
/// <param name="name">Debug name of the resource</param>
/// <param name="options">Additional options of the resource allocation</param>
/// <returns>An <see cref="Handle{Texture}"/> point to the resource</returns>
Handle<Texture> CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default);
Handle<GPUTexture> CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default);
/// <summary>
/// Creates a buffer resource
@@ -116,7 +116,7 @@ public interface IResourceAllocator : IDisposable
/// <param name="name">Debug name of the resource</param>
/// <param name="options">Additional options of the resource allocation</param>
/// <returns>An <see cref="Handle{GraphicsBuffer}"/> point to the resource</returns>
Handle<GraphicsBuffer> CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default);
Handle<GPUBuffer> CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default);
/// <summary>
/// Creates a temporary upload buffer of the specified size in bytes.
@@ -127,7 +127,7 @@ public interface IResourceAllocator : IDisposable
/// <param name="sizeInBytes">The size of the upload buffer to create, in bytes.</param>
/// <param name="offset">The offset within the upload buffer where the allocation begins.</param>
/// <returns>An <see cref="Handle{GraphicsBuffer}"/> pointing to the created upload buffer.</returns>
Handle<GraphicsBuffer> CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset);
Handle<GPUBuffer> CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset);
/// <summary>
/// Creates a new sampler object using the specified sampler description.

View File

@@ -43,13 +43,13 @@ public interface ISwapChain : IDisposable
/// Gets the current back buffer texture
/// </summary>
/// <returns>Current back buffer texture</returns>
Handle<Texture> GetCurrentBackBuffer();
Handle<GPUTexture> GetCurrentBackBuffer();
/// <summary>
/// Gets all back buffer textures
/// </summary>
/// <returns>AlowBufferAndTexture back buffer textures</returns>
ReadOnlySpan<Handle<Texture>> GetBackBuffers();
ReadOnlySpan<Handle<GPUTexture>> GetBackBuffers();
/// <summary>
/// Presents the rendered frame

View File

@@ -3,30 +3,30 @@ using Ghost.Core;
namespace Ghost.Graphics.RHI;
public readonly struct GPUResource;
public readonly struct Texture;
public readonly struct GraphicsBuffer;
public readonly struct GPUTexture;
public readonly struct GPUBuffer;
public readonly struct Sampler;
public static class ResourceHandleExtensions
{
public static Handle<GPUResource> AsResource(this Handle<Texture> texture)
public static Handle<GPUResource> AsResource(this Handle<GPUTexture> texture)
{
return new Handle<GPUResource>(texture.ID, texture.Generation);
}
public static Handle<GPUResource> AsResource(this Handle<GraphicsBuffer> buffer)
public static Handle<GPUResource> AsResource(this Handle<GPUBuffer> buffer)
{
return new Handle<GPUResource>(buffer.ID, buffer.Generation);
}
public static Handle<Texture> AsTexture(this Handle<GPUResource> resource)
public static Handle<GPUTexture> AsTexture(this Handle<GPUResource> resource)
{
return new Handle<Texture>(resource.ID, resource.Generation);
return new Handle<GPUTexture>(resource.ID, resource.Generation);
}
public static Handle<GraphicsBuffer> AsGraphicsBuffer(this Handle<GPUResource> resource)
public static Handle<GPUBuffer> AsGraphicsBuffer(this Handle<GPUResource> resource)
{
return new Handle<GraphicsBuffer>(resource.ID, resource.Generation);
return new Handle<GPUBuffer>(resource.ID, resource.Generation);
}
}

View File

@@ -11,16 +11,16 @@ namespace Ghost.Graphics.Core;
internal struct CBufferCache : IResourceReleasable
{
private UnsafeArray<byte> _cpuData;
private Handle<GraphicsBuffer> _gpuResource;
private Handle<RHI.GPUBuffer> _gpuResource;
private uint _size;
public readonly UnsafeArray<byte> CpuData => _cpuData;
public readonly Handle<GraphicsBuffer> GpuResource => _gpuResource;
public readonly Handle<RHI.GPUBuffer> GpuResource => _gpuResource;
public readonly uint Size => _size;
public readonly bool IsCreated => _size != 0 && _gpuResource.IsValid && _cpuData.IsCreated;
public CBufferCache(Handle<GraphicsBuffer> buffer, uint bufferSize)
public CBufferCache(Handle<RHI.GPUBuffer> buffer, uint bufferSize)
{
_size = bufferSize;
_cpuData = new UnsafeArray<byte>((int)bufferSize, Allocator.Persistent);
@@ -37,7 +37,7 @@ internal struct CBufferCache : IResourceReleasable
_cpuData.Dispose();
database.ReleaseResource(_gpuResource.AsResource());
_gpuResource = Handle<GraphicsBuffer>.Invalid;
_gpuResource = Handle<RHI.GPUBuffer>.Invalid;
_size = 0;
}
}

View File

@@ -138,7 +138,7 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the vertex buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> VertexBuffer
public Handle<RHI.GPUBuffer> VertexBuffer
{
get; internal set;
}
@@ -146,7 +146,7 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the index buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> IndexBuffer
public Handle<RHI.GPUBuffer> IndexBuffer
{
get; internal set;
}
@@ -154,7 +154,7 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the meshlet buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> MeshLetBuffer
public Handle<RHI.GPUBuffer> MeshLetBuffer
{
get; internal set;
}
@@ -162,7 +162,7 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the meshlet vertices buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> MeshletVerticesBuffer
public Handle<RHI.GPUBuffer> MeshletVerticesBuffer
{
get; internal set;
}
@@ -170,7 +170,7 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the meshlet triangles buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> MeshletTrianglesBuffer
public Handle<RHI.GPUBuffer> MeshletTrianglesBuffer
{
get; internal set;
}
@@ -178,12 +178,12 @@ public struct Mesh : IResourceReleasable
/// <summary>
/// Gets the handle to the mesh data buffer on the GPU.
/// </summary>
public Handle<GraphicsBuffer> ObjectDataBuffer
public Handle<RHI.GPUBuffer> ObjectDataBuffer
{
get; internal set;
}
internal Mesh(ReadOnlySpan<Vertex> vertices, ReadOnlySpan<uint> indices, Handle<GraphicsBuffer> vertexBuffer, Handle<GraphicsBuffer> indexBuffer)
internal Mesh(ReadOnlySpan<Vertex> vertices, ReadOnlySpan<uint> indices, Handle<RHI.GPUBuffer> vertexBuffer, Handle<RHI.GPUBuffer> indexBuffer)
{
Vertices = new UnsafeList<Vertex>(vertices.Length, Allocator.Persistent);
Indices = new UnsafeList<uint>(indices.Length, Allocator.Persistent);

View File

@@ -25,7 +25,7 @@ internal class SwapChainRenderOutput : IRenderOutput
Scissor = new ScissorRectDesc { Right = swapChain.Width, Bottom = swapChain.Height };
}
public Handle<Texture> GetRenderTarget()
public Handle<GPUTexture> GetRenderTarget()
{
return _swapChain.GetCurrentBackBuffer();
}
@@ -58,7 +58,7 @@ internal class SwapChainRenderOutput : IRenderOutput
internal class TextureRenderOutput : IRenderOutput
{
private readonly Handle<Texture> _texture;
private readonly Handle<GPUTexture> _texture;
public ViewportDesc Viewport
{
@@ -70,12 +70,12 @@ internal class TextureRenderOutput : IRenderOutput
get; set;
}
public TextureRenderOutput(Handle<Texture> texture)
public TextureRenderOutput(Handle<GPUTexture> texture)
{
_texture = texture;
}
public Handle<Texture> GetRenderTarget()
public Handle<GPUTexture> GetRenderTarget()
{
return _texture;
}

View File

@@ -183,8 +183,8 @@ public unsafe struct RenderRequest: IDisposable
public RenderView view;
public int swapChainIndex;
public Handle<Texture> colorTarget;
public Handle<Texture> depthTarget;
public Handle<GPUTexture> colorTarget;
public Handle<GPUTexture> depthTarget;
public RenderList opaqueRenderList;
public RenderList transparentRenderList;

View File

@@ -242,7 +242,7 @@ public readonly unsafe ref struct RenderingContext
TransitionBarrier(bufferHandle, false, BarrierLayout.Undefined, BarrierAccess.ShaderResource, BarrierSync.PixelShading | BarrierSync.NonPixelShading);
}
public Handle<Texture> CreateTexture<T>(ref readonly TextureDesc desc, ReadOnlySpan<T> data, string name)
public Handle<GPUTexture> CreateTexture<T>(ref readonly TextureDesc desc, ReadOnlySpan<T> data, string name)
where T : unmanaged
{
var handle = ResourceAllocator.CreateTexture(in desc, name);
@@ -251,7 +251,7 @@ public readonly unsafe ref struct RenderingContext
return handle;
}
public void UploadTexture<T>(Handle<Texture> texture, ReadOnlySpan<T> data)
public void UploadTexture<T>(Handle<GPUTexture> texture, ReadOnlySpan<T> data)
where T : unmanaged
{
var desc = ResourceDatabase.GetResourceDescription(texture.AsResource()).GetValueOrThrow();

View File

@@ -105,7 +105,7 @@ public sealed class RenderGraph : IDisposable
/// </summary>
/// <param name="texture">The external texture handle.</param>
/// <returns>The identifier of the imported render graph texture. Invalid if import fails.</returns>
public Identifier<RGTexture> ImportTexture(Handle<Texture> texture, string name,
public Identifier<RGTexture> ImportTexture(Handle<GPUTexture> texture, string name,
Color128 clearColor = default, float clearDepth = 1.0f, byte clearStencil = 0,
bool clearAtFirstUse = true, bool discardAtLastUse = true)
{
@@ -125,7 +125,7 @@ public sealed class RenderGraph : IDisposable
/// </summary>
/// <param name="buffer">The external buffer handle.</param>
/// <returns>The identifier of the imported render graph buffer. Invalid if import fails.</returns>
public Identifier<RGBuffer> ImportBuffer(Handle<GraphicsBuffer> buffer, string name)
public Identifier<RGBuffer> ImportBuffer(Handle<RHI.GPUBuffer> buffer, string name)
{
var r = _resourceDatabase.GetResourceDescription(buffer.AsResource());
if (r.IsFailure)

View File

@@ -79,6 +79,20 @@ public interface IRenderGraphBuilder : IDisposable
/// <param name="hint">Optional hint about how the buffer will be used.</param>
/// <returns>An identifier for the buffer.</returns>
Identifier<RGBuffer> UseBuffer(Identifier<RGBuffer> buffer, AccessFlags accessMode);
/// <summary>
/// Extracts the actual texture resource associated with the given identifier for use in outside of the render graph execution context.
/// </summary>
/// <param name="texture">The identifier of the texture to be extracted.</param>
/// <returns>A handle to the actual texture resource that can be used outside of the render graph execution context.</returns>
Handle<GPUTexture> ExtractTexture(Identifier<RGTexture> texture);
/// <summary>
/// Extracts the actual buffer resource associated with the given identifier for use in outside of the render graph execution context.
/// </summary>
/// <param name="buffer">The identifier of the buffer to be extracted.</param>
/// <returns>A handle to the actual buffer resource that can be used outside of the render graph execution context.</returns>
Handle<GPUBuffer> ExtractBuffer(Identifier<RGBuffer> buffer);
}
public interface IRasterRenderGraphBuilder : IRenderGraphBuilder
@@ -254,6 +268,17 @@ internal class RenderGraphBuilder : IRasterRenderGraphBuilder, IComputeRenderGra
return UseResource(buffer.AsResource(), flags, RenderGraphResourceType.Buffer).AsBuffer();
}
// TODO: Implement ExtractTexture and ExtractBuffer to allow users to get the actual GPU resources for use outside of the render graph execution context.
public Handle<GPUTexture> ExtractTexture(Identifier<RGTexture> texture)
{
throw new NotImplementedException();
}
public Handle<GPUBuffer> ExtractBuffer(Identifier<RGBuffer> buffer)
{
throw new NotImplementedException();
}
public Identifier<RGTexture> UseRandomAccessTexture(Identifier<RGTexture> texture)
{
ThrowIfDisposed();

View File

@@ -11,11 +11,11 @@ public interface IRenderGraphContext
IResourceDatabase ResourceDatabase { get; }
Handle<GPUResource> GetActualResource(Identifier<RGResource> resource);
Handle<Texture> GetActualTexture(Identifier<RGTexture> texture);
Handle<GraphicsBuffer> GetActualBuffer(Identifier<RGBuffer> buffer);
Handle<GPUTexture> GetActualTexture(Identifier<RGTexture> texture);
Handle<RHI.GPUBuffer> GetActualBuffer(Identifier<RGBuffer> buffer);
Handle<Texture> GetHistoryTexture(ReadOnlySpan<Identifier<RGTexture>> texture, int historyOffset);
Handle<GraphicsBuffer> GetHistoryBuffer(ReadOnlySpan<Identifier<RGBuffer>> buffer, int historyOffset);
Handle<GPUTexture> GetHistoryTexture(ReadOnlySpan<Identifier<RGTexture>> texture, int historyOffset);
Handle<RHI.GPUBuffer> GetHistoryBuffer(ReadOnlySpan<Identifier<RGBuffer>> buffer, int historyOffset);
ICommandBuffer GetCommandBufferUnsafe();
}
@@ -60,8 +60,8 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
private TextureFormat _dsvFormat;
private int _rtvCount;
private Handle<GraphicsBuffer> _activePerMaterialData;
private Handle<GraphicsBuffer> _activePerMeshData;
private Handle<RHI.GPUBuffer> _activePerMaterialData;
private Handle<RHI.GPUBuffer> _activePerMeshData;
private int _activeMeshIndexCount;
private uint _activeFrameBuffer;
@@ -115,21 +115,21 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
return _resources.GetResource(resource).backingResource;
}
public Handle<Texture> GetActualTexture(Identifier<RGTexture> texture)
public Handle<GPUTexture> GetActualTexture(Identifier<RGTexture> texture)
{
return _resources.GetResource(texture.AsResource()).backingResource.AsTexture();
}
public Handle<GraphicsBuffer> GetActualBuffer(Identifier<RGBuffer> buffer)
public Handle<RHI.GPUBuffer> GetActualBuffer(Identifier<RGBuffer> buffer)
{
return _resources.GetResource(buffer.AsResource()).backingResource.AsGraphicsBuffer();
}
public Handle<Texture> GetHistoryTexture(ReadOnlySpan<Identifier<RGTexture>> textures, int historyOffset)
public Handle<GPUTexture> GetHistoryTexture(ReadOnlySpan<Identifier<RGTexture>> textures, int historyOffset)
{
if (historyOffset < 0 || historyOffset >= textures.Length)
{
return Handle<Texture>.Invalid;
return Handle<GPUTexture>.Invalid;
}
var index = (int)(_frameIndex % textures.Length) - historyOffset;
@@ -141,11 +141,11 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
return GetActualTexture(textures[index]);
}
public Handle<GraphicsBuffer> GetHistoryBuffer(ReadOnlySpan<Identifier<RGBuffer>> buffers, int historyOffset)
public Handle<RHI.GPUBuffer> GetHistoryBuffer(ReadOnlySpan<Identifier<RGBuffer>> buffers, int historyOffset)
{
if (historyOffset < 0 || historyOffset >= buffers.Length)
{
return Handle<GraphicsBuffer>.Invalid;
return Handle<RHI.GPUBuffer>.Invalid;
}
var index = (int)(_frameIndex % buffers.Length) - historyOffset;
@@ -172,7 +172,7 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
var r = _resourceManager.GetMaterialReference(material);
if (r.IsFailure)
{
_activePerMaterialData = Handle<GraphicsBuffer>.Invalid;
_activePerMaterialData = Handle<RHI.GPUBuffer>.Invalid;
return;
}
@@ -185,7 +185,7 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
var shaderResult = _resourceManager.GetShaderReference(material.Shader);
if (shaderResult.IsFailure)
{
_activePerMaterialData = Handle<GraphicsBuffer>.Invalid;
_activePerMaterialData = Handle<RHI.GPUBuffer>.Invalid;
return;
}
@@ -230,7 +230,7 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext
var r = _resourceManager.GetMeshReference(mesh);
if (r.IsFailure)
{
_activePerMeshData = Handle<GraphicsBuffer>.Invalid;
_activePerMeshData = Handle<RHI.GPUBuffer>.Invalid;
_activeMeshIndexCount = 0;
return;
}

View File

@@ -134,7 +134,7 @@ internal sealed class RenderGraphExecutor
{
Texture = nativePass.hasDepthAttachment
? _resources.GetResource(nativePass.depthAttachment.texture).backingResource.AsTexture()
: Handle<Texture>.Invalid,
: Handle<GPUTexture>.Invalid,
ClearDepth = nativePass.depthAttachment.clearDepth,
ClearStencil = nativePass.depthAttachment.clearStencil,
DepthLoadOp = nativePass.hasDepthAttachment

View File

@@ -163,7 +163,7 @@ internal sealed class RenderGraphResourceRegistry
_resources.Clear();
}
public Identifier<RGTexture> ImportTexture(ref readonly TextureDesc desc, Handle<Texture> texture, string name,
public Identifier<RGTexture> ImportTexture(ref readonly TextureDesc desc, Handle<GPUTexture> texture, string name,
Color128 clearColor, float clearDepth, byte clearStencil,
bool clearAtFirstUse, bool discardAtLastUse)
{
@@ -211,7 +211,7 @@ internal sealed class RenderGraphResourceRegistry
return new Identifier<RGTexture>(resource.index);
}
public Identifier<RGBuffer> ImportBuffer(ref readonly BufferDesc desc, Handle<GraphicsBuffer> buffer, string name)
public Identifier<RGBuffer> ImportBuffer(ref readonly BufferDesc desc, Handle<RHI.GPUBuffer> buffer, string name)
{
var resource = _pool.Rent<RenderGraphResource>();
resource.name = name;

View File

@@ -1,7 +1,6 @@
using Ghost.MeshOptimizer;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
using Misaki.HighPerformance.LowLevel.Utilities;
using Misaki.HighPerformance.Mathematics;
using System.Diagnostics;
@@ -19,9 +18,9 @@ internal struct Cluster : IDisposable
public void Dispose()
{
if (indices.IsCreated) indices.Dispose();
if (uniqueVertices.IsCreated) uniqueVertices.Dispose();
if (localIndices.IsCreated) localIndices.Dispose();
indices.Dispose();
uniqueVertices.Dispose();
localIndices.Dispose();
}
}
@@ -267,7 +266,7 @@ public static unsafe class MeshletUtility
for (nuint j = 0; j < meshlet.triangle_count * 3; j++)
{
byte localIdx = pMeshletTriangles[meshlet.triangle_offset + j];
var localIdx = pMeshletTriangles[meshlet.triangle_offset + j];
cluster.localIndices.Add(localIdx);
cluster.indices.Add(pMeshletVertices[meshlet.vertex_offset + localIdx]);
}

View File

@@ -109,8 +109,6 @@ shader "MyShader/Standard"
// float4 blendedColor = (color1 + color2 + color3 + color4) * 0.25f;
// return perMaterialData.color * blendedColor + input.color;
// TODO: Randome color on meshlet.
// return 1.0;
uint hash = PCGHash(input.meshletID);
float r = float((hash & 0xFF0000u) >> 16) / 255.0;

View File

@@ -126,7 +126,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline
continue; // Nothing to render
}
Handle<Texture> rt;
Handle<GPUTexture> rt;
if (request.swapChainIndex < 0)
{
rt = request.colorTarget;

View File

@@ -81,7 +81,7 @@ public sealed partial class GraphicsTestWindow : Window
_world.EntityManager.SetComponent(cameraEntity, new Camera
{
swapChainIndex = 0,
depthTarget = Handle<Texture>.Invalid,
depthTarget = Handle<GPUTexture>.Invalid,
nearClipPlane = 0.1f,
farClipPlane = 1000.0f,
focalLength = 50.0f,

View File

@@ -1,9 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Ghost.MeshOptimizer;
internal class ClusterLod
{
}