Skip to content

Commit 30e6aae

Browse files
committed
Bitflag usages for QueryPool functions and enum changes
+ moved PipelineStageFlags vulkan conversion via static assert to CVulkanCommon
1 parent a581a05 commit 30e6aae

13 files changed

+48
-39
lines changed

include/nbl/asset/ICommandBuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ class ICommandBuffer
309309
virtual bool bindComputePipeline(const compute_pipeline_t* pipeline) = 0;
310310

311311
virtual bool resetQueryPool(video::IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount) {return false;}
312-
virtual bool beginQuery(video::IQueryPool* queryPool, uint32_t query, video::IQueryPool::E_QUERY_CONTROL_FLAGS flags = static_cast<video::IQueryPool::E_QUERY_CONTROL_FLAGS>(0)) {return false;}
312+
virtual bool beginQuery(video::IQueryPool* queryPool, uint32_t query, core::bitflag<video::IQueryPool::E_QUERY_CONTROL_FLAGS> flags = video::IQueryPool::E_QUERY_CONTROL_FLAGS::EQCF_NONE) {return false;}
313313
virtual bool endQuery(video::IQueryPool* queryPool, uint32_t query) {return false;}
314-
virtual bool copyQueryPoolResults(video::IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, video::IQueryPool::E_QUERY_RESULTS_FLAGS flags) {return false;}
314+
virtual bool copyQueryPoolResults(video::IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, core::bitflag<video::IQueryPool::E_QUERY_RESULTS_FLAGS> flags) {return false;}
315315
virtual bool writeTimestamp(asset::E_PIPELINE_STAGE_FLAGS pipelineStage, video::IQueryPool* queryPool, uint32_t query) {return false;}
316316

317317
// Acceleration Structure Properties (Only available on Vulkan)

include/nbl/video/ILogicalDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ class ILogicalDevice : public core::IReferenceCounted
609609

610610
virtual core::smart_refctd_ptr<IQueryPool> createQueryPool(IQueryPool::SCreationParams&& params) { return nullptr; }
611611

612-
virtual bool getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags) { return false;}
612+
virtual bool getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, core::bitflag<IQueryPool::E_QUERY_RESULTS_FLAGS> flags) { return false;}
613613

