Merge pull request #582 from Sergio0694/dev/d2d1-shader-descriptor

Refactor interface and introduce new ID2D1PixelShaderDescriptor<T>
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2023-09-30 19:28:34 +02:00
コミット e3407bfe7d
44ファイル変更
+257 -265

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

+2 -1
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Descriptors;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp;
#else
@@ -62,7 +63,7 @@ public abstract class PixelShaderEffect : CanvasEffect
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
public sealed class For<T> : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="PixelShaderEffect{T}"/> node in use.
+2 -1
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.WinUI;
namespace ComputeSharp.SwapChain.D2D1.Backend;
@@ -56,7 +57,7 @@ internal abstract class PixelShaderEffect : CanvasEffect
/// </summary>
/// <typeparam name="T">The type of pixel shader to render.</typeparam>
public sealed class For<T> : PixelShaderEffect
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="PixelShaderEffect{T}"/> node in use.
+2 -2
ファイルの表示
@@ -78,8 +78,8 @@
<Compile Include="..\ComputeSharp.D2D1\Extensions\ComPtrExtensions.cs" Link="ComputeSharp.D2D1\Extensions\ComPtrExtensions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Extensions\HRESULTExtensions.cs" Link="ComputeSharp.D2D1\Extensions\HRESULTExtensions.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" Link="ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1ConstantBufferLoader.cs" Link="ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1ConstantBufferLoader.cs" />
<Compile Include="..\ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1PixelShaderDescriptor{T}.cs" Link="ComputeSharp.D2D1\Interfaces\Descriptors\ID2D1PixelShaderDescriptor{T}.cs" />
<Compile Include="..\ComputeSharp.D2D1\Intrinsics\D2D.cs" Link="ComputeSharp.D2D1\Intrinsics\D2D.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" Link="ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" />
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" />
@@ -8,38 +8,37 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
/// <inheritdoc/>
partial class InitializeFromDispatchData
partial class CreateFromConstantBuffer
{
/// <summary>
/// Writes the <c>InitializeFromDispatchData</c> method.
/// Writes the <c>CreateFromConstantBuffer</c> method.
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine("readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InitializeFromDispatchData(global::System.ReadOnlySpan<byte> data)");
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
writer.WriteLine($"readonly unsafe {typeName} global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.CreateFromConstantBuffer(global::System.ReadOnlySpan<byte> data)");
using (writer.WriteBlock())
{
// If there are no fields, the method body is just empty
// If there are no fields, just return an empty shader (TODO: add length check on .NET 8)
if (info.Fields.IsEmpty)
{
writer.WriteLine("return default;");
return;
}
// Insert the fallback for empty shaders. This will generate the following code:
writer.WriteLine("if (data.IsEmpty)");
using (writer.WriteBlock())
{
writer.WriteLine("return;");
}
// Get a reference to the data through the generated native layout type
// Get a reference to the data through the generated native layout type and define the shader
writer.WriteLine($"ref readonly global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.D2D1.Generated.ConstantBuffer>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));");
writer.WriteLine();
writer.WriteLine($"{typeName} shader;");
writer.WriteLine();
writer.WriteLine("ref readonly global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer = ref global::System.Runtime.CompilerServices.Unsafe.As<byte, global::ComputeSharp.D2D1.Generated.ConstantBuffer>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));");
// Generate loading statements for each captured field
foreach (FieldInfo fieldInfo in info.Fields)
@@ -49,7 +48,7 @@ partial class ID2D1ShaderGenerator
case FieldInfo.Primitive primitive:
// Read a primitive value
writer.WriteLine($"global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.{string.Join(".", primitive.FieldPath)}) = buffer.{string.Join("_", primitive.FieldPath)};");
writer.WriteLine($"*&shader.{string.Join(".", primitive.FieldPath)} = buffer.{string.Join("_", primitive.FieldPath)};");
break;
case FieldInfo.NonLinearMatrix matrix:
@@ -58,18 +57,22 @@ partial class ID2D1ShaderGenerator
// Read all rows of a given matrix type:
//
// global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.<FIELD_PATH>)[0] = buffer.<CONSTANT_BUFFER_ROW_0_PATH>;
// global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.<FIELD_PATH>)[1] = buffer.<CONSTANT_BUFFER_ROW_1_PATH>;
// (*&shader.<FIELD_PATH>)[0] = buffer.<CONSTANT_BUFFER_ROW_0_PATH>;
// (*&shader.<FIELD_PATH>)[1] = buffer.<CONSTANT_BUFFER_ROW_1_PATH>;
// ...
// global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.<FIELD_PATH>)[N] = buffer.<CONSTANT_BUFFER_ROW_N_PATH>;
// (*&shader.<FIELD_PATH>)[N] = buffer.<CONSTANT_BUFFER_ROW_N_PATH>;
for (int j = 0; j < matrix.Rows; j++)
{
writer.WriteLine($"global::System.Runtime.CompilerServices.Unsafe.AsRef(in this.{fieldPath})[{j}] = buffer.{fieldNamePrefix}_{j};");
writer.WriteLine($"(*&shader.{fieldPath})[{j}] = buffer.{fieldNamePrefix}_{j};");
}
break;
}
}
// Return the populated shader
writer.WriteLine();
writer.WriteLine("return shader;");
}
}
}
@@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine("readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectId");
writer.WriteLine($"readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.EffectId");
using (writer.WriteBlock())
{
@@ -17,7 +17,7 @@ partial class ID2D1ShaderGenerator
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteEffectDisplayNameSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
WriteEffectMetadataSyntax("EffectDisplayName", info.EffectDisplayName, writer);
WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectDisplayName", info.EffectDisplayName, writer);
}
/// <summary>
@@ -27,7 +27,7 @@ partial class ID2D1ShaderGenerator
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteEffectDescriptionSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
WriteEffectMetadataSyntax("EffectDescription", info.EffectDescription, writer);
WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectDescription", info.EffectDescription, writer);
}
/// <summary>
@@ -37,7 +37,7 @@ partial class ID2D1ShaderGenerator
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteEffectCategorySyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
WriteEffectMetadataSyntax("EffectCategory", info.EffectCategory, writer);
WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectCategory", info.EffectCategory, writer);
}
/// <summary>
@@ -47,20 +47,21 @@ partial class ID2D1ShaderGenerator
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteEffectAuthorSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
WriteEffectMetadataSyntax("EffectAuthor", info.EffectAuthor, writer);
WriteEffectMetadataSyntax(info.Hierarchy.Hierarchy[0].QualifiedName, "EffectAuthor", info.EffectAuthor, writer);
}
/// <summary>
/// Writes a specified metadata property.
/// </summary>
/// <param name="qualifiedName">The qualified name of the shader type.</param>
/// <param name="propertyName">The property name to generate.</param>
/// <param name="metadataValue">The input effect metadata value, if available.</param>
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
private static void WriteEffectMetadataSyntax(string propertyName, string? metadataValue, IndentedTextWriter writer)
private static void WriteEffectMetadataSyntax(string qualifiedName, string propertyName, string? metadataValue, IndentedTextWriter writer)
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.Write($"readonly string? global::ComputeSharp.D2D1.__Internals.ID2D1Shader.{propertyName} => ");
writer.Write($"readonly string? global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{qualifiedName}>.{propertyName} => ");
// Append null or the metadata value as a string literal
if (metadataValue is null)
@@ -10,7 +10,7 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
/// <inheritdoc/>
partial class LoadBytecode
partial class HlslBytecode
{
/// <summary>
/// Writes the <c>ShaderProfile</c> property.
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};");
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ShaderProfile global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ShaderProfile => global::ComputeSharp.D2D1.D2D1ShaderProfile.{info.HlslInfoKey.EffectiveShaderProfile};");
}
/// <summary>
@@ -41,7 +41,7 @@ partial class ID2D1ShaderGenerator
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.CompileOptions => {compileOptionsExpression};");
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1CompileOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.CompileOptions => {compileOptionsExpression};");
}
/// <summary>
@@ -53,7 +53,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.Write("readonly global::System.ReadOnlyMemory<byte> global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslBytecode => ");
writer.Write($"readonly global::System.ReadOnlyMemory<byte> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslBytecode => ");
// If there is no bytecode, just return a default expression.
// Otherwise, return the memory manager backed memory instance.
@@ -21,9 +21,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
/// <summary>
/// A helper with all logic to generate the <c>LoadBytecode</c> method.
/// A helper with all logic to generate the HLSL bytecode properties.
/// </summary>
internal static partial class LoadBytecode
internal static partial class HlslBytecode
{
/// <summary>
/// The shared cache of <see cref="HlslBytecodeInfo"/> values.
@@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine("readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslSource =>");
writer.WriteLine($"readonly string global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.HlslSource =>");
writer.IncreaseIndent();
writer.WriteLine("\"\"\"");
writer.Write(info.HlslInfoKey.HlslSource, isMultiline: true);
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.Write("readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1InputDescription> global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputDescriptions => ");
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1InputDescription> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputDescriptions => ");
// If there are no input descriptions, just return a default expression.
// Otherwise, return the shared array with cached input descriptions.
@@ -19,7 +19,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.Write("readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputTypes => ");
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1PixelShaderInputType> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputTypes => ");
// If there are no inputs, simply return a default expression. Otherwise, create
// a ReadOnlyMemory<D2D1PixelShaderInputType> instance from the memory manager.
@@ -9,18 +9,21 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
/// <inheritdoc/>
partial class LoadDispatchData
partial class LoadConstantBuffer
{
/// <summary>
/// Writes the <c>LoadDispatchData</c> method.
/// Writes the <c>LoadConstantBuffer</c> method.
/// </summary>
/// <param name="info">The input <see cref="D2D1ShaderInfo"/> instance with gathered shader info.</param>
/// <param name="writer">The <see cref="IndentedTextWriter"/> instance to write into.</param>
public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
{
string typeName = info.Hierarchy.Hierarchy[0].QualifiedName;
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine("readonly unsafe void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadDispatchData<TLoader>(ref TLoader loader)");
writer.WriteLine("[global::System.Runtime.CompilerServices.SkipLocalsInit]");
writer.WriteLine($"readonly unsafe void global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{typeName}>.LoadConstantBuffer<TLoader>(in {typeName} shader, ref TLoader loader)");
using (writer.WriteBlock())
{
@@ -32,6 +35,7 @@ partial class ID2D1ShaderGenerator
else
{
writer.WriteLine("global::ComputeSharp.D2D1.Generated.ConstantBuffer buffer;");
writer.WriteLine();
// Generate loading statements for each captured field
foreach (FieldInfo fieldInfo in info.Fields)
@@ -18,9 +18,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
/// <summary>
/// A helper with all logic to generate the <c>LoadDispatchData</c> method.
/// A helper with all logic to generate the <c>LoadConstantBuffer</c> method.
/// </summary>
private static partial class LoadDispatchData
private static partial class LoadConstantBuffer
{
/// <summary>
/// Explores a given type hierarchy and generates statements to load fields.
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
}
/// <summary>
@@ -33,7 +33,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};");
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.InputCount => {info.InputTypes.Length};");
}
/// <summary>
@@ -45,7 +45,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};");
writer.WriteLine($"readonly int global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};");
}
}
}
@@ -28,7 +28,7 @@ partial class ID2D1ShaderGenerator
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BufferPrecision => {bufferPrecisionExpression};");
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1BufferPrecision global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.BufferPrecision => {bufferPrecisionExpression};");
}
/// <summary>
@@ -47,7 +47,7 @@ partial class ID2D1ShaderGenerator
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ChannelDepth => {channelDepthExpression};");
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1ChannelDepth global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ChannelDepth => {channelDepthExpression};");
}
}
}
@@ -26,7 +26,7 @@ partial class ID2D1ShaderGenerator
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.__Internals.ID2D1Shader.PixelOptions => {pixelOptionsExpression};");
writer.WriteLine($"readonly ComputeSharp.D2D1.D2D1PixelOptions global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.PixelOptions => {pixelOptionsExpression};");
}
}
}
@@ -21,7 +21,7 @@ partial class ID2D1ShaderGenerator
{
writer.WriteLine("/// <inheritdoc/>");
writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
writer.Write("readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription> global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureDescriptions => ");
writer.Write($"readonly global::System.ReadOnlyMemory<global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription> global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{info.Hierarchy.Hierarchy[0].QualifiedName}>.ResourceTextureDescriptions => ");
// If there are no resource texture descriptions, just return a default expression.
// Otherwise, return a memory instance from the generated static readonly array.
+20 -16
ファイルの表示
@@ -74,7 +74,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
using ImmutableArrayBuilder<DiagnosticInfo> diagnostics = ImmutableArrayBuilder<DiagnosticInfo>.Rent();
// LoadDispatchData() info
ImmutableArray<FieldInfo> fieldInfos = LoadDispatchData.GetInfo(
ImmutableArray<FieldInfo> fieldInfos = LoadConstantBuffer.GetInfo(
diagnostics,
typeSymbol,
out int constantBufferSizeInBytes);
@@ -132,11 +132,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
token.ThrowIfCancellationRequested();
// Get the shader profile and linking info for LoadBytecode()
bool isLinkingSupported = LoadBytecode.IsSimpleInputShader(typeSymbol, inputCount);
D2D1ShaderProfile? requestedShaderProfile = LoadBytecode.GetRequestedShaderProfile(typeSymbol);
D2D1CompileOptions? requestedCompileOptions = LoadBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol);
D2D1ShaderProfile effectiveShaderProfile = LoadBytecode.GetEffectiveShaderProfile(requestedShaderProfile);
D2D1CompileOptions effectiveCompileOptions = LoadBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported);
bool isLinkingSupported = HlslBytecode.IsSimpleInputShader(typeSymbol, inputCount);
D2D1ShaderProfile? requestedShaderProfile = HlslBytecode.GetRequestedShaderProfile(typeSymbol);
D2D1CompileOptions? requestedCompileOptions = HlslBytecode.GetRequestedCompileOptions(diagnostics, typeSymbol);
D2D1ShaderProfile effectiveShaderProfile = HlslBytecode.GetEffectiveShaderProfile(requestedShaderProfile);
D2D1CompileOptions effectiveCompileOptions = HlslBytecode.GetEffectiveCompileOptions(requestedCompileOptions, isLinkingSupported);
bool hasErrors = diagnostics.Count > 0;
token.ThrowIfCancellationRequested();
@@ -152,12 +152,12 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
hasErrors);
// TODO: cache this across transform runs
HlslBytecodeInfo hlslInfo = LoadBytecode.GetInfo(ref hlslInfoKey, token);
HlslBytecodeInfo hlslInfo = HlslBytecode.GetInfo(ref hlslInfoKey, token);
token.ThrowIfCancellationRequested();
// Append any diagnostic for the shader compilation
LoadBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics);
HlslBytecode.GetInfoDiagnostics(typeSymbol, hlslInfo, diagnostics);
token.ThrowIfCancellationRequested();
@@ -210,24 +210,28 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
declaredMembers.Add(PixelOptions.WriteSyntax);
declaredMembers.Add(OutputBuffer.WriteBufferPrecisionSyntax);
declaredMembers.Add(OutputBuffer.WriteChannelDepthSyntax);
declaredMembers.Add(LoadBytecode.WriteShaderProfileSyntax);
declaredMembers.Add(LoadBytecode.WriteCompileOptionsSyntax);
declaredMembers.Add(HlslBytecode.WriteShaderProfileSyntax);
declaredMembers.Add(HlslBytecode.WriteCompileOptionsSyntax);
declaredMembers.Add(HlslSource.WriteSyntax);
declaredMembers.Add(LoadBytecode.WriteHlslBytecodeSyntax);
declaredMembers.Add(InitializeFromDispatchData.WriteSyntax);
declaredMembers.Add(LoadDispatchData.WriteSyntax);
declaredMembers.Add(HlslBytecode.WriteHlslBytecodeSyntax);
declaredMembers.Add(CreateFromConstantBuffer.WriteSyntax);
declaredMembers.Add(LoadConstantBuffer.WriteSyntax);
using ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>> additionalTypes = ImmutableArrayBuilder<IndentedTextWriter.Callback<D2D1ShaderInfo>>.Rent();
using ImmutableHashSetBuilder<string> usingDirectives = ImmutableHashSetBuilder<string>.Rent();
LoadDispatchData.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
LoadConstantBuffer.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputDescriptions.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
InputTypes.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
LoadBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
HlslBytecode.RegisterAdditionalTypeSyntax(item, additionalTypes, usingDirectives);
using IndentedTextWriter writer = IndentedTextWriter.Rent();
item.Hierarchy.WriteSyntax(item, writer, declaredMembers.WrittenSpan);
item.Hierarchy.WriteSyntax(
state: item,
writer: writer,
baseTypes: new[] { $"global::ComputeSharp.D2D1.Descriptors.ID2D1PixelShaderDescriptor<{item.Hierarchy.Hierarchy[0].QualifiedName}>" },
memberCallbacks: declaredMembers.WrittenSpan);
// If any generated types are needed, they go into a separate namespace
// This allows the code to use using directives without any conflicts.
+5 -6
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
@@ -9,8 +10,6 @@ using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CS0618
#if WINDOWS_UWP
namespace ComputeSharp.D2D1.Uwp.Extensions;
#else
@@ -29,7 +28,7 @@ internal static unsafe class ID2D1EffectExtensions
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
/// <returns>The constant buffer of type <typeparamref name="T"/> for <paramref name="d2D1Effect"/>.</returns>
public static T GetConstantBuffer<T>(this ref ID2D1Effect d2D1Effect)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
@@ -55,7 +54,7 @@ internal static unsafe class ID2D1EffectExtensions
Unsafe.SkipInit(out T shader);
shader.InitializeFromDispatchData(buffer.AsSpan(0, constantBufferSize));
shader = shader.CreateFromConstantBuffer(buffer.AsSpan(0, constantBufferSize));
ArrayPool<byte>.Shared.Return(buffer);
@@ -69,7 +68,7 @@ internal static unsafe class ID2D1EffectExtensions
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
/// <param name="value">The constant buffer value to set.</param>
public static void SetConstantBuffer<T>(this ref ID2D1Effect d2D1Effect, in T value)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
// Same as above, simply do nothing for empty types. This case is still handled to
// avoid crashing when someone's just setting an empty constant buffer, which is
@@ -90,7 +89,7 @@ internal static unsafe class ID2D1EffectExtensions
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
/// <returns>The <see cref="D2D1TransformMapper{T}"/> instance for <paramref name="d2D1Effect"/>.</returns>
public static D2D1TransformMapper<T>? GetTransformMapper<T>(this ref ID2D1Effect d2D1Effect)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
using ComPtr<ID2D1TransformMapper> d2D1TransformMapper = default;
@@ -13,7 +13,7 @@ using ComputeSharp.D2D1.WinUI.Buffers;
using ComputeSharp.D2D1.WinUI.Collections;
#endif
#pragma warning disable CS0618, CS8767
#pragma warning disable CS8767
#if WINDOWS_UWP
namespace ComputeSharp.D2D1.Uwp;
+2 -1
ファイルの表示
@@ -2,6 +2,7 @@
using System.Diagnostics.CodeAnalysis;
#endif
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.Interop;
using Microsoft.Graphics.Canvas;
@@ -20,7 +21,7 @@ namespace ComputeSharp.D2D1.WinUI;
/// </summary>
/// <typeparam name="T">The type of shader to use to render frames.</typeparam>
public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICanvasEffect, ICanvasImageInterop.Interface
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="ReferenceTracker"/> value for the current instance.
+15
ファイルの表示
@@ -0,0 +1,15 @@
using System;
namespace ComputeSharp.D2D1.Descriptors;
/// <summary>
/// A type representing a data loader for the constant buffer of a D2D1 shader.
/// </summary>
public interface ID2D1ConstantBufferLoader
{
/// <summary>
/// Loads the constant buffer of a D2D1 shader.
/// </summary>
/// <param name="data">The constant buffer for the D2D1 shader.</param>
void LoadConstantBuffer(ReadOnlySpan<byte> data);
}
@@ -1,21 +1,22 @@
using System;
using System.ComponentModel;
using ComputeSharp.D2D1.Interop;
namespace ComputeSharp.D2D1.__Internals;
namespace ComputeSharp.D2D1.Descriptors;
/// <summary>
/// A base <see langword="interface"/> representing a given shader that can be dispatched.
/// An interface for a descriptor for a given D2D1 pixel shader.
/// Descriptors contain metadata associated to D2D1 pixel shaders,
/// with all information needed to run them and create effects.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface ID2D1Shader
/// <typeparam name="T">The type of D2D1 pixel shader being described.</typeparam>
public interface ID2D1PixelShaderDescriptor<T>
where T : unmanaged, ID2D1PixelShader
{
/// <summary>
/// Gets the effect id of the D2D effect using this shader.
/// </summary>
/// <remarks>
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
/// This only applies to effects created from <see cref="D2D1PixelShaderEffect"/>.
/// </remarks>
ref readonly Guid EffectId { get; }
@@ -23,7 +24,7 @@ public interface ID2D1Shader
/// Gets the display name of the D2D effect using this shader, if specified.
/// </summary>
/// <remarks>
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
/// This only applies to effects created from <see cref="D2D1PixelShaderEffect"/>.
/// </remarks>
string? EffectDisplayName { get; }
@@ -31,7 +32,7 @@ public interface ID2D1Shader
/// Gets the description of the D2D effect using this shader, if specified.
/// </summary>
/// <remarks>
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
/// This only applies to effects created from <see cref="D2D1PixelShaderEffect"/>.
/// </remarks>
string? EffectDescription { get; }
@@ -39,7 +40,7 @@ public interface ID2D1Shader
/// Gets the category of the D2D effect using this shader, if specified.
/// </summary>
/// <remarks>
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
/// This only applies to effects created from <see cref="D2D1PixelShaderEffect"/>.
/// </remarks>
string? EffectCategory { get; }
@@ -47,107 +48,61 @@ public interface ID2D1Shader
/// Gets the author of the D2D effect using this shader, if specified.
/// </summary>
/// <remarks>
/// This only applies to effects created from <see cref="Interop.D2D1PixelShaderEffect"/>.
/// This only applies to effects created from <see cref="D2D1PixelShaderEffect"/>.
/// </remarks>
string? EffectAuthor { get; }
/// <summary>
/// Initializes the current shader from a buffer with the serialized dispatch data.
/// </summary>
/// <param name="data">The input buffer with the serialized dispatch data.</param>
/// <remarks>The input buffer must be retrieved from <see cref="LoadDispatchData"/>.</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void InitializeFromDispatchData(ReadOnlySpan<byte> data);
/// <summary>
/// Gets the pixel options for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1PixelOptions PixelOptions { get; }
/// <summary>
/// Gets the size in bytes of the constant buffer for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
int ConstantBufferSize { get; }
/// <summary>
/// Gets the number of inputs for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
int InputCount { get; }
/// <summary>
/// Gets the number of resource textures for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
int ResourceTextureCount { get; }
/// <summary>
/// Gets the input types for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1PixelShaderInputType> InputTypes { get; }
/// <summary>
/// Gets the input descriptions for the current shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1InputDescription> InputDescriptions { get; }
/// <summary>
/// Gets the resource texture descriptions for the shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<D2D1ResourceTextureDescription> ResourceTextureDescriptions { get; }
/// <summary>
/// Gets the pixel options for the current shader.
/// </summary>
D2D1PixelOptions PixelOptions { get; }
/// <summary>
/// Gets the buffer precision for the shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1BufferPrecision BufferPrecision { get; }
/// <summary>
/// Gets the channel depth for the shader.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1ChannelDepth ChannelDepth { get; }
/// <summary>
/// Loads the dispatch data for the shader.
/// </summary>
/// <typeparam name="TLoader">The type of data loader being used.</typeparam>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the data.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
void LoadDispatchData<TLoader>(ref TLoader loader)
where TLoader : struct, ID2D1DispatchDataLoader;
/// <summary>
/// Gets the HLSL source code for the current shader instance.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
string HlslSource { get; }
/// <summary>
/// Gets the shader profile for the current shader.
/// </summary>
/// <remarks>
/// This shader profile is either explicitly set by users, or the default one for D2D1 shaders.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1ShaderProfile ShaderProfile { get; }
/// <summary>
@@ -156,17 +111,34 @@ public interface ID2D1Shader
/// <remarks>
/// This compile options are either explicitly set by users, or the default one for D2D1 shaders.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
D2D1CompileOptions CompileOptions { get; }
/// <summary>
/// Gets the HLSL source code for the current shader instance.
/// </summary>
string HlslSource { get; }
/// <summary>
/// Gets the HLSL bytecode for the current shader, if available.
/// </summary>
/// <remarks>
/// If no precompiled HLSL bytecode is available, the returned <see cref="ReadOnlyMemory{T}"/> instance will be empty.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
ReadOnlyMemory<byte> HlslBytecode { get; }
/// <summary>
/// Creates a new <typeparamref name="T"/> shader instance from a constant buffer.
/// </summary>
/// <param name="buffer">The input constant buffer to read.</param>
/// <remarks>The input buffer must be retrieved from <see cref="LoadConstantBuffer"/>.</remarks>
T CreateFromConstantBuffer(ReadOnlySpan<byte> buffer);
/// <summary>
/// Loads the constant buffer of a given input shader.
/// </summary>
/// <typeparam name="TLoader">The type of data loader being used.</typeparam>
/// <param name="shader">The input shader to load the constant buffer for.</param>
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the constant buffer.</param>
void LoadConstantBuffer<TLoader>(in T shader, ref TLoader loader)
where TLoader : struct, ID2D1ConstantBufferLoader;
}
+1 -5
ファイルの表示
@@ -1,13 +1,9 @@
using ComputeSharp.D2D1.__Internals;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1;
/// <summary>
/// An <see langword="interface"/> representing a D2D1 pixel shader.
/// </summary>
public interface ID2D1PixelShader : ID2D1Shader
public interface ID2D1PixelShader
{
/// <summary>
/// Executes the current pixel shader.
-18
ファイルの表示
@@ -1,18 +0,0 @@
using System;
using System.ComponentModel;
namespace ComputeSharp.D2D1.__Internals;
/// <summary>
/// A base <see langword="interface"/> representing a data loader for a D2D1 shader being dispatched.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This interface is not intended to be used directly by user code")]
public interface ID2D1DispatchDataLoader
{
/// <summary>
/// Loads the captured values used by the D2D1 shader to be dispatched.
/// </summary>
/// <param name="data">The sequence of serialized captured values.</param>
void LoadConstantBuffer(ReadOnlySpan<byte> data);
}
+5 -6
ファイルの表示
@@ -1,11 +1,10 @@
using System.Buffers;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using ComputeSharp.D2D1.Shaders.Loaders;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Interop;
/// <summary>
@@ -13,7 +12,7 @@ namespace ComputeSharp.D2D1.Interop;
/// </summary>
/// <typeparam name="T">The type of shader the transform will interact with.</typeparam>
public readonly unsafe ref struct D2D1DrawInfoUpdateContext<T>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="ID2D1DrawInfoUpdateContext"/> instance associated with the current object.
@@ -48,7 +47,7 @@ public readonly unsafe ref struct D2D1DrawInfoUpdateContext<T>
Unsafe.SkipInit(out T shader);
shader.InitializeFromDispatchData(buffer);
shader = shader.CreateFromConstantBuffer(buffer);
ArrayPool<byte>.Shared.Return(buffer);
@@ -61,8 +60,8 @@ public readonly unsafe ref struct D2D1DrawInfoUpdateContext<T>
/// <param name="shader">The <typeparamref name="T"/> instance to be used in the associated effect.</param>
public void SetConstantBuffer(in T shader)
{
D2D1DrawInfoUpdateContextDispatchDataLoader dataLoader = new(this.d2D1DrawInfoUpdateContext);
D2D1DrawInfoUpdateContextConstantBufferLoader dataLoader = new(this.d2D1DrawInfoUpdateContext);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
}
}
+29 -30
ファイルの表示
@@ -1,12 +1,11 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Shaders.Loaders;
using ComputeSharp.D2D1.Shaders.Translation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Interop;
/// <summary>
@@ -27,7 +26,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -58,7 +57,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(out D2D1ShaderProfile shaderProfile, out D2D1CompileOptions compileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
return LoadOrCompileBytecode<T>(null, null, out shaderProfile, out compileOptions);
}
@@ -84,7 +83,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1ShaderProfile shaderProfile)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
return LoadOrCompileBytecode<T>(shaderProfile, null, out _, out _);
}
@@ -111,7 +110,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1ShaderProfile shaderProfile, out D2D1CompileOptions compileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
return LoadOrCompileBytecode<T>(shaderProfile, null, out _, out compileOptions);
}
@@ -140,7 +139,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1CompileOptions compileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
@@ -172,7 +171,7 @@ public static class D2D1PixelShader
/// </para>
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1CompileOptions compileOptions, out D2D1ShaderProfile shaderProfile)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
@@ -195,7 +194,7 @@ public static class D2D1PixelShader
/// If the shader was compiled at runtime, the returned <see cref="ReadOnlyMemory{T}"/> instance will wrap a <see cref="byte"/> array with the bytecode.
/// </remarks>
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1ShaderProfile shaderProfile, D2D1CompileOptions compileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
@@ -217,7 +216,7 @@ public static class D2D1PixelShader
D2D1CompileOptions? requestedCompileOptions,
out D2D1ShaderProfile effectiveShaderProfile,
out D2D1CompileOptions effectiveCompileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -250,7 +249,7 @@ public static class D2D1PixelShader
D2D1CompileOptions? requestedCompileOptions,
out D2D1ShaderProfile effectiveShaderProfile,
out D2D1CompileOptions effectiveCompileOptions)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -275,7 +274,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the pixel options for.</typeparam>
/// <returns>The pixel options for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static D2D1PixelOptions GetPixelOptions<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -288,7 +287,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the input count for.</typeparam>
/// <returns>The number of inputs for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static int GetInputCount<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -301,7 +300,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the resource texture count for.</typeparam>
/// <returns>The number of resource texture for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static int GetResourceTextureCount<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -314,7 +313,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the input types for.</typeparam>
/// <returns>The input types of the target D2D1 pixel shader.</returns>
public static ReadOnlyMemory<D2D1PixelShaderInputType> GetInputTypes<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -327,7 +326,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the input descriptions for.</typeparam>
/// <returns>A <see cref="ReadOnlyMemory{T}"/> with the available input descriptions for the shader.</returns>
public static ReadOnlyMemory<D2D1InputDescription> GetInputDescriptions<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -340,7 +339,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the resource texture descriptions for.</typeparam>
/// <returns>A <see cref="ReadOnlyMemory{T}"/> with the available resource texture descriptions for the shader.</returns>
public static ReadOnlyMemory<D2D1ResourceTextureDescription> GetResourceTextureDescriptions<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -353,7 +352,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the output buffer precision for.</typeparam>
/// <returns>The output buffer precision for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static D2D1BufferPrecision GetOutputBufferPrecision<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -366,7 +365,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to get the output buffer channel depth for.</typeparam>
/// <returns>The output buffer channel depth for the D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static D2D1ChannelDepth GetOutputBufferChannelDepth<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -383,11 +382,11 @@ public static class D2D1PixelShader
/// This method will allocate a buffer every time it is invoked.
/// For a zero-allocation alternative, use <see cref="SetConstantBufferForD2D1DrawInfo"/>.</remarks>
public static ReadOnlyMemory<byte> GetConstantBuffer<T>(in T shader)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
D2D1ByteArrayDispatchDataLoader dataLoader = default;
D2D1ByteArrayConstantBufferLoader dataLoader = default;
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
return dataLoader.GetResultingDispatchData();
}
@@ -398,7 +397,7 @@ public static class D2D1PixelShader
/// <typeparam name="T">The type of D2D1 pixel shader to retrieve info for.</typeparam>
/// <returns>The size of the constant buffer for a D2D1 pixel shader of type <typeparamref name="T"/>.</returns>
public static int GetConstantBufferSize<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -414,7 +413,7 @@ public static class D2D1PixelShader
/// <returns>The number of bytes written into <paramref name="span"/>.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="span"/> is not large enough to contain the constant buffer.</exception>
public static int GetConstantBuffer<T>(in T shader, Span<byte> span)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
if (!TryGetConstantBuffer(in shader, span, out int writtenBytes))
{
@@ -433,13 +432,13 @@ public static class D2D1PixelShader
/// <param name="bytesWritten">The number of bytes written into <paramref name="span"/>.</param>
/// <returns>Whether or not the constant buffer was retrieved successfully.</returns>
public static unsafe bool TryGetConstantBuffer<T>(in T shader, Span<byte> span, out int bytesWritten)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
fixed (byte* buffer = span)
{
D2D1ByteBufferDispatchDataLoader dataLoader = new(buffer, span.Length);
D2D1ByteBufferConstantBufferLoader dataLoader = new(buffer, span.Length);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
return dataLoader.TryGetWrittenBytes(out bytesWritten);
}
@@ -454,12 +453,12 @@ public static class D2D1PixelShader
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1DrawInfo"/> is <see langword="null"/>.</exception>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1drawinfo-setpixelshaderconstantbuffer"/>.</remarks>
public static unsafe void SetConstantBufferForD2D1DrawInfo<T>(void* d2D1DrawInfo, in T shader)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(d2D1DrawInfo);
D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);
D2D1DrawInfoConstantBufferLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
}
}
+13 -14
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Interop.Effects;
using ComputeSharp.D2D1.Shaders.Interop.Buffers;
@@ -9,8 +10,6 @@ using ComputeSharp.D2D1.Shaders.Loaders;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Interop;
/// <summary>
@@ -24,7 +23,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect id for.</typeparam>
/// <returns>The effect id of the D2D effect using <typeparamref name="T"/> shaders.</returns>
public static ref readonly Guid GetEffectId<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -37,7 +36,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect display name for.</typeparam>
/// <returns>The effect display name of the D2D effect using <typeparamref name="T"/> shaders, if available.</returns>
public static string? GetEffectDisplayName<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -50,7 +49,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect description for.</typeparam>
/// <returns>The effect description of the D2D effect using <typeparamref name="T"/> shaders, if available.</returns>
public static string? GetEffectDescription<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -63,7 +62,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect category for.</typeparam>
/// <returns>The effect category of the D2D effect using <typeparamref name="T"/> shaders, if available.</returns>
public static string? GetEffectCategory<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -76,7 +75,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <typeparam name="T">The type of D2D1 pixel shader to get the effect author for.</typeparam>
/// <returns>The effect author of the D2D effect using <typeparamref name="T"/> shaders, if available.</returns>
public static string? GetEffectAuthor<T>()
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
@@ -96,7 +95,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <para>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.</para>
/// </remarks>
public static void RegisterForD2D1Factory1<T>(void* d2D1Factory1, out Guid effectId)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(d2D1Factory1);
@@ -345,7 +344,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <para>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.</para>
/// </remarks>
public static ReadOnlyMemory<byte> GetRegistrationBlob<T>(out Guid effectId)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
ArrayPoolBufferWriter<byte> writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
@@ -560,7 +559,7 @@ public static unsafe class D2D1PixelShaderEffect
/// </exception>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1devicecontext-createeffect"/>.</remarks>
public static void CreateFromD2D1DeviceContext<T>(void* d2D1DeviceContext, void** d2D1Effect)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(d2D1DeviceContext);
default(ArgumentNullException).ThrowIfNull(d2D1Effect);
@@ -582,13 +581,13 @@ public static unsafe class D2D1PixelShaderEffect
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Effect"/> is <see langword="null"/>.</exception>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
public static void SetConstantBufferForD2D1Effect<T>(void* d2D1Effect, in T shader)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(d2D1Effect);
D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect);
D2D1EffectConstantBufferLoader dataLoader = new((ID2D1Effect*)d2D1Effect);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
Unsafe.AsRef(in shader).LoadConstantBuffer(in shader, ref dataLoader);
}
/// <summary>
@@ -662,7 +661,7 @@ public static unsafe class D2D1PixelShaderEffect
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Effect"/> or <paramref name="transformMapper"/> are <see langword="null"/>.</exception>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
public static void SetTransformMapperForD2D1Effect<T>(void* d2D1Effect, D2D1TransformMapper<T> transformMapper)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
default(ArgumentNullException).ThrowIfNull(d2D1Effect);
default(ArgumentNullException).ThrowIfNull(transformMapper);
+2 -3
ファイルの表示
@@ -1,12 +1,11 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Translation;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Interop;
/// <summary>
@@ -28,7 +27,7 @@ public static class D2D1ReflectionServices
/// </para>
/// </remarks>
public static unsafe D2D1ShaderInfo GetShaderInfo<T>()
where T : struct, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
Unsafe.SkipInit(out T shader);
+2 -1
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Numerics;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Shaders.Interop.Factories;
namespace ComputeSharp.D2D1.Interop;
@@ -9,7 +10,7 @@ namespace ComputeSharp.D2D1.Interop;
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
public static class D2D1TransformMapperFactory<T>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// Creates an <see cref="D2D1TransformMapper{T}"/> instance for an inflate transform.
+2 -1
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop.Effects;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using TerraFX.Interop.Windows;
@@ -94,7 +95,7 @@ namespace ComputeSharp.D2D1.Interop;
/// </para>
/// </remarks>
public abstract unsafe class D2D1TransformMapper<T> : ICustomQueryInterface, ID2D1TransformMapperInterop
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="D2D1TransformMapperImpl"/> object wrapped by the current instance.
+2 -1
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Descriptors;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#if !NET6_0_OR_GREATER
@@ -27,7 +28,7 @@ internal unsafe partial struct PixelShaderEffect
/// </summary>
/// <typeparam name="T">The type of shader.</typeparam>
public sealed class For<T>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <summary>
/// The <see cref="FactoryDelegate"/> wrapper for the shader factory.
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Shaders.Interop.Helpers;
@@ -12,7 +13,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
/// <typeparam name="TParameters">The type of parameters that the transform mapper will use.</typeparam>
internal abstract class D2D1TransformMapper<T, TParameters> : D2D1TransformMapper<T>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
where TParameters : unmanaged
{
/// <summary>
+2 -1
ファイルの表示
@@ -1,6 +1,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
using ComputeSharp.D2D1.Shaders.Interop.Helpers;
@@ -80,7 +81,7 @@ file static class D2D1AffineTransformMapper
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
internal abstract class D2D1AffineTransformMapper<T> : D2D1TransformMapper<T, Matrix3x2>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <inheritdoc/>
protected sealed override void TransformInputToOutput(in Matrix3x2 parameters, ref Rectangle64 rectangle)
+2 -1
ファイルの表示
@@ -1,3 +1,4 @@
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Shaders.Interop.Factories.Abstract;
using ComputeSharp.D2D1.Shaders.Interop.Helpers;
@@ -9,7 +10,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Factories;
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader associated to the transform mapper.</typeparam>
internal abstract class D2D1InflateTransformMapper<T> : D2D1TransformMapper<T, (int Left, int Top, int Right, int Bottom)>
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
/// <inheritdoc/>
protected sealed override void TransformInputToOutput(in (int Left, int Top, int Right, int Bottom) parameters, ref Rectangle64 rectangle)
@@ -1,16 +1,14 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Descriptors;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders dispatched via <see cref="ID2D1DrawInfo"/>.
/// </summary>
internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader
internal struct D2D1ByteArrayConstantBufferLoader : ID2D1ConstantBufferLoader
{
/// <summary>
/// The resulting array with the constant buffer to use.
@@ -28,7 +26,7 @@ internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.data = data.ToArray();
}
@@ -1,16 +1,14 @@
using System;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Descriptors;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders dispatched via <see cref="ID2D1DrawInfo"/>.
/// </summary>
internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoader
internal unsafe struct D2D1ByteBufferConstantBufferLoader : ID2D1ConstantBufferLoader
{
/// <summary>
/// The target buffer to write data to.
@@ -28,12 +26,12 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade
private int writtenBytes;
/// <summary>
/// Creates a new <see cref="D2D1ByteBufferDispatchDataLoader"/> instance.
/// Creates a new <see cref="D2D1ByteBufferConstantBufferLoader"/> instance.
/// </summary>
/// <param name="buffer">The target buffer to write data to.</param>
/// <param name="length">The length of the buffer pointed to by <see cref="buffer"/>.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1ByteBufferDispatchDataLoader(byte* buffer, int length)
internal D2D1ByteBufferConstantBufferLoader(byte* buffer, int length)
{
this.buffer = buffer;
this.length = length;
@@ -65,7 +63,7 @@ internal unsafe struct D2D1ByteBufferDispatchDataLoader : ID2D1DispatchDataLoade
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
if (data.TryCopyTo(new Span<byte>(this.buffer, this.length)))
{
@@ -1,18 +1,16 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders dispatched via <see cref="ID2D1DrawInfo"/>.
/// </summary>
internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDataLoader
internal readonly unsafe struct D2D1DrawInfoConstantBufferLoader : ID2D1ConstantBufferLoader
{
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> object in use.
@@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDa
private readonly ID2D1DrawInfo* d2D1DrawInfo;
/// <summary>
/// Creates a new <see cref="D2D1DrawInfoDispatchDataLoader"/> instance.
/// Creates a new <see cref="D2D1DrawInfoConstantBufferLoader"/> instance.
/// </summary>
/// <param name="d2D1DrawInfo">The <see cref="ID2D1DrawInfo"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1DrawInfoDispatchDataLoader(ID2D1DrawInfo* d2D1DrawInfo)
internal D2D1DrawInfoConstantBufferLoader(ID2D1DrawInfo* d2D1DrawInfo)
{
this.d2D1DrawInfo = d2D1DrawInfo;
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
@@ -1,18 +1,16 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders to be passed onto an <see cref="ID2D1DrawInfoUpdateContext"/> object.
/// </summary>
internal readonly unsafe struct D2D1DrawInfoUpdateContextDispatchDataLoader : ID2D1DispatchDataLoader
internal readonly unsafe struct D2D1DrawInfoUpdateContextConstantBufferLoader : ID2D1ConstantBufferLoader
{
/// <summary>
/// The <see cref="ID2D1DrawInfoUpdateContext"/> object in use.
@@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1DrawInfoUpdateContextDispatchDataLoader : ID
private readonly ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext;
/// <summary>
/// Creates a new <see cref="D2D1DrawInfoUpdateContextDispatchDataLoader"/> instance.
/// Creates a new <see cref="D2D1DrawInfoUpdateContextConstantBufferLoader"/> instance.
/// </summary>
/// <param name="d2D1DrawInfoUpdateContext">The <see cref="ID2D1DrawInfoUpdateContext"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1DrawInfoUpdateContextDispatchDataLoader(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext)
internal D2D1DrawInfoUpdateContextConstantBufferLoader(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext)
{
this.d2D1DrawInfoUpdateContext = d2D1DrawInfoUpdateContext;
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.d2D1DrawInfoUpdateContext->SetConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
@@ -1,18 +1,16 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders dispatched via <see cref="ID2D1Effect"/>.
/// </summary>
internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchDataLoader
internal readonly unsafe struct D2D1EffectConstantBufferLoader : ID2D1ConstantBufferLoader
{
/// <summary>
/// The <see cref="ID2D1Effect"/> object in use.
@@ -20,17 +18,17 @@ internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchData
private readonly ID2D1Effect* d2D1Effect;
/// <summary>
/// Creates a new <see cref="D2D1EffectDispatchDataLoader"/> instance.
/// Creates a new <see cref="D2D1EffectConstantBufferLoader"/> instance.
/// </summary>
/// <param name="d2D1Effect">The <see cref="ID2D1Effect"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1EffectDispatchDataLoader(ID2D1Effect* d2D1Effect)
internal D2D1EffectConstantBufferLoader(ID2D1Effect* d2D1Effect)
{
this.d2D1Effect = d2D1Effect;
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
void ID2D1ConstantBufferLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
if (data.IsEmpty)
{
+20 -2
ファイルの表示
@@ -48,8 +48,13 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
/// <typeparam name="T">The type of state to pass to callbacks.</typeparam>
/// <param name="state">The input state to pass to callbacks.</param>
/// <param name="writer">The target <see cref="IndentedTextWriter"/> instance to write text to.</param>
/// <param name="baseTypes">A list of base types to add to the generated type, if any.</param>
/// <param name="memberCallbacks">The callbacks to use to write members into the declared type.</param>
public void WriteSyntax<T>(T state, IndentedTextWriter writer, ReadOnlySpan<IndentedTextWriter.Callback<T>> memberCallbacks)
public void WriteSyntax<T>(
T state,
IndentedTextWriter writer,
ReadOnlySpan<string> baseTypes,
ReadOnlySpan<IndentedTextWriter.Callback<T>> memberCallbacks)
{
// Write the generated file header
writer.WriteLine("// <auto-generated/>");
@@ -68,7 +73,20 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName,
for (int i = Hierarchy.Length - 1; i >= 0; i--)
{
writer.WriteLine($$"""/// <inheritdoc cref="{{Hierarchy[i].QualifiedName}}"/>""");
writer.WriteLine($$"""partial {{Hierarchy[i].GetTypeKeyword()}} {{Hierarchy[i].QualifiedName}}""");
writer.Write($$"""partial {{Hierarchy[i].GetTypeKeyword()}} {{Hierarchy[i].QualifiedName}}""");
// Add any base types, if needed
if (i == 0 && !baseTypes.IsEmpty)
{
writer.Write(" : ");
writer.WriteInitializationExpressions(baseTypes, static (item, writer) => writer.Write(item));
writer.WriteLine();
}
else
{
writer.WriteLine();
}
writer.WriteLine($$"""{""");
writer.IncreaseIndent();
}
+5 -4
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.Tests.Helpers;
using Win32;
@@ -32,7 +33,7 @@ internal static class D2D1TestRunner
string expectedFileName,
[CallerMemberName] string destinationFileName = "",
float threshold = 0.00001f)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
@@ -73,7 +74,7 @@ internal static class D2D1TestRunner
[CallerMemberName] string destinationFileName = "",
float threshold = 0.00001f,
params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
@@ -109,7 +110,7 @@ internal static class D2D1TestRunner
D2D1TransformMapper<T>? transformMapper,
string sourcePath,
string destinationPath)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
@@ -158,7 +159,7 @@ internal static class D2D1TestRunner
int height,
string destinationPath,
params (int Index, D2D1ResourceTextureManager ResourceTextureManager)[] resourceTextures)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
+2 -1
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Helpers;
using ComputeSharp.SwapChain.Shaders.D2D1;
@@ -114,7 +115,7 @@ public class ShadersTests
}
private static void RunTest<T>(float threshold = 0.00001f)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!;
+3 -2
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
using ComputeSharp.D2D1.Descriptors;
using ComputeSharp.D2D1.UI.Tests.Helpers;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp;
@@ -79,7 +80,7 @@ public class ShadersTests
}
private static async Task RunTestAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(WrapperType wrapperType, float threshold = 0.00001f)
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
T shader = (T)Activator.CreateInstance(typeof(T), 0f, new int2(1280, 720))!;
@@ -118,7 +119,7 @@ public class ShadersTests
}
private sealed class TestCanvasEffect<T> : CanvasEffect
where T : unmanaged, ID2D1PixelShader
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
{
private static readonly EffectNode<PixelShaderEffect<T>> Effect = new();