Permalink
Browse files

First public SL# commit; SL# is now an open source project available …

…under the MIT (Expat) License.
  • Loading branch information...
0 parents commit 02c2776be400a670258fb632b60c2b78c33e5eb1 XTZGZoReX committed Mar 30, 2011
Showing with 86,730 additions and 0 deletions.
  1. +19 −0 .gitignore
  2. BIN Dependencies/Mono.Reflection.dll
  3. BIN Dependencies/OpenTK.dll
  4. +76,187 −0 Dependencies/OpenTK.xml
  5. +17 −0 IIS.SLSharp.Core/Expressions/DualLogicalExpression.cs
  6. +126 −0 IIS.SLSharp.Core/Expressions/LoopReducer.cs
  7. +44 −0 IIS.SLSharp.Core/Expressions/WhileExpression.cs
  8. +56 −0 IIS.SLSharp.Core/Extensions.cs
  9. +110 −0 IIS.SLSharp.Core/GpuStopwatch.cs
  10. +72 −0 IIS.SLSharp.Core/IIS.SLSharp.Core.csproj
  11. +728 −0 IIS.SLSharp.Core/Reflection/Decompiler.cs
  12. +48 −0 IIS.SLSharp.Core/Reflection/ReflectionMarkerAttribute.cs
  13. +18 −0 IIS.SLSharp.Core/Reflection/ReflectionToken.cs
  14. +258 −0 IIS.SLSharp.Core/Runtime/ResourceHelper.cs
  15. +65 −0 IIS.SLSharp.Core/Utilities.cs
  16. +100 −0 IIS.SLSharp.Examples.Complex/DemoWindow.cs
  17. +99 −0 IIS.SLSharp.Examples.Complex/IIS.SLSharp.Examples.Complex.csproj
  18. +11 −0 IIS.SLSharp.Examples.Complex/Program.cs
  19. +67 −0 IIS.SLSharp.Examples.Complex/Resources.Designer.cs
  20. +124 −0 IIS.SLSharp.Examples.Complex/Resources.resx
  21. +81 −0 IIS.SLSharp.Examples.Complex/Shaders/BackdropShader.cs
  22. +70 −0 IIS.SLSharp.Examples.Complex/Shaders/Cube.cs
  23. +55 −0 IIS.SLSharp.Examples.Complex/Shaders/CubeShader.cs
  24. +178 −0 IIS.SLSharp.Examples.Complex/Shaders/SimplexNoiseShader.cs
  25. +37 −0 IIS.SLSharp.Examples.Complex/Shaders/WangShader.cs
  26. +367 −0 IIS.SLSharp.Examples.Complex/Textures/WangMap.cs
  27. BIN IIS.SLSharp.Examples.Complex/tiles.png
  28. +48 −0 IIS.SLSharp.Examples.Simple/DemoWindow.cs
  29. +83 −0 IIS.SLSharp.Examples.Simple/IIS.SLSharp.Examples.Simple.csproj
  30. +11 −0 IIS.SLSharp.Examples.Simple/Program.cs
  31. +21 −0 IIS.SLSharp.Examples.Simple/Shaders/InvertShader.cs
  32. +62 −0 IIS.SLSharp.Examples.Simple/Shaders/MyShader.cs
  33. +1,447 −0 IIS.SLSharp.Installer/IIS.SLSharp.Installer.vdproj
  34. +9 −0 IIS.SLSharp/Annotations/FragmentOutAttribute.cs
  35. +22 −0 IIS.SLSharp/Annotations/FragmentShaderAttribute.cs
  36. +7 −0 IIS.SLSharp/Annotations/IShaderAttribute.cs
  37. +12 −0 IIS.SLSharp/Annotations/ShaderVariableAttribute.cs
  38. +22 −0 IIS.SLSharp/Annotations/UniformAttribute.cs
  39. +9 −0 IIS.SLSharp/Annotations/VaryingAttribute.cs
  40. +9 −0 IIS.SLSharp/Annotations/VertexInAttribute.cs
  41. +22 −0 IIS.SLSharp/Annotations/VertexShaderAttribute.cs
  42. +24 −0 IIS.SLSharp/Diagnostics/ShaderDebugger.cs
  43. +109 −0 IIS.SLSharp/IIS.SLSharp.csproj
  44. +913 −0 IIS.SLSharp/Shader.cs
  45. +827 −0 IIS.SLSharp/ShaderDefinition.Common.cs
  46. +65 −0 IIS.SLSharp/ShaderDefinition.Derivative.cs
  47. +276 −0 IIS.SLSharp/ShaderDefinition.DoubleVector.cs
  48. +203 −0 IIS.SLSharp/ShaderDefinition.Exponential.cs
  49. +402 −0 IIS.SLSharp/ShaderDefinition.Geometric.cs
  50. +90 −0 IIS.SLSharp/ShaderDefinition.Interpolation.cs
  51. +23 −0 IIS.SLSharp/ShaderDefinition.Matrix.cs
  52. +77 −0 IIS.SLSharp/ShaderDefinition.Noise.cs
  53. +32 −0 IIS.SLSharp/ShaderDefinition.Sampler.cs
  54. +58 −0 IIS.SLSharp/ShaderDefinition.Texture.cs
  55. +238 −0 IIS.SLSharp/ShaderDefinition.Trigonometry.cs
  56. +279 −0 IIS.SLSharp/ShaderDefinition.Vector.cs
  57. +39 −0 IIS.SLSharp/ShaderDefinition.cs
  58. +159 −0 IIS.SLSharp/Textures/BaseTexture.cs
  59. +714 −0 IIS.SLSharp/Textures/Externals/LoaderDDS.cs
  60. +48 −0 IIS.SLSharp/Textures/Externals/LoaderStatics.cs
  61. +89 −0 IIS.SLSharp/Textures/FramebufferObject.cs
  62. +22 −0 IIS.SLSharp/Textures/ITexture.cs
  63. +117 −0 IIS.SLSharp/Textures/RenderToTexture.cs
  64. +69 −0 IIS.SLSharp/Textures/RenderbufferObject.cs
  65. +41 −0 IIS.SLSharp/Textures/Texture1D.cs
  66. +211 −0 IIS.SLSharp/Textures/Texture2D.cs
  67. +45 −0 IIS.SLSharp/Textures/TextureCube.cs
  68. +14 −0 IIS.SLSharp/Translation/DebugTranslatorAttribute.cs
  69. +67 −0 IIS.SLSharp/Translation/GlslTransform.cs
  70. +607 −0 IIS.SLSharp/Translation/GlslVisitor.cs
  71. +21 −0 LICENSE
  72. +64 −0 README.md
  73. +54 −0 SLSharp.sln
  74. +12 −0 SolutionInfo.cs
