Skip to content

Commit 2e6bffa

Browse files
committed
Added OpIAddCarry and OpISubBorrow intrinsics
1 parent 62b4be3 commit 2e6bffa

File tree

4 files changed

+49
-4
lines changed

4 files changed

+49
-4
lines changed

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
#ifndef _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_CORE_INCLUDED_
55
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_CORE_INCLUDED_
66

7-
87
#ifdef __HLSL_VERSION // TODO: AnastZIuk fix public search paths so we don't choke
98
#include "spirv/unified1/spirv.hpp"
109

1110
#include <nbl/builtin/hlsl/vector_utils/vector_traits.hlsl>
12-
#include "nbl/builtin/hlsl/type_traits.hlsl"
11+
#include <nbl/builtin/hlsl/type_traits.hlsl>
1312
#include <nbl/builtin/hlsl/concepts.hlsl>
13+
#include <nbl/builtin/hlsl/spirv_intrinsics/output_structs.hlsl>
1414

1515
namespace nbl
1616
{
@@ -300,6 +300,14 @@ template<typename BooleanVector>
300300
[[vk::ext_instruction(spv::OpAny)]]
301301
enable_if_t<is_vector_v<BooleanVector>&& is_same_v<typename vector_traits<BooleanVector>::scalar_type, bool>, BooleanVector> any(BooleanVector vec);
302302

303+
template<typename T NBL_FUNC_REQUIRES(concepts::UnsignedIntegral<T>)
304+
[[vk::ext_instruction(spv::OpIAddCarry)]]
305+
AddCarryOutput<T> AddCarry(T operand1, T operand2);
306+
307+
template<typename T NBL_FUNC_REQUIRES(concepts::UnsignedIntegral<T>)
308+
[[vk::ext_instruction(spv::OpISubBorrow)]]
309+
SubBorrowOutput<T> SubBorrow(T operand1, T operand2);
310+
303311
}
304312

305313
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2023 - 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_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
6+
7+
#include <nbl/builtin/hlsl/concepts/core.hlsl>
8+
9+
namespace nbl
10+
{
11+
namespace hlsl
12+
{
13+
14+
template<typename T NBL_STRUCT_CONSTRAINABLE>
15+
struct AddCarryOutput;
16+
template<typename T NBL_STRUCT_CONSTRAINABLE>
17+
struct SubBorrowOutput;
18+
19+
20+
template<typename T> NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegral<T>)
21+
struct AddCarryOutput<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegral<T>) >
22+
{
23+
T result;
24+
T carry;
25+
};
26+
27+
template<typename T> NBL_PARTIAL_REQ_TOP(concepts::UnsignedIntegral<T>)
28+
struct SubBorrowOutput<T NBL_PARTIAL_REQ_BOT(concepts::UnsignedIntegral<T>) >
29+
{
30+
T result;
31+
T borrow;
32+
};
33+
}
34+
}
35+
36+
#endif

include/nbl/builtin/hlsl/tgmath/output_structs.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (C) 2023 - DevSH Graphics Programming Sp. z O.O.
22
// This file is part of the "Nabla Engine".
33
// For conditions of distribution and use, see copyright notice in nabla.h
4-
#ifndef _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
5-
#define _NBL_BUILTIN_HLSL_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
4+
#ifndef _NBL_BUILTIN_HLSL_TGMATH_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_TGMATH_SPIRV_INTRINSICS_OUTPUT_STRUCTS_INCLUDED_
66

77
#include <nbl/builtin/hlsl/concepts/core.hlsl>
88
#include <nbl/builtin/hlsl/concepts/vector.hlsl>

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_bas
238238
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_shuffle.hlsl")
239239
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/subgroup_vote.hlsl")
240240
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/glsl.std.450.hlsl")
241+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/spirv_intrinsics/output_structs.hlsl")
241242
#C++ compatibility
242243
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat.hlsl")
243244
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/cpp_compat/basic.h")

0 commit comments

Comments
 (0)