فهرست منبع

Fixed issues with Open GL ES floats, and support for MathF.Pow overloads.

Minor tweaks as requested in GH-80
Craig Dean 7 سال پیش
والد
کامیت
ccf1aa080a

+ 0 - 2
src/ShaderGen.Tests/ShaderGen.Tests.csproj.DotSettings

@@ -1,2 +0,0 @@
-<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
-	<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp72</s:String></wpf:ResourceDictionary>

+ 0 - 57
src/ShaderGen.Tests/TestUtil.cs

@@ -280,7 +280,6 @@ namespace ShaderGen.Tests
             for (int i = 0; i < floatCount; i++)
             {
                 floats[i] = (float)((random.NextDouble() * 2.0 - 1.0) * Math.Pow(2.0, random.Next(minMantissa, maxMantissa)));
-                //floats[i] = (float)(random.NextDouble() * floatRange * 2f) - floatRange;
             }
 
             return floats;
@@ -300,34 +299,6 @@ namespace ShaderGen.Tests
 
         private static readonly string[] _memoryUnitsShort = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
 
-        /// <summary>
-        /// Converts a number of bytes to a friendly memory size.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="longUnits">if set to <see langword="true" /> use long form unit names instead of symbols.</param>
-        /// <param name="decimalPlaces">The number of decimal places between 0 and 16 (ignored for bytes).</param>
-        /// <param name="breakPoint">The break point between 0 and 1024 (or 0D to base on decimal points).</param>
-        /// <returns>System.String.</returns>
-        public static string ToMemorySize(
-            this short bytes,
-            bool longUnits = false,
-            uint decimalPlaces = 1,
-            double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
-
-        /// <summary>
-        /// Converts a number of bytes to a friendly memory size.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="longUnits">if set to <see langword="true" /> use long form unit names instead of symbols.</param>
-        /// <param name="decimalPlaces">The number of decimal places between 0 and 16 (ignored for bytes).</param>
-        /// <param name="breakPoint">The break point between 0 and 1024 (or 0D to base on decimal points).</param>
-        /// <returns>System.String.</returns>
-        public static string ToMemorySize(
-            this ushort bytes,
-            bool longUnits = false,
-            uint decimalPlaces = 1,
-            double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
-
         /// <summary>
         /// Converts a number of bytes to a friendly memory size.
         /// </summary>
@@ -342,20 +313,6 @@ namespace ShaderGen.Tests
             uint decimalPlaces = 1,
             double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
 
-        /// <summary>
-        /// Converts a number of bytes to a friendly memory size.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="longUnits">if set to <see langword="true" /> use long form unit names instead of symbols.</param>
-        /// <param name="decimalPlaces">The number of decimal places between 0 and 16 (ignored for bytes).</param>
-        /// <param name="breakPoint">The break point between 0 and 1024 (or 0D to base on decimal points).</param>
-        /// <returns>System.String.</returns>
-        public static string ToMemorySize(
-            this uint bytes,
-            bool longUnits = false,
-            uint decimalPlaces = 1,
-            double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
-
         /// <summary>
         /// Converts a number of bytes to a friendly memory size.
         /// </summary>
@@ -370,20 +327,6 @@ namespace ShaderGen.Tests
             uint decimalPlaces = 1,
             double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
 
-        /// <summary>
-        /// Converts a number of bytes to a friendly memory size.
-        /// </summary>
-        /// <param name="bytes">The bytes.</param>
-        /// <param name="longUnits">if set to <see langword="true" /> use long form unit names instead of symbols.</param>
-        /// <param name="decimalPlaces">The number of decimal places between 0 and 16 (ignored for bytes).</param>
-        /// <param name="breakPoint">The break point between 0 and 1024 (or 0D to base on decimal points).</param>
-        /// <returns>System.String.</returns>
-        public static string ToMemorySize(
-            this ulong bytes,
-            bool longUnits = false,
-            uint decimalPlaces = 1,
-            double breakPoint = 512D) => ToMemorySize((double)bytes, longUnits, decimalPlaces, breakPoint);
-
         /// <summary>
         /// Converts a number of bytes to a friendly memory size.
         /// </summary>

+ 1 - 1
src/ShaderGen.Tests/Tools/ToolChain.cs

@@ -672,7 +672,7 @@ namespace ShaderGen.Tests.Tools
         private static readonly Lazy<string> _glslvPath = new Lazy<string>(
             () =>
             {
-                // Execute, try to launch from the current environment.
+                // First, try to launch from the current environment.
                 try
                 {
                     ProcessStartInfo psi = new ProcessStartInfo()

+ 14 - 1
src/ShaderGen/Glsl/Glsl330KnownFunctions.cs

@@ -617,6 +617,19 @@ namespace ShaderGen.Glsl
         }
 
         private static readonly string[] _vectorAccessors = { "x", "y", "z", "w" };
+
+        private static readonly HashSet<string> _oneDimensionalTypes =
+            new HashSet<string>(new[]
+                {
+                    "System.Single",
+                    "float",
+                    "System.Int32",
+                    "int",
+                    "System.UInt32",
+                    "uint"
+                },
+                StringComparer.InvariantCultureIgnoreCase);
+
         /// <summary>
         /// Implements a check for each element of a vector.
         /// </summary>
@@ -625,7 +638,7 @@ namespace ShaderGen.Glsl
         /// <returns></returns>
         private static string AddCheck(string typeName, string check)
         {
-            if (typeName == "System.Single" || typeName == "float") // TODO Why are we getting float?
+            if (_oneDimensionalTypes.Contains(typeName))
             {
                 // The check can stay as it is, strip the '`' characters.
                 return check.Replace("`", string.Empty);

+ 14 - 1
src/ShaderGen/Glsl/Glsl450KnownFunctions.cs

@@ -628,6 +628,19 @@ namespace ShaderGen.Glsl
         }
 
         private static readonly string[] _vectorAccessors = { "x", "y", "z", "w" };
+
+        private static readonly HashSet<string> _oneDimensionalTypes =
+            new HashSet<string>(new[]
+                {
+                    "System.Single",
+                    "float",
+                    "System.Int32",
+                    "int",
+                    "System.UInt32",
+                    "uint"
+                },
+                StringComparer.InvariantCultureIgnoreCase);
+
         /// <summary>
         /// Implements a check for each element of a vector.
         /// </summary>
@@ -636,7 +649,7 @@ namespace ShaderGen.Glsl
         /// <returns></returns>
         private static string AddCheck(string typeName, string check)
         {
-            if (typeName == "System.Single" || typeName == "float") // TODO Why are we getting float?
+            if (_oneDimensionalTypes.Contains(typeName))
             {
                 // The check can stay as it is, strip the '`' characters.
                 return check.Replace("`", string.Empty);

+ 16 - 3
src/ShaderGen/Glsl/GlslEs300KnownFunctions.cs

@@ -613,7 +613,7 @@ namespace ShaderGen.Glsl
         {
             // OpenGL returns NaN for -ve P0's, whereas Vulkan ignores sign.
             return AddCheck(parameters[0].FullTypeName,
-                $"pow(abs({parameters[0].Identifier}`),{parameters[1].Identifier}`)");
+                $"pow(abs(float({parameters[0].Identifier})`),float({parameters[1].Identifier}`))");
         }
 
         private static string Clamp(string typeName, string methodName, InvocationParameterInfo[] parameters)
@@ -624,7 +624,7 @@ namespace ShaderGen.Glsl
             string p1 = $"{parameters[1].Identifier}{(isFloat ? string.Empty : "`")}";
             string p2 = $"{parameters[2].Identifier}{(isFloat ? string.Empty : "`")}";
             return AddCheck(parameters[0].FullTypeName,
-                $"(({p1}<{p2})?(clamp({parameters[0].Identifier}`,{p1},{p2})):({p2}))");
+                $"((float({p1})<float({p2}))?(clamp({parameters[0].Identifier}`,float({p1}),float({p2}))):float({p2}))");
         }
 
         private static string FMod(string typeName, string methodName, InvocationParameterInfo[] parameters)
@@ -639,6 +639,19 @@ namespace ShaderGen.Glsl
         }
 
         private static readonly string[] _vectorAccessors = { "x", "y", "z", "w" };
+
+        private static readonly HashSet<string> _oneDimensionalTypes =
+            new HashSet<string>(new[]
+                {
+                    "System.Single",
+                    "float",
+                    "System.Int32",
+                    "int",
+                    "System.UInt32",
+                    "uint"
+                },
+                StringComparer.InvariantCultureIgnoreCase);
+
         /// <summary>
         /// Implements a check for each element of a vector.
         /// </summary>
@@ -647,7 +660,7 @@ namespace ShaderGen.Glsl
         /// <returns></returns>
         private static string AddCheck(string typeName, string check)
         {
-            if (typeName == "System.Single" || typeName == "float") // TODO Why are we getting float?
+            if (_oneDimensionalTypes.Contains(typeName))
             {
                 // The check can stay as it is, strip the '`' characters.
                 return check.Replace("`", string.Empty);

+ 14 - 1
src/ShaderGen/Hlsl/HlslKnownFunctions.cs

@@ -625,6 +625,19 @@ namespace ShaderGen.Hlsl
         }
 
         private static readonly string[] _vectorAccessors = { "x", "y", "z", "w" };
+
+        private static readonly HashSet<string> _oneDimensionalTypes =
+            new HashSet<string>(new[]
+                {
+                    "System.Single",
+                    "float",
+                    "System.Int32",
+                    "int",
+                    "System.UInt32",
+                    "uint"
+                },
+                StringComparer.InvariantCultureIgnoreCase);
+
         /// <summary>
         /// Implements a check for each element of a vector.
         /// </summary>
@@ -633,7 +646,7 @@ namespace ShaderGen.Hlsl
         /// <returns></returns>
         private static string AddCheck(string typeName, string check)
         {
-            if (typeName == "System.Single" || typeName == "float") // TODO Why are we getting float?
+            if (_oneDimensionalTypes.Contains(typeName))
             {
                 // The check can stay as it is, strip the '`' characters.
                 return check.Replace("`", string.Empty);

+ 14 - 1
src/ShaderGen/Metal/MetalKnownFunctions.cs

@@ -700,6 +700,19 @@ namespace ShaderGen.Metal
         }
 
         private static readonly string[] _vectorAccessors = { "x", "y", "z", "w" };
+
+        private static readonly HashSet<string> _oneDimensionalTypes =
+            new HashSet<string>(new[]
+                {
+                    "System.Single",
+                    "float",
+                    "System.Int32",
+                    "int",
+                    "System.UInt32",
+                    "uint"
+                },
+                StringComparer.InvariantCultureIgnoreCase);
+
         /// <summary>
         /// Implements a check for each element of a vector.
         /// </summary>
@@ -708,7 +721,7 @@ namespace ShaderGen.Metal
         /// <returns></returns>
         private static string AddCheck(string typeName, string check)
         {
-            if (typeName == "System.Single" || typeName == "float") // TODO Why are we getting float?
+            if (_oneDimensionalTypes.Contains(typeName))
             {
                 // The check can stay as it is, strip the '`' characters.
                 return check.Replace("`", string.Empty);