Horrible performance compiling zero-initialization of large arrays

Abierto
#8,958 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
cpp

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
C++
Estrellas
3.7k
Forks
926
Merge medio
3 d 22 h
PR fusionados (30 d)
45

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/DirectXShaderCompiler

Todos los issues de microsoft/DirectXShaderCompiler

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.