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

@@ -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();