Replace Metal constant
keyword with const
.
"Constant" is an address space qualifier and can't be applied to a local variable. "Const" in GLSL (and hypothetically SkSL) is meant to apply to a constant expression regardless of address space. Our previous test was not finding any error because the optimizer was eliminating the constant expressions entirely. Change-Id: I6cfe8e2a621c79945b33e0166780d81e79890a1b Bug: skia:11304 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368517 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
da6426141f
commit
0bd5578c31
@ -3,7 +3,8 @@ uniform half4 colorGreen, colorRed;
|
||||
half4 main() {
|
||||
const float4 a = float4(0);
|
||||
const float4 b = float4(1);
|
||||
if (a == b) {
|
||||
const float4 c = abs(b); // still a Constant Expression, but SkSL cannot eliminate it (today)
|
||||
if (a == b || b != c) {
|
||||
return colorRed;
|
||||
} else {
|
||||
return colorGreen;
|
||||
|
@ -1559,7 +1559,7 @@ void MetalCodeGenerator::writeModifiers(const Modifiers& modifiers,
|
||||
this->write("thread ");
|
||||
}
|
||||
if (modifiers.fFlags & Modifiers::kConst_Flag) {
|
||||
this->write("constant ");
|
||||
this->write("const ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ struct Inputs {
|
||||
struct Outputs {
|
||||
float4 sk_FragColor [[color(0)]];
|
||||
};
|
||||
constant array<float, 4> test = array<float, 4>{1.0, 2.0, 3.0, 4.0};
|
||||
const array<float, 4> test = array<float, 4>{1.0, 2.0, 3.0, 4.0};
|
||||
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
||||
Outputs _out;
|
||||
(void)_out;
|
||||
|
@ -10,6 +10,7 @@ OpMemberName %_UniformBuffer 0 "colorGreen"
|
||||
OpMemberName %_UniformBuffer 1 "colorRed"
|
||||
OpName %_entrypoint "_entrypoint"
|
||||
OpName %main "main"
|
||||
OpName %c "c"
|
||||
OpDecorate %sk_FragColor RelaxedPrecision
|
||||
OpDecorate %sk_FragColor Location 0
|
||||
OpDecorate %sk_FragColor Index 0
|
||||
@ -22,7 +23,8 @@ OpMemberDecorate %_UniformBuffer 1 RelaxedPrecision
|
||||
OpDecorate %_UniformBuffer Block
|
||||
OpDecorate %10 Binding 0
|
||||
OpDecorate %10 DescriptorSet 0
|
||||
OpDecorate %24 RelaxedPrecision
|
||||
OpDecorate %36 RelaxedPrecision
|
||||
OpDecorate %39 RelaxedPrecision
|
||||
%float = OpTypeFloat 32
|
||||
%v4float = OpTypeVector %float 4
|
||||
%_ptr_Output_v4float = OpTypePointer Output %v4float
|
||||
@ -36,8 +38,13 @@ OpDecorate %24 RelaxedPrecision
|
||||
%void = OpTypeVoid
|
||||
%15 = OpTypeFunction %void
|
||||
%18 = OpTypeFunction %v4float
|
||||
%_ptr_Function_v4float = OpTypePointer Function %v4float
|
||||
%float_1 = OpConstant %float 1
|
||||
%24 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
|
||||
%v4bool = OpTypeVector %bool 4
|
||||
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
|
||||
%int = OpTypeInt 32 1
|
||||
%int_1 = OpConstant %int 1
|
||||
%int_0 = OpConstant %int 0
|
||||
%_entrypoint = OpFunction %void None %15
|
||||
%16 = OpLabel
|
||||
@ -47,7 +54,22 @@ OpReturn
|
||||
OpFunctionEnd
|
||||
%main = OpFunction %v4float None %18
|
||||
%19 = OpLabel
|
||||
%20 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
|
||||
%24 = OpLoad %v4float %20
|
||||
OpReturnValue %24
|
||||
%c = OpVariable %_ptr_Function_v4float Function
|
||||
%22 = OpExtInst %v4float %1 FAbs %24
|
||||
OpStore %c %22
|
||||
%25 = OpLoad %v4float %c
|
||||
%26 = OpFOrdNotEqual %v4bool %24 %25
|
||||
%28 = OpAny %bool %26
|
||||
OpSelectionMerge %31 None
|
||||
OpBranchConditional %28 %29 %30
|
||||
%29 = OpLabel
|
||||
%32 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1
|
||||
%36 = OpLoad %v4float %32
|
||||
OpReturnValue %36
|
||||
%30 = OpLabel
|
||||
%37 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
|
||||
%39 = OpLoad %v4float %37
|
||||
OpReturnValue %39
|
||||
%31 = OpLabel
|
||||
OpUnreachable
|
||||
OpFunctionEnd
|
||||
|
@ -3,7 +3,10 @@ out vec4 sk_FragColor;
|
||||
uniform vec4 colorGreen;
|
||||
uniform vec4 colorRed;
|
||||
vec4 main() {
|
||||
{
|
||||
const vec4 c = abs(vec4(1.0));
|
||||
if (vec4(1.0) != c) {
|
||||
return colorRed;
|
||||
} else {
|
||||
return colorGreen;
|
||||
}
|
||||
}
|
||||
|
@ -15,8 +15,13 @@ struct Outputs {
|
||||
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
||||
Outputs _out;
|
||||
(void)_out;
|
||||
{
|
||||
const float4 c = abs(float4(1.0));
|
||||
if (any(float4(1.0) != c)) {
|
||||
_out.sk_FragColor = _uniforms.colorRed;
|
||||
return _out;
|
||||
} else {
|
||||
_out.sk_FragColor = _uniforms.colorGreen;
|
||||
return _out;
|
||||
}
|
||||
return _out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user