614614
virtual bool buildAccelerationStructures(
615615
core::smart_refctd_ptr<IDeferredOperation>&& deferredOperation,

include/nbl/video/IQueryPool.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class IQueryPool : public core::IReferenceCounted, public IBackendObject
2323

2424
enum E_PIPELINE_STATISTICS_FLAGS
2525
{
26+
EPSF_NONE = 0,
2627
EPSF_INPUT_ASSEMBLY_VERTICES_BIT = 0x00000001,
2728
EPSF_INPUT_ASSEMBLY_PRIMITIVES_BIT = 0x00000002,
2829
EPSF_VERTEX_SHADER_INVOCATIONS_BIT = 0x00000004,
@@ -38,6 +39,7 @@ class IQueryPool : public core::IReferenceCounted, public IBackendObject
3839

3940
enum E_QUERY_RESULTS_FLAGS
4041
{
42+
EQRF_NONE = 0,
4143
EQRF_64_BIT = 0x00000001,
4244
EQRF_WAIT_BIT = 0x00000002,
4345
EQRF_WITH_AVAILABILITY_BIT = 0x00000004,
@@ -46,14 +48,15 @@ class IQueryPool : public core::IReferenceCounted, public IBackendObject
4648

4749
enum E_QUERY_CONTROL_FLAGS : uint32_t
4850
{
49-
EQCF_PRECISE_BIT = 0x01
51+
EQCF_NONE = 0,
52+
EQCF_PRECISE_BIT = 0x01,
5053
};
5154

5255
struct SCreationParams
5356
{
54-
E_QUERY_TYPE queryType;
55-
uint32_t queryCount;
56-
E_PIPELINE_STATISTICS_FLAGS pipelineStatisticsFlags; // only when the queryType is EQT_PIPELINE_STATISTICS
57+
E_QUERY_TYPE queryType;
58+
uint32_t queryCount;
59+
core::bitflag<E_PIPELINE_STATISTICS_FLAGS> pipelineStatisticsFlags; // only when the queryType is EQT_PIPELINE_STATISTICS
5760
};
5861

5962
public:

src/nbl/video/COpenGLCommandBuffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
927927
{
928928
auto& c = cmd.get<impl::ECT_BEGIN_QUERY>();
929929
const COpenGLQueryPool* qp = static_cast<const COpenGLQueryPool*>(c.queryPool.get());
930-
qp->beginQuery(gl, c.query, c.flags);
930+
qp->beginQuery(gl, c.query, c.flags.value);
931931
}
932932
break;
933933
case impl::ECT_END_QUERY:
@@ -951,10 +951,10 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
951951
auto queries = queriesRange.begin();
952952

953953
IQueryPool::E_QUERY_TYPE queryType = qp->getCreationParameters().queryType;
954-
bool use64Version = (c.flags & IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_64_BIT) == IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_64_BIT;
955-
bool availabilityFlag = (c.flags & IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WITH_AVAILABILITY_BIT) == IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WITH_AVAILABILITY_BIT;
956-
bool waitForAllResults = (c.flags & IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WAIT_BIT) == IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WAIT_BIT;
957-
bool partialResults = (c.flags & IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_PARTIAL_BIT) == IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_PARTIAL_BIT;
954+
bool use64Version = c.flags.hasValue(IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_64_BIT);
955+
bool availabilityFlag = c.flags.hasValue(IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WITH_AVAILABILITY_BIT);
956+
bool waitForAllResults = c.flags.hasValue(IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_WAIT_BIT);
957+
bool partialResults = c.flags.hasValue(IQueryPool::E_QUERY_RESULTS_FLAGS::EQRF_PARTIAL_BIT);
958958

959959
if(c.firstQuery + c.queryCount > queryPoolQueriesCount)
960960
{

src/nbl/video/COpenGLCommandBuffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ namespace impl
310310
{
311311
core::smart_refctd_ptr<const IQueryPool> queryPool;
312312
uint32_t query;
313-
IQueryPool::E_QUERY_CONTROL_FLAGS flags;
313+
core::bitflag<IQueryPool::E_QUERY_CONTROL_FLAGS> flags;
314314
};
315315
_NBL_DEFINE_SCMD_SPEC(ECT_END_QUERY)
316316
{
@@ -325,7 +325,7 @@ namespace impl
325325
core::smart_refctd_ptr<const IGPUBuffer> dstBuffer;
326326
size_t dstOffset;
327327
size_t stride;
328-
IQueryPool::E_QUERY_RESULTS_FLAGS flags;
328+
core::bitflag<IQueryPool::E_QUERY_RESULTS_FLAGS> flags;
329329
};
330330
_NBL_DEFINE_SCMD_SPEC(ECT_WRITE_TIMESTAMP)
331331
{
@@ -1066,7 +1066,7 @@ class COpenGLCommandBuffer final : public IGPUCommandBuffer
10661066
pushCommand(std::move(cmd));
10671067
return true;
10681068
}
1069-
bool beginQuery(IQueryPool* queryPool, uint32_t query, IQueryPool::E_QUERY_CONTROL_FLAGS flags = static_cast<IQueryPool::E_QUERY_CONTROL_FLAGS>(0)) override
1069+
bool beginQuery(IQueryPool* queryPool, uint32_t query, core::bitflag<video::IQueryPool::E_QUERY_CONTROL_FLAGS> flags) override
10701070
{
10711071
if (!this->isCompatibleDevicewise(queryPool))
10721072
return false;
@@ -1087,7 +1087,7 @@ class COpenGLCommandBuffer final : public IGPUCommandBuffer
10871087
pushCommand(std::move(cmd));
10881088
return true;
10891089
}
1090-
bool copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags) override
1090+
bool copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, core::bitflag<video::IQueryPool::E_QUERY_RESULTS_FLAGS> flags) override
10911091
{
10921092
if (!this->isCompatibleDevicewise(queryPool))
10931093
return false;

src/nbl/video/COpenGL_LogicalDevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice
416416
return retval;
417417
}
418418

419-
bool getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags) override
419+
bool getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, core::bitflag<IQueryPool::E_QUERY_RESULTS_FLAGS> flags) override
420420
{
421421
SRequestGetQueryPoolResults req_params;
422422
req_params.queryPool = core::smart_refctd_ptr<const IQueryPool>(queryPool);

src/nbl/video/CVulkanCommandBuffer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ namespace nbl::video
276276
return ret;
277277
}
278278

