Merge pull request #659 from Sergio0694/dev/native-library-sample
Add native library sample
このコミットが含まれているのは:
4ファイル変更
+129
検索条件に一致するファイルはありません
@@ -292,6 +292,10 @@ jobs:
|
||||
msbuild samples\ComputeSharp.SwapChain.D2D1.Cli\ComputeSharp.SwapChain.D2D1.Cli.csproj /restore -t:publish /p:Configuration=Release
|
||||
/p:Platform=${{matrix.platform}} /p:RuntimeIdentifier=win-${{matrix.platform}}
|
||||
|
||||
# Publish the native library as a NativeAOT shared library
|
||||
- name: Publish ComputeSharp.NativeLibrary
|
||||
run: dotnet publish samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj -r win-${{matrix.platform}} /p:NativeLib=Shared -v n
|
||||
|
||||
# Download the NuGet packages generated in the previous job and use them
|
||||
# to build and run the sample project referencing them. This is used as
|
||||
# a test to ensure the NuGet packages work in a consuming project.
|
||||
|
||||
@@ -164,6 +164,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "arm64", "arm64", "{B4F6A41C
|
||||
libs\arm64\WinPixEventRuntime_UAP.dll = libs\arm64\WinPixEventRuntime_UAP.dll
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputeSharp.NativeLibrary", "samples\ComputeSharp.NativeLibrary\ComputeSharp.NativeLibrary.csproj", "{1A3E20B3-F711-41C0-82EA-3B53A575955C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -444,6 +446,14 @@ Global
|
||||
{9B4448B1-200F-4966-8A13-A508691B3003}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{9B4448B1-200F-4966-8A13-A508691B3003}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9B4448B1-200F-4966-8A13-A508691B3003}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -481,6 +491,7 @@ Global
|
||||
{59A17380-24A0-4BD7-9012-B105A9E7D46F} = {F8EFBB27-4EE2-4463-A75B-7EFDFB55D0F7}
|
||||
{79FD7862-4707-4DE0-8777-3872558E4C1C} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104}
|
||||
{B4F6A41C-AA9A-4302-92B3-AC64CF2E30F5} = {A5013F9B-92EC-419F-B0B3-3D6B721E7104}
|
||||
{1A3E20B3-F711-41C0-82EA-3B53A575955C} = {0ED8F632-5E17-46BE-8CC3-B14A82D4AEB1}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {4664C5E3-0340-4E22-BCFD-98AAEDF5F2DC}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Platforms>AnyCPU;x64;ARM64</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- NativeAOT configuration -->
|
||||
<PropertyGroup>
|
||||
<PublishAot>true</PublishAot>
|
||||
<UseSystemResourceKeys>true</UseSystemResourceKeys>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<OptimizationPreference>Size</OptimizationPreference>
|
||||
<StackTraceSupport>false</StackTraceSupport>
|
||||
|
||||
<!-- Unsupported size saving options, can be experimented with to investigate binary size -->
|
||||
<IlcFoldIdenticalMethodBodies>false</IlcFoldIdenticalMethodBodies>
|
||||
<IlcDisableReflection>false</IlcDisableReflection>
|
||||
|
||||
<!-- Enable generating files to inspect the binary size with sizoscope (https://github.com/MichalStrehovsky/sizoscope) -->
|
||||
<IlcGenerateMstatFile>true</IlcGenerateMstatFile>
|
||||
<IlcGenerateDgmlFile>true</IlcGenerateDgmlFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1.SourceGenerators\ComputeSharp.D2D1.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
|
||||
<ProjectReference Include="..\..\src\ComputeSharp.D2D1\ComputeSharp.D2D1.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.D2D1;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
[assembly: SupportedOSPlatform("windows6.1")]
|
||||
|
||||
/// <summary>
|
||||
/// Native exports for the library.
|
||||
/// </summary>
|
||||
public static unsafe class Library
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers the <see cref="HelloWorld"/> effect into a target <c>ID2D1Factory1</c> instance.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Factory1"><inheritdoc cref="D2D1PixelShaderEffect.RegisterForD2D1Factory1" path="/param[@name='d2D1Factory1']/node()"/></param>
|
||||
/// <param name="effectId"><inheritdoc cref="D2D1PixelShaderEffect.RegisterForD2D1Factory1" path="/param[@name='effectId']/node()"/></param>
|
||||
/// <returns>The <c>HRESULT</c> for the operation.</returns>
|
||||
[UnmanagedCallersOnly(EntryPoint = nameof(RegisterHelloWorldEffect))]
|
||||
public static int RegisterHelloWorldEffect(void* d2D1Factory1, Guid* effectId)
|
||||
{
|
||||
try
|
||||
{
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<HelloWorld>(d2D1Factory1, out *effectId);
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Marshal.GetHRForException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the constant buffer for the input <c>ID2D1Effect</c> (assumed to be <see cref="HelloWorld"/>).
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect"><inheritdoc cref="D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect" path="/param[@name='d2D1Effect']/node()"/></param>
|
||||
/// <param name="time"><inheritdoc cref="HelloWorld(float, Int2)" path="/param[@name='time']/node()"/></param>
|
||||
/// <param name="dispatchWidth">The horizontal dispatch size for the current output.</param>
|
||||
/// <param name="dispatchHeight">The vertical dispatch size for the current output.</param>
|
||||
/// <returns></returns>
|
||||
[UnmanagedCallersOnly(EntryPoint = nameof(SetHelloWorldEffectConstantBuffer))]
|
||||
public static int SetHelloWorldEffectConstantBuffer(void* d2D1Effect, float time, int dispatchWidth, int dispatchHeight)
|
||||
{
|
||||
try
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(d2D1Effect, new HelloWorld(time, new int2(dispatchWidth, dispatchHeight)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return Marshal.GetHRForException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hello world effect that displays a color gradient.
|
||||
/// </summary>
|
||||
/// <param name="time">The current time since the start of the application.</param>
|
||||
/// <param name="dispatchSize">The dispatch size for the current output.</param>
|
||||
[D2DEffectDisplayName(nameof(HelloWorld))]
|
||||
[D2DEffectDescription("A hello world effect that displays a color gradient.")]
|
||||
[D2DEffectCategory("Render")]
|
||||
[D2DEffectAuthor("ComputeSharp.D2D1")]
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)]
|
||||
[D2DGeneratedPixelShaderDescriptor]
|
||||
internal readonly partial struct HelloWorld(float time, int2 dispatchSize) : ID2D1PixelShader
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
float2 uv = xy / (float2)dispatchSize;
|
||||
float3 color = 0.5f + (0.5f * Hlsl.Cos(time + new float3(uv, uv.X) + new float3(0, 2, 4)));
|
||||
|
||||
return new(color, 1f);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする