summaryrefslogtreecommitdiffstats
path: root/tools/gfx/nvapi
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gfx/nvapi')
-rw-r--r--tools/gfx/nvapi/nvapi-include.h19
-rw-r--r--tools/gfx/nvapi/nvapi-util.cpp30
-rw-r--r--tools/gfx/nvapi/nvapi-util.h19
3 files changed, 68 insertions, 0 deletions
diff --git a/tools/gfx/nvapi/nvapi-include.h b/tools/gfx/nvapi/nvapi-include.h
new file mode 100644
index 000000000..e3674af95
--- /dev/null
+++ b/tools/gfx/nvapi/nvapi-include.h
@@ -0,0 +1,19 @@
+// nvapi-include.h
+#pragma once
+
+// A helper that makes the NVAPI available across targets
+
+#ifdef GFX_NVAPI
+// On windows if we include NVAPI, we must include windows.h first
+
+# ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <Windows.h>
+# undef WIN32_LEAN_AND_MEAN
+# undef NOMINMAX
+# endif
+
+# include <nvapi.h>
+#endif
+
diff --git a/tools/gfx/nvapi/nvapi-util.cpp b/tools/gfx/nvapi/nvapi-util.cpp
new file mode 100644
index 000000000..63bcc65fc
--- /dev/null
+++ b/tools/gfx/nvapi/nvapi-util.cpp
@@ -0,0 +1,30 @@
+#include "nvapi-util.h"
+
+#include "nvapi-include.h"
+
+namespace gfx {
+
+static SlangResult g_initStatus = SLANG_E_UNINITIALIZED;
+
+/* static */SlangResult NVAPIUtil::initialize()
+{
+#ifdef GFX_NVAPI
+ if (g_initStatus == SLANG_E_UNINITIALIZED)
+ {
+ NvAPI_Status ret = NVAPI_OK;
+ ret = NvAPI_Initialize();
+ g_initStatus = (ret == NVAPI_OK) ? SLANG_OK : SLANG_E_NOT_AVAILABLE;
+ }
+#else
+ g_initStatus = SLANG_E_NOT_AVAILABLE;
+#endif
+
+ return g_initStatus;
+}
+
+/* static */bool NVAPIUtil::isAvailable()
+{
+ return SLANG_SUCCEEDED(g_initStatus);
+}
+
+} // gfx
diff --git a/tools/gfx/nvapi/nvapi-util.h b/tools/gfx/nvapi/nvapi-util.h
new file mode 100644
index 000000000..704f4ede4
--- /dev/null
+++ b/tools/gfx/nvapi/nvapi-util.h
@@ -0,0 +1,19 @@
+// nvapi-util.h
+#pragma once
+
+#include "../../slang-com-helper.h"
+#include "../../slang-com-ptr.h"
+
+namespace gfx {
+
+struct NVAPIUtil
+{
+ /// Set up NVAPI for use. Must be called before any other function is used.
+ static SlangResult initialize();
+ /// True if the NVAPI is available, can be called even if initialize fails.
+ /// If initialize has not been called will return false
+ static bool isAvailable();
+};
+
+
+} // gfx