public void UsageAfterDispose(Device device, Type bufferType)
        {
            using TransferTexture2D <float> texture = device.Get().AllocateTransferTexture2D <float>(bufferType, 32, 32);

            texture.Dispose();

            _ = texture.View;
        }
        public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType)
        {
            using TransferTexture2D <float> buffer = device.Get().AllocateTransferTexture2D <float>(bufferType, 128, 256);

            Assert.IsNotNull(buffer);
            Assert.AreEqual(buffer.Width, 128);
            Assert.AreEqual(buffer.Height, 256);
            Assert.AreEqual(buffer.View.Width, 128);
            Assert.AreEqual(buffer.View.Height, 256);
            Assert.AreSame(buffer.GraphicsDevice, device.Get());
        }
    public void ResourceFromTransferTexture2D(Device device, Type bufferType)
    {
        using TransferTexture2D <float> buffer = device.Get().AllocateTransferTexture2D <float>(bufferType, 16, 16);

        using ComPtr <ID3D12Resource> d3D12Resource = default;

        InteropServices.GetID3D12Resource(buffer, Windows.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf());

        Assert.IsTrue(d3D12Resource.Get() != null);
        Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);

        d3D12Resource.Dispose();

        int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof <ID3D12Resource>(), (void **)d3D12Resource.GetAddressOf());

        Assert.AreEqual(hResult, S.S_OK);
        Assert.IsTrue(d3D12Resource.Get() != null);
        Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
    }
示例#4
0
    public void DisposeAfterDevice(Device device, Type textureType)
    {
        GraphicsDevice?gpu = device switch
        {
            Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
            Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(),
            _ => throw new ArgumentException(nameof(device))
        };

        if (gpu is null)
        {
            Assert.Inconclusive();

            return;
        }

        TransferTexture2D <float> texture = gpu.AllocateTransferTexture2D <float>(textureType, 32, 32);

        gpu.Dispose();
        texture.Dispose();
    }
        public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType, AllocationMode allocationMode)
        {
            using TransferTexture2D <float> texture = device.Get().AllocateTransferTexture2D <float>(bufferType, 128, 256, allocationMode);

            Assert.IsNotNull(texture);
            Assert.AreEqual(texture.Width, 128);
            Assert.AreEqual(texture.Height, 256);
            Assert.AreEqual(texture.View.Width, 128);
            Assert.AreEqual(texture.View.Height, 256);
            Assert.AreSame(texture.GraphicsDevice, device.Get());

            if (allocationMode == AllocationMode.Clear)
            {
                for (int y = 0; y < texture.Height; y++)
                {
                    foreach (float x in texture.View.GetRowSpan(y))
                    {
                        Assert.AreEqual(x, 0f);
                    }
                }
            }
        }
示例#6
0
 /// <summary>
 /// Tries to get the underlying COM object for a given resource, as a specified interface. This method invokes
 /// <see href="https://docs.microsoft.com/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(refiid_void)">IUnknown::QueryInterface</see>.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="TransferTexture2D{T}"/> instance in use.</param>
 /// <param name="riid">A reference to the interface identifier (IID) of the resource interface being queried for.</param>
 /// <param name="ppvObject">The address of a pointer to an interface with the IID specified in <paramref name="riid"/>.</param>
 /// <returns>
 /// <c>S_OK</c> if the interface is supported, and <c>E_NOINTERFACE</c> otherwise.
 /// If ppvObject (the address) is nullptr, then this method returns <c>E_POINTER</c>.
 /// </returns>
 public static int TryGetID3D12Resource <T>(TransferTexture2D <T> texture, Guid *riid, void **ppvObject)
     where T : unmanaged
 {
     return(texture.D3D12Resource->QueryInterface(riid, ppvObject));
 }
示例#7
0
 /// <summary>
 /// Gets the underlying COM object for a given resource, as a specified interface. This method invokes
 /// <see href="https://docs.microsoft.com/windows/win32/api/unknwn/nf-unknwn-iunknown-queryinterface(refiid_void)">IUnknown::QueryInterface</see>.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="TransferTexture2D{T}"/> instance in use.</param>
 /// <param name="riid">A reference to the interface identifier (IID) of the resource interface being queried for.</param>
 /// <param name="ppvObject">The address of a pointer to an interface with the IID specified in <paramref name="riid"/>.</param>
 /// <exception cref="Win32Exception">Thrown if the <c>IUnknown::QueryInterface</c> call doesn't return <c>S_OK</c>.</exception>
 public static void GetID3D12Resource <T>(TransferTexture2D <T> texture, Guid *riid, void **ppvObject)
     where T : unmanaged
 {
     texture.D3D12Resource->QueryInterface(riid, ppvObject).Assert();
 }
 public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height)
 {
     using TransferTexture2D <float> texture = device.Get().AllocateTransferTexture2D <float>(bufferType, width, height);
 }
示例#9
0
 /// <summary>
 /// Throws a new <see cref="GraphicsDeviceMismatchException"/> instance from the specified parameters.
 /// </summary>
 /// <typeparam name="T">The type of values in the input buffer.</typeparam>
 /// <param name="texture">The input <see cref="TransferTexture2D{T}"/> that was used.</param>
 /// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
 internal static void Throw <T>(TransferTexture2D <T> texture, GraphicsDevice device)
     where T : unmanaged
 {
     throw Create(texture, texture.GraphicsDevice, device);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransferTexture2DDebugView{T}"/> class with the specified parameters.
 /// </summary>
 /// <param name="texture">The input <see cref="TransferTexture2D{T}"/> instance with the items to display.</param>
 public TransferTexture2DDebugView(TransferTexture2D <T>?texture)
 {
     Items = texture?.View.ToArray();
 }