Skip to content

Commit bdf9e64

Browse files
committed
Non-functional: Remove reinventing the scalar type, note code issues
The scalar type was already the basic type passed in. Also factored out of this the checking of extensions for 8/16-bit stuff. This code seems wrong in several ways, but for now just documenting it.
1 parent b58f308 commit bdf9e64

File tree

1 file changed

+37
-46
lines changed

1 file changed

+37
-46
lines changed

glslang/MachineIndependent/Intermediate.cpp

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,64 +1040,30 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
10401040
// Note: callers are responsible for other aspects of shape,
10411041
// like vector and matrix sizes.
10421042

1043-
TBasicType promoteTo;
1044-
// GL_EXT_shader_16bit_storage can't do OpConstantComposite with
1045-
// 16-bit types, so disable promotion for those types.
1046-
bool canPromoteConstant = true;
1047-
10481043
switch (op) {
10491044
//
10501045
// Explicit conversions (unary operations)
10511046
//
10521047
case EOpConstructBool:
1053-
promoteTo = EbtBool;
1054-
break;
10551048
case EOpConstructFloat:
1056-
promoteTo = EbtFloat;
1057-
break;
10581049
case EOpConstructInt:
1059-
promoteTo = EbtInt;
1060-
break;
10611050
case EOpConstructUint:
1062-
promoteTo = EbtUint;
1063-
break;
10641051
#ifndef GLSLANG_WEB
10651052
case EOpConstructDouble:
1066-
promoteTo = EbtDouble;
1067-
break;
10681053
case EOpConstructFloat16:
1069-
promoteTo = EbtFloat16;
1070-
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1071-
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_float16);
1072-
break;
10731054
case EOpConstructInt8:
1074-
promoteTo = EbtInt8;
1075-
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1076-
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int8);
1077-
break;
10781055
case EOpConstructUint8:
1079-
promoteTo = EbtUint8;
1080-
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1081-
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int8);
1082-
break;
10831056
case EOpConstructInt16:
1084-
promoteTo = EbtInt16;
1085-
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1086-
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16);
1087-
break;
10881057
case EOpConstructUint16:
1089-
promoteTo = EbtUint16;
1090-
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1091-
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16);
1092-
break;
10931058
case EOpConstructInt64:
1094-
promoteTo = EbtInt64;
1095-
break;
10961059
case EOpConstructUint64:
1097-
promoteTo = EbtUint64;
10981060
break;
1061+
10991062
#endif
11001063

1064+
//
1065+
// Implicit conversions
1066+
//
11011067
case EOpLogicalNot:
11021068

11031069
case EOpFunctionCall:
@@ -1152,9 +1118,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
11521118
if (type.getBasicType() == node->getType().getBasicType())
11531119
return node;
11541120

1155-
if (canImplicitlyPromote(node->getBasicType(), type.getBasicType(), op))
1156-
promoteTo = type.getBasicType();
1157-
else
1121+
if (! canImplicitlyPromote(node->getBasicType(), type.getBasicType(), op))
11581122
return nullptr;
11591123
break;
11601124

@@ -1164,9 +1128,7 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
11641128
case EOpLeftShiftAssign:
11651129
case EOpRightShiftAssign:
11661130
{
1167-
if (getSource() == EShSourceHlsl && node->getType().getBasicType() == EbtBool)
1168-
promoteTo = type.getBasicType();
1169-
else {
1131+
if (!(getSource() == EShSourceHlsl && node->getType().getBasicType() == EbtBool)) {
11701132
if (isTypeInt(type.getBasicType()) && isTypeInt(node->getBasicType()))
11711133
return node;
11721134
else
@@ -1184,13 +1146,42 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
11841146
return nullptr;
11851147
}
11861148

1149+
bool canPromoteConstant = true;
1150+
#ifndef GLSLANG_WEB
1151+
// GL_EXT_shader_16bit_storage can't do OpConstantComposite with
1152+
// 16-bit types, so disable promotion for those types.
1153+
// Many issues with this, from JohnK:
1154+
// - this isn't really right to discuss SPIR-V here
1155+
// - this could easily be entirely about scalars, so is overstepping
1156+
// - we should be looking at what the shader asked for, and saying whether or
1157+
// not it can be done, in the parser, by calling requireExtensions(), not
1158+
// changing language sementics on the fly by asking what extensions are in use
1159+
// - at the time of this writing (14-Aug-2020), no test results are changed by this.
1160+
switch (op) {
1161+
case EOpConstructFloat16:
1162+
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1163+
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_float16);
1164+
break;
1165+
case EOpConstructInt8:
1166+
case EOpConstructUint8:
1167+
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1168+
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int8);
1169+
break;
1170+
case EOpConstructInt16:
1171+
case EOpConstructUint16:
1172+
canPromoteConstant = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
1173+
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16);
1174+
break;
1175+
}
1176+
#endif
1177+
11871178
if (canPromoteConstant && node->getAsConstantUnion())
1188-
return promoteConstantUnion(promoteTo, node->getAsConstantUnion());
1179+
return promoteConstantUnion(type.getBasicType(), node->getAsConstantUnion());
11891180

11901181
//
11911182
// Add a new newNode for the conversion.
11921183
//
1193-
TIntermTyped* newNode = createConversion(promoteTo, node);
1184+
TIntermTyped* newNode = createConversion(type.getBasicType(), node);
11941185

11951186
return newNode;
11961187
}

0 commit comments

Comments
 (0)