skia2/tests/sksl/shared/ScopedSymbol.metal
John Stiles 5420cbcf65 Match GLSL scoping rules more closely in SkSL.
GLSL treats builtin types and user-defined types differently; `int` and
`float` are keywords and cannot be used to name variables. However, it's
fine for a user type like `struct xyz` to be hidden by a variable
`int xyz` or even `xyz xyz` (i.e., a variable of type `struct xyz` named
`xyz`).

We now honor that distinction and include tests for it. This will fix
several ES2 conformance tests (local_struct_variable_hides_struct_type,
local_int_variable_hides_struct_type, etc.).

Change-Id: I7a45c70707087f9f355ce5b06b032fed16683f3e
Bug: skia:12527
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458721
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-10-12 21:53:28 +00:00

44 lines
1.2 KiB
Metal

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct S {
int i;
};
struct Uniforms {
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
struct Globals {
int glob;
};
bool block_variable_hides_global_variable_b(thread Globals& _globals) {
return _globals.glob == 2;
}
bool local_variable_hides_struct_b() {
bool S = true;
return S;
}
bool local_struct_variable_hides_struct_type_b() {
S S = S{1};
return S.i == 1;
}
bool local_variable_hides_global_variable_b() {
int glob = 1;
return glob == 1;
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Globals _globals{{}};
(void)_globals;
Outputs _out;
(void)_out;
_globals.glob = 2;
bool _0_var = true;
_out.sk_FragColor = (((_0_var && block_variable_hides_global_variable_b(_globals)) && local_variable_hides_struct_b()) && local_struct_variable_hides_struct_type_b()) && local_variable_hides_global_variable_b() ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}