|
| 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 |
0 commit comments