DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Implement support for groupshared arguments in 202x

Open spall opened this issue 1 month ago • 2 comments

Implement support for groupshared arguments in 202x based on this proposal: https://github.com/microsoft/hlsl-specs/blob/main/proposals/0043-groupshared-arguments.md

Errors:

  • Error if a function annotated with 'export' or '[noinline]' annotates a parameter with groupshared.
  • Error if the argument to a groupshared parameter is not a groupshared variable.
  • Error if the argument to a groupshared parameter is not exactly the same type as the parameter. No implicit or explicit conversion are allowed.
  • the following overload calls are errors. Given this set of overloads
void fn(groupshared uint shared);
void fn(inout uint u);

This call site is ambiguous and results in an error:

groupshared uint Shared;
void caller() {
  fn(Shared);
}

This call site is not ambiguous however:

void caller() {
  uint Local;
  fn(Local);
}

Given this set of overloads

void fn(groupshared uint shared);
void fn(uint u);

This call site is ambiguous and results in an error:

groupshared uint Shared;
void caller() {
  fn(Shared);
}

These call sites are not ambiguous however:

void caller() {
  uint Local;
  fn(Local);
  fn(5);
}

Warnings:

  • Warn if language mode is earlier than 202x and groupshared annotation is used on a parameter
  • Warn when language mode is 202x or later and a groupshared variable is passed to a function annotated with inout.

spall avatar Dec 03 '25 20:12 spall

may I suggest a simpler solution which already works for us? https://godbolt.devsh.eu/z/TPzWoE

This approach beats even Slang (see the %_ptr_Function__arr_uint_int_512 you get that you can't optimize out) https://godbolt.org/z/Tbx3rzKeh

Could I suggest pointers/references with address spaces like groupshared?

may I suggest a simpler solution which already works for us? https://godbolt.devsh.eu/z/TPzWoE

This approach beats even Slang (see the %_ptr_Function__arr_uint_int_512 you get that you can't optimize out) https://godbolt.org/z/Tbx3rzKeh

This feature as proposed is just giving an official spelling to a concept that already exists in HLSL for the interlocked instructions and a few other places. The goal here is to make something that was hacked into the language spellable to make it easier to work with in the future.

Could I suggest pointers/references with address spaces like groupshared?

Full featured references with address space annotations is something we're considering (https://github.com/microsoft/hlsl-specs/blob/main/proposals/0006-reference-types.md) for a future language version. That change is a lot more work and we're not yet ready to bite it off.

On a process note: please direct comments and suggestions about language direction to the language evolution process (https://github.com/microsoft/hlsl-specs/), not the issues tracking compiler implementation work.

llvm-beanz avatar Dec 04 '25 17:12 llvm-beanz