2024-09-15 17:03:38 +00:00
|
|
|
#include <cstdlib>
|
2022-06-26 13:02:21 +00:00
|
|
|
#include <iterator>
|
2022-03-27 23:07:11 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <d3d11_1.h>
|
|
|
|
#include "PCDX11DeviceManager.h"
|
|
|
|
|
|
|
|
namespace cdc {
|
|
|
|
|
|
|
|
PCDX11DeviceManager::PCDX11DeviceManager(HMODULE d3d11, HMODULE dxgi) :
|
|
|
|
d3d11(d3d11),
|
2023-04-12 00:00:31 +00:00
|
|
|
dxgi(dxgi),
|
|
|
|
currentAdapter(nullptr)
|
2022-03-27 23:07:11 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PCDX11DeviceManager::PCDX11DeviceManager(
|
|
|
|
HMODULE d3d11,
|
2022-06-02 18:26:30 +00:00
|
|
|
HMODULE dxgi,
|
|
|
|
ID3D11Device *device,
|
|
|
|
ID3D11DeviceContext *deviceContext)
|
2022-03-27 23:07:11 +00:00
|
|
|
:
|
|
|
|
d3d11(d3d11),
|
|
|
|
dxgi(dxgi),
|
|
|
|
device(device),
|
|
|
|
deviceContext(deviceContext)
|
|
|
|
{
|
2022-08-07 21:10:46 +00:00
|
|
|
#if _WIN32
|
2022-06-02 18:26:30 +00:00
|
|
|
auto createDXGIFactory = (decltype(&CreateDXGIFactory))(GetProcAddress(d3d11, "CreateDXGIFactory"));
|
|
|
|
createDXGIFactory(__uuidof(IDXGIFactory), (void**)&dxgiFactory);
|
2022-08-07 21:10:46 +00:00
|
|
|
#else
|
|
|
|
IDXGIDevice *dxgiDevice;
|
|
|
|
IDXGIAdapter *adapter;
|
|
|
|
device->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
|
|
|
|
dxgiDevice->GetAdapter(&adapter);
|
|
|
|
adapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxgiFactory);
|
|
|
|
#endif
|
2023-04-12 00:00:31 +00:00
|
|
|
|
|
|
|
// HACK
|
|
|
|
adapters.push_back(AdapterInfo {
|
|
|
|
/*backBufferFormat=*/ DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
|
|
|
|
/*depthTextureFormat=*/ DXGI_FORMAT_R24G8_TYPELESS
|
|
|
|
});
|
|
|
|
currentAdapter = &adapters[0];
|
2024-09-15 17:03:38 +00:00
|
|
|
HRESULT r = deviceContext->QueryInterface(
|
|
|
|
__uuidof(ID3DUserDefinedAnnotation), reinterpret_cast<void**>(&annotation));
|
2022-03-27 23:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_00() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayConfig *PCDX11DeviceManager::getDisplayConfig() {
|
|
|
|
return &config1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::setBrightness(float brightness) {
|
|
|
|
config1.brightness = brightness;
|
|
|
|
}
|
|
|
|
|
2022-06-29 12:54:05 +00:00
|
|
|
bool PCDX11DeviceManager::isConfigAcceptable(DisplayConfig*) {
|
2022-03-27 23:07:11 +00:00
|
|
|
// TODO
|
2022-06-29 12:54:05 +00:00
|
|
|
return true;
|
2022-03-27 23:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_10() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_14() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_18() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_1C() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_20() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::method_24() {
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2024-09-15 17:03:38 +00:00
|
|
|
void PCDX11DeviceManager::StartMarker(const char *str) {
|
|
|
|
if (!annotation) return;
|
|
|
|
size_t len = strlen(str);
|
|
|
|
wchar_t *wstr = new wchar_t[len+1];
|
|
|
|
mbstowcs(wstr, str, len+1);
|
|
|
|
StartMarker(wstr);
|
|
|
|
delete[] wstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::StartMarker(const wchar_t *wstr) {
|
|
|
|
if (annotation) annotation->BeginEvent(wstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PCDX11DeviceManager::EndMarker() {
|
|
|
|
if (annotation) annotation->EndEvent();
|
|
|
|
}
|
|
|
|
|
2022-03-27 23:07:11 +00:00
|
|
|
PCDX11DeviceManager *deviceManager = nullptr;
|
|
|
|
|
|
|
|
PCDX11DeviceManager *createPCDX11DeviceManager() {
|
2022-08-07 21:10:46 +00:00
|
|
|
#if _WIN32
|
2022-03-27 23:07:11 +00:00
|
|
|
HMODULE d3d11 = LoadLibraryA("d3d11.dll");
|
|
|
|
if (!d3d11)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
HMODULE dxgi = LoadLibraryA("dxgi.dll");
|
|
|
|
if (!dxgi) {
|
|
|
|
FreeLibrary(d3d11);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto createDevice = (decltype(&D3D11CreateDevice))(GetProcAddress(d3d11, "D3D11CreateDevice"));
|
2022-08-07 21:10:46 +00:00
|
|
|
#else
|
|
|
|
void *d3d11 = nullptr;
|
|
|
|
void *dxgi = nullptr;
|
|
|
|
#endif
|
2022-03-27 23:07:11 +00:00
|
|
|
|
|
|
|
D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0 };
|
|
|
|
D3D_FEATURE_LEVEL chosenFeatureLevel;
|
|
|
|
|
|
|
|
ID3D11Device* baseDevice;
|
|
|
|
ID3D11DeviceContext* baseDeviceContext;
|
|
|
|
|
|
|
|
HRESULT r = D3D11CreateDevice(
|
|
|
|
nullptr,
|
|
|
|
D3D_DRIVER_TYPE_HARDWARE,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
featureLevels,
|
2022-06-26 13:02:21 +00:00
|
|
|
std::size(featureLevels),
|
2022-03-27 23:07:11 +00:00
|
|
|
D3D11_SDK_VERSION,
|
|
|
|
&baseDevice,
|
|
|
|
&chosenFeatureLevel,
|
|
|
|
&baseDeviceContext);
|
|
|
|
|
|
|
|
if (r < 0) {
|
2022-08-07 21:10:46 +00:00
|
|
|
#if _WIN32
|
2022-03-27 23:07:11 +00:00
|
|
|
FreeLibrary(dxgi);
|
|
|
|
FreeLibrary(d3d11);
|
2022-08-07 21:10:46 +00:00
|
|
|
#endif
|
2022-03-27 23:07:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ID3D11Device_Release(baseDevice);
|
|
|
|
// ID3D11DeviceContext_Release(baseDeviceContext);
|
|
|
|
|
|
|
|
deviceManager = new PCDX11DeviceManager(dxgi, d3d11, baseDevice, baseDeviceContext);
|
|
|
|
return deviceManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|