Move sampler to type.
This CL moves the sampler from sem to type and updates the namespace. Bug: tint:1718 Change-Id: I22d228df5d24e154dbebecb43e7c6730475e08d2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113283 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
4595fb7989
commit
5ee58b60a8
|
@ -448,7 +448,6 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"sem/pipeline_stage_set.h",
|
"sem/pipeline_stage_set.h",
|
||||||
"sem/pointer.h",
|
"sem/pointer.h",
|
||||||
"sem/reference.h",
|
"sem/reference.h",
|
||||||
"sem/sampler.h",
|
|
||||||
"sem/sampler_texture_pair.h",
|
"sem/sampler_texture_pair.h",
|
||||||
"sem/struct.h",
|
"sem/struct.h",
|
||||||
"sem/switch_statement.h",
|
"sem/switch_statement.h",
|
||||||
|
@ -576,6 +575,7 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"type/multisampled_texture.h",
|
"type/multisampled_texture.h",
|
||||||
"type/node.h",
|
"type/node.h",
|
||||||
"type/sampled_texture.h",
|
"type/sampled_texture.h",
|
||||||
|
"type/sampler.h",
|
||||||
"type/storage_texture.h",
|
"type/storage_texture.h",
|
||||||
"type/texture.h",
|
"type/texture.h",
|
||||||
"type/type.h",
|
"type/type.h",
|
||||||
|
@ -699,8 +699,6 @@ libtint_source_set("libtint_sem_src") {
|
||||||
"sem/pointer.h",
|
"sem/pointer.h",
|
||||||
"sem/reference.cc",
|
"sem/reference.cc",
|
||||||
"sem/reference.h",
|
"sem/reference.h",
|
||||||
"sem/sampler.cc",
|
|
||||||
"sem/sampler.h",
|
|
||||||
"sem/statement.cc",
|
"sem/statement.cc",
|
||||||
"sem/struct.cc",
|
"sem/struct.cc",
|
||||||
"sem/struct.h",
|
"sem/struct.h",
|
||||||
|
@ -741,6 +739,8 @@ libtint_source_set("libtint_type_src") {
|
||||||
"type/node.h",
|
"type/node.h",
|
||||||
"type/sampled_texture.cc",
|
"type/sampled_texture.cc",
|
||||||
"type/sampled_texture.h",
|
"type/sampled_texture.h",
|
||||||
|
"type/sampler.cc",
|
||||||
|
"type/sampler.h",
|
||||||
"type/storage_texture.cc",
|
"type/storage_texture.cc",
|
||||||
"type/storage_texture.h",
|
"type/storage_texture.h",
|
||||||
"type/texture.cc",
|
"type/texture.cc",
|
||||||
|
@ -1213,7 +1213,6 @@ if (tint_build_unittests) {
|
||||||
"sem/matrix_test.cc",
|
"sem/matrix_test.cc",
|
||||||
"sem/pointer_test.cc",
|
"sem/pointer_test.cc",
|
||||||
"sem/reference_test.cc",
|
"sem/reference_test.cc",
|
||||||
"sem/sampler_test.cc",
|
|
||||||
"sem/struct_test.cc",
|
"sem/struct_test.cc",
|
||||||
"sem/u32_test.cc",
|
"sem/u32_test.cc",
|
||||||
"sem/vector_test.cc",
|
"sem/vector_test.cc",
|
||||||
|
@ -1227,6 +1226,7 @@ if (tint_build_unittests) {
|
||||||
"type/external_texture_test.cc",
|
"type/external_texture_test.cc",
|
||||||
"type/multisampled_texture_test.cc",
|
"type/multisampled_texture_test.cc",
|
||||||
"type/sampled_texture_test.cc",
|
"type/sampled_texture_test.cc",
|
||||||
|
"type/sampler_test.cc",
|
||||||
"type/storage_texture_test.cc",
|
"type/storage_texture_test.cc",
|
||||||
"type/texture_test.cc",
|
"type/texture_test.cc",
|
||||||
"type/type_manager_test.cc",
|
"type/type_manager_test.cc",
|
||||||
|
|
|
@ -355,8 +355,6 @@ list(APPEND TINT_LIB_SRCS
|
||||||
sem/reference.cc
|
sem/reference.cc
|
||||||
sem/reference.h
|
sem/reference.h
|
||||||
sem/sampler_texture_pair.h
|
sem/sampler_texture_pair.h
|
||||||
sem/sampler.cc
|
|
||||||
sem/sampler.h
|
|
||||||
sem/statement.cc
|
sem/statement.cc
|
||||||
sem/struct.cc
|
sem/struct.cc
|
||||||
sem/switch_statement.cc
|
sem/switch_statement.cc
|
||||||
|
@ -497,6 +495,8 @@ list(APPEND TINT_LIB_SRCS
|
||||||
type/node.h
|
type/node.h
|
||||||
type/sampled_texture.cc
|
type/sampled_texture.cc
|
||||||
type/sampled_texture.h
|
type/sampled_texture.h
|
||||||
|
type/sampler.cc
|
||||||
|
type/sampler.h
|
||||||
type/storage_texture.cc
|
type/storage_texture.cc
|
||||||
type/storage_texture.h
|
type/storage_texture.h
|
||||||
type/texture.cc
|
type/texture.cc
|
||||||
|
@ -931,7 +931,6 @@ if(TINT_BUILD_TESTS)
|
||||||
sem/matrix_test.cc
|
sem/matrix_test.cc
|
||||||
sem/pointer_test.cc
|
sem/pointer_test.cc
|
||||||
sem/reference_test.cc
|
sem/reference_test.cc
|
||||||
sem/sampler_test.cc
|
|
||||||
sem/struct_test.cc
|
sem/struct_test.cc
|
||||||
sem/u32_test.cc
|
sem/u32_test.cc
|
||||||
sem/vector_test.cc
|
sem/vector_test.cc
|
||||||
|
@ -947,6 +946,7 @@ if(TINT_BUILD_TESTS)
|
||||||
type/external_texture_test.cc
|
type/external_texture_test.cc
|
||||||
type/multisampled_texture_test.cc
|
type/multisampled_texture_test.cc
|
||||||
type/sampled_texture_test.cc
|
type/sampled_texture_test.cc
|
||||||
|
type/sampler_test.cc
|
||||||
type/storage_texture_test.cc
|
type/storage_texture_test.cc
|
||||||
type/texture_test.cc
|
type/texture_test.cc
|
||||||
type/type_test.cc
|
type/type_test.cc
|
||||||
|
|
|
@ -584,11 +584,11 @@ bool match_sampler(MatchState&, const type::Type* ty) {
|
||||||
if (ty->Is<Any>()) {
|
if (ty->Is<Any>()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return ty->Is([](const sem::Sampler* s) { return s->kind() == ast::SamplerKind::kSampler; });
|
return ty->Is([](const type::Sampler* s) { return s->kind() == ast::SamplerKind::kSampler; });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sem::Sampler* build_sampler(MatchState& state) {
|
const type::Sampler* build_sampler(MatchState& state) {
|
||||||
return state.builder.create<sem::Sampler>(ast::SamplerKind::kSampler);
|
return state.builder.create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match_sampler_comparison(MatchState&, const type::Type* ty) {
|
bool match_sampler_comparison(MatchState&, const type::Type* ty) {
|
||||||
|
@ -596,11 +596,11 @@ bool match_sampler_comparison(MatchState&, const type::Type* ty) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return ty->Is(
|
return ty->Is(
|
||||||
[](const sem::Sampler* s) { return s->kind() == ast::SamplerKind::kComparisonSampler; });
|
[](const type::Sampler* s) { return s->kind() == ast::SamplerKind::kComparisonSampler; });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sem::Sampler* build_sampler_comparison(MatchState& state) {
|
const type::Sampler* build_sampler_comparison(MatchState& state) {
|
||||||
return state.builder.create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
return state.builder.create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match_texture(MatchState&,
|
bool match_texture(MatchState&,
|
||||||
|
|
|
@ -280,7 +280,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) {
|
||||||
auto* vec2_f32 = create<sem::Vector>(f32, 2u);
|
auto* vec2_f32 = create<sem::Vector>(f32, 2u);
|
||||||
auto* vec4_f32 = create<sem::Vector>(f32, 4u);
|
auto* vec4_f32 = create<sem::Vector>(f32, 4u);
|
||||||
auto* tex = create<type::SampledTexture>(ast::TextureDimension::k2d, f32);
|
auto* tex = create<type::SampledTexture>(ast::TextureDimension::k2d, f32);
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
auto result = table->Lookup(BuiltinType::kTextureSample, utils::Vector{tex, sampler, vec2_f32},
|
auto result = table->Lookup(BuiltinType::kTextureSample, utils::Vector{tex, sampler, vec2_f32},
|
||||||
sem::EvaluationStage::kConstant, Source{});
|
sem::EvaluationStage::kConstant, Source{});
|
||||||
ASSERT_NE(result.sem, nullptr) << Diagnostics().str();
|
ASSERT_NE(result.sem, nullptr) << Diagnostics().str();
|
||||||
|
|
|
@ -69,7 +69,6 @@
|
||||||
#include "src/tint/sem/module.h"
|
#include "src/tint/sem/module.h"
|
||||||
#include "src/tint/sem/pointer.h"
|
#include "src/tint/sem/pointer.h"
|
||||||
#include "src/tint/sem/reference.h"
|
#include "src/tint/sem/reference.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/sem/statement.h"
|
#include "src/tint/sem/statement.h"
|
||||||
#include "src/tint/sem/struct.h"
|
#include "src/tint/sem/struct.h"
|
||||||
#include "src/tint/sem/switch_statement.h"
|
#include "src/tint/sem/switch_statement.h"
|
||||||
|
@ -81,6 +80,7 @@
|
||||||
#include "src/tint/type/depth_texture.h"
|
#include "src/tint/type/depth_texture.h"
|
||||||
#include "src/tint/type/multisampled_texture.h"
|
#include "src/tint/type/multisampled_texture.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/utils/defer.h"
|
#include "src/tint/utils/defer.h"
|
||||||
#include "src/tint/utils/math.h"
|
#include "src/tint/utils/math.h"
|
||||||
|
@ -278,7 +278,7 @@ type::Type* Resolver::Type(const ast::Type* ty) {
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
},
|
},
|
||||||
[&](const ast::Sampler* t) { return builder_->create<sem::Sampler>(t->kind); },
|
[&](const ast::Sampler* t) { return builder_->create<type::Sampler>(t->kind); },
|
||||||
[&](const ast::SampledTexture* t) -> type::SampledTexture* {
|
[&](const ast::SampledTexture* t) -> type::SampledTexture* {
|
||||||
if (auto* el = Type(t->type)) {
|
if (auto* el = Type(t->type)) {
|
||||||
auto* sem = builder_->create<type::SampledTexture>(t->dim, el);
|
auto* sem = builder_->create<type::SampledTexture>(t->dim, el);
|
||||||
|
|
|
@ -60,7 +60,6 @@
|
||||||
#include "src/tint/sem/member_accessor_expression.h"
|
#include "src/tint/sem/member_accessor_expression.h"
|
||||||
#include "src/tint/sem/pointer.h"
|
#include "src/tint/sem/pointer.h"
|
||||||
#include "src/tint/sem/reference.h"
|
#include "src/tint/sem/reference.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/sem/statement.h"
|
#include "src/tint/sem/statement.h"
|
||||||
#include "src/tint/sem/struct.h"
|
#include "src/tint/sem/struct.h"
|
||||||
#include "src/tint/sem/switch_statement.h"
|
#include "src/tint/sem/switch_statement.h"
|
||||||
|
@ -72,6 +71,7 @@
|
||||||
#include "src/tint/type/depth_texture.h"
|
#include "src/tint/type/depth_texture.h"
|
||||||
#include "src/tint/type/multisampled_texture.h"
|
#include "src/tint/type/multisampled_texture.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/utils/defer.h"
|
#include "src/tint/utils/defer.h"
|
||||||
#include "src/tint/utils/map.h"
|
#include "src/tint/utils/map.h"
|
||||||
|
@ -231,7 +231,7 @@ bool Validator::IsHostShareable(const type::Type* type) const {
|
||||||
|
|
||||||
// https://gpuweb.github.io/gpuweb/wgsl.html#storable-types
|
// https://gpuweb.github.io/gpuweb/wgsl.html#storable-types
|
||||||
bool Validator::IsStorable(const type::Type* type) const {
|
bool Validator::IsStorable(const type::Type* type) const {
|
||||||
return IsPlain(type) || type->IsAnyOf<type::Texture, sem::Sampler>();
|
return IsPlain(type) || type->IsAnyOf<type::Texture, type::Sampler>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ast::Statement* Validator::ClosestContinuing(bool stop_at_loop,
|
const ast::Statement* Validator::ClosestContinuing(bool stop_at_loop,
|
||||||
|
@ -832,7 +832,7 @@ bool Validator::Parameter(const ast::Function* func, const sem::Variable* var) c
|
||||||
AddError("type of function parameter must be constructible", decl->type->source);
|
AddError("type of function parameter must be constructible", decl->type->source);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!var->Type()->IsAnyOf<type::Texture, sem::Sampler, sem::Pointer>()) {
|
} else if (!var->Type()->IsAnyOf<type::Texture, type::Sampler, sem::Pointer>()) {
|
||||||
AddError("type of function parameter cannot be " + sem_.TypeNameOf(var->Type()),
|
AddError("type of function parameter cannot be " + sem_.TypeNameOf(var->Type()),
|
||||||
decl->source);
|
decl->source);
|
||||||
return false;
|
return false;
|
||||||
|
@ -2266,7 +2266,7 @@ bool Validator::Assignment(const ast::Statement* a, const type::Type* rhs_ty) co
|
||||||
// https://www.w3.org/TR/WGSL/#phony-assignment-section
|
// https://www.w3.org/TR/WGSL/#phony-assignment-section
|
||||||
auto* ty = rhs_ty->UnwrapRef();
|
auto* ty = rhs_ty->UnwrapRef();
|
||||||
if (!ty->IsConstructible() &&
|
if (!ty->IsConstructible() &&
|
||||||
!ty->IsAnyOf<sem::Pointer, type::Texture, sem::Sampler, sem::AbstractNumeric>()) {
|
!ty->IsAnyOf<sem::Pointer, type::Texture, type::Sampler, sem::AbstractNumeric>()) {
|
||||||
AddError("cannot assign '" + sem_.TypeNameOf(rhs_ty) +
|
AddError("cannot assign '" + sem_.TypeNameOf(rhs_ty) +
|
||||||
"' to '_'. '_' can only be assigned a constructible, pointer, texture or "
|
"' to '_'. '_' can only be assigned a constructible, pointer, texture or "
|
||||||
"sampler type",
|
"sampler type",
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "src/tint/sem/node.h"
|
#include "src/tint/sem/node.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/sem/variable.h"
|
#include "src/tint/sem/variable.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/utils/hash.h"
|
#include "src/tint/utils/hash.h"
|
||||||
#include "src/tint/utils/vector.h"
|
#include "src/tint/utils/vector.h"
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ Function::VariableBindings Function::TransitivelyReferencedSamplerVariablesImpl(
|
||||||
|
|
||||||
for (auto* global : TransitivelyReferencedGlobals()) {
|
for (auto* global : TransitivelyReferencedGlobals()) {
|
||||||
auto* unwrapped_type = global->Type()->UnwrapRef();
|
auto* unwrapped_type = global->Type()->UnwrapRef();
|
||||||
auto* sampler = unwrapped_type->As<sem::Sampler>();
|
auto* sampler = unwrapped_type->As<type::Sampler>();
|
||||||
if (sampler == nullptr || sampler->kind() != kind) {
|
if (sampler == nullptr || sampler->kind() != kind) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ struct CombineSamplers::State {
|
||||||
for (auto* global : ctx.src->AST().GlobalVariables()) {
|
for (auto* global : ctx.src->AST().GlobalVariables()) {
|
||||||
auto* global_sem = sem.Get(global)->As<sem::GlobalVariable>();
|
auto* global_sem = sem.Get(global)->As<sem::GlobalVariable>();
|
||||||
auto* type = sem.Get(global->type);
|
auto* type = sem.Get(global->type);
|
||||||
if (tint::IsAnyOf<type::Texture, sem::Sampler>(type) &&
|
if (tint::IsAnyOf<type::Texture, type::Sampler>(type) &&
|
||||||
!type->Is<type::StorageTexture>()) {
|
!type->Is<type::StorageTexture>()) {
|
||||||
ctx.Remove(ctx.src->AST().GlobalDeclarations(), global);
|
ctx.Remove(ctx.src->AST().GlobalDeclarations(), global);
|
||||||
} else if (global->HasBindingPoint()) {
|
} else if (global->HasBindingPoint()) {
|
||||||
|
@ -208,7 +208,7 @@ struct CombineSamplers::State {
|
||||||
// Filter out separate textures and samplers from the original
|
// Filter out separate textures and samplers from the original
|
||||||
// function signature.
|
// function signature.
|
||||||
for (auto* param : fn->Parameters()) {
|
for (auto* param : fn->Parameters()) {
|
||||||
if (!param->Type()->IsAnyOf<type::Texture, sem::Sampler>()) {
|
if (!param->Type()->IsAnyOf<type::Texture, type::Sampler>()) {
|
||||||
params.Push(ctx.Clone(param->Declaration()));
|
params.Push(ctx.Clone(param->Declaration()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ struct CombineSamplers::State {
|
||||||
: function_combined_texture_samplers_[call->Stmt()->Function()]
|
: function_combined_texture_samplers_[call->Stmt()->Function()]
|
||||||
[new_pair];
|
[new_pair];
|
||||||
args.Push(ctx.dst->Expr(var->symbol));
|
args.Push(ctx.dst->Expr(var->symbol));
|
||||||
} else if (auto* sampler_type = type->As<sem::Sampler>()) {
|
} else if (auto* sampler_type = type->As<type::Sampler>()) {
|
||||||
ast::SamplerKind kind = sampler_type->kind();
|
ast::SamplerKind kind = sampler_type->kind();
|
||||||
int index = (kind == ast::SamplerKind::kSampler) ? 0 : 1;
|
int index = (kind == ast::SamplerKind::kSampler) ? 0 : 1;
|
||||||
const ast::Variable*& p = placeholder_samplers_[index];
|
const ast::Variable*& p = placeholder_samplers_[index];
|
||||||
|
@ -321,7 +321,7 @@ struct CombineSamplers::State {
|
||||||
for (auto* arg : expr->args) {
|
for (auto* arg : expr->args) {
|
||||||
if (!ctx.src->TypeOf(arg)
|
if (!ctx.src->TypeOf(arg)
|
||||||
->UnwrapRef()
|
->UnwrapRef()
|
||||||
->IsAnyOf<type::Texture, sem::Sampler>()) {
|
->IsAnyOf<type::Texture, type::Sampler>()) {
|
||||||
args.Push(ctx.Clone(arg));
|
args.Push(ctx.Clone(arg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
|
||||||
}
|
}
|
||||||
// Don't hoist textures / samplers as they can't be placed into a let, nor
|
// Don't hoist textures / samplers as they can't be placed into a let, nor
|
||||||
// can they have side effects.
|
// can they have side effects.
|
||||||
if (var_user->Variable()->Type()->IsAnyOf<type::Texture, sem::Sampler>()) {
|
if (var_user->Variable()->Type()->IsAnyOf<type::Texture, type::Sampler>()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
#include "src/tint/sem/block_statement.h"
|
#include "src/tint/sem/block_statement.h"
|
||||||
#include "src/tint/sem/for_loop_statement.h"
|
#include "src/tint/sem/for_loop_statement.h"
|
||||||
#include "src/tint/sem/reference.h"
|
#include "src/tint/sem/reference.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/sem/variable.h"
|
#include "src/tint/sem/variable.h"
|
||||||
#include "src/tint/type/depth_multisampled_texture.h"
|
#include "src/tint/type/depth_multisampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
|
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::Transform);
|
TINT_INSTANTIATE_TYPEINFO(tint::transform::Transform);
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::Data);
|
TINT_INSTANTIATE_TYPEINFO(tint::transform::Data);
|
||||||
|
@ -165,7 +165,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
|
||||||
return ctx.dst->create<ast::StorageTexture>(t->dim(), t->texel_format(),
|
return ctx.dst->create<ast::StorageTexture>(t->dim(), t->texel_format(),
|
||||||
CreateASTTypeFor(ctx, t->type()), t->access());
|
CreateASTTypeFor(ctx, t->type()), t->access());
|
||||||
}
|
}
|
||||||
if (auto* s = ty->As<sem::Sampler>()) {
|
if (auto* s = ty->As<type::Sampler>()) {
|
||||||
return ctx.dst->create<ast::Sampler>(s->kind());
|
return ctx.dst->create<ast::Sampler>(s->kind());
|
||||||
}
|
}
|
||||||
TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics())
|
TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics())
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2020 The Tint Authors.
|
// Copyright 2022 The Tint Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,14 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "src/tint/sem/sampler.h"
|
#include "src/tint/type/sampler.h"
|
||||||
|
|
||||||
#include "src/tint/program_builder.h"
|
#include "src/tint/program_builder.h"
|
||||||
#include "src/tint/utils/hash.h"
|
#include "src/tint/utils/hash.h"
|
||||||
|
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::sem::Sampler);
|
TINT_INSTANTIATE_TYPEINFO(tint::type::Sampler);
|
||||||
|
|
||||||
namespace tint::sem {
|
namespace tint::type {
|
||||||
|
|
||||||
Sampler::Sampler(ast::SamplerKind kind) : Base(type::TypeFlags{}), kind_(kind) {}
|
Sampler::Sampler(ast::SamplerKind kind) : Base(type::TypeFlags{}), kind_(kind) {}
|
||||||
|
|
||||||
|
@ -42,4 +42,4 @@ std::string Sampler::FriendlyName(const SymbolTable&) const {
|
||||||
return kind_ == ast::SamplerKind::kSampler ? "sampler" : "sampler_comparison";
|
return kind_ == ast::SamplerKind::kSampler ? "sampler" : "sampler_comparison";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tint::sem
|
} // namespace tint::type
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2020 The Tint Authors.
|
// Copyright 2022 The Tint Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,15 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_TINT_SEM_SAMPLER_H_
|
#ifndef SRC_TINT_TYPE_SAMPLER_H_
|
||||||
#define SRC_TINT_SEM_SAMPLER_H_
|
#define SRC_TINT_TYPE_SAMPLER_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "src/tint/ast/sampler.h"
|
#include "src/tint/ast/sampler.h"
|
||||||
#include "src/tint/type/type.h"
|
#include "src/tint/type/type.h"
|
||||||
|
|
||||||
namespace tint::sem {
|
namespace tint::type {
|
||||||
|
|
||||||
/// A sampler type.
|
/// A sampler type.
|
||||||
class Sampler final : public Castable<Sampler, type::Type> {
|
class Sampler final : public Castable<Sampler, type::Type> {
|
||||||
|
@ -54,6 +54,6 @@ class Sampler final : public Castable<Sampler, type::Type> {
|
||||||
ast::SamplerKind const kind_;
|
ast::SamplerKind const kind_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::sem
|
} // namespace tint::type
|
||||||
|
|
||||||
#endif // SRC_TINT_SEM_SAMPLER_H_
|
#endif // SRC_TINT_TYPE_SAMPLER_H_
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2020 The Tint Authors.
|
// Copyright 2022 The Tint Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,11 +12,11 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "src/tint/sem/sampler.h"
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/sem/test_helper.h"
|
#include "src/tint/type/test_helper.h"
|
||||||
#include "src/tint/type/texture.h"
|
#include "src/tint/type/texture.h"
|
||||||
|
|
||||||
namespace tint::sem {
|
namespace tint::type {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using SamplerTest = TestHelper;
|
using SamplerTest = TestHelper;
|
||||||
|
@ -52,7 +52,7 @@ TEST_F(SamplerTest, Equals) {
|
||||||
|
|
||||||
EXPECT_TRUE(a->Equals(*b));
|
EXPECT_TRUE(a->Equals(*b));
|
||||||
EXPECT_FALSE(a->Equals(*c));
|
EXPECT_FALSE(a->Equals(*c));
|
||||||
EXPECT_FALSE(a->Equals(Void{}));
|
EXPECT_FALSE(a->Equals(sem::Void{}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SamplerTest, FriendlyNameSampler) {
|
TEST_F(SamplerTest, FriendlyNameSampler) {
|
||||||
|
@ -66,4 +66,4 @@ TEST_F(SamplerTest, FriendlyNameComparisonSampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::sem
|
} // namespace tint::type
|
|
@ -24,10 +24,10 @@
|
||||||
#include "src/tint/sem/matrix.h"
|
#include "src/tint/sem/matrix.h"
|
||||||
#include "src/tint/sem/pointer.h"
|
#include "src/tint/sem/pointer.h"
|
||||||
#include "src/tint/sem/reference.h"
|
#include "src/tint/sem/reference.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/sem/struct.h"
|
#include "src/tint/sem/struct.h"
|
||||||
#include "src/tint/sem/u32.h"
|
#include "src/tint/sem/u32.h"
|
||||||
#include "src/tint/sem/vector.h"
|
#include "src/tint/sem/vector.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/texture.h"
|
#include "src/tint/type/texture.h"
|
||||||
|
|
||||||
TINT_INSTANTIATE_TYPEINFO(tint::type::Type);
|
TINT_INSTANTIATE_TYPEINFO(tint::type::Type);
|
||||||
|
@ -172,7 +172,7 @@ bool Type::is_numeric_scalar_or_vector() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_handle() const {
|
bool Type::is_handle() const {
|
||||||
return IsAnyOf<sem::Sampler, type::Texture>();
|
return IsAnyOf<type::Sampler, type::Texture>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::HoldsAbstract() const {
|
bool Type::HoldsAbstract() const {
|
||||||
|
|
|
@ -2065,7 +2065,7 @@ bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable*
|
||||||
|
|
||||||
auto name = builder_.Symbols().NameFor(var->symbol);
|
auto name = builder_.Symbols().NameFor(var->symbol);
|
||||||
auto* type = sem->Type()->UnwrapRef();
|
auto* type = sem->Type()->UnwrapRef();
|
||||||
if (type->Is<sem::Sampler>()) {
|
if (type->Is<type::Sampler>()) {
|
||||||
// GLSL ignores Sampler variables.
|
// GLSL ignores Sampler variables.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2893,7 +2893,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
<< "Attempting to emit pointer type. These should have been removed "
|
<< "Attempting to emit pointer type. These should have been removed "
|
||||||
"with the InlinePointerLets transform";
|
"with the InlinePointerLets transform";
|
||||||
return false;
|
return false;
|
||||||
} else if (type->Is<sem::Sampler>()) {
|
} else if (type->Is<type::Sampler>()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (auto* str = type->As<sem::Struct>()) {
|
} else if (auto* str = type->As<sem::Struct>()) {
|
||||||
out << StructName(str);
|
out << StructName(str);
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "src/tint/ast/call_statement.h"
|
#include "src/tint/ast/call_statement.h"
|
||||||
#include "src/tint/ast/stage_attribute.h"
|
#include "src/tint/ast/stage_attribute.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/type/depth_texture.h"
|
#include "src/tint/type/depth_texture.h"
|
||||||
#include "src/tint/type/multisampled_texture.h"
|
#include "src/tint/type/multisampled_texture.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/writer/glsl/test_helper.h"
|
#include "src/tint/writer/glsl/test_helper.h"
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GlslGeneratorImplTest_Type, EmitSampler) {
|
TEST_F(GlslGeneratorImplTest_Type, EmitSampler) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) {
|
TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -3064,7 +3064,7 @@ bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable*
|
||||||
if (unwrapped_type->Is<type::StorageTexture>()) {
|
if (unwrapped_type->Is<type::StorageTexture>()) {
|
||||||
register_space = "u";
|
register_space = "u";
|
||||||
}
|
}
|
||||||
} else if (unwrapped_type->Is<sem::Sampler>()) {
|
} else if (unwrapped_type->Is<type::Sampler>()) {
|
||||||
register_space = "s";
|
register_space = "s";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3999,7 +3999,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
"removed with the InlinePointerLets transform";
|
"removed with the InlinePointerLets transform";
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
[&](const sem::Sampler* sampler) {
|
[&](const type::Sampler* sampler) {
|
||||||
out << "Sampler";
|
out << "Sampler";
|
||||||
if (sampler->IsComparison()) {
|
if (sampler->IsComparison()) {
|
||||||
out << "Comparison";
|
out << "Comparison";
|
||||||
|
|
|
@ -15,10 +15,10 @@
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "src/tint/ast/call_statement.h"
|
#include "src/tint/ast/call_statement.h"
|
||||||
#include "src/tint/ast/stage_attribute.h"
|
#include "src/tint/ast/stage_attribute.h"
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/type/depth_texture.h"
|
#include "src/tint/type/depth_texture.h"
|
||||||
#include "src/tint/type/multisampled_texture.h"
|
#include "src/tint/type/multisampled_texture.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/writer/hlsl/test_helper.h"
|
#include "src/tint/writer/hlsl/test_helper.h"
|
||||||
|
|
||||||
|
@ -273,7 +273,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
|
TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
|
TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -2597,7 +2597,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](const sem::Sampler*) {
|
[&](const type::Sampler*) {
|
||||||
out << "sampler";
|
out << "sampler";
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,11 +16,11 @@
|
||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
#include "src/tint/sem/sampler.h"
|
|
||||||
#include "src/tint/type/depth_multisampled_texture.h"
|
#include "src/tint/type/depth_multisampled_texture.h"
|
||||||
#include "src/tint/type/depth_texture.h"
|
#include "src/tint/type/depth_texture.h"
|
||||||
#include "src/tint/type/multisampled_texture.h"
|
#include "src/tint/type/multisampled_texture.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
|
#include "src/tint/type/sampler.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/writer/msl/test_helper.h"
|
#include "src/tint/writer/msl/test_helper.h"
|
||||||
|
|
||||||
|
@ -730,7 +730,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Sampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
|
|
||||||
GeneratorImpl& gen = Build();
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
|
|
@ -797,7 +797,7 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!type->Is<sem::Sampler>()) {
|
if (!type->Is<type::Sampler>()) {
|
||||||
// If we don't have a initializer and we're an Output or Private
|
// If we don't have a initializer and we're an Output or Private
|
||||||
// variable, then WGSL requires that we zero-initialize.
|
// variable, then WGSL requires that we zero-initialize.
|
||||||
// If we're a Workgroup variable, and the
|
// If we're a Workgroup variable, and the
|
||||||
|
@ -3732,16 +3732,16 @@ uint32_t Builder::GenerateTypeIfNeeded(const type::Type* type) {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](const type::Texture* tex) { return GenerateTextureType(tex, result); },
|
[&](const type::Texture* tex) { return GenerateTextureType(tex, result); },
|
||||||
[&](const sem::Sampler* s) {
|
[&](const type::Sampler* s) {
|
||||||
push_type(spv::Op::OpTypeSampler, {result});
|
push_type(spv::Op::OpTypeSampler, {result});
|
||||||
|
|
||||||
// Register both of the sampler type names. In SPIR-V they're the same
|
// Register both of the sampler type names. In SPIR-V they're the same
|
||||||
// sampler type, so we need to match that when we do the dedup check.
|
// sampler type, so we need to match that when we do the dedup check.
|
||||||
if (s->kind() == ast::SamplerKind::kSampler) {
|
if (s->kind() == ast::SamplerKind::kSampler) {
|
||||||
type_to_id_[builder_.create<sem::Sampler>(
|
type_to_id_[builder_.create<type::Sampler>(
|
||||||
ast::SamplerKind::kComparisonSampler)] = id;
|
ast::SamplerKind::kComparisonSampler)] = id;
|
||||||
} else {
|
} else {
|
||||||
type_to_id_[builder_.create<sem::Sampler>(ast::SamplerKind::kSampler)] = id;
|
type_to_id_[builder_.create<type::Sampler>(ast::SamplerKind::kSampler)] = id;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
|
@ -964,7 +964,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint)
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, Sampler) {
|
TEST_F(BuilderTest_Type, Sampler) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -974,7 +974,7 @@ TEST_F(BuilderTest_Type, Sampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, ComparisonSampler) {
|
TEST_F(BuilderTest_Type, ComparisonSampler) {
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
@ -984,8 +984,8 @@ TEST_F(BuilderTest_Type, ComparisonSampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) {
|
TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) {
|
||||||
auto* comp_sampler = create<sem::Sampler>(ast::SamplerKind::kComparisonSampler);
|
auto* comp_sampler = create<type::Sampler>(ast::SamplerKind::kComparisonSampler);
|
||||||
auto* sampler = create<sem::Sampler>(ast::SamplerKind::kSampler);
|
auto* sampler = create<type::Sampler>(ast::SamplerKind::kSampler);
|
||||||
|
|
||||||
spirv::Builder& b = Build();
|
spirv::Builder& b = Build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue