spirv-reader: HLSL-IO: Convert input, output vars to private

Bug: tint:508
Change-Id: I5cd7c1b476112eb489f9e6acc94f7a1cf6e43b6d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48863
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
David Neto 2021-04-29 22:04:55 +00:00 committed by Commit Bot service account
parent 5f7f7c0f9e
commit e08cc15dd9
2 changed files with 58 additions and 0 deletions

View File

@ -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<sem::Pointer>(ast_elem_ty, ast_storage_class);
}

View File

@ -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.