summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-layout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-layout.cpp')
-rw-r--r--source/slang/slang-ir-layout.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/source/slang/slang-ir-layout.cpp b/source/slang/slang-ir-layout.cpp
index 6a4e9360a..3a2471930 100644
--- a/source/slang/slang-ir-layout.cpp
+++ b/source/slang/slang-ir-layout.cpp
@@ -443,6 +443,33 @@ struct NaturalLayoutRules : IRTypeLayoutRules
}
};
+struct ConstantBufferLayoutRules : IRTypeLayoutRules
+{
+ ConstantBufferLayoutRules()
+ {
+ ruleName = IRTypeLayoutRuleName::D3DConstantBuffer;
+ }
+
+ /// Next member only aligns to 16 if the next member is an array/matrix/struct
+ virtual IRSizeAndAlignment alignCompositeElement(IRSizeAndAlignment currentSize)
+ {
+ // Matrix/Array/Struct should be aligned on a new register
+ return IRSizeAndAlignment(currentSize.size, 16);
+ }
+
+ virtual IRIntegerValue adjustOffsetForNextAggregateMember(IRIntegerValue currentSize, IRIntegerValue lastElementAlignment)
+ {
+ SLANG_UNUSED(lastElementAlignment);
+ return currentSize;
+ }
+
+ virtual IRSizeAndAlignment getVectorSizeAndAlignment(IRSizeAndAlignment element, IRIntegerValue count)
+ {
+ IRIntegerValue countForAlignment = count;
+ return IRSizeAndAlignment((int)(element.size * count), (int)(element.size * countForAlignment));
+ }
+};
+
struct Std430LayoutRules : IRTypeLayoutRules
{
Std430LayoutRules()
@@ -534,6 +561,13 @@ IRTypeLayoutRules* IRTypeLayoutRules::getNatural()
static NaturalLayoutRules rules;
return &rules;
}
+
+IRTypeLayoutRules* IRTypeLayoutRules::getConstantBuffer()
+{
+ static ConstantBufferLayoutRules rules;
+ return &rules;
+}
+
IRTypeLayoutRules* IRTypeLayoutRules::get(IRTypeLayoutRuleName name)
{
switch (name)
@@ -541,6 +575,7 @@ IRTypeLayoutRules* IRTypeLayoutRules::get(IRTypeLayoutRuleName name)
case IRTypeLayoutRuleName::Std430: return getStd430();
case IRTypeLayoutRuleName::Std140: return getStd140();
case IRTypeLayoutRuleName::Natural: return getNatural();
+ case IRTypeLayoutRuleName::D3DConstantBuffer: return getConstantBuffer();
default: return nullptr;
}
}