Skip to content

Commit

Permalink
[Release] added swapchain scaling (#210)
Browse files Browse the repository at this point in the history
* added swapchain scaling

* wayland

* removed surface maintenace

* Restyled added swapchain scaling (#211)

* Restyled by astyle

* Restyled by clang-format

* Restyled by prettier-markdown

---------

Co-authored-by: Restyled.io <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people committed Jan 30, 2025
1 parent a7986bf commit adedf37
Show file tree
Hide file tree
Showing 30 changed files with 960 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

cmake_minimum_required(VERSION 3.22)

set(WISDOM_VERSION "0.6.2")
set(WISDOM_VERSION "0.6.3")
project("Wisdom" VERSION ${WISDOM_VERSION})

set(CMAKE_DEBUG_POSTFIX d)
Expand Down
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Version History

- 0.6.3 Swapchain extension

- Added support for VK_EXT_swapchain_maintenance1 extension
- Added scaling to the swapchain creation. Default is 1:1

- 0.6.1 - 0.6.2 Nuget package update

- Fixed Vulkan headers in the Nuget package
Expand All @@ -11,7 +16,7 @@
- Added Raytracing support for DXR and VK_KHR_ray_tracing
- Added compute pipeline and compute functions to the device and command list
- Added more bindings to the Descriptor storage

- 0.5.0 API stabilization

- Most of the API is now stable and will not change
Expand Down
16 changes: 15 additions & 1 deletion bindings/wisdom.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/** \mainpage Wisdom API Documentation
<b>Version 0.5.0</b>
<b>Version 0.6.2</b>
Copyright (c) 2024 Ilya Doroshenko. All rights reserved.
License: MIT
Expand Down Expand Up @@ -817,6 +817,18 @@ enum WisSampleRate {
SampleRateS16 = 16, ///< 16 samples per pixel.
};

/**
* @brief Swapchain scaling mode.
*
* Translates to VkPresentScalingFlagsEXT for vk implementation.
* Translates to DXGI_SCALING for dx implementation.
* */
enum WisSwapchainScaling {
SwapchainScalingNone = 0, ///< No scaling. The swapchain size is equal to the window size.
SwapchainScalingStretch = 1, ///< Stretch scaling. The swapchain size is stretched to the window size.
SwapchainScalingAspect = 2, ///< Aspect scaling. The swapchain size is scaled to the window size with aspect ratio preserved.
};

/**
* @brief Comparison function for depth and stencil operations.
*
Expand Down Expand Up @@ -1514,6 +1526,7 @@ typedef enum WisFillMode WisFillMode;
typedef enum WisDescriptorMemory WisDescriptorMemory;
typedef enum WisWindingOrder WisWindingOrder;
typedef enum WisSampleRate WisSampleRate;
typedef enum WisSwapchainScaling WisSwapchainScaling;
typedef enum WisCompare WisCompare;
typedef enum WisStencilOp WisStencilOp;
typedef enum WisBlendFactor WisBlendFactor;
Expand Down Expand Up @@ -1754,6 +1767,7 @@ struct WisSwapchainDesc {
bool stereo; ///< Stereo mode enable. If there is no stereo in the system will be ignored.
bool vsync; ///< VSync enable. Specifies Initial VSync. This value may be changed on per-present bases with DeviceFeatureDynamicVSync.
bool tearing; ///< Tearing enable. If VSync is disabled, Tearing may be enabled. If System does not allow tearing the flag is ignored.
WisSwapchainScaling scaling; ///< Swapchain scaling mode.
};

/**
Expand Down
54 changes: 51 additions & 3 deletions examples/common/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ wis::SwapChain ex::Window::CreateSwapchain(wis::Result& result, ex::ExampleSetup
HWND hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
if (hwnd) {
return static_cast<wis::platform::WindowsExtension*>(_platform.get())
->CreateSwapchain(result, setup.device, setup.queue, &desc, hwnd);
->CreateSwapchain(result, setup.device, setup.queue, desc, hwnd);
}
} break;
#elif defined(SDL_PLATFORM_LINUX)
Expand All @@ -74,15 +74,63 @@ wis::SwapChain ex::Window::CreateSwapchain(wis::Result& result, ex::ExampleSetup
::Window xwindow = (::Window)SDL_GetNumberProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
if (xdisplay && xwindow) {
return static_cast<wis::platform::X11Extension*>(_platform.get())
->CreateSwapchain(result, setup.device, setup.queue, &desc, xdisplay, xwindow);
->CreateSwapchain(result, setup.device, setup.queue, desc, xdisplay, xwindow);
}
} break;
case Wayland: {
struct wl_display* display = (struct wl_display*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
struct wl_surface* surface = (struct wl_surface*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
if (display && surface) {
return static_cast<wis::platform::WaylandExtension*>(_platform.get())
->CreateSwapchain(result, setup.device, setup.queue, &desc, display, surface);
->CreateSwapchain(result, setup.device, setup.queue, desc, display, surface);
}
} break;
#endif
}
throw ex::Exception("Failed to create swapchain");
}

wis::SwapChain ex::Window::CreateSwapchain(wis::Result& result, ex::PlatformExtension& ext, ex::ExampleSetup& setup, wis::DataFormat fmt, bool stereo)
{
using enum PlatformExtension::Selector;
if (_platform.current == None) {
throw ex::Exception("Platform is not selected");
}

auto [width, height] = PixelSize();
wis::SwapchainDesc desc{
.size = { uint32_t(width), uint32_t(height) },
.format = fmt,
.buffer_count = ex::swap_buffer_count,
.stereo = stereo,
.vsync = true,
.tearing = false,
};

switch (ext.current) {
#if defined(SDL_PLATFORM_WIN32)
case Windows: {
HWND hwnd = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
if (hwnd) {
return static_cast<wis::platform::WindowsExtension*>(ext.get())
->CreateSwapchain(result, setup.device, setup.queue, desc, hwnd);
}
} break;
#elif defined(SDL_PLATFORM_LINUX)
case X11: {
Display* xdisplay = (Display*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
::Window xwindow = (::Window)SDL_GetNumberProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
if (xdisplay && xwindow) {
return static_cast<wis::platform::X11Extension*>(ext.get())
->CreateSwapchain(result, setup.device, setup.queue, desc, xdisplay, xwindow);
}
} break;
case Wayland: {
struct wl_display* display = (struct wl_display*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
struct wl_surface* surface = (struct wl_surface*)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
if (display && surface) {
return static_cast<wis::platform::WaylandExtension*>(ext.get())
->CreateSwapchain(result, setup.device, setup.queue, desc, display, surface);
}
} break;
#endif
Expand Down
15 changes: 15 additions & 0 deletions examples/common/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ class Window
{
window = SDL_CreateWindow(title, width, height, SDL_WINDOW_RESIZABLE);
}
Window(const char* title, int x, int y, int width, int height, SDL_WindowFlags flags)
{
SDL_PropertiesID props = SDL_CreateProperties();
if (title && *title) {
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title);
}
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, x);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, y);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, width);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, height);
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_FLAGS_NUMBER, flags);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
}
~Window()
{
SDL_DestroyWindow(window);
Expand All @@ -65,6 +79,7 @@ class Window
return _platform.get();
}
wis::SwapChain CreateSwapchain(wis::Result& result, ex::ExampleSetup& setup, wis::DataFormat fmt = ex::swapchain_format, bool stereo = false);
wis::SwapChain CreateSwapchain(wis::Result& result, ex::PlatformExtension& external_ext, ex::ExampleSetup& setup, wis::DataFormat fmt = ex::swapchain_format, bool stereo = false);

void PostQuit();
ex::WindowEvent PollEvents();
Expand Down
3 changes: 3 additions & 0 deletions examples/custom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ if(WISDOM_WINDOWS AND NOT WISDOM_WINDOWS_STORE)
add_subdirectory(cross_device)
add_subdirectory(multimon)
endif()

add_example(multimon-single)
add_example(cross-app)
endif()
17 changes: 17 additions & 0 deletions examples/custom/cross-app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project(cross-app-${POSTFIX})

set(HEADERS)
set(SOURCES entry_main.cpp)

add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PUBLIC common-${POSTFIX})
add_dependencies(${PROJECT_NAME} compile_shaders_basic)
set_target_properties(
${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 RUNTIME_OUTPUT_DIRECTORY
${EXAMPLE_BIN_OUTPUT})

if(POSTFIX STREQUAL "dx12")
wis_make_exports_dx(${PROJECT_NAME}) # install the d3d12 agility sdk, for
# examples this is enough
# for the main project, use wis_installdeps(${PROJECT_NAME}) instead
endif()
Loading

0 comments on commit adedf37

Please sign in to comment.