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/DxilConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,7 @@ extern const char *kDxBreakFuncName;
extern const char *kDxBreakCondName;
extern const char *kDxBreakMDName;
extern const char *kDxIsHelperGlobalName;
extern const char *kDxLinAlgMatrixTypePrefix;

extern const char *kHostLayoutTypePrefix;

Expand Down
2 changes: 2 additions & 0 deletions include/dxc/DXIL/DxilUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ bool IsHLSLObjectType(llvm::Type *Ty);
bool IsHLSLRayQueryType(llvm::Type *Ty);
llvm::Type *GetHLSLHitObjectType(llvm::Module *M);
bool IsHLSLHitObjectType(llvm::Type *Ty);
bool IsHLSLLinAlgMatrixType(llvm::Type *Ty);
llvm::StringRef GetHLSLLinAlgMatrixTypeMangling(llvm::StructType *Ty);
bool IsHLSLResourceDescType(llvm::Type *Ty);
bool IsResourceSingleComponent(llvm::Type *Ty);
uint8_t GetResourceComponentCount(llvm::Type *Ty);
Expand Down
1 change: 1 addition & 0 deletions lib/DXIL/DxilModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const char *kDxBreakFuncName = "dx.break";
const char *kDxBreakCondName = "dx.break.cond";
const char *kDxBreakMDName = "dx.break.br";
const char *kDxIsHelperGlobalName = "dx.ishelper";
const char *kDxLinAlgMatrixTypePrefix = "dx.types.LinAlgMatrix";

const char *kHostLayoutTypePrefix = "hostlayout.";

Expand Down
4 changes: 4 additions & 0 deletions lib/DXIL/DxilOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilInstructions.h"
#include "dxc/DXIL/DxilModule.h"
#include "dxc/DXIL/DxilUtil.h"
#include "dxc/Support/Global.h"

#include "llvm/ADT/ArrayRef.h"
Expand Down Expand Up @@ -3173,6 +3174,9 @@ StringRef OP::GetTypeName(Type *Ty, SmallVectorImpl<char> &Storage) {
return ST->getStructName();
} else if (TypeSlot == TS_Object) {
StructType *ST = cast<StructType>(Ty);
if (dxilutil::IsHLSLLinAlgMatrixType(Ty))
return (Twine("m") + Twine(dxilutil::GetHLSLLinAlgMatrixTypeMangling(ST)))
.toStringRef(Storage);
return ST->getStructName();
} else if (TypeSlot == TS_Vector) {
VectorType *VecTy = cast<VectorType>(Ty);
Expand Down
19 changes: 19 additions & 0 deletions lib/DXIL/DxilUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
///////////////////////////////////////////////////////////////////////////////

#include "dxc/DXIL/DxilUtil.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilInstructions.h"
#include "dxc/DXIL/DxilModule.h"
#include "dxc/DXIL/DxilOperations.h"
Expand All @@ -18,9 +19,11 @@
#include "dxc/Support/Global.h"

#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
Expand Down Expand Up @@ -577,6 +580,9 @@ bool IsHLSLObjectType(llvm::Type *Ty) {

if (IsHLSLHitObjectType(Ty))
return true;

if (IsHLSLLinAlgMatrixType(Ty))
return true;
}
return false;
}
Expand Down Expand Up @@ -612,6 +618,19 @@ bool IsHLSLHitObjectType(llvm::Type *Ty) {
return ST->getName() == "dx.types.HitObject";
}

bool IsHLSLLinAlgMatrixType(llvm::Type *Ty) {
llvm::StructType *ST = dyn_cast<llvm::StructType>(Ty);
if (!ST)
return false;
if (!ST->hasName())
return false;
return ST->getName().startswith(DXIL::kDxLinAlgMatrixTypePrefix);
}

StringRef GetHLSLLinAlgMatrixTypeMangling(llvm::StructType *Ty) {
return Ty->getStructName().substr(strlen(DXIL::kDxLinAlgMatrixTypePrefix));
}

