microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] Inefficient codegen when writing to RWByteAddressBuffer

Open
#7,089 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
When writing/reading to/from a RWByteAddressBuffer, it emits a lot of loads/writes using a uint each.
Even though the driver might catch this and fix it at PSO creation time certain validation tools might still see performance degradations.
In this issue: https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9317#issuecomment-2616396801 compilation takes a loooong time because every access needs to be validated individually.
If there is a way to reduce this, for example by using bitcasts as suggested by devshgraphicsprogramming in a different issue (https://github.com/microsoft/DirectXShaderCompiler/issues/7038#issuecomment-2572959501) it could help a lot to reduce overhead with validation layers and potentially other tools as well. Maybe also drivers that are written less well can also benefit from this.

Steps to Reproduce
RWByteAddressBuffer or ByteAddressBuffer load/write with a relatively big struct. This will emit a lot of bloat https://godbolt.org/z/qE95f8jvb. Where each index needs to be bounds checked by the tool.

Actual Behavior
Slowdowns on validation tools.

Environment

  • DXC version: Latest from a few days back
  • Host Operating System: N/A (though the issue happens on Android)

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

Start with the Godbolt reproduction and inspect the generated SPIR-V for RWByteAddressBuffer accesses to understand the repeated loads, writes, and bounds checks. Compare output for a relatively large struct before and after any investigation, and treat reduced validation overhead without changing buffer access behavior as the completion criteria.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.