Skip to content

[HLSL] Gather resource binding information  #58051

Closed as not planned
Closed as not planned
@python3kgae

Description

@python3kgae

Resource binding information is currently recorded only in HLSLResourceBinding attributes on declarations. The binding can be directly on a resource type, but also there may also be multiple register binding on a user defined type that contains multiple resource types. We need to gather all of this explicit resource binding information and create 1:1 mapping of FieldDecl or VarDecl to explicit. HLSLResourceBindingAttr.

Based on this information we can then:

We should try to share code between the register binding allocation and the diagnostics for invalid bindings. A strawman design for sharing the code would probably look something like this:

  1. SemaHLSL::handleResourceBindingAttr just diagnoses 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 would recursively walk the type similarly to the traversal described in this proposal, but instead of setting flags we'd calculate the size of the UAV, SRV, CBuffer, and Sampler bindings to add to SemaHLSL::Bindings.

    If a binding has zero size but we have an attribute for the binding we diagnose a mismatch:

    • warn_hlsl_binding_type_mismatch if it's a UDT
    • err_hlsl_binding_type_mismatch if it's a simple type

    This is where we would diagnose a new warn_hlsl_overlapping_binding if multiple separate things are bound in overlapping places.

  4. In SemaHLSL::ActOnFinishBuffer, add the binding for the cbuffer/tbuffer as a whole, using the size we calculate for diagnostics already. This will also need to diagnose a couple of things:

    • err_hlsl_binding_type_mismatch if it's a simple type
    • warn_hlsl_overlapping_binding

    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.

  5. Later on in Sema (ActOnEndOfTranslationUnit?) we walk the list of unbound Decls and assign them bindings ([HLSL] Assign implicit resource binding #109861)

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportbackend:DirectXobsoleteIssues with old (unsupported) versions of LLVM

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions