Use ComPtr<T> for all fields of native objects

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-21 12:07:14 +01:00
1 親 423ee790ca
コミット 265de8d1ea
13ファイル変更
+96 -117

検索条件に一致するファイルはありません

@@ -69,10 +69,10 @@ partial struct PixelShaderEffect
{
default(ArgumentOutOfRangeException).ThrowIfNotEqual((int)inputRectsCount, @this->GetGlobals().InputCount, nameof(inputRectsCount));
if (@this->d2D1TransformMapper is not null)
if (@this->d2D1TransformMapper.Get() is not null)
{
// Forward to the current ID2D1TransformMapper instance
@this->d2D1TransformMapper->MapOutputRectToInputRects(outputRect, inputRects, inputRectsCount).Assert();
@this->d2D1TransformMapper.Get()->MapOutputRectToInputRects(outputRect, inputRects, inputRectsCount).Assert();
}
else
{
@@ -117,7 +117,7 @@ partial struct PixelShaderEffect
{
default(ArgumentOutOfRangeException).ThrowIfNotEqual((int)inputRectCount, @this->GetGlobals().InputCount, nameof(inputRectCount));
if (@this->d2D1TransformMapper is not null)
if (@this->d2D1TransformMapper.Get() is not null)
{
using ComPtr<D2D1DrawInfoUpdateContextImpl> d2D1DrawInfoUpdateContext = default;
@@ -126,10 +126,10 @@ partial struct PixelShaderEffect
drawInfoUpdateContext: d2D1DrawInfoUpdateContext.GetAddressOf(),
constantBuffer: @this->constantBuffer,
constantBufferSize: @this->GetGlobals().ConstantBufferSize,
d2D1DrawInfo: @this->d2D1DrawInfo).Assert();
d2D1DrawInfo: @this->d2D1DrawInfo.Get()).Assert();
// Forward the call to the input ID2D1TransformMapper instance
HRESULT hresult = @this->d2D1TransformMapper->MapInputRectsToOutputRect(
HRESULT hresult = @this->d2D1TransformMapper.Get()->MapInputRectsToOutputRect(
updateContext: (ID2D1DrawInfoUpdateContext*)d2D1DrawInfoUpdateContext.Get(),
inputRects: inputRects,
inputOpaqueSubRects: inputOpaqueSubRects,
@@ -209,10 +209,10 @@ partial struct PixelShaderEffect
{
default(ArgumentOutOfRangeException).ThrowIfGreaterThanOrEqual((int)inputIndex, @this->GetGlobals().InputCount, nameof(inputIndex));
if (@this->d2D1TransformMapper is not null)
if (@this->d2D1TransformMapper.Get() is not null)
{
// Forward to the current ID2D1TransformMapper instance
@this->d2D1TransformMapper->MapInvalidRect(inputIndex, invalidInputRect, invalidOutputRect).Assert();
@this->d2D1TransformMapper.Get()->MapInvalidRect(inputIndex, invalidInputRect, invalidOutputRect).Assert();
}
else
{
@@ -248,7 +248,7 @@ partial struct PixelShaderEffect
try
{
// Store the new ID2D1DrawInfo object
ComPtr.CopyTo(drawInfo, ref @this->d2D1DrawInfo);
@this->d2D1DrawInfo.Attach(new ComPtr<ID2D1DrawInfo>(drawInfo).Get());
Guid shaderId = @this->GetGlobals().EffectId;
D2D1PixelOptions pixelOptions = @this->GetGlobals().PixelOptions;
@@ -70,7 +70,7 @@ internal unsafe partial struct PixelShaderEffect
transformGraph->SetSingleTransformNode((ID2D1TransformNode*)&@this->lpVtblForID2D1DrawTransform).Assert();
// Store the new ID2D1EffectContext object
ComPtr.CopyTo(effectContext, ref @this->d2D1EffectContext);
@this->d2D1EffectContext.Attach(new ComPtr<ID2D1EffectContext>(effectContext).Get());
return S.S_OK;
}
@@ -99,7 +99,7 @@ internal unsafe partial struct PixelShaderEffect
// First, set the constant buffer, if available
if (@this->constantBuffer is not null)
{
@this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
@this->d2D1DrawInfo.Get()->SetPixelShaderConstantBuffer(
buffer: @this->constantBuffer,
bufferCount: (uint)@this->GetGlobals().ConstantBufferSize).Assert();
}
@@ -131,7 +131,7 @@ internal unsafe partial struct PixelShaderEffect
ref readonly D2D1ResourceTextureDescription resourceTextureDescription = ref resourceTextureDescriptions[i];
// Set the ID2D1ResourceTexture object to the current index in the ID2D1DrawInfo object in use
@this->d2D1DrawInfo->SetResourceTexture(
@this->d2D1DrawInfo.Get()->SetResourceTexture(
textureIndex: (uint)resourceTextureDescription.Index,
resourceTexture: d2D1ResourceTexture.Get()).Assert();
}
+4 -14
ファイルの表示
@@ -107,14 +107,7 @@ unsafe partial struct PixelShaderEffect
default(ArgumentNullException).ThrowIfNull(data);
default(ArgumentOutOfRangeException).ThrowIfLessThan((int)dataSize, sizeof(void*), nameof(dataSize));
if (@this->d2D1TransformMapper is null)
{
*(void**)data = null;
}
else
{
((IUnknown*)@this->d2D1TransformMapper)->QueryInterface(Windows.__uuidof<ID2D1TransformMapper>(), (void**)data).Assert();
}
@this->d2D1TransformMapper.CopyTo((ID2D1TransformMapper**)data).Assert();
if (actualSize is not null)
{
@@ -150,11 +143,8 @@ unsafe partial struct PixelShaderEffect
// Check that the input object implements ID2D1TransformMapper
unknown.CopyTo(transformMapper.GetAddressOf()).Assert();
// If there's already an existing manager, release it
ComPtr.Dispose(@this->d2D1TransformMapper);
// Store the transform mapper manager into the effect
@this->d2D1TransformMapper = transformMapper.Detach();
@this->d2D1TransformMapper.Attach(transformMapper.Detach());
return S.S_OK;
}
@@ -226,7 +216,7 @@ unsafe partial struct PixelShaderEffect
unknown.CopyTo(resourceTextureManagerInternal.GetAddressOf()).Assert();
// Initialize the resource texture manager, if an effect context is available
if (this.d2D1EffectContext is not null)
if (this.d2D1EffectContext.Get() is not null)
{
uint dimensions = (uint)GetGlobals().ResourceTextureDescriptions.Span[index].Dimensions;
@@ -235,7 +225,7 @@ unsafe partial struct PixelShaderEffect
// enable sharing resource texture managers across different source textures and effects), or
// E_INVALIDARG if the manager has already been initialized through the public interface,
// and the stored dimensions for that don't match the ones for this resource texture index.
resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext, &dimensions).Assert();
resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext.Get(), &dimensions).Assert();
}
// Store the resource texture manager into the buffer
+9 -9
ファイルの表示
@@ -80,17 +80,17 @@ internal unsafe partial struct PixelShaderEffect
/// <summary>
/// The <see cref="ID2D1TransformMapper"/> instance to use, if any.
/// </summary>
private ID2D1TransformMapper* d2D1TransformMapper;
private ComPtr<ID2D1TransformMapper> d2D1TransformMapper;
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
/// </summary>
private ID2D1DrawInfo* d2D1DrawInfo;
private ComPtr<ID2D1DrawInfo> d2D1DrawInfo;
/// <summary>
/// The <see cref="ID2D1EffectContext"/> instance currently in use.
/// </summary>
private ID2D1EffectContext* d2D1EffectContext;
private ComPtr<ID2D1EffectContext> d2D1EffectContext;
/// <summary>
/// The resource texture managers for the current instance.
@@ -118,9 +118,9 @@ internal unsafe partial struct PixelShaderEffect
@this->referenceCount = 1;
@this->globalsHandle = globalsHandle;
@this->constantBuffer = null;
@this->d2D1TransformMapper = null;
@this->d2D1DrawInfo = null;
@this->d2D1EffectContext = null;
@this->d2D1TransformMapper = default;
@this->d2D1DrawInfo = default;
@this->d2D1EffectContext = default;
@this->resourceTextureManagerBuffer = default;
*effectImpl = (IUnknown*)@this;
@@ -197,9 +197,9 @@ internal unsafe partial struct PixelShaderEffect
NativeMemory.Free(this.constantBuffer);
ComPtr.Dispose(this.d2D1TransformMapper);
ComPtr.Dispose(this.d2D1DrawInfo);
ComPtr.Dispose(this.d2D1EffectContext);
this.d2D1TransformMapper.Dispose();
this.d2D1DrawInfo.Dispose();
this.d2D1EffectContext.Dispose();
// Retrieve all possible resource texture managers in use and release the ones that had been
// assigned (from one of the property bindings). We just try to dispose all of them here and
@@ -19,7 +19,7 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
lock (@this->lockHandle.Target!)
{
// If the method has already been called, fail
if (@this->d2D1ResourceTexture is not null ||
if (@this->d2D1ResourceTexture.Get() is not null ||
@this->data is not null)
{
return E.E_NOT_VALID_STATE;
@@ -35,20 +35,20 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
}
// If the method has already been called, just forward the call
if (@this->d2D1EffectContext is not null)
if (@this->d2D1EffectContext.Get() is not null)
{
@this->d2D1Multithread->Enter();
@this->d2D1Multithread.Get()->Enter();
// Create the resource after taking a D2D lock
int hresult = @this->d2D1EffectContext->CreateResourceTexture(
int hresult = @this->d2D1EffectContext.Get()->CreateResourceTexture(
resourceId: resourceId,
resourceTextureProperties: resourceTextureProperties,
data: data,
strides: strides,
dataSize: dataSize,
resourceTexture: &@this->d2D1ResourceTexture);
resourceTexture: @this->d2D1ResourceTexture.GetAddressOf());
@this->d2D1Multithread->Leave();
@this->d2D1Multithread.Get()->Leave();
return hresult;
}
@@ -76,14 +76,14 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
{
lock (@this->lockHandle.Target!)
{
if (@this->d2D1ResourceTexture is null &&
if (@this->d2D1ResourceTexture.Get() is null &&
@this->data is null)
{
return E.E_NOT_VALID_STATE;
}
// If no resource texture already exists, update the staging buffer
if (@this->d2D1ResourceTexture is null)
if (@this->d2D1ResourceTexture.Get() is null)
{
return ID2D1ResourceTextureManagerMethods.UpdateWithStagingBuffer(
@this: @this,
@@ -103,10 +103,10 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
// checked for this while taking the instance lock). So we can now take the D2D
// lock and update the texture directly. We need to take this when we're not also
// taking the instance lock, or we might trigger an AB/BA deadlock across threads.
@this->d2D1Multithread->Enter();
@this->d2D1Multithread.Get()->Enter();
// Take a D2D lock here too to ensure thread safety
int hresult = @this->d2D1ResourceTexture->Update(
int hresult = @this->d2D1ResourceTexture.Get()->Update(
minimumExtents: minimumExtents,
maximimumExtents: maximimumExtents,
strides: strides,
@@ -114,7 +114,7 @@ unsafe partial struct D2D1ResourceTextureManagerImpl
data: data,
dataCount: dataCount);
@this->d2D1Multithread->Leave();
@this->d2D1Multithread.Get()->Leave();
return hresult;
}
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Extensions;
using ComputeSharp.Win32;
@@ -70,7 +71,7 @@ partial struct D2D1ResourceTextureManagerImpl
// If this is the first time the method is called, just store the context.
// Before doing so, get an ID2D1Multithread instance, to ensure thread safety.
// For additional info, see docs on ID2D1EffectFactoryExtensions.GetD2D1Multithread.
if (@this->d2D1EffectContext is null)
if (@this->d2D1EffectContext.Get() is null)
{
using ComPtr<ID2D1Multithread> d2D1Multithread = default;
@@ -88,9 +89,9 @@ partial struct D2D1ResourceTextureManagerImpl
// Now, the effect context can actually be stored safely while holding the lock.
// This is guaranteed to be the case here, as this method is only called (as per
// contact of the COM interface) from ID2D1EffectImpl, which holds the D2D lock.
ComPtr.WriteTo(effectContext, out @this->d2D1EffectContext);
@this->d2D1Multithread = d2D1Multithread.Detach();
// Also store the actual multithread object after storing the effect context.
@this->d2D1EffectContext.Attach(new ComPtr<ID2D1EffectContext>(effectContext).Get());
@this->d2D1Multithread.Attach(d2D1Multithread.Detach());
}
return hresult;
@@ -117,15 +118,15 @@ partial struct D2D1ResourceTextureManagerImpl
lock (@this->lockHandle.Target!)
{
// If the effect context is null, it means Initialize has not been called yet
if (@this->d2D1EffectContext is null)
if (@this->d2D1EffectContext.Get() is null)
{
return E.E_NOT_VALID_STATE;
}
// If the texture has already been created, just return it
if (@this->d2D1ResourceTexture is not null)
if (@this->d2D1ResourceTexture.Get() is not null)
{
ComPtr.WriteTo(@this->d2D1ResourceTexture, out *resourceTexture);
@this->d2D1ResourceTexture.CopyTo(resourceTexture).Assert();
return S.S_OK;
}
@@ -139,7 +140,7 @@ partial struct D2D1ResourceTextureManagerImpl
using ComPtr<ID2D1ResourceTexture> d2D1ResourceTexture = default;
// Create the resource now, as it hasn't been created yet
int result = @this->d2D1EffectContext->CreateResourceTexture(
int result = @this->d2D1EffectContext.Get()->CreateResourceTexture(
resourceId: @this->resourceId,
resourceTextureProperties: &@this->resourceTextureProperties,
data: @this->data,
@@ -74,17 +74,17 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
/// <summary>
/// The <see cref="ID2D1EffectContext"/> object currently wrapped by the current instance.
/// </summary>
private ID2D1EffectContext* d2D1EffectContext;
private ComPtr<ID2D1EffectContext> d2D1EffectContext;
/// <summary>
/// The <see cref="ID2D1Multithread"/> instance used to lock accesses to <see cref="d2D1EffectContext"/> and <see cref="d2D1ResourceTexture"/>.
/// </summary>
private ID2D1Multithread* d2D1Multithread;
private ComPtr<ID2D1Multithread> d2D1Multithread;
/// <summary>
/// The <see cref="ID2D1ResourceTexture"/> object, if one was created already.
/// </summary>
private ID2D1ResourceTexture* d2D1ResourceTexture;
private ComPtr<ID2D1ResourceTexture> d2D1ResourceTexture;
/// <summary>
/// The <see cref="Guid"/> to identify the resource, if available.
@@ -142,9 +142,9 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
@this->lpVtblForID2D1ResourceTextureManager = VtblForID2D1ResourceTextureManager;
@this->lpVtblForID2D1ResourceTextureManagerInternal = VtblForID2D1ResourceTextureManagerInternal;
@this->referenceCount = 1;
@this->d2D1EffectContext = null;
@this->d2D1Multithread = null;
@this->d2D1ResourceTexture = null;
@this->d2D1EffectContext = default;
@this->d2D1Multithread = default;
@this->d2D1ResourceTexture = default;
@this->requiresMultithread = requiresMultithread ? 1 : 0;
@this->resourceId = null;
@this->resourceTextureProperties = default;
@@ -211,24 +211,25 @@ internal unsafe partial struct D2D1ResourceTextureManagerImpl
this.lockHandle.Free();
// Synchronize on the ID2D1Multithread instance before touching D2D objects
if (this.d2D1Multithread is not null)
if (this.d2D1Multithread.Get() is not null)
{
// Enter the lock, and then free the effect context. That is guaranteed to
// not be null here, as it is only ever set if ID2D1Multithread is retrieved.
this.d2D1Multithread->Enter();
this.d2D1Multithread.Get()->Enter();
// Release the resource too if it has been created
ComPtr.Dispose(this.d2D1ResourceTexture);
this.d2D1ResourceTexture.Dispose();
// Now that the resource, if any, has been released, the effect context can also
// be released. This must be done only after any associated resource textures have
// been released. Releasing an effect context first, in case it was the last reference
// to it, will otherwise cause the Release() call on the resource texture to explode.
_ = this.d2D1EffectContext->Release();
this.d2D1EffectContext.Dispose();
this.d2D1Multithread->Leave();
this.d2D1Multithread.Get()->Leave();
_ = this.d2D1Multithread->Release();
// Finally release the multithread object after exiting the lock and releasing all other D2D objects
this.d2D1Multithread.Dispose();
}
NativeMemory.Free(this.resourceId);
@@ -42,7 +42,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return E.E_POINTER;
}
if (@this->d2D1DrawInfo is null)
if (@this->d2D1DrawInfo.Get() is null)
{
return RO.RO_E_CLOSED;
}
@@ -71,7 +71,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return E.E_NOT_VALID_STATE;
}
if (@this->d2D1DrawInfo is null)
if (@this->d2D1DrawInfo.Get() is null)
{
return RO.RO_E_CLOSED;
}
@@ -98,7 +98,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return E.E_INVALIDARG;
}
if (@this->d2D1DrawInfo is null)
if (@this->d2D1DrawInfo.Get() is null)
{
return RO.RO_E_CLOSED;
}
@@ -113,7 +113,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
Buffer.MemoryCopy(buffer, @this->constantBuffer, bufferCount, bufferCount);
// Propagate it to the ID2D1DrawInfo object in use as well
return @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(buffer, bufferCount);
return @this->d2D1DrawInfo.Get()->SetPixelShaderConstantBuffer(buffer, bufferCount);
}
}
}
@@ -10,7 +10,8 @@ unsafe partial struct D2D1DrawInfoUpdateContextImpl
/// <inheritdoc cref="ID2D1DrawInfoUpdateContextInternal.Close"/>
public int Close()
{
this.d2D1DrawInfo = null;
// No need to call Release on the ID2D1DrawInfo object (see notes in the Factory method)
this.d2D1DrawInfo = default;
return S.S_OK;
}
@@ -75,7 +75,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
/// </summary>
private ID2D1DrawInfo* d2D1DrawInfo;
private ComPtr<ID2D1DrawInfo> d2D1DrawInfo;
/// <summary>
/// The factory method for <see cref="D2D1DrawInfoUpdateContextImpl"/> instances.
@@ -109,7 +109,13 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
@this->referenceCount = 1;
@this->constantBuffer = constantBuffer;
@this->constantBufferSize = constantBufferSize;
@this->d2D1DrawInfo = d2D1DrawInfo;
// This ID2D1DrawInfo manager instance is short lived, and the contract guarantees that it will not remain
// alive after the underlying ID2D1DrawInfo instance has been invalidated. As such, we can optimize the
// initialization by skipping the AddRef/Release calls on the ID2D1DrawInfo object, and simply storing the
// pointer to the object. When this instance is closed, that will just be set to null again.
@this->d2D1DrawInfo = default;
@this->d2D1DrawInfo.Attach(d2D1DrawInfo);
*drawInfoUpdateContext = @this;
+11 -16
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Interop.Allocation;
using ComputeSharp.Win32;
using D3D12MA_Allocation = TerraFX.Interop.DirectX.D3D12MA_Allocation;
@@ -47,17 +48,17 @@ internal unsafe struct ID3D12AllocationImpl
/// <summary>
/// The parent <see cref="ID3D12MemoryAllocatorImpl"/> instance.
/// </summary>
private ID3D12MemoryAllocatorImpl* allocatorImpl;
private ComPtr<ID3D12MemoryAllocatorImpl> allocatorImpl;
/// <summary>
/// The wrapped <see cref="D3D12MA_Allocation"/> instance.
/// </summary>
private D3D12MA_Allocation* allocation;
private ComPtr<D3D12MA_Allocation> allocation;
/// <summary>
/// The underlying <see cref="ID3D12Resource"/> instance.
/// </summary>
private ID3D12Resource* d3D12Resource;
private ComPtr<ID3D12Resource> d3D12Resource;
/// <summary>
/// The factory method for <see cref="ID3D12AllocationImpl"/> instances.
@@ -86,15 +87,11 @@ internal unsafe struct ID3D12AllocationImpl
return E.E_OUTOFMEMORY;
}
_ = allocatorImpl->AddRef();
_ = allocation->AddRef();
_ = d3D12Resource->AddRef();
@this->lpVtbl = Vtbl;
@this->referenceCount = 1;
@this->allocatorImpl = allocatorImpl;
@this->allocation = allocation;
@this->d3D12Resource = d3D12Resource;
@this->allocatorImpl = new ComPtr<ID3D12MemoryAllocatorImpl>(allocatorImpl);
@this->allocation = new ComPtr<D3D12MA_Allocation>(allocation);
@this->d3D12Resource = new ComPtr<ID3D12Resource>(d3D12Resource);
*allocationImpl = @this;
@@ -140,15 +137,15 @@ internal unsafe struct ID3D12AllocationImpl
if (referenceCount == 0)
{
_ = @this->allocation->Release();
_ = @this->d3D12Resource->Release();
@this->allocation.Dispose();
@this->d3D12Resource.Dispose();
// Release the parent allocator as well as last thing. This is needed because the D3D12MA allocator
// will fail if an allocator is released while there are still outstanding allocations. So here we
// increment the reference count of the allocator when creating a new allocation object, and then we
// decrement it after the underlying allocation has been released. This means that if this allocation
// is the last thing keeping the allocator alive, it'll be disposed correctly after this last object.
_ = @this->allocatorImpl->Release();
@this->allocatorImpl.Dispose();
NativeMemory.Free(@this);
}
@@ -165,9 +162,7 @@ internal unsafe struct ID3D12AllocationImpl
return E.E_POINTER;
}
_ = @this->d3D12Resource->AddRef();
*resource = @this->d3D12Resource;
@this->d3D12Resource.CopyTo(resource).Assert();
return S.S_OK;
}
+8 -21
ファイルの表示
@@ -51,12 +51,12 @@ internal unsafe struct ID3D12MemoryAllocatorImpl
/// <summary>
/// The <see cref="D3D12MA_Allocator"/> in use associated to the current device.
/// </summary>
private D3D12MA_Allocator* allocator;
private ComPtr<D3D12MA_Allocator> allocator;
/// <summary>
/// The <see cref="D3D12MA_Pool"/> instance in use, if the device is using cache coherent UMA.
/// </summary>
private D3D12MA_Pool* pool;
private ComPtr<D3D12MA_Pool> pool;
/// <summary>
/// The factory method for <see cref="ID3D12MemoryAllocatorImpl"/> instances.
@@ -83,19 +83,10 @@ internal unsafe struct ID3D12MemoryAllocatorImpl
return E.E_OUTOFMEMORY;
}
_ = allocator->AddRef();
// The pool is not necessarily available (it's only used for UMA devices), as it allows creating
// resources in a CPU readable memory region. With non UMA devices, we use the default behavior.
if (pool is not null)
{
_ = pool->AddRef();
}
@this->lpVtbl = Vtbl;
@this->referenceCount = 1;
@this->allocator = allocator;
@this->pool = pool;
@this->allocator = new ComPtr<D3D12MA_Allocator>(allocator);
@this->pool = new ComPtr<D3D12MA_Pool>(pool);
*allocatorImpl = @this;
@@ -122,12 +113,8 @@ internal unsafe struct ID3D12MemoryAllocatorImpl
// must have been disposed already before the allocator is released. This is done by
// having the allocator also increment the reference count of their associated allocator.
// So here we just have to release first the pool, if present, and then the allocator.
if (this.pool is not null)
{
_ = this.pool->Release();
}
_ = this.allocator->Release();
this.pool.Dispose();
this.allocator.Dispose();
NativeMemory.Free(Unsafe.AsPointer(ref this));
}
@@ -190,13 +177,13 @@ internal unsafe struct ID3D12MemoryAllocatorImpl
D3D12MA_ALLOCATION_DESC allocationDesc = default;
allocationDesc.HeapType = (TerraFX.Interop.DirectX.D3D12_HEAP_TYPE)heapType;
allocationDesc.Flags = allocationFlags;
allocationDesc.CustomPool = @this->pool;
allocationDesc.CustomPool = @this->pool.Get();
using ComPtr<D3D12MA_Allocation> d3D12MA_allocation = default;
using ComPtr<ID3D12Resource> d3D12Resource = default;
// Invoke D3D12MA and create an allocation and resource
TerraFX.Interop.Windows.HRESULT hresult = @this->allocator->CreateResource(
TerraFX.Interop.Windows.HRESULT hresult = @this->allocator.Get()->CreateResource(
pAllocDesc: &allocationDesc,
pResourceDesc: (TerraFX.Interop.DirectX.D3D12_RESOURCE_DESC*)resourceDescription,
InitialResourceState: (TerraFX.Interop.DirectX.D3D12_RESOURCE_STATES)resourceStates,
+6 -8
ファイルの表示
@@ -132,7 +132,7 @@ partial class DeviceHelper
/// <summary>
/// The wrapped <see cref="IDXGIFactory4"/> instance.
/// </summary>
private IDXGIFactory4* dxgiFactory4;
private ComPtr<IDXGIFactory4> dxgiFactory4;
/// <summary>
/// Creates and initializes a new <see cref="IDXGIFactory4As6Backcompat"/> instance.
@@ -144,9 +144,7 @@ partial class DeviceHelper
IDXGIFactory4As6Backcompat* @this = (IDXGIFactory4As6Backcompat*)NativeMemory.Alloc((nuint)sizeof(IDXGIFactory4As6Backcompat));
@this->lpVtbl = Vtbl;
@this->dxgiFactory4 = dxgiFactory4;
_ = dxgiFactory4->AddRef();
@this->dxgiFactory4 = new ComPtr<IDXGIFactory4>(dxgiFactory4);
*dxgiFactory6 = (IDXGIFactory6*)@this;
}
@@ -155,7 +153,7 @@ partial class DeviceHelper
[UnmanagedCallersOnly]
private static uint Release(IDXGIFactory4As6Backcompat* @this)
{
_ = @this->dxgiFactory4->Release();
@this->dxgiFactory4.Dispose();
NativeMemory.Free(@this);
@@ -166,21 +164,21 @@ partial class DeviceHelper
[UnmanagedCallersOnly]
private static int EnumAdapters(IDXGIFactory4As6Backcompat* @this, uint Adapter, IDXGIAdapter** ppAdapter)
{
return @this->dxgiFactory4->EnumAdapters(Adapter, ppAdapter);
return @this->dxgiFactory4.Get()->EnumAdapters(Adapter, ppAdapter);
}
/// <inheritdoc cref="IDXGIFactory6.EnumWarpAdapter(Guid*, void**)"/>
[UnmanagedCallersOnly]
private static int EnumWarpAdapter(IDXGIFactory4As6Backcompat* @this, Guid* riid, void** ppvAdapter)
{
return @this->dxgiFactory4->EnumWarpAdapter(riid, ppvAdapter);
return @this->dxgiFactory4.Get()->EnumWarpAdapter(riid, ppvAdapter);
}
/// <inheritdoc cref="IDXGIFactory6.EnumAdapterByGpuPreference(uint, DXGI_GPU_PREFERENCE, Guid*, void**)"/>
[UnmanagedCallersOnly]
private static int EnumAdapterByGpuPreference(IDXGIFactory4As6Backcompat* @this, uint Adapter, DXGI_GPU_PREFERENCE GpuPreference, Guid* riid, void** ppvAdapter)
{
return @this->dxgiFactory4->EnumAdapters1(Adapter, (IDXGIAdapter1**)ppvAdapter);
return @this->dxgiFactory4.Get()->EnumAdapters1(Adapter, (IDXGIAdapter1**)ppvAdapter);
}
}
}