Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/dxc/DXIL/DxilMetadataHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class DxilMDHelper {
static const unsigned kDxilStructuredBufferElementStrideTag = 1;
static const unsigned kDxilSamplerFeedbackKindTag = 2;
static const unsigned kDxilAtomic64UseTag = 3;
static const unsigned kDxilReorderCoherentTag = 4;

// Type system.
static const char kDxilTypeSystemMDName[];
Expand Down
3 changes: 3 additions & 0 deletions include/dxc/DXIL/DxilResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class DxilResource : public DxilResourceBase {

bool IsGloballyCoherent() const;
void SetGloballyCoherent(bool b);
bool IsReorderCoherent() const;
void SetReorderCoherent(bool b);
bool HasCounter() const;
void SetHasCounter(bool b);

Expand Down Expand Up @@ -97,6 +99,7 @@ class DxilResource : public DxilResourceBase {
CompType m_CompType;
DXIL::SamplerFeedbackType m_SamplerFeedbackType;
bool m_bGloballyCoherent;
bool m_bReorderCoherent;
bool m_bHasCounter;
bool m_bROV;
bool m_bHasAtomic64Use;
Expand Down
3 changes: 2 additions & 1 deletion include/dxc/DXIL/DxilResourceProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ struct DxilResourceProperties {
uint8_t SamplerCmpOrHasCounter : 1;

// BYTE 2
uint8_t Reserved2;
uint8_t IsReorderCoherent : 1;
uint8_t Reserved2 : 7;

// BYTE 3
uint8_t Reserved3;
Expand Down
1 change: 1 addition & 0 deletions include/dxc/DxilContainer/RDAT_LibraryTypes.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ RDAT_ENUM_START(DxilResourceFlag, uint32_t)
RDAT_ENUM_VALUE(UAVRasterizerOrderedView, 1 << 2)
RDAT_ENUM_VALUE(DynamicIndexing, 1 << 3)
RDAT_ENUM_VALUE(Atomics64Use, 1 << 4)
RDAT_ENUM_VALUE(UAVReorderCoherent, 1 << 5)
RDAT_ENUM_END()

RDAT_ENUM_START(DxilShaderStageFlags, uint32_t)
Expand Down
10 changes: 10 additions & 0 deletions lib/DXIL/DxilMetadataHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,13 @@ void DxilExtraPropertyHelper::EmitUAVProperties(
DxilMDHelper::kDxilAtomic64UseTag, m_Ctx));
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD((unsigned)true, m_Ctx));
}
// Whether resource is reordercoherent.
if (DXIL::CompareVersions(m_ValMajor, m_ValMinor, 1, 9) >= 0 &&
UAV.IsReorderCoherent()) {
MDVals.emplace_back(DxilMDHelper::Uint32ToConstMD(
DxilMDHelper::kDxilReorderCoherentTag, m_Ctx));
MDVals.emplace_back(DxilMDHelper::BoolToConstMD(true, m_Ctx));
}
}

