Skip to content

Commit eaeaf2a

Browse files
committed
code review feedback - minor changes
1 parent 62094b2 commit eaeaf2a

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,8 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
103103

104104
// get the layout struct from constant buffer target type
105105
llvm::Type *BufType = BufGV->getValueType();
106-
assert(isa<llvm::TargetExtType>(BufType) &&
107-
"expected target type for HLSL buffer resource");
108106
llvm::Type *BufLayoutType =
109107
cast<llvm::TargetExtType>(BufType)->getTypeParameter(0);
110-
assert(isa<llvm::TargetExtType>(BufLayoutType) &&
111-
"expected target type for buffer layout struct");
112108
llvm::StructType *LayoutStruct = cast<llvm::StructType>(
113109
cast<llvm::TargetExtType>(BufLayoutType)->getTypeParameter(0));
114110

@@ -139,20 +135,22 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
139135
// Emit static and groupshared variables and resource classes inside
140136
// cbuffer as regular globals
141137
CGM.EmitGlobal(VD);
138+
} else {
139+
// Anything else that is not in the hlsl_constant address space must be
140+
// an empty struct or a zero-sized array and can be ignored
141+
assert(BufDecl->getASTContext().getTypeSize(VDTy) == 0 &&
142+
"constant buffer decl with non-zero sized type outside of "
143+
"hlsl_constant address space");
142144
}
143-
// Anything else that is not in the hlsl_constant address space must be
144-
// an empty struct or a zero-sized array and can be ignored
145145
continue;
146146
}
147147

148148
assert(ElemIt != LayoutStruct->element_end() &&
149149
"number of elements in layout struct does not match");
150150
llvm::Type *LayoutType = *ElemIt++;
151151

152-
// there might be resources inside the used defined structs
153-
if (VDTy->isStructureType() && VDTy->isHLSLIntangibleType())
154-
// FIXME: handle resources in cbuffer structs
155-
llvm_unreachable("resources in cbuffer are not supported yet");
152+
// FIXME: handle resources inside user defined structs
153+
// (llvm/wg-hlsl#175)
156154

157155
// create global variable for the constant and to metadata list
158156
GlobalVariable *ElemGV =
@@ -161,7 +159,6 @@ void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
161159
}
162160
assert(ElemIt == LayoutStruct->element_end() &&
163161
"number of elements in layout struct does not match");
164-
// set the size of the buffer
165162

166163
// add buffer metadata to the module
167164
CGM.getModule()
@@ -235,6 +232,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
235232
const HLSLResourceBindingAttr *RBA =
236233
BufDecl->getAttr<HLSLResourceBindingAttr>();
237234
// FIXME: handle implicit binding if no binding attribute is found
235+
// (llvm/llvm-project#110722)
238236
if (RBA)
239237
createResourceInitFn(CGM, BufGV, RBA->getSlotNumber(),
240238
RBA->getSpaceNumber());

0 commit comments

Comments
 (0)