|
5 | 5 | #define _NBL_BUILTIN_HLSL_FUNCTIONAL_INCLUDED_
|
6 | 6 |
|
7 | 7 |
|
8 |
| -#include "nbl/builtin/hlsl/bit.hlsl" |
| 8 | +#include "nbl/builtin/hlsl/glsl_compat/core.hlsl" |
9 | 9 | #include "nbl/builtin/hlsl/limits.hlsl"
|
10 | 10 |
|
11 | 11 |
|
12 | 12 | namespace nbl
|
13 | 13 | {
|
14 | 14 | namespace hlsl
|
15 | 15 | {
|
| 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 | + |
16 | 71 | #ifndef __HLSL_VERSION // CPP
|
17 | 72 | #define ALIAS_STD(NAME,OP) template<typename T> struct NAME : std::NAME<T> { \
|
18 | 73 | using type_t = T;
|
|
0 commit comments