bool IsHLSLResourceDescType(llvm::Type *Ty) {
if (llvm::StructType *ST = dyn_cast<llvm::StructType>(Ty)) {
if (!ST->hasName())
Expand Down
181 changes: 156 additions & 25 deletions lib/HLSL/HLOperationLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6908,6 +6908,131 @@ Value *TranslateVectorAccumulate(CallInst *CI, IntrinsicOp IOP,
{OpArg, InputVector, MatrixBuffer, MatrixOffset});
}

Value *TranslateLinAlgFillMatrix(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
hlsl::OP *HlslOp = &Helper.hlslOP;
IRBuilder<> Builder(CI);

Value *MatrixPtr = CI->getArgOperand(1);
DXASSERT_NOMSG(isa<PointerType>(MatrixPtr->getType()));
Type *MatrixType = MatrixPtr->getType()->getPointerElementType();
Value *Scalar = CI->getArgOperand(2);

Constant *OpArg = HlslOp->GetU32Const((unsigned)OpCode);
Function *DxilFunc =
HlslOp->GetOpFunc(OpCode, {MatrixType, Scalar->getType()});

Value *Matrix = Builder.CreateCall(DxilFunc, {OpArg, Scalar});
Builder.CreateStore(Matrix, MatrixPtr);

return nullptr;
}

Value *TranslateLinAlgMatrixAccumStoreToDescriptor(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatVecMul(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatVecMulAdd(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixLoadFromDescriptor(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixOuterProduct(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixAccumulate(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixGetCoordinate(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixGetElement(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixSetElement(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixMatrixMultiply(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgMatrixMatrixMultiplyAccumulate(
CallInst *CI, IntrinsicOp IOP, OP::OpCode OpCode,
HLOperationLowerHelper &Helper, HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

Value *TranslateLinAlgCopyConvertMatrix(CallInst *CI, IntrinsicOp IOP,
OP::OpCode OpCode,
HLOperationLowerHelper &Helper,
HLObjectOperationLowerHelper *ObjHelper,
bool &Translated) {
DXASSERT(false, "Not implemented.");
return nullptr;
}

} // namespace

// Lower table.
Expand Down Expand Up @@ -7657,44 +7782,50 @@ constexpr IntrinsicLower gLowerTable[] = {
TranslateHitObjectTriangleObjectPositions,
DXIL::OpCode::HitObject_TriangleObjectPosition},

{IntrinsicOp::IOP___builtin_LinAlg_CopyConvertMatrix, EmptyLower,
DXIL::OpCode::LinAlgCopyConvertMatrix},
{IntrinsicOp::IOP___builtin_LinAlg_FillMatrix, EmptyLower,
{IntrinsicOp::IOP___builtin_LinAlg_CopyConvertMatrix,
TranslateLinAlgCopyConvertMatrix, DXIL::OpCode::LinAlgCopyConvertMatrix},
{IntrinsicOp::IOP___builtin_LinAlg_FillMatrix, TranslateLinAlgFillMatrix,
DXIL::OpCode::LinAlgFillMatrix},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixGetCoordinate, EmptyLower,
{IntrinsicOp::IOP___builtin_LinAlg_MatrixGetCoordinate,
TranslateLinAlgMatrixGetCoordinate,
DXIL::OpCode::LinAlgMatrixGetCoordinate},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixGetElement, EmptyLower,
DXIL::OpCode::LinAlgMatrixGetElement},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixLength, EmptyLower,
{IntrinsicOp::IOP___builtin_LinAlg_MatrixGetElement,
TranslateLinAlgMatrixGetElement, DXIL::OpCode::LinAlgMatrixGetElement},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixLength, TrivialUnaryOperation,
DXIL::OpCode::LinAlgMatrixLength},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixLoadFromDescriptor, EmptyLower,
{IntrinsicOp::IOP___builtin_LinAlg_MatrixLoadFromDescriptor,
TranslateLinAlgMatrixLoadFromDescriptor,
DXIL::OpCode::LinAlgMatrixLoadFromDescriptor},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixLoadFromMemory, EmptyLower,
DXIL::OpCode::LinAlgMatrixLoadFromMemory},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixSetElement, EmptyLower,
DXIL::OpCode::LinAlgMatrixSetElement},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixStoreToDescriptor, EmptyLower,
{IntrinsicOp::IOP___builtin_LinAlg_MatrixSetElement,
TranslateLinAlgMatrixSetElement, DXIL::OpCode::LinAlgMatrixSetElement},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixStoreToDescriptor,
TranslateLinAlgMatrixAccumStoreToDescriptor,
DXIL::OpCode::LinAlgMatrixStoreToDescriptor},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixStoreToMemory, EmptyLower,
DXIL::OpCode::LinAlgMatrixStoreToMemory},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulate, EmptyLower,
DXIL::OpCode::LinAlgMatrixAccumulate},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixMatrixMultiply, EmptyLower,
DXIL::OpCode::LinAlgMatrixMultiply},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulate,
TranslateLinAlgMatrixAccumulate, DXIL::OpCode::LinAlgMatrixAccumulate},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixMatrixMultiply,
TranslateLinAlgMatrixMatrixMultiply, DXIL::OpCode::LinAlgMatrixMultiply},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixMatrixMultiplyAccumulate,
EmptyLower, DXIL::OpCode::LinAlgMatrixMultiplyAccumulate},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixQueryAccumulatorLayout, EmptyLower,
DXIL::OpCode::LinAlgMatrixQueryAccumulatorLayout},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulateToDescriptor, EmptyLower,
TranslateLinAlgMatrixMatrixMultiplyAccumulate,
DXIL::OpCode::LinAlgMatrixMultiplyAccumulate},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixQueryAccumulatorLayout,
TrivialNoArgOperation, DXIL::OpCode::LinAlgMatrixQueryAccumulatorLayout},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulateToDescriptor,
TranslateLinAlgMatrixAccumStoreToDescriptor,
DXIL::OpCode::LinAlgMatrixAccumulateToDescriptor},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixAccumulateToMemory, EmptyLower,
DXIL::OpCode::LinAlgMatrixAccumulateToMemory},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixOuterProduct, EmptyLower,
DXIL::OpCode::LinAlgMatrixOuterProduct},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixVectorMultiply, EmptyLower,
DXIL::OpCode::LinAlgMatVecMul},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixVectorMultiplyAdd, EmptyLower,
DXIL::OpCode::LinAlgMatVecMulAdd},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixOuterProduct,
TranslateLinAlgMatrixOuterProduct, DXIL::OpCode::LinAlgMatrixOuterProduct},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixVectorMultiply,
TranslateLinAlgMatVecMul, DXIL::OpCode::LinAlgMatVecMul},
{IntrinsicOp::IOP___builtin_LinAlg_MatrixVectorMultiplyAdd,
TranslateLinAlgMatVecMulAdd, DXIL::OpCode::LinAlgMatVecMulAdd},

