@@ -993,10 +993,11 @@ void ReplaceMinPrecisionRawBufferStoreByType(
993993 Args.emplace_back (NewV);
994994 }
995995 } else if (FromTy->isIntegerTy ()) {
996- // Since we are extending integer, we have to know if we should sign ext
997- // or zero ext. For StructuredBuffers we get signedness from the struct
998- // type annotation. For ByteAddressBuffer (raw buffers) there is no struct
999- // annotation, so we fall back to sext as a conservative default.
996+ // This case only applies to typed buffer since Store operation of byte
997+ // address buffer for min precision is handled by implicit conversion on
998+ // intrinsic call. Since we are extending integer, we have to know if we
999+ // should sign ext or zero ext. We can do this by iterating checking the
1000+ // size of the element at struct type and comp type at type annotation
10001001 CallInst *handleCI = dyn_cast<CallInst>(
10011002 CI->getArgOperand (DxilInst_RawBufferStore::arg_uav));
10021003 DXASSERT (handleCI,
@@ -1006,50 +1007,34 @@ void ReplaceMinPrecisionRawBufferStoreByType(
10061007 " otherwise fail to handle for buffer store lost its retTy" );
10071008 StructType *STy = dyn_cast<StructType>(resTyIt->second );
10081009
1009- StructType *InnerSTy =
1010- STy ? dyn_cast<StructType>(STy->getElementType (0 )) : nullptr ;
1011- DxilStructAnnotation *SAnnot =
1012- InnerSTy ? typeSys.GetStructAnnotation (InnerSTy) : nullptr ;
1013-
1014- if (SAnnot) {
1015- // StructuredBuffer path: use struct annotation to determine signedness.
1016- ConstantInt *offsetInt = dyn_cast<ConstantInt>(
1017- CI->getArgOperand (DxilInst_RawBufferStore::arg_elementOffset));
1018- unsigned offset = offsetInt->getSExtValue ();
1019- unsigned currentOffset = 0 ;
1020- for (DxilStructTypeIterator iter = begin (InnerSTy, SAnnot),
1021- ItEnd = end (InnerSTy, SAnnot);
1022- iter != ItEnd; ++iter) {
1023- std::pair<Type *, DxilFieldAnnotation *> pair = *iter;
1024- currentOffset += DL.getTypeAllocSize (pair.first );
1025- if (currentOffset > offset) {
1026- if (pair.second ->GetCompType ().IsUIntTy ()) {
1027- for (unsigned i = 4 ; i < 8 ; ++i) {
1028- Value *NewV = CIBuilder.CreateZExt (CI->getArgOperand (i), ToTy);
1029- Args.emplace_back (NewV);
1030- }
1031- break ;
1032- } else if (pair.second ->GetCompType ().IsIntTy ()) {
1033- for (unsigned i = 4 ; i < 8 ; ++i) {
1034- Value *NewV = CIBuilder.CreateSExt (CI->getArgOperand (i), ToTy);
1035- Args.emplace_back (NewV);
1036- }
1037- break ;
1038- } else {
1039- DXASSERT (false , " Invalid comp type" );
1010+ STy = cast<StructType>(STy->getElementType (0 ));
1011+ DxilStructAnnotation *SAnnot = typeSys.GetStructAnnotation (STy);
1012+ ConstantInt *offsetInt = dyn_cast<ConstantInt>(
1013+ CI->getArgOperand (DxilInst_RawBufferStore::arg_elementOffset));
1014+ unsigned offset = offsetInt->getSExtValue ();
1015+ unsigned currentOffset = 0 ;
1016+ for (DxilStructTypeIterator iter = begin (STy, SAnnot),
1017+ ItEnd = end (STy, SAnnot);
1018+ iter != ItEnd; ++iter) {
1019+ std::pair<Type *, DxilFieldAnnotation *> pair = *iter;
1020+ currentOffset += DL.getTypeAllocSize (pair.first );
1021+ if (currentOffset > offset) {
1022+ if (pair.second ->GetCompType ().IsUIntTy ()) {
1023+ for (unsigned i = 4 ; i < 8 ; ++i) {
1024+ Value *NewV = CIBuilder.CreateZExt (CI->getArgOperand (i), ToTy);
1025+ Args.emplace_back (NewV);
10401026 }
1027+ break ;
1028+ } else if (pair.second ->GetCompType ().IsIntTy ()) {
1029+ for (unsigned i = 4 ; i < 8 ; ++i) {
1030+ Value *NewV = CIBuilder.CreateSExt (CI->getArgOperand (i), ToTy);
1031+ Args.emplace_back (NewV);
1032+ }
1033+ break ;
1034+ } else {
1035+ DXASSERT (false , " Invalid comp type" );
10411036 }
10421037 }
1043- } else {
1044- // ByteAddressBuffer path: no struct annotation available, so
1045- // signedness is unknown. Default to sext.
1046- for (unsigned i = 4 ; i < 8 ; ++i) {
1047- Value *Arg = CI->getArgOperand (i);
1048- if (isa<UndefValue>(Arg))
1049- Args.emplace_back (UndefValue::get (ToTy));
1050- else
1051- Args.emplace_back (CIBuilder.CreateSExt (Arg, ToTy));
1052- }
10531038 }
10541039 }
10551040
0 commit comments