[wgsl-writer] Omit the storage class for handle types
These types have an implicit storage class of UniformConstant. Bug: tint:332 Change-Id: I78c5b2a085e543ebba7d5e92b8f11550d0cd4d49 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40400 Auto-Submit: James Price <jrprice@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
parent
0ff5e0bfb8
commit
1f2d38c826
|
@ -493,8 +493,8 @@ Maybe<ParserImpl::VarDeclInfo> ParserImpl::variable_decl() {
|
||||||
if (decl.errored)
|
if (decl.errored)
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
|
||||||
if (decl->type->Is<type::Sampler>() || decl->type->Is<type::Texture>()) {
|
if (decl->type->is_handle()) {
|
||||||
// sampler and texture variables implicitly have the storage class `handle`.
|
// handle types implicitly have the `UniformConstant` storage class.
|
||||||
// TODO(jrprice): Produce an error if an explicit storage class is provided.
|
// TODO(jrprice): Produce an error if an explicit storage class is provided.
|
||||||
sc = ast::StorageClass::kUniformConstant;
|
sc = ast::StorageClass::kUniformConstant;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,5 +127,9 @@ bool Type::is_bool_scalar_or_vector() const {
|
||||||
return Is<Bool>() || is_bool_vector();
|
return Is<Bool>() || is_bool_vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Type::is_handle() const {
|
||||||
|
return Is<type::Sampler>() || Is<type::Texture>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace type
|
} // namespace type
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -99,6 +99,8 @@ class Type : public Castable<Type> {
|
||||||
bool is_bool_vector() const;
|
bool is_bool_vector() const;
|
||||||
/// @returns true if this type is boolean scalar or vector
|
/// @returns true if this type is boolean scalar or vector
|
||||||
bool is_bool_scalar_or_vector() const;
|
bool is_bool_scalar_or_vector() const;
|
||||||
|
/// @returns true if this type is a handle type
|
||||||
|
bool is_handle() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Type();
|
Type();
|
||||||
|
|
|
@ -597,7 +597,8 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
|
||||||
} else {
|
} else {
|
||||||
out_ << "var";
|
out_ << "var";
|
||||||
if (sem->StorageClass() != ast::StorageClass::kNone &&
|
if (sem->StorageClass() != ast::StorageClass::kNone &&
|
||||||
sem->StorageClass() != ast::StorageClass::kFunction) {
|
sem->StorageClass() != ast::StorageClass::kFunction &&
|
||||||
|
!var->type()->is_handle()) {
|
||||||
out_ << "<" << sem->StorageClass() << ">";
|
out_ << "<" << sem->StorageClass() << ">";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "src/ast/variable.h"
|
#include "src/ast/variable.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
#include "src/type/f32_type.h"
|
#include "src/type/f32_type.h"
|
||||||
|
#include "src/type/sampled_texture_type.h"
|
||||||
#include "src/writer/wgsl/generator_impl.h"
|
#include "src/writer/wgsl/generator_impl.h"
|
||||||
#include "src/writer/wgsl/test_helper.h"
|
#include "src/writer/wgsl/test_helper.h"
|
||||||
|
|
||||||
|
@ -76,6 +77,35 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||||
EXPECT_EQ(gen.result(), " var<private> a : f32;\n");
|
EXPECT_EQ(gen.result(), " var<private> a : f32;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Sampler) {
|
||||||
|
auto* var = Global("s", ast::StorageClass::kUniformConstant,
|
||||||
|
create<type::Sampler>(type::SamplerKind::kSampler));
|
||||||
|
|
||||||
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
|
||||||
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
gen.increment_indent();
|
||||||
|
|
||||||
|
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||||
|
EXPECT_EQ(gen.result(), " var s : sampler;\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Texture) {
|
||||||
|
auto* var = Global(
|
||||||
|
"t", ast::StorageClass::kUniformConstant,
|
||||||
|
create<type::SampledTexture>(type::TextureDimension::k1d, ty.f32()));
|
||||||
|
|
||||||
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
|
||||||
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
gen.increment_indent();
|
||||||
|
|
||||||
|
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||||
|
EXPECT_EQ(gen.result(), " var t : texture_1d<f32>;\n");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
|
|
Loading…
Reference in New Issue