[wgsl-reader] Parsing texture sampler types
Change-Id: I6a29d81deca40e89cf5b8ca95cf0373af3dd16b7 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28005 Commit-Queue: Tomek Ponitka <tommek@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
f6e5c936b9
commit
4beff41b7d
1
BUILD.gn
1
BUILD.gn
|
@ -926,6 +926,7 @@ source_set("tint_unittests_wgsl_reader_src") {
|
|||
"src/reader/wgsl/parser_impl_test.cc",
|
||||
"src/reader/wgsl/parser_impl_test_helper.cc",
|
||||
"src/reader/wgsl/parser_impl_test_helper.h",
|
||||
"src/reader/wgsl/parser_impl_texture_sampler_types_test.cc",
|
||||
"src/reader/wgsl/parser_impl_type_alias_test.cc",
|
||||
"src/reader/wgsl/parser_impl_type_decl_test.cc",
|
||||
"src/reader/wgsl/parser_impl_unary_expression_test.cc",
|
||||
|
|
|
@ -457,6 +457,7 @@ if(${TINT_BUILD_WGSL_READER})
|
|||
reader/wgsl/parser_impl_test.cc
|
||||
reader/wgsl/parser_impl_test_helper.cc
|
||||
reader/wgsl/parser_impl_test_helper.h
|
||||
reader/wgsl/parser_impl_texture_sampler_types_test.cc
|
||||
reader/wgsl/parser_impl_type_alias_test.cc
|
||||
reader/wgsl/parser_impl_type_decl_test.cc
|
||||
reader/wgsl/parser_impl_unary_expression_test.cc
|
||||
|
|
|
@ -577,6 +577,26 @@ std::unique_ptr<ast::Variable> ParserImpl::variable_decl() {
|
|||
return std::make_unique<ast::Variable>(source, name, sc, type);
|
||||
}
|
||||
|
||||
// texture_sampler_types
|
||||
// : sampler_type
|
||||
// | depth_texture_type
|
||||
// | TODO: sampled_texture_type LESS_THAN type_decl GREATER_THAN
|
||||
// | TODO: multisampled_texture_type LESS_THAN type_decl GREATER_THAN
|
||||
// | TODO: storage_texture_type LESS_THAN image_storage_type GREATER_THAN
|
||||
ast::type::Type* ParserImpl::texture_sampler_types() {
|
||||
auto* type = sampler_type();
|
||||
if (type != nullptr) {
|
||||
return type;
|
||||
}
|
||||
|
||||
type = depth_texture_type();
|
||||
if (type != nullptr) {
|
||||
return type;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// sampler_type
|
||||
// : SAMPLER
|
||||
// | SAMPLER_COMPARISON
|
||||
|
|
|
@ -180,6 +180,9 @@ class ParserImpl {
|
|||
/// Parses a `function_decl` grammar element
|
||||
/// @returns the parsed function, nullptr otherwise
|
||||
std::unique_ptr<ast::Function> function_decl();
|
||||
/// Parses a `texture_sampler_types` grammar element
|
||||
/// @returns the parsed Type or nullptr if none matched.
|
||||
ast::type::Type* texture_sampler_types();
|
||||
/// Parses a `sampler_type` grammar element
|
||||
/// @returns the parsed Type or nullptr if none matched.
|
||||
ast::type::Type* sampler_type();
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/ast/type/sampled_texture_type.h"
|
||||
#include "src/ast/type/sampler_type.h"
|
||||
#include "src/reader/wgsl/parser_impl.h"
|
||||
#include "src/reader/wgsl/parser_impl_test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace reader {
|
||||
namespace wgsl {
|
||||
namespace {
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_Invalid) {
|
||||
auto* p = parser("1234");
|
||||
auto* t = p->texture_sampler_types();
|
||||
EXPECT_EQ(t, nullptr);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) {
|
||||
auto* p = parser("sampler");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->IsSampler());
|
||||
ASSERT_FALSE(t->AsSampler()->IsComparison());
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) {
|
||||
auto* p = parser("texture_depth_2d");
|
||||
auto* t = p->texture_sampler_types();
|
||||
ASSERT_NE(t, nullptr);
|
||||
ASSERT_TRUE(t->IsTexture());
|
||||
ASSERT_TRUE(t->AsTexture()->IsDepth());
|
||||
EXPECT_EQ(t->AsTexture()->dim(), ast::type::TextureDimension::k2d);
|
||||
EXPECT_FALSE(p->has_error());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace wgsl
|
||||
} // namespace reader
|
||||
} // namespace tint
|
Loading…
Reference in New Issue