Skip to content

Commit 0580adb

Browse files
author
devsh
committed
AND WE HAVE REFERENCES IN HLSL!
1 parent 30e6bbf commit 0580adb

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

include/nbl/builtin/hlsl/functional.hlsl

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,69 @@
55
#define _NBL_BUILTIN_HLSL_FUNCTIONAL_INCLUDED_
66

77

8-
#include "nbl/builtin/hlsl/bit.hlsl"
8+
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
99
#include "nbl/builtin/hlsl/limits.hlsl"
1010

1111

1212
namespace nbl
1313
{
1414
namespace hlsl
1515
{
16+
template<uint32_t StorageClass, typename T>
17+
using __spv_ptr_t = spirv::pointer_t<StorageClass,T>;
18+
19+
template<uint32_t StorageClass, typename T>
20+
[[vk::ext_instruction(spv::OpCopyObject)]]
21+
__spv_ptr_t<StorageClass,T> addrof([[vk::ext_reference]] T v);
22+
23+
template<uint32_t StorageClass, typename T>
24+
struct reference_wrapper_base
25+
{
26+
using spv_ptr_t = __spv_ptr_t<StorageClass,T>;
27+
spv_ptr_t ptr;
28+
29+
void __init(spv_ptr_t _ptr)
30+
{
31+
ptr = _ptr;
32+
}
33+
34+
T load()
35+
{
36+
return spirv::load<T,spv_ptr_t>(ptr);
37+
}
38+
39+
void store(const T val)
40+
{
41+
spirv::store<T,spv_ptr_t>(ptr,val);
42+
}
43+
44+
// TODO: use the same defaults as `glsl::atomicAnd`
45+
template<uint32_t memoryScope, uint32_t memorySemantics, typename S=T>
46+
// TODO: instead of `is_scalar_v` we need a test on whether the `spirv::atomicAnd` expression is callable
47+
enable_if_t<is_same_v<S,T>&&is_scalar_v<S>,T> atomicAnd(const T value)
48+
{
49+
return spirv::atomicAnd<T,spv_ptr_t>(ptr,memoryScope,memorySemantics,value);
50+
}
51+
// TODO: generate Or,Xor through a macro
52+
53+
// TODO: comp swap is special, has an extra parameter
54+
};
55+
template<typename T>
56+
struct reference_wrapper_base<spv::StorageClassPhysicalStorageBuffer,T>
57+
{
58+
using spv_ptr_t = typename T::instead_use_nbl::hlsl::bda::__ref;
59+
60+
// normally would have specializations of load and store
61+
};
62+
63+
template<uint32_t StorageClass, typename T>
64+
struct reference_wrapper : reference_wrapper_base<StorageClass,T>
65+
{
66+
};
67+
// TODO: generate atomic Add,Sub,Min,Max through partial template specializations on T
68+
// TODO: partial specializations for T being a special SPIR-V type for image ops, etc.
69+
70+
1671
#ifndef __HLSL_VERSION // CPP
1772
#define ALIAS_STD(NAME,OP) template<typename T> struct NAME : std::NAME<T> { \
1873
using type_t = T;

0 commit comments

Comments
 (0)