dusk: no more dependency to Ast type structures from IR
This commit is contained in:
parent
059411fa97
commit
0a09a4b118
3 changed files with 121 additions and 15 deletions
|
|
@ -650,7 +650,6 @@ pub const InterpolationSample = enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AddressSpace = enum {
|
pub const AddressSpace = enum {
|
||||||
none, // TODO
|
|
||||||
function,
|
function,
|
||||||
private,
|
private,
|
||||||
workgroup,
|
workgroup,
|
||||||
|
|
@ -659,7 +658,6 @@ pub const AddressSpace = enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AccessMode = enum {
|
pub const AccessMode = enum {
|
||||||
none, // TODO
|
|
||||||
read,
|
read,
|
||||||
write,
|
write,
|
||||||
read_write,
|
read_write,
|
||||||
|
|
|
||||||
|
|
@ -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_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) {
|
if (gv.access_mode != Ast.null_index) {
|
||||||
const addr_space_loc = self.tree.tokenLoc(gv.addr_space);
|
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) {
|
if (gv.access_mode != Ast.null_index) {
|
||||||
const access_mode_loc = self.tree.tokenLoc(gv.access_mode);
|
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));
|
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);
|
std.debug.assert(self.tree.nodeTag(node) == .storage_texture_type);
|
||||||
|
|
||||||
const texel_format_loc = self.tree.tokenLoc(self.tree.nodeLHS(node));
|
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_loc = self.tree.tokenLoc(self.tree.nodeRHS(node));
|
||||||
const access_mode_full = std.meta.stringToEnum(Ast.AccessMode, access_mode_loc.slice(self.tree.source)).?;
|
const access_mode_full = std.meta.stringToEnum(Ast.AccessMode, access_mode_loc.slice(self.tree.source)).?;
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ pub const Inst = struct {
|
||||||
/// attributes with an expression argument.
|
/// attributes with an expression argument.
|
||||||
attr_expr: AttrExpr,
|
attr_expr: AttrExpr,
|
||||||
/// @builtin attribute which accepts a BuiltinValue argument.
|
/// @builtin attribute which accepts a BuiltinValue argument.
|
||||||
attr_builtin: Ast.BuiltinValue,
|
attr_builtin: BuiltinValue,
|
||||||
/// @workgroup attribute. accepts at laest 1 argument.
|
/// @workgroup attribute. accepts at laest 1 argument.
|
||||||
attr_workgroup: AttrWorkgroup,
|
attr_workgroup: AttrWorkgroup,
|
||||||
/// @interpolate attribute. accepts 2 arguments.
|
/// @interpolate attribute. accepts 2 arguments.
|
||||||
|
|
@ -230,10 +230,26 @@ pub const Inst = struct {
|
||||||
/// index to null-terminated string in `strings`
|
/// index to null-terminated string in `strings`
|
||||||
name: u32,
|
name: u32,
|
||||||
type: Ref,
|
type: Ref,
|
||||||
addr_space: Ast.AddressSpace = .none,
|
addr_space: AddressSpace,
|
||||||
access_mode: Ast.AccessMode = .none,
|
access_mode: AccessMode,
|
||||||
/// length of attributes
|
/// length of attributes
|
||||||
attrs: u4 = 0,
|
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 {
|
pub const StructDecl = struct {
|
||||||
|
|
@ -250,6 +266,21 @@ pub const Inst = struct {
|
||||||
@"align": u29, // 0 means null
|
@"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 {
|
pub const AttrSimple = enum {
|
||||||
invariant,
|
invariant,
|
||||||
@"const",
|
@"const",
|
||||||
|
|
@ -279,8 +310,20 @@ pub const Inst = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AttrInterpolate = struct {
|
pub const AttrInterpolate = struct {
|
||||||
type: Ast.InterpolationType,
|
type: InterpolationType,
|
||||||
sample: Ast.InterpolationSample,
|
sample: InterpolationSample,
|
||||||
|
|
||||||
|
pub const InterpolationType = enum {
|
||||||
|
perspective,
|
||||||
|
linear,
|
||||||
|
flat,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const InterpolationSample = enum {
|
||||||
|
center,
|
||||||
|
centroid,
|
||||||
|
sample,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const VectorType = struct {
|
pub const VectorType = struct {
|
||||||
|
|
@ -305,8 +348,22 @@ pub const Inst = struct {
|
||||||
|
|
||||||
pub const PointerType = struct {
|
pub const PointerType = struct {
|
||||||
component_type: Ref,
|
component_type: Ref,
|
||||||
addr_space: Ast.AddressSpace,
|
addr_space: AddressSpace,
|
||||||
access_mode: Ast.AccessMode,
|
access_mode: AccessMode,
|
||||||
|
|
||||||
|
pub const AddressSpace = enum {
|
||||||
|
function,
|
||||||
|
private,
|
||||||
|
workgroup,
|
||||||
|
uniform,
|
||||||
|
storage,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const AccessMode = enum {
|
||||||
|
read,
|
||||||
|
write,
|
||||||
|
read_write,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SampledTextureType = struct {
|
pub const SampledTextureType = struct {
|
||||||
|
|
@ -332,7 +389,7 @@ pub const Inst = struct {
|
||||||
|
|
||||||
pub const StorageTextureType = struct {
|
pub const StorageTextureType = struct {
|
||||||
kind: Kind,
|
kind: Kind,
|
||||||
texel_format: Ast.TexelFormat,
|
texel_format: TexelFormat,
|
||||||
access_mode: AccessMode,
|
access_mode: AccessMode,
|
||||||
|
|
||||||
pub const Kind = enum {
|
pub const Kind = enum {
|
||||||
|
|
@ -342,6 +399,26 @@ pub const Inst = struct {
|
||||||
@"3d",
|
@"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 };
|
pub const AccessMode = enum { write };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue