@@ -799,107 +799,15 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
799799 return Reg;
800800}
801801
802- static std::string GetSpirvImageTypeName (const SPIRVType *Type,
803- MachineIRBuilder &MIRBuilder,
804- const std::string &Prefix,
805- SPIRVGlobalRegistry &GR);
806-
807802// Returns a name based on the Type. Notes that this does not look at
808803// decorations, and will return the same string for two types that are the same
809804// except for decorations.
810- static std::string buildSpirvTypeName (const SPIRVType *Type,
811- MachineIRBuilder &MIRBuilder,
812- SPIRVGlobalRegistry &GR) {
813- switch (Type->getOpcode ()) {
814- case SPIRV::OpTypeSampledImage: {
815- return GetSpirvImageTypeName (Type, MIRBuilder, " sampled_image_" , GR);
816- }
817- case SPIRV::OpTypeImage: {
818- return GetSpirvImageTypeName (Type, MIRBuilder, " image_" , GR);
819- }
820- case SPIRV::OpTypeArray: {
821- MachineRegisterInfo *MRI = MIRBuilder.getMRI ();
822- Register ElementTypeReg = Type->getOperand (1 ).getReg ();
823- auto *ElementType = MRI->getUniqueVRegDef (ElementTypeReg);
824- uint32_t ArraySize = getArrayComponentCount (MRI, Type);
825- return (buildSpirvTypeName (ElementType, MIRBuilder, GR) + Twine (" [" ) +
826- Twine (ArraySize) + Twine (" ]" ))
827- .str ();
828- }
829- case SPIRV::OpTypeFloat:
830- return (" f" + Twine (Type->getOperand (1 ).getImm ())).str ();
831- case SPIRV::OpTypeSampler:
832- return (" sampler" );
833- case SPIRV::OpTypeInt:
834- if (Type->getOperand (2 ).getImm ())
835- return (" i" + Twine (Type->getOperand (1 ).getImm ())).str ();
836- return (" u" + Twine (Type->getOperand (1 ).getImm ())).str ();
837- case SPIRV::OpTypePointer: {
838- uint32_t StorageClass = GR.getPointerStorageClass (Type);
839- SPIRVType *PointeeType = GR.getPointeeType (Type);
840- return (" p_" + Twine (StorageClass) + Twine (" _" ) +
841- buildSpirvTypeName (PointeeType, MIRBuilder, GR))
842- .str ();
843- }
844- case SPIRV::OpTypeStruct: {
845- std::string TypeName = " {" ;
846- for (uint32_t I = 1 ; I < Type->getNumOperands (); ++I) {
847- SPIRVType *MemberType =
848- GR.getSPIRVTypeForVReg (Type->getOperand (I).getReg ());
849- TypeName += ' _' + buildSpirvTypeName (MemberType, MIRBuilder, GR);
850- }
851- return TypeName + " }" ;
852- }
853- case SPIRV::OpTypeVector: {
854- MachineRegisterInfo *MRI = MIRBuilder.getMRI ();
855- Register ElementTypeReg = Type->getOperand (1 ).getReg ();
856- auto *ElementType = MRI->getUniqueVRegDef (ElementTypeReg);
857- uint32_t VectorSize = GR.getScalarOrVectorComponentCount (Type);
858- return (buildSpirvTypeName (ElementType, MIRBuilder, GR) + Twine (" [" ) +
859- Twine (VectorSize) + Twine (" ]" ))
860- .str ();
861- }
862- case SPIRV::OpTypeRuntimeArray: {
863- MachineRegisterInfo *MRI = MIRBuilder.getMRI ();
864- Register ElementTypeReg = Type->getOperand (1 ).getReg ();
865- auto *ElementType = MRI->getUniqueVRegDef (ElementTypeReg);
866- uint32_t ArraySize = 0 ;
867- return (buildSpirvTypeName (ElementType, MIRBuilder, GR) + Twine (" [" ) +
868- Twine (ArraySize) + Twine (" ]" ))
869- .str ();
870- }
871- default :
872- llvm_unreachable (" Trying to the the name of an unknown type." );
873- }
874- }
875-
876- static std::string GetSpirvImageTypeName (const SPIRVType *Type,
877- MachineIRBuilder &MIRBuilder,
878- const std::string &Prefix,
879- SPIRVGlobalRegistry &GR) {
880- Register SampledTypeReg = Type->getOperand (1 ).getReg ();
881- auto *SampledType = MIRBuilder.getMRI ()->getUniqueVRegDef (SampledTypeReg);
882- std::string TypeName =
883- Prefix + buildSpirvTypeName (SampledType, MIRBuilder, GR);
884- for (uint32_t I = 2 ; I < Type->getNumOperands (); ++I) {
885- TypeName = (TypeName + ' _' + Twine (Type->getOperand (I).getImm ())).str ();
886- }
887- return TypeName;
888- }
889-
890805Register SPIRVGlobalRegistry::getOrCreateGlobalVariableWithBinding (
891- const SPIRVType *VarType, uint32_t Set, uint32_t Binding,
806+ const SPIRVType *VarType, uint32_t Set, uint32_t Binding, StringRef Name,
892807 MachineIRBuilder &MIRBuilder) {
893808 Register VarReg =
894809 MIRBuilder.getMRI ()->createVirtualRegister (&SPIRV::iIDRegClass);
895810
896- // TODO(138533): The name should come from the llvm-ir, but how that name will
897- // be passed from the HLSL to the backend has not been decided. Using this
898- // place holder for now.
899- std::string Name =
900- (" __resource_" + buildSpirvTypeName (VarType, MIRBuilder, *this ) + " _" +
901- Twine (Set) + " _" + Twine (Binding))
902- .str ();
903811 buildGlobalVariable (VarReg, VarType, Name, nullptr ,
904812 getPointerStorageClass (VarType), nullptr , false , false ,
905813 SPIRV::LinkageType::Import, MIRBuilder, false );
0 commit comments