@@ -297,9 +297,9 @@ struct ResKeyHash {
297297 }
298298};
299299
300- // Limited to retrieving handles created by CreateHandleFromBinding. returns null otherwise
301- // map should contain resources indexed by class, lower, and upper bounds
302- DxilResource *GetResourceFromAnnotateHandle (CallInst *handleCall,
300+ // Limited to retrieving handles created by CreateHandleFromBinding and CreateHandleForLib . returns null otherwise
301+ // map should contain resources indexed by space, class, lower, and upper bounds
302+ DxilResource *GetResourceFromAnnotateHandle (const hlsl::DxilModule *M, CallInst *handleCall,
303303 std::unordered_map<ResourceKey, DxilResource *, ResKeyHash, ResKeyEq> resMap) {
304304 DxilResource *resource = nullptr ;
305305
@@ -317,6 +317,17 @@ DxilResource *GetResourceFromAnnotateHandle(CallInst *handleCall,
317317 DxilResourceBinding B = resource_helper::loadBindingFromConstant (*cast<Constant>(fromBind.get_bind ()));
318318 ResourceKey key = {B.resourceClass , B.spaceID , B.rangeLowerBound , B.rangeUpperBound };
319319 resource = resMap[key];
320+ } else if (handleOp == DXIL::OpCode::CreateHandleForLib) {
321+ // If library handle, find DxilResource by checking the name
322+ if (LoadInst *LI = dyn_cast<LoadInst>(createCall->getArgOperand (
323+ DXIL::OperandIndex::kCreateHandleForLibResOpIdx ))) {
324+ Value *resType = LI->getOperand (0 );
325+ for (auto &&res : M->GetUAVs ()) {
326+ if (res->GetGlobalSymbol () == resType) {
327+ return resource = res.get ();
328+ }
329+ }
330+ }
320331 }
321332 }
322333
@@ -487,7 +498,7 @@ ShaderFlags ShaderFlags::CollectShaderFlags(const Function *F,
487498 if (DXIL::IsTyped (RP.getResourceKind ()))
488499 hasAtomicInt64OnTypedResource = true ;
489500 // set uses 64-bit flag if relevant
490- if (DxilResource *res = GetResourceFromAnnotateHandle (handleCall, resMap)) {
501+ if (DxilResource *res = GetResourceFromAnnotateHandle (M, handleCall, resMap)) {
491502 res->SetHasAtomic64Use (true );
492503 } else {
493504 // Assuming CreateHandleFromHeap, which indicates a descriptor
0 commit comments