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>
This commit is contained in:
Corentin Wallez 2020-06-01 13:58:22 +00:00 committed by Commit Bot service account
parent 0357eed7de
commit 13110bff05
3 changed files with 10 additions and 11 deletions

View File

@ -15,7 +15,7 @@
#ifndef COMMON_WINDOWS_WITH_UNDEFS_H_ #ifndef COMMON_WINDOWS_WITH_UNDEFS_H_
#define COMMON_WINDOWS_WITH_UNDEFS_H_ #define COMMON_WINDOWS_WITH_UNDEFS_H_
#include "common/Compiler.h" #include "common/Platform.h"
#if !defined(DAWN_PLATFORM_WINDOWS) #if !defined(DAWN_PLATFORM_WINDOWS)
# error "windows_with_undefs.h included on non-Windows" # error "windows_with_undefs.h included on non-Windows"

View File

@ -488,17 +488,17 @@ namespace dawn_native { namespace d3d12 {
uint64_t errorsToPrint = std::min(kMaxDebugMessagesToPrint, totalErrors); uint64_t errorsToPrint = std::min(kMaxDebugMessagesToPrint, totalErrors);
for (uint64_t i = 0; i < errorsToPrint; ++i) { for (uint64_t i = 0; i < errorsToPrint; ++i) {
SIZE_T messageLength = 0; SIZE_T messageLength = 0;
HRESULT hr = infoQueue->GetMessageW(i, nullptr, &messageLength); HRESULT hr = infoQueue->GetMessage(i, nullptr, &messageLength);
if (FAILED(hr)) { if (FAILED(hr)) {
messages << " ID3D12InfoQueue::GetMessageW failed with " << hr << '\n'; messages << " ID3D12InfoQueue::GetMessagefailed with " << hr << '\n';
continue; continue;
} }
std::unique_ptr<uint8_t[]> messageData(new uint8_t[messageLength]); std::unique_ptr<uint8_t[]> messageData(new uint8_t[messageLength]);
D3D12_MESSAGE* message = reinterpret_cast<D3D12_MESSAGE*>(messageData.get()); D3D12_MESSAGE* message = reinterpret_cast<D3D12_MESSAGE*>(messageData.get());
hr = infoQueue->GetMessageW(i, message, &messageLength); hr = infoQueue->GetMessage(i, message, &messageLength);
if (FAILED(hr)) { if (FAILED(hr)) {
messages << " ID3D12InfoQueue::GetMessageW failed with " << hr << '\n'; messages << " ID3D12InfoQueue::GetMessage failed with " << hr << '\n';
continue; continue;
} }

View File

@ -15,6 +15,11 @@
#ifndef DAWNNATIVE_D3D12_D3D12PLATFORM_H_ #ifndef DAWNNATIVE_D3D12_D3D12PLATFORM_H_
#define 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 <d3d11_2.h>
#include <d3d11on12.h> #include <d3d11on12.h>
#include <d3d12.h> #include <d3d12.h>
@ -29,10 +34,4 @@
using Microsoft::WRL::ComPtr; 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_ #endif // DAWNNATIVE_D3D12_D3D12PLATFORM_H_