Skip to content

[SPIR-V] Fix vk::BufferPointer bitfield stores - #8713

Open
dnovillo wants to merge 1 commit into
microsoft:mainfrom
dnovillo:fix-8402
Open

[SPIR-V] Fix vk::BufferPointer bitfield stores#8713
dnovillo wants to merge 1 commit into
microsoft:mainfrom
dnovillo:fix-8402

Conversation

@dnovillo

Copy link
Copy Markdown
Collaborator

This fixes #8402.

Storing to a bitfield through vk::BufferPointer crashes in AlignmentSizeCalculator::getAlignmentAndSize. The bitfield update was losing the AST Type and alignment information.

This change preserves the original AST type while producing the replacement value. It calculates the physical-memory alignment from that type and applies it to both the generated load and store.

I added the original reproducer as a new test.

Preserve the bitfield AST type and align the generated load and store.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dnovillo dnovillo added the spirv Work related to SPIR-V label Jul 29, 2026
@dnovillo

Copy link
Copy Markdown
Collaborator Author

@pow2clk I can't add reviewers yet. Could you please review?

@pow2clk

pow2clk commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@pow2clk pow2clk 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.

I tried to convince myself that there was some way to reorganize things so the alignment value could be calculated sooner and the bitfieldLoad wouldn't have to be outside the conditional so the bitfield handling code could be consolidated, but I don't think that's reasonable if it is possible.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a SPIR-V codegen crash when storing into a bitfield through vk::BufferPointer by ensuring the replacement value keeps AST type information so alignment can be computed and applied to the generated memory ops.

Changes:

  • Preserve AST result type on the bitfield-inserted store value to avoid a null/invalid type flowing into alignment calculation.
  • Apply the computed PhysicalStorageBuffer alignment to both the generated load (for read-modify-write) and the final store.
  • Add a regression test covering pc.ptr.Get().a = 123 for a bitfield member.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/clang/lib/SPIRV/SpirvBuilder.cpp Keeps AST typing/alignment intact for bitfield RMW stores via vk::BufferPointer, preventing the alignment calculator crash.
tools/clang/test/CodeGenSPIRV/vk.buffer-pointer.bitfield.hlsl Adds a regression test asserting the expected OpLoad/OpBitFieldInsert/OpStore sequence with Aligned 4.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +317 to +322
bitfieldLoad = createLoad(value->getResultType(), address, loc, range);
source = createBitFieldInsert(/*QualType*/ {}, bitfieldLoad, value,
bitfieldInfo->offsetInBits,
bitfieldInfo->sizeInBits, loc, range);
source->setResultType(value->getResultType());
source->setAstResultType(value->getAstResultType());
@damyanp

damyanp commented Jul 30, 2026

Copy link
Copy Markdown
Member

[Auto-generated note from @damyanp]

This looks like a user-visible bug fix/feature change. Please add (or point to) the corresponding entry in docs/ReleaseNotes.md.

If release-note coverage is planned in a related PR (including one that hasn’t been submitted yet), please mention that plan/link so we can avoid duplicate notes.

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

Status: New

Development

Successfully merging this pull request may close these issues.

[SPIR-V] Compiler SIGSEGV when trying to write bitfield through vk::BufferPointer

4 participants