Skip to content

Commit 4fd1d3e

Browse files
committed
Loads of minor changes
1 parent b8671be commit 4fd1d3e

31 files changed

+207
-211
lines changed

examples_tests/common/CommonAPI.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ class CommonAPI
608608
bool hasSparseBindingFlag = (familyProperty.queueFlags & IPhysicalDevice::EQF_SPARSE_BINDING_BIT).value != 0;
609609
bool hasProtectedFlag = (familyProperty.queueFlags & IPhysicalDevice::EQF_PROTECTED_BIT).value != 0;
610610

611-
const uint32_t extraQueueCount = core::min(remainingQueueCounts[familyIndex], 2u); // UP + DOWN
611+
const uint32_t extraQueueCount = nbl::core::min(remainingQueueCounts[familyIndex], 2u); // UP + DOWN
612612
const bool hasExtraQueues = extraQueueCount >= 1u;
613613

614614
/*
@@ -1459,12 +1459,12 @@ class CommonAPI
14591459
else
14601460
imageSharingMode = asset::ESM_CONCURRENT;
14611461

1462-
video::ISurface::SFormat surfaceFormat;
1462+
nbl::video::ISurface::SFormat surfaceFormat;
14631463

14641464
if(api_type == nbl::video::EAT_VULKAN)
14651465
{
14661466
// Deduce format features from imageUsage param
1467-
video::IPhysicalDevice::SFormatImageUsage requiredFormatUsages = {};
1467+
nbl::video::IPhysicalDevice::SFormatImageUsage requiredFormatUsages = {};
14681468
if (imageUsage & asset::IImage::EUF_STORAGE_BIT)
14691469
requiredFormatUsages.storageImage = 1;
14701470

@@ -1561,8 +1561,8 @@ class CommonAPI
15611561
sc_params.imageUsage = imageUsage;
15621562
sc_params.surface = surface;
15631563
sc_params.imageSharingMode = imageSharingMode;
1564-
sc_params.preTransform = video::ISurface::EST_IDENTITY_BIT;
1565-
sc_params.compositeAlpha = video::ISurface::ECA_OPAQUE_BIT;
1564+
sc_params.preTransform = nbl::video::ISurface::EST_IDENTITY_BIT;
1565+
sc_params.compositeAlpha = nbl::video::ISurface::ECA_OPAQUE_BIT;
15661566
sc_params.surfaceFormat = surfaceFormat;
15671567

15681568
auto swapchain = device->createSwapchain(std::move(sc_params));
@@ -1636,7 +1636,7 @@ class CommonAPI
16361636
{
16371637
using namespace nbl;
16381638
bool useDepth = asset::isDepthOrStencilFormat(depthFormat);
1639-
std::array<nbl::core::smart_refctd_ptr<video::IGPUFramebuffer>, InitOutput::MaxSwapChainImageCount> fbo;
1639+
std::array<nbl::core::smart_refctd_ptr<nbl::video::IGPUFramebuffer>, InitOutput::MaxSwapChainImageCount> fbo;
16401640
auto sc_images = swapchain->getImages();
16411641
assert(sc_images.size() == imageCount);
16421642
for (uint32_t i = 0u; i < imageCount; ++i)
@@ -1716,10 +1716,10 @@ class CommonAPI
17161716
{
17171717
submit.commandBufferCount = 1u;
17181718
submit.commandBuffers = &cmdbuf;
1719-
video::IGPUSemaphore* signalsem = renderFinishedSemaphore;
1719+
nbl::video::IGPUSemaphore* signalsem = renderFinishedSemaphore;
17201720
submit.signalSemaphoreCount = waitSemaphore ? 1u:0u;
17211721
submit.pSignalSemaphores = &signalsem;
1722-
video::IGPUSemaphore* waitsem = waitSemaphore;
1722+
nbl::video::IGPUSemaphore* waitsem = waitSemaphore;
17231723
asset::E_PIPELINE_STAGE_FLAGS dstWait = waitDstStageMask.value;
17241724
submit.waitSemaphoreCount = 1u;
17251725
submit.pWaitSemaphores = &waitsem;

include/nbl/core/math/glslFunctions.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class matrix3x4SIMD;
2828
template<typename T>
2929
NBL_FORCE_INLINE T radians(const T& degrees)
3030
{
31-
static_assert(
32-
std::is_same<T, float>::value ||
33-
std::is_same<T, double>::value ||
34-
std::is_same<T, vectorSIMDf>::value,
35-
"This code expects the type to be double, float or vectorSIMDf, only (float, double, vectorSIMDf).");
31+
//static_assert(
32+
// std::is_same<T, float>::value ||
33+
// std::is_same<T, double>::value ||
34+
// std::is_same<T, vectorSIMDf>::value,
35+
// "This code expects the type to be double, float or vectorSIMDf, only (float, double, vectorSIMDf).");
3636

3737
return degrees*PI<T>()/T(180);
3838
}
File renamed without changes.

include/nbl/video/IGPUQueue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ class IGPUQueue : public core::Interface, public core::Unmovable
9696
if(cmdbuf == nullptr)
9797
return false;
9898

99-
if(cmdbuf->isResettable())
100-
cmdbuf->setState(IGPUCommandBuffer::ES_INVALID);
101-
else
99+
if (cmdbuf->isResettable())
102100
cmdbuf->setState(IGPUCommandBuffer::ES_EXECUTABLE);
101+
else
102+
cmdbuf->setState(IGPUCommandBuffer::ES_INVALID);
103103
}
104104
}
105105
return true;

include/nbl/video/declarations.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// platform and API specific stuff
2424
#include "nbl/video/COpenGL_Connection.h"
2525
#include "nbl/video/CVulkanConnection.h"
26-
#include "nbl/video/surface/ISurfaceGL.h"
26+
#include "nbl/video/surface/CSurfaceGL.h"
2727
#include "nbl/video/surface/CSurfaceVulkan.h"
2828

2929
// utilities

include/nbl/video/surface/ISurfaceGL.h renamed to include/nbl/video/surface/CSurfaceGL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CSurfaceGLImpl : public Base<Window>
2424
{
2525
if (!api || !window)
2626
return nullptr;
27-
auto retval = new this_t(std::move(api),std::move(window));
27+
auto retval = new this_t(std::move(window), std::move(api));
2828
return core::smart_refctd_ptr<this_t>(retval,core::dont_grab);
2929
}
3030
template<video::E_API_TYPE API_TYPE>

include/nbl/video/surface/CSurfaceVulkan.h

Lines changed: 39 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -2,198 +2,72 @@
22
#define __NBL_C_SURFACE_VULKAN_H_INCLUDED__
33

44
#include "nbl/video/surface/ISurface.h"
5-
#include "nbl/video/CVulkanCommon.h"
6-
#include "nbl/video/CVulkanPhysicalDevice.h"
75
#include "nbl/video/CVulkanConnection.h"
86

97
#include "nbl/ui/IWindowAndroid.h"
108

119
namespace nbl::video
1210
{
1311

14-
class CVulkanConnection;
15-
class CVulkanPhysicalDevice;
1612

17-
template <typename Window>
18-
class CSurfaceVulkan final : public CSurface<Window>
13+
#include "volk.h"
14+
15+
class ISurfaceVulkan : public ISurface
1916
{
17+
using base_t = ISurface;
2018
public:
21-
using this_t = CSurfaceVulkan<Window>;
22-
using base_t = CSurface<Window>;
19+
bool isSupportedForPhysicalDevice(const IPhysicalDevice* dev, uint32_t _queueFamIx) const override;
20+
void getAvailableFormatsForPhysicalDevice(const IPhysicalDevice* physicalDevice, uint32_t& formatCount, ISurface::SFormat* formats) const override;
21+
E_PRESENT_MODE getAvailablePresentModesForPhysicalDevice(const IPhysicalDevice* physicalDevice) const override;
22+
bool getSurfaceCapabilitiesForPhysicalDevice(const IPhysicalDevice* physicalDevice, ISurface::SCapabilities& capabilities) const override;
2323

24-
static inline core::smart_refctd_ptr<this_t> create(core::smart_refctd_ptr<video::CVulkanConnection>&& api, core::smart_refctd_ptr<Window>&& window)
25-
{
26-
if (!api || !window)
27-
return nullptr;
24+
inline VkSurfaceKHR getInternalObject() const { return m_vkSurfaceKHR; }
2825

29-
#ifdef _NBL_PLATFORM_WINDOWS_
30-
// This needs to know what ui::IWindowWin32 is! Won't work on other platforms!
31-
if constexpr (std::is_same_v<Window, ui::IWindowWin32>)
32-
{
33-
VkWin32SurfaceCreateInfoKHR createInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
34-
createInfo.pNext = nullptr; // pNext must be NULL
35-
createInfo.flags = static_cast<VkWin32SurfaceCreateFlagsKHR>(0);
36-
createInfo.hinstance = GetModuleHandle(NULL);
37-
createInfo.hwnd = (static_cast<HWND>(window->getNativeHandle()));
26+
protected:
27+
explicit ISurfaceVulkan(core::smart_refctd_ptr<video::IAPIConnection>&& api, VkSurfaceKHR vk_surface) : base_t(std::move(api)), m_vkSurfaceKHR(vk_surface) {}
28+
virtual ~ISurfaceVulkan() = default;
3829

39-
VkSurfaceKHR vk_surface;
40-
if (vkCreateWin32SurfaceKHR(api->getInternalObject(), &createInfo, nullptr,
41-
&vk_surface) == VK_SUCCESS)
42-
{
43-
auto retval = new this_t(std::move(api), std::move(window), vk_surface);
44-
return core::smart_refctd_ptr<this_t>(retval, core::dont_grab);
45-
}
46-
else
47-
{
48-
return nullptr;
49-
}
50-
}
51-
#else
52-
return nullptr;
53-
#endif
54-
}
30+
VkSurfaceKHR m_vkSurfaceKHR = VK_NULL_HANDLE;
31+
};
5532

56-
inline bool isSupportedForPhysicalDevice(const IPhysicalDevice* dev, uint32_t _queueFamIx) const override
33+
#ifdef _NBL_PLATFORM_WINDOWS_
34+
class CSurfaceVulkanWin32 final : public CSurface<ui::IWindowWin32, ISurfaceVulkan>
35+
{
36+
using this_t = CSurfaceVulkanWin32;
37+
using base_t = CSurface<ui::IWindowWin32, ISurfaceVulkan>;
38+
public:
39+
CSurfaceVulkanWin32(core::smart_refctd_ptr<ui::IWindowWin32>&& window, core::smart_refctd_ptr<IAPIConnection>&& api, VkSurfaceKHR surf) :
40+
base_t(std::move(window), std::move(api), surf)
5741
{
58-
if (dev->getAPIType() != EAT_VULKAN)
59-
return false;
60-
61-
VkPhysicalDevice vk_physicalDevice = static_cast<const CVulkanPhysicalDevice*>(dev)->getInternalObject();
62-
63-
VkBool32 supported;
64-
if (vkGetPhysicalDeviceSurfaceSupportKHR(vk_physicalDevice, _queueFamIx, m_vkSurfaceKHR, &supported) == VK_SUCCESS)
65-
{
66-
return static_cast<bool>(supported);
67-
}
68-
else
69-
{
70-
return false;
71-
}
7242
}
73-
74-
inline void getAvailableFormatsForPhysicalDevice(const IPhysicalDevice* physicalDevice, uint32_t& formatCount, ISurface::SFormat* formats) const override
43+
static inline core::smart_refctd_ptr<this_t> create(core::smart_refctd_ptr<video::CVulkanConnection>&& api, core::smart_refctd_ptr<ui::IWindowWin32>&& window)
7544
{
76-
constexpr uint32_t MAX_SURFACE_FORMAT_COUNT = 1000u;
77-
78-
if (physicalDevice && physicalDevice->getAPIType() != EAT_VULKAN)
79-
return;
80-
81-
VkPhysicalDevice vk_physicalDevice = static_cast<const CVulkanPhysicalDevice*>(physicalDevice)->getInternalObject();
82-
83-
VkResult retval = vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physicalDevice, m_vkSurfaceKHR,
84-
&formatCount, nullptr);
85-
86-
if ((retval != VK_SUCCESS) && (retval != VK_INCOMPLETE))
87-
{
88-
formatCount = 0u;
89-
return;
90-
}
91-
92-
if (!formats)
93-
return;
94-
95-
VkSurfaceFormatKHR vk_formats[MAX_SURFACE_FORMAT_COUNT];
96-
retval = vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physicalDevice, m_vkSurfaceKHR,
97-
&formatCount, vk_formats);
45+
if (!api || !window)
46+
return nullptr;
9847

99-
if ((retval != VK_SUCCESS) && (retval != VK_INCOMPLETE))
100-
{
101-
formatCount = 0u;
102-
formats = nullptr;
103-
return;
104-
}
48+
VkWin32SurfaceCreateInfoKHR createInfo = { VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR };
49+
createInfo.pNext = nullptr; // pNext must be NULL
50+
createInfo.flags = static_cast<VkWin32SurfaceCreateFlagsKHR>(0);
51+
createInfo.hinstance = GetModuleHandle(NULL);
52+
createInfo.hwnd = static_cast<HWND>(window->getNativeHandle());
10553

106-
for (uint32_t i = 0u; i < formatCount; ++i)
54+
VkSurfaceKHR vk_surface;
55+
// `vkCreateWin32SurfaceKHR` is taken from `volk` (cause it uses `extern` globals like a n00b)
56+
if (vkCreateWin32SurfaceKHR(api->getInternalObject(), &createInfo, nullptr, &vk_surface) == VK_SUCCESS)
10757
{
108-
formats[i].format = getFormatFromVkFormat(vk_formats[i].format);
109-
formats[i].colorSpace = getColorSpaceFromVkColorSpaceKHR(vk_formats[i].colorSpace);
58+
auto retval = new this_t(std::move(window), std::move(api), vk_surface);
59+
return core::smart_refctd_ptr<this_t>(retval, core::dont_grab);
11060
}
111-
}
112-
113-
inline ISurface::E_PRESENT_MODE getAvailablePresentModesForPhysicalDevice(const IPhysicalDevice* physicalDevice) const override
114-
{
115-
constexpr uint32_t MAX_PRESENT_MODE_COUNT = 4u;
116-
117-
ISurface::E_PRESENT_MODE result = ISurface::EPM_UNKNOWN;
118-
119-
if (physicalDevice && physicalDevice->getAPIType() != EAT_VULKAN)
120-
return result;
121-
122-
VkPhysicalDevice vk_physicalDevice = static_cast<const CVulkanPhysicalDevice*>(physicalDevice)->getInternalObject();
123-
124-
uint32_t count = 0u;
125-
VkResult retval = vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physicalDevice, m_vkSurfaceKHR,
126-
&count, nullptr);
127-
128-
if ((retval != VK_SUCCESS) && (retval != VK_INCOMPLETE))
129-
return result;
130-
131-
assert(count <= MAX_PRESENT_MODE_COUNT);
132-
133-
VkPresentModeKHR vk_presentModes[MAX_PRESENT_MODE_COUNT];
134-
retval = vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physicalDevice, m_vkSurfaceKHR,
135-
&count, vk_presentModes);
136-
137-
if ((retval != VK_SUCCESS) && (retval != VK_INCOMPLETE))
138-
return result;
139-
140-
for (uint32_t i = 0u; i < count; ++i)
141-
result = static_cast<ISurface::E_PRESENT_MODE>(result | getPresentModeFromVkPresentModeKHR(vk_presentModes[i]));
142-
143-
return result;
144-
}
145-
146-
inline bool getSurfaceCapabilitiesForPhysicalDevice(const IPhysicalDevice* physicalDevice, ISurface::SCapabilities& capabilities) const override
147-
{
148-
if (physicalDevice && physicalDevice->getAPIType() != EAT_VULKAN)
149-
return false;
150-
151-
VkPhysicalDevice vk_physicalDevice = static_cast<const CVulkanPhysicalDevice*>(physicalDevice)->getInternalObject();
152-
153-
VkSurfaceCapabilitiesKHR vk_surfaceCapabilities;
154-
if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_physicalDevice, m_vkSurfaceKHR,
155-
&vk_surfaceCapabilities) != VK_SUCCESS)
61+
else
15662
{
157-
return false;
63+
return nullptr;
15864
}
159-
160-
capabilities.minImageCount = vk_surfaceCapabilities.minImageCount;
161-
capabilities.maxImageCount = (vk_surfaceCapabilities.maxImageCount == 0u) ? ~0u : vk_surfaceCapabilities.maxImageCount;
162-
capabilities.currentExtent = vk_surfaceCapabilities.currentExtent;
163-
capabilities.minImageExtent = vk_surfaceCapabilities.minImageExtent;
164-
capabilities.maxImageExtent = vk_surfaceCapabilities.maxImageExtent;
165-
capabilities.maxImageArrayLayers = vk_surfaceCapabilities.maxImageArrayLayers;
166-
capabilities.supportedTransforms = static_cast<ISurface::E_SURFACE_TRANSFORM_FLAGS>(vk_surfaceCapabilities.supportedTransforms);
167-
capabilities.currentTransform = static_cast<ISurface::E_SURFACE_TRANSFORM_FLAGS>(vk_surfaceCapabilities.currentTransform);
168-
capabilities.supportedCompositeAlpha = static_cast<ISurface::E_COMPOSITE_ALPHA>(vk_surfaceCapabilities.supportedCompositeAlpha);
169-
capabilities.supportedUsageFlags = static_cast<asset::IImage::E_USAGE_FLAGS>(vk_surfaceCapabilities.supportedUsageFlags);
170-
171-
return true;
172-
}
173-
174-
inline VkSurfaceKHR getInternalObject() const { return m_vkSurfaceKHR; }
175-
176-
protected:
177-
explicit CSurfaceVulkan(core::smart_refctd_ptr<video::CVulkanConnection>&& api,
178-
core::smart_refctd_ptr<Window>&& window, VkSurfaceKHR vk_surface)
179-
: base_t(std::move(api), std::move(window)), m_vkSurfaceKHR(vk_surface)
180-
{}
181-
182-
inline ~CSurfaceVulkan()
183-
{
184-
VkInstance vk_instance = static_cast<const CVulkanConnection*>(base_t::m_api.get())->getInternalObject();
185-
vkDestroySurfaceKHR(vk_instance, m_vkSurfaceKHR, nullptr);
18665
}
187-
188-
VkSurfaceKHR m_vkSurfaceKHR = VK_NULL_HANDLE;
18966
};
190-
191-
#ifdef _NBL_PLATFORM_WINDOWS_
192-
using CSurfaceVulkanWin32 = CSurfaceVulkan<ui::IWindowWin32>;
19367
#elif defined _NBL_PLATFORM_LINUX_
194-
using CSurfaceVulkanX11 = CSurfaceVulkan<ui::IWindowX11>;
68+
// TODO: later, not this week
19569
#elif defined _NBL_PLATFORM_ANDROID_
196-
using CSurfaceVulkanAndroid = CSurfaceVulkan<ui::IWindowAndroid>;
70+
// TODO: later, not this week
19771
#endif
19872
}
19973

include/nbl/video/surface/ISurface.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class ISurface : public core::IReferenceCounted
109109
virtual const void* getNativeWindowHandle() const = 0;
110110
};
111111

112-
template<class Window>
113-
class CSurface : public ISurface
112+
template<class Window, class ImmediateBase = ISurface>
113+
class CSurface : public ImmediateBase
114114
{
115115
public:
116116
inline const void* getNativeWindowHandle() const override final
@@ -119,7 +119,8 @@ class CSurface : public ISurface
119119
}
120120

121121
protected:
122-
CSurface(core::smart_refctd_ptr<IAPIConnection>&& api, core::smart_refctd_ptr<Window>&& window) : ISurface(std::move(api)), m_window(std::move(window)) {}
122+
template<typename... Args>
123+
CSurface(core::smart_refctd_ptr<Window>&& window, Args&&... args) : ImmediateBase(std::forward<Args>(args)...), m_window(std::move(window)) {}
123124
virtual ~CSurface() = default;
124125

125126
uint32_t getWidth() const override { return m_window->getWidth(); }
@@ -128,8 +129,8 @@ class CSurface : public ISurface
128129
core::smart_refctd_ptr<Window> m_window;
129130
};
130131

131-
template<class Window>
132-
class CSurfaceNative : public ISurface
132+
template<class Window, class ImmediateBase = ISurface>
133+
class CSurfaceNative : public ImmediateBase
133134
{
134135
public:
135136
inline const void* getNativeWindowHandle() const override final
@@ -138,7 +139,7 @@ class CSurfaceNative : public ISurface
138139
}
139140

140141
protected:
141-
CSurfaceNative(core::smart_refctd_ptr<IAPIConnection>&& api, typename Window::native_handle_t handle) : ISurface(std::move(api)), m_handle(handle) {}
142+
CSurfaceNative(core::smart_refctd_ptr<IAPIConnection>&& api, typename Window::native_handle_t handle) : ImmediateBase(std::move(api)), m_handle(handle) {}
142143
virtual ~CSurfaceNative() = default;
143144

144145
typename Window::native_handle_t m_handle;

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ set(NABLA_SRCS_NORMAL
349349
${NBL_ROOT_PATH}/src/nbl/video/CVulkanConnection.cpp
350350
${NBL_ROOT_PATH}/src/nbl/video/CVulkanGraphicsPipeline.cpp
351351
${NBL_ROOT_PATH}/src/nbl/video/CVulkanEvent.cpp
352+
${NBL_ROOT_PATH}/src/nbl/video/CSurfaceVulkan.cpp
352353

353354

354355
#opengl
@@ -722,4 +723,3 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
722723
nbl_install_lib(tbbmalloc)
723724
nbl_install_lib(tbbmalloc_proxy)
724725
endif()
725-

0 commit comments

Comments
 (0)