Merge pull request #33 from Sergio0694/feature_hlsl-intrinsics

Added HLSL intrinsic functions
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2019-08-20 13:45:59 +02:00
コミット 02460a2dcb
4ファイル変更
+1676 -88

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

+10 -4
ファイルの表示
@@ -23,6 +23,11 @@ namespace ComputeSharp.BokehBlur
/// </summary>
private const float Gamma = 3;
/// <summary>
/// The inverse gamma exposure value to use when applying the effect
/// </summary>
private const float InverseGamma = 1 / Gamma;
static void Main()
{
// Load the input image
@@ -51,6 +56,7 @@ namespace ComputeSharp.BokehBlur
}
});
// Create the kernel
Console.WriteLine(">> Creating kernel");
int diameter = Radius * 2 + 1;
float[] kernel = new float[diameter * diameter];
@@ -67,6 +73,7 @@ namespace ComputeSharp.BokehBlur
}
}
// Normalize the kernel
Console.WriteLine(">> Normalizing kernel");
for (int i = 0; i < diameter; i++)
for (int j = 0; j < diameter; j++)
@@ -115,15 +122,14 @@ namespace ComputeSharp.BokehBlur
ref Vector4 r4 = ref vectorArray[i * width];
Vector4 low = Vector4.Zero;
Vector4 high = new Vector4(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
float invGamma = 1 / Gamma;
for (int j = 0; j < width; j++)
{
Vector4 v4 = Unsafe.Add(ref r4, j);
Vector4 clamp = Vector4.Clamp(v4, low, high);
v4.X = MathF.Pow(clamp.X, invGamma);
v4.Y = MathF.Pow(clamp.Y, invGamma);
v4.Z = MathF.Pow(clamp.Z, invGamma);
v4.X = MathF.Pow(clamp.X, InverseGamma);
v4.Y = MathF.Pow(clamp.Y, InverseGamma);
v4.Z = MathF.Pow(clamp.Z, InverseGamma);
Unsafe.Add(ref rPixel, j).FromVector4(v4);
}
+1 -3
ファイルの表示
@@ -12,8 +12,6 @@ namespace ComputeSharp.Graphics.Exceptions
/// Creates a new <see cref="InvalidExecutionContextException"/> instance
/// </summary>
/// <param name="name">The name of the caller API</param>
internal InvalidExecutionContextException([CallerMemberName] string? name = null)
: base($"The API {name} can only be used from within an HLSL shader")
{ }
internal InvalidExecutionContextException(string name) : base($"The API {name} can only be used from within an HLSL shader") { }
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
+106 -81
ファイルの表示
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.Shaders.Mappings
@@ -10,95 +12,118 @@ namespace ComputeSharp.Shaders.Mappings
/// </summary>
internal static class HlslKnownMethods
{
private static IReadOnlyDictionary<string, string> _KnownMethods;
/// <summary>
/// The mapping of supported known methods to HLSL methods
/// </summary>
private static readonly IReadOnlyDictionary<string, string> KnownMethods = new Dictionary<string, string>
private static IReadOnlyDictionary<string, string> KnownMethods
{
// Math
["System.Math.Max"] = "max",
["System.Math.Min"] = "min",
["System.Math.Pow"] = "pow",
["System.Math.Sin"] = "sin",
["System.Math.Sinh"] = "sinh",
["System.Math.Asin"] = "asin",
["System.Math.Cos"] = "cos",
["System.Math.Cosh"] = "cosh",
["System.Math.Acos"] = "acos",
["System.Math.Tan"] = "tan",
["System.Math.Tanh"] = "tanh",
["System.Math.Atan"] = "atan",
["System.Math.Atan2"] = "atan2",
["System.Math.Ceiling"] = "ceil",
["System.Math.Floor"] = "floor",
["System.Math.Clamp"] = "clamp",
["System.Math.Exp"] = "exp",
["System.Math.Log"] = "log",
["System.Math.Log10"] = "log10",
["System.Math.Round"] = "round",
["System.Math.Sqrt"] = "sqrt",
["System.Math.Sign"] = "sign",
["System.Math.Truncate"] = "trunc",
["System.Math.PI"] = "3.1415926535897931",
get
{
if (_KnownMethods != null) return _KnownMethods;
// MathF
["System.MathF.Max"] = "max",
["System.MathF.Min"] = "min",
["System.MathF.Pow"] = "pow",
["System.MathF.Sin"] = "sin",
["System.MathF.Sinh"] = "sinh",
["System.MathF.Asin"] = "asin",
["System.MathF.Cos"] = "cos",
["System.MathF.Cosh"] = "cosh",
["System.MathF.Acos"] = "acos",
["System.MathF.Tan"] = "tan",
["System.MathF.Tanh"] = "tanh",
["System.MathF.Atan"] = "atan",
["System.MathF.Atan2"] = "atan2",
["System.MathF.Ceiling"] = "ceil",
["System.MathF.Floor"] = "floor",
["System.MathF.Clamp"] = "clamp",
["System.MathF.Exp"] = "exp",
["System.MathF.Log"] = "log",
["System.MathF.Log10"] = "log10",
["System.MathF.Round"] = "round",
["System.MathF.Sqrt"] = "sqrt",
["System.MathF.Sign"] = "sign",
["System.MathF.Truncate"] = "trunc",
["System.MathF.PI"] = "3.14159274f",
// Initialize the initial mappings
Dictionary<string, string> knownMethods = new Dictionary<string, string>
{
// Math
["System.Math.Max"] = "max",
["System.Math.Min"] = "min",
["System.Math.Pow"] = "pow",
["System.Math.Sin"] = "sin",
["System.Math.Sinh"] = "sinh",
["System.Math.Asin"] = "asin",
["System.Math.Cos"] = "cos",
["System.Math.Cosh"] = "cosh",
["System.Math.Acos"] = "acos",
["System.Math.Tan"] = "tan",
["System.Math.Tanh"] = "tanh",
["System.Math.Atan"] = "atan",
["System.Math.Atan2"] = "atan2",
["System.Math.Ceiling"] = "ceil",
["System.Math.Floor"] = "floor",
["System.Math.Clamp"] = "clamp",
["System.Math.Exp"] = "exp",
["System.Math.Log"] = "log",
["System.Math.Log10"] = "log10",
["System.Math.Round"] = "round",
["System.Math.Sqrt"] = "sqrt",
["System.Math.Sign"] = "sign",
["System.Math.Truncate"] = "trunc",
["System.Math.PI"] = "3.1415926535897931",
// ThreadIds
["ComputeSharp.ThreadIds.X"] = ".x",
["ComputeSharp.ThreadIds.Y"] = ".y",
["ComputeSharp.ThreadIds.Z"] = ".z",
// MathF
["System.MathF.Max"] = "max",
["System.MathF.Min"] = "min",
["System.MathF.Pow"] = "pow",
["System.MathF.Sin"] = "sin",
["System.MathF.Sinh"] = "sinh",
["System.MathF.Asin"] = "asin",
["System.MathF.Cos"] = "cos",
["System.MathF.Cosh"] = "cosh",
["System.MathF.Acos"] = "acos",
["System.MathF.Tan"] = "tan",
["System.MathF.Tanh"] = "tanh",
["System.MathF.Atan"] = "atan",
["System.MathF.Atan2"] = "atan2",
["System.MathF.Ceiling"] = "ceil",
["System.MathF.Floor"] = "floor",
["System.MathF.Clamp"] = "clamp",
["System.MathF.Exp"] = "exp",
["System.MathF.Log"] = "log",
["System.MathF.Log10"] = "log10",
["System.MathF.Round"] = "round",
["System.MathF.Sqrt"] = "sqrt",
["System.MathF.Sign"] = "sign",
["System.MathF.Truncate"] = "trunc",
["System.MathF.PI"] = "3.14159274f",
// Vector3
["System.Numerics.Vector3.X"] = ".x",
["System.Numerics.Vector3.Y"] = ".y",
["System.Numerics.Vector3.Z"] = ".z",
["System.Numerics.Vector3.Cross"] = "cross",
["System.Numerics.Vector3.Dot"] = "dot",
["System.Numerics.Vector3.Lerp"] = "lerp",
["System.Numerics.Vector3.Transform"] = "mul",
["System.Numerics.Vector3.TransformNormal"] = "mul",
["System.Numerics.Vector3.Normalize"] = "normalize",
["System.Numerics.Vector3.Zero"] = "(float3)0",
["System.Numerics.Vector3.One"] = "float3(1.0f, 1.0f, 1.0f)",
["System.Numerics.Vector3.UnitX"] = "float3(1.0f, 0.0f, 0.0f)",
["System.Numerics.Vector3.UnitY"] = "float3(0.0f, 1.0f, 0.0f)",
["System.Numerics.Vector3.UnitZ"] = "float3(0.0f, 0.0f, 1.0f)",
// ThreadIds
["ComputeSharp.ThreadIds.X"] = ".x",
["ComputeSharp.ThreadIds.Y"] = ".y",
["ComputeSharp.ThreadIds.Z"] = ".z",
// Vector4
["System.Numerics.Vector4.X"] = ".x",
["System.Numerics.Vector4.Y"] = ".y",
["System.Numerics.Vector4.Z"] = ".z",
["System.Numerics.Vector4.W"] = ".w",
["System.Numerics.Vector4.Lerp"] = "lerp",
["System.Numerics.Vector4.Transform"] = "mul",
["System.Numerics.Vector4.Normalize"] = "normalize",
["System.Numerics.Vector4.Zero"] = "(float4)0",
["System.Numerics.Vector4.One"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)"
};
// Vector3
["System.Numerics.Vector3.X"] = ".x",
["System.Numerics.Vector3.Y"] = ".y",
["System.Numerics.Vector3.Z"] = ".z",
["System.Numerics.Vector3.Cross"] = "cross",
["System.Numerics.Vector3.Dot"] = "dot",
["System.Numerics.Vector3.Lerp"] = "lerp",
["System.Numerics.Vector3.Transform"] = "mul",
["System.Numerics.Vector3.TransformNormal"] = "mul",
["System.Numerics.Vector3.Normalize"] = "normalize",
["System.Numerics.Vector3.Zero"] = "(float3)0",
["System.Numerics.Vector3.One"] = "float3(1.0f, 1.0f, 1.0f)",
["System.Numerics.Vector3.UnitX"] = "float3(1.0f, 0.0f, 0.0f)",
["System.Numerics.Vector3.UnitY"] = "float3(0.0f, 1.0f, 0.0f)",
["System.Numerics.Vector3.UnitZ"] = "float3(0.0f, 0.0f, 1.0f)",
// Vector4
["System.Numerics.Vector4.X"] = ".x",
["System.Numerics.Vector4.Y"] = ".y",
["System.Numerics.Vector4.Z"] = ".z",
["System.Numerics.Vector4.W"] = ".w",
["System.Numerics.Vector4.Lerp"] = "lerp",
["System.Numerics.Vector4.Transform"] = "mul",
["System.Numerics.Vector4.Normalize"] = "normalize",
["System.Numerics.Vector4.Zero"] = "(float4)0",
["System.Numerics.Vector4.One"] = "float4(1.0f, 1.0f, 1.0f, 1.0f)"
};
// Programmatically load mappings from the Hlsl class as well
foreach (string name in
from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static)
group method by method.Name
into groups
select groups.Key)
{
knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{name}", name.ToLowerInvariant());
}
return _KnownMethods = knownMethods;
}
}
/// <summary>
/// Checks whether or not a specified method is a known HLSL method