spirv-reader: refactor image access tests

Bug: tint:349
Change-Id: I0cd3dc6d6704f5b636a14542993c39d3f6ea5f59
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34101
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
This commit is contained in:
David Neto 2020-11-27 16:46:33 +00:00 committed by Commit Bot service account
parent 76e5f17313
commit e5aa390e15
1 changed files with 73 additions and 97 deletions

View File

@ -1188,21 +1188,23 @@ INSTANTIATE_TEST_SUITE_P(Images,
// Test emission of variables when we have sampled image accesses in // Test emission of variables when we have sampled image accesses in
// executable code. // executable code.
struct DeclSampledImageCase { struct SampledImageCase {
std::string inst; // The provoking image access instruction. // SPIR-V image type, excluding result ID and opcode
std::string spirv_image_type_details;
std::string spirv_image_access; // The provoking image access instruction.
std::string var_decl; // WGSL variable declaration std::string var_decl; // WGSL variable declaration
std::string texture_builtin; // WGSL texture usage. std::string texture_builtin; // WGSL texture usage.
}; };
inline std::ostream& operator<<(std::ostream& out, inline std::ostream& operator<<(std::ostream& out, const SampledImageCase& c) {
const DeclSampledImageCase& c) { out << "ImageCase(" << c.spirv_image_type_details << "\n"
out << "DeclSampledImageCase(" << c.inst << "\n" << c.spirv_image_access << "\n"
<< c.var_decl << "\n" << c.var_decl << "\n"
<< c.texture_builtin << ")"; << c.texture_builtin << ")";
return out; return out;
} }
using SpvParserTest_DeclHandle_SampledImage = using SpvParserTest_DeclHandle_SampledImage =
SpvParserTestBase<::testing::TestWithParam<DeclSampledImageCase>>; SpvParserTestBase<::testing::TestWithParam<SampledImageCase>>;
TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) { TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) {
const auto assembly = Preamble() + R"( const auto assembly = Preamble() + R"(
@ -1217,13 +1219,17 @@ TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) {
OpDecorate %20 Binding 1 OpDecorate %20 Binding 1
OpDecorate %30 DescriptorSet 0 OpDecorate %30 DescriptorSet 0
OpDecorate %30 Binding 1 OpDecorate %30 Binding 1
)" + CommonTypes() + R"( )" + CommonBasicTypes() +
; Vulkan ignores the "depth" parameter on OpTypeImage. R"(
; So this image type can serve for both regular sampling and depth-compare. %sampler = OpTypeSampler
%si_ty = OpTypeSampledImage %f_texture_2d %ptr_sampler = OpTypePointer UniformConstant %sampler
%im_ty = OpTypeImage )" +
GetParam().spirv_image_type_details + R"(
%ptr_im_ty = OpTypePointer UniformConstant %im_ty
%si_ty = OpTypeSampledImage %im_ty
%10 = OpVariable %ptr_sampler UniformConstant %10 = OpVariable %ptr_sampler UniformConstant
%20 = OpVariable %ptr_f_texture_2d UniformConstant %20 = OpVariable %ptr_im_ty UniformConstant
%30 = OpVariable %ptr_sampler UniformConstant ; comparison sampler, when needed %30 = OpVariable %ptr_sampler UniformConstant ; comparison sampler, when needed
%main = OpFunction %void None %voidfn %main = OpFunction %void None %voidfn
@ -1244,10 +1250,11 @@ TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) {
%offsets2d = OpCopyObject %v2int %value_offset %offsets2d = OpCopyObject %v2int %value_offset
%sam = OpLoad %sampler %10 %sam = OpLoad %sampler %10
%im = OpLoad %f_texture_2d %20 %im = OpLoad %im_ty %20
%sampled_image = OpSampledImage %si_ty %im %sam %sampled_image = OpSampledImage %si_ty %im %sam
)" + GetParam().inst + R"( )" + GetParam().spirv_image_access +
R"(
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
@ -1265,49 +1272,12 @@ TEST_P(SpvParserTest_DeclHandle_SampledImage, Variable) {
// TODO(dneto): Test variable declaration and texture builtins provoked by // TODO(dneto): Test variable declaration and texture builtins provoked by
// use of an image access instruction inside helper function. // use of an image access instruction inside helper function.
TEST_P(SpvParserTest_RegisterHandleUsage_SampledImage, DISABLED_FunctionParam) { TEST_P(SpvParserTest_RegisterHandleUsage_SampledImage, DISABLED_FunctionParam) {
const auto assembly = Preamble() + CommonTypes() + R"(
%f_ty = OpTypeFunction %void %ptr_sampler %ptr_f_texture_2d
%si_ty = OpTypeSampledImage %f_texture_2d
%coords = OpConstantNull %v2float
%component = OpConstant %uint 1
%10 = OpVariable %ptr_sampler UniformConstant
%20 = OpVariable %ptr_f_texture_2d UniformConstant
%func = OpFunction %void None %f_ty
%110 = OpFunctionParameter %ptr_sampler
%120 = OpFunctionParameter %ptr_f_texture_2d
%func_entry = OpLabel
%sam = OpLoad %sampler %110
%im = OpLoad %f_texture_2d %120
%sampled_image = OpSampledImage %si_ty %im %sam
)" + GetParam().inst + R"(
OpReturn
OpFunctionEnd
%main = OpFunction %void None %voidfn
%entry = OpLabel
%foo = OpFunctionCall %void %func %10 %20
OpReturn
OpFunctionEnd
)";
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildInternalModule()) << p->error() << assembly << std::endl;
EXPECT_TRUE(p->RegisterHandleUsage()) << p->error() << assembly << std::endl;
EXPECT_TRUE(p->error().empty()) << p->error() << assembly << std::endl;
Usage su = p->GetHandleUsage(10);
Usage iu = p->GetHandleUsage(20);
EXPECT_THAT(su.to_str(), Eq(GetParam().expected_sampler_usage));
EXPECT_THAT(iu.to_str(), Eq(GetParam().expected_image_usage));
} }
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
DISABLED_ImageGather, DISABLED_ImageGather,
SpvParserTest_DeclHandle_SampledImage, SpvParserTest_DeclHandle_SampledImage,
::testing::ValuesIn(std::vector<DeclSampledImageCase>{ ::testing::ValuesIn(std::vector<SampledImageCase>{
// TODO(dneto): OpImageGather // TODO(dneto): OpImageGather
// TODO(dneto): OpImageGather with ConstOffset (signed and unsigned) // TODO(dneto): OpImageGather with ConstOffset (signed and unsigned)
// TODO(dneto): OpImageGather with Offset (signed and unsigned) // TODO(dneto): OpImageGather with Offset (signed and unsigned)
@ -1317,7 +1287,7 @@ INSTANTIATE_TEST_SUITE_P(
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
DISABLED_ImageDrefGather, DISABLED_ImageDrefGather,
SpvParserTest_DeclHandle_SampledImage, SpvParserTest_DeclHandle_SampledImage,
::testing::ValuesIn(std::vector<DeclSampledImageCase>{ ::testing::ValuesIn(std::vector<SampledImageCase>{
// TODO(dneto): OpImageDrefGather // TODO(dneto): OpImageDrefGather
// TODO(dneto): OpImageDrefGather with ConstOffset (signed and // TODO(dneto): OpImageDrefGather with ConstOffset (signed and
// unsigned) // unsigned)
@ -1331,7 +1301,8 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values( ::testing::Values(
// OpImageSampleImplicitLod // OpImageSampleImplicitLod
DeclSampledImageCase{"%result = OpImageSampleImplicitLod " SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12", "%v4float %sampled_image %coords12",
R"( R"(
DecoratedVariable{ DecoratedVariable{
@ -1363,7 +1334,8 @@ INSTANTIATE_TEST_SUITE_P(
})"}, })"},
// OpImageSampleImplicitLod with ConstOffset // OpImageSampleImplicitLod with ConstOffset
DeclSampledImageCase{ SampledImageCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod " "%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12 ConstOffset %offsets2d", "%v4float %sampled_image %coords12 ConstOffset %offsets2d",
R"( R"(
@ -1397,7 +1369,8 @@ INSTANTIATE_TEST_SUITE_P(
})"}, })"},
// OpImageSampleImplicitLod with Bias // OpImageSampleImplicitLod with Bias
DeclSampledImageCase{"%result = OpImageSampleImplicitLod " SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12 Bias %float_7", "%v4float %sampled_image %coords12 Bias %float_7",
R"( R"(
DecoratedVariable{ DecoratedVariable{
@ -1432,7 +1405,7 @@ INSTANTIATE_TEST_SUITE_P(
// OpImageSampleImplicitLod with Bias and ConstOffset // OpImageSampleImplicitLod with Bias and ConstOffset
// TODO(dneto): OpImageSampleImplicitLod with Bias and unsigned // TODO(dneto): OpImageSampleImplicitLod with Bias and unsigned
// ConstOffset // ConstOffset
DeclSampledImageCase{ SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleImplicitLod " "%result = OpImageSampleImplicitLod "
"%v4float %sampled_image %coords12 Bias|ConstOffset " "%v4float %sampled_image %coords12 Bias|ConstOffset "
"%float_7 %offsets2d", "%float_7 %offsets2d",
@ -1476,7 +1449,7 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values( ::testing::Values(
// OpImageSampleImplicitLod // OpImageSampleImplicitLod
DeclSampledImageCase{R"( SampledImageCase{"%float 2D 0 0 0 1 Unknown", R"(
%sam_dref = OpLoad %sampler %30 %sam_dref = OpLoad %sampler %30
%sampled_dref_image = OpSampledImage %si_ty %im %sam_dref %sampled_dref_image = OpSampledImage %si_ty %im %sam_dref
@ -1553,7 +1526,8 @@ INSTANTIATE_TEST_SUITE_P(
SpvParserTest_DeclHandle_SampledImage, SpvParserTest_DeclHandle_SampledImage,
::testing::Values( ::testing::Values(
// ImageSampleDrefImplicitLod // ImageSampleDrefImplicitLod
DeclSampledImageCase{"%result = OpImageSampleDrefImplicitLod " SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleDrefImplicitLod "
"%v4float %sampled_image %coords12 %depth", "%v4float %sampled_image %coords12 %depth",
R"( R"(
DecoratedVariable{ DecoratedVariable{
@ -1586,7 +1560,8 @@ INSTANTIATE_TEST_SUITE_P(
})"}, })"},
// ImageSampleDrefImplicitLod with ConstOffset // ImageSampleDrefImplicitLod with ConstOffset
DeclSampledImageCase{ SampledImageCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleDrefImplicitLod %v4float " "%result = OpImageSampleDrefImplicitLod %v4float "
"%sampled_image %coords12 %depth ConstOffset %offsets2d", "%sampled_image %coords12 %depth ConstOffset %offsets2d",
R"( R"(
@ -1628,7 +1603,7 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values( ::testing::Values(
// OpImageSampleExplicitLod - using Lod // OpImageSampleExplicitLod - using Lod
DeclSampledImageCase{ SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod " "%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Lod %float_null", "%v4float %sampled_image %coords12 Lod %float_null",
R"( R"(
@ -1664,7 +1639,7 @@ INSTANTIATE_TEST_SUITE_P(
// OpImageSampleExplicitLod - using Lod and ConstOffset // OpImageSampleExplicitLod - using Lod and ConstOffset
// TODO(dneto) OpImageSampleExplicitLod - using Lod and unsigned // TODO(dneto) OpImageSampleExplicitLod - using Lod and unsigned
// ConstOffset // ConstOffset
DeclSampledImageCase{ SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod " "%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Lod|ConstOffset " "%v4float %sampled_image %coords12 Lod|ConstOffset "
"%float_null %offsets2d", "%float_null %offsets2d",
@ -1700,7 +1675,8 @@ INSTANTIATE_TEST_SUITE_P(
})"}, })"},
// OpImageSampleExplicitLod - using Grad // OpImageSampleExplicitLod - using Grad
DeclSampledImageCase{ SampledImageCase{
"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod " "%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Grad %float_7 %float_null", "%v4float %sampled_image %coords12 Grad %float_7 %float_null",
R"( R"(
@ -1737,7 +1713,7 @@ INSTANTIATE_TEST_SUITE_P(
// OpImageSampleExplicitLod - using Grad and ConstOffset // OpImageSampleExplicitLod - using Grad and ConstOffset
// TODO(dneto): OpImageSampleExplicitLod - using Grad and unsigned // TODO(dneto): OpImageSampleExplicitLod - using Grad and unsigned
// ConstOffset // ConstOffset
DeclSampledImageCase{ SampledImageCase{"%float 2D 0 0 0 1 Unknown",
"%result = OpImageSampleExplicitLod " "%result = OpImageSampleExplicitLod "
"%v4float %sampled_image %coords12 Grad|ConstOffset " "%v4float %sampled_image %coords12 Grad|ConstOffset "
"%float_7 %float_null %offsets2d", "%float_7 %float_null %offsets2d",
@ -1774,8 +1750,8 @@ INSTANTIATE_TEST_SUITE_P(
})"})); })"}));
struct ImageCoordsCase { struct ImageCoordsCase {
std::string spirv_image_type_details; // SPIR-V image type, excluding result // SPIR-V image type, excluding result ID and opcode
// ID and opcode std::string spirv_image_type_details;
std::string spirv_image_access; std::string spirv_image_access;
std::string expected_error; std::string expected_error;
std::vector<std::string> expected_expressions; std::vector<std::string> expected_expressions;