writer/spirv: Fix emission of select()

The argument order between WGSL and SPIR-V is different (condition is first in SPIR-V, last in WGSL)

Fixed: tint:560
Change-Id: I56c659c441292e05f71a24d96dbc9f93f25b71f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53620
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2021-06-07 20:01:54 +00:00
parent d7255e37f6
commit dfcc7b5714
14 changed files with 443 additions and 336 deletions

View File

@@ -2349,9 +2349,22 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call,
case IntrinsicType::kReverseBits:
op = spv::Op::OpBitReverse;
break;
case IntrinsicType::kSelect:
op = spv::Op::OpSelect;
break;
case IntrinsicType::kSelect: {
// Note: Argument order is different in WGSL and SPIR-V
auto cond_id = get_param_as_value_id(2);
auto true_id = get_param_as_value_id(0);
auto false_id = get_param_as_value_id(1);
if (!cond_id || !true_id || !false_id) {
return 0;
}
if (!push_function_inst(
spv::Op::OpSelect,
{Operand::Int(result_type_id), result, Operand::Int(cond_id),
Operand::Int(true_id), Operand::Int(false_id)})) {
return 0;
}
return result_id;
}
default: {
auto set_id = GetGLSLstd450Import();
auto inst_id = intrinsic_to_glsl_method(intrinsic);

View File

@@ -509,9 +509,9 @@ TEST_F(IntrinsicBuilderTest, Call_Select) {
%6 = OpVariable %7 Private %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
R"(%12 = OpLoad %3 %1
R"(%12 = OpLoad %8 %6
%13 = OpLoad %3 %1
%14 = OpLoad %8 %6
%14 = OpLoad %3 %1
%11 = OpSelect %3 %12 %13 %14
)");
}