@@ -240,16 +240,18 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
240240 DescriptorTable Table;
241241 std::optional<llvm::dxbc::ShaderVisibility> Visibility;
242242
243- // Iterate as many Clauses as possible
244- do {
243+ // Iterate as many Clauses as possible, until we hit ')'
244+ while (! peekExpectedToken (TokenKind::pu_r_paren)) {
245245 if (tryConsumeExpectedToken ({TokenKind::kw_CBV, TokenKind::kw_SRV,
246246 TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
247+ // DescriptorTableClause - CBV, SRV, UAV, or Sampler
247248 auto Clause = parseDescriptorTableClause ();
248249 if (!Clause.has_value ())
249250 return std::nullopt ;
250251 Elements.push_back (*Clause);
251252 Table.NumClauses ++;
252253 } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
254+ // visibility = SHADER_VISIBILITY
253255 if (Visibility.has_value ()) {
254256 reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
255257 return std::nullopt ;
@@ -262,17 +264,21 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
262264 if (!Visibility.has_value ())
263265 return std::nullopt ;
264266 }
265- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
266267
267- // Fill in optional visibility
268- if (Visibility.has_value ())
269- Table.Visibility = Visibility.value ();
268+ // ',' denotes another element, otherwise, expected to be at ')'
269+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
270+ break ;
271+ }
270272
271273 if (consumeExpectedToken (TokenKind::pu_r_paren,
272274 diag::err_hlsl_unexpected_end_of_params,
273275 /* param of=*/ TokenKind::kw_DescriptorTable))
274276 return std::nullopt ;
275277
278+ // Fill in optional visibility
279+ if (Visibility.has_value ())
280+ Table.Visibility = Visibility.value ();
281+
276282 return Table;
277283}
278284
0 commit comments