d3d12_platform: ensure windows.h macros don't cause compile errors

The windows.h macros were undefined only at the end of this platform
header previously but with the addition of d3d12sdklayers.h the
definition of ID3D12DebugQueue::GetMessage picked up the macro and
became GetMessageA or GetMessageW, but Dawn code referred to it as
GetMessage causing a compilation error.

Fix this by preemptively loading windows.h and undefing some of the
macros so that the D3D12 headers don't see them.

Bug:
Change-Id: I1985cc20a9bdec1d25619ac5088e918b2acf8ecb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22400
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/common/windows_with_undefs.h b/src/common/windows_with_undefs.h
index 381116a..6d8649c 100644
--- a/src/common/windows_with_undefs.h
+++ b/src/common/windows_with_undefs.h
@@ -15,7 +15,7 @@
 #ifndef COMMON_WINDOWS_WITH_UNDEFS_H_
 #define COMMON_WINDOWS_WITH_UNDEFS_H_
 
-#include "common/Compiler.h"
+#include "common/Platform.h"
 
 #if !defined(DAWN_PLATFORM_WINDOWS)
 #    error "windows_with_undefs.h included on non-Windows"
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp
index aea4aca..efacac3 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp
@@ -488,17 +488,17 @@
         uint64_t errorsToPrint = std::min(kMaxDebugMessagesToPrint, totalErrors);
         for (uint64_t i = 0; i < errorsToPrint; ++i) {
             SIZE_T messageLength = 0;
-            HRESULT hr = infoQueue->GetMessageW(i, nullptr, &messageLength);
+            HRESULT hr = infoQueue->GetMessage(i, nullptr, &messageLength);
             if (FAILED(hr)) {
-                messages << " ID3D12InfoQueue::GetMessageW failed with " << hr << '\n';
+                messages << " ID3D12InfoQueue::GetMessagefailed with " << hr << '\n';
                 continue;
             }
 
             std::unique_ptr<uint8_t[]> messageData(new uint8_t[messageLength]);
             D3D12_MESSAGE* message = reinterpret_cast<D3D12_MESSAGE*>(messageData.get());
-            hr = infoQueue->GetMessageW(i, message, &messageLength);
+            hr = infoQueue->GetMessage(i, message, &messageLength);
             if (FAILED(hr)) {
-                messages << " ID3D12InfoQueue::GetMessageW failed with " << hr << '\n';
+                messages << " ID3D12InfoQueue::GetMessage failed with " << hr << '\n';
                 continue;
             }
 
diff --git a/src/dawn_native/d3d12/d3d12_platform.h b/src/dawn_native/d3d12/d3d12_platform.h
index 1962468..1c733c8 100644
--- a/src/dawn_native/d3d12/d3d12_platform.h
+++ b/src/dawn_native/d3d12/d3d12_platform.h
@@ -15,6 +15,11 @@
 #ifndef DAWNNATIVE_D3D12_D3D12PLATFORM_H_
 #define DAWNNATIVE_D3D12_D3D12PLATFORM_H_
 
+// Pre-emptively include windows.h but remove its macros so that they aren't set when declaring the
+// COM interfaces. Otherwise ID3D12InfoQueue::GetMessage would be either GetMessageA or GetMessageW
+// which causes compilation errors.
+#include "common/windows_with_undefs.h"
+
 #include <d3d11_2.h>
 #include <d3d11on12.h>
 #include <d3d12.h>
@@ -29,10 +34,4 @@
 
 using Microsoft::WRL::ComPtr;
 
-// Remove windows.h macros after d3d12's include of windows.h
-#include "common/Platform.h"
-#if defined(DAWN_PLATFORM_WINDOWS)
-#    include "common/windows_with_undefs.h"
-#endif
-
 #endif  // DAWNNATIVE_D3D12_D3D12PLATFORM_H_