Skip to content

Commit 102367f

Browse files
committed
Apply reviews & merge swapchain_maintenance2
1 parent c63e230 commit 102367f

File tree

9 files changed

+18
-35
lines changed

9 files changed

+18
-35
lines changed

include/nbl/video/COpenGLImage.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class IOpenGL_FunctionTable;
1919

2020
class COpenGLImage final : public IGPUImage, public IOpenGLMemoryAllocation
2121
{
22-
friend COpenGLSwapchain;
23-
friend COpenGLESSwapchain;
2422
protected:
2523
virtual ~COpenGLImage();
2624

include/nbl/video/ISwapchain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ class NBL_API ISwapchain : public core::IReferenceCounted, public IBackendObject
109109
IGPUImage::SCreationParams m_imgCreationParams;
110110

111111
friend class CCleanupSwapchainReference;
112-
void freeImageExists(uint32_t ix) { m_imageExists.fetch_and(~(1U << ix)); }
112+
void freeImageExists(uint32_t ix) { std::cout << "freeImageExists(" << ix << ")\n;"; m_imageExists.fetch_and(~(1U << ix)); }
113113

114114
// Returns false if the image already existed
115-
bool setImageExists(uint32_t ix) { return (m_imageExists.fetch_or(1U << ix) & (1U << ix)) == 0; }
115+
bool setImageExists(uint32_t ix) { std::cout << "setImageExists(" << ix << ")\n;"; return (m_imageExists.fetch_or(1U << ix) & (1U << ix)) == 0; }
116116

117117
public:
118118
static inline constexpr uint32_t MaxImages = sizeof(m_imageExists) * 8u;

src/nbl/video/COpenGLBuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace nbl::video
1010
COpenGLBuffer::~COpenGLBuffer()
1111
{
1212
preDestroyStep();
13-
if (!m_cachedCreationParams.importedHandle)
13+
if (!m_cachedCreationParams.skipHandleDestroy)
1414
{
1515
auto* device = static_cast<IOpenGL_LogicalDevice*>(const_cast<ILogicalDevice*>(getOriginDevice()));
1616
device->destroyBuffer(BufferName);

src/nbl/video/COpenGLImage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ COpenGLImage::~COpenGLImage()
6161
fbohash = COpenGLFramebuffer::getHashColorImage(this);
6262
device->destroyFramebuffer(fbohash);
6363
// destroy only if not observing (we own)
64-
if (!m_cachedCreationParams.importedHandle)
64+
if (!m_cachedCreationParams.skipHandleDestroy)
6565
device->destroyTexture(name);
6666
}
6767

src/nbl/video/COpenGL_Queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class COpenGL_Queue final : public IGPUQueue
230230
}
231231

232232
// need to possibly wait for master context (object creation, and buffer mapping and flushing)
233-
m_masterContextCallsWaited = m_device->waitOnMasterContext(gl,m_masterContextCallsWaited);
233+
m_masterContextCallsWaited = m_device->waitOnMasterContext(&gl,m_masterContextCallsWaited);
234234

235235
if (barrierBits)
236236
gl.glSync.pglMemoryBarrier(barrierBits);

src/nbl/video/COpenGL_Swapchain.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
3636

3737
const egl::CEGL* egl;
3838
ISurface::E_PRESENT_MODE m_presentMode;
39-
const COpenGLFeatureMap* features;
4039
uint32_t imageCount;
4140
uint32_t imgWidth, imgHeight;
4241
core::smart_refctd_ptr<COpenGLSync> syncs[ISwapchain::MaxImages];
@@ -46,7 +45,7 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
4645
asset::E_FORMAT m_ourFormat;
4746
GLenum m_glFormat;
4847

49-
bool needToBlit = false;
48+
std::atomic_bool needToBlit = false;
5049

5150
EGLBoolean m_makeCurrentRes = EGL_FALSE;
5251
//std::condition_variable m_ctxCreatedCvar;
@@ -55,15 +54,13 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
5554
IOpenGL_LogicalDevice* dev,
5655
ISurface::E_PRESENT_MODE presentMode,
5756
uint32_t _imgCount, uint32_t _imgWidth, uint32_t _imgHeight,
58-
const COpenGLFeatureMap* _features,
5957
egl::CEGL::Context _glctx,
6058
COpenGLDebugCallback* _dbgCb,
6159
asset::E_FORMAT format
6260
) : m_device(dev), m_masterContextCallsWaited(0),
6361
egl(_egl),
6462
m_presentMode(presentMode),
6563
glctx(_glctx),
66-
features(_features),
6764
imageCount(_imgCount),
6865
imgWidth(_imgWidth),
6966
imgHeight(_imgHeight),
@@ -75,7 +72,7 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
7572
{
7673
auto raii_handler = base_t::createRAIIDispatchHandler();
7774

78-
needToBlit = true;
75+
needToBlit.store(true);
7976
request.imgIx = _imgIx;
8077
request.semCount = semCount;
8178
request.sems = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<core::smart_refctd_ptr<COpenGLSemaphore>>>(semCount);
@@ -141,9 +138,9 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
141138
}
142139

143140
if (m_device->getAPIType() == video::EAT_OPENGL)
144-
new (state_ptr) COpenGLFunctionTable(egl, features, core::smart_refctd_ptr<system::ILogger>(m_dbgCb->getLogger()));
141+
new (state_ptr) COpenGLFunctionTable(egl, m_device->getGlFeatures(), core::smart_refctd_ptr<system::ILogger>(m_dbgCb->getLogger()));
145142
else if (m_device->getAPIType() == video::EAT_OPENGL_ES)
146-
new (state_ptr) COpenGLESFunctionTable(egl, features, core::smart_refctd_ptr<system::ILogger>(m_dbgCb->getLogger()));
143+
new (state_ptr) COpenGLESFunctionTable(egl, m_device->getGlFeatures(), core::smart_refctd_ptr<system::ILogger>(m_dbgCb->getLogger()));
147144
else assert(false);
148145
auto gl = getFunctionTable(m_device->getAPIType(), state_ptr);
149146

@@ -195,7 +192,7 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
195192
void work(typename base_t::lock_t& lock, typename base_t::internal_state_t& state)
196193
{
197194
auto gl = getFunctionTable(m_device->getAPIType(), &state);
198-
needToBlit = false;
195+
needToBlit.store(false);
199196

200197
const uint32_t imgix = request.imgIx;
201198
const uint32_t w = imgWidth;
@@ -226,8 +223,8 @@ class COpenGL_SwapchainThreadHandler final : public system::IThreadHandler<COpen
226223
egl->call.peglDestroySurface(egl->display, glctx.surface);
227224
}
228225

229-
bool wakeupPredicate() const { return needToBlit; }
230-
bool continuePredicate() const { return needToBlit; }
226+
bool wakeupPredicate() const { return needToBlit.load(); }
227+
bool continuePredicate() const { return needToBlit.load(); }
231228
};
232229

233230
template <typename FunctionTableType>
@@ -236,7 +233,8 @@ const void* COpenGL_Swapchain<FunctionTableType>::getNativeHandle() const { retu
236233
template <typename FunctionTableType>
237234
core::smart_refctd_ptr<COpenGL_Swapchain<FunctionTableType>> COpenGL_Swapchain<FunctionTableType>::create(const core::smart_refctd_ptr<ILogicalDevice>&& logicalDevice, ISwapchain::SCreationParams&& params)
238235
{
239-
if (params.surface->getAPIType() != EAT_OPENGL || (params.presentMode == ISurface::EPM_MAILBOX) || (params.presentMode == ISurface::EPM_UNKNOWN))
236+
// surfaces are only supported by queue family index 0 on opengl
237+
if (!params.surface->isSupportedForPhysicalDevice(logicalDevice->getPhysicalDevice(), 0u) || params.surface->getAPIType() != EAT_OPENGL || (params.presentMode == ISurface::EPM_MAILBOX) || (params.presentMode == ISurface::EPM_UNKNOWN))
240238
return nullptr;
241239

242240
auto device = core::smart_refctd_ptr_static_cast<IOpenGL_LogicalDevice>(logicalDevice);
@@ -281,7 +279,7 @@ core::smart_refctd_ptr<COpenGL_Swapchain<FunctionTableType>> COpenGL_Swapchain<F
281279
device.get(),
282280
params.presentMode,
283281
params.minImageCount, params.width, params.height,
284-
device->getGlFeatures(), { ctx, surface },
282+
{ ctx, surface },
285283
static_cast<COpenGLDebugCallback*>(device->getPhysicalDevice()->getDebugCallback()),
286284
params.surfaceFormat.format
287285
));
@@ -378,7 +376,7 @@ core::smart_refctd_ptr<IGPUImage> COpenGL_Swapchain<FunctionTableType>::createIm
378376
swapchainRef->m_imageIndex = imageIndex;
379377

380378
imgCreationParams.preDestroyCleanup = std::unique_ptr<ICleanup>(swapchainRef.release());
381-
imgCreationParams.importedHandle = true;
379+
imgCreationParams.skipHandleDestroy = true;
382380

383381
return m_threadHandler->createImageAsImported(imageIndex, std::move(imgCreationParams));
384382
}

src/nbl/video/CVulkanBuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace nbl::video
88
CVulkanBuffer::~CVulkanBuffer()
99
{
1010
preDestroyStep();
11-
if (m_cachedCreationParams.importedHandle)
11+
if (m_cachedCreationParams.skipHandleDestroy)
1212
{
1313
const CVulkanLogicalDevice* vulkanDevice = static_cast<const CVulkanLogicalDevice*>(getOriginDevice());
1414
auto* vk = vulkanDevice->getFunctionTable();

src/nbl/video/CVulkanImage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CVulkanImage::~CVulkanImage()
1010
{
1111
preDestroyStep();
1212
// don't destroy imported handles
13-
if (!m_cachedCreationParams.importedHandle)
13+
if (!m_cachedCreationParams.skipHandleDestroy)
1414
{
1515
if (m_vkImage != VK_NULL_HANDLE)
1616
{

src/nbl/video/IOpenGL_LogicalDevice.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -997,19 +997,6 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log
997997
IOpenGL_LogicalDevice(core::smart_refctd_ptr<IAPIConnection>&& api, IPhysicalDevice* physicalDevice, const SCreationParams& params, const egl::CEGL* _egl)
998998
: ILogicalDevice(std::move(api),physicalDevice,params), m_masterContextCallsInvoked(0u), m_masterContextCallsReturned(0u), m_masterContextSync(nullptr), m_egl(_egl) {}
999999

1000-
template <typename FunctionTableType>
1001-
inline uint64_t waitOnMasterContext(FunctionTableType& _gl, const uint64_t waitedCallsSoFar)
1002-
{
1003-
const uint64_t invokedSoFar = m_masterContextCallsInvoked.load();
1004-
assert(invokedSoFar >= waitedCallsSoFar); // something went very wrong with causality
1005-
if (invokedSoFar == waitedCallsSoFar)
1006-
return waitedCallsSoFar;
1007-
uint64_t returnedSoFar;
1008-
while ((returnedSoFar = m_masterContextCallsReturned.load()) < invokedSoFar) {} // waiting on address deadlocks
1009-
_gl.glSync.pglWaitSync(m_masterContextSync.load(), 0, GL_TIMEOUT_IGNORED);
1010-
return returnedSoFar;
1011-
}
1012-
10131000
template <typename FunctionTableType>
10141001
inline uint64_t waitOnMasterContext(FunctionTableType* _gl, const uint64_t waitedCallsSoFar)
10151002
{

0 commit comments

Comments
 (0)