Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvofapi: NvOFAPICreateInstanceCuda - stub #253

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

SveSop
Copy link
Contributor

@SveSop SveSop commented Feb 1, 2025

This will return an error with a logtext indicating to upgrade DLSS version since the new DLSS4 version do not use opticalflow for DLSS anymore ref NVIDIA

jp7677
jp7677 previously requested changes Feb 1, 2025
Copy link
Owner

@jp7677 jp7677 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments, lets strip some of the ceremony . For completeness, could add a very brief corresponding nvofapi_cuda.cpp file like https://github.com/jp7677/dxvk-nvapi/blob/master/tests/nvofapi_vk.cpp

src/nvofapi_cuda.cpp Show resolved Hide resolved
src/nvofapi_cuda.cpp Outdated Show resolved Hide resolved
@jp7677
Copy link
Owner

jp7677 commented Feb 2, 2025

Not tested, but this is probably all that is needed (excluding comments why not having included the nvofapi_cuda header):

Code

diff --git a/src/meson.build b/src/meson.build
index 2d35672..8e0b999 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -51,6 +51,7 @@ nvofapi_src = files([
   'nvofapi.cpp',
   'nvofapi_d3d12.cpp',
   'nvofapi_vk.cpp',
+  'nvofapi_cuda.cpp',
 ])
 
 # Only build 64-bit versions of nvofapi
diff --git a/src/nvofapi_cuda.cpp b/src/nvofapi_cuda.cpp
new file mode 100644
index 0000000..eeaeae3
--- /dev/null
+++ b/src/nvofapi_cuda.cpp
@@ -0,0 +1,17 @@
+#include "nvofapi_private.h"
+#include "util/util_log.h"
+#include "util/util_statuscode.h"
+
+extern "C" {
+
+    using namespace dxvk;
+
+    NV_OF_STATUS __cdecl NvOFAPICreateInstanceCuda(uint32_t apiVer, void* functionList) {
+        constexpr auto n = __func__;
+
+        if (log::tracing())
+            log::trace(n, apiVer, log::fmt::ptr(functionList));
+
+        return OFNotAvailable(n);
+    }
+}
diff --git a/src/nvofapi_entrypoints.h b/src/nvofapi_entrypoints.h
index 17cbc7f..188f497 100644
--- a/src/nvofapi_entrypoints.h
+++ b/src/nvofapi_entrypoints.h
@@ -34,4 +34,7 @@ extern "C" {
     NV_OF_STATUS NVOFAPI OFSessionGetLastError(NvOFHandle hOf, char lastError[], uint32_t* size);
 
     NV_OF_STATUS NVOFAPI OFSessionGetCaps(NvOFHandle hOf, NV_OF_CAPS capsParam, uint32_t* capsVal, uint32_t* size);
+
+    // Overwrite CUDA entrypoint to avoid dependency to cuda.h
+    NV_OF_STATUS NVOFAPI NvOFAPICreateInstanceCuda(uint32_t apiVer, void* functionList);
 }
diff --git a/tests/meson.build b/tests/meson.build
index e4ba6ce..429ac40 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -67,12 +67,14 @@ nvofapi_src = files([
   '../src/nvofapi.cpp',
   '../src/nvofapi_d3d12.cpp',
   '../src/nvofapi_vk.cpp',
+  '../src/nvofapi_cuda.cpp',
 ])
 
 nvofapi_tests_src = files([
   'nvofapi_main.cpp',
   'nvofapi_d3d12.cpp',
   'nvofapi_vk.cpp',
+  'nvofapi_cuda.cpp',
 ])
 
 target_name = 'nvofapi'+target_suffix+'-tests'
diff --git a/tests/nvofapi_cuda.cpp b/tests/nvofapi_cuda.cpp
new file mode 100644
index 0000000..cc3ad00
--- /dev/null
+++ b/tests/nvofapi_cuda.cpp
@@ -0,0 +1,10 @@
+#include "nvofapi_tests_private.h"
+#include "nvofapi/mock_factory.h"
+
+using namespace trompeloeil;
+
+TEST_CASE("CreateInstanceVk returns not-available", "[.cuda]") {
+    struct NV_OF_CUDA_API_FUNCTION_LIST {
+    } functionList;
+    REQUIRE(NvOFAPICreateInstanceCuda(80, &functionList) == NV_OF_ERR_OF_NOT_AVAILABLE);
+}
diff --git a/tests/nvofapi_main.cpp b/tests/nvofapi_main.cpp
index d62e6ab..9b5a105 100644
--- a/tests/nvofapi_main.cpp
+++ b/tests/nvofapi_main.cpp
@@ -2,7 +2,7 @@
 #include "../inc/catch_amalgamated.hpp"
 #include "nvofapi/section_listener.h"
 
-CATCH_REGISTER_TAG_ALIAS("[@unit-tests]", "[d3d12],[vk]")
-CATCH_REGISTER_TAG_ALIAS("[@all]", "[d3d12],[vk]")
+CATCH_REGISTER_TAG_ALIAS("[@unit-tests]", "[d3d12],[vk],[cuda]")
+CATCH_REGISTER_TAG_ALIAS("[@all]", "[d3d12],[vk],[cuda]")
 
 CATCH_REGISTER_LISTENER(SectionListener)
diff --git a/tests/nvofapi_tests_private.h b/tests/nvofapi_tests_private.h
index 3860e10..8783a1b 100644
--- a/tests/nvofapi_tests_private.h
+++ b/tests/nvofapi_tests_private.h
@@ -5,6 +5,7 @@
 #endif // defined(__GNUC__) || defined(__clang__)
 
 #include "../src/nvofapi_private.h"
+#include "../src/nvofapi_entrypoints.h"
 #include "../src/nvofapi_globals.h"
 
 #include "../inc/catch_amalgamated.hpp"

But still very meh that it hacks around the actual header

@SveSop
Copy link
Contributor Author

SveSop commented Feb 2, 2025

NV_OF_CUDA_API_FUNCTION_LIST is not known unless you use the header as you probably discovered.

So.. non-elegant solution is to make a nvofapi_cuda_private.h perhaps and just declare these for usage, but then again, it would not use the ACTUAL correct struct.

@SveSop SveSop force-pushed the nvofapi-cuda branch 2 times, most recently from a58b327 to b0208db Compare February 2, 2025 12:51
Return not-available because OpticalFlow using CUDA is not implemented.

The game Indiana Jones and The Great Circle will still crash if manually
spoofing AD100 or greater, so the workaround spoofing GA100 is still
needed for this game.

Signed-off-by: Sveinar Søpler <[email protected]>
@jp7677 jp7677 self-requested a review February 2, 2025 16:14
@jp7677 jp7677 dismissed their stale review February 2, 2025 16:14

Dismissed review

@jp7677 jp7677 merged commit 0c1df26 into jp7677:master Feb 2, 2025
4 checks passed
@SveSop SveSop deleted the nvofapi-cuda branch February 2, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants