Implement texture_depth_multisampled_2d

Implemented for all readers and writers.

Cleaned up some verbose code in sem::Function and the Inspector in the
process.

Fixed: tint:1032
Change-Id: Ia6f2f59e6d2e511c89160b97be990e8b7c9828d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59664
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-07-26 22:19:48 +00:00
committed by Tint LUCI CQ
parent d12379a405
commit fd35aa8e47
85 changed files with 5024 additions and 2515 deletions

View File

@@ -0,0 +1,54 @@
// Copyright 2021 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 "src/sem/depth_multisampled_texture_type.h"
#include "src/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::sem::DepthMultisampledTexture);
namespace tint {
namespace sem {
namespace {
bool IsValidDepthDimension(ast::TextureDimension dim) {
return dim == ast::TextureDimension::k2d;
}
} // namespace
DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim)
: Base(dim) {
TINT_ASSERT(Semantic, IsValidDepthDimension(dim));
}
DepthMultisampledTexture::DepthMultisampledTexture(DepthMultisampledTexture&&) =
default;
DepthMultisampledTexture::~DepthMultisampledTexture() = default;
std::string DepthMultisampledTexture::type_name() const {
std::ostringstream out;
out << "__depth_multisampled_texture_" << dim();
return out.str();
}
std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
std::ostringstream out;
out << "texture_depth_multisampled_" << dim();
return out.str();
}
} // namespace sem
} // namespace tint

View File

@@ -0,0 +1,48 @@
// Copyright 2021 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.
#ifndef SRC_SEM_DEPTH_MULTISAMPLED_TEXTURE_TYPE_H_
#define SRC_SEM_DEPTH_MULTISAMPLED_TEXTURE_TYPE_H_
#include <string>
#include "src/sem/texture_type.h"
namespace tint {
namespace sem {
/// A multisampled depth texture type.
class DepthMultisampledTexture
: public Castable<DepthMultisampledTexture, Texture> {
public:
/// Constructor
/// @param dim the dimensionality of the texture
explicit DepthMultisampledTexture(ast::TextureDimension dim);
/// Move constructor
DepthMultisampledTexture(DepthMultisampledTexture&&);
~DepthMultisampledTexture() override;
/// @returns the name for this type
std::string type_name() const override;
/// @param symbols the program's symbol table
/// @returns the name for this type that closely resembles how it would be
/// declared in WGSL.
std::string FriendlyName(const SymbolTable& symbols) const override;
};
} // namespace sem
} // namespace tint
#endif // SRC_SEM_DEPTH_MULTISAMPLED_TEXTURE_TYPE_H_

View File

@@ -0,0 +1,46 @@
// Copyright 2021 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 "src/sem/depth_multisampled_texture_type.h"
#include "src/sem/test_helper.h"
#include "src/sem/external_texture_type.h"
#include "src/sem/sampled_texture_type.h"
#include "src/sem/storage_texture_type.h"
namespace tint {
namespace sem {
namespace {
using DepthMultisampledTextureTest = TestHelper;
TEST_F(DepthMultisampledTextureTest, Dim) {
DepthMultisampledTexture d(ast::TextureDimension::k2d);
EXPECT_EQ(d.dim(), ast::TextureDimension::k2d);
}
TEST_F(DepthMultisampledTextureTest, TypeName) {
DepthMultisampledTexture d(ast::TextureDimension::k2d);
EXPECT_EQ(d.type_name(), "__depth_multisampled_texture_2d");
}
TEST_F(DepthMultisampledTextureTest, FriendlyName) {
DepthMultisampledTexture d(ast::TextureDimension::k2d);
EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_multisampled_2d");
}
} // namespace
} // namespace sem
} // namespace tint

View File

@@ -130,53 +130,15 @@ Function::VariableBindings Function::ReferencedMultisampledTextureVariables()
return ReferencedSampledTextureVariablesImpl(true);
}
Function::VariableBindings Function::ReferencedStorageTextureVariables() const {
Function::VariableBindings Function::ReferencedVariablesOfType(
const tint::TypeInfo& type_info) const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type = var->Type()->UnwrapRef();
auto* storage_texture = unwrapped_type->As<sem::StorageTexture>();
if (storage_texture == nullptr) {
continue;
}
if (auto binding_point = var->Declaration()->binding_point()) {
ret.push_back({var, binding_point});
}
}
return ret;
}
Function::VariableBindings Function::ReferencedDepthTextureVariables() const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type = var->Type()->UnwrapRef();
auto* storage_texture = unwrapped_type->As<sem::DepthTexture>();
if (storage_texture == nullptr) {
continue;
}
if (auto binding_point = var->Declaration()->binding_point()) {
ret.push_back({var, binding_point});
}
}
return ret;
}
Function::VariableBindings Function::ReferencedExternalTextureVariables()
const {
VariableBindings ret;
for (auto* var : ReferencedModuleVariables()) {
auto* unwrapped_type = var->Type()->UnwrapRef();
auto* external_texture = unwrapped_type->As<sem::ExternalTexture>();
if (external_texture == nullptr) {
continue;
}
if (auto binding_point = var->Declaration()->binding_point()) {
ret.push_back({var, binding_point});
if (unwrapped_type->TypeInfo().Is(type_info)) {
if (auto binding_point = var->Declaration()->binding_point()) {
ret.push_back({var, binding_point});
}
}
}
return ret;

View File

@@ -144,20 +144,20 @@ class Function : public Castable<Function, CallTarget> {
/// @returns the referenced sampled textures
VariableBindings ReferencedMultisampledTextureVariables() const;
/// Retrieves any referenced storage texture variables. Note, the variables
/// Retrieves any referenced variables of the given type. Note, the variables
/// must be decorated with both binding and group decorations.
/// @returns the referenced storage textures
VariableBindings ReferencedStorageTextureVariables() const;
/// @param type_info the type of the variables to find
/// @returns the referenced variables
VariableBindings ReferencedVariablesOfType(
const tint::TypeInfo& type_info) const;
/// Retrieves any referenced depth texture variables. Note, the variables
/// Retrieves any referenced variables of the given type. Note, the variables
/// must be decorated with both binding and group decorations.
/// @returns the referenced depth textures
VariableBindings ReferencedDepthTextureVariables() const;
/// Retrieves any referenced external texture variables. Note, the variables
/// must be decorated with both binding and group decorations.
/// @returns the referenced external textures
VariableBindings ReferencedExternalTextureVariables() const;
/// @returns the referenced variables
template <typename T>
VariableBindings ReferencedVariablesOfType() const {
return ReferencedVariablesOfType(TypeInfo::Of<T>());
}
/// Checks if the given entry point is an ancestor
/// @param sym the entry point symbol