[ir][spirv-writer] Emit vector types
Bug: tint:1906 Change-Id: I1caedc1e9fea90c7cd3ffe03eb89002beb5a9fef Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132741 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
90b9ac2b7b
commit
8370ddddc5
|
@ -26,6 +26,7 @@
|
||||||
#include "src/tint/type/i32.h"
|
#include "src/tint/type/i32.h"
|
||||||
#include "src/tint/type/type.h"
|
#include "src/tint/type/type.h"
|
||||||
#include "src/tint/type/u32.h"
|
#include "src/tint/type/u32.h"
|
||||||
|
#include "src/tint/type/vector.h"
|
||||||
#include "src/tint/type/void.h"
|
#include "src/tint/type/void.h"
|
||||||
#include "src/tint/writer/spirv/module.h"
|
#include "src/tint/writer/spirv/module.h"
|
||||||
|
|
||||||
|
@ -119,6 +120,9 @@ uint32_t GeneratorImplIr::Type(const type::Type* ty) {
|
||||||
[&](const type::F16*) {
|
[&](const type::F16*) {
|
||||||
module_.PushType(spv::Op::OpTypeFloat, {id, 16u});
|
module_.PushType(spv::Op::OpTypeFloat, {id, 16u});
|
||||||
},
|
},
|
||||||
|
[&](const type::Vector* vec) {
|
||||||
|
module_.PushType(spv::Op::OpTypeVector, {id, Type(vec->type()), vec->Width()});
|
||||||
|
},
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
TINT_ICE(Writer, diagnostics_) << "unhandled type: " << ty->FriendlyName();
|
TINT_ICE(Writer, diagnostics_) << "unhandled type: " << ty->FriendlyName();
|
||||||
});
|
});
|
||||||
|
|
|
@ -60,7 +60,52 @@ TEST_F(SpvGeneratorImplTest, Type_F16) {
|
||||||
EXPECT_EQ(DumpTypes(), "%1 = OpTypeFloat 16\n");
|
EXPECT_EQ(DumpTypes(), "%1 = OpTypeFloat 16\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that we do can emit multiple types.
|
TEST_F(SpvGeneratorImplTest, Type_Vec2i) {
|
||||||
|
auto* vec = ir.types.Get<type::Vector>(ir.types.Get<type::I32>(), 2u);
|
||||||
|
auto id = generator_.Type(vec);
|
||||||
|
EXPECT_EQ(id, 1u);
|
||||||
|
EXPECT_EQ(DumpTypes(),
|
||||||
|
"%2 = OpTypeInt 32 1\n"
|
||||||
|
"%1 = OpTypeVector %2 2\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvGeneratorImplTest, Type_Vec3u) {
|
||||||
|
auto* vec = ir.types.Get<type::Vector>(ir.types.Get<type::U32>(), 3u);
|
||||||
|
auto id = generator_.Type(vec);
|
||||||
|
EXPECT_EQ(id, 1u);
|
||||||
|
EXPECT_EQ(DumpTypes(),
|
||||||
|
"%2 = OpTypeInt 32 0\n"
|
||||||
|
"%1 = OpTypeVector %2 3\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvGeneratorImplTest, Type_Vec4f) {
|
||||||
|
auto* vec = ir.types.Get<type::Vector>(ir.types.Get<type::F32>(), 4u);
|
||||||
|
auto id = generator_.Type(vec);
|
||||||
|
EXPECT_EQ(id, 1u);
|
||||||
|
EXPECT_EQ(DumpTypes(),
|
||||||
|
"%2 = OpTypeFloat 32\n"
|
||||||
|
"%1 = OpTypeVector %2 4\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvGeneratorImplTest, Type_Vec4h) {
|
||||||
|
auto* vec = ir.types.Get<type::Vector>(ir.types.Get<type::F16>(), 2u);
|
||||||
|
auto id = generator_.Type(vec);
|
||||||
|
EXPECT_EQ(id, 1u);
|
||||||
|
EXPECT_EQ(DumpTypes(),
|
||||||
|
"%2 = OpTypeFloat 16\n"
|
||||||
|
"%1 = OpTypeVector %2 2\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvGeneratorImplTest, Type_Vec4Bool) {
|
||||||
|
auto* vec = ir.types.Get<type::Vector>(ir.types.Get<type::Bool>(), 4u);
|
||||||
|
auto id = generator_.Type(vec);
|
||||||
|
EXPECT_EQ(id, 1u);
|
||||||
|
EXPECT_EQ(DumpTypes(),
|
||||||
|
"%2 = OpTypeBool\n"
|
||||||
|
"%1 = OpTypeVector %2 4\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that we can emit multiple types.
|
||||||
// Includes types with the same opcode but different parameters.
|
// Includes types with the same opcode but different parameters.
|
||||||
TEST_F(SpvGeneratorImplTest, Type_Multiple) {
|
TEST_F(SpvGeneratorImplTest, Type_Multiple) {
|
||||||
EXPECT_EQ(generator_.Type(ir.types.Get<type::I32>()), 1u);
|
EXPECT_EQ(generator_.Type(ir.types.Get<type::I32>()), 1u);
|
||||||
|
|
Loading…
Reference in New Issue