{IntrinsicOp::IOP_DebugBreak, TrivialNoArgOperation,
DXIL::OpCode::DebugBreak},
{IntrinsicOp::IOP_DxIsDebuggerPresent, TranslateWaveToVal,
Expand Down
3 changes: 2 additions & 1 deletion tools/clang/lib/CodeGen/CGHLSLMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "CodeGenModule.h"
#include "dxc/DXIL/DxilConstants.h"
#include "dxc/DXIL/DxilOperations.h"
#include "dxc/DXIL/DxilTypeSystem.h"
#include "dxc/DXIL/DxilUtil.h"
Expand Down Expand Up @@ -6621,7 +6622,7 @@ llvm::Type *CGMSHLSLRuntime::ConvertAttributedLinAlgMatrixType(

llvm::SmallString<64> Buf;
llvm::raw_svector_ostream OS(Buf);
OS << "dx.types.LinAlgMatrix";
OS << DXIL::kDxLinAlgMatrixTypePrefix;
T->appendMangledAttributes(OS);
StringRef TypeName = OS.str();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// REQUIRES: dxil-1-10
// RUN: %dxc -T cs_6_10 -E main %s | FileCheck %s

[numthreads(1,1,1)]
void main() {
// CHECK-LABEL: define void @main()

// CHECK: %{{.*}} = call %dx.types.LinAlgMatrixC4M5N4U1S2 @dx.op.linAlgFillMatrix.mC4M5N4U1S2.i32(i32 -2147483636, i32 {{.*}}) ; LinAlgFillMatrix(value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does -2147483636 mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh that's the opcode! 0x80000001 in hex. Its negative because the opcodes are currently experimental

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually 8000000C!
See DxilConstants.h:

// LinAlgFillMatrix = 0x8000000C, 2147483660U, -2147483636

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right! haha nice catch :)

__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(4, 5, 4, 1, 2)]] mat1;
__builtin_LinAlg_FillMatrix(mat1, 5);
// CHECK: %{{.*}} = call %dx.types.LinAlgMatrixC5M3N4U0S0 @dx.op.linAlgFillMatrix.mC5M3N4U0S0.f32(i32 -2147483636, float {{.*}}) ; LinAlgFillMatrix(value)
__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(5, 3, 4, 0, 0)]] mat2;
__builtin_LinAlg_FillMatrix(mat2, 3.14);
}
15 changes: 15 additions & 0 deletions tools/clang/test/SemaHLSL/hlsl/linalg/builtins/fillmatrix/ast.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES: dxil-1-10
// RUN: %dxc -T lib_6_10 -E main %s -ast-dump-implicit | FileCheck %s

// CHECK: FunctionDecl {{.*}} implicit used __builtin_LinAlg_FillMatrix 'void (__builtin_LinAlgMatrix & {{.*}}, unsigned int)' extern
// CHECK-NEXT: ParmVarDecl {{.*}} ret '__builtin_LinAlgMatrix &&__restrict {{.*}}'
// CHECK-NEXT: ParmVarDecl {{.*}} value 'unsigned int'
// CHECK-NEXT: HLSLIntrinsicAttr {{.*}} Implicit "op" "" 406
// CHECK-NEXT: AvailabilityAttr {{.*}} Implicit 6.10 0 0 ""

[shader("compute")]
[numthreads(1,1,1)]
void main() {
__builtin_LinAlgMatrix [[__LinAlgMatrix_Attributes(1, 5, 4, 2, 2)]] mat;
__builtin_LinAlg_FillMatrix(mat, 15);
}
Loading