Skip to content

Commit f1086b0

Browse files
committed
static_casts replaced for compatibility_cast on Vulkan Objects
1 parent 8cd3223 commit f1086b0

File tree

7 files changed

+109
-110
lines changed

7 files changed

+109
-110
lines changed

include/nbl/video/decl/IBackendObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IBackendObject
4242
static inline derived_t_ptr compatibility_cast(base_t_ptr base, const other_t_ptr& compatibleWith)
4343
{
4444
using other_t = std::remove_pointer_t<other_t_ptr>;
45-
static_assert(std::is_base_of_v<IBackendObject, other_t>,"other_t_ptr should be derived from IBackendObject");
45+
static_assert(std::is_base_of_v<IBackendObject, other_t>,"other_t should be derived from IBackendObject");
4646
return device_compatibility_cast<derived_t_ptr,base_t_ptr>(base,compatibleWith->getOriginDevice());
4747
}
4848

src/nbl/video/CVulkanCommandBuffer.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace nbl::video
8989

9090
// Add Refs of BuildInfo to CmdPool
9191
auto tmp = getBuildGeometryInfoReferences(infos[i]);
92-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
92+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
9393
vulkanCommandPool->emplace_n(m_argListTail, tmp.data(), tmp.data() + tmp.size());
9494
}
9595

@@ -149,7 +149,7 @@ namespace nbl::video
149149

150150
// Add Refs of BuildInfo to CmdPool
151151
auto tmp = getBuildGeometryInfoReferences(infos[i]);
152-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
152+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
153153
vulkanCommandPool->emplace_n(m_argListTail, tmp.data(), tmp.data() + tmp.size());
154154
}
155155

@@ -182,7 +182,7 @@ namespace nbl::video
182182
core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.src),
183183
core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.dst),
184184
};
185-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
185+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
186186
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 2);
187187

188188

@@ -215,7 +215,7 @@ namespace nbl::video
215215
copyInfo.dst.buffer,
216216
core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.src),
217217
};
218-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
218+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
219219
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 2);
220220

221221
VkCopyAccelerationStructureToMemoryInfoKHR info = CVulkanAccelerationStructure::getVkASCopyToMemoryInfo(vk_device, vk, copyInfo);
@@ -247,7 +247,7 @@ namespace nbl::video
247247
copyInfo.src.buffer,
248248
core::smart_refctd_ptr<const IGPUAccelerationStructure>(copyInfo.dst),
249249
};
250-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
250+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
251251
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 2);
252252

253253
VkCopyMemoryToAccelerationStructureInfoKHR info = CVulkanAccelerationStructure::getVkASCopyFromMemoryInfo(vk_device, vk, copyInfo);
@@ -266,10 +266,10 @@ namespace nbl::video
266266

267267
// Add Ref to CmdPool
268268
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
269-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
269+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
270270
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
271271

272-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
272+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
273273
vk->vk.vkCmdResetQueryPool(m_cmdbuf, vk_queryPool, firstQuery, queryCount);
274274
ret = true;
275275
}
@@ -285,10 +285,10 @@ namespace nbl::video
285285

286286
// Add Ref to CmdPool
287287
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
288-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
288+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
289289
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
290290

291-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
291+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
292292
auto vk_flags = CVulkanQueryPool::getVkQueryControlFlagsFromQueryControlFlags(flags);
293293
vk->vk.vkCmdBeginQuery(m_cmdbuf, vk_queryPool, query, vk_flags);
294294
ret = true;
@@ -305,10 +305,10 @@ namespace nbl::video
305305

306306
// Add Ref to CmdPool
307307
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
308-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
308+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
309309
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
310310

311-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
311+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
312312
vk->vk.vkCmdEndQuery(m_cmdbuf, vk_queryPool, query);
313313
ret = true;
314314
}
@@ -328,11 +328,11 @@ namespace nbl::video
328328
core::smart_refctd_ptr<const IQueryPool>(queryPool),
329329
core::smart_refctd_ptr<const buffer_t>(dstBuffer),
330330
};
331-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
331+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
332332
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 2);
333333

334-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
335-
auto vk_dstBuffer = static_cast<CVulkanBuffer*>(dstBuffer)->getInternalObject();
334+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
335+
auto vk_dstBuffer = IBackendObject::compatibility_cast<CVulkanBuffer*>(dstBuffer, this)->getInternalObject();
336336
auto vk_queryResultsFlags = CVulkanQueryPool::getVkQueryResultsFlagsFromQueryResultsFlags(flags);
337337
vk->vk.vkCmdCopyQueryPoolResults(m_cmdbuf, vk_queryPool, firstQuery, queryCount, vk_dstBuffer, dstOffset, static_cast<VkDeviceSize>(stride), vk_queryResultsFlags);
338338
ret = true;
@@ -349,10 +349,10 @@ namespace nbl::video
349349

350350
// Add Ref to CmdPool
351351
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
352-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
352+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
353353
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
354354

355-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
355+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
356356
auto vk_pipelineStage = static_cast<VkPipelineStageFlagBits>(pipelineStage); // am I doing this right?
357357

358358
vk->vk.vkCmdWriteTimestamp(m_cmdbuf, vk_pipelineStage, vk_queryPool, query);
@@ -372,10 +372,10 @@ namespace nbl::video
372372

373373
// Add Ref to CmdPool
374374
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
375-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
375+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
376376
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
377377

378-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
378+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
379379
auto vk_flags = CVulkanQueryPool::getVkQueryControlFlagsFromQueryControlFlags(flags);
380380
vk->vk.vkCmdBeginQueryIndexedEXT(m_cmdbuf, vk_queryPool, query, vk_flags, index);
381381
ret = true;
@@ -393,10 +393,10 @@ namespace nbl::video
393393

394394
// Add Ref to CmdPool
395395
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
396-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
396+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
397397
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
398398

399-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
399+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
400400
vk->vk.vkCmdEndQueryIndexedEXT(m_cmdbuf, vk_queryPool, query, index);
401401
ret = true;
402402
}
@@ -409,11 +409,10 @@ namespace nbl::video
409409
bool ret = false;
410410
if(queryPool != nullptr && pAccelerationStructures.empty() == false)
411411
{
412-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
412+
CVulkanCommandPool* vulkanCommandPool = IBackendObject::compatibility_cast<CVulkanCommandPool*>(m_cmdpool.get(), this);
413413
{
414414
// Add Ref to CmdPool
415415
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[1] = { core::smart_refctd_ptr<const IQueryPool>(queryPool) };
416-
CVulkanCommandPool* vulkanCommandPool = static_cast<CVulkanCommandPool*>(m_cmdpool.get());
417416
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
418417
}
419418

@@ -427,7 +426,7 @@ namespace nbl::video
427426
core::smart_refctd_ptr<const core::IReferenceCounted> tmpRefCntd[MaxAccelerationStructureCount];
428427
for(size_t i = 0; i < asCount; ++i)
429428
{
430-
vk_accelerationStructures[i] = static_cast<CVulkanAccelerationStructure*>(&accelerationStructures[i])->getInternalObject();
429+
vk_accelerationStructures[i] = IBackendObject::compatibility_cast<CVulkanAccelerationStructure*>(&accelerationStructures[i], this)->getInternalObject();
431430
// Add Refs to CmdPool
432431
tmpRefCntd[i] = core::smart_refctd_ptr<const IGPUAccelerationStructure>(&accelerationStructures[i]);
433432
}
@@ -436,7 +435,7 @@ namespace nbl::video
436435

437436
const auto* vk = static_cast<const CVulkanLogicalDevice*>(getOriginDevice())->getFunctionTable();
438437

439-
auto vk_queryPool = static_cast<CVulkanQueryPool*>(queryPool)->getInternalObject();
438+
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
440439
auto vk_queryType = CVulkanQueryPool::getVkQueryTypeFromQueryType(queryType);
441440
vk->vk.vkCmdWriteAccelerationStructuresPropertiesKHR(m_cmdbuf, asCount, vk_accelerationStructures, vk_queryType, vk_queryPool, firstQuery);
442441
ret = true;

0 commit comments

Comments
 (0)