Skip to content

Commit 22d9d1f

Browse files
committed
code review feedback - fix typo and naked constant
1 parent 458d5f0 commit 22d9d1f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) {
188188
// 2. default constant buffer declarations at global scope can have
189189
// register(c#) annotations (translates to HLSLResourceBindingAttr with
190190
// RegisterType::C)
191-
// It is not quaranteed that all declarations in a buffer have an annotation.
191+
// It is not guaranteed that all declarations in a buffer have an annotation.
192192
// For those where it is not specified a -1 value is added to the Layout
193193
// vector. In the final layout these declarations will be placed at the end
194194
// of the HLSL buffer after all of the elements with specified offset.
@@ -213,7 +213,7 @@ static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl,
213213
if (RBA->getRegisterType() ==
214214
HLSLResourceBindingAttr::RegisterType::C) {
215215
// size of constant buffer row is 16 bytes
216-
Offset = RBA->getSlotNumber() * 16U;
216+
Offset = RBA->getSlotNumber() * CGHLSLRuntime::BufferRowSizeInBytes;
217217
}
218218
}
219219
}

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class CGHLSLRuntime {
134134
BufferResBinding(HLSLResourceBindingAttr *Attr);
135135
};
136136

137+
static const unsigned BufferRowSizeInBytes = 16U;
138+
137139
protected:
138140
CodeGenModule &CGM;
139141

clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ bool HLSLBufferLayoutBuilder::layoutField(const FieldDecl *FD,
196196
unsigned ArrayCount = 1;
197197
unsigned ArrayStride = 0;
198198

199-
const unsigned BufferRowAlign = 16U;
200-
unsigned NextRowOffset = llvm::alignTo(EndOffset, BufferRowAlign);
199+
unsigned NextRowOffset =
200+
llvm::alignTo(EndOffset, CGHLSLRuntime::BufferRowSizeInBytes);
201201

202202
llvm::Type *ElemLayoutTy = nullptr;
203203
QualType FieldTy = FD->getType();
@@ -227,7 +227,7 @@ bool HLSLBufferLayoutBuilder::layoutField(const FieldDecl *FD,
227227
getScalarOrVectorSizeInBytes(CGM.getTypes().ConvertTypeForMem(Ty));
228228
ElemLayoutTy = CGM.getTypes().ConvertTypeForMem(FieldTy);
229229
}
230-
ArrayStride = llvm::alignTo(ElemSize, BufferRowAlign);
230+
ArrayStride = llvm::alignTo(ElemSize, CGHLSLRuntime::BufferRowSizeInBytes);
231231
ElemOffset = (Packoffset != -1) ? Packoffset : NextRowOffset;
232232

233233
} else if (FieldTy->isStructureType()) {

0 commit comments

Comments
 (0)