Skip to content

WIP, for gains estimation #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/rewriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,27 @@ let private simplifyBlock stmts =
Some (ForE (Some e, cond, inc, body))
| (Expr e, While (cond, body)) -> // a=0;while(i<5); -> for(a=0;i<5;);
Some (ForE(Some e, Some cond, None, body))
| (Expr (FunCall(Op "=", [Var d1; e1])),
Expr (FunCall(Op "=", [Var d2; FunCall(Var func, [Var d3; e2])])))
when d1 = d2 && d1 = d3 -> // d=e1;d=f(d,e2); -> d=f(e1,e2);
// Particularly useful for: d=min(d,f1());d=min(d,f2()); -> d=min(min(d,f1()),f2());
// conditions to perform the replacement:
// [A] d is a local. if it's not, a function call in e2 (or even f) could modify it
// [B] d3 must be the only use of d in the FunCall to f
// [C] f doesn't take d3 as "out" or "inout".
if not (List.contains func.Name ["min"; "max"]) then // takes care of [C]
None
else
let e2UsesD = false//failwith "TODO: visiter e2 savoir s'il utilise d" // [B]
if e2UsesD then
None
else
let dIsALocal = true//failwith "TODO: savoir si d est une locale, mais pour ça il faut avoir accumulé la liste des decls locales de la fonction en cours" // [A]
if not dIsALocal then
None
else
failwith "les gains sont pas fous en compressé, en fait..."
Some (Expr (FunCall(Op "=", [Var d1; FunCall(Var func, [e1; e2])])))
| _ -> None)

// Inline inner decl-less blocks. (Presence of decl could lead to redefinitions.) a();{b();}c(); -> a();b();c();
Expand Down
10 changes: 5 additions & 5 deletions tests/compression_results.log
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ clod.frag... 8960 => 1545.563
audio-flight-v2.frag 4650 => 902.661
buoy.frag 4242 => 632.431
controllable-machinery.frag 7771 => 1227.917
ed-209.frag 7932 => 1361.638
ed-209.frag 7916 => 1363.067
elevated.hlsl 3416 => 603.918
endeavour.frag 2661 => 541.942
from-the-seas-to-the-stars.frag 14367 => 2342.623
frozen-wasteland.frag 4609 => 812.410
kinder_painter.frag 2905 => 450.888
kinder_painter.frag 2901 => 450.835
leizex.frag 2327 => 515.566
lunaquatic.frag 5231 => 1055.816
mandelbulb.frag 2419 => 546.857
ohanami.frag 3292 => 736.461
orchard.frag 5647 => 1033.964
oscars_chair.frag 4651 => 986.364
robin.frag 6343 => 1057.981
robin.frag 6327 => 1057.611
slisesix.frag 4587 => 937.138
terrarium.frag 3634 => 747.342
the_real_party_is_in_your_pocket.frag 12243 => 1814.824
the_real_party_is_in_your_pocket.frag 12187 => 1823.704
valley_ball.glsl 4386 => 888.496
yx_long_way_from_home.frag 3030 => 615.535
Total: 119303 => 21358.334
Total: 119211 => 21368.221
8 changes: 2 additions & 6 deletions tests/real/ed-209.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ MarchData gunPod(vec3 p)
float bump=sign(sin(pp.z*33.3))*.003,d=sdBox(pp,vec3(.1-bump,.38-bump,.34))-.02;
pp=p-vec3(0,0,-.6);
pp.x=abs(pp.x)-.1;
d=min(d,sdCappedCylinder(pp,.06,.15));
d=min(d,sdCappedCylinder(pp+vec3(0,.12,-.05),.06,.05));
d=min(d,sdBox(p+vec3(0,0,.54),vec3(.1,.06,.04)));
d=min(min(min(d,sdCappedCylinder(pp,.06,.15)),sdCappedCylinder(pp+vec3(0,.12,-.05),.06,.05)),sdBox(p+vec3(0,0,.54),vec3(.1,.06,.04)));
if(d<r.d)
d=max(d,-sdCappedCylinder(pp+vec3(0,0,.1),.03,.2)),r.d=d,r.mat=vec3(.02);
float fs=fireShock();
Expand Down Expand Up @@ -277,9 +275,7 @@ MarchData room(vec3 p)
if(r.d==backWall)
{
float ocp;
ocp=min(abs(sdOctogon(xy,2.6)),abs(sdOctogon(xy,1.9)));
ocp=max(ocp,min(.7-abs(xy.x+1.2),-xy.y));
ocp=min(ocp,max(abs(sdOctogon(xy,1.2)),min(xy.x,.7-abs(xy.y))));
ocp=min(max(min(abs(sdOctogon(xy,2.6)),abs(sdOctogon(xy,1.9))),min(.7-abs(xy.x+1.2),-xy.y)),max(abs(sdOctogon(xy,1.2)),min(xy.x,.7-abs(xy.y))));
if(ocp<.3)
r.mat=vec3(.39,.57,.71);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/real/kinder_painter.expected
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@
"b=n(z,f,v,m);"
"d=dot(b,r.xyz);"
"s.xyz=reflect(y,b);"
"i=dot(s.xyz,r.xyz);"
"i=max(i,0.);"
"i=max(dot(s.xyz,r.xyz),0.);"
"i*=i;"
"i*=i;"
"if(x(v,r.xyz,r.w))"
Expand Down
Loading