WrapIOSurface: Add support for RGBA8

BUG=dawn:112

Change-Id: I18d2e8bc0bcca2725f2087913955c8ecadbd5852
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9642
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Idan Raiter <idanr@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn_native/metal/TextureMTL.mm b/src/dawn_native/metal/TextureMTL.mm
index 5e12f7a..755069c 100644
--- a/src/dawn_native/metal/TextureMTL.mm
+++ b/src/dawn_native/metal/TextureMTL.mm
@@ -109,6 +109,8 @@
 
         ResultOrError<dawn::TextureFormat> GetFormatEquivalentToIOSurfaceFormat(uint32_t format) {
             switch (format) {
+                case 'RGBA':
+                    return dawn::TextureFormat::RGBA8Unorm;
                 case 'BGRA':
                     return dawn::TextureFormat::BGRA8Unorm;
                 case '2C08':
diff --git a/src/tests/end2end/IOSurfaceWrappingTests.cpp b/src/tests/end2end/IOSurfaceWrappingTests.cpp
index 843247b..c475026 100644
--- a/src/tests/end2end/IOSurfaceWrappingTests.cpp
+++ b/src/tests/end2end/IOSurfaceWrappingTests.cpp
@@ -407,7 +407,7 @@
 }
 
 // Test sampling from a BGRA8 IOSurface
-TEST_P(IOSurfaceUsageTests, SampleFromBGRA8888IOSurface) {
+TEST_P(IOSurfaceUsageTests, SampleFromBGRA8IOSurface) {
     DAWN_SKIP_TEST_IF(UsesWire());
     ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'BGRA', 4);
 
@@ -425,5 +425,24 @@
     DoClearTest(ioSurface.get(), dawn::TextureFormat::BGRA8Unorm, &data, sizeof(data));
 }
 
+// Test sampling from an RGBA8 IOSurface
+TEST_P(IOSurfaceUsageTests, SampleFromRGBA8IOSurface) {
+    DAWN_SKIP_TEST_IF(UsesWire());
+    ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4);
+
+    uint32_t data = 0x01020304;  // Stored as (A, B, G, R)
+    DoSampleTest(ioSurface.get(), dawn::TextureFormat::RGBA8Unorm, &data, sizeof(data),
+                 RGBA8(4, 3, 2, 1));
+}
+
+// Test clearing an RGBA8 IOSurface
+TEST_P(IOSurfaceUsageTests, ClearRGBA8IOSurface) {
+    DAWN_SKIP_TEST_IF(UsesWire());
+    ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, 'RGBA', 4);
+
+    uint32_t data = 0x04030201;
+    DoClearTest(ioSurface.get(), dawn::TextureFormat::RGBA8Unorm, &data, sizeof(data));
+}
+
 DAWN_INSTANTIATE_TEST(IOSurfaceValidationTests, MetalBackend);
 DAWN_INSTANTIATE_TEST(IOSurfaceUsageTests, MetalBackend);