Horrible performance compiling zero-initialization of large arrays

オープン
#8,958 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
cpp

調査の方向性

Start by compiling the two provided HLSL shaders with DXC at -O3 and compare their timings. Follow the main entry point and the zero-initialization path through the optimizer to identify where the large-array case expands; done means the slow shader no longer exhibits the reported optimizer slowdown while preserving its behavior.

索引モデルが issue の本文から書いたものです。

説明

bug needs-triage

Description
See https://github.com/gfx-rs/wgpu/pull/10314.

When trying to compile shaders which zero-initialize large multi-dimensional arrays, dxc's optimizer goes absolutely crazy and spends huge amounts of time. On my M4 mac, I experienced 1.4s compilation times for a simple shader which only zero initializes a single structure.

Steps to Reproduce
Use DXC with -O3 on the following shaders:

// Slow compilation
groupshared float4 inp[4][18][18];
RWByteAddressBuffer output : register(u0);

uint naga_div(uint lhs, uint rhs) {
    return lhs / (rhs == 0u ? 1u : rhs);
}

uint naga_mod(uint lhs, uint rhs) {
    return lhs % (rhs == 0u ? 1u : rhs);
}

[numthreads(16, 16, 1)]
void main(uint index : SV_GroupIndex)
{
    if (index == 0) {
        inp = (float4[4][18][18])0;
    }
    GroupMemoryBarrierWithGroupSync();
    float4 _e15 = inp[min(uint(naga_div(index, 324u)), 3u)][min(uint(naga_mod(naga_div(index, 18u), 18u)), 17u)][min(uint(naga_mod(index, 18u)), 17u)];
    output.Store4(index*16, asuint(_e15));
    return;
}
// Fast compilation
groupshared float4 inp[4][18][18];
RWByteAddressBuffer output : register(u0);

uint naga_div(uint lhs, uint rhs) {
    return lhs / (rhs == 0u ? 1u : rhs);
}

uint naga_mod(uint lhs, uint rhs) {
    return lhs % (rhs == 0u ? 1u : rhs);
}

[numthreads(16, 16, 1)]
void main(uint index : SV_GroupIndex)
{
    [loop]
    for (uint zero_flat_index = index; zero_flat_index < 1296u; zero_flat_index += 256u) {
        uint zero_index = (zero_flat_index / 324u) % 4u;
        uint zero_index_1 = (zero_flat_index / 18u) % 18u;
        uint zero_index_2 = (zero_flat_index / 1u) % 18u;
        inp[zero_index][zero_index_1][zero_index_2] = (float4)0;
    }
    GroupMemoryBarrierWithGroupSync();
    float4 _e15 = inp[min(uint(naga_div(index, 324u)), 3u)][min(uint(naga_mod(naga_div(index, 18u), 18u)), 17u)][min(uint(naga_mod(index, 18u)), 17u)];
    output.Store4(index*16, asuint(_e15));
    return;
}

Actual Behavior
Slow perf, 1.4s vs 8ms on my Mac.

Environment

  • DXC version libdxcompiler.dylib: 1.10(5180-e3554182)(1.9.0.5180)
  • Host Operating System macOS 26.5.1
主要言語
C++
スター
3.7k
フォーク
926
平均マージ
3日 22時間
マージ済み PR(30日)
45

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/DirectXShaderCompiler のほかの issue

microsoft/DirectXShaderCompiler の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。