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>
18 lines
492 B
Metal
18 lines
492 B
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Inputs {
|
|
float4 pos;
|
|
};
|
|
struct Outputs {
|
|
float4 sk_Position [[position]];
|
|
float sk_PointSize [[point_size]];
|
|
};
|
|
|
|
vertex Outputs vertexMain(Inputs _in [[stage_in]], uint sk_VertexID [[vertex_id]], uint sk_InstanceID [[instance_id]]) {
|
|
Outputs _outputStruct;
|
|
thread Outputs* _out = &_outputStruct;
|
|
_out->sk_Position = _in.pos;
|
|
return (_out->sk_Position.y = -_out->sk_Position.y, *_out);
|
|
}
|