From 89e6c68f2a5d1b5a0e0e545406669df9c2923c76 Mon Sep 17 00:00:00 2001 From: Misaki Date: Mon, 30 Mar 2026 21:27:16 +0900 Subject: [PATCH] feat(rhi)!: refactor resource handles to GPUTexture/GPUBuffer Refactored all graphics resource handles to use Handle and Handle instead of Handle and Handle. 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 and Handle are replaced with Handle and Handle. This affects all APIs and resource management code. Callers must update their code to use the new handle types. --- .../AssetHandler/TextureAsset.cs | 8 +- src/Runtime/Ghost.Core/Ghost.Core.csproj | 8 +- src/Runtime/Ghost.Core/TemJobAllocator.cs | 164 ++++++++++ src/Runtime/Ghost.Engine/Components/Camera.cs | 4 +- .../Ghost.Entities/EntityQuery.JobChunk.cs | 3 +- .../Templates/EntityQuery.JobEntity.gen.cs | 280 +++++++++--------- .../Templates/EntityQuery.JobEntity.tt | 14 +- .../D3D12CommandBuffer.cs | 22 +- .../D3D12ResourceAllocator.cs | 14 +- .../D3D12ResourceDatabase.cs | 1 - .../Ghost.Graphics.D3D12/DXGISwapChain.cs | 8 +- src/Runtime/Ghost.Graphics.RHI/Common.cs | 8 +- .../Ghost.Graphics.RHI/ICommandBuffer.cs | 20 +- .../Ghost.Graphics.RHI/IRenderOutput.cs | 2 +- .../Ghost.Graphics.RHI/IResourceAllocator.cs | 8 +- src/Runtime/Ghost.Graphics.RHI/ISwapChain.cs | 6 +- .../Ghost.Graphics.RHI/ResourceHandle.cs | 16 +- src/Runtime/Ghost.Graphics/Core/Material.cs | 8 +- src/Runtime/Ghost.Graphics/Core/Mesh.cs | 14 +- .../Ghost.Graphics/Core/RenderOutput.cs | 8 +- .../Ghost.Graphics/Core/RenderRequest.cs | 4 +- .../Ghost.Graphics/Core/RenderingContext.cs | 4 +- .../RenderGraphModule/RenderGraph.cs | 4 +- .../RenderGraphModule/RenderGraphBuilder.cs | 25 ++ .../RenderGraphModule/RenderGraphContext.cs | 30 +- .../RenderGraphModule/RenderGraphExecutor.cs | 2 +- .../RenderGraphResourcePool.cs | 4 +- .../Utilities/MeshletUtility.cs | 9 +- src/Runtime/Ghost.Graphics/test.gshdr | 6 +- .../RenderPasses/TestRenderPipeline.cs | 2 +- .../Windows/GraphicsTestWindow.xaml.cs | 2 +- .../Ghost.MeshOptimizer/ClusterLod.cs | 9 - 32 files changed, 447 insertions(+), 270 deletions(-) create mode 100644 src/Runtime/Ghost.Core/TemJobAllocator.cs delete mode 100644 src/ThridParty/Ghost.MeshOptimizer/ClusterLod.cs diff --git a/src/Editor/Ghost.Editor.Core/AssetHandler/TextureAsset.cs b/src/Editor/Ghost.Editor.Core/AssetHandler/TextureAsset.cs index 0d7276f..ee5ccf7 100644 --- a/src/Editor/Ghost.Editor.Core/AssetHandler/TextureAsset.cs +++ b/src/Editor/Ghost.Editor.Core/AssetHandler/TextureAsset.cs @@ -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; + private readonly Handle _texture; public override Guid TypeID => s_typeGuid; - public Handle Texture => _texture; + public Handle Texture => _texture; - public TextureAsset(Guid id, Guid[] dependencies, IAssetSettings? settings, Handle texture) + public TextureAsset(Guid id, Guid[] dependencies, IAssetSettings? settings, Handle texture) : base(id, dependencies, settings) { _texture = texture; @@ -394,4 +394,4 @@ internal class TextureAssetHandler : IImportableAssetHandler { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/src/Runtime/Ghost.Core/Ghost.Core.csproj b/src/Runtime/Ghost.Core/Ghost.Core.csproj index 06b3588..7cbe6bf 100644 --- a/src/Runtime/Ghost.Core/Ghost.Core.csproj +++ b/src/Runtime/Ghost.Core/Ghost.Core.csproj @@ -9,7 +9,7 @@ True - $(DefineConstants);ENABLE_DEBUG_LAYER + $(DefineConstants);MHP_ENABLE_SAFETY_CHECKS True @@ -19,9 +19,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Runtime/Ghost.Core/TemJobAllocator.cs b/src/Runtime/Ghost.Core/TemJobAllocator.cs new file mode 100644 index 0000000..58a3371 --- /dev/null +++ b/src/Runtime/Ghost.Core/TemJobAllocator.cs @@ -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; + } +} \ No newline at end of file diff --git a/src/Runtime/Ghost.Engine/Components/Camera.cs b/src/Runtime/Ghost.Engine/Components/Camera.cs index eb159b2..d09d100 100644 --- a/src/Runtime/Ghost.Engine/Components/Camera.cs +++ b/src/Runtime/Ghost.Engine/Components/Camera.cs @@ -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 colorTarget; - public Handle depthTarget; + public Handle colorTarget; + public Handle 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. diff --git a/src/Runtime/Ghost.Entities/EntityQuery.JobChunk.cs b/src/Runtime/Ghost.Entities/EntityQuery.JobChunk.cs index 2d5305e..333e5a7 100644 --- a/src/Runtime/Ghost.Entities/EntityQuery.JobChunk.cs +++ b/src/Runtime/Ghost.Entities/EntityQuery.JobChunk.cs @@ -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(_matchingArchetypes.Count * 2, JobScheduler.TempAllocatorHandle); + var chunkInfos = new UnsafeList(_matchingArchetypes.Count * 2, TempJobAllocator.AllocationHandle); foreach (var archID in _matchingArchetypes) { diff --git a/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.gen.cs b/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.gen.cs index 9897385..5fd2cae 100644 --- a/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.gen.cs +++ b/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.gen.cs @@ -1107,14 +1107,14 @@ public unsafe partial struct EntityQuery } // 1. Flatten the World - var chunks = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices3 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices4 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices5 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets6 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets6 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices6 = new UnsafeList(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(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices0 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices0 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices1 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices1 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices2 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices2 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices3 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices3 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices4 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices4 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices5 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices5 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices6 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets6 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets6 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices6 = new UnsafeList(128, TempJobAllocator.AllocationHandle); - var offsets7 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets7 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices7 = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets7 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets7 = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices7 = new UnsafeList(128, TempJobAllocator.AllocationHandle); // Iterate the Query's matching archetypes foreach (var archID in _matchingArchetypes) diff --git a/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.tt b/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.tt index 67370e3..3819dbc 100644 --- a/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.tt +++ b/src/Runtime/Ghost.Entities/Templates/EntityQuery.JobEntity.tt @@ -137,15 +137,15 @@ public unsafe partial struct EntityQuery } // 1. Flatten the World - var chunks = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkVersions = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var chunkEntityCounts = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var entityOffsets = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var chunks = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkVersions = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var chunkEntityCounts = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var entityOffsets = new UnsafeList(128, TempJobAllocator.AllocationHandle); <# for (var j = 0; j < i; j++){ #> - var offsets<#= j #> = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var bitsOffsets<#= j #> = new UnsafeList(128, JobScheduler.TempAllocatorHandle); - var versionIndices<#= j #> = new UnsafeList(128, JobScheduler.TempAllocatorHandle); + var offsets<#= j #> = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var bitsOffsets<#= j #> = new UnsafeList(128, TempJobAllocator.AllocationHandle); + var versionIndices<#= j #> = new UnsafeList(128, TempJobAllocator.AllocationHandle); <# } #> // Iterate the Query's matching archetypes diff --git a/src/Runtime/Ghost.Graphics.D3D12/D3D12CommandBuffer.cs b/src/Runtime/Ghost.Graphics.D3D12/D3D12CommandBuffer.cs index 63d23f8..04b93ed 100644 --- a/src/Runtime/Ghost.Graphics.D3D12/D3D12CommandBuffer.cs +++ b/src/Runtime/Ghost.Graphics.D3D12/D3D12CommandBuffer.cs @@ -307,7 +307,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectBarrier(groupCount, groups); } - public void SetRenderTargets(ReadOnlySpan> renderTargets, Handle depthTarget) + public void SetRenderTargets(ReadOnlySpan> renderTargets, Handle depthTarget) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -360,7 +360,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectOMSetRenderTargets(rtvCount, pRtvHandles, FALSE, pDsvHandle); } - public void ClearRenderTargetView(Handle renderTarget, Color128 clearColor) + public void ClearRenderTargetView(Handle renderTarget, Color128 clearColor) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -385,7 +385,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectClearRenderTargetView(cpuHandle, (float*)&clearColor, 0, null); } - public void ClearDepthStencilView(Handle depthStencil, bool inlcudeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0) + public void ClearDepthStencilView(Handle depthStencil, bool inlcudeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -631,7 +631,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectSetPipelineState(psor.Value); } - public void SetConstantBufferView(uint slot, Handle buffer) + public void SetConstantBufferView(uint slot, Handle buffer) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -647,7 +647,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectSetGraphicsRootConstantBufferView(slot, resource.Get()->GetGPUVirtualAddress()); } - public void SetVertexBuffer(uint slot, Handle buffer, ulong offset = 0) + public void SetVertexBuffer(uint slot, Handle buffer, ulong offset = 0) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -677,7 +677,7 @@ internal unsafe class D3D12CommandBuffer : D3D12ObjectIASetVertexBuffers(slot, 1, &vbView); } - public void SetIndexBuffer(Handle buffer, IndexType type, ulong offset = 0) + public void SetIndexBuffer(Handle buffer, IndexType type, ulong offset = 0) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -817,7 +817,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object argumentBuffer, ulong argumentOffset, Handle countBuffer, ulong countBufferOffset) + public void ExecuteIndirect(Handle argumentBuffer, ulong argumentOffset, Handle countBuffer, ulong countBufferOffset) { throw new NotImplementedException(); @@ -841,7 +841,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object(Handle buffer, params ReadOnlySpan data) + public void UploadBuffer(Handle buffer, params ReadOnlySpan data) where T : unmanaged { static void Map(T* pData, nuint size, ulong offset, SharedPtr resource) @@ -891,7 +891,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object texture, params ReadOnlySpan subresources) + public void UploadTexture(Handle texture, params ReadOnlySpan subresources) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -932,7 +932,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object dst, Handle src, ulong dstOffset = 0, ulong srcOffset = 0, ulong numBytes = 0) + public void CopyBuffer(Handle dst, Handle src, ulong dstOffset = 0, ulong srcOffset = 0, ulong numBytes = 0) { AssertNotDisposed(); ThrowIfNotRecording(); @@ -991,7 +991,7 @@ internal unsafe class D3D12CommandBuffer : D3D12Object dst, TextureRegion? dstRegion, Handle src, TextureRegion? srcRegion) + public void CopyTexture(Handle dst, TextureRegion? dstRegion, Handle src, TextureRegion? srcRegion) { AssertNotDisposed(); ThrowIfNotRecording(); diff --git a/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceAllocator.cs b/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceAllocator.cs index a21c322..90704ee 100644 --- a/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceAllocator.cs +++ b/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceAllocator.cs @@ -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 _uploadBatch; + private readonly Handle _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 CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default) + public Handle 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.Invalid; + return Handle.Invalid; } var isTemp = options.AllocationType == ResourceAllocationType.Temporary; @@ -698,7 +698,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator return resource.AsTexture(); } - public Handle CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default) + public Handle 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 CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default) + public Handle 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.Invalid; + return Handle.Invalid; } var isTemp = options.AllocationType == ResourceAllocationType.Temporary; @@ -808,7 +808,7 @@ internal sealed unsafe partial class D3D12ResourceAllocator : IResourceAllocator return resource.AsGraphicsBuffer(); } - public Handle CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset) + public Handle CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset) { if (sizeInBytes <= _MAX_RESOURCE_SIZE_TO_FIT_IN_UPLOAD_BATCH && sizeInBytes + _uploadBatchOffset <= _UPLOAD_BATCH_SIZE) { diff --git a/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceDatabase.cs b/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceDatabase.cs index 1b66f1e..b5aa881 100644 --- a/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceDatabase.cs +++ b/src/Runtime/Ghost.Graphics.D3D12/D3D12ResourceDatabase.cs @@ -99,7 +99,6 @@ internal class D3D12ResourceDatabase : IResourceDatabase private readonly D3D12DescriptorAllocator _descriptorAllocator; - // TODO: Change AOS to SOA? private UnsafeSlotMap _resources; private UnsafeHashMap> _samplers; #if DEBUG || GHOST_EDITOR diff --git a/src/Runtime/Ghost.Graphics.D3D12/DXGISwapChain.cs b/src/Runtime/Ghost.Graphics.D3D12/DXGISwapChain.cs index a4c091d..a56f5c6 100644 --- a/src/Runtime/Ghost.Graphics.D3D12/DXGISwapChain.cs +++ b/src/Runtime/Ghost.Graphics.D3D12/DXGISwapChain.cs @@ -19,7 +19,7 @@ internal unsafe class DXGISwapChain : ISwapChain private readonly D3D12RenderDevice _device; private UniquePtr _swapChain; - private UnsafeArray> _backBuffers; + private UnsafeArray> _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>((int)bufferCount, Allocator.Persistent); + _backBuffers = new UnsafeArray>((int)bufferCount, Allocator.Persistent); Width = desc.Width; Height = desc.Height; @@ -166,14 +166,14 @@ internal unsafe class DXGISwapChain : ISwapChain } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Handle GetCurrentBackBuffer() + public Handle GetCurrentBackBuffer() { Debug.Assert(!_disposed); return _backBuffers[_swapChain.Get()->GetCurrentBackBufferIndex()]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpan> GetBackBuffers() + public ReadOnlySpan> GetBackBuffers() { Debug.Assert(!_disposed); return _backBuffers.AsSpan(); diff --git a/src/Runtime/Ghost.Graphics.RHI/Common.cs b/src/Runtime/Ghost.Graphics.RHI/Common.cs index 9f50a9c..59ff5f9 100644 --- a/src/Runtime/Ghost.Graphics.RHI/Common.cs +++ b/src/Runtime/Ghost.Graphics.RHI/Common.cs @@ -292,12 +292,12 @@ public struct RenderDesc } // The "Target" (Where to write pixels) - public Handle Target + public Handle Target { get; set; } - public Handle DepthTarget + public Handle DepthTarget { get; set; } @@ -377,7 +377,7 @@ public struct SubResourceData public struct PassRenderTargetDesc { - public Handle Texture + public Handle Texture { get; set; } @@ -407,7 +407,7 @@ public struct PassRenderTargetDesc public struct PassDepthStencilDesc { - public Handle Texture + public Handle Texture { get; set; } diff --git a/src/Runtime/Ghost.Graphics.RHI/ICommandBuffer.cs b/src/Runtime/Ghost.Graphics.RHI/ICommandBuffer.cs index aef8a8e..a1ca220 100644 --- a/src/Runtime/Ghost.Graphics.RHI/ICommandBuffer.cs +++ b/src/Runtime/Ghost.Graphics.RHI/ICommandBuffer.cs @@ -63,14 +63,14 @@ public interface ICommandBuffer : IDisposable /// 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. /// A handle to the texture to be used as the depth Target. Specify a invalid handle if no depth Target is required. - void SetRenderTargets(ReadOnlySpan> renderTargets, Handle depthTarget); + void SetRenderTargets(ReadOnlySpan> renderTargets, Handle depthTarget); /// /// Clears the specified render target to a given color. /// /// A handle to the render target texture to be cleared. Must reference a valid render target. /// The color value used to clear the render target. Specifies the RGBA components to fill the target. - void ClearRenderTargetView(Handle renderTarget, Color128 clearColor); + void ClearRenderTargetView(Handle renderTarget, Color128 clearColor); /// /// Clears the specified depth-stencil view by resetting its depth and/or stencil values. @@ -80,7 +80,7 @@ public interface ICommandBuffer : IDisposable /// A value indicating whether the stencil component should be cleared. /// The value to which the depth buffer will be set. Typically ranges from 0.0f (nearest) to 1.0f (farthest). /// The value to which the stencil buffer will be set. Must be a valid stencil value supported by the format. - void ClearDepthStencilView(Handle depthStencil, bool inlcludeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0); + void ClearDepthStencilView(Handle depthStencil, bool inlcludeDepth, bool includeStencil, float clearDepth = 1.0f, byte clearStencil = 0); /// /// Begins a render pass with the specified render Target @@ -112,7 +112,7 @@ public interface ICommandBuffer : IDisposable /// /// The zero-based index of the slot to bind the constant buffer view to. /// A graphics buffer to use as the constant buffer view. - void SetConstantBufferView(uint slot, Handle buffer); + void SetConstantBufferView(uint slot, Handle buffer); /// /// Binds a vertex buffer to the specified slot for subsequent draw calls. @@ -120,7 +120,7 @@ public interface ICommandBuffer : IDisposable /// The vertex buffer slot to bind to. /// The handle to the graphics buffer containing vertex data. /// The Offset in bytes from the start of the buffer. - void SetVertexBuffer(uint slot, Handle buffer, ulong offset = 0); + void SetVertexBuffer(uint slot, Handle buffer, ulong offset = 0); /// /// Binds an index buffer for indexed drawing. @@ -128,7 +128,7 @@ public interface ICommandBuffer : IDisposable /// The handle to the graphics buffer containing index data. /// The space of indices (e.g., 16-bit or 32-bit). /// The Offset in bytes from the start of the buffer. - void SetIndexBuffer(Handle buffer, IndexType type, ulong offset = 0); + void SetIndexBuffer(Handle buffer, IndexType type, ulong offset = 0); /// /// Sets the primitive topology to be used for subsequent drawing operations. @@ -192,7 +192,7 @@ public interface ICommandBuffer : IDisposable /// A handle to the buffer that will receive the uploaded data. /// A read-only span containing the data to upload to the buffer. The span must contain elements of space /// . - void UploadBuffer(Handle buffer, params ReadOnlySpan data) + void UploadBuffer(Handle buffer, params ReadOnlySpan data) where T : unmanaged; /// @@ -201,7 +201,7 @@ public interface ICommandBuffer : IDisposable /// The texture resource to which the subresource data will be uploaded. Must be a valid, initialized texture handle. /// A reference to the structure containing the subresource data to upload. The data must match the Format and layout expected by the texture. /// Must be greater than zero and not exceed the remaining subresources in the texture. - void UploadTexture(Handle texture, params ReadOnlySpan subresources); + void UploadTexture(Handle texture, params ReadOnlySpan subresources); /// /// Copies a specified number of bytes from the source graphics buffer to the destination graphics buffer. @@ -211,7 +211,7 @@ public interface ICommandBuffer : IDisposable /// The byte Offset in the destination buffer at which to begin writing. Must be zero or greater. /// The byte Offset in the source buffer at which to begin reading. Must be zero or greater. /// The number of bytes to copy. If zero, copies the remaining bytes from the source buffer starting at . - void CopyBuffer(Handle dest, Handle src, ulong destOffset = 0, ulong srcOffset = 0, ulong numBytes = 0); + void CopyBuffer(Handle dest, Handle src, ulong destOffset = 0, ulong srcOffset = 0, ulong numBytes = 0); /// /// 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 /// The region of the destination texture to copy to. If null, the entire texture will be used. /// The handle to the source texture from which data will be read. /// The region of the source texture to copy from. If null, the entire texture will be used. - void CopyTexture(Handle dst, TextureRegion? dstRegion, Handle src, TextureRegion? srcRegion); + void CopyTexture(Handle dst, TextureRegion? dstRegion, Handle src, TextureRegion? srcRegion); } diff --git a/src/Runtime/Ghost.Graphics.RHI/IRenderOutput.cs b/src/Runtime/Ghost.Graphics.RHI/IRenderOutput.cs index 3a241f7..e6cef64 100644 --- a/src/Runtime/Ghost.Graphics.RHI/IRenderOutput.cs +++ b/src/Runtime/Ghost.Graphics.RHI/IRenderOutput.cs @@ -18,7 +18,7 @@ public interface IRenderOutput /// Gets a handle to the current render target texture. /// /// A handle to the texture that is currently set as the render target. - Handle GetRenderTarget(); + Handle GetRenderTarget(); /// /// Begins a rendering operation using the specified command buffer. Typically this will include resource barriers, diff --git a/src/Runtime/Ghost.Graphics.RHI/IResourceAllocator.cs b/src/Runtime/Ghost.Graphics.RHI/IResourceAllocator.cs index f11751f..0a88575 100644 --- a/src/Runtime/Ghost.Graphics.RHI/IResourceAllocator.cs +++ b/src/Runtime/Ghost.Graphics.RHI/IResourceAllocator.cs @@ -98,7 +98,7 @@ public interface IResourceAllocator : IDisposable /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource - Handle CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default); + Handle CreateTexture(ref readonly TextureDesc desc, string name, CreationOptions options = default); /// /// Creates a render Target for off-screen rendering @@ -107,7 +107,7 @@ public interface IResourceAllocator : IDisposable /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource - Handle CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default); + Handle CreateRenderTarget(ref readonly RenderTargetDesc desc, string name, CreationOptions options = default); /// /// Creates a buffer resource @@ -116,7 +116,7 @@ public interface IResourceAllocator : IDisposable /// Debug name of the resource /// Additional options of the resource allocation /// An point to the resource - Handle CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default); + Handle CreateBuffer(ref readonly BufferDesc desc, string name, CreationOptions options = default); /// /// Creates a temporary upload buffer of the specified size in bytes. @@ -127,7 +127,7 @@ public interface IResourceAllocator : IDisposable /// The size of the upload buffer to create, in bytes. /// The offset within the upload buffer where the allocation begins. /// An pointing to the created upload buffer. - Handle CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset); + Handle CreateTempUploadBuffer(ulong sizeInBytes, out ulong offset); /// /// Creates a new sampler object using the specified sampler description. diff --git a/src/Runtime/Ghost.Graphics.RHI/ISwapChain.cs b/src/Runtime/Ghost.Graphics.RHI/ISwapChain.cs index 6c55e77..b63689a 100644 --- a/src/Runtime/Ghost.Graphics.RHI/ISwapChain.cs +++ b/src/Runtime/Ghost.Graphics.RHI/ISwapChain.cs @@ -43,13 +43,13 @@ public interface ISwapChain : IDisposable /// Gets the current back buffer texture /// /// Current back buffer texture - Handle GetCurrentBackBuffer(); + Handle GetCurrentBackBuffer(); /// /// Gets all back buffer textures /// /// AlowBufferAndTexture back buffer textures - ReadOnlySpan> GetBackBuffers(); + ReadOnlySpan> GetBackBuffers(); /// /// Presents the rendered frame @@ -70,4 +70,4 @@ public interface ISwapChain : IDisposable /// The factor by which to scale the object along the X-axis. /// The factor by which to scale the object along the Y-axis. void SetScale(float scaleX, float scaleY); -} \ No newline at end of file +} diff --git a/src/Runtime/Ghost.Graphics.RHI/ResourceHandle.cs b/src/Runtime/Ghost.Graphics.RHI/ResourceHandle.cs index b7250ca..a6c660e 100644 --- a/src/Runtime/Ghost.Graphics.RHI/ResourceHandle.cs +++ b/src/Runtime/Ghost.Graphics.RHI/ResourceHandle.cs @@ -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 AsResource(this Handle texture) + public static Handle AsResource(this Handle texture) { return new Handle(texture.ID, texture.Generation); } - public static Handle AsResource(this Handle buffer) + public static Handle AsResource(this Handle buffer) { return new Handle(buffer.ID, buffer.Generation); } - public static Handle AsTexture(this Handle resource) + public static Handle AsTexture(this Handle resource) { - return new Handle(resource.ID, resource.Generation); + return new Handle(resource.ID, resource.Generation); } - public static Handle AsGraphicsBuffer(this Handle resource) + public static Handle AsGraphicsBuffer(this Handle resource) { - return new Handle(resource.ID, resource.Generation); + return new Handle(resource.ID, resource.Generation); } } diff --git a/src/Runtime/Ghost.Graphics/Core/Material.cs b/src/Runtime/Ghost.Graphics/Core/Material.cs index 2ebded7..6a354d7 100644 --- a/src/Runtime/Ghost.Graphics/Core/Material.cs +++ b/src/Runtime/Ghost.Graphics/Core/Material.cs @@ -11,16 +11,16 @@ namespace Ghost.Graphics.Core; internal struct CBufferCache : IResourceReleasable { private UnsafeArray _cpuData; - private Handle _gpuResource; + private Handle _gpuResource; private uint _size; public readonly UnsafeArray CpuData => _cpuData; - public readonly Handle GpuResource => _gpuResource; + public readonly Handle GpuResource => _gpuResource; public readonly uint Size => _size; public readonly bool IsCreated => _size != 0 && _gpuResource.IsValid && _cpuData.IsCreated; - public CBufferCache(Handle buffer, uint bufferSize) + public CBufferCache(Handle buffer, uint bufferSize) { _size = bufferSize; _cpuData = new UnsafeArray((int)bufferSize, Allocator.Persistent); @@ -37,7 +37,7 @@ internal struct CBufferCache : IResourceReleasable _cpuData.Dispose(); database.ReleaseResource(_gpuResource.AsResource()); - _gpuResource = Handle.Invalid; + _gpuResource = Handle.Invalid; _size = 0; } } diff --git a/src/Runtime/Ghost.Graphics/Core/Mesh.cs b/src/Runtime/Ghost.Graphics/Core/Mesh.cs index 8460c74..ea36c58 100644 --- a/src/Runtime/Ghost.Graphics/Core/Mesh.cs +++ b/src/Runtime/Ghost.Graphics/Core/Mesh.cs @@ -138,7 +138,7 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the vertex buffer on the GPU. /// - public Handle VertexBuffer + public Handle VertexBuffer { get; internal set; } @@ -146,7 +146,7 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the index buffer on the GPU. /// - public Handle IndexBuffer + public Handle IndexBuffer { get; internal set; } @@ -154,7 +154,7 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the meshlet buffer on the GPU. /// - public Handle MeshLetBuffer + public Handle MeshLetBuffer { get; internal set; } @@ -162,7 +162,7 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the meshlet vertices buffer on the GPU. /// - public Handle MeshletVerticesBuffer + public Handle MeshletVerticesBuffer { get; internal set; } @@ -170,7 +170,7 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the meshlet triangles buffer on the GPU. /// - public Handle MeshletTrianglesBuffer + public Handle MeshletTrianglesBuffer { get; internal set; } @@ -178,12 +178,12 @@ public struct Mesh : IResourceReleasable /// /// Gets the handle to the mesh data buffer on the GPU. /// - public Handle ObjectDataBuffer + public Handle ObjectDataBuffer { get; internal set; } - internal Mesh(ReadOnlySpan vertices, ReadOnlySpan indices, Handle vertexBuffer, Handle indexBuffer) + internal Mesh(ReadOnlySpan vertices, ReadOnlySpan indices, Handle vertexBuffer, Handle indexBuffer) { Vertices = new UnsafeList(vertices.Length, Allocator.Persistent); Indices = new UnsafeList(indices.Length, Allocator.Persistent); diff --git a/src/Runtime/Ghost.Graphics/Core/RenderOutput.cs b/src/Runtime/Ghost.Graphics/Core/RenderOutput.cs index 2caa5a9..b528ac3 100644 --- a/src/Runtime/Ghost.Graphics/Core/RenderOutput.cs +++ b/src/Runtime/Ghost.Graphics/Core/RenderOutput.cs @@ -25,7 +25,7 @@ internal class SwapChainRenderOutput : IRenderOutput Scissor = new ScissorRectDesc { Right = swapChain.Width, Bottom = swapChain.Height }; } - public Handle GetRenderTarget() + public Handle GetRenderTarget() { return _swapChain.GetCurrentBackBuffer(); } @@ -58,7 +58,7 @@ internal class SwapChainRenderOutput : IRenderOutput internal class TextureRenderOutput : IRenderOutput { - private readonly Handle _texture; + private readonly Handle _texture; public ViewportDesc Viewport { @@ -70,12 +70,12 @@ internal class TextureRenderOutput : IRenderOutput get; set; } - public TextureRenderOutput(Handle texture) + public TextureRenderOutput(Handle texture) { _texture = texture; } - public Handle GetRenderTarget() + public Handle GetRenderTarget() { return _texture; } diff --git a/src/Runtime/Ghost.Graphics/Core/RenderRequest.cs b/src/Runtime/Ghost.Graphics/Core/RenderRequest.cs index a54d2f8..965fce9 100644 --- a/src/Runtime/Ghost.Graphics/Core/RenderRequest.cs +++ b/src/Runtime/Ghost.Graphics/Core/RenderRequest.cs @@ -183,8 +183,8 @@ public unsafe struct RenderRequest: IDisposable public RenderView view; public int swapChainIndex; - public Handle colorTarget; - public Handle depthTarget; + public Handle colorTarget; + public Handle depthTarget; public RenderList opaqueRenderList; public RenderList transparentRenderList; diff --git a/src/Runtime/Ghost.Graphics/Core/RenderingContext.cs b/src/Runtime/Ghost.Graphics/Core/RenderingContext.cs index 5f5f11a..e31cbf9 100644 --- a/src/Runtime/Ghost.Graphics/Core/RenderingContext.cs +++ b/src/Runtime/Ghost.Graphics/Core/RenderingContext.cs @@ -242,7 +242,7 @@ public readonly unsafe ref struct RenderingContext TransitionBarrier(bufferHandle, false, BarrierLayout.Undefined, BarrierAccess.ShaderResource, BarrierSync.PixelShading | BarrierSync.NonPixelShading); } - public Handle CreateTexture(ref readonly TextureDesc desc, ReadOnlySpan data, string name) + public Handle CreateTexture(ref readonly TextureDesc desc, ReadOnlySpan 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(Handle texture, ReadOnlySpan data) + public void UploadTexture(Handle texture, ReadOnlySpan data) where T : unmanaged { var desc = ResourceDatabase.GetResourceDescription(texture.AsResource()).GetValueOrThrow(); diff --git a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraph.cs b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraph.cs index 7c56157..b18f6f0 100644 --- a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraph.cs +++ b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraph.cs @@ -105,7 +105,7 @@ public sealed class RenderGraph : IDisposable /// /// The external texture handle. /// The identifier of the imported render graph texture. Invalid if import fails. - public Identifier ImportTexture(Handle texture, string name, + public Identifier ImportTexture(Handle 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 /// /// The external buffer handle. /// The identifier of the imported render graph buffer. Invalid if import fails. - public Identifier ImportBuffer(Handle buffer, string name) + public Identifier ImportBuffer(Handle buffer, string name) { var r = _resourceDatabase.GetResourceDescription(buffer.AsResource()); if (r.IsFailure) diff --git a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphBuilder.cs b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphBuilder.cs index 939327d..9ee472b 100644 --- a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphBuilder.cs +++ b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphBuilder.cs @@ -79,6 +79,20 @@ public interface IRenderGraphBuilder : IDisposable /// Optional hint about how the buffer will be used. /// An identifier for the buffer. Identifier UseBuffer(Identifier buffer, AccessFlags accessMode); + + /// + /// Extracts the actual texture resource associated with the given identifier for use in outside of the render graph execution context. + /// + /// The identifier of the texture to be extracted. + /// A handle to the actual texture resource that can be used outside of the render graph execution context. + Handle ExtractTexture(Identifier texture); + + /// + /// Extracts the actual buffer resource associated with the given identifier for use in outside of the render graph execution context. + /// + /// The identifier of the buffer to be extracted. + /// A handle to the actual buffer resource that can be used outside of the render graph execution context. + Handle ExtractBuffer(Identifier 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 ExtractTexture(Identifier texture) + { + throw new NotImplementedException(); + } + + public Handle ExtractBuffer(Identifier buffer) + { + throw new NotImplementedException(); + } + public Identifier UseRandomAccessTexture(Identifier texture) { ThrowIfDisposed(); diff --git a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphContext.cs b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphContext.cs index 17f822d..c644bf5 100644 --- a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphContext.cs +++ b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphContext.cs @@ -11,11 +11,11 @@ public interface IRenderGraphContext IResourceDatabase ResourceDatabase { get; } Handle GetActualResource(Identifier resource); - Handle GetActualTexture(Identifier texture); - Handle GetActualBuffer(Identifier buffer); + Handle GetActualTexture(Identifier texture); + Handle GetActualBuffer(Identifier buffer); - Handle GetHistoryTexture(ReadOnlySpan> texture, int historyOffset); - Handle GetHistoryBuffer(ReadOnlySpan> buffer, int historyOffset); + Handle GetHistoryTexture(ReadOnlySpan> texture, int historyOffset); + Handle GetHistoryBuffer(ReadOnlySpan> buffer, int historyOffset); ICommandBuffer GetCommandBufferUnsafe(); } @@ -60,8 +60,8 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext private TextureFormat _dsvFormat; private int _rtvCount; - private Handle _activePerMaterialData; - private Handle _activePerMeshData; + private Handle _activePerMaterialData; + private Handle _activePerMeshData; private int _activeMeshIndexCount; private uint _activeFrameBuffer; @@ -115,21 +115,21 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext return _resources.GetResource(resource).backingResource; } - public Handle GetActualTexture(Identifier texture) + public Handle GetActualTexture(Identifier texture) { return _resources.GetResource(texture.AsResource()).backingResource.AsTexture(); } - public Handle GetActualBuffer(Identifier buffer) + public Handle GetActualBuffer(Identifier buffer) { return _resources.GetResource(buffer.AsResource()).backingResource.AsGraphicsBuffer(); } - public Handle GetHistoryTexture(ReadOnlySpan> textures, int historyOffset) + public Handle GetHistoryTexture(ReadOnlySpan> textures, int historyOffset) { if (historyOffset < 0 || historyOffset >= textures.Length) { - return Handle.Invalid; + return Handle.Invalid; } var index = (int)(_frameIndex % textures.Length) - historyOffset; @@ -141,11 +141,11 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext return GetActualTexture(textures[index]); } - public Handle GetHistoryBuffer(ReadOnlySpan> buffers, int historyOffset) + public Handle GetHistoryBuffer(ReadOnlySpan> buffers, int historyOffset) { if (historyOffset < 0 || historyOffset >= buffers.Length) { - return Handle.Invalid; + return Handle.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.Invalid; + _activePerMaterialData = Handle.Invalid; return; } @@ -185,7 +185,7 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext var shaderResult = _resourceManager.GetShaderReference(material.Shader); if (shaderResult.IsFailure) { - _activePerMaterialData = Handle.Invalid; + _activePerMaterialData = Handle.Invalid; return; } @@ -230,7 +230,7 @@ internal sealed class RenderGraphContext : IUnsafeRenderContext var r = _resourceManager.GetMeshReference(mesh); if (r.IsFailure) { - _activePerMeshData = Handle.Invalid; + _activePerMeshData = Handle.Invalid; _activeMeshIndexCount = 0; return; } diff --git a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphExecutor.cs b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphExecutor.cs index fbdc076..9c935fd 100644 --- a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphExecutor.cs +++ b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphExecutor.cs @@ -134,7 +134,7 @@ internal sealed class RenderGraphExecutor { Texture = nativePass.hasDepthAttachment ? _resources.GetResource(nativePass.depthAttachment.texture).backingResource.AsTexture() - : Handle.Invalid, + : Handle.Invalid, ClearDepth = nativePass.depthAttachment.clearDepth, ClearStencil = nativePass.depthAttachment.clearStencil, DepthLoadOp = nativePass.hasDepthAttachment diff --git a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphResourcePool.cs b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphResourcePool.cs index 4fc63b0..64c6d03 100644 --- a/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphResourcePool.cs +++ b/src/Runtime/Ghost.Graphics/RenderGraphModule/RenderGraphResourcePool.cs @@ -163,7 +163,7 @@ internal sealed class RenderGraphResourceRegistry _resources.Clear(); } - public Identifier ImportTexture(ref readonly TextureDesc desc, Handle texture, string name, + public Identifier ImportTexture(ref readonly TextureDesc desc, Handle texture, string name, Color128 clearColor, float clearDepth, byte clearStencil, bool clearAtFirstUse, bool discardAtLastUse) { @@ -211,7 +211,7 @@ internal sealed class RenderGraphResourceRegistry return new Identifier(resource.index); } - public Identifier ImportBuffer(ref readonly BufferDesc desc, Handle buffer, string name) + public Identifier ImportBuffer(ref readonly BufferDesc desc, Handle buffer, string name) { var resource = _pool.Rent(); resource.name = name; diff --git a/src/Runtime/Ghost.Graphics/Utilities/MeshletUtility.cs b/src/Runtime/Ghost.Graphics/Utilities/MeshletUtility.cs index 1797707..3150141 100644 --- a/src/Runtime/Ghost.Graphics/Utilities/MeshletUtility.cs +++ b/src/Runtime/Ghost.Graphics/Utilities/MeshletUtility.cs @@ -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]); } diff --git a/src/Runtime/Ghost.Graphics/test.gshdr b/src/Runtime/Ghost.Graphics/test.gshdr index 59a5c52..af6209a 100644 --- a/src/Runtime/Ghost.Graphics/test.gshdr +++ b/src/Runtime/Ghost.Graphics/test.gshdr @@ -109,14 +109,12 @@ 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; float g = float((hash & 0x00FF00u) >> 8) / 255.0; float b = float((hash & 0x0000FFu)) / 255.0; - + return float4(r, g, b, 1.0); } } diff --git a/src/Test/Ghost.Graphics.Test/RenderPasses/TestRenderPipeline.cs b/src/Test/Ghost.Graphics.Test/RenderPasses/TestRenderPipeline.cs index 46d4a5c..6d3422f 100644 --- a/src/Test/Ghost.Graphics.Test/RenderPasses/TestRenderPipeline.cs +++ b/src/Test/Ghost.Graphics.Test/RenderPasses/TestRenderPipeline.cs @@ -126,7 +126,7 @@ public unsafe partial class TestRenderPipeline : IRenderPipeline continue; // Nothing to render } - Handle rt; + Handle rt; if (request.swapChainIndex < 0) { rt = request.colorTarget; diff --git a/src/Test/Ghost.Graphics.Test/Windows/GraphicsTestWindow.xaml.cs b/src/Test/Ghost.Graphics.Test/Windows/GraphicsTestWindow.xaml.cs index 0dde4e6..85a1af6 100644 --- a/src/Test/Ghost.Graphics.Test/Windows/GraphicsTestWindow.xaml.cs +++ b/src/Test/Ghost.Graphics.Test/Windows/GraphicsTestWindow.xaml.cs @@ -81,7 +81,7 @@ public sealed partial class GraphicsTestWindow : Window _world.EntityManager.SetComponent(cameraEntity, new Camera { swapChainIndex = 0, - depthTarget = Handle.Invalid, + depthTarget = Handle.Invalid, nearClipPlane = 0.1f, farClipPlane = 1000.0f, focalLength = 50.0f, diff --git a/src/ThridParty/Ghost.MeshOptimizer/ClusterLod.cs b/src/ThridParty/Ghost.MeshOptimizer/ClusterLod.cs deleted file mode 100644 index ab39bf7..0000000 --- a/src/ThridParty/Ghost.MeshOptimizer/ClusterLod.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Ghost.MeshOptimizer; - -internal class ClusterLod -{ -}