aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGHLSLRuntime.h
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.h')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.h35
1 files changed, 32 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 9d31714..488a322 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -81,6 +81,33 @@ class CodeGenModule;
class CodeGenFunction;
class LValue;
+class CGHLSLOffsetInfo {
+ SmallVector<uint32_t> Offsets;
+
+public:
+ static const uint32_t Unspecified = ~0U;
+
+ /// Iterates over all declarations in the HLSL buffer and based on the
+ /// packoffset or register(c#) annotations it fills outs the Offsets vector
+ /// with the user-specified layout offsets. The buffer offsets can be
+ /// specified 2 ways: 1. declarations in cbuffer {} block can have a
+ /// packoffset annotation (translates to HLSLPackOffsetAttr) 2. default
+ /// constant buffer declarations at global scope can have register(c#)
+ /// annotations (translates to HLSLResourceBindingAttr with RegisterType::C)
+ /// It is not guaranteed that all declarations in a buffer have an annotation.
+ /// For those where it is not specified a `~0U` value is added to the Offsets
+ /// 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.
+ static CGHLSLOffsetInfo fromDecl(const HLSLBufferDecl &BufDecl);
+
+ /// Get the given offset, or `~0U` if there is no offset for the member.
+ uint32_t operator[](size_t I) const {
+ if (Offsets.empty())
+ return Unspecified;
+ return Offsets[I];
+ }
+};
+
class CGHLSLRuntime {
public:
//===----------------------------------------------------------------------===//
@@ -167,9 +194,11 @@ public:
CGHLSLRuntime(CodeGenModule &CGM) : CGM(CGM) {}
virtual ~CGHLSLRuntime() {}
- llvm::Type *
- convertHLSLSpecificType(const Type *T,
- SmallVector<int32_t> *Packoffsets = nullptr);
+ llvm::Type *convertHLSLSpecificType(const Type *T,
+ const CGHLSLOffsetInfo &OffsetInfo);
+ llvm::Type *convertHLSLSpecificType(const Type *T) {
+ return convertHLSLSpecificType(T, CGHLSLOffsetInfo());
+ }
void generateGlobalCtorDtorCalls();