Skip to content

[HLSL] Collect explicit resource binding information #110719

Closed
@bogner

Description

@bogner

This is the explicit bindings part of the bindings approach originally described in #58051.

Binding information is recorded in HLSLResourceBinding attributes on declarations. We currently have logic to diagnose these bindings, but we don't store this information to later use in lowering to llvm.dx.handle.fromBinding intrinsics. We need to gather all of the explicit resource binding information and create 1:1 mapping of FieldDecl or VarDecl to explicit HLSLResourceBindingAttr.

In order to share code with the binding diagnostics, we need a couple of adjustments:

  1. SemaHLSL::handleResourceBindingAttr can continue to diagnose the simple/local errors:

    • err_hlsl_binding_type_invalid - the type isn't valid at all, like x0
    • warn_hlsl_deprecated_register_type_i - the type is deprecated/removed and ignored
    • warn_hlsl_deprecated_register_type_b - the type is deprecated/removed and ignored
    • warn_hlsl_register_type_c_packoffset - the type is in the wrong place (in a cbuffer)
    • warn_hlsl_overlapping_binding - the same binding type is applied more than once

    These shouldn't need any traversal of types to diagnose, so keeping them here is simplest.

  2. Add a data member, Bindings, to SemaHLSL to track the ranges that are already bound and the list of Decls that still need to be bound.

  3. In Sema::ActOnVariableDeclarator (in SemaDecl.cpp) after the call to ProcessDeclAttributes, call into SemaHLSL:

    if (getLangOpts().HLSL && NewVD->hasGlobalStorage()) {
        HLSL()->handleBindings(NewVD);

    This is where the recursive walk that diagnoses binding type mismatches should move. It can fill in the binding map as it goes.

  4. The bindings for cbuffer/tbuffer can be diagnosed and applied in SemaHLSL::ActOnFinishBuffer.

    Note that doing this here simplifies the parts of the design that need to differentiate between HLSLBufferDecl and VarDecl, since the two code paths are separate.

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions