@@ -43,6 +43,41 @@ static void _insertBinding(
43
43
ranges.add (newRange);
44
44
}
45
45
46
+ void collectMetadataFromInst (IRInst* param, ArtifactPostEmitMetadata& outMetadata)
47
+ {
48
+ auto layoutDecoration = param->findDecoration <IRLayoutDecoration>();
49
+ if (!layoutDecoration)
50
+ return ;
51
+
52
+ auto varLayout = as<IRVarLayout>(layoutDecoration->getLayout ());
53
+ if (!varLayout)
54
+ return ;
55
+
56
+ for (auto sizeAttr : varLayout->getTypeLayout ()->getSizeAttrs ())
57
+ {
58
+ auto kind = sizeAttr->getResourceKind ();
59
+
60
+ // Only track resource types that we can reliably track, such as textures.
61
+ // Do not track individual uniforms, for example.
62
+ if (!ShaderBindingRange::isUsageTracked (kind))
63
+ continue ;
64
+
65
+ if (auto offsetAttr = varLayout->findOffsetAttr (kind))
66
+ {
67
+ // Get the binding information from this attribute and insert it into the list
68
+ auto spaceIndex = offsetAttr->getSpace ();
69
+ if (auto spaceAttr = varLayout->findOffsetAttr (LayoutResourceKind::RegisterSpace))
70
+ {
71
+ spaceIndex += spaceAttr->getOffset ();
72
+ }
73
+ auto registerIndex = offsetAttr->getOffset ();
74
+ auto size = sizeAttr->getSize ();
75
+ auto count = size.isFinite () ? size.getFiniteValue () : 0 ;
76
+ _insertBinding (outMetadata.m_usedBindings , kind, spaceIndex, registerIndex, count);
77
+ }
78
+ }
79
+ }
80
+
46
81
// Collects the metadata from the provided IR module, saves it in outMetadata.
47
82
void collectMetadata (const IRModule* irModule, ArtifactPostEmitMetadata& outMetadata)
48
83
{
@@ -57,39 +92,18 @@ void collectMetadata(const IRModule* irModule, ArtifactPostEmitMetadata& outMeta
57
92
auto name = func->findDecoration <IRExportDecoration>()->getMangledName ();
58
93
outMetadata.m_exportedFunctionMangledNames .add (name);
59
94
}
95
+
96
+ // Collect metadata from entrypoint params.
97
+ for (auto param : func->getParams ())
98
+ {
99
+ collectMetadataFromInst (param, outMetadata);
100
+ }
60
101
}
61
102
62
103
auto param = as<IRGlobalParam>(inst);
63
104
if (!param)
64
105
continue ;
65
-
66
- auto layoutDecoration = param->findDecoration <IRLayoutDecoration>();
67
- if (!layoutDecoration)
68
- continue ;
69
-
70
- auto varLayout = as<IRVarLayout>(layoutDecoration->getLayout ());
71
- if (!varLayout)
72
- continue ;
73
-
74
- for (auto sizeAttr : varLayout->getTypeLayout ()->getSizeAttrs ())
75
- {
76
- auto kind = sizeAttr->getResourceKind ();
77
-
78
- // Only track resource types that we can reliably track, such as textures.
79
- // Do not track individual uniforms, for example.
80
- if (!ShaderBindingRange::isUsageTracked (kind))
81
- continue ;
82
-
83
- if (auto offsetAttr = varLayout->findOffsetAttr (kind))
84
- {
85
- // Get the binding information from this attribute and insert it into the list
86
- auto spaceIndex = offsetAttr->getSpace ();
87
- auto registerIndex = offsetAttr->getOffset ();
88
- auto size = sizeAttr->getSize ();
89
- auto count = size.isFinite () ? size.getFiniteValue () : 0 ;
90
- _insertBinding (outMetadata.m_usedBindings , kind, spaceIndex, registerIndex, count);
91
- }
92
- }
106
+ collectMetadataFromInst (param, outMetadata);
93
107
}
94
108
}
95
109
0 commit comments