Commit 817b7ff4 authored by Laurent Le Brun's avatar Laurent Le Brun
Browse files

Fix smoothstep optimization trick

It was leading to things like "x--0.1", which doesn't parse. Now prints
"x+0.1" as expected.
parent 14038f39
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="2.3.0.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="2.3.5.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="4.0.0.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="4.3.0.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.3.1.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="2.3.5.1" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.78.3.1" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.259.3.1" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="4.3.1.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.47.4.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.78.4.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="3.259.4.0" newVersion="4.4.0.0" />
<bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="2.3.0.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0" />
<bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
......
......@@ -9,10 +9,10 @@
<OutputType>Exe</OutputType>
<RootNamespace>glsl_minifier</RootNamespace>
<AssemblyName>shader_minifier</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Name>Shader Minifier</Name>
<TargetFrameworkProfile />
<TargetFSharpCoreVersion>2.3.0.0</TargetFSharpCoreVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
......@@ -33,7 +33,7 @@
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<StartArguments>-o "" ../../tests\unit\1.simple.frag</StartArguments>
<StartArguments>-o "" ../../tests\unit\smoothstep.frag --smoothstep</StartArguments>
<OtherFlags>--standalone</OtherFlags>
</PropertyGroup>
<Choose>
......
......@@ -101,6 +101,7 @@ let foldList env fct li =
snd x) : 'a -> 'a)
!env, res
// Applies env.fExpr recursively on all nodes of an expression.
let rec mapExpr env = function
| FunCall(fct, args) ->
env.fExpr env (FunCall(mapExpr env fct, List.map (mapExpr env) args))
......
......@@ -35,15 +35,13 @@ let printSize code =
printfn "Shader size is: %d" n
let rename code =
Renamer.renameMode <- Renamer.Unambiguous
Printer.printMode <- Printer.SingleChar
let code, lastIdent = Renamer.renTopLevel code
let code, lastIdent = Renamer.renTopLevel code Renamer.Unambiguous
computeFrequencyIdentTable code
Renamer.computeContextTable code
Printer.printMode <- Printer.FromTable
Renamer.renameMode <- Renamer.Context
let code, lastIdent = Renamer.renTopLevel code
let code, lastIdent = Renamer.renTopLevel code Renamer.Context
vprintf "%d identifiers renamed. " Renamer.numberOfUsedIdents
printSize code
code
......@@ -129,7 +127,6 @@ let () =
"--smoothstep", ArgType.Unit (fun() -> Ast.smoothstepTrick<-true), "Use IQ's smoothstep trick"
//"--macro-threshold", ArgType.Int (fun i ->
// printfn "Macros are disabled in the release."; Ast.macroThreshold <- i), "[disabled] Use a #define macro if it can save at least <int> bytes"
//"--make-elevated2", ArgType.Unit (fun () -> printfn "Please buy the commercial version."; exit 1), "Generate the 4k intro 'Elevated 2'"
"--shader-only", ArgType.Unit (fun() -> Ast.targetOutput<-Ast.Text), "[Deprecated]"
"--js-output", ArgType.Unit (fun() -> Ast.targetOutput<-Ast.JS), "[Deprecated]"
"--", ArgType.Rest setFile, "Stop parsing command line"
......
......@@ -279,7 +279,8 @@ let rec doNotOverload env = function
let env = {env with map = Map.add name name env.map; reusable = re}
doNotOverload env li
let rec renTopLevel li =
let rec renTopLevel li mode =
renameMode <- mode
let idents = Printer.identTable |> Array.toList
|> List.filter (fun x -> x.Length = 1)
|> List.filter (fun x -> not <| List.exists ((=) x) Ast.forbiddenNames)
......
......@@ -70,6 +70,11 @@ let rec expr env = function
| FunCall(Var ",", [e1; FunCall(Var ",", [e2; e3])]) ->
FunCall(Var ",", [expr env (FunCall(Var ",", [e1; e2])); e3])
| FunCall(Var "-", [x; Float (f, s)]) when f < 0. ->
FunCall(Var "+", [x; Float (-f, s)]) |> expr env
| FunCall(Var "-", [x; Int (i, s)]) when i < 0 ->
FunCall(Var "+", [x; Int (-i, s)]) |> expr env
// Boolean simplifications (let's ignore the suffix)
| FunCall(Var "<", [Int (i1, _); Int (i2, _)]) -> bool(i1 < i2)
| FunCall(Var ">", [Int (i1, _); Int (i2, _)]) -> bool(i1 > i2)
......
......@@ -5,5 +5,7 @@ void main()
s = smoothstep(0.0,1.0,s);
ao = smoothstep(0.0,0.4,s) - smoothstep(0.4,0.7,s);
ao = smoothstep(0.0,0.4,s) - 1.0 * smoothstep(0.4,0.7,s);
float dom = 1.0 * smoothstep( (-0.1), (0.1), ref.y); // https://github.com/laurentlb/Shader_Minifier/issues/7
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment