From 0acfbbebe6e0164eaf9b3524cff4af8d407f881e Mon Sep 17 00:00:00 2001 From: "Eduardo P. Gomez" Date: Thu, 21 Sep 2023 01:54:21 -0300 Subject: [PATCH] D3DDEVTYPE detection --- .vscode/settings.json | 51 +++++++++++++++++++++++++++++++++++++++++- include/config.hpp | 2 +- include/config.hpp.in | 2 +- libs/d3d9/d3d9.cpp | 32 +++++++++++++++++++++----- libs/d3d9/d3d9.hpp | 1 + libs/opendx/opendx.cpp | 6 +++++ libs/opendx/opendx.hpp | 1 + prod_include/windows.h | 2 +- 8 files changed, 87 insertions(+), 10 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 20f36e4c..8194360e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,55 @@ ], "files.associations": { "phtml": "php", - "new": "cpp" + "new": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" } } \ No newline at end of file diff --git a/include/config.hpp b/include/config.hpp index 105c3e85..cea063b6 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -1,6 +1,6 @@ #pragma once -#define DEBUG false +#define DEBUG true //PREPROCESSING ONLY!!! #define PROJECT_SOURCE_DIR "/home/eduardo/Documentos/proj/OpenDX/" diff --git a/include/config.hpp.in b/include/config.hpp.in index 95178dbe..5de81e97 100644 --- a/include/config.hpp.in +++ b/include/config.hpp.in @@ -1,6 +1,6 @@ #pragma once -#define DEBUG false +#define DEBUG true //PREPROCESSING ONLY!!! #define PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@/" diff --git a/libs/d3d9/d3d9.cpp b/libs/d3d9/d3d9.cpp index 3ea1ed95..7c046b54 100644 --- a/libs/d3d9/d3d9.cpp +++ b/libs/d3d9/d3d9.cpp @@ -12,6 +12,10 @@ IDirect3D9::IDirect3D9 (UINT SDKVersion) { + #ifdef DEBUG + std::cout << "libd3d9.so: IDirect3D9::IDirect3D9()" << std::endl; + #endif + //Create connection with DRM int fd = open("/dev/dri/card0", O_RDWR, 0); //DirectX automatically selects the first GPU @@ -20,36 +24,52 @@ IDirect3D9::IDirect3D9 (UINT SDKVersion) { << "ODX ERROR: Failed to open /dev/dri/card0. Please check if you have the proper permissions to access the device." << std::endl << "Direct3DCreate9 fails and returns NULL.\033[0;0m" << std::endl << std::endl; + close(fd); return; } //check if the device is Hardware or Software (Does DirectX have this check?) - unsigned int gpuType; - + drm_get_cap gpuType; int ioctlResult = ioctl(fd, DRM_IOCTL_GET_CAP, &gpuType); + if (ioctlResult != 0) { std::cerr << "\033[1;31m" << "ODX ERROR: Failed to get device info" << std::endl << "Direct3DCreate9 fails and returns NULL.\033[0;0m" << std::endl << std::endl; + close(fd); + perror("ioctl"); return; } - std::cout << "\033[1;32m" //GREEN BOLD - << "ODX INFO: Device is " << (gpuType == DRM_CAP_DUMB_BUFFER ? "Software" : "Hardware") << std::endl - << "\033[0;0m" << std::endl; + + #ifdef DEBUG + std::cout << "\033[1;32m" //GREEN BOLD + << "ODX INFO: Device is " << (gpuType.value == DRM_CAP_DUMB_BUFFER ? "Software" : "Hardware") << std::endl + << "\033[0;0m" << std::endl; + #endif + + D3DDEVTYPE deviceType = D3DDEVTYPE::D3DDEVTYPE_NULLREF; + + if (gpuType.value == DRM_CAP_DUMB_BUFFER) { + deviceType = D3DDEVTYPE::D3DDEVTYPE_SW; + } else { + deviceType = D3DDEVTYPE::D3DDEVTYPE_HAL; + } IDirect3DDevice9* device; this->CreateDevice( D3DADAPTER_DEFAULT, - D3DDEVTYPE::D3DDEVTYPE_SW, // TODO + deviceType, NULL, // TODO NULL, // TODO NULL, // TODO &device ); + + close(fd); } diff --git a/libs/d3d9/d3d9.hpp b/libs/d3d9/d3d9.hpp index 78646f7b..7c3ba602 100644 --- a/libs/d3d9/d3d9.hpp +++ b/libs/d3d9/d3d9.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include "d3d9helper.hpp" #include "d3d9types.hpp" diff --git a/libs/opendx/opendx.cpp b/libs/opendx/opendx.cpp index 0dff20ac..64b9df24 100644 --- a/libs/opendx/opendx.cpp +++ b/libs/opendx/opendx.cpp @@ -1,7 +1,9 @@ +#include "opendx.hpp" #include #include #include #include +#include /** * @brief Create a Window @@ -22,6 +24,10 @@ HWND CreateWindowExA( HINSTANCE instance, //optional (Windows ignores it) LPVOID param //optional ) { + #ifdef DEBUG + std::cout << "libopendx.so: CreateWindowExA()" << std::endl; + #endif + GtkWidget* window = gtk_window_new(); if (title != nullptr) { diff --git a/libs/opendx/opendx.hpp b/libs/opendx/opendx.hpp index 3f59c932..04eb6c7e 100644 --- a/libs/opendx/opendx.hpp +++ b/libs/opendx/opendx.hpp @@ -1,2 +1,3 @@ #pragma once +#include \ No newline at end of file diff --git a/prod_include/windows.h b/prod_include/windows.h index c12f22ab..a1ae96fd 100644 --- a/prod_include/windows.h +++ b/prod_include/windows.h @@ -35,7 +35,7 @@ #include #include #include -//#include +#include #define DWORD unsigned long #define HWND GtkWidget*