tint: spir-v reader: add support for GLSLstd450Determinant

Bug: tint:1061
Change-Id: I18f6d0726c2fac192b8893f35dcbf45bf4a3d752
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100466
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2022-08-29 20:52:00 +00:00
committed by Dawn LUCI CQ
parent c165937955
commit cbe8b36256
9 changed files with 431 additions and 1 deletions

View File

@@ -315,6 +315,8 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
return "cross";
case GLSLstd450Degrees:
return "degrees";
case GLSLstd450Determinant:
return "determinant";
case GLSLstd450Distance:
return "distance";
case GLSLstd450Exp:
@@ -413,7 +415,6 @@ std::string GetGlslStd450FuncName(uint32_t ext_opcode) {
case GLSLstd450Acosh:
case GLSLstd450Atanh:
case GLSLstd450Determinant:
case GLSLstd450MatrixInverse:
case GLSLstd450Modf:
@@ -3960,6 +3961,12 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst
// Some GLSLstd450 builtins have scalar forms not supported by WGSL.
// Emulate them.
switch (ext_opcode) {
case GLSLstd450Determinant: {
auto m = MakeOperand(inst, 2);
TINT_ASSERT(Reader, m.type->Is<Matrix>());
return {ty_.F32(), builder_.Call(Source{}, "determinant", m.expr)};
}
case GLSLstd450Normalize:
// WGSL does not have scalar form of the normalize builtin.
// The answer would be 1 anyway, so return that directly.

View File

@@ -52,6 +52,9 @@ std::string Preamble() {
OpName %v3f2 "v3f2"
OpName %v4f1 "v4f1"
OpName %v4f2 "v4f2"
OpName %m2x2f1 "m2x2f1"
OpName %m3x3f1 "m3x3f1"
OpName %m4x4f1 "m4x4f1"
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
@@ -75,6 +78,9 @@ std::string Preamble() {
%v2float = OpTypeVector %float 2
%v3float = OpTypeVector %float 3
%v4float = OpTypeVector %float 4
%mat2v2float = OpTypeMatrix %v2float 2
%mat3v3float = OpTypeMatrix %v3float 3
%mat4v4float = OpTypeMatrix %v4float 4
%v2uint_10_20 = OpConstantComposite %v2uint %uint_10 %uint_20
%v2uint_20_10 = OpConstantComposite %v2uint %uint_20 %uint_10
@@ -91,6 +97,10 @@ std::string Preamble() {
%v4float_50_50_50_50 = OpConstantComposite %v4float %float_50 %float_50 %float_50 %float_50
%mat2v2float_50_60 = OpConstantComposite %mat2v2float %v2float_50_60 %v2float_50_60
%mat3v3float_50_60_70 = OpConstantComposite %mat2v2float %v3float_50_60_70 %v3float_50_60_70 %v3float_50_60_70
%mat4v4float_50_50_50_50 = OpConstantComposite %mat2v2float %v4float_50_50_50_50 %v4float_50_50_50_50 %v4float_50_50_50_50 %v4float_50_50_50_50
%100 = OpFunction %void None %voidfn
%entry = OpLabel
@@ -123,6 +133,10 @@ std::string Preamble() {
%v4f1 = OpCopyObject %v4float %v4float_50_50_50_50
%v4f2 = OpCopyObject %v4float %v4f1
%m2x2f1 = OpCopyObject %mat2v2float %mat2v2float_50_60
%m3x3f1 = OpCopyObject %mat3v3float %mat3v3float_50_60_70
%m4x4f1 = OpCopyObject %mat4v4float %mat4v4float_50_50_50_50
)";
}
@@ -1122,5 +1136,27 @@ TEST_F(SpvParserTest, GlslStd450_Ldexp_Vector_Floatvec_Uintvec) {
EXPECT_THAT(body, HasSubstr(expected)) << body;
}
using GlslStd450_Determinant = SpvParserTestBase<::testing::TestWithParam<std::string>>;
TEST_P(GlslStd450_Determinant, Test) {
const auto assembly = Preamble() + R"(
%1 = OpExtInst %float %glsl Determinant %)" +
GetParam() + R"(
OpReturn
OpFunctionEnd
)";
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
auto fe = p->function_emitter(100);
EXPECT_TRUE(fe.EmitBody()) << p->error();
auto ast_body = fe.ast_body();
const auto body = test::ToString(p->program(), ast_body);
std::string expected = "let x_1 : f32 = determinant(" + GetParam() + ");";
EXPECT_THAT(body, HasSubstr(expected)) << body;
}
INSTANTIATE_TEST_SUITE_P(Test,
GlslStd450_Determinant,
::testing::Values("m2x2f1", "m3x3f1", "m4x4f1"));
} // namespace
} // namespace tint::reader::spirv