mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 04:06:01 +00:00
tint: Minor IntrinsicTable cleanup
Fix the namespace - this should have been tint::resolver. Use a single u32 bitset for overload flags instead of multiple fields. Bug: tint:1504 Change-Id: I633b21ce14e20fc9aeeed5221886c1d22e327bdc Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90241 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
500f4eedd3
commit
59e23943f3
@ -33,7 +33,7 @@
|
|||||||
#include "src/tint/utils/math.h"
|
#include "src/tint/utils/math.h"
|
||||||
#include "src/tint/utils/scoped_assignment.h"
|
#include "src/tint/utils/scoped_assignment.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint::resolver {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
@ -289,9 +289,21 @@ using TexelFormat = ast::TexelFormat;
|
|||||||
using Access = ast::Access;
|
using Access = ast::Access;
|
||||||
using StorageClass = ast::StorageClass;
|
using StorageClass = ast::StorageClass;
|
||||||
using ParameterUsage = sem::ParameterUsage;
|
using ParameterUsage = sem::ParameterUsage;
|
||||||
using PipelineStageSet = sem::PipelineStageSet;
|
|
||||||
using PipelineStage = ast::PipelineStage;
|
using PipelineStage = ast::PipelineStage;
|
||||||
|
|
||||||
|
/// Unique flag bits for overloads
|
||||||
|
enum class OverloadFlag {
|
||||||
|
kIsBuiltin, // The overload is a builtin ('fn')
|
||||||
|
kIsOperator, // The overload is an operator ('op')
|
||||||
|
kSupportsVertexPipeline, // The overload can be used in vertex shaders
|
||||||
|
kSupportsFragmentPipeline, // The overload can be used in fragment shaders
|
||||||
|
kSupportsComputePipeline, // The overload can be used in compute shaders
|
||||||
|
kIsDeprecated, // The overload is deprecated
|
||||||
|
};
|
||||||
|
|
||||||
|
// An enum set of OverloadFlag, used by OperatorInfo
|
||||||
|
using OverloadFlags = utils::EnumSet<OverloadFlag>;
|
||||||
|
|
||||||
bool match_bool(const sem::Type* ty) {
|
bool match_bool(const sem::Type* ty) {
|
||||||
return ty->IsAnyOf<Any, sem::Bool>();
|
return ty->IsAnyOf<Any, sem::Bool>();
|
||||||
}
|
}
|
||||||
@ -756,10 +768,8 @@ struct OverloadInfo {
|
|||||||
/// Matchers::number, used to build the return type. If the function has no
|
/// Matchers::number, used to build the return type. If the function has no
|
||||||
/// return type then this is null
|
/// return type then this is null
|
||||||
MatcherIndex const* const return_matcher_indices;
|
MatcherIndex const* const return_matcher_indices;
|
||||||
/// The pipeline stages that this overload can be used in
|
/// The flags for the overload
|
||||||
PipelineStageSet supported_stages;
|
OverloadFlags flags;
|
||||||
/// True if the overload is marked as deprecated
|
|
||||||
bool is_deprecated;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// IntrinsicInfo describes a builtin function or operator overload
|
/// IntrinsicInfo describes a builtin function or operator overload
|
||||||
@ -791,21 +801,18 @@ struct IntrinsicPrototype {
|
|||||||
for (auto& p : i.parameters) {
|
for (auto& p : i.parameters) {
|
||||||
utils::HashCombine(&hash, p.type, p.usage);
|
utils::HashCombine(&hash, p.type, p.usage);
|
||||||
}
|
}
|
||||||
return utils::Hash(hash, i.index, i.return_type, i.supported_stages, i.is_deprecated);
|
return utils::Hash(hash, i.overload, i.return_type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t index = 0; // Index of the intrinsic (builtin or operator)
|
const OverloadInfo* overload = nullptr;
|
||||||
std::vector<Parameter> parameters;
|
|
||||||
sem::Type const* return_type = nullptr;
|
sem::Type const* return_type = nullptr;
|
||||||
PipelineStageSet supported_stages;
|
std::vector<Parameter> parameters;
|
||||||
bool is_deprecated = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Equality operator for IntrinsicPrototype
|
/// Equality operator for IntrinsicPrototype
|
||||||
bool operator==(const IntrinsicPrototype& a, const IntrinsicPrototype& b) {
|
bool operator==(const IntrinsicPrototype& a, const IntrinsicPrototype& b) {
|
||||||
if (a.index != b.index || a.supported_stages != b.supported_stages ||
|
if (a.overload != b.overload || a.return_type != b.return_type ||
|
||||||
a.return_type != b.return_type || a.is_deprecated != b.is_deprecated ||
|
|
||||||
a.parameters.size() != b.parameters.size()) {
|
a.parameters.size() != b.parameters.size()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -845,7 +852,6 @@ class Impl : public IntrinsicTable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const IntrinsicPrototype Match(const char* intrinsic_name,
|
const IntrinsicPrototype Match(const char* intrinsic_name,
|
||||||
uint32_t intrinsic_index,
|
|
||||||
const OverloadInfo& overload,
|
const OverloadInfo& overload,
|
||||||
const std::vector<const sem::Type*>& args,
|
const std::vector<const sem::Type*>& args,
|
||||||
int& match_score);
|
int& match_score);
|
||||||
@ -905,7 +911,7 @@ const sem::Builtin* Impl::Lookup(sem::BuiltinType builtin_type,
|
|||||||
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
||||||
int match_score = 1000;
|
int match_score = 1000;
|
||||||
auto& overload = builtin.overloads[o];
|
auto& overload = builtin.overloads[o];
|
||||||
auto match = Match(intrinsic_name, intrinsic_index, overload, args, match_score);
|
auto match = Match(intrinsic_name, overload, args, match_score);
|
||||||
if (match.return_type) {
|
if (match.return_type) {
|
||||||
// De-duplicate builtins that are identical.
|
// De-duplicate builtins that are identical.
|
||||||
return utils::GetOrCreate(builtins, match, [&] {
|
return utils::GetOrCreate(builtins, match, [&] {
|
||||||
@ -916,9 +922,19 @@ const sem::Builtin* Impl::Lookup(sem::BuiltinType builtin_type,
|
|||||||
nullptr, static_cast<uint32_t>(params.size()), p.type,
|
nullptr, static_cast<uint32_t>(params.size()), p.type,
|
||||||
ast::StorageClass::kNone, ast::Access::kUndefined, p.usage));
|
ast::StorageClass::kNone, ast::Access::kUndefined, p.usage));
|
||||||
}
|
}
|
||||||
return builder.create<sem::Builtin>(builtin_type, match.return_type,
|
sem::PipelineStageSet supported_stages;
|
||||||
std::move(params), match.supported_stages,
|
if (match.overload->flags.Contains(OverloadFlag::kSupportsVertexPipeline)) {
|
||||||
match.is_deprecated);
|
supported_stages.Add(ast::PipelineStage::kVertex);
|
||||||
|
}
|
||||||
|
if (match.overload->flags.Contains(OverloadFlag::kSupportsFragmentPipeline)) {
|
||||||
|
supported_stages.Add(ast::PipelineStage::kFragment);
|
||||||
|
}
|
||||||
|
if (match.overload->flags.Contains(OverloadFlag::kSupportsComputePipeline)) {
|
||||||
|
supported_stages.Add(ast::PipelineStage::kCompute);
|
||||||
|
}
|
||||||
|
return builder.create<sem::Builtin>(
|
||||||
|
builtin_type, match.return_type, std::move(params), supported_stages,
|
||||||
|
match.overload->flags.Contains(OverloadFlag::kIsDeprecated));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (match_score > 0) {
|
if (match_score > 0) {
|
||||||
@ -970,7 +986,7 @@ IntrinsicTable::UnaryOperator Impl::Lookup(ast::UnaryOp op,
|
|||||||
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
||||||
int match_score = 1000;
|
int match_score = 1000;
|
||||||
auto& overload = builtin.overloads[o];
|
auto& overload = builtin.overloads[o];
|
||||||
auto match = Match(intrinsic_name, intrinsic_index, overload, {arg}, match_score);
|
auto match = Match(intrinsic_name, overload, {arg}, match_score);
|
||||||
if (match.return_type) {
|
if (match.return_type) {
|
||||||
return UnaryOperator{match.return_type, match.parameters[0].type};
|
return UnaryOperator{match.return_type, match.parameters[0].type};
|
||||||
}
|
}
|
||||||
@ -1055,7 +1071,7 @@ IntrinsicTable::BinaryOperator Impl::Lookup(ast::BinaryOp op,
|
|||||||
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
for (uint32_t o = 0; o < builtin.num_overloads; o++) {
|
||||||
int match_score = 1000;
|
int match_score = 1000;
|
||||||
auto& overload = builtin.overloads[o];
|
auto& overload = builtin.overloads[o];
|
||||||
auto match = Match(intrinsic_name, intrinsic_index, overload, {lhs, rhs}, match_score);
|
auto match = Match(intrinsic_name, overload, {lhs, rhs}, match_score);
|
||||||
if (match.return_type) {
|
if (match.return_type) {
|
||||||
return BinaryOperator{match.return_type, match.parameters[0].type,
|
return BinaryOperator{match.return_type, match.parameters[0].type,
|
||||||
match.parameters[1].type};
|
match.parameters[1].type};
|
||||||
@ -1088,7 +1104,6 @@ IntrinsicTable::BinaryOperator Impl::Lookup(ast::BinaryOp op,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const IntrinsicPrototype Impl::Match(const char* intrinsic_name,
|
const IntrinsicPrototype Impl::Match(const char* intrinsic_name,
|
||||||
uint32_t intrinsic_index,
|
|
||||||
const OverloadInfo& overload,
|
const OverloadInfo& overload,
|
||||||
const std::vector<const sem::Type*>& args,
|
const std::vector<const sem::Type*>& args,
|
||||||
int& match_score) {
|
int& match_score) {
|
||||||
@ -1177,11 +1192,9 @@ const IntrinsicPrototype Impl::Match(const char* intrinsic_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
IntrinsicPrototype builtin;
|
IntrinsicPrototype builtin;
|
||||||
builtin.index = intrinsic_index;
|
builtin.overload = &overload;
|
||||||
builtin.return_type = return_type;
|
builtin.return_type = return_type;
|
||||||
builtin.parameters = std::move(parameters);
|
builtin.parameters = std::move(parameters);
|
||||||
builtin.supported_stages = overload.supported_stages;
|
|
||||||
builtin.is_deprecated = overload.is_deprecated;
|
|
||||||
return builtin;
|
return builtin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1270,7 +1283,7 @@ std::unique_ptr<IntrinsicTable> IntrinsicTable::Create(ProgramBuilder& builder)
|
|||||||
|
|
||||||
IntrinsicTable::~IntrinsicTable() = default;
|
IntrinsicTable::~IntrinsicTable() = default;
|
||||||
|
|
||||||
/// TypeInfo for the Any type declared in the anonymous namespace above
|
} // namespace tint::resolver
|
||||||
TINT_INSTANTIATE_TYPEINFO(Any);
|
|
||||||
|
|
||||||
} // namespace tint
|
/// TypeInfo for the Any type declared in the anonymous namespace above
|
||||||
|
TINT_INSTANTIATE_TYPEINFO(tint::resolver::Any);
|
||||||
|
@ -26,7 +26,7 @@ namespace tint {
|
|||||||
class ProgramBuilder;
|
class ProgramBuilder;
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
||||||
namespace tint {
|
namespace tint::resolver {
|
||||||
|
|
||||||
/// IntrinsicTable is a lookup table of all the WGSL builtin functions and intrinsic operators
|
/// IntrinsicTable is a lookup table of all the WGSL builtin functions and intrinsic operators
|
||||||
class IntrinsicTable {
|
class IntrinsicTable {
|
||||||
@ -91,6 +91,6 @@ class IntrinsicTable {
|
|||||||
bool is_compound) = 0;
|
bool is_compound) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint
|
} // namespace tint::resolver
|
||||||
|
|
||||||
#endif // SRC_TINT_RESOLVER_INTRINSIC_TABLE_H_
|
#endif // SRC_TINT_RESOLVER_INTRINSIC_TABLE_H_
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -97,11 +97,11 @@ constexpr OverloadInfo kOverloads[] = {
|
|||||||
{{- if $o.ReturnMatcherIndicesOffset }} &kMatcherIndices[{{$o.ReturnMatcherIndicesOffset}}]
|
{{- if $o.ReturnMatcherIndicesOffset }} &kMatcherIndices[{{$o.ReturnMatcherIndicesOffset}}]
|
||||||
{{- else }} nullptr
|
{{- else }} nullptr
|
||||||
{{- end }},
|
{{- end }},
|
||||||
/* supported_stages */ PipelineStageSet(
|
/* flags */ OverloadFlags(OverloadFlag::kIs{{Title $o.Kind}}
|
||||||
{{- range $i, $u := $o.CanBeUsedInStage.List -}}
|
{{- range $i, $u := $o.CanBeUsedInStage.List -}}
|
||||||
{{- if $i -}}, {{end}}PipelineStage::k{{Title $u}}
|
, OverloadFlag::kSupports{{Title $u}}Pipeline
|
||||||
{{- end }}),
|
{{- end }}
|
||||||
/* is_deprecated */ {{$o.IsDeprecated}},
|
{{- if $o.IsDeprecated}}, OverloadFlag::kIsDeprecated{{end }}),
|
||||||
},
|
},
|
||||||
{{- end }}
|
{{- end }}
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "src/tint/sem/sampled_texture.h"
|
#include "src/tint/sem/sampled_texture.h"
|
||||||
#include "src/tint/sem/storage_texture.h"
|
#include "src/tint/sem/storage_texture.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint::resolver {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using ::testing::HasSubstr;
|
using ::testing::HasSubstr;
|
||||||
@ -662,4 +662,4 @@ TEST_F(IntrinsicTableTest, MismatchCompoundOp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint
|
} // namespace tint::resolver
|
||||||
|
@ -102,6 +102,8 @@ type Overload struct {
|
|||||||
CanBeUsedInStage sem.StageUses
|
CanBeUsedInStage sem.StageUses
|
||||||
// True if the overload is marked as deprecated
|
// True if the overload is marked as deprecated
|
||||||
IsDeprecated bool
|
IsDeprecated bool
|
||||||
|
// The kind of overload
|
||||||
|
Kind string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intrinsic is used to create the C++ IntrinsicInfo structure
|
// Intrinsic is used to create the C++ IntrinsicInfo structure
|
||||||
@ -202,6 +204,7 @@ func (b *IntrinsicTableBuilder) buildOverload(o *sem.Overload) (Overload, error)
|
|||||||
ReturnMatcherIndicesOffset: ob.returnTypeMatcherIndicesOffset,
|
ReturnMatcherIndicesOffset: ob.returnTypeMatcherIndicesOffset,
|
||||||
CanBeUsedInStage: o.CanBeUsedInStage,
|
CanBeUsedInStage: o.CanBeUsedInStage,
|
||||||
IsDeprecated: o.IsDeprecated,
|
IsDeprecated: o.IsDeprecated,
|
||||||
|
Kind: string(o.Decl.Kind),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user