summaryrefslogtreecommitdiff
path: root/tools/gfx/d3d12
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/d3d12
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/d3d12')
-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
8 files changed, 37 insertions, 18 deletions
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];
}