From cd9e5f6e913b0f92e23b7a0405990635a78ab687 Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 11 Dec 2020 18:19:33 +0000 Subject: [PATCH] spirv-reader: Support multisampled textures Only ImageFetch is supported. Converts the signedness of the sample operand as needed. Bug: tint:109 Bug: dawn:399 Change-Id: I1d00ff4452af123457bb1841d872afcf2c591c48 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35540 Auto-Submit: David Neto Reviewed-by: Ben Clayton Commit-Queue: David Neto --- src/reader/spirv/function.cc | 13 +++ src/reader/spirv/parser_impl_handle_test.cc | 113 ++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index be68f8eed9..ec024bb9b4 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -3947,10 +3947,23 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { } if (arg_index < num_args && (image_operands_mask & SpvImageOperandsConstOffsetMask)) { + // TODO(dneto): convert to signed integer if needed params.push_back(MakeOperand(inst, arg_index).expr); image_operands_mask ^= SpvImageOperandsConstOffsetMask; arg_index++; } + if (arg_index < num_args && + (image_operands_mask & SpvImageOperandsSampleMask)) { + TypedExpression sample = MakeOperand(inst, arg_index); + if (!sample.type->Is()) { + sample.expr = ast_module_.create( + ast_module_.create(), + ast::ExpressionList{sample.expr}); + } + params.push_back(sample.expr); + image_operands_mask ^= SpvImageOperandsSampleMask; + arg_index++; + } if (image_operands_mask) { return Fail() << "unsupported image operands (" << image_operands_mask << "): " << inst.PrettyPrint(); diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 693d845c7d..7c3fc65828 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -2934,6 +2934,7 @@ INSTANTIATE_TEST_SUITE_P( } })"}, // OpImageFetch with ConstOffset + // TODO(dneto): Seems this is not valid in WGSL. {"%float 2D 0 0 0 1 Unknown", "%99 = OpImageFetch %v4float %im %vu12 ConstOffset %offsets2d", R"(Variable{ @@ -2963,6 +2964,118 @@ INSTANTIATE_TEST_SUITE_P( } })"}})); +INSTANTIATE_TEST_SUITE_P( + ImageFetch_Multisampled, + SpvParserTest_ImageAccessTest, + ::testing::ValuesIn(std::vector{ + // SPIR-V requires a Sample image operand when operating on a + // multisampled image. + + // ImageFetch non-arrayed + {"%float 2D 0 0 1 1 Unknown", + "%99 = OpImageFetch %v4float %im %vi12 Sample %i1", + R"(Variable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __multisampled_texture_2d__f32 + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + Identifier[not set]{vi12} + Identifier[not set]{i1} + ) + } + } + } + })"}, + // ImageFetch arrayed + {"%float 2D 0 1 1 1 Unknown", + "%99 = OpImageFetch %v4float %im %vi123 Sample %i1", + R"(Variable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __multisampled_texture_2d_array__f32 + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + MemberAccessor[not set]{ + Identifier[not set]{vi123} + Identifier[not set]{xy} + } + TypeConstructor[not set]{ + __i32 + MemberAccessor[not set]{ + Identifier[not set]{vi123} + Identifier[not set]{z} + } + } + Identifier[not set]{i1} + ) + } + } + } + })"}})); + +INSTANTIATE_TEST_SUITE_P( + ImageFetch_Multisampled_ConvertSampleOperand, + SpvParserTest_ImageAccessTest, + ::testing::ValuesIn(std::vector{ + {"%float 2D 0 0 1 1 Unknown", + "%99 = OpImageFetch %v4float %im %vi12 Sample %u1", + R"(Variable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __multisampled_texture_2d__f32 + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + Identifier[not set]{vi12} + TypeConstructor[not set]{ + __i32 + Identifier[not set]{u1} + } + ) + } + } + } + })"}})); + INSTANTIATE_TEST_SUITE_P( ConvertResultSignedness, SpvParserTest_SampledImageAccessTest,