[spirv-reader] use Function storage class on function vars

Change-Id: I22c76ea8bce7d050411b9dd0e283abe1dae8bc6c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19101
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-04-08 17:18:07 +00:00 committed by dan sinclair
parent d877e8b084
commit 2c60b4c2cc
3 changed files with 25 additions and 28 deletions

View File

@ -144,11 +144,8 @@ bool FunctionEmitter::EmitFunctionVariables() {
if (failed()) { if (failed()) {
return false; return false;
} }
// Use StorageClass::kNone because function variables should not explicitly mention auto var = parser_impl_.MakeVariable(
// their storage class. inst.result_id(), ast::StorageClass::kFunction, var_store_type);
auto var =
parser_impl_.MakeVariable(inst.result_id(),
ast::StorageClass::kNone, var_store_type);
if (inst.NumInOperands() > 1) { if (inst.NumInOperands() > 1) {
// SPIR-V initializers are always constants. // SPIR-V initializers are always constants.
// (OpenCL also allows the ID of an OpVariable, but we don't handle that // (OpenCL also allows the ID of an OpVariable, but we don't handle that

View File

@ -87,21 +87,21 @@ TEST_F(SpvParserTest, EmitFunctionVariables_AnonymousVars) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_1 x_1
none function
__u32 __u32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
x_2 x_2
none function
__u32 __u32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
x_3 x_3
none function
__u32 __u32
} }
} }
@ -125,21 +125,21 @@ TEST_F(SpvParserTest, EmitFunctionVariables_NamedVars) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
none function
__u32 __u32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
b b
none function
__u32 __u32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
c c
none function
__u32 __u32
} }
} }
@ -163,21 +163,21 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MixedTypes) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
none function
__u32 __u32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
b b
none function
__i32 __i32
} }
} }
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
c c
none function
__f32 __f32
} }
} }
@ -204,7 +204,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarInitializers) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
none function
__bool __bool
{ {
ScalarConstructor{true} ScalarConstructor{true}
@ -214,7 +214,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarInitializers) {
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
b b
none function
__bool __bool
{ {
ScalarConstructor{false} ScalarConstructor{false}
@ -224,7 +224,7 @@ VariableDeclStatement{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
c c
none function
__i32 __i32
{ {
ScalarConstructor{-1} ScalarConstructor{-1}
@ -234,7 +234,7 @@ VariableDeclStatement{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
d d
none function
__u32 __u32
{ {
ScalarConstructor{1} ScalarConstructor{1}
@ -244,7 +244,7 @@ VariableDeclStatement{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
e e
none function
__f32 __f32
{ {
ScalarConstructor{1.500000} ScalarConstructor{1.500000}
@ -278,7 +278,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarNullInitializers) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
a a
none function
__bool __bool
{ {
ScalarConstructor{false} ScalarConstructor{false}
@ -288,7 +288,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ScalarNullInitializers) {
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
b b
none function
__i32 __i32
{ {
ScalarConstructor{0} ScalarConstructor{0}
@ -298,7 +298,7 @@ VariableDeclStatement{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
c c
none function
__u32 __u32
{ {
ScalarConstructor{0} ScalarConstructor{0}
@ -308,7 +308,7 @@ VariableDeclStatement{
VariableDeclStatement{ VariableDeclStatement{
Variable{ Variable{
d d
none function
__f32 __f32
{ {
ScalarConstructor{0.000000} ScalarConstructor{0.000000}
@ -337,7 +337,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_VectorInitializer) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
none function
__vec_2__f32 __vec_2__f32
{ {
TypeConstructor{ TypeConstructor{
@ -375,7 +375,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_MatrixInitializer) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
none function
__mat_2_3__f32 __mat_2_3__f32
{ {
TypeConstructor{ TypeConstructor{
@ -421,7 +421,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_ArrayInitializer) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
none function
__array__u32_2 __array__u32_2
{ {
TypeConstructor{ TypeConstructor{
@ -455,7 +455,7 @@ TEST_F(SpvParserTest, EmitFunctionVariables_StructInitializer) {
EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{ EXPECT_THAT(ToString(fe.ast_body()), HasSubstr(R"(VariableDeclStatement{
Variable{ Variable{
x_200 x_200
none function
__struct_S __struct_S
{ {
TypeConstructor{ TypeConstructor{

View File

@ -214,7 +214,7 @@ class ParserImpl : Reader {
/// Creates an AST Variable node for a SPIR-V ID, including any attached /// Creates an AST Variable node for a SPIR-V ID, including any attached
/// decorations. /// decorations.
/// @param id the SPIR-V result ID /// @param id the SPIR-V result ID
/// @param sc the storage class, which can be ast::StorageClass::kNone /// @param sc the storage class, which cannot be ast::StorageClass::kNone
/// @param type the type /// @param type the type
/// @returns a new Variable node, or null in the error case /// @returns a new Variable node, or null in the error case
std::unique_ptr<ast::Variable> MakeVariable(uint32_t id, std::unique_ptr<ast::Variable> MakeVariable(uint32_t id,