win-capture/graphics-hook: Fix D3D10/D3D11 detection
When hooking DXGI-based graphics programs in the hook, the first hook point is IDXGISwapChain::Present. To be able to initiate a capture, a pointer to the device context that created the swap chain is required, which can be retrieved via IDXGISwapChain::GetDevice. Determining whether the device context was D3D10 or D3D11 has always been somewhat of an issue due to D3D10 and D3D11 being nearly identical, as well as their interoperability/interchangeability. The GetDevice function would first be called with the UUID of ID3D10Device, then if that failed, the UUID of ID3D11Device. However, with certain specific D3D11 games, GetDevice would for some unknown reason succeed with the UUID of ID3D10Device, which would cause capture to fail. (Conversely, attempting to call GetDevice with the UUID of ID3D11Device on a device that's actually ID3D10Device would always succeed, so reversing the order of the test was not an option). There were originally three known D3D11 games that would erroneously succeed when querying a D3D10 device interface: Call of Duty: Ghosts, Just Cause 3, and theHunter: Call of the Wild. All other known D3D11 games would work correctly. Because it was only these three games, a hack was originally implemented in the form of an executable exception list that would force them to capture D3D11. Unfortunately, Oculus games are now failing under the same circumstance as well, so a simple hack will no longer work. To fix this, a more reliable method of detecting which context it is had to be discovered: simply check the feature level using ID3D11Device::GetFeatureLevel. If the feature level is D3D_FEATURE_LEVEL_11_0 or D3D_FEATURE_LEVEL_11_1, the device is definitely a D3D11 device. Otherwise, continue the tests as they were before. Successfully tested with many D3D10 games, many D3D11 games, and especially those three D3D11 games that previously were detected as D3D10 erroneously.
This commit is contained in:
parent
054148a0af
commit
c4036b18bb
@ -28,32 +28,32 @@ static struct dxgi_swap_data data = {};
|
||||
|
||||
static bool setup_dxgi(IDXGISwapChain *swap)
|
||||
{
|
||||
const char *process_name = get_process_name();
|
||||
bool ignore_d3d10 = false;
|
||||
IUnknown *device;
|
||||
HRESULT hr;
|
||||
|
||||
/* Call of duty ghosts allows the context to be queried as a d3d10
|
||||
* context when it's actually a d3d11 context. Why this is I don't
|
||||
* quite know. */
|
||||
if (_strcmpi(process_name, "iw6sp64_ship.exe") == 0 ||
|
||||
_strcmpi(process_name, "iw6mp64_ship.exe") == 0 ||
|
||||
_strcmpi(process_name, "justcause3.exe") == 0 ||
|
||||
_strcmpi(process_name, "theHunterCotW_F.exe") == 0) {
|
||||
ignore_d3d10 = true;
|
||||
}
|
||||
hr = swap->GetDevice(__uuidof(ID3D11Device), (void**)&device);
|
||||
if (SUCCEEDED(hr)) {
|
||||
ID3D11Device *d3d11 = reinterpret_cast<ID3D11Device*>(device);
|
||||
D3D_FEATURE_LEVEL level = d3d11->GetFeatureLevel();
|
||||
device->Release();
|
||||
|
||||
if (!ignore_d3d10) {
|
||||
hr = swap->GetDevice(__uuidof(ID3D10Device), (void**)&device);
|
||||
if (SUCCEEDED(hr)) {
|
||||
if (level >= D3D_FEATURE_LEVEL_11_0) {
|
||||
data.swap = swap;
|
||||
data.capture = d3d10_capture;
|
||||
data.free = d3d10_free;
|
||||
device->Release();
|
||||
data.capture = d3d11_capture;
|
||||
data.free = d3d11_free;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
hr = swap->GetDevice(__uuidof(ID3D10Device), (void**)&device);
|
||||
if (SUCCEEDED(hr)) {
|
||||
data.swap = swap;
|
||||
data.capture = d3d10_capture;
|
||||
data.free = d3d10_free;
|
||||
device->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
hr = swap->GetDevice(__uuidof(ID3D11Device), (void**)&device);
|
||||
if (SUCCEEDED(hr)) {
|
||||
data.swap = swap;
|
||||
|
Loading…
x
Reference in New Issue
Block a user