Skip to content

Commit 7c8005a

Browse files
author
Greg Roth
authored
[SM6.9] Allow native vectors longer than 4 (microsoft#7143)
Remove errors in Sema diagnostics for vectors longer than 4 in 6.9. Test for failures using long vectors in unspported contexts and for correct codegen in supported contexts. Verify errors persist in pre-6.9 shader models The type buffer cache expects a max vector size of 4. By just skipping the cache for longer vectors, we don't overrun and store float7 vectors in the double3 slot or retrieve the double3 in place of float7. Testing is for acceptance, mangling and basic copying that takes place at the high level to ensure they are being accepted and recognized correctly. The intent is not to tully test the passing of data as that requires enabling vector operations to do properly. This test is used to verify that these same constructs are disallowed in 6.8 and earlier. A separate test verifies that disallowed contexts produce the appropriate errors Fixes microsoft#7117
2 parents 4d3a2f5 + 88479cf commit 7c8005a

26 files changed

+1267
-365
lines changed

include/dxc/DXIL/DxilConstants.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ const unsigned kMaxMSTotalSigRows = 32;
147147
const unsigned kMaxMSSMSize = 1024 * 28;
148148
const unsigned kMinWaveSize = 4;
149149
const unsigned kMaxWaveSize = 128;
150+
const unsigned kDefaultMaxVectorLength = 4;
151+
const unsigned kSM69MaxVectorLength = 1024;
150152

151153
const float kMaxMipLodBias = 15.99f;
152154
const float kMinMipLodBias = -16.0f;
@@ -463,6 +465,11 @@ inline bool IsTBuffer(DXIL::ResourceKind ResourceKind) {
463465
return ResourceKind == DXIL::ResourceKind::TBuffer;
464466
}
465467

468+
inline bool IsCTBuffer(DXIL::ResourceKind ResourceKind) {
469+
return ResourceKind == DXIL::ResourceKind::CBuffer ||
470+
ResourceKind == DXIL::ResourceKind::TBuffer;
471+
}
472+
466473
/// Whether the resource kind is a FeedbackTexture.
467474
inline bool IsFeedbackTexture(DXIL::ResourceKind ResourceKind) {
468475
return ResourceKind == DXIL::ResourceKind::FeedbackTexture2D ||

lib/DXIL/DxilUtil.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -426,35 +426,37 @@ GetHLSLResourceProperties(llvm::Type *Ty) {
426426
false, false, false));
427427

428428
if (name == "SamplerComparisonState")
429-
return RetType(
430-
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::Sampler, false,
431-
false, /*cmp or counter*/ true));
429+
return RetType(true, MakeResourceProperties(
430+
hlsl::DXIL::ResourceKind::Sampler, /*UAV*/ false,
431+
/*ROV*/ false, /*cmp or counter*/ true));
432432

433433
if (name.startswith("AppendStructuredBuffer<"))
434-
return RetType(true, MakeResourceProperties(
435-
hlsl::DXIL::ResourceKind::StructuredBuffer,
436-
false, false, /*cmp or counter*/ true));
434+
return RetType(true,
435+
MakeResourceProperties(
436+
hlsl::DXIL::ResourceKind::StructuredBuffer,
437+
/*UAV*/ true, /*ROV*/ false, /*cmp or counter*/ true));
437438

438439
if (name.startswith("ConsumeStructuredBuffer<"))
439440
return RetType(true, MakeResourceProperties(
440441
hlsl::DXIL::ResourceKind::StructuredBuffer,
441-
false, false, /*cmp or counter*/ true));
442+
/*UAV*/ true, /*ROV*/ false,
443+
/*cmp or counter*/ true));
442444

443445
if (name == "RaytracingAccelerationStructure")
444446
return RetType(true,
445447
MakeResourceProperties(
446448
hlsl::DXIL::ResourceKind::RTAccelerationStructure,
447-
false, false, false));
449+
/*UAV*/ false, /*ROV*/ false, false));
448450

449451
if (name.startswith("ConstantBuffer<"))
450-
return RetType(true,
451-
MakeResourceProperties(hlsl::DXIL::ResourceKind::CBuffer,
452-
false, false, false));
452+
return RetType(
453+
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::CBuffer,
454+
/*UAV*/ false, /*ROV*/ false, false));
453455

454456
if (name.startswith("TextureBuffer<"))
455-
return RetType(true,
456-
MakeResourceProperties(hlsl::DXIL::ResourceKind::TBuffer,
457-
false, false, false));
457+
return RetType(
458+
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::TBuffer,
459+
/*UAV*/ false, /*ROV*/ false, false));
458460

