Skip to content

Commit 0a7e924

Browse files
author
devsh
committed
juicy address-of operator incoming!
1 parent 6be8aec commit 0a7e924

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

include/nbl/builtin/hlsl/bda/__ref.hlsl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ namespace nbl
1212
{
1313
namespace hlsl
1414
{
15+
16+
// TODO: make a common `nbl/builtin/hlsl/__ref.hlsl`
17+
// TODO: also refactor `bda::__base_ref` into just `__ref` and make it a typedef
18+
template<uint32_t StorageClass, typename T>
19+
using __spv_ptr_t = spirv::pointer_t<StorageClass,T>;
20+
21+
template<uint32_t StorageClass, typename T>
22+
[[vk::ext_instruction(spv::OpCopyObject)]]
23+
__spv_ptr_t<StorageClass,T> addrof([[vk::ext_reference]] T v);
24+
1525
namespace bda
1626
{
1727
template<typename T>
18-
using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer, T>;
28+
using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer,T>;
1929

2030
template<typename T>
2131
struct __ptr;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ using pointer_t = vk::SpirvOpaqueType<spv::OpTypePointer,vk::Literal<vk::integra
5454

5555
//! General Operations
5656

57+
// The holy operation that makes addrof possible
58+
template<uint32_t StorageClass, typename T>
59+
[[vk::ext_instruction(spv::OpCopyObject)]]
60+
pointer_t<StorageClass,T> copyObject([[vk::ext_reference]] T v);
61+
5762
// Here's the thing with atomics, it's not only the data type that dictates whether you can do an atomic or not.
5863
// It's the storage class that has the most effect (shared vs storage vs image) and we can't check that easily
5964
template<typename T> // integers operate on 2s complement so same op for signed and unsigned

0 commit comments

Comments
 (0)