Description
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:
- fill in implicit bindings ([HLSL] Assign implicit resource binding #109861)
- generate
createHandleFromBinding
calls for all used resources during CodeGen ([HLSL] Emit dx.handle.fromBinding instead of dx.create_handle when resource is created #105076).
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:
-
SemaHLSL::handleResourceBindingAttr
just diagnoses the simple/local errors:err_hlsl_binding_type_invalid
- the type isn't valid at all, likex0
warn_hlsl_deprecated_register_type_i
- the type is deprecated/removed and ignoredwarn_hlsl_deprecated_register_type_b
- the type is deprecated/removed and ignoredwarn_hlsl_register_type_c_packoffset
- the type is in the wrong place (in acbuffer
)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.
-
Add a data member,
Bindings
, toSemaHLSL
to track the ranges that are already bound and the list ofDecl
s that still need to be bound. -
In
Sema::ActOnVariableDeclarator
(inSemaDecl.cpp
) after the call toProcessDeclAttributes
, call intoSemaHLSL
: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 UDTerr_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. -
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 typewarn_hlsl_overlapping_binding
Note that doing this here simplifies the parts of the design that need to differentiate between
HLSLBufferDecl
andVarDecl
, since the two code paths are separate. -
Later on in Sema (
ActOnEndOfTranslationUnit
?) we walk the list of unboundDecl
s and assign them bindings ([HLSL] Assign implicit resource binding #109861)
Metadata
Metadata
Assignees
Type
Projects
Status