459461
if (ConsumePrefix(name, "FeedbackTexture2D")) {
460462
hlsl::DXIL::ResourceKind kind = hlsl::DXIL::ResourceKind::Invalid;
@@ -464,7 +466,9 @@ GetHLSLResourceProperties(llvm::Type *Ty) {
464466
kind = hlsl::DXIL::ResourceKind::FeedbackTexture2D;
465467

466468
if (name.startswith("<"))
467-
return RetType(true, MakeResourceProperties(kind, false, false, false));
469+
return RetType(true,
470+
MakeResourceProperties(kind, /*UAV*/ false,
471+
/*ROV*/ false, /*Cmp*/ false));
468472

469473
return FalseRet;
470474
}
@@ -475,63 +479,63 @@ GetHLSLResourceProperties(llvm::Type *Ty) {
475479
if (name == "ByteAddressBuffer")
476480
return RetType(true,
477481
MakeResourceProperties(hlsl::DXIL::ResourceKind::RawBuffer,
478-
UAV, ROV, false));
482+
UAV, ROV, /*Cmp*/ false));
479483

480484
if (name.startswith("Buffer<"))
481485
return RetType(
482486
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::TypedBuffer,
483-
UAV, ROV, false));
487+
UAV, ROV, /*Cmp*/ false));
484488

485489
if (name.startswith("StructuredBuffer<"))
486490
return RetType(true, MakeResourceProperties(
487491
hlsl::DXIL::ResourceKind::StructuredBuffer, UAV,
488-
ROV, false));
492+
ROV, /*Cmp*/ false));
489493

490494
if (ConsumePrefix(name, "Texture")) {
491495
if (name.startswith("1D<"))
492496
return RetType(
493497
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::Texture1D,
494-
UAV, ROV, false));
498+
UAV, ROV, /*Cmp*/ false));
495499

496500
if (name.startswith("1DArray<"))
497501
return RetType(true, MakeResourceProperties(
498502
hlsl::DXIL::ResourceKind::Texture1DArray, UAV,
499-
ROV, false));
503+
ROV, /*Cmp*/ false));
500504

501505
if (name.startswith("2D<"))
502506
return RetType(
503507
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::Texture2D,
504-
UAV, ROV, false));
508+
UAV, ROV, /*Cmp*/ false));
505509

506510
if (name.startswith("2DArray<"))
507511
return RetType(true, MakeResourceProperties(
508512
hlsl::DXIL::ResourceKind::Texture2DArray, UAV,
509-
ROV, false));
513+
ROV, /*Cmp*/ false));
510514

511515
if (name.startswith("3D<"))
512516
return RetType(
513517
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::Texture3D,
514-
UAV, ROV, false));
518+
UAV, ROV, /*Cmp*/ false));
515519

516520
if (name.startswith("Cube<"))
517521
return RetType(
518522
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::TextureCube,
519-
UAV, ROV, false));
523+
UAV, ROV, /*Cmp*/ false));
520524

521525
if (name.startswith("CubeArray<"))
522526
return RetType(true, MakeResourceProperties(
523527
hlsl::DXIL::ResourceKind::TextureCubeArray,
524-
UAV, ROV, false));
528+
UAV, ROV, /*Cmp*/ false));
525529

526530
if (name.startswith("2DMS<"))
527531
return RetType(
528532
true, MakeResourceProperties(hlsl::DXIL::ResourceKind::Texture2DMS,
529-
UAV, ROV, false));
533+
UAV, ROV, /*Cmp*/ false));
530534

531535
if (name.startswith("2DMSArray<"))
532536
return RetType(true, MakeResourceProperties(
533537
hlsl::DXIL::ResourceKind::Texture2DMSArray,
534-
UAV, ROV, false));
538+
UAV, ROV, /*Cmp*/ false));
535539
return FalseRet;
536540
}
537541
}

