986c7fb8ca
The Metal return type from main() diverges from the SkSL source, so we patch it in the Metal code generator. This CL improves the patching process in multiple ways: - A `return` statement from a fragment processor main() is rewritten to: return *_out; - A `return` statement from a vertex processor main() is rewritten to: return (_out->sk_Position.y = -_out->sk_Position.y, *_out); - We avoid emitting a duplicate `return *_out;` statement if we can determine that main() already ends in a return statement. This is harmless either way so it doesn't necessarily catch everything. (e.g. it doesn't detect an if/else which returns at the end of both blocks.) Also added a unit test which returns from the middle of a vertex shader, since we didn't test this anywhere and we need to verify that sk_Position.y will be negated. (This didn't work properly before.) Change-Id: I14cf18375894fc712fa6c6466df3888ebaeba7c8 Bug: skia:10903 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/339636 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
30 lines
775 B
Metal
30 lines
775 B
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Outputs _outputStruct;
|
|
thread Outputs* _out = &_outputStruct;
|
|
if (sqrt(2.0) > 5.0) {
|
|
_out->sk_FragColor = float4(0.75);
|
|
} else {
|
|
discard_fragment();
|
|
}
|
|
int i = 0;
|
|
while (i < 10) {
|
|
_out->sk_FragColor *= 0.5;
|
|
i++;
|
|
}
|
|
do {
|
|
_out->sk_FragColor += 0.25;
|
|
} while (_out->sk_FragColor.x < 0.75);
|
|
for (int i = 0;i < 10; i++) {
|
|
if (i % 2 == 1) break; else if (i > 100) return *_out; else continue;
|
|
}
|
|
return *_out;
|
|
}
|