279-
bool CVulkanCommandBuffer::beginQuery(IQueryPool* queryPool, uint32_t query, IQueryPool::E_QUERY_CONTROL_FLAGS flags)
279+
bool CVulkanCommandBuffer::beginQuery(IQueryPool* queryPool, uint32_t query, core::bitflag<IQueryPool::E_QUERY_CONTROL_FLAGS> flags)
280280
{
281281
bool ret = false;
282282
if(queryPool != nullptr)
@@ -289,7 +289,7 @@ namespace nbl::video
289289
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
290290

291291
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
292-
auto vk_flags = CVulkanQueryPool::getVkQueryControlFlagsFromQueryControlFlags(flags);
292+
auto vk_flags = CVulkanQueryPool::getVkQueryControlFlagsFromQueryControlFlags(flags.value);
293293
vk->vk.vkCmdBeginQuery(m_cmdbuf, vk_queryPool, query, vk_flags);
294294
ret = true;
295295
}
@@ -315,7 +315,7 @@ namespace nbl::video
315315
return ret;
316316
}
317317

318-
bool CVulkanCommandBuffer::copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags)
318+
bool CVulkanCommandBuffer::copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, core::bitflag<IQueryPool::E_QUERY_RESULTS_FLAGS> flags)
319319
{
320320
bool ret = false;
321321
if(queryPool != nullptr && dstBuffer != nullptr)
@@ -333,7 +333,7 @@ namespace nbl::video
333333

334334
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
335335
auto vk_dstBuffer = IBackendObject::compatibility_cast<CVulkanBuffer*>(dstBuffer, this)->getInternalObject();
336-
auto vk_queryResultsFlags = CVulkanQueryPool::getVkQueryResultsFlagsFromQueryResultsFlags(flags);
336+
auto vk_queryResultsFlags = CVulkanQueryPool::getVkQueryResultsFlagsFromQueryResultsFlags(flags.value);
337337
vk->vk.vkCmdCopyQueryPoolResults(m_cmdbuf, vk_queryPool, firstQuery, queryCount, vk_dstBuffer, dstOffset, static_cast<VkDeviceSize>(stride), vk_queryResultsFlags);
338338
ret = true;
339339
}
@@ -353,9 +353,10 @@ namespace nbl::video
353353
vulkanCommandPool->emplace_n(m_argListTail, tmpRefCntd, tmpRefCntd + 1);
354354

355355
auto vk_queryPool = IBackendObject::compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
356-
auto vk_pipelineStage = static_cast<VkPipelineStageFlagBits>(pipelineStage); // am I doing this right?
356+
assert(core::isPoT(static_cast<uint32_t>(pipelineStage))); // should only be 1 stage (1 bit set)
357+
auto vk_pipelineStageFlagBit = static_cast<VkPipelineStageFlagBits>(getVkPipelineStageFlagsFromPipelineStageFlags(pipelineStage));
357358

358-
vk->vk.vkCmdWriteTimestamp(m_cmdbuf, vk_pipelineStage, vk_queryPool, query);
359+
vk->vk.vkCmdWriteTimestamp(m_cmdbuf, vk_pipelineStageFlagBit, vk_queryPool, query);
359360
ret = true;
360361
}
361362
return ret;

src/nbl/video/CVulkanCommandBuffer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
771771
vk->vk.vkCmdResetEvent(
772772
m_cmdbuf,
773773
IBackendObject::compatibility_cast<const CVulkanEvent*>(event, this)->getInternalObject(),
774-
static_cast<VkPipelineStageFlags>(stageMask));
774+
getVkPipelineStageFlagsFromPipelineStageFlags(stageMask));
775775

776776
return true;
777777
}
@@ -952,8 +952,8 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
952952
}
953953

