@@ -13,58 +13,46 @@ namespace hlsl
1313namespace bda
1414{
1515
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 >
2020{
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;
4322};
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 >
4625{
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;
4833
4934 void __init (const spirv::bda_pointer_t<T> _ptr)
5035 {
51- ptr = _ptr;
36+ ptr.value = _ptr;
5237 }
5338
5439 spirv::bda_pointer_t<T> __get_spv_ptr ()
5540 {
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));
5846 }
5947
6048 T load ()
6149 {
62- return spirv::load<T,alignment>(__get_spv_ptr () );
50+ return spirv::load<T,alignment>(__get_spv_ptr ());
6351 }
6452
6553 void store (const T val)
6654 {
67- spirv::store<T,alignment>(__get_spv_ptr (), val);
55+ spirv::store<T,alignment>(__get_spv_ptr (),val);
6856 }
6957};
7058
@@ -81,4 +69,53 @@ struct __ref : __base_ref<T,alignment,_restrict>
8169
8270// time for some macros!
8371// 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+ */
84121#endif
0 commit comments