2017-10-11 03:09:04 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "dxgi_adapter.h"
|
|
|
|
#include "dxgi_output.h"
|
2018-04-10 22:07:25 +02:00
|
|
|
#include "dxgi_swapchain.h"
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
#include "../dxvk/dxvk_format.h"
|
|
|
|
|
2017-10-11 03:09:04 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
DxgiOutput::DxgiOutput(
|
2018-04-12 01:51:28 +02:00
|
|
|
const Com<DxgiAdapter>& adapter,
|
2018-01-13 16:32:46 +01:00
|
|
|
HMONITOR monitor)
|
|
|
|
: m_adapter(adapter),
|
|
|
|
m_monitor(monitor) {
|
2018-04-12 13:38:22 +02:00
|
|
|
// Init output data if necessary
|
|
|
|
if (FAILED(m_adapter->GetOutputData(m_monitor, nullptr))) {
|
|
|
|
DXGI_VK_OUTPUT_DATA outputData;
|
|
|
|
outputData.FrameStats = DXGI_FRAME_STATISTICS();
|
|
|
|
outputData.GammaCurve.Scale = { 1.0f, 1.0f, 1.0f };
|
|
|
|
outputData.GammaCurve.Offset = { 0.0f, 0.0f, 0.0f };
|
|
|
|
|
2018-04-13 13:47:15 +02:00
|
|
|
for (uint32_t i = 0; i < DXGI_VK_GAMMA_CP_COUNT; i++) {
|
|
|
|
const float value = GammaControlPointLocation(i);
|
2018-04-12 13:38:22 +02:00
|
|
|
outputData.GammaCurve.GammaCurve[i] = { value, value, value };
|
|
|
|
}
|
|
|
|
|
|
|
|
outputData.GammaDirty = FALSE;
|
|
|
|
m_adapter->SetOutputData(m_monitor, &outputData);
|
|
|
|
}
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxgiOutput::~DxgiOutput() {
|
2017-11-26 14:01:41 +01:00
|
|
|
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::QueryInterface(REFIID riid, void** ppvObject) {
|
2018-04-02 12:52:02 +02:00
|
|
|
*ppvObject = nullptr;
|
|
|
|
|
|
|
|
if (riid == __uuidof(IUnknown)
|
|
|
|
|| riid == __uuidof(IDXGIObject)
|
|
|
|
|| riid == __uuidof(IDXGIOutput)) {
|
|
|
|
*ppvObject = ref(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2017-10-11 03:09:04 +02:00
|
|
|
|
|
|
|
Logger::warn("DxgiOutput::QueryInterface: Unknown interface query");
|
2018-03-12 12:05:43 +01:00
|
|
|
Logger::warn(str::format(riid));
|
2017-10-11 03:09:04 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-28 11:56:58 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetParent(REFIID riid, void **ppParent) {
|
2017-10-11 03:09:04 +02:00
|
|
|
return m_adapter->QueryInterface(riid, ppParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::FindClosestMatchingMode(
|
2017-10-11 03:09:04 +02:00
|
|
|
const DXGI_MODE_DESC *pModeToMatch,
|
|
|
|
DXGI_MODE_DESC *pClosestMatch,
|
|
|
|
IUnknown *pConcernedDevice) {
|
2018-04-14 12:02:55 +02:00
|
|
|
if (pModeToMatch == nullptr || pClosestMatch == nullptr)
|
2018-03-12 08:52:32 +01:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
2018-04-14 12:02:55 +02:00
|
|
|
if (pModeToMatch->Format == DXGI_FORMAT_UNKNOWN && pConcernedDevice == nullptr)
|
2018-03-12 08:52:32 +01:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2018-03-24 11:31:39 +01:00
|
|
|
|
|
|
|
// If no format was specified, fall back to a standard
|
|
|
|
// SRGB format, which is supported on all devices.
|
2018-03-24 13:42:23 +01:00
|
|
|
DXGI_FORMAT targetFormat = pModeToMatch->Format;
|
2018-03-24 11:31:39 +01:00
|
|
|
|
2018-03-24 13:42:23 +01:00
|
|
|
if (targetFormat == DXGI_FORMAT_UNKNOWN)
|
|
|
|
targetFormat = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
|
|
|
|
|
|
|
UINT targetRefreshRate = 0;
|
|
|
|
|
|
|
|
if (pModeToMatch->RefreshRate.Denominator != 0
|
|
|
|
&& pModeToMatch->RefreshRate.Numerator != 0) {
|
|
|
|
targetRefreshRate = pModeToMatch->RefreshRate.Numerator
|
|
|
|
/ pModeToMatch->RefreshRate.Denominator;
|
|
|
|
}
|
2018-03-24 11:31:39 +01:00
|
|
|
|
|
|
|
// List all supported modes and filter
|
|
|
|
// out those we don't actually need
|
|
|
|
UINT modeCount = 0;
|
2018-03-24 13:42:23 +01:00
|
|
|
GetDisplayModeList(targetFormat, DXGI_ENUM_MODES_SCALING, &modeCount, nullptr);
|
2018-03-24 11:31:39 +01:00
|
|
|
|
|
|
|
if (modeCount == 0) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: FindClosestMatchingMode: No modes found");
|
2018-03-12 08:52:32 +01:00
|
|
|
return DXGI_ERROR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2018-03-24 11:31:39 +01:00
|
|
|
std::vector<DXGI_MODE_DESC> modes(modeCount);
|
2018-03-24 13:42:23 +01:00
|
|
|
GetDisplayModeList(targetFormat, DXGI_ENUM_MODES_SCALING, &modeCount, modes.data());
|
|
|
|
|
|
|
|
for (auto it = modes.begin(); it != modes.end(); ) {
|
|
|
|
bool skipMode = false;
|
2018-03-24 11:31:39 +01:00
|
|
|
|
2018-03-24 13:42:23 +01:00
|
|
|
// Remove modes with a different refresh rate
|
|
|
|
if (targetRefreshRate != 0) {
|
2018-03-24 11:31:39 +01:00
|
|
|
UINT modeRefreshRate = it->RefreshRate.Numerator
|
|
|
|
/ it->RefreshRate.Denominator;
|
2018-03-24 13:42:23 +01:00
|
|
|
skipMode |= modeRefreshRate != targetRefreshRate;
|
2018-03-12 08:52:32 +01:00
|
|
|
}
|
2018-03-24 13:42:23 +01:00
|
|
|
|
|
|
|
// Remove modes with incorrect scaling
|
|
|
|
if (pModeToMatch->Scaling != DXGI_MODE_SCALING_UNSPECIFIED)
|
|
|
|
skipMode |= it->Scaling != pModeToMatch->Scaling;
|
|
|
|
|
|
|
|
it = skipMode ? modes.erase(it) : ++it;
|
2018-03-12 08:52:32 +01:00
|
|
|
}
|
2018-03-24 11:31:39 +01:00
|
|
|
|
|
|
|
// No matching modes found
|
|
|
|
if (modes.size() == 0)
|
2018-03-12 08:52:32 +01:00
|
|
|
return DXGI_ERROR_NOT_FOUND;
|
|
|
|
|
2018-03-24 11:31:39 +01:00
|
|
|
// Select mode with minimal height+width difference
|
2018-04-02 18:49:19 +02:00
|
|
|
UINT minDifference = std::numeric_limits<unsigned int>::max();
|
2018-03-24 13:42:23 +01:00
|
|
|
|
2018-03-12 08:52:32 +01:00
|
|
|
for (auto& mode : modes) {
|
2018-03-24 13:42:23 +01:00
|
|
|
UINT currDifference = std::abs(int(pModeToMatch->Width - mode.Width))
|
|
|
|
+ std::abs(int(pModeToMatch->Height - mode.Height));
|
2018-03-12 08:52:32 +01:00
|
|
|
|
|
|
|
if (currDifference < minDifference) {
|
|
|
|
minDifference = currDifference;
|
|
|
|
*pClosestMatch = mode;
|
|
|
|
}
|
|
|
|
}
|
2018-03-24 11:31:39 +01:00
|
|
|
|
2018-03-12 08:52:32 +01:00
|
|
|
return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetDesc(DXGI_OUTPUT_DESC *pDesc) {
|
2017-10-11 03:09:04 +02:00
|
|
|
if (pDesc == nullptr)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
2018-04-12 20:12:48 +02:00
|
|
|
::MONITORINFOEXW monInfo;
|
2018-01-18 23:59:40 +01:00
|
|
|
monInfo.cbSize = sizeof(monInfo);
|
2018-03-24 13:42:23 +01:00
|
|
|
|
2018-04-12 20:12:48 +02:00
|
|
|
if (!::GetMonitorInfoW(m_monitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to query monitor info");
|
2018-01-13 16:32:46 +01:00
|
|
|
return E_FAIL;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-12 20:12:48 +02:00
|
|
|
std::memcpy(pDesc->DeviceName, monInfo.szDevice, std::size(pDesc->DeviceName));
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
pDesc->DesktopCoordinates = monInfo.rcMonitor;
|
2017-10-11 03:09:04 +02:00
|
|
|
pDesc->AttachedToDesktop = 1;
|
|
|
|
pDesc->Rotation = DXGI_MODE_ROTATION_UNSPECIFIED;
|
2018-01-13 16:32:46 +01:00
|
|
|
pDesc->Monitor = m_monitor;
|
2017-10-11 03:09:04 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetDisplayModeList(
|
2017-10-11 03:09:04 +02:00
|
|
|
DXGI_FORMAT EnumFormat,
|
|
|
|
UINT Flags,
|
|
|
|
UINT *pNumModes,
|
|
|
|
DXGI_MODE_DESC *pDesc) {
|
|
|
|
if (pNumModes == nullptr)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
// Query monitor info to get the device name
|
2018-04-12 20:12:48 +02:00
|
|
|
::MONITORINFOEXW monInfo;
|
2018-01-18 23:59:40 +01:00
|
|
|
monInfo.cbSize = sizeof(monInfo);
|
2018-03-24 13:42:23 +01:00
|
|
|
|
2018-04-12 20:12:48 +02:00
|
|
|
if (!::GetMonitorInfoW(m_monitor, reinterpret_cast<MONITORINFO*>(&monInfo))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to query monitor info");
|
2018-01-13 16:32:46 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
// Walk over all modes that the display supports and
|
|
|
|
// return those that match the requested format etc.
|
2018-04-12 20:12:48 +02:00
|
|
|
DEVMODEW devMode;
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
uint32_t srcModeId = 0;
|
|
|
|
uint32_t dstModeId = 0;
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-03-24 13:42:23 +01:00
|
|
|
const bool includeStretchedModes = (Flags & DXGI_ENUM_MODES_SCALING);
|
|
|
|
|
2018-04-12 20:12:48 +02:00
|
|
|
while (::EnumDisplaySettingsW(monInfo.szDevice, srcModeId++, &devMode)) {
|
2018-01-13 16:32:46 +01:00
|
|
|
// Skip interlaced modes altogether
|
|
|
|
if (devMode.dmDisplayFlags & DM_INTERLACED)
|
|
|
|
continue;
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
// Skip modes with incompatible formats
|
|
|
|
if (devMode.dmBitsPerPel != GetFormatBpp(EnumFormat))
|
|
|
|
continue;
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2018-03-24 13:42:23 +01:00
|
|
|
// Skip stretched modes unless they are requested
|
|
|
|
const bool isStretched = devMode.dmPelsWidth != UINT(monInfo.rcMonitor.right - monInfo.rcMonitor.left)
|
|
|
|
|| devMode.dmPelsHeight != UINT(monInfo.rcMonitor.bottom - monInfo.rcMonitor.top);
|
|
|
|
|
|
|
|
if (isStretched && !includeStretchedModes)
|
|
|
|
continue;
|
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
// Write back display mode
|
|
|
|
if (pDesc != nullptr) {
|
|
|
|
if (dstModeId >= *pNumModes)
|
|
|
|
return DXGI_ERROR_MORE_DATA;
|
2017-10-11 03:09:04 +02:00
|
|
|
|
2017-12-31 00:23:34 +01:00
|
|
|
DXGI_MODE_DESC mode;
|
2018-01-13 16:32:46 +01:00
|
|
|
mode.Width = devMode.dmPelsWidth;
|
|
|
|
mode.Height = devMode.dmPelsHeight;
|
|
|
|
mode.RefreshRate = { devMode.dmDisplayFrequency, 1 };
|
|
|
|
mode.Format = EnumFormat;
|
|
|
|
mode.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
|
2018-03-24 13:42:23 +01:00
|
|
|
mode.Scaling = isStretched
|
|
|
|
? DXGI_MODE_SCALING_STRETCHED
|
|
|
|
: DXGI_MODE_SCALING_CENTERED;
|
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
pDesc[dstModeId] = mode;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
2018-01-13 16:32:46 +01:00
|
|
|
|
|
|
|
dstModeId += 1;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
*pNumModes = dstModeId;
|
|
|
|
return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetDisplaySurfaceData(IDXGISurface* pDestination) {
|
2017-10-11 03:09:04 +02:00
|
|
|
Logger::err("DxgiOutput::GetDisplaySurfaceData: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetFrameStatistics(DXGI_FRAME_STATISTICS* pStats) {
|
|
|
|
DXGI_VK_OUTPUT_DATA outputData;
|
|
|
|
|
|
|
|
if (FAILED(m_adapter->GetOutputData(m_monitor, &outputData))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to query output data");
|
2018-04-12 13:38:22 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pStats = outputData.FrameStats;
|
|
|
|
return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetGammaControl(DXGI_GAMMA_CONTROL* pArray) {
|
|
|
|
DXGI_VK_OUTPUT_DATA outputData;
|
|
|
|
|
|
|
|
if (FAILED(m_adapter->GetOutputData(m_monitor, &outputData))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to query output data");
|
2018-04-12 13:38:22 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pArray = outputData.GammaCurve;
|
|
|
|
return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::GetGammaControlCapabilities(DXGI_GAMMA_CONTROL_CAPABILITIES* pGammaCaps) {
|
2018-04-10 22:07:25 +02:00
|
|
|
pGammaCaps->ScaleAndOffsetSupported = TRUE;
|
|
|
|
pGammaCaps->MaxConvertedValue = 1.0f;
|
|
|
|
pGammaCaps->MinConvertedValue = 0.0f;
|
2018-04-13 13:47:15 +02:00
|
|
|
pGammaCaps->NumGammaControlPoints = DXGI_VK_GAMMA_CP_COUNT;
|
2018-04-10 22:07:25 +02:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < pGammaCaps->NumGammaControlPoints; i++)
|
2018-04-13 13:47:15 +02:00
|
|
|
pGammaCaps->ControlPointPositions[i] = GammaControlPointLocation(i);
|
2018-04-10 22:07:25 +02:00
|
|
|
return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
void STDMETHODCALLTYPE DxgiOutput::ReleaseOwnership() {
|
2017-10-11 03:09:04 +02:00
|
|
|
Logger::warn("DxgiOutput::ReleaseOwnership: Stub");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::SetDisplaySurface(IDXGISurface* pScanoutSurface) {
|
2017-10-11 03:09:04 +02:00
|
|
|
Logger::err("DxgiOutput::SetDisplaySurface: Not implemented");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-12 13:38:22 +02:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::SetGammaControl(const DXGI_GAMMA_CONTROL* pArray) {
|
|
|
|
DXGI_VK_OUTPUT_DATA outputData;
|
|
|
|
|
|
|
|
if (FAILED(m_adapter->GetOutputData(m_monitor, &outputData))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to query output data");
|
2018-04-12 13:38:22 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
outputData.GammaCurve = *pArray;
|
|
|
|
outputData.GammaDirty = TRUE;
|
|
|
|
|
|
|
|
if (FAILED(m_adapter->SetOutputData(m_monitor, &outputData))) {
|
2018-04-14 12:02:55 +02:00
|
|
|
Logger::err("DXGI: Failed to update output data");
|
2018-04-12 13:38:22 +02:00
|
|
|
return E_FAIL;
|
|
|
|
} return S_OK;
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::TakeOwnership(
|
2017-10-11 03:09:04 +02:00
|
|
|
IUnknown *pDevice,
|
|
|
|
BOOL Exclusive) {
|
|
|
|
Logger::warn("DxgiOutput::TakeOwnership: Stub");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-12 12:50:52 +01:00
|
|
|
HRESULT STDMETHODCALLTYPE DxgiOutput::WaitForVBlank() {
|
2017-10-11 03:09:04 +02:00
|
|
|
Logger::warn("DxgiOutput::WaitForVBlank: Stub");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-13 16:32:46 +01:00
|
|
|
|
|
|
|
uint32_t DxgiOutput::GetFormatBpp(DXGI_FORMAT Format) const {
|
2018-04-12 17:49:14 +02:00
|
|
|
DXGI_VK_FORMAT_INFO formatInfo = m_adapter->LookupFormat(Format, DXGI_VK_FORMAT_MODE_ANY);
|
|
|
|
return imageFormatInfo(formatInfo.Format)->elementSize * 8;
|
2018-01-13 16:32:46 +01:00
|
|
|
}
|
|
|
|
|
2017-10-11 03:09:04 +02:00
|
|
|
}
|