Skip to content

Commit 30e6bbf

Browse files
author
devsh
committed
add OpLoad and OpStore SPIR-V intrinsics for non-BDA pointer types
Also note that `nbl::hlsl::bit_cast` needs a lot of fixing
1 parent e5104e7 commit 30e6bbf

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

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

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
// Copyright (C) 2018-2024 - 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-
5-
#include "nbl/builtin/hlsl/cpp_compat.hlsl"
6-
#include "nbl/builtin/hlsl/spirv_intrinsics/core.hlsl"
7-
84
#ifndef _NBL_BUILTIN_HLSL_BDA_REF_INCLUDED_
95
#define _NBL_BUILTIN_HLSL_BDA_REF_INCLUDED_
106

7+
#include "nbl/builtin/hlsl/functional.hlsl"
8+
119
namespace nbl
1210
{
1311
namespace hlsl
1412
{
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-
2513
namespace bda
2614
{
2715
template<typename T>
@@ -30,6 +18,7 @@ using __spv_ptr_t = spirv::pointer_t<spv::StorageClassPhysicalStorageBuffer,T>;
3018
template<typename T>
3119
struct __ptr;
3220

21+
// TODO: refactor this in terms of `nbl::hlsl::` when they fix the composite struct inline SPIR-V BDA issue
3322
template<typename T, uint32_t alignment, bool _restrict>
3423
struct __base_ref
3524
{
@@ -52,12 +41,12 @@ struct __base_ref
5241

5342
T load()
5443
{
55-
return spirv::load < T, __spv_ptr_t<T>, alignment > (__get_spv_ptr());
44+
return spirv::load<T,alignment>(__get_spv_ptr());
5645
}
5746

5847
void store(const T val)
5948
{
60-
spirv::store < T, __spv_ptr_t<T>, alignment > (__get_spv_ptr(), val);
49+
spirv::store<T,alignment>(__get_spv_ptr(),val);
6150
}
6251
};
6352

include/nbl/builtin/hlsl/memory_accessor.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct StructureOfArrays : impl::StructureOfArraysBase<IndexType,ElementStride,S
116116
enable_if_t<sizeof(T)%sizeof(access_t)==0,void> get(const index_t ix, NBL_REF_ARG(T) value)
117117
{
118118
NBL_CONSTEXPR uint64_t SubElementCount = sizeof(T)/sizeof(access_t);
119-
// `vector` for now, we'll use `array` later
119+
// `vector` for now, we'll use `array` later when `bit_cast` gets fixed
120120
vector<access_t,SubElementCount> aux;
121121
for (index_t i=0; i<SubElementCount; i++)
122122
accessor.get(base_t::getIx(ix,i),aux[i]);
@@ -127,7 +127,7 @@ struct StructureOfArrays : impl::StructureOfArraysBase<IndexType,ElementStride,S
127127
enable_if_t<sizeof(T)%sizeof(access_t)==0,void> set(const index_t ix, NBL_CONST_REF_ARG(T) value)
128128
{
129129
NBL_CONSTEXPR uint64_t SubElementCount = sizeof(T)/sizeof(access_t);
130-
// `vector` for now, we'll use `array` later
130+
// `vector` for now, we'll use `array` later when `bit_cast` gets fixed
131131
vector<access_t,SubElementCount> aux;
132132
aux = bit_cast<vector<access_t,SubElementCount>,T>(value);
133133
for (index_t i=0; i<SubElementCount; i++)

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,24 @@ template<typename T, typename Ptr_T> // DXC Workaround
169169
[[vk::ext_instruction(spv::OpAtomicCompareExchange)]]
170170
enable_if_t<is_spirv_type_v<Ptr_T>, T> atomicCompareExchange(Ptr_T ptr, uint32_t memoryScope, uint32_t memSemanticsEqual, uint32_t memSemanticsUnequal, T value, T comparator);
171171

172-
template<typename T, typename P, uint32_t alignment>
172+
173+
template<typename T, uint32_t alignment>
173174
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
174175
[[vk::ext_instruction(spv::OpLoad)]]
175-
enable_if_t<is_spirv_type_v<P>, T> load(P pointer, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
176+
T load(pointer_t<spv::StorageClassPhysicalStorageBuffer,T> pointer, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
177+
178+
template<typename T, typename P>
179+
[[vk::ext_instruction(spv::OpLoad)]]
180+
enable_if_t<is_spirv_type_v<P>,T> load(P pointer);
176181

177-
template<typename T, typename P, uint32_t alignment >
182+
template<typename T, uint32_t alignment>
178183
[[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
179184
[[vk::ext_instruction(spv::OpStore)]]
180-
enable_if_t<is_spirv_type_v<P>, void> store(P pointer, T obj, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
185+
void store(pointer_t<spv::StorageClassPhysicalStorageBuffer,T> pointer, T obj, [[vk::ext_literal]] uint32_t __aligned = /*Aligned*/0x00000002, [[vk::ext_literal]] uint32_t __alignment = alignment);
186+
187+
template<typename T, typename P>
188+
[[vk::ext_instruction(spv::OpStore)]]
189+
enable_if_t<is_spirv_type_v<P>,void> store(P pointer, T obj);
181190

182191
//! Std 450 Extended set operations
183192
template<typename SquareMatrix>

0 commit comments

Comments
 (0)