Skip to content

Commit

Permalink
code review feedback - fix typo and naked constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hekota committed Feb 27, 2025
1 parent 458d5f0 commit 22d9d1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGHLSLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ createBufferHandleType(const HLSLBufferDecl *BufDecl) {
// 2. default constant buffer declarations at global scope can have
// register(c#) annotations (translates to HLSLResourceBindingAttr with
// RegisterType::C)
// It is not quaranteed that all declarations in a buffer have an annotation.
// It is not guaranteed that all declarations in a buffer have an annotation.
// For those where it is not specified a -1 value is added to the Layout
// vector. In the final layout these declarations will be placed at the end
// of the HLSL buffer after all of the elements with specified offset.
Expand All @@ -213,7 +213,7 @@ static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl,
if (RBA->getRegisterType() ==
HLSLResourceBindingAttr::RegisterType::C) {
// size of constant buffer row is 16 bytes
Offset = RBA->getSlotNumber() * 16U;
Offset = RBA->getSlotNumber() * CGHLSLRuntime::BufferRowSizeInBytes;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGHLSLRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class CGHLSLRuntime {
BufferResBinding(HLSLResourceBindingAttr *Attr);
};

static const unsigned BufferRowSizeInBytes = 16U;

protected:
CodeGenModule &CGM;

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ bool HLSLBufferLayoutBuilder::layoutField(const FieldDecl *FD,
unsigned ArrayCount = 1;
unsigned ArrayStride = 0;

const unsigned BufferRowAlign = 16U;
unsigned NextRowOffset = llvm::alignTo(EndOffset, BufferRowAlign);
unsigned NextRowOffset =
llvm::alignTo(EndOffset, CGHLSLRuntime::BufferRowSizeInBytes);

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

} else if (FieldTy->isStructureType()) {
Expand Down

0 comments on commit 22d9d1f

Please sign in to comment.