feat(rhi): refactor resource & barrier management for D3D12

Modernizes resource and barrier management for the D3D12 backend. Key changes:
- Simplifies BarrierDesc by removing nullable "before" states; now inferred from resource database.
- Adds IsAliasing flag to BarrierDesc for aliasing transitions.
- Replaces ResourceMemoryType with HeapType in BufferDesc and related APIs.
- Enhances ResourceViewGroup with usage inference methods.
- Adds D3D12 utility helpers for heap/flag conversions and resource description extraction.
- Optimizes command buffer barrier emission, skipping redundant barriers.
- Refactors Material and RenderContext to use new APIs and state tracking.
- Updates ResourceManager pooling to use HeapType and standard Queue.
- Simplifies RenderGraphExecutor barrier logic and aliasing handling.
- Improves RenderSystem frame synchronization and resource retirement.
- Cleans up obsolete code and improves debug output.

BREAKING CHANGE: Updates to resource and barrier APIs require changes to all code interfacing with resource creation, barriers, and memory types.
This commit is contained in:
2026-04-03 17:03:41 +09:00
parent 6321b36ef5
commit ba9e24c46c
20 changed files with 316 additions and 422 deletions

View File

@@ -397,6 +397,17 @@ internal static unsafe class D3D12Utility
};
}
public static HeapType ToHeapType(this D3D12_HEAP_TYPE heapType)
{
return heapType switch
{
D3D12_HEAP_TYPE_DEFAULT => HeapType.Default,
D3D12_HEAP_TYPE_UPLOAD => HeapType.Upload,
D3D12_HEAP_TYPE_READBACK => HeapType.Readback,
_ => throw new ArgumentException($"Unknown D3D12 heap type: {heapType}")
};
}
public static D3D12_HEAP_FLAGS ToD3D12HeapFlags(this HeapFlags flags)
{
return flags switch
@@ -411,6 +422,24 @@ internal static unsafe class D3D12Utility
};
}
public static HeapFlags ToHeapFlags(this D3D12_HEAP_FLAGS flags)
{
if (flags == D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES)
{
return HeapFlags.AllowAllBufferAndTexture;
}
return flags switch
{
D3D12_HEAP_FLAG_NONE => HeapFlags.None,
D3D12_HEAP_FLAG_SHARED => HeapFlags.Shared,
D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS => HeapFlags.AllowOnlyBuffers,
D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES => HeapFlags.AllowOnlyTextures,
D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES => HeapFlags.AllowOnlyRTAndDS,
_ => throw new ArgumentException($"Unknown D3D12 heap flags: {flags}")
};
}
public static D3D12_RESOURCE_DESC ToD3D12ResourceDesc(this in TextureDesc desc)
{
var dxgiFormat = desc.Format.ToDXGIFormat();
@@ -497,17 +526,22 @@ internal static unsafe class D3D12Utility
return D3D12_RESOURCE_DESC.Buffer(alignedSize, resourceFlags);
}
public static ResourceDesc ToResourceDesc(this D3D12_RESOURCE_DESC desc)
public static ResourceDesc GetResourceDesc(ID3D12Resource* pResource, ResourceViewGroup viewGroup)
{
D3D12_HEAP_PROPERTIES heapProperties;
D3D12_HEAP_FLAGS heapFlags;
ThrowIfFailed(pResource->GetHeapProperties(&heapProperties, &heapFlags));
var desc = pResource->GetDesc();
if (desc.Dimension == D3D12_RESOURCE_DIMENSION.D3D12_RESOURCE_DIMENSION_BUFFER)
{
return ResourceDesc.Buffer(new BufferDesc
{
Size = (uint)desc.Width,
Stride = 0,
Usage = BufferUsage.None,
MemoryType = ResourceMemoryType.Default
Usage = viewGroup.GetBufferUsage(),
HeapType = heapProperties.Type.ToHeapType()
});
}
else
@@ -520,7 +554,7 @@ internal static unsafe class D3D12Utility
Format = desc.Format.ToTextureFormat(),
Dimension = desc.Dimension.ToTextureDimension(),
MipLevels = desc.MipLevels,
Usage = TextureUsage.None,
Usage = viewGroup.GetTextureUsage(),
});
}
}