Added disposed validation for loaded buffers
このコミットが含まれているのは:
1 親
92a85fbcfb
コミット
e0838e678b
2ファイル変更
+33
-5
検索条件に一致するファイルはありません
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ComputeSharp.Core.Interop
|
||||
{
|
||||
@@ -47,5 +48,22 @@ namespace ComputeSharp.Core.Interop
|
||||
/// Releases unmanaged and (optionally) managed resources.
|
||||
/// </summary>
|
||||
protected abstract void OnDispose();
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ObjectDisposedException"/> if the current instance has been disposed.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void ThrowIfDisposed()
|
||||
{
|
||||
if (this.isDisposed)
|
||||
{
|
||||
// We can't use ThrowHelper here as we only want to invoke ToString if we
|
||||
// are about to throw an exception. The JIT will recognize this pattern
|
||||
// as this method has a single basic block that always throws an exception.
|
||||
void Throw() => throw new ObjectDisposedException(ToString());
|
||||
|
||||
Throw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using System.Reflection.Emit;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Core.Interop;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
@@ -78,6 +79,11 @@ namespace ComputeSharp.Shaders.Translation
|
||||
/// </summary>
|
||||
private void BuildDispatchDataLoader()
|
||||
{
|
||||
// The delegate signature is <in T, ref D3D12_GPU_DESCRIPTOR_HANDLE, ref byte, void>.
|
||||
//
|
||||
// ldarg.0 = in T shader
|
||||
// ldarg.1 = ref D3D12_GPU_DESCRIPTOR_HANDLE r0
|
||||
// ldarg.1 = ref byte r1
|
||||
this.dispatchDataLoader = DynamicMethod<DispatchDataLoader>.New(il =>
|
||||
{
|
||||
foreach (ReadableMember member in this.capturedMembers)
|
||||
@@ -95,12 +101,16 @@ namespace ComputeSharp.Shaders.Translation
|
||||
if (!member.IsStatic) il.Emit(OpCodes.Ldarg_0);
|
||||
il.EmitReadMember(member);
|
||||
|
||||
// Access Buffer<T>.D3D12GpuDescriptorHandle
|
||||
FieldInfo gpuDescriptorInfo = member.MemberType.GetField(
|
||||
nameof(Buffer<byte>.D3D12GpuDescriptorHandle),
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)!;
|
||||
// Call NativeObject.ThrowIfDisposed()
|
||||
il.Emit(OpCodes.Dup);
|
||||
il.EmitCall(OpCodes.Callvirt, typeof(NativeObject).GetMethod(
|
||||
nameof(NativeObject.ThrowIfDisposed),
|
||||
BindingFlags.Instance | BindingFlags.NonPublic)!, null);
|
||||
|
||||
il.EmitReadMember(gpuDescriptorInfo);
|
||||
// Access Buffer<T>.D3D12GpuDescriptorHandle
|
||||
il.EmitReadMember(member.MemberType.GetField(
|
||||
nameof(Buffer<byte>.D3D12GpuDescriptorHandle),
|
||||
BindingFlags.NonPublic | BindingFlags.Instance)!);
|
||||
il.EmitStoreToAddress(typeof(D3D12_GPU_DESCRIPTOR_HANDLE));
|
||||
|
||||
this.totalResourceCount++;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする