Skip to content

Commit 6387cb7

Browse files
DiligentCore.NET: Base implementation
1 parent 0a8ea61 commit 6387cb7

38 files changed

+2787
-6
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build NuGet package
2+
3+
on: [push, pull_request]
4+
5+
env:
6+
MSBuildEnableWorkloadResolver: false
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
toolset: [x64]
13+
config: [Debug, Release]
14+
15+
runs-on: windows-latest
16+
name: Windows 10, ${{ matrix.config }} ${{ matrix.toolset }}
17+
18+
steps:
19+
- name: Clone repository
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
submodules: recursive
24+
- name: Build and run
25+
working-directory: ${{github.workspace}}
26+
run: python dotnet-build-package.py -c ${{matrix.config}} --dotnet-tests --free-memory
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish NuGet package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
MSBuildEnableWorkloadResolver: false
10+
NUGET_SOURCE_URL: 'https://api.nuget.org/v3/index.json'
11+
12+
jobs:
13+
deploy:
14+
runs-on: windows-latest
15+
name: Deploying NuGet package
16+
17+
steps:
18+
- name: Clone repository
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
submodules: recursive
23+
- name: Build and run
24+
working-directory: ${{github.workspace}}
25+
run: python dotnet-build-package.py -c Release --dotnet-publish
26+
27+
- name: Publish NuGet package
28+
run: dotnet nuget push *.nupkg -k ${{secrets.NUGET_AUTH_TOKEN}} -s ${{env.NUGET_SOURCE_URL}}
29+
working-directory: ${{github.workspace}}/build/.NET/Graphics/GraphicsEngine.NET/bin/Release

BuildTools/FormatValidation/validate_format_win.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ python clang-format-validate.py --color never --clang-format-executable clang-fo
33
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions.h ^
44
--exclude ../../Graphics/HLSL2GLSLConverterLib/include/GLSLDefinitions_inc.h ^
55
--exclude ../../Graphics/GraphicsEngineVulkan/shaders/* ^
6+
--exclude ../../Graphics/GraphicsEngine.NET/* ^
67
--exclude ../../Tests/DiligentCoreAPITest/assets/*

Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<PropertyGroup>
3+
<RelativeProjectPath>$([MSBuild]::MakeRelative('$(MSBuildThisFileDirectory)', '$(MSBuildProjectDirectory)'))</RelativeProjectPath>
4+
<BaseProjectPath>$(MSBuildThisFileDirectory)/build/.NET/$(RelativeProjectPath)</BaseProjectPath>
5+
<OutputPath>$(BaseProjectPath)/bin/$(Platform)/$(Configuration)</OutputPath>
6+
<BaseIntermediateOutputPath>$(BaseProjectPath)/obj</BaseIntermediateOutputPath>
7+
</PropertyGroup>
8+
</Project>

Directory.Packages.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
7+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.4.5" />
8+
<PackageVersion Include="xunit" Version="2.4.2" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2019-2023 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
using System;
28+
using System.Runtime.CompilerServices;
29+
using System.Runtime.InteropServices;
30+
31+
namespace Diligent;
32+
33+
public partial struct ShaderUnpackInfo
34+
{
35+
public delegate void ModifyShaderDelegate(ref ShaderDesc desc);
36+
37+
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
38+
internal static unsafe void ModifyShaderDescImpl(IntPtr nativeDesc, IntPtr userData)
39+
{
40+
ShaderDesc desc = default;
41+
desc.__MarshalFrom(ref *(ShaderDesc.__Native*)nativeDesc);
42+
Marshal.GetDelegateForFunctionPointer<ModifyShaderDelegate>(userData)(ref desc);
43+
desc.__MarshalTo(ref *(ShaderDesc.__Native*)nativeDesc);
44+
}
45+
}
46+
47+
public partial struct PipelineStateUnpackInfo
48+
{
49+
public delegate void ModifyPipelineStateDelegate(PipelineStateCreateInfo createInfo);
50+
51+
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
52+
internal static unsafe void ModifyPipelineStateCreateInfoImpl(IntPtr nativeCI, IntPtr userData)
53+
{
54+
// TODO DRY
55+
switch (((PipelineStateCreateInfo.__Native*)nativeCI)->PSODesc.PipelineType)
56+
{
57+
case PipelineType.Mesh:
58+
case PipelineType.Graphics:
59+
{
60+
var pipelineCI = new GraphicsPipelineStateCreateInfo(ref *(GraphicsPipelineStateCreateInfo.__Native*)nativeCI);
61+
Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI);
62+
pipelineCI.__MarshalTo(ref *(GraphicsPipelineStateCreateInfo.__Native*)nativeCI);
63+
break;
64+
}
65+
case PipelineType.Compute:
66+
{
67+
var pipelineCI = new ComputePipelineStateCreateInfo(ref *(ComputePipelineStateCreateInfo.__Native*)nativeCI);
68+
Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI);
69+
pipelineCI.__MarshalTo(ref *(ComputePipelineStateCreateInfo.__Native*)nativeCI);
70+
break;
71+
}
72+
case PipelineType.RayTracing:
73+
{
74+
var pipelineCI = new RayTracingPipelineStateCreateInfo(ref *(RayTracingPipelineStateCreateInfo.__Native*)nativeCI);
75+
Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI);
76+
pipelineCI.__MarshalTo(ref *(RayTracingPipelineStateCreateInfo.__Native*)nativeCI);
77+
break;
78+
}
79+
case PipelineType.Tile:
80+
{
81+
var pipelineCI = new TilePipelineStateCreateInfo(ref *(TilePipelineStateCreateInfo.__Native*)nativeCI);
82+
Marshal.GetDelegateForFunctionPointer<ModifyPipelineStateDelegate>(userData)(pipelineCI);
83+
pipelineCI.__MarshalTo(ref *(TilePipelineStateCreateInfo.__Native*)nativeCI);
84+
break;
85+
}
86+
default:
87+
throw new InvalidOperationException();
88+
}
89+
}
90+
}
91+
92+
public partial struct RenderPassUnpackInfo
93+
{
94+
public delegate void ModifyRenderPassDelegate(ref RenderPassDesc desc);
95+
96+
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
97+
internal static unsafe void ModifyRenderPassDescImpl(IntPtr nativeDesc, IntPtr userData)
98+
{
99+
var desc = new RenderPassDesc { };
100+
desc.__MarshalFrom(ref *(RenderPassDesc.__Native*)nativeDesc);
101+
Marshal.GetDelegateForFunctionPointer<ModifyRenderPassDelegate>(userData)(ref desc);
102+
desc.__MarshalTo(ref *(RenderPassDesc.__Native*)nativeDesc);
103+
}
104+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright 2019-2023 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
using System;
28+
using System.Runtime.CompilerServices;
29+
using System.Runtime.InteropServices;
30+
31+
namespace Diligent;
32+
33+
public partial class IDeviceContext
34+
{
35+
public unsafe Span<T> MapBuffer<T>(IBuffer buffer, MapType mapTypes, MapFlags mapFlags) where T : unmanaged
36+
{
37+
var data = new Span<byte>(MapBuffer(buffer, mapTypes, mapFlags).ToPointer(), (int)buffer.GetDesc().Size);
38+
return MemoryMarshal.Cast<byte, T>(data);
39+
}
40+
41+
public unsafe void SetVertexBuffers(uint startSlot, IBuffer[] buffers, ulong[] offsets, ResourceStateTransitionMode stateTransitionMode, SetVertexBuffersFlags flags = SetVertexBuffersFlags.None)
42+
{
43+
var ppBuffers = stackalloc IntPtr[buffers.Length];
44+
for (var i = 0; i < buffers.Length; i++)
45+
ppBuffers[i] = buffers[i]?.NativePointer ?? IntPtr.Zero;
46+
47+
fixed (ulong* pOffsets = offsets)
48+
SetVertexBuffers(startSlot, (uint)buffers.Length, ppBuffers, pOffsets, stateTransitionMode, flags);
49+
GC.KeepAlive(buffers);
50+
}
51+
52+
public unsafe void SetRenderTargets(ITextureView[] renderTargetViews, ITextureView depthStencilView, ResourceStateTransitionMode mode)
53+
{
54+
var ppRTVs = stackalloc IntPtr[renderTargetViews?.Length ?? 0];
55+
for (var i = 0; i < renderTargetViews?.Length; i++)
56+
ppRTVs[i] = renderTargetViews[i]?.NativePointer ?? IntPtr.Zero;
57+
SetRenderTargets((uint)(renderTargetViews?.Length ?? 0), ppRTVs, depthStencilView, mode);
58+
GC.KeepAlive(renderTargetViews);
59+
}
60+
61+
public unsafe void UpdateBuffer<T>(IBuffer buffer, ulong offset, ReadOnlySpan<T> data, ResourceStateTransitionMode stateTransitionMode) where T : unmanaged
62+
{
63+
fixed (T* dataPtr = data)
64+
UpdateBuffer(buffer, offset, (ulong)(Unsafe.SizeOf<T>() * data.Length), new(dataPtr), stateTransitionMode);
65+
}
66+
67+
public unsafe void ExecuteCommandLists(ICommandList[] commandLists)
68+
{
69+
var ppCmdLists = stackalloc IntPtr[commandLists.Length];
70+
for (var i = 0; i < commandLists.Length; i++)
71+
ppCmdLists[i] = commandLists[i].NativePointer;
72+
ExecuteCommandLists((uint)commandLists.Length, ppCmdLists);
73+
GC.KeepAlive(commandLists);
74+
}
75+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Diligent-SharpGenTools.Sdk" Version="2.0.3" />
3+
<Import Project="$(BaseProjectPath)/Version.props" />
4+
<PropertyGroup>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<Platforms>x86;x64</Platforms>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
9+
<Version>$(PackageGitVersion)</Version>
10+
<PackageProjectUrl>https://github.com/DiligentGraphics/DiligentCore</PackageProjectUrl>
11+
<RepositoryUrl>https://github.com/DiligentGraphics/DiligentCore</RepositoryUrl>
12+
<RepositoryType>git</RepositoryType>
13+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
14+
<Company>Diligent Graphics LLC</Company>
15+
<Copyright>(c) 2019-2023 Diligent Graphics LLC</Copyright>
16+
<Tags>Graphics;Vulkan;D3D11;D3D12;OpenGL;CPlusPlus</Tags>
17+
<IncludeSymbols>true</IncludeSymbols>
18+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<SharpGenMapping Include="Mapping.xml" />
23+
</ItemGroup>
24+
25+
<ItemGroup>
26+
<Content Include="$(PackageId).targets">
27+
<PackagePath>build</PackagePath>
28+
<Pack>true</Pack>
29+
</Content>
30+
<None Include="$(BaseProjectPath)/bin/x86/$(Configuration)/$(TargetFramework)/$(ProjectName).dll">
31+
<PackagePath>lib/$(TargetFramework)/x86/$(ProjectName).dll</PackagePath>
32+
<Visible>false</Visible>
33+
<Pack>true</Pack>
34+
</None>
35+
<None Include="$(BaseProjectPath)/bin/x64/$(Configuration)/$(TargetFramework)/$(ProjectName).dll">
36+
<PackagePath>lib/$(TargetFramework)/x64/$(ProjectName).dll</PackagePath>
37+
<Visible>false</Visible>
38+
<Pack>true</Pack>
39+
</None>
40+
<Content Include="$(BaseProjectPath)/native/win-x86/**">
41+
<Visible>false</Visible>
42+
<PackagePath>runtimes/win-x86/native</PackagePath>
43+
<Pack>true</Pack>
44+
</Content>
45+
<Content Include="$(BaseProjectPath)/native/win-x64/**">
46+
<Visible>false</Visible>
47+
<PackagePath>runtimes/win-x64/native</PackagePath>
48+
<Pack>true</Pack>
49+
</Content>
50+
</ItemGroup>
51+
52+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project>
2+
<Target Name="PlatformCheck" BeforeTargets="InjectReference"
3+
Condition="(('$(Platform)' != 'x86') AND ('$(Platform)' != 'x64'))">
4+
<Error Text="$(MSBuildThisFileName) does not work correctly on '$(Platform)' platform. You need to specify platform (x86 or x64)." />
5+
</Target>
6+
<Target Name="InjectReference" BeforeTargets="ResolveAssemblyReferences">
7+
<Message Text="Copy platform specific dll: $(MSBuildThisFileDirectory)../lib/net6.0/$(Platform)/Diligent-GraphicsEngine.NET.dll" Importance="High" />
8+
<Copy SourceFiles="$(MSBuildThisFileDirectory)../lib/net6.0/$(Platform)/Diligent-GraphicsEngine.NET.dll"
9+
DestinationFolder="$(MSBuildThisFileDirectory)../lib/net6.0/" />
10+
11+
</Target>
12+
</Project>

0 commit comments

Comments
 (0)