summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-14 17:08:18 +0800
committerGitHub <noreply@github.com>2023-04-14 17:08:18 +0800
commit4c9c8a7a4d9b97fec6041a562638fbea521533ed (patch)
treebcbe353f9c3a64ce7e7e5419c4172a5fadac297b /tools
parent5a629b3ccd801a1f0647e971d01481c55d3381c2 (diff)
Some small fixes with Windows/DX usage (#2797)
* Correct case of windows.h includes * Use Slang::SharedLibrary to load directx dlls * s/max/std::max/ * Factor common OS code in calcHasApi * Add DXIL test for compute/simple * s/false/FALSE for calls to WinAPI functions * Factor common OS code in gfxGetAdapters * 2 missing headers d3d12sdklayers for ID3DDebug climits for UINT_MAX * Define out unused function on Linux * Only try to load Vulkan and CUDA on Windows or Linux * simplify D3DUtil::getDxgiModule * Remove WIN32_LEAN_AND_MEAN &co from source files Add a global define * Set WIN32_LEAN_AND_MEAN &friends in headers Restore previous state also * regenerate vs projects
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx-unit-test/gfx-test-texture-util.cpp3
-rw-r--r--tools/gfx-unit-test/gfx-test-util.cpp3
-rw-r--r--tools/gfx/d3d/d3d-util.cpp28
-rw-r--r--tools/gfx/d3d/d3d-util.h7
-rw-r--r--tools/gfx/d3d11/d3d11-base.h10
-rw-r--r--tools/gfx/d3d11/d3d11-device.cpp15
-rw-r--r--tools/gfx/d3d11/d3d11-helper-functions.cpp2
-rw-r--r--tools/gfx/d3d12/d3d12-base.h15
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp17
-rw-r--r--tools/gfx/d3d12/d3d12-device.h5
-rw-r--r--tools/gfx/d3d12/d3d12-pipeline-state.cpp2
-rw-r--r--tools/gfx/d3d12/d3d12-query.cpp2
-rw-r--r--tools/gfx/d3d12/d3d12-resource.h10
-rw-r--r--tools/gfx/d3d12/d3d12-swap-chain.cpp2
-rw-r--r--tools/gfx/d3d12/d3d12-transient-heap.cpp2
-rw-r--r--tools/gfx/nvapi/nvapi-include.h10
-rw-r--r--tools/gfx/open-gl/render-gl.cpp7
-rw-r--r--tools/gfx/render.cpp16
-rw-r--r--tools/platform/gui.cpp4
-rw-r--r--tools/platform/windows/win-window.cpp3
-rw-r--r--tools/render-test/render-test-main.cpp3
21 files changed, 98 insertions, 68 deletions
diff --git a/tools/gfx-unit-test/gfx-test-texture-util.cpp b/tools/gfx-unit-test/gfx-test-texture-util.cpp
index ff1ef39d0..ed651475d 100644
--- a/tools/gfx-unit-test/gfx-test-texture-util.cpp
+++ b/tools/gfx-unit-test/gfx-test-texture-util.cpp
@@ -21,8 +21,7 @@
#if GFX_ENABLE_RENDERDOC_INTEGRATION
# include "external/renderdoc_app.h"
-# define WIN32_LEAN_AND_MEAN
-# include <Windows.h>
+# include <windows.h>
#endif
using namespace Slang;
diff --git a/tools/gfx-unit-test/gfx-test-util.cpp b/tools/gfx-unit-test/gfx-test-util.cpp
index fcebdda9f..298283a4a 100644
--- a/tools/gfx-unit-test/gfx-test-util.cpp
+++ b/tools/gfx-unit-test/gfx-test-util.cpp
@@ -7,8 +7,7 @@
#if GFX_ENABLE_RENDERDOC_INTEGRATION
# include "external/renderdoc_app.h"
-# define WIN32_LEAN_AND_MEAN
-# include <Windows.h>
+# include <windows.h>
#endif
using Slang::ComPtr;
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp
index 05a948773..eece71c16 100644
--- a/tools/gfx/d3d/d3d-util.cpp
+++ b/tools/gfx/d3d/d3d-util.cpp
@@ -10,6 +10,7 @@
#include <stdio.h>
#include "core/slang-basic.h"
+#include "core/slang-platform.h"
namespace gfx {
using namespace Slang;
@@ -498,15 +499,22 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
}
}
-/* static */HMODULE D3DUtil::getDxgiModule()
+/* static */SharedLibrary::Handle D3DUtil::getDxgiModule()
{
- static HMODULE s_dxgiModule = LoadLibraryA("dxgi.dll");
- if (!s_dxgiModule)
- {
- fprintf(stderr, "error: failed load 'dxgi.dll'\n");
- return nullptr;
- }
-
+#if SLANG_WINDOWS_FAMILY
+ const char* const libPath = "dxgi";
+#else
+ const char* const libPath = "dxvk_dxgi";
+#endif
+ static SharedLibrary::Handle s_dxgiModule = [&](){
+ SharedLibrary::Handle h = nullptr;
+ SharedLibrary::load(libPath, h);
+ if (!h)
+ {
+ fprintf(stderr, "error: failed to load dll '%s'\n", libPath);
+ }
+ return h;
+ }();
return s_dxgiModule;
}
@@ -522,7 +530,7 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
typedef HRESULT(WINAPI *PFN_DXGI_CREATE_FACTORY_2)(UINT Flags, REFIID riid, _COM_Outptr_ void **ppFactory);
{
- auto createFactory2 = (PFN_DXGI_CREATE_FACTORY_2)::GetProcAddress(dxgiModule, "CreateDXGIFactory2");
+ auto createFactory2 = (PFN_DXGI_CREATE_FACTORY_2)SharedLibrary::findSymbolAddressByName(dxgiModule, "CreateDXGIFactory2");
if (createFactory2)
{
UINT dxgiFlags = 0;
@@ -541,7 +549,7 @@ bool D3DUtil::isTypeless(DXGI_FORMAT format)
}
{
- auto createFactory = (PFN_DXGI_CREATE_FACTORY)::GetProcAddress(dxgiModule, "CreateDXGIFactory");
+ auto createFactory = (PFN_DXGI_CREATE_FACTORY)SharedLibrary::findSymbolAddressByName(dxgiModule, "CreateDXGIFactory");
if (!createFactory)
{
fprintf(stderr, "error: failed load symbol '%s'\n", "CreateDXGIFactory");
diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h
index 617ae4af2..1869d7de6 100644
--- a/tools/gfx/d3d/d3d-util.h
+++ b/tools/gfx/d3d/d3d-util.h
@@ -7,13 +7,14 @@
#include "slang-com-ptr.h"
#include "core/slang-basic.h"
+#include "core/slang-platform.h"
#include "../flag-combiner.h"
#include "slang-gfx.h"
-#include <D3Dcommon.h>
-#include <DXGIFormat.h>
+#include <d3dcommon.h>
+#include <dxgiformat.h>
#include <dxgi.h>
#include <d3d12.h>
@@ -82,7 +83,7 @@ class D3DUtil
static SlangResult createFactory(DeviceCheckFlags flags, Slang::ComPtr<IDXGIFactory>& outFactory);
/// Get the dxgiModule
- static HMODULE getDxgiModule();
+ static Slang::SharedLibrary::Handle getDxgiModule();
/// Find adapters
static SlangResult findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, Slang::List<Slang::ComPtr<IDXGIAdapter>>& dxgiAdapters);
diff --git a/tools/gfx/d3d11/d3d11-base.h b/tools/gfx/d3d11/d3d11-base.h
index d47682f18..ce38bb174 100644
--- a/tools/gfx/d3d11/d3d11-base.h
+++ b/tools/gfx/d3d11/d3d11-base.h
@@ -13,11 +13,15 @@
#include "slang-com-ptr.h"
#include "../flag-combiner.h"
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <Windows.h>
+#pragma push_macro("WIN32_LEAN_AND_MEAN")
+#pragma push_macro("NOMINMAX")
#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
#undef NOMINMAX
+#define NOMINMAX
+#include <windows.h>
+#pragma pop_macro("NOMINMAX")
+#pragma pop_macro("WIN32_LEAN_AND_MEAN")
#include <d3d11_2.h>
#include <d3dcompiler.h>
diff --git a/tools/gfx/d3d11/d3d11-device.cpp b/tools/gfx/d3d11/d3d11-device.cpp
index cc2eda089..e6a348dc1 100644
--- a/tools/gfx/d3d11/d3d11-device.cpp
+++ b/tools/gfx/d3d11/d3d11-device.cpp
@@ -46,15 +46,20 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
m_desc = desc;
// Rather than statically link against D3D, we load it dynamically.
- HMODULE d3dModule = LoadLibraryA("d3d11.dll");
- if (!d3dModule)
+ SharedLibrary::Handle d3dModule;
+#if SLANG_WINDOWS_FAMILY
+ const char* libName = "d3d11";
+#else
+ const char* libName = "dxvk_d3d11";
+#endif
+ if (SLANG_FAILED(SharedLibrary::load(libName, d3dModule)))
{
- fprintf(stderr, "error: failed load 'd3d11.dll'\n");
+ fprintf(stderr, "error: failed to load '%s'\n", libName);
return SLANG_FAIL;
}
PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN D3D11CreateDeviceAndSwapChain_ =
- (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)GetProcAddress(d3dModule, "D3D11CreateDeviceAndSwapChain");
+ (PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)SharedLibrary::findSymbolAddressByName(d3dModule, "D3D11CreateDeviceAndSwapChain");
if (!D3D11CreateDeviceAndSwapChain_)
{
fprintf(stderr,
@@ -63,7 +68,7 @@ SlangResult DeviceImpl::initialize(const Desc& desc)
}
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice_ =
- (PFN_D3D11_CREATE_DEVICE)GetProcAddress(d3dModule, "D3D11CreateDevice");
+ (PFN_D3D11_CREATE_DEVICE)SharedLibrary::findSymbolAddressByName(d3dModule, "D3D11CreateDevice");
if (!D3D11CreateDevice_)
{
fprintf(stderr,
diff --git a/tools/gfx/d3d11/d3d11-helper-functions.cpp b/tools/gfx/d3d11/d3d11-helper-functions.cpp
index 4e1df9879..6774b7d93 100644
--- a/tools/gfx/d3d11/d3d11-helper-functions.cpp
+++ b/tools/gfx/d3d11/d3d11-helper-functions.cpp
@@ -337,7 +337,7 @@ namespace d3d11
default: assert(!"Unknown dimension");
}
- descOut.Texture2DArray.ArraySize = max(textureDesc.size.depth, arraySize);
+ descOut.Texture2DArray.ArraySize = std::max(textureDesc.size.depth, arraySize);
descOut.Texture2DArray.MostDetailedMip = 0;
descOut.Texture2DArray.MipLevels = textureDesc.numMipLevels;
descOut.Texture2DArray.FirstArraySlice = 0;
diff --git a/tools/gfx/d3d12/d3d12-base.h b/tools/gfx/d3d12/d3d12-base.h
index 2446151a2..52e8d4623 100644
--- a/tools/gfx/d3d12/d3d12-base.h
+++ b/tools/gfx/d3d12/d3d12-base.h
@@ -14,12 +14,19 @@
#include "d3d12-descriptor-heap.h"
#include "d3d12-resource.h"
-#define _CRT_SECURE_NO_WARNINGS
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <Windows.h>
+#pragma push_macro("WIN32_LEAN_AND_MEAN")
+#pragma push_macro("NOMINMAX")
+#pragma push_macro("_CRT_SECURE_NO_WARNINGS")
#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
#undef NOMINMAX
+#define NOMINMAX
+#undef _CRT_SECURE_NO_WARNINGS
+#define _CRT_SECURE_NO_WARNINGS
+#include <windows.h>
+#pragma pop_macro("_CRT_SECURE_NO_WARNINGS")
+#pragma pop_macro("NOMINMAX")
+#pragma pop_macro("WIN32_LEAN_AND_MEAN")
#include <d3d12.h>
#include <dxgi1_4.h>
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 312c81d75..9bf54a01b 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -405,8 +405,13 @@ Result DeviceImpl::initialize(const Desc& desc)
// Rather than statically link against D3D, we load it dynamically.
- HMODULE d3dModule = LoadLibraryA("d3d12.dll");
- if (!d3dModule)
+ SharedLibrary::Handle d3dModule;
+#if SLANG_WINDOWS_FAMILY
+ const char* libName = "d3d11";
+#else
+ const char* libName = "vkd3d-proton-d3d12";
+#endif
+ if (SLANG_FAILED(SharedLibrary::load(libName, d3dModule)))
{
getDebugCallback()->handleMessage(
DebugMessageType::Error, DebugMessageSource::Layer, "error: failed load 'd3d12.dll'\n");
@@ -1990,7 +1995,7 @@ void DeviceImpl::submitResourceCommandsAndWait(const DeviceImpl::ResourceCommand
m_resourceCommandTransientHeap->synchronizeAndReset();
}
-void DeviceImpl::processExperimentalFeaturesDesc(void* d3dModule, void* inDesc)
+void DeviceImpl::processExperimentalFeaturesDesc(SharedLibrary::Handle d3dModule, void* inDesc)
{
typedef HRESULT(WINAPI* PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)(
UINT NumFeatures,
@@ -2002,7 +2007,7 @@ void DeviceImpl::processExperimentalFeaturesDesc(void* d3dModule, void* inDesc)
D3D12ExperimentalFeaturesDesc desc = {};
memcpy(&desc, inDesc, sizeof(desc));
auto enableExperimentalFeaturesFunc =
- (PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)loadProc((HMODULE)d3dModule, "D3D12EnableExperimentalFeatures");
+ (PFN_D3D12_ENABLE_EXPERIMENTAL_FEATURES)loadProc(d3dModule, "D3D12EnableExperimentalFeatures");
if (!enableExperimentalFeaturesFunc)
{
getDebugCallback()->handleMessage(
@@ -2173,9 +2178,9 @@ Result DeviceImpl::createCommandQueueImpl(CommandQueueImpl** outQueue)
return SLANG_OK;
}
-PROC DeviceImpl::loadProc(HMODULE module, char const* name)
+void* DeviceImpl::loadProc(SharedLibrary::Handle module, char const* name)
{
- PROC proc = ::GetProcAddress(module, name);
+ void* proc = SharedLibrary::findSymbolAddressByName(module, name);
if (!proc)
{
fprintf(stderr, "error: failed load symbol '%s'\n", name);
diff --git a/tools/gfx/d3d12/d3d12-device.h b/tools/gfx/d3d12/d3d12-device.h
index fb54e5543..e77693ebe 100644
--- a/tools/gfx/d3d12/d3d12-device.h
+++ b/tools/gfx/d3d12/d3d12-device.h
@@ -6,6 +6,7 @@
#include "d3d12-texture.h"
#include <d3d12.h>
+#include <d3d12sdklayers.h>
namespace gfx
{
@@ -207,7 +208,7 @@ public:
const RayTracingPipelineStateDesc& desc, IPipelineState** outState) override;
public:
- static PROC loadProc(HMODULE module, char const* name);
+ static void* loadProc(SharedLibrary::Handle module, char const* name);
Result createCommandQueueImpl(CommandQueueImpl** outQueue);
@@ -248,7 +249,7 @@ public:
ResourceCommandRecordInfo encodeResourceCommands();
void submitResourceCommandsAndWait(const ResourceCommandRecordInfo& info);
private:
- void processExperimentalFeaturesDesc(void* d3dModule, void* desc);
+ void processExperimentalFeaturesDesc(SharedLibrary::Handle d3dModule, void* desc);
};
} // namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-pipeline-state.cpp b/tools/gfx/d3d12/d3d12-pipeline-state.cpp
index 35313f676..754c07e5c 100644
--- a/tools/gfx/d3d12/d3d12-pipeline-state.cpp
+++ b/tools/gfx/d3d12/d3d12-pipeline-state.cpp
@@ -11,6 +11,8 @@
#include "d3d12-shader-program.h"
#include "d3d12-vertex-layout.h"
+#include <climits>
+
namespace gfx
{
namespace d3d12
diff --git a/tools/gfx/d3d12/d3d12-query.cpp b/tools/gfx/d3d12/d3d12-query.cpp
index 319976bbc..6b2e92980 100644
--- a/tools/gfx/d3d12/d3d12-query.cpp
+++ b/tools/gfx/d3d12/d3d12-query.cpp
@@ -73,7 +73,7 @@ Result QueryPoolImpl::init(const IQueryPool::Desc& desc, DeviceImpl* device)
m_commandQueue = device->m_resourceCommandQueue->m_d3dQueue;
// Create wait event.
- m_waitEvent = CreateEventEx(nullptr, false, 0, EVENT_ALL_ACCESS);
+ m_waitEvent = CreateEventEx(nullptr, FALSE, 0, EVENT_ALL_ACCESS);
return SLANG_OK;
}
diff --git a/tools/gfx/d3d12/d3d12-resource.h b/tools/gfx/d3d12/d3d12-resource.h
index ab9244470..cd56793cc 100644
--- a/tools/gfx/d3d12/d3d12-resource.h
+++ b/tools/gfx/d3d12/d3d12-resource.h
@@ -1,11 +1,15 @@
// d3d12-resource.h
#pragma once
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <Windows.h>
+#pragma push_macro("WIN32_LEAN_AND_MEAN")
+#pragma push_macro("NOMINMAX")
#undef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
#undef NOMINMAX
+#define NOMINMAX
+#include <windows.h>
+#pragma pop_macro("NOMINMAX")
+#pragma pop_macro("WIN32_LEAN_AND_MEAN")
#include <dxgi1_4.h>
#include <d3d12.h>
diff --git a/tools/gfx/d3d12/d3d12-swap-chain.cpp b/tools/gfx/d3d12/d3d12-swap-chain.cpp
index 39a4565e0..57825a323 100644
--- a/tools/gfx/d3d12/d3d12-swap-chain.cpp
+++ b/tools/gfx/d3d12/d3d12-swap-chain.cpp
@@ -26,7 +26,7 @@ Result SwapchainImpl::init(
{
m_frameEvents.add(CreateEventEx(
nullptr,
- false,
+ FALSE,
CREATE_EVENT_INITIAL_SET | CREATE_EVENT_MANUAL_RESET,
EVENT_ALL_ACCESS));
}
diff --git a/tools/gfx/d3d12/d3d12-transient-heap.cpp b/tools/gfx/d3d12/d3d12-transient-heap.cpp
index 11b03dc12..9139f6d8a 100644
--- a/tools/gfx/d3d12/d3d12-transient-heap.cpp
+++ b/tools/gfx/d3d12/d3d12-transient-heap.cpp
@@ -64,7 +64,7 @@ TransientResourceHeapImpl::QueueWaitInfo& TransientResourceHeapImpl::getQueueWai
for (auto i = oldCount; i < m_waitInfos.getCount(); i++)
{
m_waitInfos[i].waitValue = 0;
- m_waitInfos[i].fenceEvent = CreateEventEx(nullptr, false, 0, EVENT_ALL_ACCESS);
+ m_waitInfos[i].fenceEvent = CreateEventEx(nullptr, FALSE, 0, EVENT_ALL_ACCESS);
}
return m_waitInfos[queueIndex];
}
diff --git a/tools/gfx/nvapi/nvapi-include.h b/tools/gfx/nvapi/nvapi-include.h
index c213e0bfb..513977048 100644
--- a/tools/gfx/nvapi/nvapi-include.h
+++ b/tools/gfx/nvapi/nvapi-include.h
@@ -7,11 +7,15 @@
// On windows if we include NVAPI, we must include windows.h first
# ifdef _WIN32
+# pragma push_macro("WIN32_LEAN_AND_MEAN")
+# pragma push_macro("NOMINMAX")
+# undef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
+# undef NOMINMAX
# define NOMINMAX
-# include <Windows.h>
-# undef WIN32_LEAN_AND_MEAN
-# undef NOMINMAX
+# include <windows.h>
+# pragma pop_macro("NOMINMAX")
+# pragma pop_macro("WIN32_LEAN_AND_MEAN")
# endif
# include <nvapi.h>
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index 9167266e9..057828d58 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -22,11 +22,8 @@
// TODO(tfoley): eventually we should be able to run these
// tests on non-Windows targets to confirm that cross-compilation
// at least *works* on those platforms...
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX
-#include <Windows.h>
-#undef WIN32_LEAN_AND_MEAN
-#undef NOMINMAX
+
+#include <windows.h>
#ifdef _MSC_VER
#include <stddef.h>
diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp
index 048eb8224..2f10fa67c 100644
--- a/tools/gfx/render.cpp
+++ b/tools/gfx/render.cpp
@@ -256,13 +256,9 @@ extern "C"
break;
case DeviceType::OpenGl:
return SLANG_E_NOT_IMPLEMENTED;
- case DeviceType::Vulkan:
- SLANG_RETURN_ON_FAIL(getVKAdapters(adapters));
- break;
- case DeviceType::CUDA:
- SLANG_RETURN_ON_FAIL(getCUDAAdapters(adapters));
- break;
-#elif SLANG_LINUX_FAMILY && !defined(__CYGWIN__)
+#endif
+#if SLANG_WINDOWS_FAMILY || SLANG_LINUX_FAMILY
+ // Assume no Vulkan or CUDA on MacOS or Cygwin
case DeviceType::Vulkan:
SLANG_RETURN_ON_FAIL(getVKAdapters(adapters));
break;
@@ -304,10 +300,6 @@ extern "C"
{
return createVKDevice(desc, outDevice);
}
- case DeviceType::CUDA:
- {
- return createCUDADevice(desc, outDevice);
- }
case DeviceType::Default:
{
IDevice::Desc newDesc = *desc;
@@ -332,11 +324,11 @@ extern "C"
{
return createVKDevice(desc, outDevice);
}
+#endif
case DeviceType::CUDA:
{
return createCUDADevice(desc, outDevice);
}
-#endif
case DeviceType::CPU:
{
return createCPUDevice(desc, outDevice);
diff --git a/tools/platform/gui.cpp b/tools/platform/gui.cpp
index 8bfff2d11..a4602e4f2 100644
--- a/tools/platform/gui.cpp
+++ b/tools/platform/gui.cpp
@@ -353,5 +353,9 @@ GUI::~GUI()
#include "external/imgui/imgui.cpp"
#include "external/imgui/imgui_draw.cpp"
#ifdef _WIN32
+// imgui_impl_win32 defines these, so make sure it doesn't error because
+// they're already there
+#undef WIN32_LEAN_AND_MEAN
+#undef NOMINMAX
#include "external/imgui/examples/imgui_impl_win32.cpp"
#endif
diff --git a/tools/platform/windows/win-window.cpp b/tools/platform/windows/win-window.cpp
index f0217e04c..d785b0fb7 100644
--- a/tools/platform/windows/win-window.cpp
+++ b/tools/platform/windows/win-window.cpp
@@ -2,8 +2,7 @@
#include "../window.h"
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <windows.h>
#include <windowsx.h>
using namespace Slang;
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index d3c284132..f21a5ff07 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -26,8 +26,7 @@
#if ENABLE_RENDERDOC_INTEGRATION
# include "external/renderdoc_app.h"
-# define WIN32_LEAN_AND_MEAN
-# include <Windows.h>
+# include <windows.h>
#endif
namespace renderer_test {