1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[dxgi] Change swap chain interface to better map to D3D12 needs

This commit is contained in:
Philip Rebohle 2022-10-07 17:38:40 +02:00
parent d7ac21b6c7
commit 69d7af42a4
4 changed files with 106 additions and 57 deletions

View File

@ -131,8 +131,9 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE D3D11SwapChain::ChangeProperties(
const DXGI_SWAP_CHAIN_DESC1* pDesc) {
const DXGI_SWAP_CHAIN_DESC1* pDesc,
const UINT* pNodeMasks,
IUnknown* const* ppPresentQueues) {
m_dirty |= m_desc.Format != pDesc->Format
|| m_desc.Width != pDesc->Width
|| m_desc.Height != pDesc->Height
@ -255,6 +256,34 @@ namespace dxvk {
}
UINT STDMETHODCALLTYPE D3D11SwapChain::CheckColorSpaceSupport(
DXGI_COLOR_SPACE_TYPE ColorSpace) {
UINT supportFlags = 0;
if (ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709)
supportFlags |= DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT;
return supportFlags;
}
HRESULT STDMETHODCALLTYPE D3D11SwapChain::SetColorSpace(
DXGI_COLOR_SPACE_TYPE ColorSpace) {
// Ignore, will only ever be sRGB
return S_OK;
}
HRESULT STDMETHODCALLTYPE D3D11SwapChain::SetHDRMetaData(
const DXGI_VK_HDR_METADATA* pMetaData) {
// For some reason this call always seems to succeed on Windows
if (pMetaData->Type == DXGI_HDR_METADATA_TYPE_HDR10)
Logger::warn("D3D11: HDR10 metadata not supported");
return S_OK;
}
HRESULT D3D11SwapChain::PresentImage(UINT SyncInterval) {
Com<ID3D11DeviceContext> deviceContext = nullptr;
m_parent->GetImmediateContext(&deviceContext);

View File

@ -52,7 +52,9 @@ namespace dxvk {
HANDLE STDMETHODCALLTYPE GetFrameLatencyEvent();
HRESULT STDMETHODCALLTYPE ChangeProperties(
const DXGI_SWAP_CHAIN_DESC1* pDesc);
const DXGI_SWAP_CHAIN_DESC1* pDesc,
const UINT* pNodeMasks,
IUnknown* const* ppPresentQueues);
HRESULT STDMETHODCALLTYPE SetPresentRegion(
const RECT* pRegion);
@ -69,6 +71,15 @@ namespace dxvk {
UINT PresentFlags,
const DXGI_PRESENT_PARAMETERS* pPresentParameters);
UINT STDMETHODCALLTYPE CheckColorSpaceSupport(
DXGI_COLOR_SPACE_TYPE ColorSpace);
HRESULT STDMETHODCALLTYPE SetColorSpace(
DXGI_COLOR_SPACE_TYPE ColorSpace);
HRESULT STDMETHODCALLTYPE SetHDRMetaData(
const DXGI_VK_HDR_METADATA* pMetaData);
private:
enum BindingIds : uint32_t {

View File

@ -30,6 +30,17 @@ struct DXGI_VK_MONITOR_DATA {
};
/**
* \brief HDR metadata struct
*/
struct DXGI_VK_HDR_METADATA {
DXGI_HDR_METADATA_TYPE Type;
union {
DXGI_HDR_METADATA_HDR10 HDR10;
};
};
/**
* \brief Private DXGI presenter
*
@ -37,7 +48,7 @@ struct DXGI_VK_MONITOR_DATA {
* chain implementation to remain API-agnostic,
* so that common code can stay in one class.
*/
MIDL_INTERFACE("104001a6-7f36-4957-b932-86ade9567d91")
MIDL_INTERFACE("e4a9059e-b569-46ab-8de7-501bd2bc7f7a")
IDXGIVkSwapChain : public IUnknown {
virtual HRESULT STDMETHODCALLTYPE GetDesc(
DXGI_SWAP_CHAIN_DESC1* pDesc) = 0;
@ -62,7 +73,9 @@ IDXGIVkSwapChain : public IUnknown {
virtual HANDLE STDMETHODCALLTYPE GetFrameLatencyEvent() = 0;
virtual HRESULT STDMETHODCALLTYPE ChangeProperties(
const DXGI_SWAP_CHAIN_DESC1* pDesc) = 0;
const DXGI_SWAP_CHAIN_DESC1* pDesc,
const UINT* pNodeMasks,
IUnknown* const* ppPresentQueues) = 0;
virtual HRESULT STDMETHODCALLTYPE SetPresentRegion(
const RECT* pRegion) = 0;
@ -78,6 +91,15 @@ IDXGIVkSwapChain : public IUnknown {
UINT SyncInterval,
UINT PresentFlags,
const DXGI_PRESENT_PARAMETERS* pPresentParameters) = 0;
virtual UINT STDMETHODCALLTYPE CheckColorSpaceSupport(
DXGI_COLOR_SPACE_TYPE ColorSpace) = 0;
virtual HRESULT STDMETHODCALLTYPE SetColorSpace(
DXGI_COLOR_SPACE_TYPE ColorSpace) = 0;
virtual HRESULT STDMETHODCALLTYPE SetHDRMetaData(
const DXGI_VK_HDR_METADATA* pMetaData) = 0;
};
@ -374,7 +396,7 @@ struct __declspec(uuid("3a6d8f2c-b0e8-4ab4-b4dc-4fd24891bfa5")) IDXGIVkInteropAd
struct __declspec(uuid("e2ef5fa5-dc21-4af7-90c4-f67ef6a09323")) IDXGIVkInteropDevice;
struct __declspec(uuid("e2ef5fa5-dc21-4af7-90c4-f67ef6a09324")) IDXGIVkInteropDevice1;
struct __declspec(uuid("5546cf8c-77e7-4341-b05d-8d4d5000e77d")) IDXGIVkInteropSurface;
struct __declspec(uuid("104001a6-7f36-4957-b932-86ade9567d91")) IDXGIVkSwapChain;
struct __declspec(uuid("e4a9059e-b569-46ab-8de7-501bd2bc7f7a")) IDXGIVkSwapChain;
struct __declspec(uuid("e7d6c3ca-23a0-4e08-9f2f-ea5231df6633")) IDXGIVkSwapChainFactory;
struct __declspec(uuid("53cb4ff0-c25a-4164-a891-0e83db0a7aac")) IWineDXGISwapChainFactory;
#else
@ -385,7 +407,7 @@ __CRT_UUID_DECL(IDXGIVkInteropAdapter, 0x3a6d8f2c,0xb0e8,0x4ab4,0xb4,0xdc,0x
__CRT_UUID_DECL(IDXGIVkInteropDevice, 0xe2ef5fa5,0xdc21,0x4af7,0x90,0xc4,0xf6,0x7e,0xf6,0xa0,0x93,0x23);
__CRT_UUID_DECL(IDXGIVkInteropDevice1, 0xe2ef5fa5,0xdc21,0x4af7,0x90,0xc4,0xf6,0x7e,0xf6,0xa0,0x93,0x24);
__CRT_UUID_DECL(IDXGIVkInteropSurface, 0x5546cf8c,0x77e7,0x4341,0xb0,0x5d,0x8d,0x4d,0x50,0x00,0xe7,0x7d);
__CRT_UUID_DECL(IDXGIVkSwapChain, 0x104001a6,0x7f36,0x4957,0xb9,0x32,0x86,0xad,0xe9,0x56,0x7d,0x91);
__CRT_UUID_DECL(IDXGIVkSwapChain, 0xe4a9059e,0xb569,0x46ab,0x8d,0xe7,0x50,0x1b,0xd2,0xbc,0x7f,0x7a);
__CRT_UUID_DECL(IDXGIVkSwapChainFactory, 0xe7d6c3ca,0x23a0,0x4e08,0x9f,0x2f,0xea,0x52,0x31,0xdf,0x66,0x33);
__CRT_UUID_DECL(IWineDXGISwapChainFactory, 0x53cb4ff0,0xc25a,0x4164,0xa8,0x91,0x0e,0x83,0xdb,0x0a,0x7a,0xac);
#endif

View File

@ -319,11 +319,24 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE DxgiSwapChain::ResizeBuffers(
UINT BufferCount,
UINT Width,
UINT Height,
DXGI_FORMAT NewFormat,
UINT SwapChainFlags) {
UINT BufferCount,
UINT Width,
UINT Height,
DXGI_FORMAT NewFormat,
UINT SwapChainFlags) {
return ResizeBuffers1(BufferCount, Width, Height,
NewFormat, SwapChainFlags, nullptr, nullptr);
}
HRESULT STDMETHODCALLTYPE DxgiSwapChain::ResizeBuffers1(
UINT BufferCount,
UINT Width,
UINT Height,
DXGI_FORMAT Format,
UINT SwapChainFlags,
const UINT* pCreationNodeMask,
IUnknown* const* ppPresentQueue) {
if (!wsi::isWindow(m_window))
return DXGI_ERROR_INVALID_CALL;
@ -343,28 +356,10 @@ namespace dxvk {
if (BufferCount != 0)
m_desc.BufferCount = BufferCount;
if (NewFormat != DXGI_FORMAT_UNKNOWN)
m_desc.Format = NewFormat;
if (Format != DXGI_FORMAT_UNKNOWN)
m_desc.Format = Format;
return m_presenter->ChangeProperties(&m_desc);
}
HRESULT STDMETHODCALLTYPE DxgiSwapChain::ResizeBuffers1(
UINT BufferCount,
UINT Width,
UINT Height,
DXGI_FORMAT Format,
UINT SwapChainFlags,
const UINT* pCreationNodeMask,
IUnknown* const* ppPresentQueue) {
static bool s_errorShown = false;
if (!std::exchange(s_errorShown, true))
Logger::warn("DxgiSwapChain::ResizeBuffers1: Stub");
return ResizeBuffers(BufferCount,
Width, Height, Format, SwapChainFlags);
return m_presenter->ChangeProperties(&m_desc, pCreationNodeMask, ppPresentQueue);
}
@ -515,11 +510,9 @@ namespace dxvk {
|| Height == 0 || Height > m_desc.Height)
return E_INVALIDARG;
RECT region;
region.left = 0;
region.top = 0;
region.right = Width;
region.bottom = Height;
std::lock_guard<dxvk::mutex> lock(m_lockBuffer);
RECT region = { 0, 0, LONG(Width), LONG(Height) };
return m_presenter->SetPresentRegion(&region);
}
@ -529,29 +522,19 @@ namespace dxvk {
UINT* pColorSpaceSupport) {
if (!pColorSpaceSupport)
return E_INVALIDARG;
UINT supportFlags = 0;
if (ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709)
supportFlags |= DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT;
*pColorSpaceSupport = supportFlags;
return S_OK;
return m_presenter->CheckColorSpaceSupport(ColorSpace);
}
HRESULT STDMETHODCALLTYPE DxgiSwapChain::SetColorSpace1(DXGI_COLOR_SPACE_TYPE ColorSpace) {
UINT support = 0;
HRESULT hr = CheckColorSpaceSupport(ColorSpace, &support);
if (FAILED(hr))
return hr;
UINT support = m_presenter->CheckColorSpaceSupport(ColorSpace);
if (!support)
return E_INVALIDARG;
return S_OK;
std::lock_guard<dxvk::mutex> lock(m_lockBuffer);
return m_presenter->SetColorSpace(ColorSpace);
}
@ -562,22 +545,26 @@ namespace dxvk {
if (Size && !pMetaData)
return E_INVALIDARG;
DXGI_VK_HDR_METADATA metadata = { Type };
switch (Type) {
case DXGI_HDR_METADATA_TYPE_NONE:
return S_OK;
break;
case DXGI_HDR_METADATA_TYPE_HDR10:
if (Size != sizeof(DXGI_HDR_METADATA_HDR10))
return E_INVALIDARG;
// For some reason this always seems to succeed on Windows
Logger::warn("DXGI: HDR not supported");
return S_OK;
metadata.HDR10 = *static_cast<const DXGI_HDR_METADATA_HDR10*>(pMetaData);
break;
default:
Logger::err(str::format("DXGI: Invalid HDR metadata type: ", Type));
Logger::err(str::format("DXGI: Unsupported HDR metadata type: ", Type));
return E_INVALIDARG;
}
std::lock_guard<dxvk::mutex> lock(m_lockBuffer);
return m_presenter->SetHDRMetaData(&metadata);
}