Repository navigation
Support Unsigned for shorthand vectors/matrices - #106
Conversation
1. enable unsigned keyword for int vectors/matrices (e.g. unsigned int2 -> vector<unsigned int, 2>) 2. disable unsigned keyword as a complete type specifier
|
Youngkim93, |
|
|
||
| // This function reads the given declaration TSS and returns the corresponding parsedType with the | ||
| // corresponding type. Replaces the given parsed type with the new type | ||
| clang::ParsedType ApplyTypeSpecSignToParsedType( |
There was a problem hiding this comment.
I think it would make more sense to operate on QualType rather than ParsedType at this level, since that's all we actually care about.
| // signed/unsigned are only valid with int/char/wchar_t. | ||
| if (TypeSpecSign != TSS_unspecified) { | ||
| if (TypeSpecType == TST_unspecified) | ||
| TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
There was a problem hiding this comment.
Instead of deleting the code that defaults to TST_int, can you "#if 0 // HLSL Change: ..." it out (makes integration with newer code easier).
| bool isStatic = storage == DeclSpec::SCS::SCS_static; | ||
| bool isExtern = storage == DeclSpec::SCS::SCS_extern; | ||
|
|
||
| bool isSigned = D.getDeclSpec().getTypeSpecSign() != DeclSpec::TSS::TSS_unspecified; |
There was a problem hiding this comment.
isSigned is a misleading name. Perhaps hasSignSpec instead?
| if (isSigned) { | ||
| HLSLExternalSource *hlslSource = HLSLExternalSource::FromSema(this); | ||
| ArTypeObjectKind objKind = hlslSource->GetTypeObjectKind(qt); | ||
| if (objKind != AR_TOBJ_MATRIX && objKind != AR_TOBJ_VECTOR && objKind != AR_TOBJ_BASIC) { |
There was a problem hiding this comment.
We should additionally get the component type and verify that it is an int/uint type, since I don't think we want to allow you to use unsigned with bool, float, double, etc... Or does fxc allow this and ignore it?
|
|
||
| void vector_unsigned() { | ||
| unsigned int4x2 intvector; | ||
| unsigned float2x4 floatvector; /* expected-error {{'float' cannot be signed or unsigned}} fxc-error {{X3085: unsigned can not be used with type}} */ |
There was a problem hiding this comment.
Shouldn't this be vector tests (as this is vector-syntax.hlsl)?
| if (qts == nullptr) { | ||
| qts = CreateVectorSpecializationShorthand(*m_context, qt, scalarType, | ||
| colCount); | ||
| m_vectorTypedefs[scalarType][colCount - 1] = qts; |
There was a problem hiding this comment.
It's probably a good time to encapsulate this lookup + create shorthand if it doesn't exist block in a method.
| if (qts == nullptr) { | ||
| qts = CreateVectorSpecializationShorthand(*m_context, qt, scalarType, | ||
| colCount); | ||
| m_matrixShorthandTypes[scalarType][rowCount - 1][colCount - 1] = qts; |
There was a problem hiding this comment.
Encapsulation for matrix case as well.
|
|
||
| void matrix_unsigned() { | ||
| unsigned int4x2 unsignedMatrix; | ||
| unsigned float1x4 unsignedFloatMatrix; /* expected-error {{'float' cannot be signed or unsigned}} fxc-error {{X3085: unsigned can not be used with type}} */ |
There was a problem hiding this comment.
Can we add more component types?
| // CHECK: uint4x4 | ||
|
|
||
| unsigned int2 a; | ||
| unsigned int4x4 b; |
There was a problem hiding this comment.
Test for signed as well? Also, try a all legal component types to ensure they translate (or pass through) properly.
There was a problem hiding this comment.
Will not add signed cases because it is not supported in HLSL
| _In_ clang::ParsedType &parsedType, | ||
| _In_ TypeSpecifierSign TSS, | ||
| _In_ SourceLocation Loc, | ||
| _In_ const PrintingPolicy &policy |
There was a problem hiding this comment.
Don't need PrintingPolicy (since you should remove Diag - but you aren't even using it here)
- allow other int types (min16int, uint64_t) to have unsigned shorthand vectors - more tests for different component types
|
|
||
| HRESULT CombineDimensions(QualType leftType, QualType rightType, QualType *resultType); | ||
|
|
||
| clang::TypedefDecl *HLSLExternalSource::GetMatrixShorthandTypes( |
There was a problem hiding this comment.
This method is being defined within the HLSLExternalSource class definition, there's no need for the "HLSLExternalSource::" prefixing the method name. Same with the next method below.
Also, GetMatrixShorthandTypes should probably not be plural, change to: GetMatrixShorthandType.
| } | ||
|
|
||
| clang::TypedefDecl *HLSLExternalSource::GetVectorShorthandType( | ||
| QualType type, HLSLScalarType scalarType, UINT colCount) { |
There was a problem hiding this comment.
These methods should incorporate Lookup[Vector|Matrix]Type, eliminating the need for the QualType parameter supplied by the caller. Further, this call is only necessary when creating the specialization shorthand, so it can be placed within the if (qts == nullptr) block.
| UINT colCount = GetHLSLVecSize(type); | ||
| QualType qt = LookupVectorType(newScalarType, colCount); | ||
| TypedefDecl *qts = GetVectorShorthandType(qt, newScalarType, colCount); | ||
| return qt; |
There was a problem hiding this comment.
Should this not return the new shorthand type? Use return "m_context->getTypeDeclType(qts);" to return the shorthand type.
| unsigned bool3x4 boolvector; /* expected-error {{'bool' cannot be signed or unsigned}} fxc-error {{X3085: unsigned can not be used with type}} */ | ||
| unsigned half4x1 halfvector; /* expected-error {{'float' cannot be signed or unsigned}} fxc-error {{X3085: unsigned can not be used with type}} */ | ||
| unsigned double1x2 doublevector; /* expected-error {{'double' cannot be signed or unsigned}} fxc-error {{X3085: unsigned can not be used with type}} */ | ||
| unsigned min12int2x3 min12intvector; /* expected-warning {{min12int is promoted to min16int}} fxc-error {{X3085: unsigned can not be used with type}} */ |
There was a problem hiding this comment.
I thought we would emit an error in this case (like fxc), not just the warning about type promotion.
- throw an error for shorthand min12int vectors/matrices
(for example, "unsigned int2" will be converted to "vector<unsigned int, 2>")