Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify NonUniformResourceIndex usage #149

Open
jeremyong opened this issue Aug 21, 2023 · 0 comments
Open

Clarify NonUniformResourceIndex usage #149

jeremyong opened this issue Aug 21, 2023 · 0 comments

Comments

@jeremyong
Copy link
Contributor

jeremyong commented Aug 21, 2023

Hi DirectX team!

There are a few aspects of NonUniformResourceIndex usage I'd like to have more fully specified if possible.

Usage outside of a subscript operator

Using an index like so:

uint index = NonUniformResourceIndex(expr);
Texture2D texture = ResourceDescriptorHeap[index];

annotates the resource handle as being nonuniform. However, this nonuniformity is lost if the index value is modified after NonUniformResourceIndex annotation, even if the modification itself is uniform:

uint index = NonUniformResourceIndex(expr);
// Oops, subscript argument no longer non-uniform
Texture2D texture = ResourceDescriptorHeap[index + 3];

I would suggest specifying that NonUniformResourceIndex must be used directly in the subscript argument unless we can distill down the specific rules governing when it is safe to be used in other contexts. A compiler warning/error may also be appropriate in situations where the annotation ends up unused (a leading indicator of user error).

Clarification of the meaning of "non-uniform"

I can think of the term "uniform" to mean several different things. Namely, uniformity can be a property of a variable's value, or the program's control-flow. Further more, there are more subtle distinctions, for example, is a value considered uniform provided it is only constant across active lanes? What about helper lanes? In the case of NonUniformResourceIndex, I'm not confident I understand every scenario where it is needed.

To make this concrete, suppose we have a pixel shader, and want to access a resource located at ResourceDescriptorHeap[index]. In what scenarios would NonUniformResourceIndex be needed?

  • Some lanes return early, and the value of index is the same for all other active lanes.
  • Some lanes discard and are demoted to helper lanes (or start as helper lanes), and the value is the same for all lanes, helper or not.
  • Some lanes discard and are demoted to helper lanes (or start as helper lanes), and the value is the same for all non-helper lanes, but may diverge across helper lanes.

Refer also to this related issue filed in the HLSL specs repo.

Guidelines for usage in other shader stages

Mentions of NonUniformResourceIndex generally refer to "draws" and "dispatches" but it would be helpful to understand where they need to be used in other stages also for correctness. In particular, DXR hit/miss/intersection shaders that may undergo execution reordering (e.g. SER) comes to mind.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant