From ecc2cdfb6192b26807085012459a8f316c534ef0 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 12 Jan 2021 21:18:58 +0000 Subject: [PATCH] writer/spirv: Use OpImageQuerySizeLod for non-MS images Fixes validation error: `Image must have either 'MS'=1 or 'Sampled'=0 or 'Sampled'=2` Bug: tint:140 Bug: tint:437 Change-Id: If6d7e86aeb7767b212debf94bcae9ee2ce8ad209 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37445 Reviewed-by: David Neto Commit-Queue: Ben Clayton --- src/writer/spirv/builder.cc | 10 ++++-- .../spirv/builder_intrinsic_texture_test.cc | 33 ++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index a02d9f99f8..bd6fda7931 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2117,11 +2117,17 @@ bool Builder::GenerateTextureIntrinsic(ast::IdentifierExpression* ident, } spirv_params.emplace_back(gen_param(pidx.texture)); - if (pidx.level != kNotUsed) { + if (texture_type->Is() || + texture_type->Is()) { + op = spv::Op::OpImageQuerySize; + } else if (pidx.level != kNotUsed) { op = spv::Op::OpImageQuerySizeLod; spirv_params.emplace_back(gen_param(pidx.level)); } else { - op = spv::Op::OpImageQuerySize; + ast::SintLiteral i32_0(Source{}, mod_->create(), 0); + op = spv::Op::OpImageQuerySizeLod; + spirv_params.emplace_back( + Operand::Int(GenerateLiteralIfNeeded(nullptr, &i32_0))); } break; } diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc index a8533ecaff..760af94132 100644 --- a/src/writer/spirv/builder_intrinsic_texture_test.cc +++ b/src/writer/spirv/builder_intrinsic_texture_test.cc @@ -51,10 +51,11 @@ expected_texture_overload_spirv expected_texture_overload( %6 = OpTypePointer UniformConstant %7 %5 = OpVariable %6 UniformConstant %9 = OpTypeInt 32 1 +%11 = OpConstant %9 0 )", R"( %10 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %10 +%8 = OpImageQuerySizeLod %9 %10 %11 )", R"( OpCapability Sampled1D @@ -72,10 +73,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %9 = OpTypeInt 32 1 %11 = OpTypeVector %9 2 +%13 = OpConstant %9 0 )", R"( %12 = OpLoad %3 %1 -%10 = OpImageQuerySize %11 %12 +%10 = OpImageQuerySizeLod %11 %12 %13 %8 = OpCompositeExtract %9 %10 0 )", R"( @@ -94,10 +96,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 2 +%12 = OpConstant %10 0 )", R"( %11 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %11 +%8 = OpImageQuerySizeLod %9 %11 %12 )", R"( OpCapability ImageQuery @@ -136,10 +139,11 @@ OpCapability ImageQuery %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 2 %12 = OpTypeVector %10 3 +%14 = OpConstant %10 0 )", R"( %13 = OpLoad %3 %1 -%11 = OpImageQuerySize %12 %13 +%11 = OpImageQuerySizeLod %12 %13 %14 %8 = OpVectorShuffle %9 %11 %11 0 1 )", R"( @@ -180,10 +184,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 3 +%12 = OpConstant %10 0 )", R"( %11 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %11 +%8 = OpImageQuerySizeLod %9 %11 %12 )", R"( OpCapability ImageQuery @@ -221,10 +226,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 3 +%12 = OpConstant %10 0 )", R"( %11 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %11 +%8 = OpImageQuerySizeLod %9 %11 %12 )", R"( OpCapability ImageQuery @@ -263,10 +269,11 @@ OpCapability ImageQuery %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 3 %12 = OpTypeVector %10 4 +%14 = OpConstant %10 0 )", R"( %13 = OpLoad %3 %1 -%11 = OpImageQuerySize %12 %13 +%11 = OpImageQuerySizeLod %12 %13 %14 %8 = OpVectorShuffle %9 %11 %11 0 1 2 )", R"( @@ -351,10 +358,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 2 +%12 = OpConstant %10 0 )", R"( %11 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %11 +%8 = OpImageQuerySizeLod %9 %11 %12 )", R"( OpCapability ImageQuery @@ -393,10 +401,11 @@ OpCapability ImageQuery %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 2 %12 = OpTypeVector %10 3 +%14 = OpConstant %10 0 )", R"( %13 = OpLoad %3 %1 -%11 = OpImageQuerySize %12 %13 +%11 = OpImageQuerySizeLod %12 %13 %14 %8 = OpVectorShuffle %9 %11 %11 0 1 )", R"( @@ -437,10 +446,11 @@ OpCapability ImageQuery %5 = OpVariable %6 UniformConstant %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 3 +%12 = OpConstant %10 0 )", R"( %11 = OpLoad %3 %1 -%8 = OpImageQuerySize %9 %11 +%8 = OpImageQuerySizeLod %9 %11 %12 )", R"( OpCapability ImageQuery @@ -479,10 +489,11 @@ OpCapability ImageQuery %10 = OpTypeInt 32 1 %9 = OpTypeVector %10 3 %12 = OpTypeVector %10 4 +%14 = OpConstant %10 0 )", R"( %13 = OpLoad %3 %1 -%11 = OpImageQuerySize %12 %13 +%11 = OpImageQuerySizeLod %12 %13 %14 %8 = OpVectorShuffle %9 %11 %11 0 1 2 )", R"(