From 81d4ed0d9c0e87962a46ee4cdec69adcb0247217 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 21 Jul 2021 14:11:01 +0000 Subject: [PATCH] Fix operator% for f32 and vecN https://github.com/gpuweb/gpuweb/pull/1945 changes the SPIR-V mapping of this operator so that it now maps to OpFRem instead of OpFMod. Polyfill OpFMod with `x - y * floor(x / y)` Also map the MSL output of this operator to use `fmod()`. Behavior of this operator is now consistent across all backends. Fixed: tint:945 Fixed: tint:977 Fixed: tint:1010 Change-Id: Iefa009b905989c55ace24e073ab0e261c7cf69b0 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/58393 Auto-Submit: Ben Clayton Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: David Neto --- src/reader/spirv/function.cc | 26 +- src/reader/spirv/function.h | 5 + src/reader/spirv/function_arithmetic_test.cc | 108 ++++++++- src/writer/msl/generator_impl.cc | 17 +- src/writer/msl/generator_impl_binary_test.cc | 30 ++- src/writer/spirv/builder.cc | 2 +- .../spirv/builder_binary_expression_test.cc | 2 +- test/bug/tint/948.wgsl.expected.msl | 223 +++++++++++++++++- test/bug/tint/948.wgsl.expected.spvasm | 2 +- test/bug/tint/977.spvasm.expected.hlsl | 2 +- test/bug/tint/977.spvasm.expected.msl | 11 +- test/bug/tint/977.spvasm.expected.spvasm | 95 ++++---- test/bug/tint/977.spvasm.expected.wgsl | 2 +- .../mod/scalar-scalar/f32.wgsl.expected.msl | 11 +- .../scalar-scalar/f32.wgsl.expected.spvasm | 2 +- .../mod/vec3-vec3/f32.wgsl.expected.msl | 11 +- .../mod/vec3-vec3/f32.wgsl.expected.spvasm | 2 +- 17 files changed, 453 insertions(+), 98 deletions(-) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 7f302c3ed0..d673c60bb6 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -212,7 +212,7 @@ ast::BinaryOp ConvertBinaryOp(SpvOp opcode) { return ast::BinaryOp::kDivide; case SpvOpUMod: case SpvOpSMod: - case SpvOpFMod: + case SpvOpFRem: return ast::BinaryOp::kModulo; case SpvOpLogicalEqual: case SpvOpIEqual: @@ -398,8 +398,9 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) { return "unpack2x16float"; default: - // TODO(dneto) - The following are not implemented. - // They are grouped semantically, as in GLSL.std.450.h. + // TODO(dneto) - The following are not implemented. + // They are grouped semantically, as in GLSL.std.450.h. + case GLSLstd450SSign: case GLSLstd450Radians: @@ -3854,6 +3855,10 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( return MakeIntrinsicCall(inst); } + if (opcode == SpvOpFMod) { + return MakeFMod(inst); + } + if (opcode == SpvOpAccessChain || opcode == SpvOpInBoundsAccessChain) { return MakeAccessChain(inst); } @@ -4074,6 +4079,21 @@ ast::IdentifierExpression* FunctionEmitter::PrefixSwizzle(uint32_t n) { return nullptr; } +TypedExpression FunctionEmitter::MakeFMod( + const spvtools::opt::Instruction& inst) { + auto x = MakeOperand(inst, 0); + auto y = MakeOperand(inst, 1); + if (!x || !y) { + return {}; + } + // Emulated with: x - y * floor(x / y) + auto* div = builder_.Div(x.expr, y.expr); + auto* floor = builder_.Call("floor", div); + auto* y_floor = builder_.Mul(y.expr, floor); + auto* res = builder_.Sub(x.expr, y_floor); + return {x.type, res}; +} + TypedExpression FunctionEmitter::MakeAccessChain( const spvtools::opt::Instruction& inst) { if (inst.NumInOperands() < 1) { diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index 1cfed625a8..f4885b2703 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -966,6 +966,11 @@ class FunctionEmitter { /// @results a copy of the expression, with possibly updated type TypedExpression InferFunctionStorageClass(TypedExpression expr); + /// Returns an expression for a SPIR-V OpFMod instruction. + /// @param inst the SPIR-V instruction + /// @returns an expression + TypedExpression MakeFMod(const spvtools::opt::Instruction& inst); + /// Returns an expression for a SPIR-V OpAccessChain or OpInBoundsAccessChain /// instruction. /// @param inst the SPIR-V instruction diff --git a/src/reader/spirv/function_arithmetic_test.cc b/src/reader/spirv/function_arithmetic_test.cc index 4897015ddb..9788a5ce56 100644 --- a/src/reader/spirv/function_arithmetic_test.cc +++ b/src/reader/spirv/function_arithmetic_test.cc @@ -1239,18 +1239,120 @@ TEST_F(SpvBinaryArithTestBasic, SMod_Vector_UnsignedResult) { } INSTANTIATE_TEST_SUITE_P( - SpvParserTest_FMod, + SpvParserTest_FRem, SpvBinaryArithTest, ::testing::Values( // Scalar float - BinaryData{"float", "float_50", "OpFMod", "float_60", "__f32", + BinaryData{"float", "float_50", "OpFRem", "float_60", "__f32", "ScalarConstructor[not set]{50.000000}", "modulo", "ScalarConstructor[not set]{60.000000}"}, // Vector float - BinaryData{"v2float", "v2float_50_60", "OpFMod", "v2float_60_50", + BinaryData{"v2float", "v2float_50_60", "OpFRem", "v2float_60_50", "__vec_2__f32", AstFor("v2float_50_60"), "modulo", AstFor("v2float_60_50")})); +TEST_F(SpvBinaryArithTestBasic, FMod_Scalar) { + const auto assembly = Preamble() + R"( + %100 = OpFunction %void None %voidfn + %entry = OpLabel + %1 = OpFMod %float %float_50 %float_60 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) + << p->error() << "\n" + << assembly; + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( + VariableConst{ + x_1 + none + undefined + __f32 + { + Binary[not set]{ + ScalarConstructor[not set]{50.000000} + subtract + Binary[not set]{ + ScalarConstructor[not set]{60.000000} + multiply + Call[not set]{ + Identifier[not set]{floor} + ( + Binary[not set]{ + ScalarConstructor[not set]{50.000000} + divide + ScalarConstructor[not set]{60.000000} + } + ) + } + } + } + } + })")); +} + +TEST_F(SpvBinaryArithTestBasic, FMod_Vector) { + const auto assembly = Preamble() + R"( + %100 = OpFunction %void None %voidfn + %entry = OpLabel + %1 = OpFMod %v2float %v2float_50_60 %v2float_60_50 + OpReturn + OpFunctionEnd + )"; + auto p = parser(test::Assemble(assembly)); + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) + << p->error() << "\n" + << assembly; + auto fe = p->function_emitter(100); + EXPECT_TRUE(fe.EmitBody()) << p->error(); + EXPECT_THAT(ToString(p->builder(), fe.ast_body()), HasSubstr(R"( + VariableConst{ + x_1 + none + undefined + __vec_2__f32 + { + Binary[not set]{ + TypeConstructor[not set]{ + __vec_2__f32 + ScalarConstructor[not set]{50.000000} + ScalarConstructor[not set]{60.000000} + } + subtract + Binary[not set]{ + TypeConstructor[not set]{ + __vec_2__f32 + ScalarConstructor[not set]{60.000000} + ScalarConstructor[not set]{50.000000} + } + multiply + Call[not set]{ + Identifier[not set]{floor} + ( + Binary[not set]{ + TypeConstructor[not set]{ + __vec_2__f32 + ScalarConstructor[not set]{50.000000} + ScalarConstructor[not set]{60.000000} + } + divide + TypeConstructor[not set]{ + __vec_2__f32 + ScalarConstructor[not set]{60.000000} + ScalarConstructor[not set]{50.000000} + } + } + ) + } + } + } + } + })")); +} + TEST_F(SpvBinaryArithTestBasic, VectorTimesScalar) { const auto assembly = Preamble() + R"( %100 = OpFunction %void None %voidfn diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index 16b0a217d7..39292bd58f 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -225,7 +225,21 @@ bool GeneratorImpl::EmitAssign(ast::AssignmentStatement* stmt) { } bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { - out << "("; + if (expr->op() == ast::BinaryOp::kModulo && + TypeOf(expr)->UnwrapRef()->is_float_scalar_or_vector()) { + out << "fmod"; + ScopedParen sp(out); + if (!EmitExpression(out, expr->lhs())) { + return false; + } + out << ", "; + if (!EmitExpression(out, expr->rhs())) { + return false; + } + return true; + } + + ScopedParen sp(out); if (!EmitExpression(out, expr->lhs())) { return false; @@ -303,7 +317,6 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, ast::BinaryExpression* expr) { return false; } - out << ")"; return true; } diff --git a/src/writer/msl/generator_impl_binary_test.cc b/src/writer/msl/generator_impl_binary_test.cc index 939a4821a4..e228516af8 100644 --- a/src/writer/msl/generator_impl_binary_test.cc +++ b/src/writer/msl/generator_impl_binary_test.cc @@ -42,7 +42,7 @@ TEST_P(MslBinaryTest, Emit) { auto* right = Var("right", type()); auto* expr = - create(params.op, Expr("left"), Expr("right")); + create(params.op, Expr(left), Expr(right)); WrapInFunction(left, right, expr); GeneratorImpl& gen = Build(); @@ -74,6 +74,34 @@ INSTANTIATE_TEST_SUITE_P( BinaryData{"(left / right)", ast::BinaryOp::kDivide}, BinaryData{"(left % right)", ast::BinaryOp::kModulo})); +TEST_F(MslBinaryTest, ModF32) { + auto* left = Var("left", ty.f32()); + auto* right = Var("right", ty.f32()); + auto* expr = create(ast::BinaryOp::kModulo, Expr(left), + Expr(right)); + WrapInFunction(left, right, expr); + + GeneratorImpl& gen = Build(); + + std::stringstream out; + ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error(); + EXPECT_EQ(out.str(), "fmod(left, right)"); +} + +TEST_F(MslBinaryTest, ModVec3F32) { + auto* left = Var("left", ty.vec3()); + auto* right = Var("right", ty.vec3()); + auto* expr = create(ast::BinaryOp::kModulo, Expr(left), + Expr(right)); + WrapInFunction(left, right, expr); + + GeneratorImpl& gen = Build(); + + std::stringstream out; + ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.error(); + EXPECT_EQ(out.str(), "fmod(left, right)"); +} + } // namespace } // namespace msl } // namespace writer diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index b666345cd5..d9bf3633c5 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2097,7 +2097,7 @@ uint32_t Builder::GenerateBinaryExpression(ast::BinaryExpression* expr) { } } else if (expr->IsModulo()) { if (lhs_is_float_or_vec) { - op = spv::Op::OpFMod; + op = spv::Op::OpFRem; } else if (lhs_is_unsigned) { op = spv::Op::OpUMod; } else { diff --git a/src/writer/spirv/builder_binary_expression_test.cc b/src/writer/spirv/builder_binary_expression_test.cc index ac4100f9ce..e384387175 100644 --- a/src/writer/spirv/builder_binary_expression_test.cc +++ b/src/writer/spirv/builder_binary_expression_test.cc @@ -246,7 +246,7 @@ INSTANTIATE_TEST_SUITE_P( BinaryArithFloatTest, testing::Values(BinaryData{ast::BinaryOp::kAdd, "OpFAdd"}, BinaryData{ast::BinaryOp::kDivide, "OpFDiv"}, - BinaryData{ast::BinaryOp::kModulo, "OpFMod"}, + BinaryData{ast::BinaryOp::kModulo, "OpFRem"}, BinaryData{ast::BinaryOp::kMultiply, "OpFMul"}, BinaryData{ast::BinaryOp::kSubtract, "OpFSub"})); diff --git a/test/bug/tint/948.wgsl.expected.msl b/test/bug/tint/948.wgsl.expected.msl index 55d9052d98..e7d07da4f9 100644 --- a/test/bug/tint/948.wgsl.expected.msl +++ b/test/bug/tint/948.wgsl.expected.msl @@ -1,11 +1,222 @@ -SKIP: FAILED +#include +using namespace metal; +struct LeftOver { + /* 0x0000 */ float time; + /* 0x0004 */ uint padding; + /* 0x0008 */ int8_t tint_pad[8]; + /* 0x0010 */ float4x4 worldViewProjection; + /* 0x0050 */ packed_float2 outputSize; + /* 0x0058 */ packed_float2 stageSize; + /* 0x0060 */ packed_float2 spriteMapSize; + /* 0x0068 */ float stageScale; + /* 0x006c */ float spriteCount; + /* 0x0070 */ packed_float3 colorMul; + /* 0x007c */ int8_t tint_pad_1[4]; +}; +struct main_out { + float4 glFragColor_1; +}; +struct tint_symbol_2 { + float3 vPosition_param [[user(locn0)]]; + float2 vUV_param [[user(locn1)]]; + float2 tUV_param [[user(locn2)]]; + float2 stageUnits_1_param [[user(locn3)]]; + float2 levelUnits_param [[user(locn4)]]; + float2 tileID_1_param [[user(locn5)]]; +}; +struct tint_symbol_3 { + float4 glFragColor_1 [[color(0)]]; +}; +float4x4 getFrameData_f1_(constant LeftOver& x_20, thread float* const frameID, texture2d tint_symbol_6, sampler tint_symbol_7) { + float fX = 0.0f; + float const x_15 = *(frameID); + float const x_25 = x_20.spriteCount; + fX = (x_15 / x_25); + float const x_37 = fX; + float4 const x_40 = tint_symbol_6.sample(tint_symbol_7, float2(x_37, 0.0f), bias(0.0f)); + float const x_44 = fX; + float4 const x_47 = tint_symbol_6.sample(tint_symbol_7, float2(x_44, 0.25f), bias(0.0f)); + float const x_51 = fX; + float4 const x_54 = tint_symbol_6.sample(tint_symbol_7, float2(x_51, 0.5f), bias(0.0f)); + return float4x4(float4(x_40.x, x_40.y, x_40.z, x_40.w), float4(x_47.x, x_47.y, x_47.z, x_47.w), float4(x_54.x, x_54.y, x_54.z, x_54.w), float4(float4(0.0f, 0.0f, 0.0f, 0.0f).x, float4(0.0f, 0.0f, 0.0f, 0.0f).y, float4(0.0f, 0.0f, 0.0f, 0.0f).z, float4(0.0f, 0.0f, 0.0f, 0.0f).w)); +} -Validation Failure: +void main_1(constant LeftOver& x_20, thread float2* const tint_symbol_8, texture2d tint_symbol_9, sampler tint_symbol_10, texture2d tint_symbol_11, texture2d tint_symbol_12, sampler tint_symbol_13, thread float* const tint_symbol_14, texture2d tint_symbol_15, sampler tint_symbol_16, texture2d tint_symbol_17, sampler tint_symbol_18, thread float4* const tint_symbol_19) { + float4 color = 0.0f; + float2 tileUV = 0.0f; + float2 tileID = 0.0f; + float2 sheetUnits = 0.0f; + float spriteUnits = 0.0f; + float2 stageUnits = 0.0f; + int i = 0; + float frameID_1 = 0.0f; + float4 animationData = 0.0f; + float f = 0.0f; + float4x4 frameData = float4x4(0.0f); + float param = 0.0f; + float2 frameSize = 0.0f; + float2 offset_1 = 0.0f; + float2 ratio = 0.0f; + float4 nc = 0.0f; + float alpha = 0.0f; + float3 mixed = 0.0f; + color = float4(0.0f, 0.0f, 0.0f, 0.0f); + float2 const x_86 = *(tint_symbol_8); + tileUV = fract(x_86); + float const x_91 = tileUV.y; + tileUV.y = (1.0f - x_91); + float2 const x_95 = *(tint_symbol_8); + tileID = floor(x_95); + float2 const x_101 = x_20.spriteMapSize; + sheetUnits = (float2(1.0f, 1.0f) / x_101); + float const x_106 = x_20.spriteCount; + spriteUnits = (1.0f / x_106); + float2 const x_111 = x_20.stageSize; + stageUnits = (float2(1.0f, 1.0f) / x_111); + i = 0; + while (true) { + int const x_122 = i; + if ((x_122 < 2)) { + } else { + break; + } + int const x_126 = i; + switch(x_126) { + case 1: { + float2 const x_150 = tileID; + float2 const x_154 = x_20.stageSize; + float4 const x_156 = tint_symbol_9.sample(tint_symbol_10, ((x_150 + float2(0.5f, 0.5f)) / x_154), bias(0.0f)); + frameID_1 = x_156.x; + break; + } + case 0: { + float2 const x_136 = tileID; + float2 const x_140 = x_20.stageSize; + float4 const x_142 = tint_symbol_11.sample(tint_symbol_10, ((x_136 + float2(0.5f, 0.5f)) / x_140), bias(0.0f)); + frameID_1 = x_142.x; + break; + } + default: { + break; + } + } + float const x_166 = frameID_1; + float const x_169 = x_20.spriteCount; + float4 const x_172 = tint_symbol_12.sample(tint_symbol_13, float2(((x_166 + 0.5f) / x_169), 0.0f), bias(0.0f)); + animationData = x_172; + float const x_174 = animationData.y; + if ((x_174 > 0.0f)) { + float const x_181 = x_20.time; + float const x_184 = animationData.z; + *(tint_symbol_14) = fmod((x_181 * x_184), 1.0f); + f = 0.0f; + while (true) { + float const x_193 = f; + if ((x_193 < 8.0f)) { + } else { + break; + } + float const x_197 = animationData.y; + float const x_198 = *(tint_symbol_14); + if ((x_197 > x_198)) { + float const x_203 = animationData.x; + frameID_1 = x_203; + break; + } + float const x_208 = frameID_1; + float const x_211 = x_20.spriteCount; + float const x_214 = f; + float4 const x_217 = tint_symbol_12.sample(tint_symbol_13, float2(((x_208 + 0.5f) / x_211), (0.125f * x_214)), bias(0.0f)); + animationData = x_217; + { + float const x_218 = f; + f = (x_218 + 1.0f); + } + } + } + float const x_222 = frameID_1; + param = (x_222 + 0.5f); + float4x4 const x_225 = getFrameData_f1_(x_20, &(param), tint_symbol_15, tint_symbol_16); + frameData = x_225; + float4 const x_228 = frameData[0]; + float2 const x_231 = x_20.spriteMapSize; + frameSize = (float2(x_228.w, x_228.z) / x_231); + float4 const x_235 = frameData[0]; + float2 const x_237 = sheetUnits; + offset_1 = (float2(x_235.x, x_235.y) * x_237); + float4 const x_241 = frameData[2]; + float4 const x_244 = frameData[0]; + ratio = (float2(x_241.x, x_241.y) / float2(x_244.w, x_244.z)); + float const x_248 = frameData[2].z; + if ((x_248 == 1.0f)) { + float2 const x_252 = tileUV; + tileUV = float2(x_252.y, x_252.x); + } + int const x_254 = i; + if ((x_254 == 0)) { + float2 const x_263 = tileUV; + float2 const x_264 = frameSize; + float2 const x_266 = offset_1; + float4 const x_268 = tint_symbol_17.sample(tint_symbol_18, ((x_263 * x_264) + x_266)); + color = x_268; + } else { + float2 const x_274 = tileUV; + float2 const x_275 = frameSize; + float2 const x_277 = offset_1; + float4 const x_279 = tint_symbol_17.sample(tint_symbol_18, ((x_274 * x_275) + x_277)); + nc = x_279; + float const x_283 = color.w; + float const x_285 = nc.w; + alpha = fmin((x_283 + x_285), 1.0f); + float4 const x_290 = color; + float4 const x_292 = nc; + float const x_295 = nc.w; + mixed = mix(float3(x_290.x, x_290.y, x_290.z), float3(x_292.x, x_292.y, x_292.z), float3(x_295, x_295, x_295)); + float3 const x_298 = mixed; + float const x_299 = alpha; + color = float4(x_298.x, x_298.y, x_298.z, x_299); + } + { + int const x_304 = i; + i = (x_304 + 1); + } + } + float3 const x_310 = x_20.colorMul; + float4 const x_311 = color; + float3 const x_313 = (float3(x_311.x, x_311.y, x_311.z) * x_310); + float4 const x_314 = color; + color = float4(x_313.x, x_313.y, x_313.z, x_314.w); + float4 const x_318 = color; + *(tint_symbol_19) = x_318; + return; +} -Compilation failed: +fragment tint_symbol_3 tint_symbol(texture2d tint_symbol_26 [[texture(6)]], sampler tint_symbol_27 [[sampler(4)]], texture2d tint_symbol_28 [[texture(5)]], texture2d tint_symbol_29 [[texture(8)]], sampler tint_symbol_30 [[sampler(7)]], texture2d tint_symbol_32 [[texture(3)]], sampler tint_symbol_33 [[sampler(2)]], texture2d tint_symbol_34 [[texture(1)]], sampler tint_symbol_35 [[sampler(0)]], tint_symbol_2 tint_symbol_1 [[stage_in]], constant LeftOver& x_20 [[buffer(9)]]) { + thread float2 tint_symbol_20 = 0.0f; + thread float2 tint_symbol_21 = 0.0f; + thread float2 tint_symbol_22 = 0.0f; + thread float2 tint_symbol_23 = 0.0f; + thread float3 tint_symbol_24 = 0.0f; + thread float2 tint_symbol_25 = 0.0f; + thread float tint_symbol_31 = 0.0f; + thread float4 tint_symbol_36 = 0.0f; + float2 const tUV_param = tint_symbol_1.tUV_param; + float2 const tileID_1_param = tint_symbol_1.tileID_1_param; + float2 const levelUnits_param = tint_symbol_1.levelUnits_param; + float2 const stageUnits_1_param = tint_symbol_1.stageUnits_1_param; + float3 const vPosition_param = tint_symbol_1.vPosition_param; + float2 const vUV_param = tint_symbol_1.vUV_param; + tint_symbol_20 = tUV_param; + tint_symbol_21 = tileID_1_param; + tint_symbol_22 = levelUnits_param; + tint_symbol_23 = stageUnits_1_param; + tint_symbol_24 = vPosition_param; + tint_symbol_25 = vUV_param; + main_1(x_20, &(tint_symbol_20), tint_symbol_26, tint_symbol_27, tint_symbol_28, tint_symbol_29, tint_symbol_30, &(tint_symbol_31), tint_symbol_32, tint_symbol_33, tint_symbol_34, tint_symbol_35, &(tint_symbol_36)); + main_out const tint_symbol_4 = {.glFragColor_1=tint_symbol_36}; + tint_symbol_3 const tint_symbol_5 = {.glFragColor_1=tint_symbol_4.glFragColor_1}; + return tint_symbol_5; +} -program_source:113:44: error: invalid operands to binary expression ('float' and 'float') - *(tint_symbol_14) = ((x_181 * x_184) % 1.0f); - ~~~~~~~~~~~~~~~ ^ ~~~~ diff --git a/test/bug/tint/948.wgsl.expected.spvasm b/test/bug/tint/948.wgsl.expected.spvasm index f4c18cf25c..81d45246d5 100644 --- a/test/bug/tint/948.wgsl.expected.spvasm +++ b/test/bug/tint/948.wgsl.expected.spvasm @@ -361,7 +361,7 @@ %217 = OpAccessChain %_ptr_Function_float %animationData %uint_2 %218 = OpLoad %float %217 %219 = OpFMul %float %215 %218 - %220 = OpFMod %float %219 %float_1 + %220 = OpFRem %float %219 %float_1 OpStore %mt %220 OpStore %f %float_0 OpBranch %221 diff --git a/test/bug/tint/977.spvasm.expected.hlsl b/test/bug/tint/977.spvasm.expected.hlsl index c37348c381..17dc1da169 100644 --- a/test/bug/tint/977.spvasm.expected.hlsl +++ b/test/bug/tint/977.spvasm.expected.hlsl @@ -13,7 +13,7 @@ float binaryOperation_f1_f1_(inout float a, inout float b) { return 1.0f; } const float x_21 = b; - if (!((round((x_21 % 2.0f)) == 1.0f))) { + if (!((round((x_21 - (2.0f * floor((x_21 / 2.0f))))) == 1.0f))) { const float x_29 = a; const float x_31 = b; x_26 = pow(abs(x_29), x_31); diff --git a/test/bug/tint/977.spvasm.expected.msl b/test/bug/tint/977.spvasm.expected.msl index 9662b9384d..ca78d1e134 100644 --- a/test/bug/tint/977.spvasm.expected.msl +++ b/test/bug/tint/977.spvasm.expected.msl @@ -1,5 +1,3 @@ -SKIP: FAILED - #include using namespace metal; @@ -25,7 +23,7 @@ float binaryOperation_f1_f1_(thread float* const a, thread float* const b) { return 1.0f; } float const x_21 = *(b); - if (!((rint((x_21 % 2.0f)) == 1.0f))) { + if (!((rint((x_21 - (2.0f * floor((x_21 / 2.0f))))) == 1.0f))) { float const x_29 = *(a); float const x_31 = *(b); x_26 = pow(fabs(x_29), x_31); @@ -62,10 +60,3 @@ kernel void tint_symbol_1(uint3 gl_GlobalInvocationID_param [[thread_position_in return; } -Compilation failed: - -program_source:26:21: error: invalid operands to binary expression ('const float' and 'float') - if (!((rint((x_21 % 2.0f)) == 1.0f))) { - ~~~~ ^ ~~~~ - - diff --git a/test/bug/tint/977.spvasm.expected.spvasm b/test/bug/tint/977.spvasm.expected.spvasm index 76dd37d7a7..25f6c65152 100644 --- a/test/bug/tint/977.spvasm.expected.spvasm +++ b/test/bug/tint/977.spvasm.expected.spvasm @@ -1,7 +1,7 @@ ; SPIR-V ; Version: 1.3 ; Generator: Google Tint Compiler; 0 -; Bound: 95 +; Bound: 98 ; Schema: 0 OpCapability Shader %43 = OpExtInstImport "GLSL.std.450" @@ -87,9 +87,9 @@ %float_1 = OpConstant %float 1 %float_2 = OpConstant %float 2 %void = OpTypeVoid - %67 = OpTypeFunction %void + %70 = OpTypeFunction %void %_ptr_Function_int = OpTypePointer Function %int - %73 = OpConstantNull %int + %76 = OpConstantNull %int %uint_0 = OpConstant %uint 0 %_ptr_Private_uint = OpTypePointer Private %uint %int_n10 = OpConstant %int -10 @@ -109,56 +109,59 @@ OpReturnValue %float_1 %36 = OpLabel %40 = OpLoad %float %b - %45 = OpFMod %float %40 %float_2 - %42 = OpExtInst %float %43 RoundEven %45 - %46 = OpFOrdEqual %bool %42 %float_1 - %41 = OpLogicalNot %bool %46 - OpSelectionMerge %47 None - OpBranchConditional %41 %48 %49 - %48 = OpLabel - %51 = OpLoad %float %a - %53 = OpLoad %float %b - %55 = OpExtInst %float %43 FAbs %51 - %54 = OpExtInst %float %43 Pow %55 %53 - OpStore %x_26 %54 - OpBranch %47 - %49 = OpLabel - %57 = OpLoad %float %a - %59 = OpLoad %float %a - %61 = OpLoad %float %b - %62 = OpExtInst %float %43 FSign %57 - %64 = OpExtInst %float %43 FAbs %59 - %63 = OpExtInst %float %43 Pow %64 %61 - %65 = OpFMul %float %62 %63 - OpStore %x_26 %65 - OpBranch %47 - %47 = OpLabel - %66 = OpLoad %float %x_26 - OpReturnValue %66 + %46 = OpFDiv %float %40 %float_2 + %45 = OpExtInst %float %43 Floor %46 + %47 = OpFMul %float %float_2 %45 + %48 = OpFSub %float %40 %47 + %42 = OpExtInst %float %43 RoundEven %48 + %49 = OpFOrdEqual %bool %42 %float_1 + %41 = OpLogicalNot %bool %49 + OpSelectionMerge %50 None + OpBranchConditional %41 %51 %52 + %51 = OpLabel + %54 = OpLoad %float %a + %56 = OpLoad %float %b + %58 = OpExtInst %float %43 FAbs %54 + %57 = OpExtInst %float %43 Pow %58 %56 + OpStore %x_26 %57 + OpBranch %50 + %52 = OpLabel + %60 = OpLoad %float %a + %62 = OpLoad %float %a + %64 = OpLoad %float %b + %65 = OpExtInst %float %43 FSign %60 + %67 = OpExtInst %float %43 FAbs %62 + %66 = OpExtInst %float %43 Pow %67 %64 + %68 = OpFMul %float %65 %66 + OpStore %x_26 %68 + OpBranch %50 + %50 = OpLabel + %69 = OpLoad %float %x_26 + OpReturnValue %69 OpFunctionEnd - %main_1 = OpFunction %void None %67 - %70 = OpLabel - %index = OpVariable %_ptr_Function_int Function %73 - %a_1 = OpVariable %_ptr_Function_int Function %73 + %main_1 = OpFunction %void None %70 + %73 = OpLabel + %index = OpVariable %_ptr_Function_int Function %76 + %a_1 = OpVariable %_ptr_Function_int Function %76 %param = OpVariable %_ptr_Function_float Function %30 %param_1 = OpVariable %_ptr_Function_float Function %30 - %79 = OpAccessChain %_ptr_Private_uint %gl_GlobalInvocationID %uint_0 - %80 = OpLoad %uint %79 - %81 = OpBitcast %int %80 - OpStore %index %81 + %82 = OpAccessChain %_ptr_Private_uint %gl_GlobalInvocationID %uint_0 + %83 = OpLoad %uint %82 + %84 = OpBitcast %int %83 + OpStore %index %84 OpStore %a_1 %int_n10 - %83 = OpLoad %int %index + %86 = OpLoad %int %index OpStore %param %float_n4 OpStore %param_1 %float_n3 - %86 = OpFunctionCall %float %binaryOperation_f1_f1_ %param %param_1 - %90 = OpAccessChain %_ptr_StorageBuffer_float %resultMatrix %uint_0 %83 - OpStore %90 %86 + %89 = OpFunctionCall %float %binaryOperation_f1_f1_ %param %param_1 + %93 = OpAccessChain %_ptr_StorageBuffer_float %resultMatrix %uint_0 %86 + OpStore %93 %89 OpReturn OpFunctionEnd - %main = OpFunction %void None %67 - %92 = OpLabel - %93 = OpLoad %v3uint %tint_symbol - OpStore %gl_GlobalInvocationID %93 - %94 = OpFunctionCall %void %main_1 + %main = OpFunction %void None %70 + %95 = OpLabel + %96 = OpLoad %v3uint %tint_symbol + OpStore %gl_GlobalInvocationID %96 + %97 = OpFunctionCall %void %main_1 OpReturn OpFunctionEnd diff --git a/test/bug/tint/977.spvasm.expected.wgsl b/test/bug/tint/977.spvasm.expected.wgsl index b9f67d48c6..98ba008fc7 100644 --- a/test/bug/tint/977.spvasm.expected.wgsl +++ b/test/bug/tint/977.spvasm.expected.wgsl @@ -43,7 +43,7 @@ fn binaryOperation_f1_f1_(a : ptr, b : ptr) -> f32 return 1.0; } let x_21 : f32 = *(b); - if (!((round((x_21 % 2.0)) == 1.0))) { + if (!((round((x_21 - (2.0 * floor((x_21 / 2.0))))) == 1.0))) { let x_29 : f32 = *(a); let x_31 : f32 = *(b); x_26 = pow(abs(x_29), x_31); diff --git a/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.msl b/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.msl index 111652a552..a64e982cb1 100644 --- a/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.msl +++ b/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.msl @@ -1,19 +1,10 @@ -SKIP: FAILED - #include using namespace metal; kernel void f() { float const a = 1.0f; float const b = 2.0f; - float const r = (a % b); + float const r = fmod(a, b); return; } -Compilation failed: - -program_source:7:22: error: invalid operands to binary expression ('const float' and 'const float') - float const r = (a % b); - ~ ^ ~ - - diff --git a/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.spvasm b/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.spvasm index 2be0b7e50a..677ede2677 100644 --- a/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.spvasm +++ b/test/expressions/binary/mod/scalar-scalar/f32.wgsl.expected.spvasm @@ -15,6 +15,6 @@ %float_2 = OpConstant %float 2 %f = OpFunction %void None %1 %4 = OpLabel - %8 = OpFMod %float %float_1 %float_2 + %8 = OpFRem %float %float_1 %float_2 OpReturn OpFunctionEnd diff --git a/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.msl b/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.msl index 53894a9f61..bfb6b5f45b 100644 --- a/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.msl +++ b/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.msl @@ -1,19 +1,10 @@ -SKIP: FAILED - #include using namespace metal; kernel void f() { float3 const a = float3(1.0f, 2.0f, 3.0f); float3 const b = float3(4.0f, 5.0f, 6.0f); - float3 const r = (a % b); + float3 const r = fmod(a, b); return; } -Compilation failed: - -program_source:7:23: error: invalid operands to binary expression ('const float3' (vector of 3 'float' values) and 'const float3') - float3 const r = (a % b); - ~ ^ ~ - - diff --git a/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.spvasm b/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.spvasm index 83be41368c..ee472bc7eb 100644 --- a/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.spvasm +++ b/test/expressions/binary/mod/vec3-vec3/f32.wgsl.expected.spvasm @@ -22,6 +22,6 @@ %14 = OpConstantComposite %v3float %float_4 %float_5 %float_6 %f = OpFunction %void None %1 %4 = OpLabel - %15 = OpFMod %v3float %10 %14 + %15 = OpFRem %v3float %10 %14 OpReturn OpFunctionEnd