[spirv] Add support for vk::offset attribute (#922)
Added support for the vk::offset attribute to manually specify offsets for struct members. This commit only handles non-nested structs and it does not validate the offset provided either.
This commit is contained in:
Родитель
ec8dc62320
Коммит
1a45ed822a
|
@ -914,6 +914,13 @@ def VKPushConstant : InheritableAttr {
|
|||
let Documentation = [Undocumented];
|
||||
}
|
||||
|
||||
def VKOffset : InheritableAttr {
|
||||
let Spellings = [CXX11<"vk", "offset">];
|
||||
let Args = [IntArgument<"Offset">];
|
||||
let LangOpts = [SPIRV];
|
||||
let Documentation = [Undocumented];
|
||||
}
|
||||
|
||||
// SPIRV Change Ends
|
||||
|
||||
def C11NoReturn : InheritableAttr {
|
||||
|
|
|
@ -619,7 +619,11 @@ TypeTranslator::getLayoutDecorations(const DeclContext *decl, LayoutRule rule) {
|
|||
getAlignmentAndSize(fieldType, rule, isRowMajor, &stride);
|
||||
|
||||
// Each structure-type member must have an Offset Decoration.
|
||||
roundToPow2(&offset, memberAlignment);
|
||||
const auto *offsetAttr = field->getAttr<VKOffsetAttr>();
|
||||
if (offsetAttr)
|
||||
offset = offsetAttr->getOffset();
|
||||
else
|
||||
roundToPow2(&offset, memberAlignment);
|
||||
decorations.push_back(Decoration::getOffset(*spirvContext, offset, index));
|
||||
offset += memberSize;
|
||||
|
||||
|
|
|
@ -10381,6 +10381,10 @@ void hlsl::HandleDeclAttributeForHLSL(Sema &S, Decl *D, const AttributeList &A,
|
|||
declAttr = ::new (S.Context) VKPushConstantAttr(A.getRange(), S.Context,
|
||||
A.getAttributeSpellingListIndex());
|
||||
break;
|
||||
case AttributeList::AT_VKOffset:
|
||||
declAttr = ::new (S.Context) VKOffsetAttr(A.getRange(), S.Context,
|
||||
ValidateAttributeIntArg(S, A), A.getAttributeSpellingListIndex());
|
||||
break;
|
||||
default:
|
||||
Handled = false;
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// Run: %dxc -T vs_6_0 -E main
|
||||
|
||||
// CHECK: OpMemberDecorate %type_PushConstant_S 0 Offset 0
|
||||
// CHECK: OpMemberDecorate %type_PushConstant_S 1 Offset 8
|
||||
// CHECK: OpMemberDecorate %type_PushConstant_S 2 Offset 32
|
||||
|
||||
struct S {
|
||||
float a;
|
||||
[[vk::offset(8)]]
|
||||
float2 b;
|
||||
[[vk::offset(32)]]
|
||||
float4 f;
|
||||
};
|
||||
|
||||
[[vk::push_constant]]
|
||||
S pcs1;
|
||||
|
||||
float main() : A {
|
||||
return 1.0;
|
||||
}
|
|
@ -1035,6 +1035,7 @@ TEST_F(FileTest, VulkanStructuredBufferCounter) {
|
|||
}
|
||||
|
||||
TEST_F(FileTest, VulkanPushConstant) { runFileTest("vk.push-constant.hlsl"); }
|
||||
TEST_F(FileTest, VulkanPushConstantOffset) { runFileTest("vk.push-constant.offset.hlsl"); }
|
||||
TEST_F(FileTest, VulkanMultiplePushConstant) {
|
||||
runFileTest("vk.push-constant.multiple.hlsl", FileTest::Expect::Failure);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче