Skip to content

Commit

Permalink
Revert "Merge for-declaration with the previous declaration"
Browse files Browse the repository at this point in the history
This is a rollback of #371

Fixes #397
Fixes #375
  • Loading branch information
laurentlb committed May 24, 2024
1 parent 22a118b commit e3aea3b
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 47 deletions.
3 changes: 0 additions & 3 deletions src/rewriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,6 @@ module private RewriterImpl =
| []-> []
| Decl(ty1, li1) :: Decl(ty2, li2) :: l when ty1 = ty2 ->
squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: l)
// int a=2; for (int b=3; ...) -> int a=2, b=3; for (; ...)
| Decl(ty1, li1) :: ForD((ty2, li2), cond, inc, body) :: l when ty1 = ty2 ->
squeezeConsecutiveDeclarations (Decl(ty1, li1 @ li2) :: ForE(None, cond, inc, body) :: l)
| e::l -> e :: squeezeConsecutiveDeclarations l

// Squeeze top-level declarations, e.g. uniforms
Expand Down
16 changes: 8 additions & 8 deletions tests/compression_results.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ mouton/mouton.vert... 16726 => 2399.560
audio-flight-v2.frag 4487 => 878.327
buoy.frag 4005 => 599.099
controllable-machinery.frag 7671 => 1220.647
ed-209.frag 7672 => 1338.529
elevated.hlsl 3401 => 602.542
endeavour.frag 2568 => 529.992
ed-209.frag 7677 => 1339.532
elevated.hlsl 3406 => 603.219
endeavour.frag 2573 => 528.814
from-the-seas-to-the-stars.frag 14211 => 2282.423
frozen-wasteland.frag 4515 => 804.953
kinder_painter.frag 2832 => 442.132
leizex.frag 2252 => 506.309
lunaquatic.frag 5222 => 1043.256
mandelbulb.frag 2317 => 532.741
lunaquatic.frag 5227 => 1044.673
mandelbulb.frag 2322 => 532.387
ohanami.frag 3246 => 712.723
orchard.frag 5394 => 1003.067
orchard.frag 5399 => 1004.125
oscars_chair.frag 4648 => 986.069
robin.frag 6196 => 1039.087
robin.frag 6199 => 1039.306
slisesix.frag 4497 => 890.639
terrarium.frag 3575 => 747.116
the_real_party_is_in_your_pocket.frag 11986 => 1774.550
valley_ball.glsl 4307 => 881.820
yx_long_way_from_home.frag 2936 => 598.845
Total: 133424 => 23300.612
Total: 133457 => 23303.455
4 changes: 2 additions & 2 deletions tests/real/ed-209.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ MarchData map(vec3 p)
float calcShadow(vec3 p,vec3 lightPos)
{
lightPos=normalize(lightPos-p);
float res=1.,t=.1,i=0.;
for(;i<SHADOW_STEPS;i++)
float res=1.,t=.1;
for(float i=0.;i<SHADOW_STEPS;i++)
{
float h=map(p+lightPos*t).d;
res=min(res,12.*h/t);
Expand Down
40 changes: 20 additions & 20 deletions tests/real/elevated.hlsl.expected
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const char *elevated_hlsl =
"float D(float2 f,float y)"
"{"
"float2 z=0;"
"float x=0,w=3,t=0;"
"for(;t<y;t++)"
"float x=0,w=3;"
"for(float r=0;r<y;r++)"
"{"
"float3 s=D(.25*f);"
"z+=s.yz;"
"x+=(w*=.5)*s.x/(1+mul(z,z));"
"float3 t=D(.25*f);"
"z+=t.yz;"
"x+=(w*=.5)*t.x/(1+mul(z,z));"
"f=mul(float2x2(1.6,-1.2,1.2,1.6),f);"
"}"
"return x;"
Expand Down Expand Up @@ -106,26 +106,26 @@ const char *elevated_hlsl =
"float4 s(float2 x:texcoord):color"
"{"
"float2 s=x+.5/1280;"
"float4 w=tex2D(m,s);"
"float3 r=tex2D(y,s);"
"if(w.w>.5)"
"float4 r=tex2D(m,s);"
"float3 w=tex2D(y,s);"
"if(r.w>.5)"
"{"
"w=mul(z,float4(w.xyz,1));"
"w.y*=-1;"
"r=0;"
"r=mul(z,float4(r.xyz,1));"
"r.y*=-1;"
"w=0;"
"for(float f=0;f<16;f++)"
"r.x+=tex2D(y,s+f*(.5+.5*w.xy/w.w-s)/16+float2(2,0)/1280).x,r.y+=tex2D(y,s+f*(.5+.5*w.xy/w.w-s)/16+float2(0,0)/1280).y,r.z+=tex2D(y,s+f*(.5+.5*w.xy/w.w-s)/16+float2(-2,0)/1280).z;"
"r/=16;"
"w.x+=tex2D(y,s+f*(.5+.5*r.xy/r.w-s)/16+float2(2,0)/1280).x,w.y+=tex2D(y,s+f*(.5+.5*r.xy/r.w-s)/16+float2(0,0)/1280).y,w.z+=tex2D(y,s+f*(.5+.5*r.xy/r.w-s)/16+float2(-2,0)/1280).z;"
"w/=16;"
"}"
"r=(pow(r,.45)*t[2].z+t[2].y)*(.4+9.6*s.x*s.y*(1-s.x)*(1-s.y));"
"r.xz*=.98;"
"w=(pow(w,.45)*t[2].z+t[2].y)*(.4+9.6*s.x*s.y*(1-s.x)*(1-s.y));"
"w.xz*=.98;"
"float D=tex2D(f,t[3].w*.1);"
"s+=D;"
"r-=.005*D;"
"r.x+=.01*tex2D(f,s+=.1);"
"r.y+=.01*tex2D(f,s+=.1);"
"r.z+=.01*tex2D(f,s+=.1);"
"return float4(r,0);"
"w-=.005*D;"
"w.x+=.01*tex2D(f,s+=.1);"
"w.y+=.01*tex2D(f,s+=.1);"
"w.z+=.01*tex2D(f,s+=.1);"
"return float4(w,0);"
"}";

#endif // ELEVATED_HLSL_EXPECTED_
4 changes: 2 additions & 2 deletions tests/real/endeavour.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void lfnoise(vec2 t,out float num)
void mfnoise(vec2 x,float fmin,float fmax,float alpha,out float num)
{
num=0.;
float a=1.,nf=0.,buf,f=fmin;
for(;f<fmax;f*=2.)
float a=1.,nf=0.,buf;
for(float f=fmin;f<fmax;f*=2.)
lfnoise(f*x,buf),num+=a*buf,a*=alpha,nf+=1.;
num*=(1.-alpha)/(1.-pow(alpha,nf));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/real/lunaquatic.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ vec3 getWaterNormal(vec3 p)
}
int traceTerrain(vec3 ro,vec3 rd,float maxt,out float depth)
{
float lh,ly,delt=0.,t=.1;
for(;t<maxt;t+=delt)
float lh,ly,delt=0.;
for(float t=.1;t<maxt;t+=delt)
{
ro+=rd*delt;
depth=height(ro.xz);
Expand Down
4 changes: 2 additions & 2 deletions tests/real/mandelbulb.expected
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const char *mandelbulb_frag =
"s.y=1e20;"
"float x;"
"vec3 z;"
"float t=1./sqrt(2.),d=s.x;"
"for(;d<s.y;)"
"float t=1./sqrt(2.);"
"for(float d=s.x;d<s.y;)"
"{"
"vec3 m=v+o*d;"
"float n=clamp(.001*d*t,1e-6,.005),p=n*.1;"
Expand Down
4 changes: 2 additions & 2 deletions tests/real/orchard.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ float shadow(vec3 ro,vec3 rd,float dis)
}
float calcOcc(vec3 pos,vec3 nor,float d)
{
float occ=0.,sca=1.,h=.05;
for(;h<.3;h+=.07)
float occ=0.,sca=1.;
for(float h=.05;h<.3;h+=.07)
{
vec3 opos=pos+h*nor;
float d=map(opos,d).x;
Expand Down
4 changes: 2 additions & 2 deletions tests/real/robin.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ float Scene(vec3 rO,vec3 rD,vec2 fragCoord)
{
float t=2.+.1*Hash(fragCoord.xy*fract(iTime)),alphaAcc=0.;
vec3 p=vec3(0);
int hits=0,j=0;
for(;j<40;j++)
int hits=0;
for(int j=0;j<40;j++)
{
if(hits==8||alphaAcc>=1.||t>45.)
break;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/blocks.expected
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const char *blocks_frag =
"int k=5;"
"float test_for()"
"{"
"int foo=2,n=0,i=0;"
"for(;i<4;i++)"
"int foo=2,n=0;"
"for(int i=0;i<4;i++)"
"foo+=i;"
"for(foo++;n<4;n++)"
"{"
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/loop.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const char *loop_frag =
"float a;"
"void main()"
"{"
"float c,d=0.;"
"for(;d<50.;++d)"
"float c;"
"for(float d=0.;d<50.;++d)"
"c+=cos(d);"
"float b;"
"for(b=0.;b<50.;++b)"
Expand Down

0 comments on commit e3aea3b

Please sign in to comment.