Skip to content

Commit 17129dc

Browse files
author
Carlos Scheidegger
committed
fix bug on Shade.cross.element
1 parent 2e9dad0 commit 17129dc

7 files changed

Lines changed: 76 additions & 51 deletions

File tree

lux.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9700,9 +9700,9 @@ function builtin_glsl_function(opts)
97009700
};
97019701
} else {
97029702
obj.element_is_constant = function(i) {
9703-
if (this.guid === 489) {
9704-
debugger;
9705-
}
9703+
// if (this.guid === 489) {
9704+
// debugger;
9705+
// }
97069706
return this.element(i).is_constant();
97079707
};
97089708
}
@@ -10074,8 +10074,8 @@ var cross = builtin_glsl_function({
1007410074
return vec3.cross(exp.parents[0].evaluate(cache),
1007510075
exp.parents[1].evaluate(cache));
1007610076
}, element_function: function (exp, i) {
10077-
var v1 = exp.parents[0].length;
10078-
var v2 = exp.parents[1].length;
10077+
var v1 = exp.parents[0];
10078+
var v2 = exp.parents[1];
1007910079
if (i === 0) { return v1.at(1).mul(v2.at(2)).sub(v1.at(2).mul(v2.at(1)));
1008010080
} else if (i === 1) { return v1.at(2).mul(v2.at(0)).sub(v1.at(0).mul(v2.at(2)));
1008110081
} else if (i === 2) { return v1.at(0).mul(v2.at(1)).sub(v1.at(1).mul(v2.at(0)));
@@ -10868,23 +10868,24 @@ Shade.program = function(program_obj)
1086810868

1086910869
var common_sequence = [
1087010870
[Shade.Optimizer.is_times_zero, Shade.Optimizer.replace_with_zero,
10871-
"v * 0", true],
10872-
[Shade.Optimizer.is_times_one, Shade.Optimizer.replace_with_notone,
10873-
"v * 1", true],
10874-
[Shade.Optimizer.is_plus_zero, Shade.Optimizer.replace_with_nonzero,
10875-
"v + 0", true],
10876-
[Shade.Optimizer.is_never_discarding,
10877-
Shade.Optimizer.remove_discard, "discard_if(false)"],
10878-
[Shade.Optimizer.is_known_branch,
10879-
Shade.Optimizer.prune_ifelse_branch, "constant?a:b", true],
10880-
[Shade.Optimizer.vec_at_constant_index,
10881-
Shade.Optimizer.replace_vec_at_constant_with_swizzle, "vec[constant_ix]"],
10882-
[Shade.Optimizer.is_constant,
10883-
Shade.Optimizer.replace_with_constant, "constant folding"],
10884-
[Shade.Optimizer.is_logical_or_with_constant,
10885-
Shade.Optimizer.replace_logical_or_with_constant, "constant||v", true],
10886-
[Shade.Optimizer.is_logical_and_with_constant,
10887-
Shade.Optimizer.replace_logical_and_with_constant, "constant&&v", true]];
10871+
"v * 0", true]
10872+
,[Shade.Optimizer.is_times_one, Shade.Optimizer.replace_with_notone,
10873+
"v * 1", true]
10874+
,[Shade.Optimizer.is_plus_zero, Shade.Optimizer.replace_with_nonzero,
10875+
"v + 0", true]
10876+
,[Shade.Optimizer.is_never_discarding,
10877+
Shade.Optimizer.remove_discard, "discard_if(false)"]
10878+
,[Shade.Optimizer.is_known_branch,
10879+
Shade.Optimizer.prune_ifelse_branch, "constant?a:b", true]
10880+
,[Shade.Optimizer.vec_at_constant_index,
10881+
Shade.Optimizer.replace_vec_at_constant_with_swizzle, "vec[constant_ix]"]
10882+
,[Shade.Optimizer.is_constant,
10883+
Shade.Optimizer.replace_with_constant, "constant folding"]
10884+
,[Shade.Optimizer.is_logical_or_with_constant,
10885+
Shade.Optimizer.replace_logical_or_with_constant, "constant||v", true]
10886+
,[Shade.Optimizer.is_logical_and_with_constant,
10887+
Shade.Optimizer.replace_logical_and_with_constant, "constant&&v", true]
10888+
];
1088810889

1088910890
// explicit per-vertex hoisting must happen before is_attribute hoisting,
1089010891
// otherwise we might end up reading from a varying in the vertex program,

lux.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shade/builtins.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ function builtin_glsl_function(opts)
109109
};
110110
} else {
111111
obj.element_is_constant = function(i) {
112-
if (this.guid === 489) {
113-
debugger;
114-
}
112+
// if (this.guid === 489) {
113+
// debugger;
114+
// }
115115
return this.element(i).is_constant();
116116
};
117117
}
@@ -483,8 +483,8 @@ var cross = builtin_glsl_function({
483483
return vec3.cross(exp.parents[0].evaluate(cache),
484484
exp.parents[1].evaluate(cache));
485485
}, element_function: function (exp, i) {
486-
var v1 = exp.parents[0].length;
487-
var v2 = exp.parents[1].length;
486+
var v1 = exp.parents[0];
487+
var v2 = exp.parents[1];
488488
if (i === 0) { return v1.at(1).mul(v2.at(2)).sub(v1.at(2).mul(v2.at(1)));
489489
} else if (i === 1) { return v1.at(2).mul(v2.at(0)).sub(v1.at(0).mul(v2.at(2)));
490490
} else if (i === 2) { return v1.at(0).mul(v2.at(1)).sub(v1.at(1).mul(v2.at(0)));

src/shade/program.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -431,23 +431,24 @@ Shade.program = function(program_obj)
431431

432432
var common_sequence = [
433433
[Shade.Optimizer.is_times_zero, Shade.Optimizer.replace_with_zero,
434-
"v * 0", true],
435-
[Shade.Optimizer.is_times_one, Shade.Optimizer.replace_with_notone,
436-
"v * 1", true],
437-
[Shade.Optimizer.is_plus_zero, Shade.Optimizer.replace_with_nonzero,
438-
"v + 0", true],
439-
[Shade.Optimizer.is_never_discarding,
440-
Shade.Optimizer.remove_discard, "discard_if(false)"],
441-
[Shade.Optimizer.is_known_branch,
442-
Shade.Optimizer.prune_ifelse_branch, "constant?a:b", true],
443-
[Shade.Optimizer.vec_at_constant_index,
444-
Shade.Optimizer.replace_vec_at_constant_with_swizzle, "vec[constant_ix]"],
445-
[Shade.Optimizer.is_constant,
446-
Shade.Optimizer.replace_with_constant, "constant folding"],
447-
[Shade.Optimizer.is_logical_or_with_constant,
448-
Shade.Optimizer.replace_logical_or_with_constant, "constant||v", true],
449-
[Shade.Optimizer.is_logical_and_with_constant,
450-
Shade.Optimizer.replace_logical_and_with_constant, "constant&&v", true]];
434+
"v * 0", true]
435+
,[Shade.Optimizer.is_times_one, Shade.Optimizer.replace_with_notone,
436+
"v * 1", true]
437+
,[Shade.Optimizer.is_plus_zero, Shade.Optimizer.replace_with_nonzero,
438+
"v + 0", true]
439+
,[Shade.Optimizer.is_never_discarding,
440+
Shade.Optimizer.remove_discard, "discard_if(false)"]
441+
,[Shade.Optimizer.is_known_branch,
442+
Shade.Optimizer.prune_ifelse_branch, "constant?a:b", true]
443+
,[Shade.Optimizer.vec_at_constant_index,
444+
Shade.Optimizer.replace_vec_at_constant_with_swizzle, "vec[constant_ix]"]
445+
,[Shade.Optimizer.is_constant,
446+
Shade.Optimizer.replace_with_constant, "constant folding"]
447+
,[Shade.Optimizer.is_logical_or_with_constant,
448+
Shade.Optimizer.replace_logical_or_with_constant, "constant||v", true]
449+
,[Shade.Optimizer.is_logical_and_with_constant,
450+
Shade.Optimizer.replace_logical_and_with_constant, "constant&&v", true]
451+
];
451452

452453
// explicit per-vertex hoisting must happen before is_attribute hoisting,
453454
// otherwise we might end up reading from a varying in the vertex program,

tests/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<script src="tests.js"></script>
1313
<script src="test_transforms.js"></script>
1414
<script src="test_bugs.js"></script>
15+
<script src="test_builtins.js"></script>
1516
<h1 id="qunit-header">Lux Test Suite</h1>
1617
<h2 id="qunit-banner"></h2>
1718
<div id="qunit-testrunner-toolbar"></div>

tests/test_bugs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ test("Tests from previous Lux bugs", function() {
3636
{"type":"constant","guid":241,"parents":[],"values":[1]}]}]}]},
3737
{"type":"constant","guid":244,"parents":[],"values":[0]}]};
3838

39+
var cond_exp = Shade.Debug.from_json(condition2);
40+
3941
var prog2 = { position: Shade.vec(0,0,0,0),
40-
color: Shade.Debug.from_json(condition2).ifelse(Shade.vec(1,0,0,0),
41-
Shade.vec(0,1,0,0)) };
42+
color: cond_exp.ifelse(Shade.vec(1,0,0,0),
43+
Shade.vec(0,1,0,0)) };
4244

4345
ok(Shade.program(prog2), "backface culling should not crash optimizer");
4446
});

tests/test_builtins.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
test("Test Shade builtins", function() {
2+
var exp = {"type": "vec", guid: 227, "parents": [
3+
{"type": "parameter", "parameter_type": "float", "guid":9999, "parents": []},
4+
{"type": "constant", "guid":9998, "parents": [], "values": [0]},
5+
{"type": "constant", "guid":9997, "parents": [], "values": [0]},
6+
{"type": "constant", "guid":9996, "parents": [], "values": [1]}]};
7+
var exp2 = {"type":"cross","guid":242,"parents":[
8+
{"type":"normalize","guid":238,"parents":[
9+
{"type":"cross","guid":237,"parents":[
10+
{"type":"dFdx","guid":235,"parents":[
11+
{"type":"div","guid":234,"parents":[
12+
{"type":"swizzle{xyz}","guid":232,"parents":[exp]},
13+
{"type":"swizzle{w}","guid":233,"parents":[{"type":"reference","guid":227}]}]}]},
14+
{"type":"dFdy","guid":236,"parents":[{"type":"reference","guid":234}]}]}]},
15+
{"type":"vec","guid":241,"parents":[
16+
{"type":"constant","guid":239,"parents":[],"values":[0]},
17+
{"type":"constant","guid":240,"parents":[],"values":[0]},
18+
{"type":"constant","guid":241,"parents":[],"values":[1]}]}]};
19+
ok(Shade.Debug.from_json(exp2).element(0));
20+
});

0 commit comments

Comments
 (0)