writer/spirv: Refactor IntrinsicTextureTest.OutsideFunction_IsError

Use the same builder helpers as IntrinsicTextureTest.Call, significantly reducing boilerplate

Change-Id: Idb37a1704b9ed76c3872d14003ff279b2955d18b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37443
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/ast/intrinsic_texture_helper_test.cc b/src/ast/intrinsic_texture_helper_test.cc
index ae705f1..8620aa3 100644
--- a/src/ast/intrinsic_texture_helper_test.cc
+++ b/src/ast/intrinsic_texture_helper_test.cc
@@ -168,10 +168,12 @@
                     b->create<ast::type::MultisampledTexture>(texture_dimension,
                                                               datatype));
 
-    case ast::intrinsic::test::TextureKind::kStorage:
-      return b->Var("texture", ast::StorageClass::kNone,
-                    b->create<ast::type::StorageTexture>(
-                        texture_dimension, access_control, image_format));
+    case ast::intrinsic::test::TextureKind::kStorage: {
+      auto* st = b->create<ast::type::StorageTexture>(
+          texture_dimension, access_control, image_format);
+      st->set_type(datatype);
+      return b->Var("texture", ast::StorageClass::kNone, st);
+    }
   }
 
   assert(false /* unreachable */);
diff --git a/src/writer/spirv/builder_intrinsic_texture_test.cc b/src/writer/spirv/builder_intrinsic_texture_test.cc
index 7e648a4..2e85a32 100644
--- a/src/writer/spirv/builder_intrinsic_texture_test.cc
+++ b/src/writer/spirv/builder_intrinsic_texture_test.cc
@@ -3734,50 +3734,10 @@
   // The point of this test is to try to generate the texture
   // intrinsic call outside a function.
 
-  ast::type::Type* datatype = nullptr;
-  switch (param.texture_data_type) {
-    case ast::intrinsic::test::TextureDataType::kF32:
-      datatype = ty.f32;
-      break;
-    case ast::intrinsic::test::TextureDataType::kU32:
-      datatype = ty.u32;
-      break;
-    case ast::intrinsic::test::TextureDataType::kI32:
-      datatype = ty.i32;
-      break;
-  }
+  auto* texture = param.buildTextureVariable(this);
+  auto* sampler = param.buildSamplerVariable(this);
 
-  ast::type::Sampler sampler_type{param.sampler_kind};
-  ast::Variable* tex = nullptr;
-  switch (param.texture_kind) {
-    case ast::intrinsic::test::TextureKind::kRegular:
-      tex = Var("texture", ast::StorageClass::kNone,
-                mod->create<ast::type::SampledTexture>(param.texture_dimension,
-                                                       datatype));
-      break;
-
-    case ast::intrinsic::test::TextureKind::kDepth:
-      tex = Var("texture", ast::StorageClass::kNone,
-                mod->create<ast::type::DepthTexture>(param.texture_dimension));
-      break;
-
-    case ast::intrinsic::test::TextureKind::kMultisampled:
-      tex = Var("texture", ast::StorageClass::kNone,
-                mod->create<ast::type::MultisampledTexture>(
-                    param.texture_dimension, datatype));
-      break;
-
-    case ast::intrinsic::test::TextureKind::kStorage: {
-      auto* st = mod->create<ast::type::StorageTexture>(
-          param.texture_dimension, param.access_control, param.image_format);
-      st->set_type(datatype);
-      tex = Var("texture", ast::StorageClass::kNone, st);
-    } break;
-  }
-
-  auto* sampler = Var("sampler", ast::StorageClass::kNone, &sampler_type);
-
-  ASSERT_TRUE(b.GenerateGlobalVariable(tex)) << b.error();
+  ASSERT_TRUE(b.GenerateGlobalVariable(texture)) << b.error();
   ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error();
 
   auto* call =