tools/clang/include/clang/AST/DeclCXX.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ class CXXRecordDecl : public RecordDecl {
465465
/// \brief Whether we are currently parsing base specifiers.
466466
bool IsParsingBaseSpecifiers : 1;
467467

468+
/// \brief Whether this class contains at least one member or base
469+
/// class containing an HLSL vector longer than 4 elements.
470+
bool HasHLSLLongVector : 1;
471+
468472
/// \brief The number of base class specifiers in Bases.
469473
unsigned NumBases;
470474

@@ -1018,6 +1022,13 @@ class CXXRecordDecl : public RecordDecl {
10181022
return data().NeedOverloadResolutionForDestructor;
10191023
}
10201024

1025+
// HLSL Change add HLSL Long vector bit.
1026+
/// \brief Determine whether this class contains an HLSL long vector
1027+
/// of over 4 elements.
1028+
bool hasHLSLLongVector() { return data().HasHLSLLongVector; }
1029+
/// \brief Set that this class contains an HLSL long vector of over 4 elements
1030+
bool setHasHLSLLongVector() { return data().HasHLSLLongVector = true; }
1031+
10211032
/// \brief Determine whether this class describes a lambda function object.
10221033
bool isLambda() const {
10231034
// An update record can't turn a non-lambda into a lambda.

tools/clang/include/clang/AST/HlslTypes.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,10 @@ void AddHLSLNodeOutputRecordTemplate(
348348
_Outptr_ clang::ClassTemplateDecl **outputRecordTemplateDecl,
349349
bool isCompleteType = true);
350350

351-
clang::CXXRecordDecl *DeclareRecordTypeWithHandle(clang::ASTContext &context,
352-
llvm::StringRef name,
353-
bool isCompleteType = true);
351+
clang::CXXRecordDecl *
352+
DeclareRecordTypeWithHandle(clang::ASTContext &context, llvm::StringRef name,
353+
bool isCompleteType = true,
354+
clang::InheritableAttr *Attr = nullptr);
354355

355356
void AddRaytracingConstants(clang::ASTContext &context);
356357
void AddSamplerFeedbackConstants(clang::ASTContext &context);
@@ -381,14 +382,14 @@ clang::CXXRecordDecl *DeclareTemplateTypeWithHandleInDeclContext(
381382

382383
clang::CXXRecordDecl *DeclareUIntTemplatedTypeWithHandle(
383384
clang::ASTContext &context, llvm::StringRef typeName,
384-
llvm::StringRef templateParamName,
385-
clang::TagTypeKind tagKind = clang::TagTypeKind::TTK_Class);
385+
llvm::StringRef templateParamName, clang::InheritableAttr *Attr = nullptr);
386386
clang::CXXRecordDecl *DeclareUIntTemplatedTypeWithHandleInDeclContext(
387387
clang::ASTContext &context, clang::DeclContext *declContext,
388388
llvm::StringRef typeName, llvm::StringRef templateParamName,
389-
clang::TagTypeKind tagKind = clang::TagTypeKind::TTK_Class);
390-
clang::CXXRecordDecl *DeclareConstantBufferViewType(clang::ASTContext &context,
391-
bool bTBuf);
389+
clang::InheritableAttr *Attr = nullptr);
390+
clang::CXXRecordDecl *
391+
DeclareConstantBufferViewType(clang::ASTContext &context,
392+
clang::InheritableAttr *Attr);
392393
clang::CXXRecordDecl *DeclareRayQueryType(clang::ASTContext &context);
393394
clang::CXXRecordDecl *DeclareResourceType(clang::ASTContext &context,
394395
bool bSampler);

tools/clang/include/clang/Basic/Attr.td

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,52 @@ def HLSLCXXOverload : InheritableAttr {
939939
let Documentation = [Undocumented];
940940
}
941941

942+
def HLSLVector : InheritableAttr {
943+
let Spellings = []; // No spellings!
944+
let Subjects = SubjectList<[CXXRecord]>;
945+
let Documentation = [Undocumented];
946+
}
947+
948+
def HLSLMatrix : InheritableAttr {
949+
let Spellings = []; // No spellings!
950+
let Subjects = SubjectList<[CXXRecord]>;
951+
let Documentation = [Undocumented];
952+
}
953+
954+
def HLSLTessPatch : InheritableAttr {
955+
let Spellings = []; // No spellings!
956+
let Args = [BoolArgument<"IsInput">];
957+
let Subjects = SubjectList<[CXXRecord]>;
958+
let Documentation = [Undocumented];
959+
}
960+
961+
def HLSLStreamOutput : InheritableAttr {
962+
let Spellings = []; // No spellings!
963+
// PrimVertices are the number of vertices that make up the streamed
964+
// primitive. Points have 1. Lines have 2. Triangles have 3.
965+
let Args = [UnsignedArgument<"PrimVertices">];
966+
let Subjects = SubjectList<[CXXRecord]>;
967+
let Documentation = [Undocumented];
968+
}
969+
970+
def HLSLResource : InheritableAttr {
971+
let Spellings = []; // No spellings!
972+
let Args = [UnsignedArgument<"ResKindUint">,
973+
UnsignedArgument<"ResClassUint">];
974+
let Subjects = SubjectList<[CXXRecord]>;
975+
let Documentation = [Undocumented];
976+
977+
// Add enum typed getters for safety and brevity.
978+
let AdditionalMembers = [{
979+
hlsl::DXIL::ResourceKind getResKind() const {
980+
return (hlsl::DXIL::ResourceKind)getResKindUint();
981+
}
982+
hlsl::DXIL::ResourceClass getResClass() const {
983+
return (hlsl::DXIL::ResourceClass)getResClassUint();
984+
}
985+
}];
986+
}
987+
942988
def HLSLNodeLaunch : InheritableAttr {
943989
let Spellings = [CXX11<"", "nodelaunch", 2017>];
944990
let Args = [StringArgument<"LaunchType">]; // one of broadcasting, coalescing, thread
@@ -992,13 +1038,6 @@ def HLSLNodeTrackRWInputSharing : InheritableAttr {
9921038
let Documentation = [Undocumented];
9931039
}
9941040

995-
def HLSLResource : InheritableAttr {
996-
let Spellings = []; // No spellings!
997-
let Args = [UnsignedArgument<"ResKind">, UnsignedArgument<"ResClass">];
998-
let Subjects = SubjectList<[CXXRecord]>;
999-
let Documentation = [Undocumented];
1000-
}
1001-
10021041
def HLSLNodeObject : InheritableAttr {
10031042
let Spellings = []; // No spellings!
10041043
let Subjects = SubjectList<[CXXRecord]>;

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7519,8 +7519,8 @@ def err_hlsl_half_load_store: Error<
75197519
"LoadHalf and StoreHalf are not supported for min precision mode">;
75207520
def err_hlsl_interfaces_cannot_inherit: Error<
75217521
"interfaces cannot inherit from other types">;
7522-
def err_hlsl_invalid_range_1_4: Error<
7523-
"invalid value, valid range is between 1 and 4 inclusive">;
7522+
def err_hlsl_invalid_range_1_to_max
7523+
: Error<"invalid value, valid range is between 1 and %0 inclusive">;
75247524
def err_hlsl_matrix_member_bad_format: Error<
75257525
"invalid format for matrix subscript '%0'">;
75267526
def err_hlsl_matrix_member_empty: Error<
@@ -7701,8 +7701,6 @@ def err_hlsl_control_flow_cond_not_scalar : Error<
77017701
"%0 statement conditional expressions must evaluate to a scalar">;
77027702
def err_hlsl_unsupportedvectortype : Error<
77037703
"%0 is declared with type %1, but only primitive scalar values are supported">;
7704-
def err_hlsl_unsupportedvectorsize : Error<
7705-
"%0 is declared with size %1, but only values 1 through 4 are supported">;
77067704
def err_hlsl_unsupportedmatrixsize : Error<
77077705
"%0 is declared with size %1x%2, but only values 1 through 4 are supported">;
77087706
def err_hlsl_norm_float_only : Error<
@@ -7853,6 +7851,14 @@ def err_hlsl_load_from_mesh_out_arrays: Error<
78537851
"output arrays of a mesh shader can not be read from">;
78547852
def err_hlsl_out_indices_array_incorrect_access: Error<
78557853
"a vector in out indices array must be accessed as a whole">;
7854+
def err_hlsl_unsupported_long_vector
7855+
: Error<"vectors of over 4 elements in "
7856+
"%select{ConstantBuffers or TextureBuffers|"
7857+
"tessellation patches|geometry streams|node records|"
7858+
"cbuffers or tbuffers|user-defined struct parameter|"
7859+
"entry function parameters|entry function return type|"
7860+
"patch constant function parameters|patch constant function return type|"
7861+
"payload parameters}0 are not supported">;
78567862
def err_hlsl_logical_binop_scalar : Error<
78577863
"operands for short-circuiting logical binary operator must be scalar, for non-scalar types use '%select{and|or}0'">;
78587864
def err_hlsl_ternary_scalar : Error<

tools/clang/include/clang/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
1616
#define LLVM_CLANG_BASIC_LANGOPTIONS_H
1717

18-
#include "dxc/DXIL/DxilConstants.h" // For DXIL::DefaultLinkage
18+
#include "dxc/DXIL/DxilConstants.h" // For DXIL:: default values.
1919
#include "dxc/Support/HLSLVersion.h"
2020
#include "clang/Basic/CommentOptions.h"
2121
#include "clang/Basic/LLVM.h"
@@ -168,6 +168,7 @@ class LangOptions : public LangOptionsBase {
168168
hlsl::DXIL::DefaultLinkage::Default;
169169
/// Whether use row major as default matrix major.
170170
bool HLSLDefaultRowMajor = false;
171+
unsigned MaxHLSLVectorLength = hlsl::DXIL::kDefaultMaxVectorLength;
171172
// HLSL Change Ends
172173

173174
bool SPIRV = false; // SPIRV Change

tools/clang/include/clang/Sema/SemaHLSL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ unsigned CaculateInitListArraySizeForHLSL(clang::Sema *sema,
128128
const clang::InitListExpr *InitList,
129129
const clang::QualType EltTy);
130130

131+
bool containsLongVector(clang::QualType qt);
132+
131133
bool IsConversionToLessOrEqualElements(clang::Sema *self,
132134
const clang::ExprResult &sourceExpr,
133135
const clang::QualType &targetType,

0 commit comments

Comments
 (0)