mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-17 04:41:23 +00:00
Add location into sem::Parameter
.
This CL adds a `location` value into the `Parameter` sem object. This will be set if the parameter has an `@location` attribute applied. Bug: tint:1633 Change-Id: I55cb5cbda951f70d071ebe1400865b63af1fb20a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101065 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
766a458f53
commit
72340d00ce
@ -716,9 +716,14 @@ sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* sem = builder_->create<sem::Parameter>(param, index, ty, ast::StorageClass::kNone,
|
std::optional<uint32_t> location;
|
||||||
ast::Access::kUndefined,
|
if (auto* l = ast::GetAttribute<ast::LocationAttribute>(param->attributes)) {
|
||||||
sem::ParameterUsage::kNone, binding_point);
|
location = l->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* sem = builder_->create<sem::Parameter>(
|
||||||
|
param, index, ty, ast::StorageClass::kNone, ast::Access::kUndefined,
|
||||||
|
sem::ParameterUsage::kNone, binding_point, location);
|
||||||
builder_->Sem().Add(param, sem);
|
builder_->Sem().Add(param, sem);
|
||||||
return sem;
|
return sem;
|
||||||
}
|
}
|
||||||
|
@ -773,6 +773,39 @@ TEST_F(ResolverTest, Function_Parameters) {
|
|||||||
EXPECT_TRUE(func_sem->ReturnType()->Is<sem::Void>());
|
EXPECT_TRUE(func_sem->ReturnType()->Is<sem::Void>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverTest, Function_Parameters_Locations) {
|
||||||
|
auto* param_a = Param("a", ty.f32(), utils::Vector{Location(3)});
|
||||||
|
auto* param_b = Param("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kVertexIndex)});
|
||||||
|
auto* param_c = Param("c", ty.u32(), utils::Vector{Location(1)});
|
||||||
|
|
||||||
|
GlobalVar("my_vec", ty.vec4<f32>(), ast::StorageClass::kPrivate);
|
||||||
|
auto* func = Func("my_func",
|
||||||
|
utils::Vector{
|
||||||
|
param_a,
|
||||||
|
param_b,
|
||||||
|
param_c,
|
||||||
|
},
|
||||||
|
ty.vec4<f32>(),
|
||||||
|
utils::Vector{
|
||||||
|
Return("my_vec"),
|
||||||
|
},
|
||||||
|
utils::Vector{
|
||||||
|
Stage(ast::PipelineStage::kVertex),
|
||||||
|
},
|
||||||
|
utils::Vector{
|
||||||
|
Builtin(ast::BuiltinValue::kPosition),
|
||||||
|
});
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
|
||||||
|
auto* func_sem = Sem().Get(func);
|
||||||
|
ASSERT_NE(func_sem, nullptr);
|
||||||
|
EXPECT_EQ(func_sem->Parameters().Length(), 3u);
|
||||||
|
EXPECT_EQ(3u, func_sem->Parameters()[0]->Location());
|
||||||
|
EXPECT_FALSE(func_sem->Parameters()[1]->Location().has_value());
|
||||||
|
EXPECT_EQ(1u, func_sem->Parameters()[2]->Location());
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
|
TEST_F(ResolverTest, Function_RegisterInputOutputVariables) {
|
||||||
auto* s = Structure("S", utils::Vector{Member("m", ty.u32())});
|
auto* s = Structure("S", utils::Vector{Member("m", ty.u32())});
|
||||||
|
|
||||||
|
@ -73,11 +73,13 @@ Parameter::Parameter(const ast::Parameter* declaration,
|
|||||||
ast::StorageClass storage_class,
|
ast::StorageClass storage_class,
|
||||||
ast::Access access,
|
ast::Access access,
|
||||||
const ParameterUsage usage /* = ParameterUsage::kNone */,
|
const ParameterUsage usage /* = ParameterUsage::kNone */,
|
||||||
sem::BindingPoint binding_point /* = {} */)
|
sem::BindingPoint binding_point /* = {} */,
|
||||||
|
std::optional<uint32_t> location /* = std::nullopt */)
|
||||||
: Base(declaration, type, EvaluationStage::kRuntime, storage_class, access, nullptr),
|
: Base(declaration, type, EvaluationStage::kRuntime, storage_class, access, nullptr),
|
||||||
index_(index),
|
index_(index),
|
||||||
usage_(usage),
|
usage_(usage),
|
||||||
binding_point_(binding_point) {}
|
binding_point_(binding_point),
|
||||||
|
location_(location) {}
|
||||||
|
|
||||||
Parameter::~Parameter() = default;
|
Parameter::~Parameter() = default;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#ifndef SRC_TINT_SEM_VARIABLE_H_
|
#ifndef SRC_TINT_SEM_VARIABLE_H_
|
||||||
#define SRC_TINT_SEM_VARIABLE_H_
|
#define SRC_TINT_SEM_VARIABLE_H_
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -189,13 +190,15 @@ class Parameter final : public Castable<Parameter, Variable> {
|
|||||||
/// @param access the variable access control type
|
/// @param access the variable access control type
|
||||||
/// @param usage the semantic usage for the parameter
|
/// @param usage the semantic usage for the parameter
|
||||||
/// @param binding_point the optional resource binding point of the parameter
|
/// @param binding_point the optional resource binding point of the parameter
|
||||||
|
/// @param location the location value, if set
|
||||||
Parameter(const ast::Parameter* declaration,
|
Parameter(const ast::Parameter* declaration,
|
||||||
uint32_t index,
|
uint32_t index,
|
||||||
const sem::Type* type,
|
const sem::Type* type,
|
||||||
ast::StorageClass storage_class,
|
ast::StorageClass storage_class,
|
||||||
ast::Access access,
|
ast::Access access,
|
||||||
const ParameterUsage usage = ParameterUsage::kNone,
|
const ParameterUsage usage = ParameterUsage::kNone,
|
||||||
sem::BindingPoint binding_point = {});
|
sem::BindingPoint binding_point = {},
|
||||||
|
std::optional<uint32_t> location = std::nullopt);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Parameter() override;
|
~Parameter() override;
|
||||||
@ -222,12 +225,16 @@ class Parameter final : public Castable<Parameter, Variable> {
|
|||||||
/// @returns the resource binding point for the parameter
|
/// @returns the resource binding point for the parameter
|
||||||
sem::BindingPoint BindingPoint() const { return binding_point_; }
|
sem::BindingPoint BindingPoint() const { return binding_point_; }
|
||||||
|
|
||||||
|
/// @returns the location value for the parameter, if set
|
||||||
|
std::optional<uint32_t> Location() const { return location_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint32_t index_;
|
const uint32_t index_;
|
||||||
const ParameterUsage usage_;
|
const ParameterUsage usage_;
|
||||||
CallTarget const* owner_ = nullptr;
|
CallTarget const* owner_ = nullptr;
|
||||||
const sem::Node* shadows_ = nullptr;
|
const sem::Node* shadows_ = nullptr;
|
||||||
const sem::BindingPoint binding_point_;
|
const sem::BindingPoint binding_point_;
|
||||||
|
const std::optional<uint32_t> location_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// VariableUser holds the semantic information for an identifier expression
|
/// VariableUser holds the semantic information for an identifier expression
|
||||||
|
Loading…
x
Reference in New Issue
Block a user