spirv: improve storage efficiency for integer and float types

In practice there are only a few variations of these types allowed, so it
kind-of makes sense to write them all out. Because the types are hashed this
does not actually save all that many bytes in the long run, though. Perhaps
some of these types should be pre-registered?
This commit is contained in:
Robin Voetter
2022-11-26 12:23:07 +01:00
parent 5826a8a064
commit 3eafe3033e
4 changed files with 181 additions and 54 deletions

View File

@@ -250,21 +250,30 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType {
switch (ty.tag()) {
.void => try types.emit(self.gpa, .OpTypeVoid, result_id_operand),
.bool => try types.emit(self.gpa, .OpTypeBool, result_id_operand),
.int => {
const signedness: spec.LiteralInteger = switch (ty.payload(.int).signedness) {
.u8,
.u16,
.u32,
.u64,
.i8,
.i16,
.i32,
.i64,
.int,
=> {
const signedness: spec.LiteralInteger = switch (ty.intSignedness()) {
.unsigned => 0,
.signed => 1,
};
try types.emit(self.gpa, .OpTypeInt, .{
.id_result = result_id,
.width = ty.payload(.int).width,
.width = ty.intFloatBits(),
.signedness = signedness,
});
},
.float => try types.emit(self.gpa, .OpTypeFloat, .{
.f16, .f32, .f64 => try types.emit(self.gpa, .OpTypeFloat, .{
.id_result = result_id,
.width = ty.payload(.float).width,
.width = ty.intFloatBits(),
}),
.vector => try types.emit(self.gpa, .OpTypeVector, .{
.id_result = result_id,