Skip to content

[HLSL] Generate unique key object for Heap and Lib resource handles #125126

Open
@V-FEXrt

Description

@V-FEXrt

The previous context and history of the issue is kept in the minimized window below.

For the remaining work of this specific task, an update is required to the DXILResourceBindingMap to lookup the unique creation call for Resources that are eventually lowered to CreateHandleFromHeap and CreateHandleForLib DXIL Ops. Depending on the actual implementation it may be possible to fully reuse the implementation dervied from @llvm.dx.resource.handlefrombinding. Here is that implementation:

case Intrinsic::dx_resource_handlefrombinding: {

Its likely not useful, but just in case, here are the bits of data from the DXIL perspective that makes the creation unique:

  • CreateHandleFromHeap - dynamic resource or sampler from heap (SM 6.6+):
    Use samplerHeap to determine whether sampler or other resource
    Use index value to uniquely identify resource.
  • CreateHandleForLib - create handle for library targets
    Use input obj loaded from global variable to uniquely identify resource (GV may be indexed with GEP)
Previous Context and History

Late stage analysis such as #114130 require the ability to discern if handles are referencing the same resource. Infrastructure should be added to generate a value/key that is unique per resource given a llvm::Value to the ident.

We should do this by adding some API surface to DXIL resource analysis that can look up a Value * and tell us which resource it is.

DXIL Approach

While we will do this at the LLVM IR representation level, it is informative to consider the problem at a DXIL level:

  • optionally drill through an AnnotateHandle (depending on shader target)
  • value should be a CreateHandle of one kind or another. There are four types, depending on target and whether it's a dynamic resource.
    • CreateHandle - bound resource on non-lib SM 6.5 and below:
      use resourceClass, rangeId (index into metadata for the resource range), and the index to uniquely identify as a bound resource.
    • CreateHandleFromBinding - bound resource on non-lib SM 6.6 and above:
      Use resbind and index to uniquely identify as a bound resource.
    • CreateHandleFromHeap - dynamic resource or sampler from heap (SM 6.6+):
      Use samplerHeap to determine whether sampler or other resource
      Use index value to uniquely identify resource.
    • CreateHandleForLib - create handle for library targets
      Use input obj loaded from global variable to uniquely identify resource (GV may be indexed with GEP)

In each case, index may be dynamic, in which case, if it's not the same Value*, you can't tell if it's the same resource as another value. For CreateHandleForLib the potential GEP from GV may have the dynamic index, so the combination of the GV and GEP indices are the key. There is also the nonUniformIndex flag which might require some special consideration.

LLVM IR approach

LLVM IR simplifies some of this in that we don't need to deal with AnnotateHandle or the version dependence of CreateHandle.

Today, we have the DXILBindingMap, which gets us most of the way there for handles from bindings (llvm.dx.resource.handlefrombinding), but we don't yet have infrastructure for handles from heaps and handles from pointers a-la library shaders.

We will need to:

  1. Update the DXILBindingMap or add an extra layer of indirection that handles indices
  2. Add mappings for heap and library to the above
  3. Implement an API that walks from a Value to the appropriate intrinsic call and then looks that up in the map

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Support

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions