[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:
Sebastian Tafuri 2017-12-15 23:06:42 +01:00 коммит произвёл Lei Zhang
Родитель ec8dc62320
Коммит 1a45ed822a
5 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -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);
}