Skip to content

[HLSL] Treat structures as packed #121010

Closed
@bogner

Description

@bogner

Structures in HLSL are all treated as packed by DXC. This is especially important for structures within a StructuredBuffer.

dxc implements this by hacking padding off of all structures in CGRecordLowering::lower, like so:

#if 0 // HLSL Change - No padding for structure. Array offset will be handled when load/store is called
  Members.push_back(StorageInfo(Size, getIntNType(8)));
  clipTailPadding();
  determinePacked(NVBaseType);
  insertPadding();
  Members.pop_back();
  calculateZeroInit();
#endif // HLSL Change End

In upstream, we can probably get away with attaching __attribute__((packed)) implicitly to structs during Sema. This is similar to how AddAlignmentAttributesForRecord and AddMsStructLayoutForRecord work and should match DXC's behaviour.

AC:

  • Implement and test implicitly applying the packed attribute to structs

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions