06b84efcb3
We now insert helper functions which defer the assignment of out- parameters back into their original variables to the end of the function call. This allows us to match the semantics listed the GLSL spec in section 6.1.1: "All arguments are evaluated at call time, exactly once, in order, from left to right. [...] Evaluation of an out parameter results in an l-value that is used to copy out a value when the function returns. Evaluation of an inout parameter results in both a value and an l-value; the value is copied to the formal parameter at call time and the lvalue is used to copy out a value when the function returns." This technique also allows us to support swizzled out-parameters in Metal, by reading the swizzle into a temp variable, calling the original function, and then re-assigning the result back into the original swizzle expression. At present, we don't deduplicate these helper functions, so in theory there could be a fair amount of redundant code generated if a function with out parameters is called many times in a row. The cost of properly deduplicating them is probably larger than the benefit in the 99% case. Change-Id: Iefc922ac9e2b24ef2ff1e9dacb17a735a75ec8ea Bug: skia:10855, skia:11052 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341162 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
33 lines
720 B
Metal
33 lines
720 B
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
void bar(thread float& x);
|
|
void _skOutParamHelper0_bar(thread float& x) {
|
|
float _var0 = x;
|
|
bar(_var0);
|
|
x = _var0;
|
|
}
|
|
float foo(float v[2]) {
|
|
return v[0] * v[1];
|
|
}
|
|
void bar(thread float& x) {
|
|
float y[2];
|
|
|
|
y[0] = x;
|
|
y[1] = x * 2.0;
|
|
foo(y);
|
|
}
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Outputs _outputStruct;
|
|
thread Outputs* _out = &_outputStruct;
|
|
float x = 10.0;
|
|
_skOutParamHelper0_bar(x);
|
|
_out->sk_FragColor = float4(x);
|
|
return *_out;
|
|
}
|