[glsl][ir] Support depth texture types

This CL adds support for the `DepthTexture` type.

Bug: 42251044
Change-Id: I489be94855482b0ad303658149af4506b31f4dc5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/204499
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/glsl/writer/printer/printer.cc b/src/tint/lang/glsl/writer/printer/printer.cc
index 9cb97bc..6e0ad47 100644
--- a/src/tint/lang/glsl/writer/printer/printer.cc
+++ b/src/tint/lang/glsl/writer/printer/printer.cc
@@ -54,6 +54,7 @@
 #include "src/tint/lang/core/texel_format.h"
 #include "src/tint/lang/core/type/array.h"
 #include "src/tint/lang/core/type/bool.h"
+#include "src/tint/lang/core/type/depth_texture.h"
 #include "src/tint/lang/core/type/f16.h"
 #include "src/tint/lang/core/type/f32.h"
 #include "src/tint/lang/core/type/i32.h"
@@ -481,12 +482,14 @@
         }
         auto* subtype = sampled ? sampled->Type() : storage ? storage->Type() : nullptr;
 
-        tint::Switch(
-            subtype,                         //
-            [&](const core::type::F32*) {},  //
-            [&](const core::type::I32*) { out << "i"; },
-            [&](const core::type::U32*) { out << "u"; },  //
-            TINT_ICE_ON_NO_MATCH);
+        if (subtype) {
+            tint::Switch(
+                subtype,                         //
+                [&](const core::type::F32*) {},  //
+                [&](const core::type::I32*) { out << "i"; },
+                [&](const core::type::U32*) { out << "u"; },  //
+                TINT_ICE_ON_NO_MATCH);
+        }
 
         out << (storage ? "image" : "sampler");
 
@@ -512,6 +515,9 @@
             default:
                 TINT_UNREACHABLE();
         }
+        if (t->Is<core::type::DepthTexture>()) {
+            out << "Shadow";
+        }
     }
 
     /// Emit a return instruction
diff --git a/src/tint/lang/glsl/writer/type_test.cc b/src/tint/lang/glsl/writer/type_test.cc
index e2bd95d..68e62c6 100644
--- a/src/tint/lang/glsl/writer/type_test.cc
+++ b/src/tint/lang/glsl/writer/type_test.cc
@@ -499,29 +499,60 @@
     out << str.str();
     return out;
 }
-using GlslWriterDepthTexturesTest = GlslWriterTestWithParam<GlslDepthTextureData>;
-// TODO(dsinclair): Add depth texture support
-TEST_P(GlslWriterDepthTexturesTest, DISABLED_Emit) {
+using GlslWriterDepthTextureESTest = GlslWriterTestWithParam<GlslDepthTextureData>;
+TEST_P(GlslWriterDepthTextureESTest, Emit) {
     auto params = GetParam();
 
     auto* t = ty.Get<core::type::DepthTexture>(params.dim);
-    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kCompute);
+    auto* func = b.Function("foo", ty.void_());
     auto* param = b.FunctionParam("a", t);
     func->SetParams({param});
-    func->SetWorkgroupSize(1, 1, 1);
     b.Append(func->Block(), [&] { b.Return(func); });
 
     ASSERT_TRUE(Generate()) << err_ << output_.glsl;
     EXPECT_EQ(output_.glsl, GlslHeader() + R"(
-layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
-void main()" + params.result +
+void foo(highp )" + params.result +
                                 R"( a) {
 }
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+}
 )");
 }
 INSTANTIATE_TEST_SUITE_P(
     GlslWriterTest,
-    GlslWriterDepthTexturesTest,
+    GlslWriterDepthTextureESTest,
+    testing::Values(
+        GlslDepthTextureData{core::type::TextureDimension::k2d, "sampler2DShadow"},
+        GlslDepthTextureData{core::type::TextureDimension::k2dArray, "sampler2DArrayShadow"},
+        GlslDepthTextureData{core::type::TextureDimension::kCube, "samplerCubeShadow"}));
+
+using GlslWriterDepthTextureNonESTest = GlslWriterTestWithParam<GlslDepthTextureData>;
+TEST_P(GlslWriterDepthTextureNonESTest, Emit) {
+    auto params = GetParam();
+
+    auto* t = ty.Get<core::type::DepthTexture>(params.dim);
+    auto* func = b.Function("foo", ty.void_());
+    auto* param = b.FunctionParam("a", t);
+    func->SetParams({param});
+    b.Append(func->Block(), [&] { b.Return(func); });
+
+    Options opts{};
+    opts.version = Version(Version::Standard::kDesktop, 4, 6);
+    ASSERT_TRUE(Generate(opts)) << err_ << output_.glsl;
+    EXPECT_EQ(output_.glsl, R"(#version 460
+
+void foo(highp )" + params.result +
+                                R"( a) {
+}
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+}
+)");
+}
+INSTANTIATE_TEST_SUITE_P(
+    GlslWriterTest,
+    GlslWriterDepthTextureNonESTest,
     testing::Values(
         GlslDepthTextureData{core::type::TextureDimension::k2d, "sampler2DShadow"},
         GlslDepthTextureData{core::type::TextureDimension::k2dArray, "sampler2DArrayShadow"},
diff --git a/test/tint/bug/chromium/342840932.wgsl.expected.ir.glsl b/test/tint/bug/chromium/342840932.wgsl.expected.ir.glsl
index 8dee2cd..64d7c5f 100644
--- a/test/tint/bug/chromium/342840932.wgsl.expected.ir.glsl
+++ b/test/tint/bug/chromium/342840932.wgsl.expected.ir.glsl
@@ -1,11 +1,7 @@
-SKIP: FAILED
+#version 310 es
 
-<dawn>/src/tint/lang/glsl/writer/printer/printer.cc:350 internal compiler error: Switch() matched no cases. Type: tint::core::type::StorageTexture
-********************************************************************
-*  The tint shader compiler has encountered an unexpected error.   *
-*                                                                  *
-*  Please help us fix this issue by submitting a bug report at     *
-*  crbug.com/tint with the source program that triggered the bug.  *
-********************************************************************
-
-tint executable returned error: signal: illegal instruction
+uniform highp readonly uimage1D image_dup_src;
+uniform highp writeonly uimage1D image_dst;
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+}