always init function fReturnValue

It's not sound to pass undefined (skvm::NA) values into select(),
but this is working today because the F32a argument is 'fixing' it.

The first time through this snippet updating fReturn value,

    int i = 0;
    for (skvm::Val& slot : currentFunction().fReturnValue) {
        slot = select(returnsHere, f32(val[i]), f32(slot)).id;
        i++;
    }

the call to f32(slot) creates an F32{builder, NA}.  We pass that to
select() and that argument's F32a(F32) constructor, resulting in
F32a{builder, NA, 0.0f}.  Then when we need that as an F32, we resolve
it as splat(0.0f) because the F32a's id field is NA.

In short, best to remove F32a. :)

Added some SkASSERTs that would have caught this.

Change-Id: I67324cf20ad39ca555e69b9c407f379d14046043
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353838
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2021-01-14 10:15:00 -06:00 committed by Skia Commit-Bot
parent a517cfc3f4
commit aebcf73404
2 changed files with 12 additions and 11 deletions

View File

@ -195,8 +195,8 @@ private:
*/
Slot getSlot(const Expression& e);
skvm::F32 f32(skvm::Val id) { return {fBuilder, id}; }
skvm::I32 i32(skvm::Val id) { return {fBuilder, id}; }
skvm::F32 f32(skvm::Val id) { SkASSERT(id != skvm::NA); return {fBuilder, id}; }
skvm::I32 i32(skvm::Val id) { SkASSERT(id != skvm::NA); return {fBuilder, id}; }
// Shorthand for scalars
skvm::F32 f32(const Value& v) { SkASSERT(v.slots() == 1); return f32(v[0]); }
@ -1483,7 +1483,8 @@ skvm::Color ProgramToSkVM(const Program& program,
skvm::Coord local,
SampleChildFn sampleChild) {
skvm::Val args[2] = {local.x.id, local.y.id};
skvm::Val result[4] = {skvm::NA, skvm::NA, skvm::NA, skvm::NA};
skvm::Val zero = builder->splat(0.0f).id;
skvm::Val result[4] = {zero,zero,zero,zero};
size_t paramSlots = 0;
for (const SkSL::Variable* param : function.declaration().parameters()) {
paramSlots += slot_count(param->type());

View File

@ -2,19 +2,19 @@
0 r0 = uniform32 ptr0 4
1 r1 = uniform32 ptr0 8
2 r2 = uniform32 ptr0 C
3 r3 = splat FFFFFFFF (nan)
4 r4 = splat 0 (0)
5 r5 = neq_f32 r0 r4
3 r3 = splat 0 (0)
4 r4 = splat FFFFFFFF (nan)
5 r5 = neq_f32 r0 r3
6 r6 = splat 3F800000 (1)
7 r6 = bit_and r6 r2
8 r7 = to_f32 r1
9 r7 = select r5 r6 r7
10 r4 = eq_i32 r1 r4
11 r4 = bit_xor r3 r4
12 r3 = splat 1 (1.4012985e-45)
13 r3 = bit_and r2 r3
10 r3 = eq_i32 r1 r3
11 r3 = bit_xor r4 r3
12 r4 = splat 1 (1.4012985e-45)
13 r4 = bit_and r2 r4
14 r0 = trunc r0
15 r0 = select r4 r3 r0
15 r0 = select r3 r4 r0
16 r0 = to_f32 r0
17 r0 = mul_f32 r7 r0
loop: