@@ -13,58 +13,46 @@ namespace hlsl
13
13
namespace bda
14
14
{
15
15
16
- template<typename T, uint32_t alignment, bool _restrict>
17
- struct __base_ref ;
18
- template<typename T, uint32_t alignment >
19
- struct __base_ref<T,alignment ,false >
16
+ template<typename T, bool _restrict>
17
+ struct __spv_ptr_t ;
18
+ template<typename T>
19
+ struct __spv_ptr_t<T ,false >
20
20
{
21
- [[vk::ext_decorate (spv::DecorationAliasedPointer)]] spirv::bda_pointer_t<T> ptr;
22
-
23
- void __init (const spirv::bda_pointer_t<T> _ptr)
24
- {
25
- ptr = _ptr;
26
- }
27
-
28
- spirv::bda_pointer_t<T> __get_spv_ptr ()
29
- {
30
- // BUG: if I don't launder the pointer through this I get ""
31
- return spirv::bitcast<spirv::bda_pointer_t<T> >(spirv::bitcast<uint32_t2>(ptr));
32
- }
33
-
34
- T load ()
35
- {
36
- return spirv::load<T,alignment>(__get_spv_ptr ());
37
- }
38
-
39
- void store (const T val)
40
- {
41
- spirv::store<T,alignment>(__get_spv_ptr (), val);
42
- }
21
+ [[vk::ext_decorate (spv::DecorationAliasedPointer)]] spirv::bda_pointer_t<T> value;
43
22
};
44
- template<typename T, uint32_t alignment >
45
- struct __base_ref<T,alignment ,true >
23
+ template<typename T>
24
+ struct __spv_ptr_t<T ,true >
46
25
{
47
- [[vk::ext_decorate (spv::DecorationRestrictPointer)]] spirv::bda_pointer_t<T> ptr;
26
+ [[vk::ext_decorate (spv::DecorationRestrictPointer)]] spirv::bda_pointer_t<T> value;
27
+ };
28
+
29
+ template<typename T, uint32_t alignment, bool _restrict>
30
+ struct __base_ref
31
+ {
32
+ __spv_ptr_t<T,_restrict> ptr;
48
33
49
34
void __init (const spirv::bda_pointer_t<T> _ptr)
50
35
{
51
- ptr = _ptr;
36
+ ptr.value = _ptr;
52
37
}
53
38
54
39
spirv::bda_pointer_t<T> __get_spv_ptr ()
55
40
{
56
- // BUG: if I don't launder the pointer through this I get ""
57
- return spirv::bitcast<spirv::bda_pointer_t<T> >(spirv::bitcast<uint32_t2>(ptr));
41
+ // BUG: if I don't launder the pointer through this I get "IsNonPtrAccessChain(ptrInst->opcode())"
42
+ //return ptr.value;
43
+ // What to do!? OpCopyObject? trick the compiler into giving me an immediate value some other way!?
44
+ // If I add `[[vk::ext_reference]]` to my OpLoad and OpStore, then compiler doesn't emit anything!?
45
+ return spirv::bitcast<spirv::bda_pointer_t<T> >(spirv::bitcast<uint32_t2>(ptr.value));
58
46
}
59
47
60
48
T load ()
61
49
{
62
- return spirv::load<T,alignment>(__get_spv_ptr () );
50
+ return spirv::load<T,alignment>(__get_spv_ptr ());
63
51
}
64
52
65
53
void store (const T val)
66
54
{
67
- spirv::store<T,alignment>(__get_spv_ptr (), val);
55
+ spirv::store<T,alignment>(__get_spv_ptr (),val);
68
56
}
69
57
};
70
58
@@ -81,4 +69,53 @@ struct __ref : __base_ref<T,alignment,_restrict>
81
69
82
70
// time for some macros!
83
71
// Sequence of (variableName,Type)
72
+ // need to gen identical struct in HLSL and C++
73
+ /*
74
+ struct MyStruct
75
+ {
76
+ // TODO: compute offsets from sizes and alignments
77
+ [[vk::ext_decorate(spv::DecorationOffset,0)]] float32_t a;
78
+ [[vk::ext_decorate(spv::DecorationOffset,4)]] int32_t b;
79
+ [[vk::ext_decorate(spv::DecorationOffset,8)]] int16_t2 c;
80
+ };
81
+ template<>
82
+ struct nbl::hlsl::alignment_of<MyStruct>
83
+ {
84
+ // TODO: compute alignment if not user specified
85
+ NBL_CONSTEXPR_STATIC_INLINE uint32_t value = 4;
86
+ };
87
+ template<<>
88
+ struct nbl::hlsl::impl::member_info<MyStruct,0>
89
+ {
90
+ using type = float32_t;
91
+ NBL_CONSTEXPR_STATIC_INLINE uint32_t offset = 0;
92
+ };
93
+ template<>
94
+ struct nbl::hlsl::impl::member_info<MyStruct,1>
95
+ {
96
+ using type = int32_t;
97
+ NBL_CONSTEXPR_STATIC_INLINE uint32_t offset = nbl::hlsl::mpl::round_up<member_info<MyStruct,0>::offset+sizeof(member_info<MyStruct,0>::type),alignof<type> >::value;
98
+ };
99
+
100
+
101
+ template<uint32_t alignment, bool _restrict>
102
+ struct nbl::hlsl::bda::__ref<MyStruct,alignment,_restrict> : nbl::hlsl::bda::__base_ref<MyStruct,alignment,_restrict>
103
+ {
104
+ using base_t = __base_ref<MyStruct,alignment,_restrict>;
105
+ using this_t = __ref<MyStruct,alignment,_restrict>;
106
+
107
+ // TODO: compute alignment as min of base alignment and offset alignment
108
+ nbl::hlsl::bda::__ref<float32_t,1,_restrict> a;
109
+ nbl::hlsl::bda::__ref<int32_t,1,_restrict> b;
110
+ nbl::hlsl::bda::__ref<int16_t2,1,_restrict> c;
111
+
112
+ void __init(const nbl::hlsl::spirv::bda_pointer_t<MyStruct> _ptr)
113
+ {
114
+ base_t::__init(_ptr);
115
+ a.__init(spirv::accessChain<float32_t>(base_t::__get_spv_ptr(),0));
116
+ b.__init(spirv::accessChain<int32_t>(base_t::__get_spv_ptr(),1));
117
+ c.__init(spirv::accessChain<int16_t2>(base_t::__get_spv_ptr(),2));
118
+ }
119
+ };
120
+ */
84
121
#endif
0 commit comments