Add ID3DInclude implementation for d2deffecthelpers.hlsli

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:46 +02:00
1 親 f0f52d4670
コミット f9ffb665c6
9ファイル変更
+530 -5

検索条件に一致するファイルはありません

@@ -10,8 +10,10 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics.CodeAnalysis\DoesNotReturnAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime.CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.NetStandard\System\Runtime\CompilerServices\IsExternalInit.cs" Link="System\Runtime.CompilerServices\IsExternalInit.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.NetStandard\System\Runtime\InteropServices\NativeMemory.cs" Link="System\Runtime\InteropServices\NativeMemory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.NetStandard\System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" Link="System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\ComputeSharp.NetStandard\System\Runtime\CompilerServices\IsExternalInit.cs" Link="System\Runtime\CompilerServices\IsExternalInit.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Text\EncodingExtensions.cs" />
</ItemGroup>
</Project>
+6
ファイルの表示
@@ -5,6 +5,12 @@
<DocumentationFile>ComputeSharp.D2D1Interop.xml</DocumentationFile>
<Platforms>AnyCPU;x64;ARM64</Platforms>
</PropertyGroup>
<ItemGroup>
<None Remove="Shaders\Translation\Headers\d2d1effecthelpers.hlsli" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Shaders\Translation\Headers\d2d1effecthelpers.hlsli" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.Core\ComputeSharp.Core.csproj" />
+149
ファイルの表示
@@ -0,0 +1,149 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if NET6_0_OR_GREATER
using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
#else
using RuntimeHelpers = ComputeSharp.D2D1Interop.NetStandard.System.Runtime.CompilerServices.RuntimeHelpers;
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
#endif
namespace ComputeSharp.D2D1Interop.Shaders.Translation;
/// <inheritdoc/>
partial class D2D1ShaderCompiler
{
/// <summary>
/// A custom <see cref="ID3DInclude"/> fallback implementation to use on systems with no support for it.
/// </summary>
private unsafe struct ID3DIncludeForD2DHelpers
{
#if !NET6_0_OR_GREATER
/// <inheritdoc cref="Open"/>
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int OpenDelegate(ID3DIncludeForD2DHelpers* @this, D3D_INCLUDE_TYPE IncludeType, sbyte* pFileName, void* pParentData, void** ppData, uint* pBytes);
/// <inheritdoc cref="Close"/>
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int CloseDelegate(ID3DIncludeForD2DHelpers* @this, void* pData);
/// <summary>
/// A cached <see cref="OpenDelegate"/> instance wrapping <see cref="Open"/>.
/// </summary>
private static readonly OpenDelegate OpenWrapper = Open;
/// <summary>
/// A cached <see cref="CloseDelegate"/> instance wrapping <see cref="Close"/>.
/// </summary>
private static readonly CloseDelegate CloseWrapper = Close;
#endif
/// <summary>
/// The shared method table pointer for all <see cref="ID3DIncludeForD2DHelpers"/> instances.
/// </summary>
private static readonly void** Vtbl = InitVtbl();
/// <summary>
/// A pointer to a buffer with the contents of <c>d2d1effecthelpers.hlsli</c>.
/// </summary>
private static void* d2D1EffectHelpersData;
/// <summary>
/// The size of the buffer in <see cref="d2D1EffectHelpersData"/>.
/// </summary>
private static int d2D1EffectHelpersSize;
/// <summary>
/// Builds the custom method table pointer for <see cref="ID3DIncludeForD2DHelpers"/>.
/// </summary>
/// <returns>The method table pointer for <see cref="ID3DIncludeForD2DHelpers"/>.</returns>
private static void** InitVtbl()
{
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(ID3DIncludeForD2DHelpers), sizeof(void*) * 2);
#if NET6_0_OR_GREATER
lpVtbl[0] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, D3D_INCLUDE_TYPE, sbyte*, void*, void**, uint*, int>)&Open;
lpVtbl[1] = (delegate* unmanaged<ID3DIncludeForD2DHelpers*, void*, int>)&Close;
#else
lpVtbl[0] = (void*)Marshal.GetFunctionPointerForDelegate(OpenWrapper);
lpVtbl[1] = (void*)Marshal.GetFunctionPointerForDelegate(CloseWrapper);
#endif
return lpVtbl;
}
/// <summary>
/// The method table pointer for the current instance.
/// </summary>
private void** lpVtbl;
/// <summary>
/// Creates and initializes a new <see cref="ID3DIncludeForD2DHelpers"/> instance.
/// </summary>
/// <returns>A pointer to a new <see cref="ID3DIncludeForD2DHelpers"/> instance.</returns>
public static ID3DIncludeForD2DHelpers* Create()
{
ID3DIncludeForD2DHelpers* @this = (ID3DIncludeForD2DHelpers*)NativeMemory.Alloc((nuint)sizeof(ID3DIncludeForD2DHelpers));
@this->lpVtbl = Vtbl;
return @this;
}
/// <inheritdoc cref="ID3DInclude.Open"/>
[UnmanagedCallersOnly]
public static int Open(ID3DIncludeForD2DHelpers* @this, D3D_INCLUDE_TYPE IncludeType, sbyte* pFileName, void* pParentData, void** ppData, uint* pBytes)
{
if (new string(pFileName) == "d2d1effecthelpers.hlsli")
{
// Load the header if needed
if (d2D1EffectHelpersData is null)
{
d2D1EffectHelpersData = LoadD2D1EffectHelpersHeader(out d2D1EffectHelpersSize);
}
*ppData = d2D1EffectHelpersData;
*pBytes = (uint)d2D1EffectHelpersSize;
return S.S_OK;
}
return S.S_FALSE;
}
/// <inheritdoc cref="ID3DInclude.Close"/>
[UnmanagedCallersOnly]
public static int Close(ID3DIncludeForD2DHelpers* @this, void* pData)
{
return S.S_OK;
}
/// <summary>
/// Loads the <c>d2d1effecthelpers.hlsli</c> header into a persistent buffer.
/// </summary>
/// <param name="size">The size of the header.</param>
/// <returns>A pointer to a buffer with the contents of <c>d2d1effecthelpers.hlsli</c>.</returns>
private static void* LoadD2D1EffectHelpersHeader(out int size)
{
const string headerFilename = "ComputeSharp.D2D1Interop.Shaders.Translation.Headers.d2d1effecthelpers.hlsli";
using Stream source = Assembly.GetExecutingAssembly().GetManifestResourceStream(headerFilename)!;
using MemoryStream destination = new();
source.CopyTo(destination);
byte[] buffer = destination.GetBuffer();
size = (int)destination.Position;
void* pointer = NativeMemory.Alloc((nuint)size);
buffer.AsSpan(0, size).CopyTo(new Span<byte>(pointer, size));
return pointer;
}
}
}
+8 -3
ファイルの表示
@@ -19,8 +19,13 @@ namespace ComputeSharp.D2D1Interop.Shaders.Translation;
/// <summary>
/// A <see langword="class"/> that uses the FXC APIs to compile D2D1 pixel shaders.
/// </summary>
internal static unsafe class D2D1ShaderCompiler
internal static unsafe partial class D2D1ShaderCompiler
{
/// <summary>
/// The <see cref="ID3DInclude"/> instance to load <c>d2d1effecthelpers.hlsli</c>.
/// </summary>
private static readonly ID3DIncludeForD2DHelpers* D3DIncludeForD2D1EffectHelpers = ID3DIncludeForD2DHelpers.Create();
/// <summary>
/// Compiles a new HLSL shader from the input source code.
/// </summary>
@@ -88,7 +93,7 @@ internal static unsafe class D2D1ShaderCompiler
SrcDataSize: (nuint)writtenBytes,
pSourceName: null,
pDefines: macros,
pInclude: null,
pInclude: D3DIncludeForD2D1EffectHelpers,
pEntrypoint: (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.Execute)),
pTarget: (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.ps_5_0)),
Flags1: D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS,
@@ -153,7 +158,7 @@ internal static unsafe class D2D1ShaderCompiler
SrcDataSize: (nuint)writtenBytes,
pSourceName: null,
pDefines: macros,
pInclude: null,
pInclude: D3DIncludeForD2D1EffectHelpers,
pEntrypoint: null,
pTarget: (sbyte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(ASCII.lib_5_0)),
Flags1: D3DCOMPILE.D3DCOMPILE_OPTIMIZATION_LEVEL3 | D3DCOMPILE.D3DCOMPILE_WARNINGS_ARE_ERRORS,
+316
ファイルの表示
@@ -0,0 +1,316 @@
//---------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This file is automatically generated. Please do not edit it directly.
//
//---------------------------------------------------------------------------
// File contents:
// - Helpers methods for authoring D2D Effect shader code.
// These are located at the end of the file (D2DGetInput, etc.).
// - The top portion contains definitions and initialization required by the helpers.
// These elements are prefaced with "__D2D" and can be safely ignored.
//
// To use these helpers, the following values must be defined before inclusion:
// D2D_INPUT_COUNT - The number of texture inputs to the effect.
// D2D_INPUT[N]_SIMPLE or D2D_INPUT[N]_COMPLEX - How the effect will sample each input. (If unspecificed, defaults to _COMPLEX.)
// D2D_ENTRY - The name of the entry point being compiled. This will usually be defined on the command line at compilation time.
//
// The following values can be optionally defined:
// D2D_FUNCTION - Compile the entry point as an export function. This will usually be defined on the command line at compilation time.
// D2D_FULL_SHADER - Compile the entry point as a full shader. This will usually be defined on the command line at compilation time.
// D2D_FULL_SHADER_ONLY - Only compile the in-scope entry points to full shaders, never to export functions.
//
#define __D2D_DEFINE_PS_GLOBALS(inputIndex) \
Texture2D<float4> InputTexture##inputIndex : register(t##inputIndex); \
SamplerState InputSampler##inputIndex : register(s##inputIndex); \
// Define a texture and sampler pair for each D2D effect input.
#if (D2D_INPUT_COUNT >= 1)
__D2D_DEFINE_PS_GLOBALS(0)
#endif
#if (D2D_INPUT_COUNT >= 2)
__D2D_DEFINE_PS_GLOBALS(1)
#endif
#if (D2D_INPUT_COUNT >= 3)
__D2D_DEFINE_PS_GLOBALS(2)
#endif
#if (D2D_INPUT_COUNT >= 4)
__D2D_DEFINE_PS_GLOBALS(3)
#endif
#if (D2D_INPUT_COUNT >= 5)
__D2D_DEFINE_PS_GLOBALS(4)
#endif
#if (D2D_INPUT_COUNT >= 6)
__D2D_DEFINE_PS_GLOBALS(5)
#endif
#if (D2D_INPUT_COUNT >= 7)
__D2D_DEFINE_PS_GLOBALS(6)
#endif
#if (D2D_INPUT_COUNT >= 8)
__D2D_DEFINE_PS_GLOBALS(7)
#endif
#define __D2D_MAXIMUM_INPUT_COUNT 8
// Validate that all required shader information has been defined.
#ifndef D2D_INPUT_COUNT
#error D2D_INPUT_COUNT is undefined.
#endif
#if (D2D_INPUT_COUNT > __D2D_MAXIMUM_INPUT_COUNT)
#error D2D_INPUT_COUNT exceeds the maximum input count.
#endif
// Define global statics to hold the values needed by intrinsic methods.
// These values are initialized by the entry point wrapper before calling into the
// effect's shader implementation.
#if !defined(D2D_FUNCTION) || defined(D2D_REQUIRES_SCENE_POSITION)
static float4 __d2dstatic_scenePos = float4(0, 0, 0, 0);
#endif
#define __D2D_DEFINE_INPUT_STATICS(inputIndex) \
static float4 __d2dstatic_input##inputIndex = float4(0, 0, 0, 0); \
static float4 __d2dstatic_uv##inputIndex = float4(0, 0, 0, 0); \
#if (D2D_INPUT_COUNT >= 1)
__D2D_DEFINE_INPUT_STATICS(0)
#endif
#if (D2D_INPUT_COUNT >= 2)
__D2D_DEFINE_INPUT_STATICS(1)
#endif
#if (D2D_INPUT_COUNT >= 3)
__D2D_DEFINE_INPUT_STATICS(2)
#endif
#if (D2D_INPUT_COUNT >= 4)
__D2D_DEFINE_INPUT_STATICS(3)
#endif
#if (D2D_INPUT_COUNT >= 5)
__D2D_DEFINE_INPUT_STATICS(4)
#endif
#if (D2D_INPUT_COUNT >= 6)
__D2D_DEFINE_INPUT_STATICS(5)
#endif
#if (D2D_INPUT_COUNT >= 7)
__D2D_DEFINE_INPUT_STATICS(6)
#endif
#if (D2D_INPUT_COUNT >= 8)
__D2D_DEFINE_INPUT_STATICS(7)
#endif
// Define the scene position parameter according to whether the shader requires it,
// and whether it is the only parameter.
// The scene position input always needs to be defined for full shaders.
#if (!defined(D2D_FUNCTION) || defined(D2D_REQUIRES_SCENE_POSITION))
#if (D2D_INPUT_COUNT == 0)
#define __D2D_SCENE_POS float4 __d2dinput_scenePos : SCENE_POSITION
#define __D2D_INIT_STATIC_SCENE_POS __d2dstatic_scenePos = __d2dinput_scenePos
#else
#define __D2D_SCENE_POS float4 __d2dinput_scenePos : SCENE_POSITION,
#define __D2D_INIT_STATIC_SCENE_POS __d2dstatic_scenePos = __d2dinput_scenePos;
#endif
#else
#define __D2D_SCENE_POS
#define __D2D_INIT_STATIC_SCENE_POS
#endif
// When compiling a function version, simple and complex inputs have different definitions.
// When compiling a full shader, they have the same definition.
// Access to input parameters also differs between functions and full shaders.
#if defined(D2D_FUNCTION)
#define __D2D_SIMPLE_INPUT(index) float4 __d2dinput_color##index : INPUT##index
#define __D2D_INIT_SIMPLE_STATIC(index) __d2dstatic_input##index = __d2dinput_color##index
#else
#define __D2D_SIMPLE_INPUT(index) float4 __d2dinput_uv##index : TEXCOORD##index
#define __D2D_INIT_SIMPLE_STATIC(index) __d2dstatic_uv##index = __d2dinput_uv##index
#endif
#define __D2D_COMPLEX_INPUT(index) float4 __d2dinput_uv##index : TEXCOORD##index
#define __D2D_INIT_COMPLEX_STATIC(index) __d2dstatic_uv##index = __d2dinput_uv##index
#define __D2D_SAMPLE_INPUT(index) InputTexture##index.Sample(InputSampler##index, __d2dstatic_uv##index.xy)
// Define each input as either simple or complex.
#if defined(D2D_INPUT0_SIMPLE)
#define __D2D_INPUT0 __D2D_SIMPLE_INPUT(0)
#define __D2D_INIT_STATIC0 __D2D_INIT_SIMPLE_STATIC(0)
#define __D2D_GET_INPUT0 __d2dstatic_input0
#else
#define __D2D_INPUT0 __D2D_COMPLEX_INPUT(0)
#define __D2D_INIT_STATIC0 __D2D_INIT_COMPLEX_STATIC(0)
#define __D2D_GET_INPUT0 __D2D_SAMPLE_INPUT(0)
#endif
#if defined(D2D_INPUT1_SIMPLE)
#define __D2D_INPUT1 __D2D_SIMPLE_INPUT(1)
#define __D2D_INIT_STATIC1 __D2D_INIT_SIMPLE_STATIC(1)
#define __D2D_GET_INPUT1 __d2dstatic_input1
#else
#define __D2D_INPUT1 __D2D_COMPLEX_INPUT(1)
#define __D2D_INIT_STATIC1 __D2D_INIT_COMPLEX_STATIC(1)
#define __D2D_GET_INPUT1 __D2D_SAMPLE_INPUT(1)
#endif
#if defined(D2D_INPUT2_SIMPLE)
#define __D2D_INPUT2 __D2D_SIMPLE_INPUT(2)
#define __D2D_INIT_STATIC2 __D2D_INIT_SIMPLE_STATIC(2)
#define __D2D_GET_INPUT2 __d2dstatic_input2
#else
#define __D2D_INPUT2 __D2D_COMPLEX_INPUT(2)
#define __D2D_INIT_STATIC2 __D2D_INIT_COMPLEX_STATIC(2)
#define __D2D_GET_INPUT2 __D2D_SAMPLE_INPUT(2)
#endif
#if defined(D2D_INPUT3_SIMPLE)
#define __D2D_INPUT3 __D2D_SIMPLE_INPUT(3)
#define __D2D_INIT_STATIC3 __D2D_INIT_SIMPLE_STATIC(3)
#define __D2D_GET_INPUT3 __d2dstatic_input3
#else
#define __D2D_INPUT3 __D2D_COMPLEX_INPUT(3)
#define __D2D_INIT_STATIC3 __D2D_INIT_COMPLEX_STATIC(3)
#define __D2D_GET_INPUT3 __D2D_SAMPLE_INPUT(3)
#endif
#if defined(D2D_INPUT4_SIMPLE)
#define __D2D_INPUT4 __D2D_SIMPLE_INPUT(4)
#define __D2D_INIT_STATIC4 __D2D_INIT_SIMPLE_STATIC(4)
#define __D2D_GET_INPUT4 __d2dstatic_input4
#else
#define __D2D_INPUT4 __D2D_COMPLEX_INPUT(4)
#define __D2D_INIT_STATIC4 __D2D_INIT_COMPLEX_STATIC(4)
#define __D2D_GET_INPUT4 __D2D_SAMPLE_INPUT(4)
#endif
#if defined(D2D_INPUT5_SIMPLE)
#define __D2D_INPUT5 __D2D_SIMPLE_INPUT(5)
#define __D2D_INIT_STATIC5 __D2D_INIT_SIMPLE_STATIC(5)
#define __D2D_GET_INPUT5 __d2dstatic_input5
#else
#define __D2D_INPUT5 __D2D_COMPLEX_INPUT(5)
#define __D2D_INIT_STATIC5 __D2D_INIT_COMPLEX_STATIC(5)
#define __D2D_GET_INPUT5 __D2D_SAMPLE_INPUT(5)
#endif
#if defined(D2D_INPUT6_SIMPLE)
#define __D2D_INPUT6 __D2D_SIMPLE_INPUT(6)
#define __D2D_INIT_STATIC6 __D2D_INIT_SIMPLE_STATIC(6)
#define __D2D_GET_INPUT6 __d2dstatic_input6
#else
#define __D2D_INPUT6 __D2D_COMPLEX_INPUT(6)
#define __D2D_INIT_STATIC6 __D2D_INIT_COMPLEX_STATIC(6)
#define __D2D_GET_INPUT6 __D2D_SAMPLE_INPUT(6)
#endif
#if defined(D2D_INPUT7_SIMPLE)
#define __D2D_INPUT7 __D2D_SIMPLE_INPUT(7)
#define __D2D_INIT_STATIC7 __D2D_INIT_SIMPLE_STATIC(7)
#define __D2D_GET_INPUT7 __d2dstatic_input7
#else
#define __D2D_INPUT7 __D2D_COMPLEX_INPUT(7)
#define __D2D_INIT_STATIC7 __D2D_INIT_COMPLEX_STATIC(7)
#define __D2D_GET_INPUT7 __D2D_SAMPLE_INPUT(7)
#endif
#if defined(D2D_INPUT8_SIMPLE)
#define __D2D_INPUT8 __D2D_SIMPLE_INPUT(8)
#define __D2D_INIT_STATIC8 __D2D_INIT_SIMPLE_STATIC(8)
#define __D2D_GET_INPUT8 __d2dstatic_input8
#else
#define __D2D_INPUT8 __D2D_COMPLEX_INPUT(8)
#define __D2D_INIT_STATIC8 __D2D_INIT_COMPLEX_STATIC(8)
#define __D2D_GET_INPUT8 __D2D_SAMPLE_INPUT(8)
#endif
// Define the export function inputs based on the defined input count and types.
#if (D2D_INPUT_COUNT == 0)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS
#elif (D2D_INPUT_COUNT == 1)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0
#elif (D2D_INPUT_COUNT == 2)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1
#elif (D2D_INPUT_COUNT == 3)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2
#elif (D2D_INPUT_COUNT == 4)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2, __D2D_INPUT3
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2; __D2D_INIT_STATIC3
#elif (D2D_INPUT_COUNT == 5)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2, __D2D_INPUT3, __D2D_INPUT4
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2; __D2D_INIT_STATIC3; __D2D_INIT_STATIC4
#elif (D2D_INPUT_COUNT == 6)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2, __D2D_INPUT3, __D2D_INPUT4, __D2D_INPUT5
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2; __D2D_INIT_STATIC3; __D2D_INIT_STATIC4; __D2D_INIT_STATIC5
#elif (D2D_INPUT_COUNT == 7)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2, __D2D_INPUT3, __D2D_INPUT4, __D2D_INPUT5, __D2D_INPUT6
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2; __D2D_INIT_STATIC3; __D2D_INIT_STATIC4; __D2D_INIT_STATIC5; __D2D_INIT_STATIC6
#elif (D2D_INPUT_COUNT == 8)
#define __D2D_FUNCTION_INPUTS __D2D_SCENE_POS __D2D_INPUT0, __D2D_INPUT1, __D2D_INPUT2, __D2D_INPUT3, __D2D_INPUT4, __D2D_INPUT5, __D2D_INPUT6, __D2D_INPUT7
#define __D2D_INIT_STATICS __D2D_INIT_STATIC_SCENE_POS __D2D_INIT_STATIC0; __D2D_INIT_STATIC1; __D2D_INIT_STATIC2; __D2D_INIT_STATIC3; __D2D_INIT_STATIC4; __D2D_INIT_STATIC5; __D2D_INIT_STATIC6; __D2D_INIT_STATIC7
#endif
#if !defined(CONCAT)
#define CONCAT(str1, str2) str1##str2
#endif
// Rename the entry point target function so that the actual entry point can use the name.
// This expansion is the same for both full shaders and functions.
#define D2D_PS_ENTRY(name) float4 CONCAT(name, _Impl)()
// If neither D2D_FUNCTION or D2D_FULL_SHADER is defined, behave as if D2D_FULL_SHADER is defined.
#if defined(D2D_FUNCTION) && !defined(D2D_FULL_SHADER_ONLY)
// Replaces simple samples with either static variable or an actual sample,
// depending on whether the input is declared as simple or complex.
#define D2DGetInput(index) __D2D_GET_INPUT##index
#if !defined(D2D_CUSTOM_ENTRY)
// Declare function prototype for the target function so that it can be referenced before definition.
// D2D_ENTRY is a macro whose actual name resolves to the effect's target "entry point" function.
float4 CONCAT(D2D_ENTRY, _Impl)();
// This is the actual entry point definition, which forwards the call to the target function.
export float4 D2D_func_entry(__D2D_FUNCTION_INPUTS)
{
__D2D_INIT_STATICS;
return CONCAT(D2D_ENTRY, _Impl)();
}
#endif
#else // !defined(D2D_FUNCTION)
// Replaces simple samples with actual samples.
#define D2DGetInput(index) __D2D_SAMPLE_INPUT(index)
#if !defined(D2D_CUSTOM_ENTRY)
// Declare function prototype for the target function so that it can be referenced before definition.
// D2D_ENTRY is a macro whose actual name resolves to the effect's target "entry point" function.
float4 CONCAT(D2D_ENTRY, _Impl)();
// This is the actual entry point definition, which forwards the call to the target function.
float4 D2D_ENTRY (float4 pos : SV_POSITION, __D2D_FUNCTION_INPUTS) : SV_TARGET
{
__D2D_INIT_STATICS;
return CONCAT(D2D_ENTRY, _Impl)();
}
#endif
#endif // D2D_FUNCTION
//===============================================================
// Along with D2DGetInput defined above, the following macros and
// methods define D2D intrinsics for use in effect shader code.
//===============================================================
#if !defined(D2D_FUNCTION) || defined(D2D_REQUIRES_SCENE_POSITION)
inline float4 D2DGetScenePosition()
{
return __d2dstatic_scenePos;
}
#endif
#define D2DGetInputCoordinate(index) __d2dstatic_uv##index
#define D2DSampleInput(index, position) InputTexture##index.Sample(InputSampler##index, position)
#define D2DSampleInputAtOffset(index, offset) InputTexture##index.Sample(InputSampler##index, __d2dstatic_uv##index.xy + offset * __d2dstatic_uv##index.zw)
#define D2DSampleInputAtPosition(index, pos) InputTexture##index.Sample(InputSampler##index, __d2dstatic_uv##index.xy + __d2dstatic_uv##index.zw * (pos - __d2dstatic_scenePos.xy))
+16
ファイルの表示
@@ -0,0 +1,16 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from d3dcommon.h in Microsoft.Direct3D.D3D12 v1.600.10
// Original source is Copyright © Microsoft. Licensed under the MIT license
namespace TerraFX.Interop.DirectX
{
internal enum D3D_INCLUDE_TYPE
{
D3D_INCLUDE_LOCAL = 0,
D3D_INCLUDE_SYSTEM = (D3D_INCLUDE_LOCAL + 1),
D3D10_INCLUDE_LOCAL = D3D_INCLUDE_LOCAL,
D3D10_INCLUDE_SYSTEM = D3D_INCLUDE_SYSTEM,
D3D_INCLUDE_FORCE_DWORD = 0x7fffffff,
}
}
+29
ファイルの表示
@@ -0,0 +1,29 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from d3dcommon.h in Microsoft.Direct3D.D3D12 v1.600.10
// Original source is Copyright © Microsoft. Licensed under the MIT license
using System.Runtime.CompilerServices;
using TerraFX.Interop.Windows;
namespace TerraFX.Interop.DirectX
{
internal unsafe partial struct ID3DInclude
{
public void** lpVtbl;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(0)]
public HRESULT Open(D3D_INCLUDE_TYPE IncludeType, [NativeTypeName("LPCSTR")] sbyte* pFileName, [NativeTypeName("LPCVOID")] void* pParentData, [NativeTypeName("LPCVOID *")] void** ppData, uint* pBytes)
{
return ((delegate* unmanaged[Stdcall]<ID3DInclude*, D3D_INCLUDE_TYPE, sbyte*, void*, void**, uint*, int>)(lpVtbl[0]))((ID3DInclude*)Unsafe.AsPointer(ref this), IncludeType, pFileName, pParentData, ppData, pBytes);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(1)]
public HRESULT Close([NativeTypeName("LPCVOID")] void* pData)
{
return ((delegate* unmanaged[Stdcall]<ID3DInclude*, void*, int>)(lpVtbl[1]))((ID3DInclude*)Unsafe.AsPointer(ref this), pData);
}
}
}
@@ -10,8 +10,10 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)..\TerraFX.Interop.Windows\DirectX\um\d3d11shader\D3D.cs" Link="DirectX\um\d3d11shader\D3D.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_INCLUDE_TYPE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_SHADER_MACRO.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shadeer\D3D11_SHADER_DESC.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\ID3DInclude.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcompiler\D3DCOMPILE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcompiler\D3D_BLOB_PART.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcompiler\DirectX.cs" />