-
Notifications
You must be signed in to change notification settings - Fork 1k
Add GLFW WSI for native builds #3111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0ce47e
Add GLFW WSI
Beyley 399ea21
Fix formatting
Beyley 29ac10f
Fix build and remove hack in vulkan_loader
Beyley c9e18cd
Add option to meson_options to change the DXVK native WSI
Beyley 7d85945
Fix formatting of pointer types
Beyley 893f24b
Remove unneeded GLFW window
Beyley db0f6e9
Fix formatting more
Beyley 118b2ec
Monitor mode bound checking and remove use of auto
Beyley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #include <windows.h> | ||
|
|
||
| #include <GLFW/glfw3.h> | ||
|
|
||
| namespace dxvk::wsi { | ||
|
|
||
| inline GLFWwindow* fromHwnd(HWND hWindow) { | ||
| return reinterpret_cast<GLFWwindow*>(hWindow); | ||
| } | ||
|
|
||
| inline HWND toHwnd(GLFWwindow* pWindow) { | ||
| return reinterpret_cast<HWND>(pWindow); | ||
| } | ||
|
|
||
| // Offset so null HMONITORs go to -1 | ||
| inline int32_t fromHmonitor(HMONITOR hMonitor) { | ||
| return static_cast<int32_t>(reinterpret_cast<intptr_t>(hMonitor)) - 1; | ||
| } | ||
|
|
||
| // Offset so -1 display id goes to 0 == NULL | ||
| inline HMONITOR toHmonitor(int32_t displayId) { | ||
| return reinterpret_cast<HMONITOR>(static_cast<intptr_t>(displayId + 1)); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #include "../dxvk_platform_exts.h" | ||
|
|
||
| #include "../../vulkan/vulkan_loader.h" | ||
| #include <GLFW/glfw3.h> | ||
|
|
||
| namespace dxvk { | ||
|
|
||
| DxvkPlatformExts DxvkPlatformExts::s_instance; | ||
|
|
||
| std::string_view DxvkPlatformExts::getName() { | ||
| return "GLFW WSI"; | ||
| } | ||
|
|
||
| DxvkNameSet DxvkPlatformExts::getInstanceExtensions() { | ||
| if (!glfwVulkanSupported()) | ||
| throw DxvkError(str::format("GLFW WSI: Vulkan is not supported in any capacity!")); | ||
|
|
||
| uint32_t extensionCount = 0; | ||
| const char** extensionArray = glfwGetRequiredInstanceExtensions(&extensionCount); | ||
|
|
||
| if (extensionCount == 0) | ||
| throw DxvkError(str::format("GLFW WSI: Failed to get required instance extensions")); | ||
|
|
||
| DxvkNameSet names; | ||
| for (uint32_t i = 0; i < extensionCount; ++i) { | ||
| names.add(extensionArray[i]); | ||
| } | ||
|
|
||
| return names; | ||
| } | ||
|
|
||
|
|
||
| DxvkNameSet DxvkPlatformExts::getDeviceExtensions( | ||
| uint32_t adapterId) { | ||
| return DxvkNameSet(); | ||
| } | ||
|
|
||
|
|
||
| void DxvkPlatformExts::initInstanceExtensions() { | ||
| //Nothing needs to be done here on GLFW | ||
| } | ||
|
|
||
|
|
||
| void DxvkPlatformExts::initDeviceExtensions( | ||
| const DxvkInstance* instance) { | ||
| //Nothing needs to be done here on GLFW | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #include "../wsi_monitor.h" | ||
|
|
||
| #include "wsi/native_wsi.h" | ||
| #include "wsi_platform_glfw.h" | ||
|
|
||
| #include "../../util/util_string.h" | ||
| #include "../../util/log/log.h" | ||
|
|
||
| #include <string> | ||
| #include <sstream> | ||
|
|
||
| namespace dxvk::wsi { | ||
|
|
||
| HMONITOR getDefaultMonitor() { | ||
| return enumMonitors(0); | ||
| } | ||
|
|
||
|
|
||
| HMONITOR enumMonitors(uint32_t index) { | ||
| return isDisplayValid(int32_t(index)) | ||
| ? toHmonitor(index) | ||
| : nullptr; | ||
| } | ||
|
|
||
| bool getDisplayName( | ||
| HMONITOR hMonitor, | ||
| WCHAR (&Name)[32]) { | ||
| const int32_t displayId = fromHmonitor(hMonitor); | ||
|
|
||
| if (!isDisplayValid(displayId)) | ||
| return false; | ||
|
|
||
| std::wstringstream nameStream; | ||
| nameStream << LR"(\\.\DISPLAY)" << (displayId + 1); | ||
|
|
||
| std::wstring name = nameStream.str(); | ||
|
|
||
| std::memset(Name, 0, sizeof(Name)); | ||
| name.copy(Name, name.length(), 0); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| bool getDesktopCoordinates( | ||
| HMONITOR hMonitor, | ||
| RECT* pRect) { | ||
| const int32_t displayId = fromHmonitor(hMonitor); | ||
|
|
||
| if (!isDisplayValid(displayId)) | ||
| return false; | ||
|
|
||
| int32_t displayCount = 0; | ||
| GLFWmonitor** monitors = glfwGetMonitors(&displayCount); | ||
| GLFWmonitor* monitor = monitors[displayId]; | ||
|
|
||
| int32_t x; | ||
| int32_t y; | ||
| int32_t w; | ||
| int32_t h; | ||
| glfwGetMonitorWorkarea(monitor, &x, &y, &w, &h); | ||
|
|
||
| pRect->left = x; | ||
| pRect->top = y; | ||
| pRect->right = x + w; | ||
| pRect->bottom = y + h; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| static inline uint32_t roundToNextPow2(uint32_t num) { | ||
| if (num-- == 0) | ||
| return 0; | ||
|
|
||
| num |= num >> 1; | ||
| num |= num >> 2; | ||
| num |= num >> 4; | ||
| num |= num >> 8; | ||
| num |= num >> 16; | ||
|
|
||
| return ++num; | ||
| } | ||
|
|
||
|
|
||
| static inline void convertMode(const GLFWvidmode& mode, WsiMode* pMode) { | ||
| pMode->width = uint32_t(mode.width); | ||
| pMode->height = uint32_t(mode.height); | ||
| pMode->refreshRate = WsiRational{uint32_t(mode.refreshRate) * 1000, 1000}; | ||
| // BPP should always be a power of two | ||
| // to match Windows behaviour of including padding. | ||
| pMode->bitsPerPixel = roundToNextPow2(mode.blueBits + mode.redBits + mode.greenBits); | ||
| pMode->interlaced = false; | ||
| } | ||
|
|
||
|
|
||
| bool getDisplayMode( | ||
| HMONITOR hMonitor, | ||
| uint32_t ModeNumber, | ||
| WsiMode* pMode) { | ||
| const int32_t displayId = fromHmonitor(hMonitor); | ||
| int32_t displayCount = 0; | ||
| GLFWmonitor** monitors = glfwGetMonitors(&displayCount); | ||
| GLFWmonitor* monitor = monitors[displayId]; | ||
|
|
||
| if (!isDisplayValid(displayId)) | ||
| return false; | ||
|
|
||
| int32_t count = 0; | ||
| const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); | ||
|
|
||
| if(ModeNumber >= uint32_t(count)) | ||
| return false; | ||
|
|
||
| convertMode(modes[ModeNumber], pMode); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| bool getCurrentDisplayMode( | ||
| HMONITOR hMonitor, | ||
| WsiMode* pMode) { | ||
| const int32_t displayId = fromHmonitor(hMonitor); | ||
|
|
||
| if (!isDisplayValid(displayId)) | ||
| return false; | ||
|
|
||
| int32_t displayCount = 0; | ||
| GLFWmonitor** monitors = glfwGetMonitors(&displayCount); | ||
| GLFWmonitor* monitor = monitors[displayId]; | ||
|
|
||
| const GLFWvidmode *mode = glfwGetVideoMode(monitor); | ||
|
|
||
| convertMode(*mode, pMode); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
|
|
||
| bool getDesktopDisplayMode( | ||
| HMONITOR hMonitor, | ||
| WsiMode* pMode) { | ||
| const int32_t displayId = fromHmonitor(hMonitor); | ||
|
|
||
| if (!isDisplayValid(displayId)) | ||
| return false; | ||
|
|
||
| int32_t displayCount = 0; | ||
| GLFWmonitor** monitors = glfwGetMonitors(&displayCount); | ||
| GLFWmonitor* monitor = monitors[displayId]; | ||
|
|
||
| //TODO: actually implement this properly, currently we just grab the current one | ||
| convertMode(*glfwGetVideoMode(monitor), pMode); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| std::vector<uint8_t> getMonitorEdid(HMONITOR hMonitor) { | ||
| Logger::err("getMonitorEdid not implemented on this platform."); | ||
| return {}; | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #pragma once | ||
|
|
||
| #include "../../vulkan/vulkan_loader.h" | ||
| #include <GLFW/glfw3.h> | ||
|
|
||
| #include "../wsi_monitor.h" | ||
|
|
||
| namespace dxvk::wsi { | ||
|
|
||
| /** | ||
| * \brief Impl-dependent state | ||
| */ | ||
| struct DxvkWindowState { | ||
| }; | ||
|
|
||
| inline bool isDisplayValid(int32_t displayId) { | ||
| int32_t displayCount = 0; | ||
| glfwGetMonitors(&displayCount); | ||
|
|
||
| return displayId < displayCount && displayId >= 0; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.