Skip to content

Commit 62353af

Browse files
committed
generate params struct string for subgroup
1 parent 7d99c5b commit 62353af

File tree

4 files changed

+66
-17
lines changed

4 files changed

+66
-17
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (C) 2025 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_SUBGROUP2_ARITHMETIC_PARAMS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_SUBGROUP2_ARITHMETIC_PARAMS_INCLUDED_
6+
7+
8+
#include "nbl/builtin/hlsl/device_capabilities_traits.hlsl"
9+
#include "nbl/builtin/hlsl/concepts.hlsl"
10+
11+
12+
namespace nbl
13+
{
14+
namespace hlsl
15+
{
16+
namespace subgroup2
17+
{
18+
19+
#ifdef __HLSL_VERSION
20+
template<typename Config, class BinOp, int32_t _ItemsPerInvocation=1, class device_capabilities=void NBL_PRIMARY_REQUIRES(is_configuration_v<Config> && is_scalar_v<typename BinOp::type_t>)
21+
struct ArithmeticParams
22+
{
23+
using config_t = Config;
24+
using binop_t = BinOp;
25+
using scalar_t = typename BinOp::type_t;
26+
using type_t = vector<scalar_t, _ItemsPerInvocation>;
27+
using device_traits = device_capabilities_traits<device_capabilities>;
28+
29+
NBL_CONSTEXPR_STATIC_INLINE int32_t ItemsPerInvocation = _ItemsPerInvocation;
30+
NBL_CONSTEXPR_STATIC_INLINE bool UseNativeIntrinsics = device_capabilities_traits<device_capabilities>::shaderSubgroupArithmetic /*&& /*some heuristic for when its faster*/;
31+
// TODO add a IHV enum to device_capabilities_traits to check !is_nvidia
32+
};
33+
#endif
34+
35+
#ifndef __HLSL_VERSION
36+
#include <sstream>
37+
#include <string>
38+
struct SArithmeticParams
39+
{
40+
void init(const uint16_t _SubgroupSizeLog2, const uint16_t _ItemsPerInvocation)
41+
{
42+
SubgroupSizeLog2 = _SubgroupSizeLog2;
43+
ItemsPerInvocation = _ItemsPerInvocation;
44+
}
45+
46+
// alias should provide Binop and device_capabilities template parameters
47+
std::string getParamTemplateStructString()
48+
{
49+
std::ostringstream os;
50+
os << "nbl::hlsl::subgroup2::ArithmeticParams<nbl::hlsl::subgroup2::Configuration<" << SubgroupSizeLog2 << ">, Binop," << ItemsPerInvocation << ", device_capabilities>;";
51+
return os.str();
52+
}
53+
54+
uint32_t SubgroupSizeLog2;
55+
uint32_t ItemsPerInvocation;
56+
};
57+
#endif
58+
59+
}
60+
}
61+
}
62+
63+
#endif

include/nbl/builtin/hlsl/subgroup2/arithmetic_portability.hlsl

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include "nbl/builtin/hlsl/subgroup2/ballot.hlsl"
1111
#include "nbl/builtin/hlsl/subgroup2/arithmetic_portability_impl.hlsl"
12-
#include "nbl/builtin/hlsl/concepts.hlsl"
13-
1412

1513
namespace nbl
1614
{
@@ -19,20 +17,6 @@ namespace hlsl
1917
namespace subgroup2
2018
{
2119

22-
template<typename Config, class BinOp, int32_t _ItemsPerInvocation=1, class device_capabilities=void NBL_PRIMARY_REQUIRES(is_configuration_v<Config> && is_scalar_v<typename BinOp::type_t>)
23-
struct ArithmeticParams
24-
{
25-
using config_t = Config;
26-
using binop_t = BinOp;
27-
using scalar_t = typename BinOp::type_t;
28-
using type_t = vector<scalar_t, _ItemsPerInvocation>;
29-
using device_traits = device_capabilities_traits<device_capabilities>;
30-
31-
NBL_CONSTEXPR_STATIC_INLINE int32_t ItemsPerInvocation = _ItemsPerInvocation;
32-
NBL_CONSTEXPR_STATIC_INLINE bool UseNativeIntrinsics = device_capabilities_traits<device_capabilities>::shaderSubgroupArithmetic /*&& /*some heuristic for when its faster*/;
33-
// TODO add a IHV enum to device_capabilities_traits to check !is_nvidia
34-
};
35-
3620
template<typename Params>
3721
struct reduction : impl::reduction<Params,typename Params::binop_t,Params::ItemsPerInvocation,Params::UseNativeIntrinsics> {};
3822
template<typename Params>

src/nbl/builtin/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup/arithmetic_portabili
332332
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup/fft.hlsl")
333333
#subgroup2
334334
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup2/ballot.hlsl")
335+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup2/arithmetic_params.hlsl")
335336
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup2/arithmetic_portability.hlsl")
336337
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/subgroup2/arithmetic_portability_impl.hlsl")
337338
#shared header between C++ and HLSL
@@ -346,6 +347,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/scratch_size.hlsl")
346347
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/shared_scan.hlsl")
347348
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/shuffle.hlsl")
348349
#workgroup2
350+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup2/basic.hlsl")
349351
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup2/arithmetic_config.hlsl")
350352
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup2/impl/virtual_wg_size_def.hlsl")
351353
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup2/impl/items_per_invoc_def.hlsl")

0 commit comments

Comments
 (0)