mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Remove DxvkSurface
This commit is contained in:
parent
9b923bb386
commit
80b9f1d03b
@ -8,8 +8,6 @@
|
||||
|
||||
#include "../d3d11/d3d11_interfaces.h"
|
||||
|
||||
#include "../dxvk/dxvk_surface.h"
|
||||
|
||||
#include "../spirv/spirv_module.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
@ -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<DxvkSurface> DxvkAdapter::createSurface(HINSTANCE instance, HWND window) {
|
||||
return new DxvkSurface(this, instance, window);
|
||||
}
|
||||
|
||||
|
||||
void DxvkAdapter::notifyHeapMemoryAlloc(
|
||||
uint32_t heap,
|
||||
VkDeviceSize bytes) {
|
||||
|
@ -8,7 +8,6 @@ namespace dxvk {
|
||||
|
||||
class DxvkDevice;
|
||||
class DxvkInstance;
|
||||
class DxvkSurface;
|
||||
|
||||
/**
|
||||
* \brief GPU vendors
|
||||
@ -193,17 +192,6 @@ namespace dxvk {
|
||||
Rc<DxvkDevice> createDevice(
|
||||
DxvkDeviceFeatures enabledFeatures);
|
||||
|
||||
/**
|
||||
* \brief Creates a surface
|
||||
*
|
||||
* \param [in] instance Module instance
|
||||
* \param [in] window Application window
|
||||
* \returns Surface handle
|
||||
*/
|
||||
Rc<DxvkSurface> createSurface(
|
||||
HINSTANCE instance,
|
||||
HWND window);
|
||||
|
||||
/**
|
||||
* \brief Registers memory allocation
|
||||
*
|
||||
|
@ -1,176 +0,0 @@
|
||||
#include "dxvk_surface.h"
|
||||
#include "dxvk_format.h"
|
||||
|
||||
#include "../util/util_math.h"
|
||||
|
||||
namespace dxvk {
|
||||
|
||||
DxvkSurface::DxvkSurface(
|
||||
const Rc<DxvkAdapter>& 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<uint32_t>::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<VkSurfaceFormatKHR> 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<VkSurfaceFormatKHR> 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<VkPresentModeKHR> 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<VkPresentModeKHR> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<DxvkAdapter>& 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<DxvkAdapter> m_adapter;
|
||||
Rc<vk::InstanceFn> m_vki;
|
||||
|
||||
VkSurfaceKHR m_handle;
|
||||
|
||||
std::vector<VkSurfaceFormatKHR> m_surfaceFormats;
|
||||
std::vector<VkPresentModeKHR> m_presentModes;
|
||||
|
||||
VkSurfaceKHR createSurface(HINSTANCE instance, HWND window);
|
||||
|
||||
std::vector<VkSurfaceFormatKHR> getSurfaceFormats();
|
||||
std::vector<VkPresentModeKHR> getPresentModes();
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user