Skip to content

Commit c079825

Browse files
committed
Added findMSB and findLSB specialization for enum types
1 parent 889eabe commit c079825

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

include/nbl/asset/ICPUGraphicsPipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ICPUGraphicsPipeline final : public ICPUPipeline<IGraphicsPipeline<ICPUPip
9393

9494
inline int8_t stageToIndex(const ICPUShader::E_SHADER_STAGE stage) const override
9595
{
96-
const auto stageIx = hlsl::findLSB(static_cast<std::underlying_type_t<ICPUShader::E_SHADER_STAGE>>(stage));
96+
const auto stageIx = hlsl::findLSB(stage);
9797
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
9898
return -1;
9999
return stageIx;

include/nbl/asset/ICPURenderpassIndependentPipeline.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
9191
inline IShader::SSpecInfo<ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage)
9292
{
9393
assert(isMutable());
94-
const auto stageIx = hlsl::findLSB(static_cast<std::underlying_type_t<ICPUShader::E_SHADER_STAGE>>(stage));
94+
const auto stageIx = hlsl::findLSB(stage);
9595
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
9696
return {};
9797
return m_infos[stageIx];
9898
}
9999
inline IShader::SSpecInfo<const ICPUShader> getSpecInfo(const ICPUShader::E_SHADER_STAGE stage) const
100100
{
101-
const auto stageIx = hlsl::findLSB(static_cast<std::underlying_type_t<ICPUShader::E_SHADER_STAGE>>(stage));
101+
const auto stageIx = hlsl::findLSB(stage);
102102
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
103103
return {};
104104
return m_infos[stageIx];
@@ -110,7 +110,7 @@ class ICPURenderpassIndependentPipeline : public IRenderpassIndependentPipeline<
110110
if (specSize<0)
111111
return false;
112112
const auto stage = info.shader->getStage();
113-
const auto stageIx = hlsl::findLSB(static_cast<std::underlying_type_t<ICPUShader::E_SHADER_STAGE>>(stage));
113+
const auto stageIx = hlsl::findLSB(stage);
114114
if (stageIx<0 || stageIx>=GRAPHICS_SHADER_STAGE_COUNT || hlsl::bitCount(stage)!=1)
115115
return false;
116116
m_infos[stageIx] = info;

include/nbl/builtin/hlsl/cpp_compat/impl/intrinsics_impl.hlsl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ struct find_msb_helper<vector<int32_t, N> >
153153
}
154154
};
155155

156+
#ifndef __HLSL_VERSION
157+
158+
template<typename EnumType>
159+
requires std::is_enum_v<EnumType>
160+
struct find_msb_helper<EnumType>
161+
{
162+
static int32_t findMSB(NBL_CONST_REF_ARG(EnumType) val)
163+
{
164+
using underlying_t = std::underlying_type_t<EnumType>;
165+
return find_msb_helper<underlying_t>::findMSB(static_cast<underlying_t>(val));
166+
}
167+
};
168+
169+
#endif
170+
156171
template<typename Integer>
157172
struct find_lsb_helper;
158173

@@ -252,6 +267,21 @@ struct find_lsb_helper<vector<uint32_t, N> >
252267
}
253268
};
254269

270+
#ifndef __HLSL_VERSION
271+
272+
template<typename EnumType>
273+
requires std::is_enum_v<EnumType>
274+
struct find_lsb_helper<EnumType>
275+
{
276+
static int32_t findLSB(NBL_CONST_REF_ARG(EnumType) val)
277+
{
278+
using underlying_t = std::underlying_type_t<EnumType>;
279+
return find_lsb_helper<underlying_t>::findLSB(static_cast<underlying_t>(val));
280+
}
281+
};
282+
283+
#endif
284+
255285
template<typename Integer>
256286
struct find_msb_return_type
257287
{

include/nbl/core/util/bitflag.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ namespace nbl::hlsl::cpp_compat_intrinsics_impl
6161
{
6262
static int32_t findLSB(NBL_CONST_REF_ARG(core::bitflag<ENUM_TYPE>) val)
6363
{
64-
using underlying_t = typename core::bitflag<ENUM_TYPE>::UNDERLYING_TYPE;
65-
return find_lsb_helper<underlying_t>::findLSB(static_cast<underlying_t>(val.value));
64+
return find_lsb_helper<ENUM_TYPE>::findLSB(val.value);
6665
}
6766
};
6867

@@ -71,8 +70,7 @@ namespace nbl::hlsl::cpp_compat_intrinsics_impl
7170
{
7271
static int32_t findMSB(NBL_CONST_REF_ARG(core::bitflag<ENUM_TYPE>) val)
7372
{
74-
using underlying_t = typename core::bitflag<ENUM_TYPE>::UNDERLYING_TYPE;
75-
return find_msb_helper<underlying_t>::findMSB(static_cast<underlying_t>(val.value));
73+
return find_msb_helper<ENUM_TYPE>::findMSB(val.value);
7674
}
7775
};
7876
}

src/nbl/video/CVulkanGraphicsPipeline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CVulkanGraphicsPipeline final : public IGPUGraphicsPipeline
1919
for (const auto& info : params.shaders)
2020
if (info.shader)
2121
{
22-
const auto stageIx = hlsl::findLSB(static_cast<std::underlying_type_t<asset::IShader::E_SHADER_STAGE>>(info.shader->getStage()));
22+
const auto stageIx = hlsl::findLSB(info.shader->getStage());
2323
m_shaders[stageIx] = core::smart_refctd_ptr<const CVulkanShader>(static_cast<const CVulkanShader*>(info.shader));
2424
}
2525
}

src/nbl/video/utilities/CAssetConverter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ class GetDependantVisit<ICPUComputePipeline> : public GetDependantVisitBase<ICPU
15091509
inline auto& getSpecInfo(const IShader::E_SHADER_STAGE stage)
15101510
{
15111511
assert(hlsl::bitCount(stage)==1);
1512-
return specInfo[hlsl::findLSB(static_cast<std::underlying_type_t<IShader::E_SHADER_STAGE>>(stage))];
1512+
return specInfo[hlsl::findLSB(stage)];
15131513
}
15141514

15151515
// ok to do non owning since some cache owns anyway
@@ -1557,7 +1557,7 @@ class GetDependantVisit<ICPUGraphicsPipeline> : public GetDependantVisitBase<ICP
15571557
inline auto& getSpecInfo(const IShader::E_SHADER_STAGE stage)
15581558
{
15591559
assert(hlsl::bitCount(stage)==1);
1560-
return specInfo[hlsl::findLSB(static_cast<std::underlying_type_t<IShader::E_SHADER_STAGE>>(stage))];
1560+
return specInfo[hlsl::findLSB(stage)];
15611561
}
15621562

15631563
// ok to do non owning since some cache owns anyway

0 commit comments

Comments
 (0)