@@ -0,0 +1,19 @@
+# User configuration files.
+*.opensdf
+*.sdf
+*.suo
+*.user
+*.userprefs
+*ReSharper*
+
+# Debugging files.
+*.pdb
+*.pidb
+*.vsp
+
+# Merge conflict-related files.
+*.orig
+
+# Output directories.
+bin/*
+*/obj/*
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
@@ -0,0 +1,17 @@
+using System.Linq.Expressions;
+
+namespace IIS.SLSharp.Core.Expressions
+{
+ public class DualLogicalExpression : Expression
+ {
+ public Expression Primary { get; private set; }
+
+ public Expression Dual { get; private set; }
+
+ public DualLogicalExpression(Expression primary, Expression dual)
+ {
+ Primary = primary;
+ Dual = dual;
+ }
+ }
+}
@@ -0,0 +1,126 @@
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using System.Linq;
+
+namespace IIS.SLSharp.Core.Expressions
+{
+ public sealed class LoopReducer
+ {
+ private readonly List<Expression> _result = new List<Expression>();
+
+ public IEnumerable<Expression> Result
+ {
+ get { return _result; }
+ }
+
+ private readonly Dictionary<LabelTarget, int> _labels = new Dictionary<LabelTarget, int>();
+
+ private readonly Dictionary<int, ParameterExpression> _locals;
+
+ private void ResolveLabels(IList<Expression> exp)
+ {
+ for (var i = 0; i < exp.Count; i++)
+ {
+ var e = exp[i];
+ if (e.NodeType == ExpressionType.Label)
+ _labels[((LabelExpression) e).Target] = i;
+ }
+ }
+
+ private int GotoTarget(Expression e)
+ {
+ int res;
+ if (e.NodeType != ExpressionType.Goto)
+ return -1;
+
+ if (_labels.TryGetValue(((GotoExpression) e).Target, out res))
+ return res + 1;
+
+ return -1;
+ }
+
+ private LoopReducer(List<Expression> expressions, Dictionary<int, ParameterExpression> locals)
+ {
+ _locals = locals;
+ ResolveLabels(expressions);
+ Simplify(expressions);
+ _result = expressions;
+ }
+
+ private void Simplify(List<Expression> exp)
+ {
+ //ResolveTernary(exp);
+ ResolveLoop(exp);
+ }
+
+ private void ResolveLoop(List<Expression> exp)
+ {
+ // scan for for() loops
+ for (var i = 0; i < exp.Count; i++)
+ {
+ var e = exp[i];
+ var target = GotoTarget(e);
+
+ if (target < i || target >= exp.Count)
+ continue;
+
+ var cond = exp[target] as ConditionalExpression;
+ var boolAssignment = exp[target] as BinaryExpression;
+
+ if (cond == null)
+ {
+ // in debug mode an additional temporary is used
+ if (boolAssignment == null)
+ continue;
+
+ if (boolAssignment.NodeType != ExpressionType.Assign)
+ continue;
+
+ if (target + 1 >= exp.Count)
+ continue;
+
+ cond = exp[target + 1] as ConditionalExpression;
+ if (cond == null)
+ continue;
+
+ cond = Expression.Condition(boolAssignment.Right, cond.IfTrue, cond.IfFalse);
+ var left = (ParameterExpression) boolAssignment.Left;
+
+ foreach (var idx in _locals.Keys.Where(idx => _locals[idx].Name == left.Name))
+ {
+ _locals.Remove(idx);
+ break;
+ }
+
+ // we MUST remove the var out of the locals
+ // if we fail to do so it is a complex condition we cannot reduce
+ //boolAssignment.Left;
+ //boolAssignment.Left
+ //_locals[]
+ }
+
+ var entry = i + 2;
+ if (GotoTarget(cond.IfFalse) != entry && GotoTarget(cond.IfTrue) != entry)
+ continue;
+
+ var bodyEnd = target - 2;
+ var pre = new List<Expression>(exp.Take(i));
+ var body = new List<Expression>(exp.Skip(entry).Take(bodyEnd - i - 1));
+ var post = new List<Expression>(exp.Skip(target + (boolAssignment == null ? 1 : 2)));
+
+ ResolveLoop(body);
+ ResolveLoop(post);
+
+ exp.Clear();
+ exp.AddRange(pre);
+ exp.Add(new WhileExpression(body, cond.Test));
+ exp.AddRange(post);
+ }
+ }
+
+ public static IEnumerable<Expression> Reduce(List<Expression> expression, Dictionary<int, ParameterExpression> locals)
+ {
+ return new LoopReducer(expression, locals).Result;
+ }
+ }
+}
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+
+namespace IIS.SLSharp.Core.Expressions
+{
+ public class WhileExpression : Expression
+ {
+ private readonly List<Expression> _body;
+
+ public IEnumerable<Expression> Body
+ {
+ get { return _body; }
+ }
+
+ public Expression Comperator { get; private set; }
+
+ public WhileExpression(List<Expression> body, Expression comperator)
+ {
+ _body = body;
+ Comperator = comperator;
+ }
+
+ public override Expression Reduce()
+ {
+ return this;
+ }
+
+ public override ExpressionType NodeType
+ {
+ get { return ExpressionType.Loop; }
+ }
+
+ public override Type Type
+ {
+ get { return typeof(WhileExpression); }
+ }
+
+ public override bool CanReduce
+ {
+ get { return false; }
+ }
+ }
+}
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+
+namespace IIS.SLSharp.Core
+{
+ public static class Extensions
+ {
+ public static TSource Max<TSource, TSelect>(this IEnumerable<TSource> source, Func<TSource, TSelect> selector)
+ where TSelect : IComparable<TSelect>
+ {
+ var enumer = source.GetEnumerator();
+
+ enumer.MoveNext();
+ var maxItem = enumer.Current;
+ var maxValue = selector(maxItem);
+
+ while (enumer.MoveNext())
+ {
+ var currentItem = enumer.Current;
+ var currentValue = selector(currentItem);
+
+ if (currentValue.CompareTo(maxValue) <= 0)
+ continue;
+
+ maxItem = currentItem;
+ maxValue = currentValue;
+ }
+
+ return maxItem;
+ }
+
+ public static TSource Min<TSource, TSelect>(this IEnumerable<TSource> source, Func<TSource, TSelect> selector)
+ where TSelect : IComparable<TSelect>
+ {
+ var enumer = source.GetEnumerator();
+
+ enumer.MoveNext();
+ var minItem = enumer.Current;
+ var minValue = selector(minItem);
+
+ while (enumer.MoveNext())
+ {
+ var currentItem = enumer.Current;
+ var currentValue = selector(currentItem);
+
+ if (currentValue.CompareTo(minValue) >= 0)
+ continue;
+
+ minItem = currentItem;
+ minValue = currentValue;
+ }
+
+ return minItem;
+ }
+ }
+}
@@ -0,0 +1,110 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using OpenTK.Graphics.OpenGL;
+
+namespace IIS.SLSharp.Core
+{
+ public sealed class GpuStopwatch : IDisposable
+ {
+ private readonly bool _hasArbTimer;
+
+ private readonly Stopwatch _simpleWatch;
+
+ private uint _query;
+
+ public GpuStopwatch()
+ {
+ _hasArbTimer = GL.GetString(StringName.Extensions).Contains("ARB_timer_query");
+
+ if (_hasArbTimer)
+ GL.GenQueries(1, out _query);
+ else
+ _simpleWatch = new Stopwatch();
+ }
+
+ public void Restart()
+ {
+ if (!_hasArbTimer)
+ _simpleWatch.Restart();
+ else
+ GL.BeginQuery((QueryTarget)(0x88BF), _query);
+ }
+
+ public void Stop()
+ {
+ if (!_hasArbTimer)
+ _simpleWatch.Stop();
+ else
+ GL.EndQuery((QueryTarget)(0x88BF));
+ }
+
+ public void StopAndFinish()
+ {
+ if (_hasArbTimer)
+ {
+ Stop();
+ GL.Finish();
+ }
+ else
+ {
+ GL.Finish();
+ Stop();
+ }
+ }
+
+ public bool IsGpuWatch
+ {
+ get { return _hasArbTimer; }
+ }
+
+ public bool Available
+ {
+ get
+ {
+ if (!_hasArbTimer)
+ return true;
+
+ int available;
+ GL.GetQueryObject(_query, GetQueryObjectParam.QueryResultAvailable, out available);
+ return available != 0;
+ }
+ }
+
+ public void WaitForResult()
+ {
+ while (!Available)
+ Thread.Yield();
+ }
+
+ public long ElapsedTicks
+ {
+ get
+ {
+ if (!_hasArbTimer)
+ return _simpleWatch.ElapsedTicks;
+
+ WaitForResult();
+ uint time;
+ GL.GetQueryObject(_query, GetQueryObjectParam.QueryResult, out time);
+ return time;
+ }
+ }
+
+ public void Dispose()
+ {
+ if (_query == 0)
+ return;
+
+ GL.DeleteQueries(1, ref _query);
+ _query = 0;
+
+ GC.SuppressFinalize(this);
+ }
+
+ ~GpuStopwatch()
+ {
+ Dispose();
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 02c2776

Please sign in to comment.