microsoft / microsoft/DirectXShaderCompiler

Bad alignment generated for loads/stores from half arrays

Open
#7,540 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description

When compiling shaders from FidelityFX-SPD, DXC generates load and store instructions with bad alignment for arrays of type half.

In the DXIL below, the half array is aligned to 4 bytes and so are the loads and stores, even the ones with odd indices which are only guaranteed to be aligned to 2 bytes.

  %10 = alloca [4 x half], align 4
  %11 = alloca [4 x half], align 4
  %12 = alloca [4 x half], align 4
  %13 = alloca [4 x half], align 4
...
  %140 = getelementptr [4 x half], [4 x half]* %10, i32 0, i32 1
  %141 = getelementptr [4 x half], [4 x half]* %11, i32 0, i32 1
  %142 = getelementptr [4 x half], [4 x half]* %12, i32 0, i32 1
  %143 = getelementptr [4 x half], [4 x half]* %13, i32 0, i32 1
  store half %136, half* %140, align 4
  store half %137, half* %141, align 4
  store half %138, half* %142, align 4
  store half %139, half* %143, align 4
...
  %431 = load half, half* %140, align 4
  %432 = load half, half* %141, align 4
  %433 = load half, half* %142, align 4
  %434 = load half, half* %143, align 4

Steps to Reproduce

  1. Clone https://github.com/GPUOpen-Effects/FidelityFX-SPD
  2. Build DX12 project
  3. Go to sample\bin\ShaderLibDX
  4. Run dxc.exe -T cs_6_3 -E main .\SPDIntegrationLinearSampler.hlsl -DA_HALF=1 -DSPD_PACKED_ONLY=1 -DSPD_NO_WAVE_OPERATIONS=1

Actual Behavior

Generated DXIL has 4-byte alignment for the half loads/stores.

Environment

  • DXC versions tried (all repro):
    • dxcompiler.dll: 1.9 - 1.8.2505.28 (9efbb6c32); dxil.dll: 1.9(1.8.2505.28)
    • dxcompiler.dll: 1.6 - 1.5.0.2743 (1db4cd60); dxil.dll: 1.3(10.0.17763.132)
  • Host Operating System: Win11 26100

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the listed FidelityFX-SPD shader and the dxc.exe command, then trace how half arrays and their load/store instructions receive alignment during compilation. Done means the generated DXIL uses alignment no greater than 2 bytes for odd-index half accesses while preserving valid alignment elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.