@@ -177,13 +177,29 @@ namespace Slang
177
177
IRBuilder subBuilder (typeUser);
178
178
IRVarLayout::Builder newVarLayoutBuilder (&subBuilder, typeLayout);
179
179
newVarLayoutBuilder.cloneEverythingButOffsetsFrom (varLayout);
180
+ IRVarOffsetAttr* uavOffsetAttr = nullptr ;
181
+ IRVarOffsetAttr* descriptorTableSlotOffsetAttr = nullptr ;
182
+
180
183
for (auto offsetAttr : varLayout->getOffsetAttrs ())
181
184
{
185
+ if (offsetAttr->getResourceKind () == LayoutResourceKind::UnorderedAccess)
186
+ uavOffsetAttr = offsetAttr;
187
+ else if (offsetAttr->getResourceKind () == LayoutResourceKind::DescriptorTableSlot)
188
+ descriptorTableSlotOffsetAttr = offsetAttr;
182
189
auto info = newVarLayoutBuilder.findOrAddResourceInfo (offsetAttr->getResourceKind ());
183
190
info->offset = offsetAttr->getOffset ();
184
191
info->space = offsetAttr->getSpace ();
185
192
info->kind = offsetAttr->getResourceKind ();
186
193
}
194
+ // If the user provided an layout offset for UAV but not for descriptor table slot, then
195
+ // we use the UAV offset for the descriptor table slot offset.
196
+ if (uavOffsetAttr && !descriptorTableSlotOffsetAttr)
197
+ {
198
+ auto info = newVarLayoutBuilder.findOrAddResourceInfo (LayoutResourceKind::DescriptorTableSlot);
199
+ info->offset = uavOffsetAttr->getOffset ();
200
+ info->space = uavOffsetAttr->getSpace ();
201
+ info->kind = LayoutResourceKind::DescriptorTableSlot;
202
+ }
187
203
auto newVarLayout = newVarLayoutBuilder.build ();
188
204
subBuilder.addLayoutDecoration (typeUser, newVarLayout);
189
205
varLayout->removeAndDeallocate ();
0 commit comments