diff --git a/src/dxgi/dxgi_swapchain.h b/src/dxgi/dxgi_swapchain.h index 80183f27..c0fa22e7 100644 --- a/src/dxgi/dxgi_swapchain.h +++ b/src/dxgi/dxgi_swapchain.h @@ -8,8 +8,6 @@ #include "../d3d11/d3d11_interfaces.h" -#include "../dxvk/dxvk_surface.h" - #include "../spirv/spirv_module.h" namespace dxvk { diff --git a/src/dxvk/dxvk_adapter.cpp b/src/dxvk/dxvk_adapter.cpp index 862f361b..addbdeb2 100644 --- a/src/dxvk/dxvk_adapter.cpp +++ b/src/dxvk/dxvk_adapter.cpp @@ -3,7 +3,6 @@ #include "dxvk_adapter.h" #include "dxvk_device.h" #include "dxvk_instance.h" -#include "dxvk_surface.h" namespace dxvk { @@ -315,11 +314,6 @@ namespace dxvk { } - Rc DxvkAdapter::createSurface(HINSTANCE instance, HWND window) { - return new DxvkSurface(this, instance, window); - } - - void DxvkAdapter::notifyHeapMemoryAlloc( uint32_t heap, VkDeviceSize bytes) { diff --git a/src/dxvk/dxvk_adapter.h b/src/dxvk/dxvk_adapter.h index 53ad83c0..dbc6f668 100644 --- a/src/dxvk/dxvk_adapter.h +++ b/src/dxvk/dxvk_adapter.h @@ -8,7 +8,6 @@ namespace dxvk { class DxvkDevice; class DxvkInstance; - class DxvkSurface; /** * \brief GPU vendors @@ -193,17 +192,6 @@ namespace dxvk { Rc createDevice( DxvkDeviceFeatures enabledFeatures); - /** - * \brief Creates a surface - * - * \param [in] instance Module instance - * \param [in] window Application window - * \returns Surface handle - */ - Rc createSurface( - HINSTANCE instance, - HWND window); - /** * \brief Registers memory allocation * diff --git a/src/dxvk/dxvk_surface.cpp b/src/dxvk/dxvk_surface.cpp deleted file mode 100644 index f9f80b1a..00000000 --- a/src/dxvk/dxvk_surface.cpp +++ /dev/null @@ -1,176 +0,0 @@ -#include "dxvk_surface.h" -#include "dxvk_format.h" - -#include "../util/util_math.h" - -namespace dxvk { - - DxvkSurface::DxvkSurface( - const Rc& adapter, - HINSTANCE instance, - HWND window) - : m_adapter (adapter), - m_vki (adapter->vki()), - m_handle (createSurface(instance, window)), - m_surfaceFormats (getSurfaceFormats()), - m_presentModes (getPresentModes()) { - - } - - - DxvkSurface::~DxvkSurface() { - m_vki->vkDestroySurfaceKHR( - m_vki->instance(), m_handle, nullptr); - } - - - VkSurfaceCapabilitiesKHR DxvkSurface::getSurfaceCapabilities() const { - VkSurfaceCapabilitiesKHR surfaceCaps; - if (m_vki->vkGetPhysicalDeviceSurfaceCapabilitiesKHR( - m_adapter->handle(), m_handle, &surfaceCaps) != VK_SUCCESS) - throw DxvkError("DxvkSurface::getSurfaceCapabilities: Failed to query surface capabilities"); - return surfaceCaps; - } - - - VkSurfaceFormatKHR DxvkSurface::pickSurfaceFormat( - uint32_t preferredCount, - const VkSurfaceFormatKHR* preferred) const { - if (preferredCount > 0) { - // If the implementation allows us to freely choose - // the format, we'll just use the preferred format. - if (m_surfaceFormats.size() == 1 && m_surfaceFormats.at(0).format == VK_FORMAT_UNDEFINED) - return preferred[0]; - - // If the preferred format is explicitly listed in - // the array of supported surface formats, use it - for (uint32_t i = 0; i < preferredCount; i++) { - for (auto fmt : m_surfaceFormats) { - if (fmt.format == preferred[i].format - && fmt.colorSpace == preferred[i].colorSpace) - return fmt; - } - } - - // If that didn't work, we'll fall back to a format - // which has similar properties to the preferred one - DxvkFormatFlags prefFlags = imageFormatInfo(preferred[0].format)->flags; - - for (auto fmt : m_surfaceFormats) { - auto currFlags = imageFormatInfo(fmt.format)->flags; - - if ((currFlags & DxvkFormatFlag::ColorSpaceSrgb) - == (prefFlags & DxvkFormatFlag::ColorSpaceSrgb)) - return fmt; - } - } - - // Otherwise, fall back to the first format - return m_surfaceFormats.at(0); - } - - - VkPresentModeKHR DxvkSurface::pickPresentMode( - uint32_t preferredCount, - const VkPresentModeKHR* preferred) const { - for (uint32_t i = 0; i < preferredCount; i++) { - for (auto mode : m_presentModes) { - if (mode == preferred[i]) - return mode; - } - } - - // This mode is guaranteed to be available - return VK_PRESENT_MODE_FIFO_KHR; - } - - - uint32_t DxvkSurface::pickImageCount( - const VkSurfaceCapabilitiesKHR& caps, - VkPresentModeKHR mode, - uint32_t preferred) const { - uint32_t count = caps.minImageCount; - - if (mode != VK_PRESENT_MODE_IMMEDIATE_KHR) - count = caps.minImageCount + 1; - - if (count < preferred) - count = preferred; - - if (count > caps.maxImageCount && caps.maxImageCount != 0) - count = caps.maxImageCount; - - return count; - } - - - VkExtent2D DxvkSurface::pickImageExtent( - const VkSurfaceCapabilitiesKHR& caps, - VkExtent2D preferred) const { - if (caps.currentExtent.width != std::numeric_limits::max()) - return caps.currentExtent; - - VkExtent2D actual; - actual.width = clamp(preferred.width, caps.minImageExtent.width, caps.maxImageExtent.width); - actual.height = clamp(preferred.height, caps.minImageExtent.height, caps.maxImageExtent.height); - return actual; - } - - - VkSurfaceKHR DxvkSurface::createSurface(HINSTANCE instance, HWND window) { - VkWin32SurfaceCreateInfoKHR info; - info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - info.pNext = nullptr; - info.flags = 0; - info.hinstance = instance; - info.hwnd = window; - - VkSurfaceKHR surface = VK_NULL_HANDLE; - if (m_vki->vkCreateWin32SurfaceKHR(m_vki->instance(), &info, nullptr, &surface) != VK_SUCCESS) - throw DxvkError("DxvkSurface::createSurface: Failed to create win32 surface"); - - VkBool32 supportStatus = VK_FALSE; - - if (m_vki->vkGetPhysicalDeviceSurfaceSupportKHR(m_adapter->handle(), - m_adapter->presentQueueFamily(), surface, &supportStatus) != VK_SUCCESS) { - m_vki->vkDestroySurfaceKHR(m_vki->instance(), surface, nullptr); - throw DxvkError("DxvkSurface::createSurface: Failed to query surface support"); - } - - if (!supportStatus) { - m_vki->vkDestroySurfaceKHR(m_vki->instance(), surface, nullptr); - throw DxvkError("DxvkSurface::createSurface: Surface not supported by device"); - } - - return surface; - } - - - std::vector DxvkSurface::getSurfaceFormats() { - uint32_t numFormats = 0; - if (m_vki->vkGetPhysicalDeviceSurfaceFormatsKHR( - m_adapter->handle(), m_handle, &numFormats, nullptr) != VK_SUCCESS) - throw DxvkError("DxvkSurface::getSurfaceFormats: Failed to query surface formats"); - - std::vector formats(numFormats); - if (m_vki->vkGetPhysicalDeviceSurfaceFormatsKHR( - m_adapter->handle(), m_handle, &numFormats, formats.data()) != VK_SUCCESS) - throw DxvkError("DxvkSurface::getSurfaceFormats: Failed to query surface formats"); - return formats; - } - - - std::vector DxvkSurface::getPresentModes() { - uint32_t numModes = 0; - if (m_vki->vkGetPhysicalDeviceSurfacePresentModesKHR( - m_adapter->handle(), m_handle, &numModes, nullptr) != VK_SUCCESS) - throw DxvkError("DxvkSurface::getPresentModes: Failed to query present modes"); - - std::vector modes(numModes); - if (m_vki->vkGetPhysicalDeviceSurfacePresentModesKHR( - m_adapter->handle(), m_handle, &numModes, modes.data()) != VK_SUCCESS) - throw DxvkError("DxvkSurface::getPresentModes: Failed to query present modes"); - return modes; - } - -} \ No newline at end of file diff --git a/src/dxvk/dxvk_surface.h b/src/dxvk/dxvk_surface.h deleted file mode 100644 index 683be9fb..00000000 --- a/src/dxvk/dxvk_surface.h +++ /dev/null @@ -1,104 +0,0 @@ -#pragma once - -#include "dxvk_adapter.h" - -namespace dxvk { - - /** - * \brief DXVK surface - * - * Vulkan representation of a drawable window surface. This - * class provides methods to query the current dimension of - * the surface as well as format support queries. - */ - class DxvkSurface : public RcObject { - - public: - - DxvkSurface( - const Rc& adapter, - HINSTANCE instance, - HWND window); - ~DxvkSurface(); - - /** - * \brief Vulkan surface handle - * \returns The surface handle - */ - VkSurfaceKHR handle() const { - return m_handle; - } - - /** - * \brief Queries surface capabilities - * - * Retrieves up-to-date information about the surface, - * such as the bounds of the swapchain images. - * \returns Current surface properties - */ - VkSurfaceCapabilitiesKHR getSurfaceCapabilities() const; - - /** - * \brief Picks a suitable surface format - * - * \param [in] preferredCount Number of formats to probe - * \param [in] preferred Preferred surface formats - * \returns The actual surface format - */ - VkSurfaceFormatKHR pickSurfaceFormat( - uint32_t preferredCount, - const VkSurfaceFormatKHR* preferred) const; - - /** - * \brief Picks a supported present mode - * - * \param [in] preferredCount Number of modes to probe - * \param [in] preferred Preferred present modes - * \returns The actual present mode - */ - VkPresentModeKHR pickPresentMode( - uint32_t preferredCount, - const VkPresentModeKHR* preferred) const; - - /** - * \brief Picks a suitable image count for a swap chain - * - * \param [in] caps Surface capabilities - * \param [in] mode The present mode - * \param [in] preferred Preferred image count - * \returns Suitable image count - */ - uint32_t pickImageCount( - const VkSurfaceCapabilitiesKHR& caps, - VkPresentModeKHR mode, - uint32_t preferred) const; - - /** - * \brief Picks a suitable image size for a swap chain - * - * \param [in] caps Surface capabilities - * \param [in] preferred Preferred image size - * \returns Selected image size - */ - VkExtent2D pickImageExtent( - const VkSurfaceCapabilitiesKHR& caps, - VkExtent2D preferred) const; - - private: - - Rc m_adapter; - Rc m_vki; - - VkSurfaceKHR m_handle; - - std::vector m_surfaceFormats; - std::vector m_presentModes; - - VkSurfaceKHR createSurface(HINSTANCE instance, HWND window); - - std::vector getSurfaceFormats(); - std::vector getPresentModes(); - - }; - -} \ No newline at end of file diff --git a/src/dxvk/meson.build b/src/dxvk/meson.build index c234f8d5..7d581961 100644 --- a/src/dxvk/meson.build +++ b/src/dxvk/meson.build @@ -86,7 +86,6 @@ dxvk_src = files([ 'dxvk_staging.cpp', 'dxvk_state_cache.cpp', 'dxvk_stats.cpp', - 'dxvk_surface.cpp', 'dxvk_sync.cpp', 'dxvk_unbound.cpp', 'dxvk_util.cpp',