microsoft / DirectX-Specs

Engineering specs for DirectX features.

Home Page:https://devblogs.microsoft.com/directx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clarify `NonUniformResourceIndex` usage

jeremyong opened this issue · comments

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!