diff --git a/resources/sksl/intrinsics/ClampFloat.sksl b/resources/sksl/intrinsics/ClampFloat.sksl index cb47fd9a00..b1673d00f0 100644 --- a/resources/sksl/intrinsics/ClampFloat.sksl +++ b/resources/sksl/intrinsics/ClampFloat.sksl @@ -2,21 +2,28 @@ uniform half4 testInputs; uniform half4 colorGreen, colorRed; half4 main(float2 coords) { - half4 expectedA = half4(-1, 0, 0.75, 1); + half4 expectedA = half4(-1, 0, 0.75, 1); - // (-1.25, 0, 0.75, 2.25) - - half4 clampLow = half4(-1, -2, -2, 1); - half4 expectedB = half4(-1, 0, 0.5, 2.25); - half4 clampHigh = half4( 1, 2, 0.5, 3); + const half4 clampLow = half4(-1, -2, -2, 1); + const half4 constVal = half4(-1.25, 0, 0.75, 2.25); + half4 expectedB = half4(-1, 0, 0.5, 2.25); + const half4 clampHigh = half4( 1, 2, 0.5, 3); return (clamp(testInputs.x, -1, 1) == expectedA.x && clamp(testInputs.xy, -1, 1) == expectedA.xy && clamp(testInputs.xyz, -1, 1) == expectedA.xyz && clamp(testInputs.xyzw, -1, 1) == expectedA.xyzw && + clamp(constVal.x, -1, 1) == expectedA.x && + clamp(constVal.xy, -1, 1) == expectedA.xy && + clamp(constVal.xyz, -1, 1) == expectedA.xyz && + clamp(constVal.xyzw, -1, 1) == expectedA.xyzw && clamp(testInputs.x, clampLow.x, clampHigh.x ) == expectedB.x && clamp(testInputs.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy && clamp(testInputs.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz && - clamp(testInputs.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen + clamp(testInputs.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw && + clamp(constVal.x, clampLow.x, clampHigh.x ) == expectedB.x && + clamp(constVal.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy && + clamp(constVal.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz && + clamp(constVal.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen : colorRed; } diff --git a/resources/sksl/intrinsics/ClampInt.sksl b/resources/sksl/intrinsics/ClampInt.sksl index f4e6731283..436e65c560 100644 --- a/resources/sksl/intrinsics/ClampInt.sksl +++ b/resources/sksl/intrinsics/ClampInt.sksl @@ -2,22 +2,30 @@ uniform half4 testInputs; uniform half4 colorGreen, colorRed; half4 main(float2 coords) { - int4 expectedA = int4(-100, 0, 75, 100); + int4 intValues = int4(testInputs * 100); - int4 intValues = int4(testInputs * 100); - // (-125, 0, 75, 225) + int4 expectedA = int4(-100, 0, 75, 100); - int4 clampLow = int4(-100, -200, -200, 100); - int4 expectedB = int4(-100, 0, 50, 225); - int4 clampHigh = int4( 100, 200, 50, 300); + const int4 clampLow = int4(-100, -200, -200, 100); + const int4 constVal = int4(-125, 0, 75, 225); + int4 expectedB = int4(-100, 0, 50, 225); + const int4 clampHigh = int4( 100, 200, 50, 300); - return (clamp(intValues.x, -100, 100) == expectedA.x && - clamp(intValues.xy, -100, 100) == expectedA.xy && - clamp(intValues.xyz, -100, 100) == expectedA.xyz && - clamp(intValues.xyzw, -100, 100) == expectedA.xyzw && - clamp(intValues.x, clampLow.x, clampHigh.x ) == expectedB.x && - clamp(intValues.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy && - clamp(intValues.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz && - clamp(intValues.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen - : colorRed; + return (clamp(intValues.x, -100, 100) == expectedA.x && + clamp(intValues.xy, -100, 100) == expectedA.xy && + clamp(intValues.xyz, -100, 100) == expectedA.xyz && + clamp(intValues.xyzw, -100, 100) == expectedA.xyzw && + clamp(constVal.x, -100, 100) == expectedA.x && + clamp(constVal.xy, -100, 100) == expectedA.xy && + clamp(constVal.xyz, -100, 100) == expectedA.xyz && + clamp(constVal.xyzw, -100, 100) == expectedA.xyzw && + clamp(intValues.x, clampLow.x, clampHigh.x ) == expectedB.x && + clamp(intValues.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy && + clamp(intValues.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz && + clamp(intValues.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw && + clamp(constVal.x, clampLow.x, clampHigh.x ) == expectedB.x && + clamp(constVal.xy, clampLow.xy, clampHigh.xy ) == expectedB.xy && + clamp(constVal.xyz, clampLow.xyz, clampHigh.xyz ) == expectedB.xyz && + clamp(constVal.xyzw, clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen + : colorRed; } diff --git a/src/sksl/ir/SkSLFunctionCall.cpp b/src/sksl/ir/SkSLFunctionCall.cpp index 62c52f494b..96a7c4e0d8 100644 --- a/src/sksl/ir/SkSLFunctionCall.cpp +++ b/src/sksl/ir/SkSLFunctionCall.cpp @@ -147,7 +147,7 @@ static std::unique_ptr evaluate_n_way_intrinsic_of_type( const Expression* arg2Subexpr = nullptr; if (arg2) { - arg2Subexpr = arg2->getConstantSubexpression(arg1Index); + arg2Subexpr = arg2->getConstantSubexpression(arg2Index); arg2Index += arg2->type().isVector() ? 1 : 0; SkASSERT(arg2Subexpr); } @@ -246,6 +246,26 @@ static std::unique_ptr evaluate_pairwise_intrinsic(const Context& co return nullptr; } +template +static std::unique_ptr evaluate_3_way_intrinsic(const Context& context, + const ExpressionArray& arguments, + const FN& eval) { + SkASSERT(arguments.size() == 3); + const Type& type = arguments.front()->type().componentType(); + + if (type.isFloat()) { + return evaluate_n_way_intrinsic_of_type( + context, arguments[0].get(), arguments[1].get(), arguments[2].get(), eval); + } + if (type.isInteger()) { + return evaluate_n_way_intrinsic_of_type( + context, arguments[0].get(), arguments[1].get(), arguments[2].get(), eval); + } + + SkDEBUGFAILF("unsupported type %s", type.description().c_str()); + return nullptr; +} + static std::unique_ptr optimize_intrinsic_call(const Context& context, IntrinsicKind intrinsic, const ExpressionArray& arguments) { @@ -356,6 +376,9 @@ static std::unique_ptr optimize_intrinsic_call(const Context& contex case k_max_IntrinsicKind: return evaluate_pairwise_intrinsic(context, arguments, [](auto a, auto b) { return (a > b) ? a : b; }); + case k_clamp_IntrinsicKind: + return evaluate_3_way_intrinsic(context, arguments, + [](auto x, auto l, auto h) { return (x < l) ? l : (x > h) ? h : x; }); default: return nullptr; } diff --git a/tests/sksl/intrinsics/ClampFloat.asm.frag b/tests/sksl/intrinsics/ClampFloat.asm.frag index 327ebf02bc..e0402f90f8 100644 --- a/tests/sksl/intrinsics/ClampFloat.asm.frag +++ b/tests/sksl/intrinsics/ClampFloat.asm.frag @@ -56,37 +56,46 @@ OpDecorate %87 RelaxedPrecision OpDecorate %88 RelaxedPrecision OpDecorate %89 RelaxedPrecision OpDecorate %90 RelaxedPrecision -OpDecorate %99 RelaxedPrecision -OpDecorate %100 RelaxedPrecision -OpDecorate %101 RelaxedPrecision -OpDecorate %102 RelaxedPrecision +OpDecorate %97 RelaxedPrecision +OpDecorate %98 RelaxedPrecision OpDecorate %103 RelaxedPrecision OpDecorate %104 RelaxedPrecision OpDecorate %105 RelaxedPrecision -OpDecorate %106 RelaxedPrecision +OpDecorate %111 RelaxedPrecision +OpDecorate %112 RelaxedPrecision OpDecorate %113 RelaxedPrecision -OpDecorate %114 RelaxedPrecision -OpDecorate %115 RelaxedPrecision -OpDecorate %116 RelaxedPrecision -OpDecorate %117 RelaxedPrecision -OpDecorate %118 RelaxedPrecision OpDecorate %119 RelaxedPrecision -OpDecorate %120 RelaxedPrecision +OpDecorate %127 RelaxedPrecision OpDecorate %128 RelaxedPrecision OpDecorate %129 RelaxedPrecision OpDecorate %130 RelaxedPrecision -OpDecorate %131 RelaxedPrecision -OpDecorate %132 RelaxedPrecision -OpDecorate %133 RelaxedPrecision -OpDecorate %134 RelaxedPrecision -OpDecorate %135 RelaxedPrecision -OpDecorate %143 RelaxedPrecision -OpDecorate %144 RelaxedPrecision -OpDecorate %145 RelaxedPrecision -OpDecorate %146 RelaxedPrecision -OpDecorate %156 RelaxedPrecision -OpDecorate %159 RelaxedPrecision -OpDecorate %160 RelaxedPrecision +OpDecorate %137 RelaxedPrecision +OpDecorate %138 RelaxedPrecision +OpDecorate %139 RelaxedPrecision +OpDecorate %140 RelaxedPrecision +OpDecorate %141 RelaxedPrecision +OpDecorate %142 RelaxedPrecision +OpDecorate %150 RelaxedPrecision +OpDecorate %151 RelaxedPrecision +OpDecorate %152 RelaxedPrecision +OpDecorate %153 RelaxedPrecision +OpDecorate %154 RelaxedPrecision +OpDecorate %155 RelaxedPrecision +OpDecorate %163 RelaxedPrecision +OpDecorate %164 RelaxedPrecision +OpDecorate %165 RelaxedPrecision +OpDecorate %166 RelaxedPrecision +OpDecorate %172 RelaxedPrecision +OpDecorate %173 RelaxedPrecision +OpDecorate %178 RelaxedPrecision +OpDecorate %179 RelaxedPrecision +OpDecorate %185 RelaxedPrecision +OpDecorate %186 RelaxedPrecision +OpDecorate %187 RelaxedPrecision +OpDecorate %193 RelaxedPrecision +OpDecorate %203 RelaxedPrecision +OpDecorate %206 RelaxedPrecision +OpDecorate %207 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -125,6 +134,13 @@ OpDecorate %160 RelaxedPrecision %v3float = OpTypeVector %float 3 %v3bool = OpTypeVector %bool 3 %v4bool = OpTypeVector %bool 4 +%103 = OpConstantComposite %v2float %float_n1 %float_0 +%111 = OpConstantComposite %v3float %float_n1 %float_0 %float_0_75 +%139 = OpConstantComposite %v2float %float_n1 %float_n2 +%140 = OpConstantComposite %v2float %float_1 %float_2 +%152 = OpConstantComposite %v3float %float_n1 %float_n2 %float_n2 +%153 = OpConstantComposite %v3float %float_1 %float_2 %float_0_5 +%185 = OpConstantComposite %v3float %float_n1 %float_0 %float_0_5 %int_1 = OpConstant %int 1 %int_2 = OpConstant %int 2 %_entrypoint_v = OpFunction %void None %15 @@ -142,7 +158,7 @@ OpFunctionEnd %clampLow = OpVariable %_ptr_Function_v4float Function %expectedB = OpVariable %_ptr_Function_v4float Function %clampHigh = OpVariable %_ptr_Function_v4float Function -%150 = OpVariable %_ptr_Function_v4float Function +%197 = OpVariable %_ptr_Function_v4float Function OpStore %expectedA %31 OpStore %clampLow %34 OpStore %expectedB %38 @@ -203,83 +219,147 @@ OpBranch %84 OpSelectionMerge %96 None OpBranchConditional %94 %95 %96 %95 = OpLabel -%98 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 -%99 = OpLoad %v4float %98 -%100 = OpCompositeExtract %float %99 0 -%101 = OpLoad %v4float %clampLow -%102 = OpCompositeExtract %float %101 0 -%103 = OpLoad %v4float %clampHigh -%104 = OpCompositeExtract %float %103 0 -%97 = OpExtInst %float %1 FClamp %100 %102 %104 -%105 = OpLoad %v4float %expectedB -%106 = OpCompositeExtract %float %105 0 -%107 = OpFOrdEqual %bool %97 %106 +%97 = OpLoad %v4float %expectedA +%98 = OpCompositeExtract %float %97 0 +%99 = OpFOrdEqual %bool %float_n1 %98 OpBranch %96 %96 = OpLabel -%108 = OpPhi %bool %false %84 %107 %95 +%100 = OpPhi %bool %false %84 %99 %95 +OpSelectionMerge %102 None +OpBranchConditional %100 %101 %102 +%101 = OpLabel +%104 = OpLoad %v4float %expectedA +%105 = OpVectorShuffle %v2float %104 %104 0 1 +%106 = OpFOrdEqual %v2bool %103 %105 +%107 = OpAll %bool %106 +OpBranch %102 +%102 = OpLabel +%108 = OpPhi %bool %false %96 %107 %101 OpSelectionMerge %110 None OpBranchConditional %108 %109 %110 %109 = OpLabel -%112 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 -%113 = OpLoad %v4float %112 -%114 = OpVectorShuffle %v2float %113 %113 0 1 -%115 = OpLoad %v4float %clampLow -%116 = OpVectorShuffle %v2float %115 %115 0 1 -%117 = OpLoad %v4float %clampHigh -%118 = OpVectorShuffle %v2float %117 %117 0 1 -%111 = OpExtInst %v2float %1 FClamp %114 %116 %118 -%119 = OpLoad %v4float %expectedB -%120 = OpVectorShuffle %v2float %119 %119 0 1 -%121 = OpFOrdEqual %v2bool %111 %120 -%122 = OpAll %bool %121 +%112 = OpLoad %v4float %expectedA +%113 = OpVectorShuffle %v3float %112 %112 0 1 2 +%114 = OpFOrdEqual %v3bool %111 %113 +%115 = OpAll %bool %114 OpBranch %110 %110 = OpLabel -%123 = OpPhi %bool %false %96 %122 %109 -OpSelectionMerge %125 None -OpBranchConditional %123 %124 %125 +%116 = OpPhi %bool %false %102 %115 %109 +OpSelectionMerge %118 None +OpBranchConditional %116 %117 %118 +%117 = OpLabel +%119 = OpLoad %v4float %expectedA +%120 = OpFOrdEqual %v4bool %31 %119 +%121 = OpAll %bool %120 +OpBranch %118 +%118 = OpLabel +%122 = OpPhi %bool %false %110 %121 %117 +OpSelectionMerge %124 None +OpBranchConditional %122 %123 %124 +%123 = OpLabel +%126 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 +%127 = OpLoad %v4float %126 +%128 = OpCompositeExtract %float %127 0 +%125 = OpExtInst %float %1 FClamp %128 %float_n1 %float_1 +%129 = OpLoad %v4float %expectedB +%130 = OpCompositeExtract %float %129 0 +%131 = OpFOrdEqual %bool %125 %130 +OpBranch %124 %124 = OpLabel -%127 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 -%128 = OpLoad %v4float %127 -%129 = OpVectorShuffle %v3float %128 %128 0 1 2 -%130 = OpLoad %v4float %clampLow -%131 = OpVectorShuffle %v3float %130 %130 0 1 2 -%132 = OpLoad %v4float %clampHigh -%133 = OpVectorShuffle %v3float %132 %132 0 1 2 -%126 = OpExtInst %v3float %1 FClamp %129 %131 %133 -%134 = OpLoad %v4float %expectedB -%135 = OpVectorShuffle %v3float %134 %134 0 1 2 -%136 = OpFOrdEqual %v3bool %126 %135 -%137 = OpAll %bool %136 -OpBranch %125 -%125 = OpLabel -%138 = OpPhi %bool %false %110 %137 %124 -OpSelectionMerge %140 None -OpBranchConditional %138 %139 %140 -%139 = OpLabel -%142 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 -%143 = OpLoad %v4float %142 -%144 = OpLoad %v4float %clampLow -%145 = OpLoad %v4float %clampHigh -%141 = OpExtInst %v4float %1 FClamp %143 %144 %145 -%146 = OpLoad %v4float %expectedB -%147 = OpFOrdEqual %v4bool %141 %146 -%148 = OpAll %bool %147 -OpBranch %140 -%140 = OpLabel -%149 = OpPhi %bool %false %125 %148 %139 -OpSelectionMerge %153 None -OpBranchConditional %149 %151 %152 -%151 = OpLabel -%154 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1 -%156 = OpLoad %v4float %154 -OpStore %150 %156 -OpBranch %153 -%152 = OpLabel -%157 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 -%159 = OpLoad %v4float %157 -OpStore %150 %159 -OpBranch %153 -%153 = OpLabel -%160 = OpLoad %v4float %150 -OpReturnValue %160 +%132 = OpPhi %bool %false %118 %131 %123 +OpSelectionMerge %134 None +OpBranchConditional %132 %133 %134 +%133 = OpLabel +%136 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 +%137 = OpLoad %v4float %136 +%138 = OpVectorShuffle %v2float %137 %137 0 1 +%135 = OpExtInst %v2float %1 FClamp %138 %139 %140 +%141 = OpLoad %v4float %expectedB +%142 = OpVectorShuffle %v2float %141 %141 0 1 +%143 = OpFOrdEqual %v2bool %135 %142 +%144 = OpAll %bool %143 +OpBranch %134 +%134 = OpLabel +%145 = OpPhi %bool %false %124 %144 %133 +OpSelectionMerge %147 None +OpBranchConditional %145 %146 %147 +%146 = OpLabel +%149 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 +%150 = OpLoad %v4float %149 +%151 = OpVectorShuffle %v3float %150 %150 0 1 2 +%148 = OpExtInst %v3float %1 FClamp %151 %152 %153 +%154 = OpLoad %v4float %expectedB +%155 = OpVectorShuffle %v3float %154 %154 0 1 2 +%156 = OpFOrdEqual %v3bool %148 %155 +%157 = OpAll %bool %156 +OpBranch %147 +%147 = OpLabel +%158 = OpPhi %bool %false %134 %157 %146 +OpSelectionMerge %160 None +OpBranchConditional %158 %159 %160 +%159 = OpLabel +%162 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 +%163 = OpLoad %v4float %162 +%164 = OpLoad %v4float %clampLow +%165 = OpLoad %v4float %clampHigh +%161 = OpExtInst %v4float %1 FClamp %163 %164 %165 +%166 = OpLoad %v4float %expectedB +%167 = OpFOrdEqual %v4bool %161 %166 +%168 = OpAll %bool %167 +OpBranch %160 +%160 = OpLabel +%169 = OpPhi %bool %false %147 %168 %159 +OpSelectionMerge %171 None +OpBranchConditional %169 %170 %171 +%170 = OpLabel +%172 = OpLoad %v4float %expectedB +%173 = OpCompositeExtract %float %172 0 +%174 = OpFOrdEqual %bool %float_n1 %173 +OpBranch %171 +%171 = OpLabel +%175 = OpPhi %bool %false %160 %174 %170 +OpSelectionMerge %177 None +OpBranchConditional %175 %176 %177 +%176 = OpLabel +%178 = OpLoad %v4float %expectedB +%179 = OpVectorShuffle %v2float %178 %178 0 1 +%180 = OpFOrdEqual %v2bool %103 %179 +%181 = OpAll %bool %180 +OpBranch %177 +%177 = OpLabel +%182 = OpPhi %bool %false %171 %181 %176 +OpSelectionMerge %184 None +OpBranchConditional %182 %183 %184 +%183 = OpLabel +%186 = OpLoad %v4float %expectedB +%187 = OpVectorShuffle %v3float %186 %186 0 1 2 +%188 = OpFOrdEqual %v3bool %185 %187 +%189 = OpAll %bool %188 +OpBranch %184 +%184 = OpLabel +%190 = OpPhi %bool %false %177 %189 %183 +OpSelectionMerge %192 None +OpBranchConditional %190 %191 %192 +%191 = OpLabel +%193 = OpLoad %v4float %expectedB +%194 = OpFOrdEqual %v4bool %38 %193 +%195 = OpAll %bool %194 +OpBranch %192 +%192 = OpLabel +%196 = OpPhi %bool %false %184 %195 %191 +OpSelectionMerge %200 None +OpBranchConditional %196 %198 %199 +%198 = OpLabel +%201 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1 +%203 = OpLoad %v4float %201 +OpStore %197 %203 +OpBranch %200 +%199 = OpLabel +%204 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%206 = OpLoad %v4float %204 +OpStore %197 %206 +OpBranch %200 +%200 = OpLabel +%207 = OpLoad %v4float %197 +OpReturnValue %207 OpFunctionEnd diff --git a/tests/sksl/intrinsics/ClampFloat.glsl b/tests/sksl/intrinsics/ClampFloat.glsl index 8591348ac4..0c442a06ec 100644 --- a/tests/sksl/intrinsics/ClampFloat.glsl +++ b/tests/sksl/intrinsics/ClampFloat.glsl @@ -5,8 +5,8 @@ uniform vec4 colorGreen; uniform vec4 colorRed; vec4 main() { vec4 expectedA = vec4(-1.0, 0.0, 0.75, 1.0); - vec4 clampLow = vec4(-1.0, -2.0, -2.0, 1.0); + const vec4 clampLow = vec4(-1.0, -2.0, -2.0, 1.0); vec4 expectedB = vec4(-1.0, 0.0, 0.5, 2.25); - vec4 clampHigh = vec4(1.0, 2.0, 0.5, 3.0); - return ((((((clamp(testInputs.x, -1.0, 1.0) == expectedA.x && clamp(testInputs.xy, -1.0, 1.0) == expectedA.xy) && clamp(testInputs.xyz, -1.0, 1.0) == expectedA.xyz) && clamp(testInputs, -1.0, 1.0) == expectedA) && clamp(testInputs.x, clampLow.x, clampHigh.x) == expectedB.x) && clamp(testInputs.xy, clampLow.xy, clampHigh.xy) == expectedB.xy) && clamp(testInputs.xyz, clampLow.xyz, clampHigh.xyz) == expectedB.xyz) && clamp(testInputs, clampLow, clampHigh) == expectedB ? colorGreen : colorRed; + const vec4 clampHigh = vec4(1.0, 2.0, 0.5, 3.0); + return ((((((((((((((clamp(testInputs.x, -1.0, 1.0) == expectedA.x && clamp(testInputs.xy, -1.0, 1.0) == expectedA.xy) && clamp(testInputs.xyz, -1.0, 1.0) == expectedA.xyz) && clamp(testInputs, -1.0, 1.0) == expectedA) && -1.0 == expectedA.x) && vec2(-1.0, 0.0) == expectedA.xy) && vec3(-1.0, 0.0, 0.75) == expectedA.xyz) && vec4(-1.0, 0.0, 0.75, 1.0) == expectedA) && clamp(testInputs.x, -1.0, 1.0) == expectedB.x) && clamp(testInputs.xy, vec2(-1.0, -2.0), vec2(1.0, 2.0)) == expectedB.xy) && clamp(testInputs.xyz, vec3(-1.0, -2.0, -2.0), vec3(1.0, 2.0, 0.5)) == expectedB.xyz) && clamp(testInputs, clampLow, clampHigh) == expectedB) && -1.0 == expectedB.x) && vec2(-1.0, 0.0) == expectedB.xy) && vec3(-1.0, 0.0, 0.5) == expectedB.xyz) && vec4(-1.0, 0.0, 0.5, 2.25) == expectedB ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/ClampFloat.metal b/tests/sksl/intrinsics/ClampFloat.metal index eac9ee9a41..a6c5cef54a 100644 --- a/tests/sksl/intrinsics/ClampFloat.metal +++ b/tests/sksl/intrinsics/ClampFloat.metal @@ -15,9 +15,9 @@ fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _unifo Outputs _out; (void)_out; float4 expectedA = float4(-1.0, 0.0, 0.75, 1.0); - float4 clampLow = float4(-1.0, -2.0, -2.0, 1.0); + const float4 clampLow = float4(-1.0, -2.0, -2.0, 1.0); float4 expectedB = float4(-1.0, 0.0, 0.5, 2.25); - float4 clampHigh = float4(1.0, 2.0, 0.5, 3.0); - _out.sk_FragColor = ((((((clamp(_uniforms.testInputs.x, -1.0, 1.0) == expectedA.x && all(clamp(_uniforms.testInputs.xy, -1.0, 1.0) == expectedA.xy)) && all(clamp(_uniforms.testInputs.xyz, -1.0, 1.0) == expectedA.xyz)) && all(clamp(_uniforms.testInputs, -1.0, 1.0) == expectedA)) && clamp(_uniforms.testInputs.x, clampLow.x, clampHigh.x) == expectedB.x) && all(clamp(_uniforms.testInputs.xy, clampLow.xy, clampHigh.xy) == expectedB.xy)) && all(clamp(_uniforms.testInputs.xyz, clampLow.xyz, clampHigh.xyz) == expectedB.xyz)) && all(clamp(_uniforms.testInputs, clampLow, clampHigh) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; + const float4 clampHigh = float4(1.0, 2.0, 0.5, 3.0); + _out.sk_FragColor = ((((((((((((((clamp(_uniforms.testInputs.x, -1.0, 1.0) == expectedA.x && all(clamp(_uniforms.testInputs.xy, -1.0, 1.0) == expectedA.xy)) && all(clamp(_uniforms.testInputs.xyz, -1.0, 1.0) == expectedA.xyz)) && all(clamp(_uniforms.testInputs, -1.0, 1.0) == expectedA)) && -1.0 == expectedA.x) && all(float2(-1.0, 0.0) == expectedA.xy)) && all(float3(-1.0, 0.0, 0.75) == expectedA.xyz)) && all(float4(-1.0, 0.0, 0.75, 1.0) == expectedA)) && clamp(_uniforms.testInputs.x, -1.0, 1.0) == expectedB.x) && all(clamp(_uniforms.testInputs.xy, float2(-1.0, -2.0), float2(1.0, 2.0)) == expectedB.xy)) && all(clamp(_uniforms.testInputs.xyz, float3(-1.0, -2.0, -2.0), float3(1.0, 2.0, 0.5)) == expectedB.xyz)) && all(clamp(_uniforms.testInputs, clampLow, clampHigh) == expectedB)) && -1.0 == expectedB.x) && all(float2(-1.0, 0.0) == expectedB.xy)) && all(float3(-1.0, 0.0, 0.5) == expectedB.xyz)) && all(float4(-1.0, 0.0, 0.5, 2.25) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; } diff --git a/tests/sksl/intrinsics/ClampInt.asm.frag b/tests/sksl/intrinsics/ClampInt.asm.frag index 6933548c09..c3af233e9a 100644 --- a/tests/sksl/intrinsics/ClampInt.asm.frag +++ b/tests/sksl/intrinsics/ClampInt.asm.frag @@ -11,8 +11,8 @@ OpMemberName %_UniformBuffer 1 "colorGreen" OpMemberName %_UniformBuffer 2 "colorRed" OpName %_entrypoint_v "_entrypoint_v" OpName %main "main" -OpName %expectedA "expectedA" OpName %intValues "intValues" +OpName %expectedA "expectedA" OpName %clampLow "clampLow" OpName %expectedB "expectedB" OpName %clampHigh "clampHigh" @@ -29,15 +29,15 @@ OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision OpDecorate %_UniformBuffer Block OpDecorate %10 Binding 0 OpDecorate %10 DescriptorSet 0 +OpDecorate %33 RelaxedPrecision +OpDecorate %35 RelaxedPrecision +OpDecorate %36 RelaxedPrecision OpDecorate %38 RelaxedPrecision OpDecorate %40 RelaxedPrecision -OpDecorate %41 RelaxedPrecision -OpDecorate %43 RelaxedPrecision -OpDecorate %45 RelaxedPrecision -OpDecorate %47 RelaxedPrecision -OpDecorate %165 RelaxedPrecision -OpDecorate %168 RelaxedPrecision -OpDecorate %169 RelaxedPrecision +OpDecorate %42 RelaxedPrecision +OpDecorate %212 RelaxedPrecision +OpDecorate %215 RelaxedPrecision +OpDecorate %216 RelaxedPrecision %float = OpTypeFloat 32 %v4float = OpTypeVector %float 4 %_ptr_Output_v4float = OpTypePointer Output %v4float @@ -58,13 +58,13 @@ OpDecorate %169 RelaxedPrecision %int = OpTypeInt 32 1 %v4int = OpTypeVector %int 4 %_ptr_Function_v4int = OpTypePointer Function %v4int -%int_n100 = OpConstant %int -100 +%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float %int_0 = OpConstant %int 0 +%float_100 = OpConstant %float 100 +%int_n100 = OpConstant %int -100 %int_75 = OpConstant %int 75 %int_100 = OpConstant %int 100 -%34 = OpConstantComposite %v4int %int_n100 %int_0 %int_75 %int_100 -%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float -%float_100 = OpConstant %float 100 +%49 = OpConstantComposite %v4int %int_n100 %int_0 %int_75 %int_100 %int_n200 = OpConstant %int -200 %52 = OpConstantComposite %v4int %int_n100 %int_n200 %int_n200 %int_100 %int_50 = OpConstant %int 50 @@ -79,6 +79,13 @@ OpDecorate %169 RelaxedPrecision %v3int = OpTypeVector %int 3 %v3bool = OpTypeVector %bool 3 %v4bool = OpTypeVector %bool 4 +%115 = OpConstantComposite %v2int %int_n100 %int_0 +%123 = OpConstantComposite %v3int %int_n100 %int_0 %int_75 +%149 = OpConstantComposite %v2int %int_n100 %int_n200 +%150 = OpConstantComposite %v2int %int_100 %int_200 +%161 = OpConstantComposite %v3int %int_n100 %int_n200 %int_n200 +%162 = OpConstantComposite %v3int %int_100 %int_200 %int_50 +%193 = OpConstantComposite %v3int %int_n100 %int_0 %int_50 %_ptr_Function_v4float = OpTypePointer Function %v4float %int_1 = OpConstant %int 1 %int_2 = OpConstant %int 2 @@ -93,26 +100,26 @@ OpFunctionEnd %main = OpFunction %v4float None %23 %24 = OpFunctionParameter %_ptr_Function_v2float %25 = OpLabel -%expectedA = OpVariable %_ptr_Function_v4int Function %intValues = OpVariable %_ptr_Function_v4int Function +%expectedA = OpVariable %_ptr_Function_v4int Function %clampLow = OpVariable %_ptr_Function_v4int Function %expectedB = OpVariable %_ptr_Function_v4int Function %clampHigh = OpVariable %_ptr_Function_v4int Function -%158 = OpVariable %_ptr_Function_v4float Function -OpStore %expectedA %34 -%36 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 -%38 = OpLoad %v4float %36 -%40 = OpVectorTimesScalar %v4float %38 %float_100 -%41 = OpCompositeExtract %float %40 0 -%42 = OpConvertFToS %int %41 -%43 = OpCompositeExtract %float %40 1 -%44 = OpConvertFToS %int %43 -%45 = OpCompositeExtract %float %40 2 -%46 = OpConvertFToS %int %45 -%47 = OpCompositeExtract %float %40 3 -%48 = OpConvertFToS %int %47 -%49 = OpCompositeConstruct %v4int %42 %44 %46 %48 -OpStore %intValues %49 +%205 = OpVariable %_ptr_Function_v4float Function +%30 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0 +%33 = OpLoad %v4float %30 +%35 = OpVectorTimesScalar %v4float %33 %float_100 +%36 = OpCompositeExtract %float %35 0 +%37 = OpConvertFToS %int %36 +%38 = OpCompositeExtract %float %35 1 +%39 = OpConvertFToS %int %38 +%40 = OpCompositeExtract %float %35 2 +%41 = OpConvertFToS %int %40 +%42 = OpCompositeExtract %float %35 3 +%43 = OpConvertFToS %int %42 +%44 = OpCompositeConstruct %v4int %37 %39 %41 %43 +OpStore %intValues %44 +OpStore %expectedA %49 OpStore %clampLow %52 OpStore %expectedB %56 OpStore %clampHigh %60 @@ -168,79 +175,143 @@ OpBranch %97 OpSelectionMerge %108 None OpBranchConditional %106 %107 %108 %107 = OpLabel -%110 = OpLoad %v4int %intValues -%111 = OpCompositeExtract %int %110 0 -%112 = OpLoad %v4int %clampLow -%113 = OpCompositeExtract %int %112 0 -%114 = OpLoad %v4int %clampHigh -%115 = OpCompositeExtract %int %114 0 -%109 = OpExtInst %int %1 SClamp %111 %113 %115 -%116 = OpLoad %v4int %expectedB -%117 = OpCompositeExtract %int %116 0 -%118 = OpIEqual %bool %109 %117 +%109 = OpLoad %v4int %expectedA +%110 = OpCompositeExtract %int %109 0 +%111 = OpIEqual %bool %int_n100 %110 OpBranch %108 %108 = OpLabel -%119 = OpPhi %bool %false %97 %118 %107 -OpSelectionMerge %121 None -OpBranchConditional %119 %120 %121 -%120 = OpLabel -%123 = OpLoad %v4int %intValues -%124 = OpVectorShuffle %v2int %123 %123 0 1 -%125 = OpLoad %v4int %clampLow -%126 = OpVectorShuffle %v2int %125 %125 0 1 -%127 = OpLoad %v4int %clampHigh -%128 = OpVectorShuffle %v2int %127 %127 0 1 -%122 = OpExtInst %v2int %1 SClamp %124 %126 %128 -%129 = OpLoad %v4int %expectedB -%130 = OpVectorShuffle %v2int %129 %129 0 1 -%131 = OpIEqual %v2bool %122 %130 -%132 = OpAll %bool %131 -OpBranch %121 +%112 = OpPhi %bool %false %97 %111 %107 +OpSelectionMerge %114 None +OpBranchConditional %112 %113 %114 +%113 = OpLabel +%116 = OpLoad %v4int %expectedA +%117 = OpVectorShuffle %v2int %116 %116 0 1 +%118 = OpIEqual %v2bool %115 %117 +%119 = OpAll %bool %118 +OpBranch %114 +%114 = OpLabel +%120 = OpPhi %bool %false %108 %119 %113 +OpSelectionMerge %122 None +OpBranchConditional %120 %121 %122 %121 = OpLabel -%133 = OpPhi %bool %false %108 %132 %120 -OpSelectionMerge %135 None -OpBranchConditional %133 %134 %135 -%134 = OpLabel -%137 = OpLoad %v4int %intValues -%138 = OpVectorShuffle %v3int %137 %137 0 1 2 -%139 = OpLoad %v4int %clampLow -%140 = OpVectorShuffle %v3int %139 %139 0 1 2 -%141 = OpLoad %v4int %clampHigh -%142 = OpVectorShuffle %v3int %141 %141 0 1 2 -%136 = OpExtInst %v3int %1 SClamp %138 %140 %142 -%143 = OpLoad %v4int %expectedB -%144 = OpVectorShuffle %v3int %143 %143 0 1 2 -%145 = OpIEqual %v3bool %136 %144 -%146 = OpAll %bool %145 -OpBranch %135 +%124 = OpLoad %v4int %expectedA +%125 = OpVectorShuffle %v3int %124 %124 0 1 2 +%126 = OpIEqual %v3bool %123 %125 +%127 = OpAll %bool %126 +OpBranch %122 +%122 = OpLabel +%128 = OpPhi %bool %false %114 %127 %121 +OpSelectionMerge %130 None +OpBranchConditional %128 %129 %130 +%129 = OpLabel +%131 = OpLoad %v4int %expectedA +%132 = OpIEqual %v4bool %49 %131 +%133 = OpAll %bool %132 +OpBranch %130 +%130 = OpLabel +%134 = OpPhi %bool %false %122 %133 %129 +OpSelectionMerge %136 None +OpBranchConditional %134 %135 %136 %135 = OpLabel -%147 = OpPhi %bool %false %121 %146 %134 -OpSelectionMerge %149 None -OpBranchConditional %147 %148 %149 -%148 = OpLabel -%151 = OpLoad %v4int %intValues -%152 = OpLoad %v4int %clampLow -%153 = OpLoad %v4int %clampHigh -%150 = OpExtInst %v4int %1 SClamp %151 %152 %153 -%154 = OpLoad %v4int %expectedB -%155 = OpIEqual %v4bool %150 %154 -%156 = OpAll %bool %155 -OpBranch %149 -%149 = OpLabel -%157 = OpPhi %bool %false %135 %156 %148 -OpSelectionMerge %162 None -OpBranchConditional %157 %160 %161 -%160 = OpLabel -%163 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1 -%165 = OpLoad %v4float %163 -OpStore %158 %165 -OpBranch %162 -%161 = OpLabel -%166 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 -%168 = OpLoad %v4float %166 -OpStore %158 %168 -OpBranch %162 -%162 = OpLabel -%169 = OpLoad %v4float %158 -OpReturnValue %169 +%138 = OpLoad %v4int %intValues +%139 = OpCompositeExtract %int %138 0 +%137 = OpExtInst %int %1 SClamp %139 %int_n100 %int_100 +%140 = OpLoad %v4int %expectedB +%141 = OpCompositeExtract %int %140 0 +%142 = OpIEqual %bool %137 %141 +OpBranch %136 +%136 = OpLabel +%143 = OpPhi %bool %false %130 %142 %135 +OpSelectionMerge %145 None +OpBranchConditional %143 %144 %145 +%144 = OpLabel +%147 = OpLoad %v4int %intValues +%148 = OpVectorShuffle %v2int %147 %147 0 1 +%146 = OpExtInst %v2int %1 SClamp %148 %149 %150 +%151 = OpLoad %v4int %expectedB +%152 = OpVectorShuffle %v2int %151 %151 0 1 +%153 = OpIEqual %v2bool %146 %152 +%154 = OpAll %bool %153 +OpBranch %145 +%145 = OpLabel +%155 = OpPhi %bool %false %136 %154 %144 +OpSelectionMerge %157 None +OpBranchConditional %155 %156 %157 +%156 = OpLabel +%159 = OpLoad %v4int %intValues +%160 = OpVectorShuffle %v3int %159 %159 0 1 2 +%158 = OpExtInst %v3int %1 SClamp %160 %161 %162 +%163 = OpLoad %v4int %expectedB +%164 = OpVectorShuffle %v3int %163 %163 0 1 2 +%165 = OpIEqual %v3bool %158 %164 +%166 = OpAll %bool %165 +OpBranch %157 +%157 = OpLabel +%167 = OpPhi %bool %false %145 %166 %156 +OpSelectionMerge %169 None +OpBranchConditional %167 %168 %169 +%168 = OpLabel +%171 = OpLoad %v4int %intValues +%172 = OpLoad %v4int %clampLow +%173 = OpLoad %v4int %clampHigh +%170 = OpExtInst %v4int %1 SClamp %171 %172 %173 +%174 = OpLoad %v4int %expectedB +%175 = OpIEqual %v4bool %170 %174 +%176 = OpAll %bool %175 +OpBranch %169 +%169 = OpLabel +%177 = OpPhi %bool %false %157 %176 %168 +OpSelectionMerge %179 None +OpBranchConditional %177 %178 %179 +%178 = OpLabel +%180 = OpLoad %v4int %expectedB +%181 = OpCompositeExtract %int %180 0 +%182 = OpIEqual %bool %int_n100 %181 +OpBranch %179 +%179 = OpLabel +%183 = OpPhi %bool %false %169 %182 %178 +OpSelectionMerge %185 None +OpBranchConditional %183 %184 %185 +%184 = OpLabel +%186 = OpLoad %v4int %expectedB +%187 = OpVectorShuffle %v2int %186 %186 0 1 +%188 = OpIEqual %v2bool %115 %187 +%189 = OpAll %bool %188 +OpBranch %185 +%185 = OpLabel +%190 = OpPhi %bool %false %179 %189 %184 +OpSelectionMerge %192 None +OpBranchConditional %190 %191 %192 +%191 = OpLabel +%194 = OpLoad %v4int %expectedB +%195 = OpVectorShuffle %v3int %194 %194 0 1 2 +%196 = OpIEqual %v3bool %193 %195 +%197 = OpAll %bool %196 +OpBranch %192 +%192 = OpLabel +%198 = OpPhi %bool %false %185 %197 %191 +OpSelectionMerge %200 None +OpBranchConditional %198 %199 %200 +%199 = OpLabel +%201 = OpLoad %v4int %expectedB +%202 = OpIEqual %v4bool %56 %201 +%203 = OpAll %bool %202 +OpBranch %200 +%200 = OpLabel +%204 = OpPhi %bool %false %192 %203 %199 +OpSelectionMerge %209 None +OpBranchConditional %204 %207 %208 +%207 = OpLabel +%210 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1 +%212 = OpLoad %v4float %210 +OpStore %205 %212 +OpBranch %209 +%208 = OpLabel +%213 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2 +%215 = OpLoad %v4float %213 +OpStore %205 %215 +OpBranch %209 +%209 = OpLabel +%216 = OpLoad %v4float %205 +OpReturnValue %216 OpFunctionEnd diff --git a/tests/sksl/intrinsics/ClampInt.glsl b/tests/sksl/intrinsics/ClampInt.glsl index e80560e8b7..4e50a8b865 100644 --- a/tests/sksl/intrinsics/ClampInt.glsl +++ b/tests/sksl/intrinsics/ClampInt.glsl @@ -4,10 +4,10 @@ uniform vec4 testInputs; uniform vec4 colorGreen; uniform vec4 colorRed; vec4 main() { - ivec4 expectedA = ivec4(-100, 0, 75, 100); ivec4 intValues = ivec4(testInputs * 100.0); - ivec4 clampLow = ivec4(-100, -200, -200, 100); + ivec4 expectedA = ivec4(-100, 0, 75, 100); + const ivec4 clampLow = ivec4(-100, -200, -200, 100); ivec4 expectedB = ivec4(-100, 0, 50, 225); - ivec4 clampHigh = ivec4(100, 200, 50, 300); - return ((((((clamp(intValues.x, -100, 100) == expectedA.x && clamp(intValues.xy, -100, 100) == expectedA.xy) && clamp(intValues.xyz, -100, 100) == expectedA.xyz) && clamp(intValues, -100, 100) == expectedA) && clamp(intValues.x, clampLow.x, clampHigh.x) == expectedB.x) && clamp(intValues.xy, clampLow.xy, clampHigh.xy) == expectedB.xy) && clamp(intValues.xyz, clampLow.xyz, clampHigh.xyz) == expectedB.xyz) && clamp(intValues, clampLow, clampHigh) == expectedB ? colorGreen : colorRed; + const ivec4 clampHigh = ivec4(100, 200, 50, 300); + return ((((((((((((((clamp(intValues.x, -100, 100) == expectedA.x && clamp(intValues.xy, -100, 100) == expectedA.xy) && clamp(intValues.xyz, -100, 100) == expectedA.xyz) && clamp(intValues, -100, 100) == expectedA) && -100 == expectedA.x) && ivec2(-100, 0) == expectedA.xy) && ivec3(-100, 0, 75) == expectedA.xyz) && ivec4(-100, 0, 75, 100) == expectedA) && clamp(intValues.x, -100, 100) == expectedB.x) && clamp(intValues.xy, ivec2(-100, -200), ivec2(100, 200)) == expectedB.xy) && clamp(intValues.xyz, ivec3(-100, -200, -200), ivec3(100, 200, 50)) == expectedB.xyz) && clamp(intValues, clampLow, clampHigh) == expectedB) && -100 == expectedB.x) && ivec2(-100, 0) == expectedB.xy) && ivec3(-100, 0, 50) == expectedB.xyz) && ivec4(-100, 0, 50, 225) == expectedB ? colorGreen : colorRed; } diff --git a/tests/sksl/intrinsics/ClampInt.metal b/tests/sksl/intrinsics/ClampInt.metal index 1ca306a502..1fd0619503 100644 --- a/tests/sksl/intrinsics/ClampInt.metal +++ b/tests/sksl/intrinsics/ClampInt.metal @@ -14,11 +14,11 @@ 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; - int4 expectedA = int4(-100, 0, 75, 100); int4 intValues = int4(_uniforms.testInputs * 100.0); - int4 clampLow = int4(-100, -200, -200, 100); + int4 expectedA = int4(-100, 0, 75, 100); + const int4 clampLow = int4(-100, -200, -200, 100); int4 expectedB = int4(-100, 0, 50, 225); - int4 clampHigh = int4(100, 200, 50, 300); - _out.sk_FragColor = ((((((clamp(intValues.x, -100, 100) == expectedA.x && all(clamp(intValues.xy, -100, 100) == expectedA.xy)) && all(clamp(intValues.xyz, -100, 100) == expectedA.xyz)) && all(clamp(intValues, -100, 100) == expectedA)) && clamp(intValues.x, clampLow.x, clampHigh.x) == expectedB.x) && all(clamp(intValues.xy, clampLow.xy, clampHigh.xy) == expectedB.xy)) && all(clamp(intValues.xyz, clampLow.xyz, clampHigh.xyz) == expectedB.xyz)) && all(clamp(intValues, clampLow, clampHigh) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; + const int4 clampHigh = int4(100, 200, 50, 300); + _out.sk_FragColor = ((((((((((((((clamp(intValues.x, -100, 100) == expectedA.x && all(clamp(intValues.xy, -100, 100) == expectedA.xy)) && all(clamp(intValues.xyz, -100, 100) == expectedA.xyz)) && all(clamp(intValues, -100, 100) == expectedA)) && -100 == expectedA.x) && all(int2(-100, 0) == expectedA.xy)) && all(int3(-100, 0, 75) == expectedA.xyz)) && all(int4(-100, 0, 75, 100) == expectedA)) && clamp(intValues.x, -100, 100) == expectedB.x) && all(clamp(intValues.xy, int2(-100, -200), int2(100, 200)) == expectedB.xy)) && all(clamp(intValues.xyz, int3(-100, -200, -200), int3(100, 200, 50)) == expectedB.xyz)) && all(clamp(intValues, clampLow, clampHigh) == expectedB)) && -100 == expectedB.x) && all(int2(-100, 0) == expectedB.xy)) && all(int3(-100, 0, 50) == expectedB.xyz)) && all(int4(-100, 0, 50, 225) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed; return _out; }