Skip to content

Commit e6d5aa7

Browse files
authored
Remove unsafe vec optimization (#234)
The optimization tried to remove a useless call to vec, e.g. replace vec2(v.xy) with v.xy This is not safe when the argument is not a vec2, e.g. it's an ivec2. Fixes #233
1 parent 8e5d8f2 commit e6d5aa7

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

src/options.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open System.IO
44
open Argu
55

6-
let version = "1.3.3" // Shader Minifier version
6+
let version = "1.3.4" // Shader Minifier version
77
let debugMode = false
88

99
type OutputFormat =

src/rewriter.fs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,7 @@ let private simplifyVec constr args =
225225

226226
let args = combineSwizzles args |> List.map useInts
227227
let args = mergeAllEquals args args
228-
match args with
229-
| [Dot (_, field) as arg] when field.Length > 1 && isFieldSwizzle field ->
230-
// vec3(v.xxy) => v.xxy
231-
// However, vec3(v.x) should be preserved.
232-
arg
233-
| _ -> FunCall (Var constr, args)
228+
FunCall (Var constr, args)
234229

235230
let private simplifyExpr (didInline: bool ref) env = function
236231
| FunCall(Var v, passedArgs) as e when v.ToBeInlined ->

tests/compression_results.log

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
clod.frag... 8960 => 1545.563
22
audio-flight-v2.frag 4650 => 902.661
3-
buoy.frag 4239 => 632.427
3+
buoy.frag 4245 => 633.229
44
controllable-machinery.frag 7773 => 1227.926
5-
ed-209.frag 7926 => 1363.748
5+
ed-209.frag 7938 => 1360.765
66
elevated.hlsl 3416 => 603.918
77
endeavour.frag 2661 => 541.942
88
from-the-seas-to-the-stars.frag 14370 => 2345.702
@@ -12,12 +12,12 @@ leizex.frag 2327 => 515.566
1212
lunaquatic.frag 5231 => 1055.816
1313
mandelbulb.frag 2419 => 546.857
1414
ohanami.frag 3292 => 736.461
15-
orchard.frag 5643 => 1034.091
15+
orchard.frag 5649 => 1035.594
1616
oscars_chair.frag 4653 => 984.586
1717
robin.frag 6343 => 1057.981
1818
slisesix.frag 4587 => 937.138
1919
terrarium.frag 3634 => 747.342
2020
the_real_party_is_in_your_pocket.frag 12248 => 1815.043
2121
valley_ball.glsl 4386 => 888.496
2222
yx_long_way_from_home.frag 3030 => 615.535
23-
Total: 119302 => 21362.097
23+
Total: 119326 => 21361.418

tests/real/ed-209.frag.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ float sdOctogon(vec2 p,float r)
5757
{
5858
const vec3 k=vec3(-.9238795325,.3826834323,.4142135623);
5959
p=abs(p);
60-
p-=2.*min(dot(k.xy,p),0.)*k.xy;
60+
p-=2.*min(dot(vec2(k.xy),p),0.)*vec2(k.xy);
6161
p-=2.*min(dot(vec2(-k.x,k.y),p),0.)*vec2(-k.x,k.y);
6262
p-=vec2(clamp(p.x,-k.z*r,k.z*r),r);
6363
return length(p)*sign(p.y);

tests/unit/vectors.frag.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
float swizzles()
22
{
33
vec2 v1=vec2(1);
4-
vec3 v2=v1.xyx,v3=vec3(v1.x,v2.xx);
5-
vec4 v4=v1.xxyx,v5=vec4(1,v2.zy,2),v6=vec4(v1.xy,v2.xy);
4+
vec3 v2=vec3(v1.xyx),v3=vec3(v1.x,v2.xx);
5+
vec4 v4=vec4(v1.xxyx),v5=vec4(1,v2.zy,2),v6=vec4(v1.xy,v2.xy);
66
return v1.x+v2.x+v3.x+v4.x+v5.x+v6.x;
77
}
88
vec4 constructor()

0 commit comments

Comments
 (0)