Add ComputeSharp.NativeLibrary sample project
このコミットが含まれているのは:
1 親
a98f0d86ef
コミット
d21853b816
3ファイル変更
+131
検索条件に一致するファイルはありません
@@ -0,0 +1,90 @@
|
||||
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.time" path="/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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[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]
|
||||
[AutoConstructor]
|
||||
internal readonly partial struct HelloWorld : ID2D1PixelShader
|
||||
{
|
||||
/// <summary>
|
||||
/// The current time since the start of the application.
|
||||
/// </summary>
|
||||
private readonly float time;
|
||||
|
||||
/// <summary>
|
||||
/// The dispatch size for the current output.
|
||||
/// </summary>
|
||||
private readonly int2 dispatchSize;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
float2 uv = xy / (float2)this.dispatchSize;
|
||||
float3 color = 0.5f + (0.5f * Hlsl.Cos(this.time + new float3(uv, uv.X) + new float3(0, 2, 4)));
|
||||
|
||||
return new(color, 1f);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする