Skip to content

Commit

Permalink
D3DDEVTYPE detection
Browse files Browse the repository at this point in the history
  • Loading branch information
EduApps-CDG committed Sep 21, 2023
1 parent 555849a commit 0acfbbe
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 10 deletions.
51 changes: 50 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion include/config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define DEBUG false
#define DEBUG true

//PREPROCESSING ONLY!!!
#define PROJECT_SOURCE_DIR "/home/eduardo/Documentos/proj/OpenDX/"
2 changes: 1 addition & 1 deletion include/config.hpp.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define DEBUG false
#define DEBUG true

//PREPROCESSING ONLY!!!
#define PROJECT_SOURCE_DIR "@PROJECT_SOURCE_DIR@/"
32 changes: 26 additions & 6 deletions libs/d3d9/d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
}


Expand Down
1 change: 1 addition & 0 deletions libs/d3d9/d3d9.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <config.hpp>
#include <windows.h>
#include "d3d9helper.hpp"
#include "d3d9types.hpp"
Expand Down
6 changes: 6 additions & 0 deletions libs/opendx/opendx.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "opendx.hpp"
#include <windows.h>
#include <gtk/gtk.h>
#include <winuser.h>
#include <opendx.h>
#include <iostream>

/**
* @brief Create a Window
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions libs/opendx/opendx.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#pragma once

#include <config.hpp>
2 changes: 1 addition & 1 deletion prod_include/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <stdarg.h>
#include <windef.h>
#include <winnt.h>
//#include <gtk/gtk.h>
#include <gtk/gtk.h>

#define DWORD unsigned long
#define HWND GtkWidget*
Expand Down

0 comments on commit 0acfbbe

Please sign in to comment.