tint: Stub intrinsic @const evaluation

Add support for @const to builtins in intrinsics.def.
Propagate this flag through to the intrinsic table.
Handle builtins that are @const annotated in the resolver.

Currently no intrinsics are decorated with @const, so there's nothing to
test (yet).

Bug: tint:1504
Change-Id: I172483688617782bd7c58b70e3f38d0222a5d1af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92323
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2022-06-01 23:57:20 +00:00
committed by Dawn LUCI CQ
parent e0cd855aa2
commit 451eee0fed
13 changed files with 814 additions and 262 deletions

View File

@@ -105,6 +105,8 @@ type Overload struct {
IsDeprecated bool
// The kind of overload
Kind string
// The function name used to evaluate the overload at shader-creation time
ConstEvalFunction string
}
// Intrinsic is used to create the C++ IntrinsicInfo structure
@@ -206,6 +208,7 @@ func (b *IntrinsicTableBuilder) buildOverload(o *sem.Overload) (Overload, error)
CanBeUsedInStage: o.CanBeUsedInStage,
IsDeprecated: o.IsDeprecated,
Kind: string(o.Decl.Kind),
ConstEvalFunction: o.ConstEvalFunction,
}, nil
}

View File

@@ -326,6 +326,16 @@ func (r *resolver) intrinsic(
Compute: true,
}
}
if constEvalFn := a.Attributes.Take("const"); constEvalFn != nil {
switch len(constEvalFn.Values) {
case 0:
overload.ConstEvalFunction = overload.Decl.Name
case 1:
overload.ConstEvalFunction = constEvalFn.Values[0]
default:
return fmt.Errorf("%v too many values for @const attribute", constEvalFn.Source)
}
}
if deprecated := a.Attributes.Take("deprecated"); deprecated != nil {
overload.IsDeprecated = true
if len(deprecated.Values) != 0 {

View File

@@ -143,15 +143,16 @@ type Intrinsic struct {
// Overload describes a single overload of a builtin or operator
type Overload struct {
Decl ast.IntrinsicDecl
Intrinsic *Intrinsic
TemplateParams []TemplateParam
TemplateTypes []*TemplateTypeParam
TemplateNumbers []TemplateParam
ReturnType *FullyQualifiedName
Parameters []Parameter
CanBeUsedInStage StageUses
IsDeprecated bool // True if this overload is deprecated
Decl ast.IntrinsicDecl
Intrinsic *Intrinsic
TemplateParams []TemplateParam
TemplateTypes []*TemplateTypeParam
TemplateNumbers []TemplateParam
ReturnType *FullyQualifiedName
Parameters []Parameter
CanBeUsedInStage StageUses
IsDeprecated bool // True if this overload is deprecated
ConstEvalFunction string // Name of the function used to evaluate the intrinsic at shader creation time
}
// StageUses describes the stages an overload can be used in