dc75a97b80
Previously, GLSL and Metal code generators would emit a struct wherever the type was first used in the code, regardless of where it was originally defined or what scope the type needs to live in. This CL adds a ProgramElement for struct definitions, so that structs will now appear at the top-level as they were originally defined. In the case of Metal, some special handling is also needed to handle the Globals struct properly. Not yet fully supported: - No special handling for structs declared inside functions yet - No support for structs in separate scopes with overlapping names The severity of the remaining issues depends mostly on whether we want to support structs inside functions in Runtime Effects. Change-Id: Ia95d4529506cb3fa6da63f5cb548199a93e1c0c5 Bug: skia:10922, skia:10923, skia:10925, skia:10926 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/338600 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
34 lines
708 B
Metal
34 lines
708 B
Metal
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
using namespace metal;
|
|
struct A {
|
|
int x;
|
|
int y;
|
|
};
|
|
struct B {
|
|
float x;
|
|
float y[2];
|
|
A z;
|
|
};
|
|
struct Inputs {
|
|
};
|
|
struct Outputs {
|
|
float4 sk_FragColor [[color(0)]];
|
|
};
|
|
struct Globals {
|
|
A a1;
|
|
B b1;
|
|
};
|
|
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
|
Globals globalStruct{{}, {}};
|
|
thread Globals* _globals = &globalStruct;
|
|
(void)_globals;
|
|
Outputs _outputStruct;
|
|
thread Outputs* _out = &_outputStruct;
|
|
_globals->a1.x = 0;
|
|
_globals->b1.x = 0.0;
|
|
_out->sk_FragColor.x = float(_globals->a1.x) + _globals->b1.x;
|
|
return *_out;
|
|
}
|