Skip to content

Commit

Permalink
Get or create a resource dim type
Browse files Browse the repository at this point in the history
This change introduces a way of getting a resource dim typ e in which the type is created if absent.
  • Loading branch information
krystian-andrzejewski authored and igcbot committed Aug 27, 2024
1 parent 1058244 commit a01ca4f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion IGC/common/igc_resourceDimTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ namespace IGC
"__2D_DIM_Resource", "__2D_ARRAY_DIM_Resource",
"__3D_DIM_Resource", "__Cube_DIM_Resource", "__Cube_ARRAY_DIM_Resource" };

inline llvm::Type* CreateResourceDimensionType(llvm::LLVMContext& llvmCtx, RESOURCE_DIMENSION_TYPE resourceDimType)
{
return llvm::StructType::create(llvmCtx, ResourceDimensionTypeName[resourceDimType]);
}

inline void CreateResourceDimensionTypes(llvm::LLVMContext& llvmCtx)
{
for (unsigned int resourceDimTypeId = 0; resourceDimTypeId < (unsigned int)RESOURCE_DIMENSION_TYPE::NUM_RESOURCE_DIMENSION_TYPES; resourceDimTypeId++)
{
llvm::StructType::create(llvmCtx, ResourceDimensionTypeName[(RESOURCE_DIMENSION_TYPE)resourceDimTypeId]);
CreateResourceDimensionType(llvmCtx, static_cast<RESOURCE_DIMENSION_TYPE>(resourceDimTypeId));
}
}

Expand All @@ -57,4 +62,14 @@ namespace IGC
return module.getTypeByName(ResourceDimensionTypeName[resourceDimTypeId]);
#endif
}

inline llvm::Type* GetOrCreateResourceDimensionType(const llvm::Module& module, RESOURCE_DIMENSION_TYPE resourceDimTypeId)
{
llvm::Type* pRet = GetResourceDimensionType(module, resourceDimTypeId);
if (pRet == nullptr)
{
pRet = CreateResourceDimensionType(module.getContext(), resourceDimTypeId);
}
return pRet;
}
}

0 comments on commit a01ca4f

Please sign in to comment.