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>
21 lines
726 B
Metal
21 lines
726 B
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Uniforms {
|
|
float4 sk_RTAdjust;
|
|
};
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_Position [[position]];
|
|
float sk_PointSize [[point_size]];
|
|
};
|
|
|
|
vertex Outputs vertexMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], uint sk_VertexID [[vertex_id]], uint sk_InstanceID [[instance_id]]) {
|
|
Outputs _outputStruct;
|
|
thread Outputs* _out = &_outputStruct;
|
|
_out->sk_Position = float4(1.0);
|
|
_out->sk_Position = float4(_out->sk_Position.xy * _uniforms.sk_RTAdjust.xz + _out->sk_Position.ww * _uniforms.sk_RTAdjust.yw, 0.0, _out->sk_Position.w);
|
|
return (_out->sk_Position.y = -_out->sk_Position.y, *_out);
|
|
}
|