diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 559136d847..dd0e0fabc1 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1072,6 +1072,16 @@ sem::Type* ParserImpl::ConvertType(uint32_t type_id, ast_storage_class = ast::StorageClass::kStorage; remap_buffer_block_type_.insert(type_id); } + + if (hlsl_style_pipeline_io_) { + // When using HLSL-style pipeline IO, intput and output variables + // are mapped to private variables. + if (ast_storage_class == ast::StorageClass::kInput || + ast_storage_class == ast::StorageClass::kOutput) { + ast_storage_class = ast::StorageClass::kPrivate; + } + } + return builder_.create(ast_elem_ty, ast_storage_class); } diff --git a/src/reader/spirv/parser_impl_module_var_test.cc b/src/reader/spirv/parser_impl_module_var_test.cc index 714d8dc7d5..9279b2b22f 100644 --- a/src/reader/spirv/parser_impl_module_var_test.cc +++ b/src/reader/spirv/parser_impl_module_var_test.cc @@ -3821,6 +3821,54 @@ TEST_F(SpvModuleScopeVarParserTest, RegisterInputOutputVars) { EXPECT_THAT(info_1300[0].outputs, ElementsAre(15)); } +TEST_F(SpvModuleScopeVarParserTest, InputVarsConvertedToPrivate) { + const auto assembly = CommonTypes() + R"( + %ptr_in_uint = OpTypePointer Input %uint + %1 = OpVariable %ptr_in_uint Input + )"; + auto p = parser(test::Assemble(assembly)); + + // TODO(crbug.com/tint/508): Remove this when everything is converted + // to HLSL style pipeline IO. + p->SetHLSLStylePipelineIO(); + + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + EXPECT_TRUE(p->error().empty()); + const auto got = p->program().to_str(); + const std::string expected = + R"(Variable{ + x_1 + private + __u32 + } +)"; + EXPECT_THAT(got, HasSubstr(expected)) << got; +} + +TEST_F(SpvModuleScopeVarParserTest, OutputVarsConvertedToPrivate) { + const auto assembly = CommonTypes() + R"( + %ptr_out_uint = OpTypePointer Output %uint + %1 = OpVariable %ptr_out_uint Output + )"; + auto p = parser(test::Assemble(assembly)); + + // TODO(crbug.com/tint/508): Remove this when everything is converted + // to HLSL style pipeline IO. + p->SetHLSLStylePipelineIO(); + + ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()); + EXPECT_TRUE(p->error().empty()); + const auto got = p->program().to_str(); + const std::string expected = + R"(Variable{ + x_1 + private + __u32 + } +)"; + EXPECT_THAT(got, HasSubstr(expected)) << got; +} + // TODO(dneto): Test passing pointer to SampleMask as function parameter, // both input case and output case.