954954
const auto* vk = static_cast<const CVulkanLogicalDevice*>(getOriginDevice())->getFunctionTable();
955-
vk->vk.vkCmdPipelineBarrier(m_cmdbuf, static_cast<VkPipelineStageFlags>(srcStageMask.value),
956-
static_cast<VkPipelineStageFlags>(dstStageMask.value),
955+
vk->vk.vkCmdPipelineBarrier(m_cmdbuf, getVkPipelineStageFlagsFromPipelineStageFlags(srcStageMask.value),
956+
getVkPipelineStageFlagsFromPipelineStageFlags(dstStageMask.value),
957957
static_cast<VkDependencyFlags>(dependencyFlags.value),
958958
memoryBarrierCount, vk_memoryBarriers,
959959
bufferMemoryBarrierCount, vk_bufferMemoryBarriers,
@@ -1051,9 +1051,9 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer
10511051

10521052

10531053
bool resetQueryPool(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount) override;
1054-
bool beginQuery(IQueryPool* queryPool, uint32_t query, IQueryPool::E_QUERY_CONTROL_FLAGS flags = static_cast<IQueryPool::E_QUERY_CONTROL_FLAGS>(0)) override;
1054+
bool beginQuery(IQueryPool* queryPool, uint32_t query, core::bitflag<video::IQueryPool::E_QUERY_CONTROL_FLAGS>) override;
10551055
bool endQuery(IQueryPool* queryPool, uint32_t query) override;
1056-
bool copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags) override;
1056+
bool copyQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, buffer_t* dstBuffer, size_t dstOffset, size_t stride, core::bitflag<video::IQueryPool::E_QUERY_RESULTS_FLAGS> flags) override;
10571057
bool writeTimestamp(asset::E_PIPELINE_STAGE_FLAGS pipelineStage, IQueryPool* queryPool, uint32_t query) override;
10581058

10591059
// Acceleration Structure Properties (Only available on Vulkan)

src/nbl/video/CVulkanCommon.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,11 @@ static inline VkColorComponentFlags getVkColorComponentFlagsFromColorWriteMask(c
683683
return static_cast<VkColorComponentFlags>(in);
684684
}
685685

686+
static inline VkPipelineStageFlags getVkPipelineStageFlagsFromPipelineStageFlags(const asset::E_PIPELINE_STAGE_FLAGS in)
687+
{
688+
return static_cast<VkPipelineStageFlags>(in);
689+
}
690+
686691
}
687692

688693
#define __NBL_VIDEO_C_VULKAN_COMMON_H_INCLUDED__

src/nbl/video/CVulkanLogicalDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,13 +912,13 @@ core::smart_refctd_ptr<IQueryPool> CVulkanLogicalDevice::createQueryPool(IQueryP
912912
return core::make_smart_refctd_ptr<CVulkanQueryPool>(core::smart_refctd_ptr<CVulkanLogicalDevice>(this), std::move(params), vk_queryPool);
913913
}
914914

915-
bool CVulkanLogicalDevice::getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, IQueryPool::E_QUERY_RESULTS_FLAGS flags)
915+
bool CVulkanLogicalDevice::getQueryPoolResults(IQueryPool* queryPool, uint32_t firstQuery, uint32_t queryCount, size_t dataSize, void * pData, uint64_t stride, core::bitflag<IQueryPool::E_QUERY_RESULTS_FLAGS> flags)
916916
{
917917
bool ret = false;
918918
if(queryPool != nullptr)
919919
{
920920
auto vk_queryPool = IBackendObject::device_compatibility_cast<CVulkanQueryPool*>(queryPool, this)->getInternalObject();
921-
auto vk_queryResultsflags = CVulkanQueryPool::getVkQueryResultsFlagsFromQueryResultsFlags(flags);
921+
auto vk_queryResultsflags = CVulkanQueryPool::getVkQueryResultsFlagsFromQueryResultsFlags(flags.value);
922922
auto vk_res = m_devf.vk.vkGetQueryPoolResults(m_vkdev, vk_queryPool, firstQuery, queryCount, dataSize, pData, static_cast<VkDeviceSize>(stride), vk_queryResultsflags);
923923
if(VK_SUCCESS == vk_res)
924924
ret = true;

0 commit comments

Comments
 (0)