2023-07-21 00:35:39 -03:00
|
|
|
#include <windows.h>
|
|
|
|
#include "d3d9helper.hpp"
|
|
|
|
#include "d3d9.hpp"
|
|
|
|
#include "d3dobject.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <drm/drm.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <linux/kd.h>
|
2023-10-10 19:14:51 -03:00
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
2023-07-21 00:35:39 -03:00
|
|
|
|
2024-03-06 03:45:51 +00:00
|
|
|
//TODO: add ifdefs when implementing another gpu
|
|
|
|
#include <drm/i915_drm.h>
|
|
|
|
|
2024-03-06 04:13:49 -03:00
|
|
|
IDirect3D9::IDirect3D9(UINT SDKVersion) {
|
2023-09-21 01:54:21 -03:00
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "libd3d9.so: IDirect3D9::IDirect3D9()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2023-07-21 00:35:39 -03:00
|
|
|
//Create connection with DRM
|
|
|
|
int fd = open("/dev/dri/card0", O_RDWR, 0); //DirectX automatically selects the first GPU
|
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
std::cerr << "\033[1;31m" //RED BOLD
|
|
|
|
<< "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;
|
2023-09-21 01:54:21 -03:00
|
|
|
|
2023-07-21 00:35:39 -03:00
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//check if the device is Hardware or Software (Does DirectX have this check?)
|
2023-09-21 01:54:21 -03:00
|
|
|
drm_get_cap gpuType;
|
2023-07-21 00:35:39 -03:00
|
|
|
int ioctlResult = ioctl(fd, DRM_IOCTL_GET_CAP, &gpuType);
|
2023-09-21 01:54:21 -03:00
|
|
|
|
2023-10-10 19:14:51 -03:00
|
|
|
//get device vendor id:
|
|
|
|
drmVersion* version = drmGetVersion(fd);
|
|
|
|
|
2023-07-21 00:35:39 -03:00
|
|
|
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;
|
2023-09-21 01:54:21 -03:00
|
|
|
|
2023-07-21 00:35:39 -03:00
|
|
|
close(fd);
|
2023-09-21 01:54:21 -03:00
|
|
|
perror("ioctl");
|
2023-07-21 00:35:39 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-21 01:54:21 -03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "\033[1;32m" //GREEN BOLD
|
2023-10-10 19:14:51 -03:00
|
|
|
<< "ODX INFO: Device \"" << version->name << '(' << version->desc << ' ' << version->version_minor << '.' << version->version_patchlevel << ')' << "\" is " << (gpuType.value == DRM_CAP_DUMB_BUFFER ? "Software" : "Hardware") << std::endl
|
2023-09-21 01:54:21 -03:00
|
|
|
<< "\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;
|
|
|
|
}
|
2023-07-21 00:35:39 -03:00
|
|
|
|
|
|
|
IDirect3DDevice9* device;
|
|
|
|
this->CreateDevice(
|
|
|
|
D3DADAPTER_DEFAULT,
|
2023-09-21 01:54:21 -03:00
|
|
|
deviceType,
|
2023-07-21 00:35:39 -03:00
|
|
|
NULL, // TODO
|
|
|
|
NULL, // TODO
|
|
|
|
NULL, // TODO
|
|
|
|
&device
|
|
|
|
);
|
2023-09-21 01:54:21 -03:00
|
|
|
|
|
|
|
close(fd);
|
2023-07-21 00:35:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG IDirect3D9::AddRef() {
|
|
|
|
DXGASSERT(((ULONG_PTR)(&m_cRef) & 3) == 0);
|
|
|
|
|
|
|
|
InterlockedIncrement((LONG *)&m_cRef);
|
|
|
|
return m_cRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT IDirect3D9::CreateDevice(
|
|
|
|
UINT Adapter,
|
|
|
|
D3DDEVTYPE DeviceType,
|
|
|
|
HWND hFocusWindow,
|
|
|
|
DWORD BehaviorFlags,
|
|
|
|
D3DPRESENT_PARAMETERS *pPresentationParameters,
|
|
|
|
IDirect3DDevice9 **ppReturnedDeviceInterface
|
|
|
|
) {
|
2024-03-06 03:45:51 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "libd3d9.so: IDirect3D9::CreateDevice()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2024-03-06 04:13:49 -03:00
|
|
|
//get GtkWindow specs and put them into D3DPRESENT_PARAMETERS
|
|
|
|
pPresentationParameters->hDeviceWindow = hFocusWindow;
|
|
|
|
pPresentationParameters->BackBufferWidth = gtk_widget_get_size(hFocusWindow,GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
pPresentationParameters->BackBufferHeight = gtk_widget_get_size(hFocusWindow,GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
|
|
|
//create the device
|
|
|
|
IDirect3DDevice9 device = IDirect3DDevice9(/*this, pPresentationParameters*/);
|
|
|
|
*ppReturnedDeviceInterface = &device;
|
|
|
|
|
|
|
|
return 0;
|
2023-07-21 00:35:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG IDirect3D9::Release() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HRESULT IDirect3D9::QueryInterface ( REFIID riid, void ** ppvObj ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IDirect3D9* Direct3DCreate9(UINT SDKVersion) {
|
|
|
|
HINSTANCE instance = NULL;
|
|
|
|
constexpr const UINT supported_sdk = 0x0900;
|
|
|
|
|
|
|
|
if (SDKVersion != supported_sdk) {
|
|
|
|
std::cout << "\033[1;31m" //RED BOLD
|
|
|
|
<< std::endl
|
|
|
|
<< "D3D ERROR: This application compiled against improper D3D headers." << std::endl
|
|
|
|
<< "The application is compiled with SDK version (" << SDKVersion << ") but the currently installed" << std::endl
|
|
|
|
<< "runtime supports versions from (" << supported_sdk << ")." << std::endl
|
|
|
|
<< "Please recompile with an up-to-date SDK.\033[0;0m" << std::endl
|
|
|
|
<< std::endl;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirect3D9* r = new IDirect3D9(SDKVersion);
|
|
|
|
|
|
|
|
if (r == NULL)
|
|
|
|
std::cout << "\033[0;31m"
|
|
|
|
<< "Creating D3D enumeration object failed; out of memory. Direct3DCreate fails and returns NULL.\033[0;0m" << std::endl;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2024-03-06 04:13:49 -03:00
|
|
|
|
|
|
|
IDirect3DDevice9::IDirect3DDevice9(/*IDirect3D9* d3d, D3DPRESENT_PARAMETERS* pp*/) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "libd3d9.so: IDirect3DDevice9::IDirect3DDevice9()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
refCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG IDirect3DDevice9::AddRef() {
|
|
|
|
DXGASSERT(((ULONG_PTR)(&refCount) & 3) == 0);
|
|
|
|
|
|
|
|
InterlockedIncrement((LONG *)&refCount);
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG IDirect3DDevice9::Release() {
|
|
|
|
InterlockedDecrement((LONG *)&refCount);
|
|
|
|
return refCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT IDirect3DDevice9::QueryInterface(REFIID riid, void** ppvObj) {
|
|
|
|
*ppvObj = this;
|
|
|
|
|
|
|
|
IDirect3DDevice9::AddRef();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT IDirect3DDevice9::Clear(DWORD Count, const void/*D3DRECT*/ *pRects, DWORD Flags, int/*D3DCOLOR*/ Color, float Z, DWORD Stencil) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
std::cout << "libd3d9.so: IDirect3DDevice9::Clear()" << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//intel code
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|