Update samples to use preferred texture format for surface

Change-Id: I1aabdc037a8ef2f537c67cbb778a35bf22e82625
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/201894
Commit-Queue: Jaswant Panchumarti <jaswant.panchumarti@kitware.com>
Auto-Submit: Jaswant Panchumarti <jaswant.panchumarti@kitware.com>
Reviewed-by: Loko Kung <lokokung@google.com>
diff --git a/src/dawn/samples/Animometer.cpp b/src/dawn/samples/Animometer.cpp
index 1efa0a6..46dbd84 100644
--- a/src/dawn/samples/Animometer.cpp
+++ b/src/dawn/samples/Animometer.cpp
@@ -128,7 +128,7 @@
         descriptor.layout = dawn::utils::MakeBasicPipelineLayout(device, &bgl);
         descriptor.vertex.module = vsModule;
         descriptor.cFragment.module = fsModule;
-        descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
+        descriptor.cTargets[0].format = GetPreferredSurfaceTextureFormat();
 
         pipeline = device.CreateRenderPipeline(&descriptor);
 
diff --git a/src/dawn/samples/ComputeBoids.cpp b/src/dawn/samples/ComputeBoids.cpp
index fddb84f..e72f433 100644
--- a/src/dawn/samples/ComputeBoids.cpp
+++ b/src/dawn/samples/ComputeBoids.cpp
@@ -138,7 +138,7 @@
         descriptor.cAttributes[2].format = wgpu::VertexFormat::Float32x2;
 
         descriptor.cFragment.module = fsModule;
-        descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
+        descriptor.cTargets[0].format = GetPreferredSurfaceTextureFormat();
 
         renderPipeline = device.CreateRenderPipeline(&descriptor);
     }
diff --git a/src/dawn/samples/HelloTriangle.cpp b/src/dawn/samples/HelloTriangle.cpp
index 1d7d250..8f99613 100644
--- a/src/dawn/samples/HelloTriangle.cpp
+++ b/src/dawn/samples/HelloTriangle.cpp
@@ -62,7 +62,7 @@
         descriptor.cBuffers[0].attributeCount = 1;
         descriptor.cAttributes[0].format = wgpu::VertexFormat::Float32x4;
         descriptor.cFragment.module = module;
-        descriptor.cTargets[0].format = GetPreferredSwapChainTextureFormat();
+        descriptor.cTargets[0].format = GetPreferredSurfaceTextureFormat();
 
         pipeline = device.CreateRenderPipeline(&descriptor);
         return true;
diff --git a/src/dawn/samples/SampleUtils.cpp b/src/dawn/samples/SampleUtils.cpp
index af23e97..d53cf4b 100644
--- a/src/dawn/samples/SampleUtils.cpp
+++ b/src/dawn/samples/SampleUtils.cpp
@@ -53,11 +53,6 @@
 #include <emscripten/emscripten.h>
 #endif  // __EMSCRIPTEN__
 
-wgpu::TextureFormat GetPreferredSwapChainTextureFormat() {
-    // TODO(dawn:1362): Return the adapter's preferred format when implemented.
-    return wgpu::TextureFormat::BGRA8Unorm;
-}
-
 // Parsed options.
 static wgpu::BackendType backendType = wgpu::BackendType::Undefined;
 static wgpu::AdapterType adapterType = wgpu::AdapterType::Unknown;
@@ -353,6 +348,7 @@
     config.width = width;
     config.height = height;
     surface.Configure(&config);
+    this->preferredSurfaceTextureFormat = capabilities.formats[0];
 
     return SetupImpl();
 }
diff --git a/src/dawn/samples/SampleUtils.h b/src/dawn/samples/SampleUtils.h
index 44387cf..94b679b 100644
--- a/src/dawn/samples/SampleUtils.h
+++ b/src/dawn/samples/SampleUtils.h
@@ -34,7 +34,6 @@
 
 #include <webgpu/webgpu_cpp.h>
 
-wgpu::TextureFormat GetPreferredSwapChainTextureFormat();
 bool InitSample(int argc, const char** argv);
 
 class SampleBase {
@@ -55,6 +54,8 @@
 
     wgpu::Surface surface = nullptr;
 
+    wgpu::TextureFormat GetPreferredSurfaceTextureFormat() { return preferredSurfaceTextureFormat; }
+
   private:
     bool Setup();
 
@@ -62,6 +63,7 @@
     static constexpr uint32_t kHeight = 480;
     uint32_t width = kWidth;
     uint32_t height = kHeight;
+    wgpu::TextureFormat preferredSurfaceTextureFormat = wgpu::TextureFormat::BGRA8Unorm;
 
 #ifndef __EMSCRIPTEN__
     GLFWwindow* window = nullptr;