summaryrefslogtreecommitdiff
path: root/tools/gfx/d3d11
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/gfx/d3d11
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/gfx/d3d11')
-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
3 files changed, 18 insertions, 9 deletions
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;