|
@@ -6303,6 +6303,33 @@ Value *CGMSHLSLRuntime::EmitHLSLLiteralCast(CodeGenFunction &CGF, Value *Src,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// For case like ((float3xfloat3)mat4x4).m21 or ((float3xfloat3)mat4x4)[1], just
|
|
|
|
+// treat it like mat4x4.m21 or mat4x4[1].
|
|
|
|
+static Value *GetOriginMatrixOperandAndUpdateMatSize(Value *Ptr, unsigned &row,
|
|
|
|
+ unsigned &col) {
|
|
|
|
+ if (CallInst *Mat = dyn_cast<CallInst>(Ptr)) {
|
|
|
|
+ HLOpcodeGroup OpcodeGroup =
|
|
|
|
+ GetHLOpcodeGroupByName(Mat->getCalledFunction());
|
|
|
|
+ if (OpcodeGroup == HLOpcodeGroup::HLCast) {
|
|
|
|
+ HLCastOpcode castOpcode = static_cast<HLCastOpcode>(GetHLOpcode(Mat));
|
|
|
|
+ if (castOpcode == HLCastOpcode::DefaultCast) {
|
|
|
|
+ Ptr = Mat->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
|
|
|
|
+ // Remove the cast which is useless now.
|
|
|
|
+ Mat->eraseFromParent();
|
|
|
|
+ // Update row and col.
|
|
|
|
+ HLMatrixType matTy =
|
|
|
|
+ HLMatrixType::cast(Ptr->getType()->getPointerElementType());
|
|
|
|
+ row = matTy.getNumRows();
|
|
|
|
+ col = matTy.getNumColumns();
|
|
|
|
+ // Don't update RetTy and DxilGeneration pass will do the right thing.
|
|
|
|
+ return Ptr;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nullptr;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
Value *CGMSHLSLRuntime::EmitHLSLMatrixSubscript(CodeGenFunction &CGF,
|
|
Value *CGMSHLSLRuntime::EmitHLSLMatrixSubscript(CodeGenFunction &CGF,
|
|
llvm::Type *RetType,
|
|
llvm::Type *RetType,
|
|
llvm::Value *Ptr,
|
|
llvm::Value *Ptr,
|
|
@@ -6321,11 +6348,16 @@ Value *CGMSHLSLRuntime::EmitHLSLMatrixSubscript(CodeGenFunction &CGF,
|
|
llvm::PointerType::get(RetType->getPointerElementType(),
|
|
llvm::PointerType::get(RetType->getPointerElementType(),
|
|
matBase->getType()->getPointerAddressSpace());
|
|
matBase->getType()->getPointerAddressSpace());
|
|
|
|
|
|
|
|
+ unsigned row, col;
|
|
|
|
+ hlsl::GetHLSLMatRowColCount(Ty, row, col);
|
|
|
|
+ if (Value *OriginPtr = GetOriginMatrixOperandAndUpdateMatSize(Ptr, row, col)) {
|
|
|
|
+ Ptr = OriginPtr;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Lower mat[Idx] into real idx.
|
|
// Lower mat[Idx] into real idx.
|
|
SmallVector<Value *, 8> args;
|
|
SmallVector<Value *, 8> args;
|
|
args.emplace_back(Ptr);
|
|
args.emplace_back(Ptr);
|
|
- unsigned row, col;
|
|
|
|
- hlsl::GetHLSLMatRowColCount(Ty, row, col);
|
|
|
|
|
|
+
|
|
if (isRowMajor) {
|
|
if (isRowMajor) {
|
|
Value *cCol = ConstantInt::get(Idx->getType(), col);
|
|
Value *cCol = ConstantInt::get(Idx->getType(), col);
|
|
Value *Base = CGF.Builder.CreateMul(cCol, Idx);
|
|
Value *Base = CGF.Builder.CreateMul(cCol, Idx);
|
|
@@ -6375,6 +6407,14 @@ Value *CGMSHLSLRuntime::EmitHLSLMatrixElement(CodeGenFunction &CGF,
|
|
// -1 to avoid opcode param which is added in EmitHLSLMatrixOperationCallImp.
|
|
// -1 to avoid opcode param which is added in EmitHLSLMatrixOperationCallImp.
|
|
Value *args[] = {paramList[HLOperandIndex::kMatSubscriptMatOpIdx - 1],
|
|
Value *args[] = {paramList[HLOperandIndex::kMatSubscriptMatOpIdx - 1],
|
|
paramList[HLOperandIndex::kMatSubscriptSubOpIdx - 1]};
|
|
paramList[HLOperandIndex::kMatSubscriptSubOpIdx - 1]};
|
|
|
|
+
|
|
|
|
+ unsigned row, col;
|
|
|
|
+ hlsl::GetHLSLMatRowColCount(Ty, row, col);
|
|
|
|
+ Value *Ptr = paramList[0];
|
|
|
|
+ if (Value *OriginPtr = GetOriginMatrixOperandAndUpdateMatSize(Ptr, row, col)) {
|
|
|
|
+ args[0] = OriginPtr;
|
|
|
|
+ }
|
|
|
|
+
|
|
// For all zero idx. Still all zero idx.
|
|
// For all zero idx. Still all zero idx.
|
|
if (ConstantAggregateZero *zeros = dyn_cast<ConstantAggregateZero>(idx)) {
|
|
if (ConstantAggregateZero *zeros = dyn_cast<ConstantAggregateZero>(idx)) {
|
|
Constant *zero = zeros->getAggregateElement((unsigned)0);
|
|
Constant *zero = zeros->getAggregateElement((unsigned)0);
|
|
@@ -6383,8 +6423,6 @@ Value *CGMSHLSLRuntime::EmitHLSLMatrixElement(CodeGenFunction &CGF,
|
|
} else {
|
|
} else {
|
|
ConstantDataSequential *elts = cast<ConstantDataSequential>(idx);
|
|
ConstantDataSequential *elts = cast<ConstantDataSequential>(idx);
|
|
unsigned count = elts->getNumElements();
|
|
unsigned count = elts->getNumElements();
|
|
- unsigned row, col;
|
|
|
|
- hlsl::GetHLSLMatRowColCount(Ty, row, col);
|
|
|
|
std::vector<Constant *> idxs(count >> 1);
|
|
std::vector<Constant *> idxs(count >> 1);
|
|
for (unsigned i = 0; i < count; i += 2) {
|
|
for (unsigned i = 0; i < count; i += 2) {
|
|
unsigned rowIdx = elts->getElementAsInteger(i);
|
|
unsigned rowIdx = elts->getElementAsInteger(i);
|