Skip to content

[spirv] Fix struct member offsets for templated buffer load. - #2411

Merged
Ehsan (ehsannas) merged 1 commit into
microsoft:masterfrom
ehsannas:fix_templated_load
Aug 22, 2019
Merged

Ehsan (ehsannas) merged 1 commit into
microsoft:masterfrom
ehsannas:fix_templated_load

Conversation

@ehsannas

Copy link
Copy Markdown
Contributor

No description provided.

@ehsannas Ehsan (ehsannas) added the spirv Work related to SPIR-V label Aug 16, 2019
@ehsannas Ehsan (ehsannas) self-assigned this Aug 16, 2019
@AppVeyorBot

Copy link
Copy Markdown

@jaebaek Jaebaek Seo (jaebaek) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please briefly describe what was the missing support of the one before this change in the commit description? I believe it would be a good future reference.

AlignmentSizeCalculator alignmentCalc(astContext,
theEmitter.getSpirvOptions());
uint32_t fieldSize = 0, fieldAlignment = 0;
std::tie(fieldAlignment, fieldSize) = alignmentCalc.getAlignmentAndSize(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my understanding, getAlignmentAndSize() looks fine but I am worried it is a little bit complicated. I am curious we have unittests to test only this small function. Actually, we have several complicated parts of code and if we tested them using unittests, it would be nice. Let's discuss this issue in offline because this is probably not directly related to this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, sounds good to me.

@ehsannas

Ehsan (ehsannas) commented Aug 22, 2019 •

Copy link
Copy Markdown
Contributor Author

In general, I had used the AstContext::getASTRecordLayout(decl) API to get the structure member byte offsets when I implemented the templated byte address buffer load (ByteAddressBuffer::Load<T>).

However, it turned out that the offsets returned by that API are not always correct in the context of HLSL, and we should be using our own AlignmentAndSizeCalculator instead. This calculator takes layout rules into account (e.g. std140 or std430 or relaxed layout or fxc-like-layout etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spirv Work related to SPIR-V

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants