mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-14 22:29:15 +01:00
[dxgi] Removed SDL dependencies from DxgiSwapChain
This commit is contained in:
parent
34ed79dacc
commit
245ba75123
@ -37,15 +37,6 @@ namespace dxvk {
|
|||||||
m_stats.SyncQPCTime.QuadPart = 0;
|
m_stats.SyncQPCTime.QuadPart = 0;
|
||||||
m_stats.SyncGPUTime.QuadPart = 0;
|
m_stats.SyncGPUTime.QuadPart = 0;
|
||||||
|
|
||||||
// Create SDL window handle
|
|
||||||
m_window = SDL_CreateWindowFrom(m_desc.OutputWindow);
|
|
||||||
|
|
||||||
if (m_window == nullptr) {
|
|
||||||
throw DxvkError(str::format(
|
|
||||||
"DxgiSwapChain::DxgiSwapChain: Failed to create window:\n",
|
|
||||||
SDL_GetError()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust initial back buffer size. If zero, these
|
// Adjust initial back buffer size. If zero, these
|
||||||
// shall be set to the current window size.
|
// shall be set to the current window size.
|
||||||
VkExtent2D windowSize = this->getWindowSize();
|
VkExtent2D windowSize = this->getWindowSize();
|
||||||
@ -54,8 +45,8 @@ namespace dxvk {
|
|||||||
if (m_desc.BufferDesc.Height == 0) m_desc.BufferDesc.Height = windowSize.height;
|
if (m_desc.BufferDesc.Height == 0) m_desc.BufferDesc.Height = windowSize.height;
|
||||||
|
|
||||||
// Set initial window mode and fullscreen state
|
// Set initial window mode and fullscreen state
|
||||||
if (FAILED(this->SetFullscreenState(!pDesc->Windowed, nullptr)))
|
// if (FAILED(this->SetFullscreenState(!pDesc->Windowed, nullptr)))
|
||||||
throw DxvkError("DxgiSwapChain::DxgiSwapChain: Failed to set initial fullscreen state");
|
// throw DxvkError("DxgiSwapChain::DxgiSwapChain: Failed to set initial fullscreen state");
|
||||||
|
|
||||||
this->createPresenter();
|
this->createPresenter();
|
||||||
this->createBackBuffer();
|
this->createBackBuffer();
|
||||||
@ -105,18 +96,9 @@ namespace dxvk {
|
|||||||
if (ppOutput != nullptr)
|
if (ppOutput != nullptr)
|
||||||
return DXGI_ERROR_INVALID_CALL;
|
return DXGI_ERROR_INVALID_CALL;
|
||||||
|
|
||||||
// We can use the display index returned by SDL to query the
|
|
||||||
// containing output, since DxgiAdapter::EnumOutputs uses the
|
|
||||||
// same output IDs.
|
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
int32_t displayId = SDL_GetWindowDisplayIndex(m_window);
|
Logger::err("DxgiSwapChain::GetContainingOutput: Not implemented yet");
|
||||||
|
return E_NOTIMPL;
|
||||||
if (displayId < 0) {
|
|
||||||
Logger::err("DxgiSwapChain::GetContainingOutput: Failed to query window display index");
|
|
||||||
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_adapter->EnumOutputs(displayId, ppOutput);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -228,27 +210,38 @@ namespace dxvk {
|
|||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
// Applies to windowed mode
|
// Applies to windowed mode
|
||||||
SDL_SetWindowSize(m_window,
|
RECT newRect;
|
||||||
|
RECT oldRect;
|
||||||
|
|
||||||
|
::SetRect(&newRect, 0, 0,
|
||||||
pNewTargetParameters->Width,
|
pNewTargetParameters->Width,
|
||||||
pNewTargetParameters->Height);
|
pNewTargetParameters->Height);
|
||||||
|
::AdjustWindowRectEx(&newRect,
|
||||||
|
GetWindowLongW(m_desc.OutputWindow, GWL_STYLE), FALSE,
|
||||||
|
GetWindowLongW(m_desc.OutputWindow, GWL_EXSTYLE));
|
||||||
|
::SetRect(&newRect, 0, 0,
|
||||||
|
newRect.right - newRect.left,
|
||||||
|
newRect.bottom - newRect.top);
|
||||||
|
::GetWindowRect(m_desc.OutputWindow, &oldRect);
|
||||||
|
::OffsetRect(&newRect, oldRect.left, oldRect.top);
|
||||||
|
|
||||||
// Applies to fullscreen mode
|
// TODO implement fullscreen mode
|
||||||
SDL_DisplayMode displayMode;
|
|
||||||
displayMode.format = SDL_PIXELFORMAT_RGBA32;
|
|
||||||
displayMode.w = pNewTargetParameters->Width;
|
|
||||||
displayMode.h = pNewTargetParameters->Height;
|
|
||||||
displayMode.refresh_rate = pNewTargetParameters->RefreshRate.Numerator
|
|
||||||
/ pNewTargetParameters->RefreshRate.Denominator;
|
|
||||||
displayMode.driverdata = nullptr;
|
|
||||||
|
|
||||||
if (SDL_SetWindowDisplayMode(m_window, &displayMode)) {
|
::MoveWindow(m_desc.OutputWindow,
|
||||||
throw DxvkError(str::format(
|
newRect.left, newRect.top,
|
||||||
"DxgiSwapChain::ResizeTarget: Failed to set display mode:\n",
|
newRect.right - newRect.left,
|
||||||
SDL_GetError()));
|
newRect.bottom - newRect.top, TRUE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
m_presenter->recreateSwapchain(
|
||||||
|
m_desc.BufferDesc.Width,
|
||||||
|
m_desc.BufferDesc.Height,
|
||||||
|
m_desc.BufferDesc.Format);
|
||||||
|
return S_OK;
|
||||||
|
} catch (const DxvkError& e) {
|
||||||
|
Logger::err(e.message());
|
||||||
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
|
return DXGI_ERROR_DRIVER_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -257,46 +250,8 @@ namespace dxvk {
|
|||||||
IDXGIOutput* pTarget) {
|
IDXGIOutput* pTarget) {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
// Unconditionally reset the swap chain to windowed mode first.
|
Logger::err("DxgiSwapChain::SetFullscreenState: Not implemented yet");
|
||||||
// This required if the application wants to move the window to
|
return E_NOTIMPL;
|
||||||
// a different display while remaining in fullscreen mode.
|
|
||||||
if (SDL_SetWindowFullscreen(m_window, 0)) {
|
|
||||||
Logger::err(str::format(
|
|
||||||
"DxgiSwapChain::SetFullscreenState: Failed to set windowed mode:\n",
|
|
||||||
SDL_GetError()));
|
|
||||||
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_desc.Windowed = !Fullscreen;
|
|
||||||
|
|
||||||
if (Fullscreen) {
|
|
||||||
// If a target output is specified, we need to move the
|
|
||||||
// window to that output first while in windowed mode.
|
|
||||||
if (pTarget != nullptr) {
|
|
||||||
DXGI_OUTPUT_DESC outputDesc;
|
|
||||||
|
|
||||||
if (FAILED(pTarget->GetDesc(&outputDesc))) {
|
|
||||||
Logger::err("DxgiSwapChain::SetFullscreenState: Failed to query output properties");
|
|
||||||
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetWindowPosition(m_window,
|
|
||||||
outputDesc.DesktopCoordinates.left,
|
|
||||||
outputDesc.DesktopCoordinates.top);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that the window is located at the target location,
|
|
||||||
// SDL should fullscreen it on the requested display. We
|
|
||||||
// only use borderless fullscreen for now, may be changed.
|
|
||||||
if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
|
||||||
Logger::err(str::format(
|
|
||||||
"DxgiSwapChain::SetFullscreenState: Failed to set fullscreen mode:\n",
|
|
||||||
SDL_GetError()));
|
|
||||||
return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -325,6 +280,7 @@ namespace dxvk {
|
|||||||
DxvkImageCreateInfo imageInfo;
|
DxvkImageCreateInfo imageInfo;
|
||||||
imageInfo.type = VK_IMAGE_TYPE_2D;
|
imageInfo.type = VK_IMAGE_TYPE_2D;
|
||||||
imageInfo.format = bufferFormat.actual;
|
imageInfo.format = bufferFormat.actual;
|
||||||
|
imageInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||||
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
imageInfo.sampleCount = VK_SAMPLE_COUNT_1_BIT;
|
||||||
imageInfo.extent.width = m_desc.BufferDesc.Width;
|
imageInfo.extent.width = m_desc.BufferDesc.Width;
|
||||||
imageInfo.extent.height = m_desc.BufferDesc.Height;
|
imageInfo.extent.height = m_desc.BufferDesc.Height;
|
||||||
@ -388,15 +344,16 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
VkExtent2D DxgiSwapChain::getWindowSize() const {
|
VkExtent2D DxgiSwapChain::getWindowSize() const {
|
||||||
int winWidth = 0;
|
RECT rect;
|
||||||
int winHeight = 0;
|
|
||||||
|
|
||||||
SDL_GetWindowSize(m_window, &winWidth, &winHeight);
|
if (::GetClientRect(m_desc.OutputWindow, &rect)) {
|
||||||
|
VkExtent2D result;
|
||||||
|
result.width = rect.right - rect.left;
|
||||||
|
result.height = rect.bottom - rect.top;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
VkExtent2D result;
|
throw DxvkError("DxgiSwapChain::getWindowSize: Failed to get window rect");
|
||||||
result.width = winWidth;
|
|
||||||
result.height = winHeight;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,6 @@ namespace dxvk {
|
|||||||
DXGI_SWAP_CHAIN_DESC m_desc;
|
DXGI_SWAP_CHAIN_DESC m_desc;
|
||||||
DXGI_FRAME_STATISTICS m_stats;
|
DXGI_FRAME_STATISTICS m_stats;
|
||||||
|
|
||||||
SDL_Window* m_window = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkContext> m_context;
|
Rc<DxvkContext> m_context;
|
||||||
Rc<DxvkCommandList> m_commandList;
|
Rc<DxvkCommandList> m_commandList;
|
||||||
Rc<DxvkSurface> m_surface;
|
Rc<DxvkSurface> m_surface;
|
||||||
|
@ -54,6 +54,9 @@ public:
|
|||||||
if (FAILED(m_device->CreateRenderTargetView(m_buffer.ptr(), nullptr, &m_bufferView)))
|
if (FAILED(m_device->CreateRenderTargetView(m_buffer.ptr(), nullptr, &m_bufferView)))
|
||||||
throw DxvkError("Failed to create render target view");
|
throw DxvkError("Failed to create render target view");
|
||||||
|
|
||||||
|
if (FAILED(m_swapChain->ResizeTarget(&swapDesc.BufferDesc)))
|
||||||
|
throw DxvkError("Failed to resize window");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user