diff --git a/libs/dusk/src/Ast.zig b/libs/dusk/src/Ast.zig index 573434cc..d71f8ec6 100644 --- a/libs/dusk/src/Ast.zig +++ b/libs/dusk/src/Ast.zig @@ -650,7 +650,6 @@ pub const InterpolationSample = enum { }; pub const AddressSpace = enum { - none, // TODO function, private, workgroup, @@ -659,7 +658,6 @@ pub const AddressSpace = enum { }; pub const AccessMode = enum { - none, // TODO read, write, read_write, diff --git a/libs/dusk/src/AstGen.zig b/libs/dusk/src/AstGen.zig index d90c2552..5211768b 100644 --- a/libs/dusk/src/AstGen.zig +++ b/libs/dusk/src/AstGen.zig @@ -146,16 +146,28 @@ pub fn genGlobalVariable(self: *AstGen, scope: *Scope, node: Ast.Index) !IR.Inst var_type = try self.genType(scope, gv.type); } - var addr_space: Ast.AddressSpace = .none; + var addr_space: IR.Inst.GlobalVariableDecl.AddressSpace = .none; if (gv.access_mode != Ast.null_index) { const addr_space_loc = self.tree.tokenLoc(gv.addr_space); - addr_space = std.meta.stringToEnum(Ast.AddressSpace, addr_space_loc.slice(self.tree.source)).?; + const ast_addr_space = std.meta.stringToEnum(Ast.AddressSpace, addr_space_loc.slice(self.tree.source)).?; + addr_space = switch (ast_addr_space) { + .function => .function, + .private => .private, + .workgroup => .workgroup, + .uniform => .uniform, + .storage => .storage, + }; } - var access_mode: Ast.AccessMode = .none; + var access_mode: IR.Inst.GlobalVariableDecl.AccessMode = .none; if (gv.access_mode != Ast.null_index) { const access_mode_loc = self.tree.tokenLoc(gv.access_mode); - access_mode = std.meta.stringToEnum(Ast.AccessMode, access_mode_loc.slice(self.tree.source)).?; + const ast_access_mode = std.meta.stringToEnum(Ast.AccessMode, access_mode_loc.slice(self.tree.source)).?; + access_mode = switch (ast_access_mode) { + .read => .read, + .write => .write, + .read_write => .read_write, + }; } const name_index = try self.addString(self.declNameLoc(node).?.slice(self.tree.source)); @@ -579,7 +591,26 @@ pub fn genStorageTextureType(self: *AstGen, node: Ast.Index) !IR.Inst.Ref { std.debug.assert(self.tree.nodeTag(node) == .storage_texture_type); const texel_format_loc = self.tree.tokenLoc(self.tree.nodeLHS(node)); - const texel_format = std.meta.stringToEnum(Ast.TexelFormat, texel_format_loc.slice(self.tree.source)).?; + const ast_texel_format = std.meta.stringToEnum(Ast.TexelFormat, texel_format_loc.slice(self.tree.source)).?; + const texel_format: IR.Inst.StorageTextureType.TexelFormat = switch (ast_texel_format) { + .rgba8unorm => .rgba8unorm, + .rgba8snorm => .rgba8snorm, + .rgba8uint => .rgba8uint, + .rgba8sint => .rgba8sint, + .rgba16uint => .rgba16uint, + .rgba16sint => .rgba16sint, + .rgba16float => .rgba16float, + .r32uint => .r32uint, + .r32sint => .r32sint, + .r32float => .r32float, + .rg32uint => .rg32uint, + .rg32sint => .rg32sint, + .rg32float => .rg32float, + .rgba32uint => .rgba32uint, + .rgba32sint => .rgba32sint, + .rgba32float => .rgba32float, + .bgra8unorm => .bgra8unorm, + }; const access_mode_loc = self.tree.tokenLoc(self.tree.nodeRHS(node)); const access_mode_full = std.meta.stringToEnum(Ast.AccessMode, access_mode_loc.slice(self.tree.source)).?; diff --git a/libs/dusk/src/IR.zig b/libs/dusk/src/IR.zig index b26324db..669b14c2 100644 --- a/libs/dusk/src/IR.zig +++ b/libs/dusk/src/IR.zig @@ -205,7 +205,7 @@ pub const Inst = struct { /// attributes with an expression argument. attr_expr: AttrExpr, /// @builtin attribute which accepts a BuiltinValue argument. - attr_builtin: Ast.BuiltinValue, + attr_builtin: BuiltinValue, /// @workgroup attribute. accepts at laest 1 argument. attr_workgroup: AttrWorkgroup, /// @interpolate attribute. accepts 2 arguments. @@ -230,10 +230,26 @@ pub const Inst = struct { /// index to null-terminated string in `strings` name: u32, type: Ref, - addr_space: Ast.AddressSpace = .none, - access_mode: Ast.AccessMode = .none, + addr_space: AddressSpace, + access_mode: AccessMode, /// length of attributes attrs: u4 = 0, + + pub const AddressSpace = enum { + none, + function, + private, + workgroup, + uniform, + storage, + }; + + pub const AccessMode = enum { + none, + read, + write, + read_write, + }; }; pub const StructDecl = struct { @@ -250,6 +266,21 @@ pub const Inst = struct { @"align": u29, // 0 means null }; + pub const BuiltinValue = enum { + vertex_index, + instance_index, + position, + front_facing, + frag_depth, + local_invocation_id, + local_invocation_index, + global_invocation_id, + workgroup_id, + num_workgroups, + sample_index, + sample_mask, + }; + pub const AttrSimple = enum { invariant, @"const", @@ -279,8 +310,20 @@ pub const Inst = struct { }; pub const AttrInterpolate = struct { - type: Ast.InterpolationType, - sample: Ast.InterpolationSample, + type: InterpolationType, + sample: InterpolationSample, + + pub const InterpolationType = enum { + perspective, + linear, + flat, + }; + + pub const InterpolationSample = enum { + center, + centroid, + sample, + }; }; pub const VectorType = struct { @@ -305,8 +348,22 @@ pub const Inst = struct { pub const PointerType = struct { component_type: Ref, - addr_space: Ast.AddressSpace, - access_mode: Ast.AccessMode, + addr_space: AddressSpace, + access_mode: AccessMode, + + pub const AddressSpace = enum { + function, + private, + workgroup, + uniform, + storage, + }; + + pub const AccessMode = enum { + read, + write, + read_write, + }; }; pub const SampledTextureType = struct { @@ -332,7 +389,7 @@ pub const Inst = struct { pub const StorageTextureType = struct { kind: Kind, - texel_format: Ast.TexelFormat, + texel_format: TexelFormat, access_mode: AccessMode, pub const Kind = enum { @@ -342,6 +399,26 @@ pub const Inst = struct { @"3d", }; + pub const TexelFormat = enum { + rgba8unorm, + rgba8snorm, + rgba8uint, + rgba8sint, + rgba16uint, + rgba16sint, + rgba16float, + r32uint, + r32sint, + r32float, + rg32uint, + rg32sint, + rg32float, + rgba32uint, + rgba32sint, + rgba32float, + bgra8unorm, + }; + pub const AccessMode = enum { write }; };