void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
Expand Down Expand Up @@ -3147,6 +3154,9 @@ void DxilExtraPropertyHelper::LoadUAVProperties(const MDOperand &MDO,
case DxilMDHelper::kDxilAtomic64UseTag:
UAV.SetHasAtomic64Use(DxilMDHelper::ConstMDToBool(MDO));
break;
case DxilMDHelper::kDxilReorderCoherentTag:
UAV.SetReorderCoherent(DxilMDHelper::ConstMDToBool(MDO));
break;
default:
DXASSERT(false, "Unknown resource record tag");
m_bExtraMetadata = true;
Expand Down
8 changes: 6 additions & 2 deletions lib/DXIL/DxilResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace hlsl {
DxilResource::DxilResource()
: DxilResourceBase(DxilResourceBase::Class::Invalid), m_SampleCount(0),
m_ElementStride(0), m_SamplerFeedbackType((DXIL::SamplerFeedbackType)0),
m_bGloballyCoherent(false), m_bHasCounter(false), m_bROV(false),
m_bHasAtomic64Use(false) {}
m_bGloballyCoherent(false), m_bReorderCoherent(false),
m_bHasCounter(false), m_bROV(false), m_bHasAtomic64Use(false) {}

CompType DxilResource::GetCompType() const { return m_CompType; }

Expand Down Expand Up @@ -74,6 +74,10 @@ bool DxilResource::IsGloballyCoherent() const { return m_bGloballyCoherent; }

void DxilResource::SetGloballyCoherent(bool b) { m_bGloballyCoherent = b; }

bool DxilResource::IsReorderCoherent() const { return m_bReorderCoherent; }

void DxilResource::SetReorderCoherent(bool b) { m_bReorderCoherent = b; }

bool DxilResource::HasCounter() const { return m_bHasCounter; }

void DxilResource::SetHasCounter(bool b) { m_bHasCounter = b; }
Expand Down
3 changes: 3 additions & 0 deletions lib/DXIL/DxilResourceProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ DxilResourceProperties loadPropsFromResourceBase(const DxilResourceBase *Res) {
RP.Basic.IsUAV = true;
RP.Basic.ResourceKind = (uint8_t)Res->GetKind();
RP.Basic.IsGloballyCoherent = UAV->IsGloballyCoherent();
RP.Basic.IsReorderCoherent = UAV->IsReorderCoherent();
RP.Basic.SamplerCmpOrHasCounter = UAV->HasCounter();
RP.Basic.IsROV = UAV->IsROV();
SetResProperties(*UAV);
Expand Down Expand Up @@ -234,6 +235,8 @@ DxilResourceProperties tryMergeProps(DxilResourceProperties curProps,
prevProps.Basic.IsGloballyCoherent) {
curProps.Basic.IsGloballyCoherent = prevProps.Basic.IsGloballyCoherent;
}
if (curProps.Basic.IsReorderCoherent != prevProps.Basic.IsReorderCoherent)
curProps.Basic.IsReorderCoherent = prevProps.Basic.IsReorderCoherent;
}

if (curProps.Basic.ResourceKind == (uint8_t)DXIL::ResourceKind::CBuffer) {
Expand Down
3 changes: 3 additions & 0 deletions lib/DxilContainer/DxilContainerAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,9 @@ class DxilRDATWriter : public DxilPartWriter {
if (pRes->IsGloballyCoherent())
info.Flags |=
static_cast<uint32_t>(RDAT::DxilResourceFlag::UAVGloballyCoherent);
if (pRes->IsReorderCoherent())
info.Flags |=
static_cast<uint32_t>(RDAT::DxilResourceFlag::UAVReorderCoherent);
if (pRes->IsROV())
info.Flags |= static_cast<uint32_t>(
RDAT::DxilResourceFlag::UAVRasterizerOrderedView);
Expand Down
1 change: 1 addition & 0 deletions lib/DxilPIXPasses/PixPassHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ hlsl::DxilResource *CreateGlobalUAVResource(hlsl::DxilModule &DM,
(unsigned int)-2); // This is the reserved-for-tools register space
pUAV->SetSampleCount(0); // This is what compiler generates for a raw UAV
pUAV->SetGloballyCoherent(false);
pUAV->SetReorderCoherent(false);
pUAV->SetHasCounter(false);
pUAV->SetCompType(
CompType::getInvalid()); // This is what compiler generates for a raw UAV
Expand Down
4 changes: 3 additions & 1 deletion lib/HLSL/DxilCondenseResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,8 @@ void DxilLowerCreateHandleForLib::ReplaceResourceUserWithHandle(
};

// Search all users for update counter
bool updateAnnotateHandle = res.IsGloballyCoherent();
bool updateAnnotateHandle =
res.IsGloballyCoherent() || res.IsReorderCoherent();
if (!res.HasCounter()) {
for (User *U : handle->users()) {
if (IsDxilOp(U, hlsl::OP::OpCode::BufferUpdateCounter)) {
Expand Down Expand Up @@ -2321,6 +2322,7 @@ void InitTBuffer(const DxilCBuffer *pSource, DxilResource *pDest) {
pDest->SetSampleCount(0);
pDest->SetElementStride(0);
pDest->SetGloballyCoherent(false);
pDest->SetReorderCoherent(false);
pDest->SetHasCounter(false);
pDest->SetRW(false);
pDest->SetROV(false);
Expand Down
1 change: 1 addition & 0 deletions lib/HLSL/DxilGenerationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void InitResource(const DxilResource *pSource, DxilResource *pDest) {
pDest->SetSampleCount(pSource->GetSampleCount());
pDest->SetElementStride(pSource->GetElementStride());
pDest->SetGloballyCoherent(pSource->IsGloballyCoherent());
pDest->SetReorderCoherent(pSource->IsReorderCoherent());
pDest->SetHasCounter(pSource->HasCounter());
pDest->SetRW(pSource->IsRW());
pDest->SetROV(pSource->IsROV());
Expand Down
1 change: 1 addition & 0 deletions lib/HLSL/DxilPatchShaderRecordBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ unsigned int DxilPatchShaderRecordBindings::AddHandle(

if (pHandle) {
pHandle->SetGloballyCoherent(false);
pHandle->SetReorderCoherent(false);
pHandle->SetHasCounter(false);
pHandle->SetCompType(CompType::getF32()); // TODO: Need to handle all types
}
Expand Down
1 change: 1 addition & 0 deletions lib/HLSL/HLModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ HLModule::AddResourceWithGlobalVariableAndProps(llvm::Constant *GV,
Res->SetRW(true);
Res->SetROV(RP.Basic.IsROV);
Res->SetGloballyCoherent(RP.Basic.IsGloballyCoherent);
Res->SetReorderCoherent(RP.Basic.IsReorderCoherent);
Res->SetHasCounter(RP.Basic.SamplerCmpOrHasCounter);
Res->SetKind(RK);
Res->SetGlobalSymbol(GV);
Expand Down
1 change: 1 addition & 0 deletions tools/clang/include/clang/AST/HlslTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ bool IsHLSLUnsigned(clang::QualType type);
bool IsHLSLMinPrecision(clang::QualType type);
bool HasHLSLUNormSNorm(clang::QualType type, bool *pIsSNorm = nullptr);
bool HasHLSLGloballyCoherent(clang::QualType type);
bool HasHLSLReorderCoherent(clang::QualType type);
bool IsHLSLInputPatchType(clang::QualType type);
bool IsHLSLOutputPatchType(clang::QualType type);
bool IsHLSLPointStreamType(clang::QualType type);
Expand Down
3 changes: 2 additions & 1 deletion tools/clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -3652,7 +3652,8 @@ class AttributedType : public Type, public llvm::FoldingSetNode {
attr_hlsl_row_major,
attr_hlsl_column_major,
attr_hlsl_globallycoherent,
// HLSL Change Ends
attr_hlsl_reordercoherent,
// HLSL Change Ends
};

private:
Expand Down
6 changes: 6 additions & 0 deletions tools/clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,12 @@ def HLSLGloballyCoherent : InheritableAttr {
let Documentation = [Undocumented];
}

def HLSLReorderCoherent : InheritableAttr {
let Spellings = [CXX11<"", "reordercoherent", 2015>];
let Subjects = SubjectList<[Var, Function]>;
let Documentation = [Undocumented];
}

def HLSLShader : InheritableAttr {
let Spellings = [CXX11<"", "shader", 2017>];
let Args = [StringArgument<"stage">]; // one of compute, pixel, vertex, hull, domain, geometry, node
Expand Down
20 changes: 15 additions & 5 deletions tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -7706,8 +7706,10 @@ def err_hlsl_varmodifierna : Error<
"%0 is not a valid modifier for a %1">;
def err_hlsl_varmodifierna_decltype : Error<
"%0 is not a valid modifier for a declaration of type %1">;
def note_hlsl_globallycoherent_applies_to : Note<
"'globallycoherent' can only be applied to UAV or RWDispatchNodeInputRecord objects">;
def note_hlsl_coherence_applies_to : Note<
"'%select{reordercoherent|globallycoherent}0' can only be applied to UAV%select{| or RWDispatchNodeInputRecord}0 objects">;
def warn_hlsl_gc_implies_rc_attribute : Warning<
"attribute 'reordercoherent' implied by 'globallycoherent' in %0. 'reordercoherent' ignored.">;
def err_hlsl_varmodifiersna : Error<
"%0 and %1 cannot be used together for a %2">;
def err_hlsl_vla : Error< // Patterened after err_opencl_vla
Expand Down Expand Up @@ -7756,9 +7758,17 @@ def warn_hlsl_semantic_attribute_position_misuse_hint: Warning<
def warn_hlsl_unary_negate_unsigned : Warning<
"unary negate of unsigned value is still unsigned">,
InGroup<Conversion>, DefaultWarn;
def warn_hlsl_impcast_glc_mismatch : Warning<
"implicit conversion from %0 to %1 %select{loses|adds}2 globallycoherent annotation">,
InGroup<Conversion>, DefaultWarn;
def warn_hlsl_impcast_coherence_mismatch : Warning<
"implicit conversion from %0 to %1 %select{"
"demotes globallycoherent to reordercoherent|"
"promotes reordercoherent to globallycoherent|"
"loses reordercoherent|"
"loses globallycoherent|"
"adds reordercoherent|"
"adds globallycoherent}2 annotation">,
InGroup<Conversion>;
def warn_hlsl_glc_implies_rdc : Warning<
"attribute 'globallycoherent' implies 'reordercoherent'">, InGroup<IgnoredAttributes>;
def warn_hlsl_narrowing : Warning<
"conversion from larger type %0 to smaller type %1, possible loss of data">,
InGroup<Conversion>, DefaultWarn;
Expand Down
1 change: 1 addition & 0 deletions tools/clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ KEYWORD(lineadj , KEYHLSL)
KEYWORD(triangle , KEYHLSL)
KEYWORD(triangleadj , KEYHLSL)
KEYWORD(globallycoherent , KEYHLSL)
KEYWORD(reordercoherent , KEYHLSL)
KEYWORD(interface , KEYHLSL)
KEYWORD(sampler_state , KEYHLSL)
KEYWORD(technique , KEYHLSL)
Expand Down
5 changes: 2 additions & 3 deletions tools/clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -3804,9 +3804,8 @@ class Sema {
bool CheckHLSLUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation Loc,
UnaryExprOrTypeTrait ExprKind);
void DiagnoseHLSLDeclAttr(const Decl *D, const Attr *A);
void DiagnoseGloballyCoherentMismatch(const Expr *SrcExpr,
QualType TargetType,
SourceLocation Loc);
void DiagnoseCoherenceMismatch(const Expr *SrcExpr, QualType TargetType,
SourceLocation Loc);
void CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
const FunctionProtoType *Proto);
void DiagnoseReachableHLSLCall(CallExpr *CE, const hlsl::ShaderModel *SM,
Expand Down
3 changes: 2 additions & 1 deletion tools/clang/include/clang/Sema/SemaHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ void Indent(unsigned int Indentation, llvm::raw_ostream &Out);
void GetHLSLAttributedTypes(clang::Sema *self, clang::QualType type,
const clang::AttributedType **ppMatrixOrientation,
const clang::AttributedType **ppNorm,
const clang::AttributedType **ppGLC);
const clang::AttributedType **ppGLC,
const clang::AttributedType **ppRDC);

bool IsMatrixType(clang::Sema *self, clang::QualType type);
bool IsVectorType(clang::Sema *self, clang::QualType type);
Expand Down
12 changes: 12 additions & 0 deletions tools/clang/lib/AST/HlslTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ bool HasHLSLGloballyCoherent(clang::QualType type) {
return false;
}

bool HasHLSLReorderCoherent(clang::QualType type) {
const AttributedType *AT = type->getAs<AttributedType>();
while (AT) {
AttributedType::Kind kind = AT->getAttrKind();
if (kind == AttributedType::attr_hlsl_reordercoherent)
return true;
AT = AT->getLocallyUnqualifiedSingleStepDesugaredType()
->getAs<AttributedType>();
}
return false;
}

/// Checks whether the pAttributes indicate a parameter is inout or out; if
/// inout, pIsIn will be set to true.
bool IsParamAttributedAsOut(clang::AttributeList *pAttributes, bool *pIsIn);
Expand Down
4 changes: 3 additions & 1 deletion tools/clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,7 @@ bool AttributedType::isHLSLTypeSpec() const {
case attr_hlsl_snorm:
case attr_hlsl_unorm:
case attr_hlsl_globallycoherent:
case attr_hlsl_reordercoherent:
return true;
}
llvm_unreachable("invalid attr kind");
Expand Down Expand Up @@ -2975,7 +2976,8 @@ bool AttributedType::isCallingConv() const {
case attr_hlsl_snorm:
case attr_hlsl_unorm:
case attr_hlsl_globallycoherent:
// HLSL Change Ends
case attr_hlsl_reordercoherent:
// HLSL Change Ends
return false;

case attr_pcs:
Expand Down
3 changes: 3 additions & 0 deletions tools/clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,9 @@ void TypePrinter::printAttributedBefore(const AttributedType *T,
case AttributedType::attr_hlsl_globallycoherent:
OS << "globallycoherent ";
break;
case AttributedType::attr_hlsl_reordercoherent:
OS << "reordercoherent ";
break;
default:
// Only HLSL attribute types are covered.
break;
Expand Down
Loading
Loading