|
25 | 25 | #include "llvm/Transforms/Utils/Local.h" |
26 | 26 | #include <deque> |
27 | 27 |
|
| 28 | +#include "PixPassHelpers.h" |
| 29 | + |
28 | 30 | #ifdef _WIN32 |
29 | 31 | #include <winerror.h> |
30 | 32 | #endif |
@@ -620,104 +622,6 @@ DxilShaderAccessTracking::GetResourceFromHandle(Value *resHandle, |
620 | 622 | return ret; |
621 | 623 | } |
622 | 624 |
|
623 | | -static bool IsDynamicResourceShaderModel(DxilModule& DM) { |
624 | | - return DM.GetShaderModel()->IsSMAtLeast(6, 6); |
625 | | -} |
626 | | - |
627 | | -// Set up a UAV with structure of a single int |
628 | | -static llvm::CallInst* CreateUAV(DxilModule & DM, IRBuilder<> & Builder, unsigned int UAVResourceHandle, unsigned int bind, const char * name) |
629 | | -{ |
630 | | - LLVMContext& Ctx = DM.GetModule()->getContext(); |
631 | | - |
632 | | - SmallVector<llvm::Type*, 1> Elements{ Type::getInt32Ty(Ctx) }; |
633 | | - llvm::StructType* UAVStructTy = |
634 | | - llvm::StructType::create(Elements, "class.RWStructuredBuffer"); |
635 | | - std::unique_ptr<DxilResource> pUAV = |
636 | | - llvm::make_unique<DxilResource>(); |
637 | | - pUAV->SetGlobalName((std::string("PIX_CountUAVName")+ std::to_string(UAVResourceHandle)).c_str()); |
638 | | - pUAV->SetGlobalSymbol(UndefValue::get(UAVStructTy->getPointerTo())); |
639 | | - pUAV->SetID(UAVResourceHandle); |
640 | | - pUAV->SetRW(true); //sets UAV class |
641 | | - pUAV->SetSpaceID(( |
642 | | - unsigned int)-2); // This is the reserved-for-tools register space |
643 | | - pUAV->SetSampleCount(1); |
644 | | - pUAV->SetGloballyCoherent(false); |
645 | | - pUAV->SetHasCounter(false); |
646 | | - pUAV->SetCompType(CompType::getI32()); |
647 | | - pUAV->SetLowerBound(0); |
648 | | - pUAV->SetRangeSize(1); |
649 | | - pUAV->SetKind(DXIL::ResourceKind::RawBuffer); |
650 | | - |
651 | | - auto pAnnotation = |
652 | | - DM.GetTypeSystem().GetStructAnnotation(UAVStructTy); |
653 | | - if (pAnnotation == nullptr) { |
654 | | - |
655 | | - pAnnotation = DM.GetTypeSystem().AddStructAnnotation(UAVStructTy); |
656 | | - pAnnotation->GetFieldAnnotation(0).SetCBufferOffset(0); |
657 | | - pAnnotation->GetFieldAnnotation(0).SetCompType( |
658 | | - hlsl::DXIL::ComponentType::I32); |
659 | | - pAnnotation->GetFieldAnnotation(0).SetFieldName("count"); |
660 | | - } |
661 | | - |
662 | | - OP *HlslOP = DM.GetOP(); |
663 | | - |
664 | | - // Create handle for the newly-added UAV |
665 | | - if (IsDynamicResourceShaderModel(DM)) { |
666 | | - Function *CreateHandleFromBindingOpFunc = |
667 | | - HlslOP->GetOpFunc(DXIL::OpCode::CreateHandleFromBinding, Type::getVoidTy(Ctx)); |
668 | | - Constant *CreateHandleFromBindingOpcodeArg = |
669 | | - HlslOP->GetU32Const((unsigned)DXIL::OpCode::CreateHandleFromBinding); |
670 | | - DxilResourceBinding binding = |
671 | | - resource_helper::loadBindingFromResourceBase(pUAV.get()); |
672 | | - Value *bindingV = resource_helper::getAsConstant( |
673 | | - binding, HlslOP->GetResourceBindingType(), *DM.GetShaderModel()); |
674 | | - |
675 | | - Value *registerIndex = HlslOP->GetU32Const(UAVResourceHandle); |
676 | | - |
677 | | - Value *isUniformRes = HlslOP->GetI1Const(0); |
678 | | - |
679 | | - Value *createHandleFromBindingArgs[] = { CreateHandleFromBindingOpcodeArg, bindingV, registerIndex, |
680 | | - isUniformRes}; |
681 | | - |
682 | | - auto * handle = Builder.CreateCall( |
683 | | - CreateHandleFromBindingOpFunc, |
684 | | - createHandleFromBindingArgs, |
685 | | - name); |
686 | | - |
687 | | - Function *annotHandleFn = HlslOP->GetOpFunc(DXIL::OpCode::AnnotateHandle, Type::getVoidTy(Ctx)); |
688 | | - Value *annotHandleArg = HlslOP->GetI32Const((unsigned)DXIL::OpCode::AnnotateHandle); |
689 | | - DxilResourceProperties RP = resource_helper::loadPropsFromResourceBase(pUAV.get()); |
690 | | - Type *resPropertyTy = HlslOP->GetResourcePropertiesType(); |
691 | | - Value *propertiesV = resource_helper::getAsConstant(RP, resPropertyTy, *DM.GetShaderModel()); |
692 | | - |
693 | | - unsigned int ID = DM.AddUAV(std::move(pUAV)); |
694 | | - DXASSERT_LOCALVAR_NOMSG(ID, (unsigned)ID == UAVResourceHandle); |
695 | | - |
696 | | - return Builder.CreateCall(annotHandleFn, {annotHandleArg, handle, propertiesV}); |
697 | | - } else { |
698 | | - unsigned int ID = DM.AddUAV(std::move(pUAV)); |
699 | | - DXASSERT_NOMSG((unsigned)ID == UAVResourceHandle); |
700 | | - |
701 | | - Function* CreateHandleOpFunc = HlslOP->GetOpFunc( |
702 | | - DXIL::OpCode::CreateHandle, Type::getVoidTy(Ctx)); |
703 | | - Constant* CreateHandleOpcodeArg = |
704 | | - HlslOP->GetU32Const((unsigned)DXIL::OpCode::CreateHandle); |
705 | | - Constant* UAVArg = HlslOP->GetI8Const( |
706 | | - static_cast<std::underlying_type<DxilResourceBase::Class>::type>( |
707 | | - DXIL::ResourceClass::UAV)); |
708 | | - Constant* MetaDataArg = |
709 | | - HlslOP->GetU32Const(ID); // position of the metadata record in the |
710 | | - // corresponding metadata list |
711 | | - Constant* IndexArg = HlslOP->GetU32Const(0); // |
712 | | - Constant* FalseArg = |
713 | | - HlslOP->GetI1Const(0); // non-uniform resource index: false |
714 | | - return Builder.CreateCall( |
715 | | - CreateHandleOpFunc, |
716 | | - { CreateHandleOpcodeArg, UAVArg, MetaDataArg, IndexArg, FalseArg }, |
717 | | - name); |
718 | | - } |
719 | | -} |
720 | | - |
721 | 625 | static uint32_t EncodeShaderModel(DXIL::ShaderKind kind) |
722 | 626 | { |
723 | 627 | DXASSERT_NOMSG(static_cast<int>(DXIL::ShaderKind::Invalid) <= 16); |
@@ -771,15 +675,12 @@ bool DxilShaderAccessTracking::runOnModule(Module &M) { |
771 | 675 | FOS << "ShouldAssumeDsvAccess"; |
772 | 676 | } |
773 | 677 | } |
774 | | - |
| 678 | + int uavRegId = 0; |
775 | 679 | for (llvm::Function &F : M.functions()) { |
776 | 680 | if (!F.getBasicBlockList().empty()) { |
777 | 681 | IRBuilder<> Builder(F.getEntryBlock().getFirstInsertionPt()); |
778 | 682 |
|
779 | | - unsigned int UAVResourceHandle = |
780 | | - static_cast<unsigned int>(DM.GetUAVs().size()); |
781 | | - |
782 | | - m_FunctionToUAVHandle[&F] = CreateUAV(DM, Builder, UAVResourceHandle, 0, "PIX_CountUAV_Handle"); |
| 683 | + m_FunctionToUAVHandle[&F] = PIXPassHelpers::CreateUAV(DM, Builder, uavRegId++, "PIX_CountUAV_Handle"); |
783 | 684 | auto const* shaderModel = DM.GetShaderModel(); |
784 | 685 | auto shaderKind = shaderModel->GetKind(); |
785 | 686 | OP *HlslOP = DM.GetOP(); |
|
0 commit comments