@@ -1038,6 +1038,8 @@ Triple::Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
1038
1038
ObjectFormat = getDefaultFormat (*this );
1039
1039
}
1040
1040
1041
+ static VersionTuple parseVersionFromName (StringRef Name);
1042
+
1041
1043
std::string Triple::normalize (StringRef Str) {
1042
1044
bool IsMinGW32 = false ;
1043
1045
bool IsCygwin = false ;
@@ -1236,21 +1238,39 @@ std::string Triple::normalize(StringRef Str) {
1236
1238
// version numbering from that of Shader Model DXIL version 1.Y corresponds to
1237
1239
// SM 6.Y. E.g., dxilv1.Y-unknown-shadermodelX.Y-hull
1238
1240
if (Components[0 ] == " dxil" ) {
1239
- std::string DXILVerStr{" dxilv1." };
1240
- if (Components.size () > 2 ) {
1241
- // OS component specified
1242
- if (Components[2 ].starts_with (" shadermodel6." )) {
1243
- Components[0 ] = DXILVerStr.append (
1244
- Components[2 ].drop_front (strlen (" shadermodel6." )));
1245
- } else if (Components[2 ].starts_with (" shadermodel" )) {
1246
- // If shader model specified is other than 6.x, set DXIL Version to 1.0
1247
- Components[0 ] = DXILVerStr.append (" 0" );
1241
+ if (Components.size () > 4 ) {
1242
+ Components.resize (4 );
1243
+ }
1244
+ // Add DXIL version only if shadermodel is specified in the triple
1245
+ if (OS == Triple::ShaderModel) {
1246
+ VersionTuple Ver = parseVersionFromName (Components[2 ].drop_front (strlen (" shadermodel" )));
1247
+ // Default DXIL minor version when Shader Model version is anything other than
1248
+ // 6.[0...8] or 6.x (which translates to latest current SM version)
1249
+ // DXIL version corresponding to Shader Model version other than 6.x is 1.0
1250
+ unsigned DXILMinor = 0 ;
1251
+ const unsigned SMMajor = 6 ;
1252
+ const unsigned LatestCurrentDXILMinor = 8 ;
1253
+ if (!Ver.empty ()) {
1254
+ if (Ver.getMajor () == SMMajor) {
1255
+ if (std::optional<unsigned > SMMinor = Ver.getMinor ()) {
1256
+ DXILMinor = *SMMinor;
1257
+ // Ensure specified minor version is supported
1258
+ if (DXILMinor > LatestCurrentDXILMinor) {
1259
+ report_fatal_error (" Unsupported Shader Model version" , false );
1260
+ }
1261
+ }
1262
+ }
1263
+ } else {
1264
+ // Special case: DXIL minor version is set to LatestCurrentDXILMinor for
1265
+ // shadermodel6.x is
1266
+ if (Components[2 ] == " shadermodel6.x" ) {
1267
+ DXILMinor = LatestCurrentDXILMinor;
1268
+ }
1248
1269
}
1270
+ Components[0 ] =
1271
+ Components[0 ].str ().append (" v1." ).append (std::to_string (DXILMinor));
1249
1272
}
1250
- // DXIL version is not set for a non-specified OS string or one that does
1251
- // not starts with shadermodel.
1252
1273
}
1253
-
1254
1274
// Stick the corrected components back together to form the normalized string.
1255
1275
return join (Components, " -" );
1256
1276
}
0 commit comments