@@ -23,100 +23,95 @@ class RawBufferHandler {
23
23
: theEmitter(emitter), astContext(emitter.getASTContext()),
24
24
spvBuilder (emitter.getSpirvBuilder()) {}
25
25
26
- // / \brief Performs (RW)ByteAddressBuffer.Load<T>(address ).
26
+ // / \brief Performs (RW)ByteAddressBuffer.Load<T>(byteAddress ).
27
27
// / (RW)ByteAddressBuffers are represented as structs with only one member
28
28
// / which is a runtime array in SPIR-V. This method works by loading one or
29
29
// / more uints, and performing necessary casts and composite constructions
30
- // / to build the 'targetType'. The 'offset' parameter can be used for finer
31
- // / grained load of bitwidths smaller than 32-bits. The layout rule for the
32
- // / result will be `Void` because the value will be built and used internally
33
- // / only. It does not have to match `buffer`.
30
+ // / to build the 'targetType'. The layout rule for the result will be `Void`
31
+ // / because the value will be built and used internally only. It does not have
32
+ // / to match `buffer`.
34
33
// /
35
34
// / Example:
36
- // / targetType = uint16_t, address=0, offset=0
37
- // / --> Load the first 16-bit uint starting at address 0.
38
- // / targetType = uint16_t, address=0, offset=16
39
- // / --> Load the second 16-bit uint starting at address 0.
40
- SpirvInstruction *processTemplatedLoadFromBuffer (SpirvInstruction *buffer,
41
- SpirvInstruction *&index,
42
- const QualType targetType,
43
- uint32_t &bitOffset,
44
- SourceRange range = {});
35
+ // / targetType = uint16_t, byteAddress=0
36
+ // / --> Load the first 16-bit uint starting at byte address 0.
37
+ SpirvInstruction *processTemplatedLoadFromBuffer (
38
+ SpirvInstruction *buffer, SpirvInstruction *byteAddress,
39
+ const QualType targetType, SourceRange range = {});
45
40
46
41
// / \brief Performs RWByteAddressBuffer.Store<T>(address, value).
47
42
// / RWByteAddressBuffers are represented in SPIR-V as structs with only one
48
43
// / member which is a runtime array of uints. This method works by decomposing
49
44
// / the given |value| to reach numeric/bool types. Then performs necessary
50
45
// / casts to uints and stores them in the underlying runtime array.
51
- // / The |bitOffset| parameter can be used for finer-grained bit-offset
52
- // / control.
53
46
// /
54
47
// / Example:
55
- // / targetType = uint16_t, address=0, offset=0
48
+ // / targetType = uint16_t, address=0
56
49
// / --> Store to the first 16-bit uint starting at address 0.
57
- // / targetType = uint16_t, address=0, offset=16
58
- // / --> Store to the second 16-bit uint starting at address 0.
59
50
void processTemplatedStoreToBuffer (SpirvInstruction *value,
60
51
SpirvInstruction *buffer,
61
- SpirvInstruction *&index ,
52
+ SpirvInstruction *&byteAddress ,
62
53
const QualType valueType,
63
- uint32_t &bitOffset,
64
54
SourceRange range = {});
65
55
66
56
private:
67
- SpirvInstruction * load16BitsAtBitOffset0 (SpirvInstruction *buffer,
68
- SpirvInstruction *&index,
69
- QualType target16BitType,
70
- uint32_t &bitOffset ,
71
- SourceRange range = {});
72
-
73
- SpirvInstruction * load32BitsAtBitOffset0 ( SpirvInstruction *buffer,
74
- SpirvInstruction *&index,
75
- QualType target32BitType,
76
- uint32_t &bitOffset ,
77
- SourceRange range = {} );
78
-
79
- SpirvInstruction * load64BitsAtBitOffset0 (SpirvInstruction *buffer,
80
- SpirvInstruction *&index,
81
- QualType target64BitType,
82
- uint32_t &bitOffset,
83
- SourceRange range = {});
84
-
85
- SpirvInstruction * load16BitsAtBitOffset16 ( SpirvInstruction *buffer,
86
- SpirvInstruction *&index,
87
- QualType target16BitType,
88
- uint32_t &bitOffset,
89
- SourceRange range = {}) ;
57
+ class BufferAddress {
58
+ public:
59
+ BufferAddress (SpirvInstruction *&byteAddress, SpirvEmitter &emitter)
60
+ : byteAddress(byteAddress), wordIndex() ,
61
+ spvBuilder (emitter.getSpirvBuilder()),
62
+ astContext(emitter.getASTContext()) {}
63
+ SpirvInstruction *getByteAddress ();
64
+ SpirvInstruction *getWordIndex (SourceLocation loc, SourceRange range);
65
+
66
+ void incrementByteAddress (SpirvInstruction *width, SourceLocation loc ,
67
+ SourceRange range);
68
+ void incrementByteAddress ( uint32_t width, SourceLocation loc,
69
+ SourceRange range);
70
+
71
+ void incrementWordIndex (SourceLocation loc, SourceRange range);
72
+
73
+ private:
74
+ SpirvInstruction *byteAddress;
75
+ llvm::Optional< SpirvInstruction *> wordIndex;
76
+
77
+ SpirvBuilder &spvBuilder;
78
+ ASTContext &astContext;
79
+ } ;
90
80
91
- private:
92
- void store16BitsAtBitOffset0 (SpirvInstruction *value,
93
- SpirvInstruction *buffer,
94
- SpirvInstruction *&index,
95
- const QualType valueType,
81
+ SpirvInstruction *processTemplatedLoadFromBuffer (SpirvInstruction *buffer,
82
+ BufferAddress &address,
83
+ const QualType targetType,
84
+ SourceRange range = {});
85
+ void processTemplatedStoreToBuffer (SpirvInstruction *value,
86
+ SpirvInstruction *buffer,
87
+ BufferAddress &address,
88
+ const QualType valueType,
89
+ SourceRange range = {});
90
+
91
+ SpirvInstruction *load16Bits (SpirvInstruction *buffer, BufferAddress &address,
92
+ QualType target16BitType,
96
93
SourceRange range = {});
97
94
98
- void store32BitsAtBitOffset0 (SpirvInstruction *value,
99
- SpirvInstruction *buffer,
100
- SpirvInstruction *&index,
101
- const QualType valueType,
95
+ SpirvInstruction *load32Bits (SpirvInstruction *buffer, BufferAddress &address,
96
+ QualType target32BitType,
102
97
SourceRange range = {});
103
98
104
- void store64BitsAtBitOffset0 (SpirvInstruction *value,
105
- SpirvInstruction *buffer,
106
- SpirvInstruction *&index,
107
- const QualType valueType,
99
+ SpirvInstruction *load64Bits (SpirvInstruction *buffer, BufferAddress &address,
100
+ QualType target64BitType,
108
101
SourceRange range = {});
109
102
110
- void store16BitsAtBitOffset16 (SpirvInstruction *value,
111
- SpirvInstruction *buffer,
112
- SpirvInstruction *&index,
113
- const QualType valueType,
114
- SourceRange range = {});
103
+ private:
104
+ void store16Bits (SpirvInstruction *value, SpirvInstruction *buffer,
105
+ BufferAddress &address, const QualType valueType,
106
+ SourceRange range = {});
107
+
108
+ void store32Bits (SpirvInstruction *value, SpirvInstruction *buffer,
109
+ BufferAddress &address, const QualType valueType,
110
+ SourceRange range = {});
115
111
116
- void storeArrayOfScalars (std::deque<SpirvInstruction *> values,
117
- SpirvInstruction *buffer, SpirvInstruction *&index,
118
- const QualType valueType, uint32_t &bitOffset,
119
- SourceLocation, SourceRange range = {});
112
+ void store64Bits (SpirvInstruction *value, SpirvInstruction *buffer,
113
+ BufferAddress &address, const QualType valueType,
114
+ SourceRange range = {});
120
115
121
116
// / \brief Serializes the given values into their components until a scalar or
122
117
// / a struct has been reached. Returns the most basic type it reaches.
0 commit comments