|
@@ -3573,14 +3573,15 @@ static Constant *GetRawBufferMaskForETy(Type *Ty, unsigned NumComponents, hlsl::
|
|
return OP->GetI8Const(mask);
|
|
return OP->GetI8Const(mask);
|
|
}
|
|
}
|
|
|
|
|
|
-Value *GenerateStructBufLd(Value *handle, Value *bufIdx, Value *offset,
|
|
|
|
|
|
+Value *GenerateRawBufLd(Value *handle, Value *bufIdx, Value *offset,
|
|
Value *status, Type *EltTy,
|
|
Value *status, Type *EltTy,
|
|
MutableArrayRef<Value *> resultElts, hlsl::OP *OP,
|
|
MutableArrayRef<Value *> resultElts, hlsl::OP *OP,
|
|
IRBuilder<> &Builder, unsigned NumComponents, Constant *alignment);
|
|
IRBuilder<> &Builder, unsigned NumComponents, Constant *alignment);
|
|
|
|
|
|
-static Value* TranslateStructBufVecLd(Type* VecEltTy, unsigned VecElemCount,
|
|
|
|
|
|
+static Value* TranslateRawBufVecLd(Type* VecEltTy, unsigned VecElemCount,
|
|
IRBuilder<>& Builder, Value* handle, hlsl::OP* OP, Value* status,
|
|
IRBuilder<>& Builder, Value* handle, hlsl::OP* OP, Value* status,
|
|
- Value* bufIdx, Value* baseOffset, const DataLayout& DL, std::vector<Value*>& bufLds, bool isScalarTy = false);
|
|
|
|
|
|
+ Value* bufIdx, Value* baseOffset, const DataLayout& DL,
|
|
|
|
+ std::vector<Value*>& bufLds, unsigned baseAlign, bool isScalarTy = false);
|
|
|
|
|
|
void TranslateLoad(ResLoadHelper &helper, HLResource::Kind RK,
|
|
void TranslateLoad(ResLoadHelper &helper, HLResource::Kind RK,
|
|
IRBuilder<> &Builder, hlsl::OP *OP, const DataLayout &DL) {
|
|
IRBuilder<> &Builder, hlsl::OP *OP, const DataLayout &DL) {
|
|
@@ -3599,26 +3600,28 @@ void TranslateLoad(ResLoadHelper &helper, HLResource::Kind RK,
|
|
Type *i64Ty = Builder.getInt64Ty();
|
|
Type *i64Ty = Builder.getInt64Ty();
|
|
Type *doubleTy = Builder.getDoubleTy();
|
|
Type *doubleTy = Builder.getDoubleTy();
|
|
Type *EltTy = Ty->getScalarType();
|
|
Type *EltTy = Ty->getScalarType();
|
|
- // If RawBuffer load of 64-bit value, don't set alignment to 8,
|
|
|
|
- // since buffer alignment isn't known to be anything over 4.
|
|
|
|
- unsigned alignValue = OP->GetAllocSizeForType(EltTy);
|
|
|
|
- if (RK == HLResource::Kind::RawBuffer && alignValue > 4)
|
|
|
|
- alignValue = 4;
|
|
|
|
- Constant *Alignment = OP->GetI32Const(alignValue);
|
|
|
|
unsigned numComponents = 1;
|
|
unsigned numComponents = 1;
|
|
if (Ty->isVectorTy()) {
|
|
if (Ty->isVectorTy()) {
|
|
numComponents = Ty->getVectorNumElements();
|
|
numComponents = Ty->getVectorNumElements();
|
|
}
|
|
}
|
|
|
|
|
|
- if (DXIL::IsStructuredBuffer(RK)) {
|
|
|
|
|
|
+ if (DXIL::IsStructuredBuffer(RK) || DXIL::IsRawBuffer(RK)) {
|
|
std::vector<Value*> bufLds;
|
|
std::vector<Value*> bufLds;
|
|
const bool isBool = EltTy->isIntegerTy(1);
|
|
const bool isBool = EltTy->isIntegerTy(1);
|
|
|
|
|
|
// Bool are represented as i32 in memory
|
|
// Bool are represented as i32 in memory
|
|
Type* MemReprTy = isBool ? Builder.getInt32Ty() : EltTy;
|
|
Type* MemReprTy = isBool ? Builder.getInt32Ty() : EltTy;
|
|
bool isScalarTy = !Ty->isVectorTy();
|
|
bool isScalarTy = !Ty->isVectorTy();
|
|
- Value* retValNew = TranslateStructBufVecLd(MemReprTy, numComponents, Builder, helper.handle, OP, helper.status,
|
|
|
|
- helper.addr, OP->GetU32Const(0), DL, bufLds, isScalarTy);
|
|
|
|
|
|
+
|
|
|
|
+ Value* retValNew = nullptr;
|
|
|
|
+ if (DXIL::IsStructuredBuffer(RK)) {
|
|
|
|
+ retValNew = TranslateRawBufVecLd(MemReprTy, numComponents, Builder, helper.handle, OP, helper.status,
|
|
|
|
+ helper.addr, OP->GetU32Const(0), DL, bufLds, /*baseAlign (in bytes)*/ 8, isScalarTy);
|
|
|
|
+ } else {
|
|
|
|
+ retValNew = TranslateRawBufVecLd(MemReprTy, numComponents, Builder, helper.handle, OP, helper.status,
|
|
|
|
+ nullptr, helper.addr, DL, bufLds, /*baseAlign (in bytes)*/ 4, isScalarTy);
|
|
|
|
+ }
|
|
|
|
+
|
|
DXASSERT_NOMSG(!bufLds.empty());
|
|
DXASSERT_NOMSG(!bufLds.empty());
|
|
dxilutil::MigrateDebugValue(helper.retVal, bufLds.front());
|
|
dxilutil::MigrateDebugValue(helper.retVal, bufLds.front());
|
|
|
|
|
|
@@ -3703,14 +3706,7 @@ void TranslateLoad(ResLoadHelper &helper, HLResource::Kind RK,
|
|
}
|
|
}
|
|
|
|
|
|
// Offset 1
|
|
// Offset 1
|
|
- if (RK == DxilResource::Kind::RawBuffer) {
|
|
|
|
- // elementOffset, mask, alignment
|
|
|
|
- loadArgs.emplace_back(undefI);
|
|
|
|
- Type *rtnTy = helper.retVal->getType();
|
|
|
|
- loadArgs.emplace_back(GetRawBufferMaskForETy(rtnTy, numComponents, OP));
|
|
|
|
- loadArgs.emplace_back(Alignment);
|
|
|
|
- }
|
|
|
|
- else if (RK == DxilResource::Kind::TypedBuffer) {
|
|
|
|
|
|
+ if (RK == DxilResource::Kind::TypedBuffer) {
|
|
loadArgs.emplace_back(undefI);
|
|
loadArgs.emplace_back(undefI);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -6815,7 +6811,7 @@ static Value* ExtractFromTypedBufferLoad(const ResRetValueArray& ResRet,
|
|
return ScalarizeElements(ResultTy, Elems, Builder);
|
|
return ScalarizeElements(ResultTy, Elems, Builder);
|
|
}
|
|
}
|
|
|
|
|
|
-Value *GenerateStructBufLd(Value *handle, Value *bufIdx, Value *offset,
|
|
|
|
|
|
+Value *GenerateRawBufLd(Value *handle, Value *bufIdx, Value *offset,
|
|
Value *status, Type *EltTy,
|
|
Value *status, Type *EltTy,
|
|
MutableArrayRef<Value *> resultElts, hlsl::OP *OP,
|
|
MutableArrayRef<Value *> resultElts, hlsl::OP *OP,
|
|
IRBuilder<> &Builder, unsigned NumComponents, Constant *alignment) {
|
|
IRBuilder<> &Builder, unsigned NumComponents, Constant *alignment) {
|
|
@@ -6871,34 +6867,36 @@ void GenerateStructBufSt(Value *handle, Value *bufIdx, Value *offset,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-static Value* TranslateStructBufVecLd(Type* VecEltTy, unsigned ElemCount,
|
|
|
|
|
|
+static Value* TranslateRawBufVecLd(Type* VecEltTy, unsigned ElemCount,
|
|
IRBuilder<>& Builder, Value* handle, hlsl::OP* OP, Value* status,
|
|
IRBuilder<>& Builder, Value* handle, hlsl::OP* OP, Value* status,
|
|
- Value* bufIdx, Value* baseOffset, const DataLayout& DL, std::vector<Value*> &bufLds, bool isScalarTy) {
|
|
|
|
|
|
+ Value* bufIdx, Value* baseOffset, const DataLayout& DL,
|
|
|
|
+ std::vector<Value*> &bufLds, unsigned baseAlign, bool isScalarTy) {
|
|
|
|
+
|
|
unsigned EltSize = DL.getTypeAllocSize(VecEltTy);
|
|
unsigned EltSize = DL.getTypeAllocSize(VecEltTy);
|
|
- Constant* alignment = OP->GetI32Const(EltSize);
|
|
|
|
|
|
+ unsigned alignment = std::min(baseAlign, EltSize);
|
|
|
|
+ Constant* alignmentVal = OP->GetI32Const(alignment);
|
|
|
|
|
|
- Value* offset = baseOffset;
|
|
|
|
- if (baseOffset == nullptr)
|
|
|
|
- offset = OP->GetU32Const(0);
|
|
|
|
|
|
+ if (baseOffset == nullptr) {
|
|
|
|
+ baseOffset = OP->GetU32Const(0);
|
|
|
|
+ }
|
|
|
|
|
|
std::vector<Value*> elts(ElemCount);
|
|
std::vector<Value*> elts(ElemCount);
|
|
unsigned rest = (ElemCount % 4);
|
|
unsigned rest = (ElemCount % 4);
|
|
- for (unsigned i = 0; i < ElemCount-rest; i += 4) {
|
|
|
|
|
|
+ for (unsigned i = 0; i < ElemCount - rest; i += 4) {
|
|
Value* ResultElts[4];
|
|
Value* ResultElts[4];
|
|
- Value* bufLd = GenerateStructBufLd(handle, bufIdx, offset, status, VecEltTy, ResultElts, OP, Builder, 4, alignment);
|
|
|
|
|
|
+ Value* bufLd = GenerateRawBufLd(handle, bufIdx, baseOffset, status, VecEltTy, ResultElts, OP, Builder, 4, alignmentVal);
|
|
bufLds.emplace_back(bufLd);
|
|
bufLds.emplace_back(bufLd);
|
|
elts[i] = ResultElts[0];
|
|
elts[i] = ResultElts[0];
|
|
elts[i + 1] = ResultElts[1];
|
|
elts[i + 1] = ResultElts[1];
|
|
elts[i + 2] = ResultElts[2];
|
|
elts[i + 2] = ResultElts[2];
|
|
elts[i + 3] = ResultElts[3];
|
|
elts[i + 3] = ResultElts[3];
|
|
|
|
|
|
- // Update offset by 4*4bytes.
|
|
|
|
- offset = Builder.CreateAdd(offset, OP->GetU32Const(4 * EltSize));
|
|
|
|
|
|
+ baseOffset = Builder.CreateAdd(baseOffset, OP->GetU32Const(4 * EltSize));
|
|
}
|
|
}
|
|
|
|
|
|
if (rest) {
|
|
if (rest) {
|
|
Value* ResultElts[4];
|
|
Value* ResultElts[4];
|
|
- Value* bufLd = GenerateStructBufLd(handle, bufIdx, offset, status, VecEltTy, ResultElts, OP, Builder, rest, alignment);
|
|
|
|
|
|
+ Value* bufLd = GenerateRawBufLd(handle, bufIdx, baseOffset, status, VecEltTy, ResultElts, OP, Builder, rest, alignmentVal);
|
|
bufLds.emplace_back(bufLd);
|
|
bufLds.emplace_back(bufLd);
|
|
for (unsigned i = 0; i < rest; i++)
|
|
for (unsigned i = 0; i < rest; i++)
|
|
elts[ElemCount - rest + i] = ResultElts[i];
|
|
elts[ElemCount - rest + i] = ResultElts[i];
|
|
@@ -6921,7 +6919,8 @@ Value *TranslateStructBufMatLd(Type *matType, IRBuilder<> &Builder,
|
|
Type *EltTy = MatTy.getElementTypeForMem();
|
|
Type *EltTy = MatTy.getElementTypeForMem();
|
|
unsigned matSize = MatTy.getNumElements();
|
|
unsigned matSize = MatTy.getNumElements();
|
|
std::vector<Value*> bufLds;
|
|
std::vector<Value*> bufLds;
|
|
- Value* Vec = TranslateStructBufVecLd(EltTy, matSize, Builder, handle, OP, status, bufIdx, baseOffset, DL, bufLds);
|
|
|
|
|
|
+ Value* Vec = TranslateRawBufVecLd(EltTy, matSize, Builder, handle, OP, status, bufIdx,
|
|
|
|
+ baseOffset, DL, bufLds, /*baseAlign (in bytes)*/ 8);
|
|
Vec = MatTy.emitLoweredMemToReg(Vec, Builder);
|
|
Vec = MatTy.emitLoweredMemToReg(Vec, Builder);
|
|
return Vec;
|
|
return Vec;
|
|
}
|
|
}
|
|
@@ -7136,13 +7135,13 @@ void TranslateStructBufMatSubscript(CallInst *CI,
|
|
for (unsigned i = 0; i < resultSize; i++) {
|
|
for (unsigned i = 0; i < resultSize; i++) {
|
|
Value *ResultElt;
|
|
Value *ResultElt;
|
|
// TODO: This can be inefficient for row major matrix load
|
|
// TODO: This can be inefficient for row major matrix load
|
|
- GenerateStructBufLd(handle, bufIdx, idxList[i],
|
|
|
|
|
|
+ GenerateRawBufLd(handle, bufIdx, idxList[i],
|
|
/*status*/ nullptr, EltTy, ResultElt, hlslOP,
|
|
/*status*/ nullptr, EltTy, ResultElt, hlslOP,
|
|
ldBuilder, 1, alignment);
|
|
ldBuilder, 1, alignment);
|
|
ldData = ldBuilder.CreateInsertElement(ldData, ResultElt, i);
|
|
ldData = ldBuilder.CreateInsertElement(ldData, ResultElt, i);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- GenerateStructBufLd(handle, bufIdx, idxList[0], /*status*/ nullptr,
|
|
|
|
|
|
+ GenerateRawBufLd(handle, bufIdx, idxList[0], /*status*/ nullptr,
|
|
EltTy, ldData, hlslOP, ldBuilder, 4, alignment);
|
|
EltTy, ldData, hlslOP, ldBuilder, 4, alignment);
|
|
}
|
|
}
|
|
ldUser->replaceAllUsesWith(ldData);
|
|
ldUser->replaceAllUsesWith(ldData);
|
|
@@ -7300,7 +7299,7 @@ void TranslateStructBufSubscriptUser(
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
Value* ResultElts[4];
|
|
Value* ResultElts[4];
|
|
- GenerateStructBufLd(handle, bufIdx, offset, status, pOverloadTy,
|
|
|
|
|
|
+ GenerateRawBufLd(handle, bufIdx, offset, status, pOverloadTy,
|
|
ResultElts, OP, Builder, numComponents, alignment);
|
|
ResultElts, OP, Builder, numComponents, alignment);
|
|
return ScalarizeElements(Ty, ResultElts, Builder);
|
|
return ScalarizeElements(Ty, ResultElts, Builder);
|
|
}
|
|
}
|