Skip to content

Allow [numthreads] to override layout-derived group size for multi-entry-point shaders; warn on inconsistency, error on conflicting duplicate [numthreads] #11881

Description

@nv-slang-bot

Originating context: PR #11715 ("Fixes GitHub issue #7894 — makes reflection and SPIR-V agree on layout(local_size) in") and maintainer discussion at #11715 (comment).

PR #11715 makes [numthreads] take precedence over a global GLSL layout(local_size_*) on an entry point. That surfaces three follow-up requirements around how the compiler should handle multiple/conflicting sources of a compute group size. This issue captures them distinctly.

(a) Allow [numthreads] to override the layout-derived group size for multi-entry-point shaders

When a shader has multiple entry points, a [numthreads] attribute on a given entry point should be allowed to override the group size derived from a global layout(local_size_*) qualifier for that entry point. This lets a global GLSL layout(...) provide a default while individual entry points opt into their own size, which is useful when porting a multi-entry-point GLSL file to Slang entry-point-by-entry-point.

(b) Warn when the group-size values are inconsistent across sources

When the value from [numthreads] and the value derived from layout(local_size_*) disagree for an entry point (i.e. the override in (a) actually changes the effective size), the compiler should emit a warning so the inconsistency is visible rather than silently resolved.

(c) Error on conflicting multiple [numthreads] attributes on a single entry point

When one entry point carries multiple [numthreads] attributes with different values, the compiler should emit an error:

[numthreads(2,3,4)]
[numthreads(5,6,7)]
[numthreads(1,5,9)]
void main() {}

Current behavior (checked at master @ 7f79b923f)

This case is not diagnosed today — the compiler silently uses the first [numthreads] attribute and ignores the rest, with no error or warning:

  • findModifier<T>() returns only the first modifier of a type: source/slang/slang-ast-base.h:737.
  • Lowering iterates the modifier list and consumes the first NumThreadsAttribute it finds, ignoring later ones: source/slang/slang-lower-to-ir.cpp:~14277.
  • NumThreadsAttribute is not registered in getModifierConflictGroupKind() (source/slang/slang-check-modifier.cpp:1564-1672), so the general duplicate-modifier detection loop (source/slang/slang-check-modifier.cpp:~2470) never flags it.

So the error requested in (c) is genuinely missing and should be added. A natural place is to give NumThreadsAttribute its own conflict group in getModifierConflictGroupKind() (or a dedicated check) plus a diagnostic near DuplicateModifier.


🤖 Generated by an automated Slang coworker — may be inaccurate. A human maintainer should verify.

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions