Skip to content

Commit

Permalink
Merge pull request #9 from tannergooding/master
Browse files Browse the repository at this point in the history
Removing dependency on TerraFX.Utilities
  • Loading branch information
tannergooding authored Sep 21, 2019
2 parents da90026 + a973890 commit 31a1dfb
Show file tree
Hide file tree
Showing 356 changed files with 5,818 additions and 6,210 deletions.
1 change: 0 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" />
<PackageReference Update="NUnit" Version="3.12.0" />
<PackageReference Update="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Update="TerraFX.Utilities" Version="0.1.0-alpha-20190917.1" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions samples/DirectX/D3D12/HelloTriangle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using TerraFX.Interop;
using static TerraFX.Interop.D3D_FEATURE_LEVEL;
using static TerraFX.Interop.D3D_PRIMITIVE_TOPOLOGY;
Expand Down Expand Up @@ -43,8 +44,6 @@
using static TerraFX.Interop.Kernel32;
using static TerraFX.Interop.Windows;
using static TerraFX.Samples.DirectX.D3D12.DXSampleHelper;
using static TerraFX.Utilities.ExceptionUtilities;
using static TerraFX.Utilities.InteropUtilities;

namespace TerraFX.Samples.DirectX.D3D12
{
Expand Down Expand Up @@ -475,7 +474,7 @@ private void LoadAssets()
};
}

var vertexBufferSize = SizeOf<Vertex>() * 3;
var vertexBufferSize = (uint)sizeof(Vertex) * 3;

// Note: using upload heaps to transfer static data like vert buffers is not
// recommended. Every time the GPU needs it, the upload heap will be marshalled
Expand Down Expand Up @@ -531,7 +530,7 @@ private void LoadAssets()

// Initialize the vertex buffer view.
_vertexBufferView.BufferLocation = _vertexBuffer->GetGPUVirtualAddress();
_vertexBufferView.StrideInBytes = SizeOf<Vertex>();
_vertexBufferView.StrideInBytes = (uint)sizeof(Vertex);
_vertexBufferView.SizeInBytes = vertexBufferSize;
}

Expand All @@ -548,7 +547,8 @@ private void LoadAssets()
_fenceEvent = CreateEvent(null, FALSE, FALSE, null);
if (_fenceEvent == IntPtr.Zero)
{
ThrowExternalExceptionForLastHRESULT(nameof(CreateEvent));
var hr = Marshal.GetHRForLastWin32Error();
Marshal.ThrowExceptionForHR(hr);
}

// Wait for the command list to execute; we are reusing the same command
Expand Down
5 changes: 3 additions & 2 deletions samples/DirectX/D3D12/HelloWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).

using System;
using System.Runtime.InteropServices;
using TerraFX.Interop;
using static TerraFX.Interop.D3D_FEATURE_LEVEL;
using static TerraFX.Interop.D3D12;
Expand All @@ -21,7 +22,6 @@
using static TerraFX.Interop.Kernel32;
using static TerraFX.Interop.Windows;
using static TerraFX.Samples.DirectX.D3D12.DXSampleHelper;
using static TerraFX.Utilities.ExceptionUtilities;

namespace TerraFX.Samples.DirectX.D3D12
{
Expand Down Expand Up @@ -282,7 +282,8 @@ private void LoadAssets()
_fenceEvent = CreateEvent(null, FALSE, FALSE, null);
if (_fenceEvent == IntPtr.Zero)
{
ThrowExternalExceptionForLastHRESULT(nameof(CreateEvent));
var hr = Marshal.GetHRForLastWin32Error();
Marshal.ThrowExceptionForHR(hr);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions samples/DirectX/D3D12/Shared/DXSampleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using TerraFX.Interop;
using static TerraFX.Interop.Windows;
using static TerraFX.Utilities.ExceptionUtilities;

namespace TerraFX.Samples.DirectX.D3D12
{
Expand All @@ -18,7 +18,7 @@ public static void ThrowIfFailed(string methodName, int hr)
{
if (FAILED(hr))
{
ThrowExternalException(methodName, hr);
Marshal.ThrowExceptionForHR(hr);
}
}

Expand All @@ -38,7 +38,7 @@ public static byte[] ReadDataFromFile(string filename)

if (endOfFile > int.MaxValue)
{
ThrowIOException();
throw new IOException();
}

var size = (int)endOfFile;
Expand Down
9 changes: 4 additions & 5 deletions samples/DirectX/D3D12/Shared/Win32Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
using System;
using System.Runtime.InteropServices;
using TerraFX.Interop;
using TerraFX.Utilities;
using static TerraFX.Interop.User32;
using static TerraFX.Interop.Windows;
using static TerraFX.Utilities.InteropUtilities;

namespace TerraFX.Samples.DirectX.D3D12
{
public static unsafe class Win32Application
{
#region Static Fields
private static readonly NativeDelegate<WNDPROC> s_wndProc = new NativeDelegate<WNDPROC>(WindowProc);
private static readonly WNDPROC s_wndProc = WindowProc;
private static readonly IntPtr s_wndProcHandle = Marshal.GetFunctionPointerForDelegate(s_wndProc);

private static IntPtr s_hwnd;
#endregion
Expand All @@ -42,9 +41,9 @@ public static int Run(DXSample pSample, IntPtr hInstance, int nCmdShow)
{
// Initialize the window class.
var windowClass = new WNDCLASSEX {
cbSize = SizeOf<WNDCLASSEX>(),
cbSize = (uint)sizeof(WNDCLASSEX),
style = CS_HREDRAW | CS_VREDRAW,
lpfnWndProc = s_wndProc,
lpfnWndProc = s_wndProcHandle,
hInstance = hInstance,
hCursor = LoadCursor(IntPtr.Zero, (char*)IDC_ARROW),
lpszClassName = lpszClassName
Expand Down
25 changes: 25 additions & 0 deletions sources/Interop/Windows/NativeTypeNameAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Diagnostics;

namespace TerraFX.Interop
{
/// <summary>Defines the type of a member as it was used in the native signature.</summary>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
[Conditional("DEBUG")]
public sealed class NativeTypeNameAttribute : Attribute
{
private readonly string _name;

/// <summary>Initializes a new instance of the <see cref="NativeTypeNameAttribute" /> class.</summary>
/// <param name="name">The name of the type that was used in the native signature.</param>
public NativeTypeNameAttribute(string name)
{
_name = name;
}

/// <summary>Gets the name of the type that was used in the native signature.</summary>
public string Name => _name;
}
}
8 changes: 2 additions & 6 deletions sources/Interop/Windows/TerraFX.Interop.Windows.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. -->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<NoWarn>1573;1591;$(NoWarn)</NoWarn>
<RootNamespace>TerraFX.Interop</RootNamespace>
<TargetFrameworks>netcoreapp3.0;netstandard2.0</TargetFrameworks>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TerraFX.Utilities" />
</ItemGroup>

</Project>
19 changes: 0 additions & 19 deletions sources/Interop/Windows/helper/Windows.cs

This file was deleted.

21 changes: 10 additions & 11 deletions sources/Interop/Windows/shared/dxgi/IDXGIAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System;
using System.Runtime.InteropServices;
using System.Security;
using static TerraFX.Utilities.InteropUtilities;

namespace TerraFX.Interop
{
Expand Down Expand Up @@ -119,7 +118,7 @@ [Out] void** ppvObject
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_QueryInterface>(lpVtbl->QueryInterface)(
return Marshal.GetDelegateForFunctionPointer<_QueryInterface>(lpVtbl->QueryInterface)(
This,
riid,
ppvObject
Expand All @@ -132,7 +131,7 @@ public uint AddRef()
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_AddRef>(lpVtbl->AddRef)(
return Marshal.GetDelegateForFunctionPointer<_AddRef>(lpVtbl->AddRef)(
This
);
}
Expand All @@ -143,7 +142,7 @@ public uint Release()
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_Release>(lpVtbl->Release)(
return Marshal.GetDelegateForFunctionPointer<_Release>(lpVtbl->Release)(
This
);
}
Expand All @@ -160,7 +159,7 @@ [In] void* pData
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_SetPrivateData>(lpVtbl->SetPrivateData)(
return Marshal.GetDelegateForFunctionPointer<_SetPrivateData>(lpVtbl->SetPrivateData)(
This,
Name,
DataSize,
Expand All @@ -177,7 +176,7 @@ public int SetPrivateDataInterface(
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_SetPrivateDataInterface>(lpVtbl->SetPrivateDataInterface)(
return Marshal.GetDelegateForFunctionPointer<_SetPrivateDataInterface>(lpVtbl->SetPrivateDataInterface)(
This,
Name,
pUnknown
Expand All @@ -194,7 +193,7 @@ [Out] void* pData
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_GetPrivateData>(lpVtbl->GetPrivateData)(
return Marshal.GetDelegateForFunctionPointer<_GetPrivateData>(lpVtbl->GetPrivateData)(
This,
Name,
pDataSize,
Expand All @@ -211,7 +210,7 @@ [Out] void** ppParent
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_GetParent>(lpVtbl->GetParent)(
return Marshal.GetDelegateForFunctionPointer<_GetParent>(lpVtbl->GetParent)(
This,
riid,
ppParent
Expand All @@ -229,7 +228,7 @@ public int EnumOutputs(
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_EnumOutputs>(lpVtbl->EnumOutputs)(
return Marshal.GetDelegateForFunctionPointer<_EnumOutputs>(lpVtbl->EnumOutputs)(
This,
Output,
ppOutput
Expand All @@ -244,7 +243,7 @@ [Out] DXGI_ADAPTER_DESC* pDesc
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_GetDesc>(lpVtbl->GetDesc)(
return Marshal.GetDelegateForFunctionPointer<_GetDesc>(lpVtbl->GetDesc)(
This,
pDesc
);
Expand All @@ -259,7 +258,7 @@ [Out] LARGE_INTEGER* pUMDVersion
{
fixed (IDXGIAdapter* This = &this)
{
return MarshalFunction<_CheckInterfaceSupport>(lpVtbl->CheckInterfaceSupport)(
return Marshal.GetDelegateForFunctionPointer<_CheckInterfaceSupport>(lpVtbl->CheckInterfaceSupport)(
This,
InterfaceName,
pUMDVersion
Expand Down
Loading

0 comments on commit 31a1dfb

Please sign in to comment.