Skip to content

Commit

Permalink
Fix resource specialization with -embed-dxil (#4990)
Browse files Browse the repository at this point in the history
* Fix resource specialization with `-embed-dxil`

fixes: #4989

Changes:
1. Before handing off to DCE an `oldFunc` which should be removed, clean up any leftover `IRKeepAliveDecoration` (else DCE won't remove our `oldFunc`s)
  • Loading branch information
ArielG-NV authored Sep 4, 2024
1 parent 599dae5 commit dc3f2d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion source/slang/slang-ir-specialize-resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ struct ResourceOutputSpecializationPass
newFunc->removeAndDeallocate();
// Check if `oldFunc` is the reason for failing,
// Otherwise don't add to 'unspecializableFuncs'
if(result == SpecializeFuncResult::ThisFuncFailed)
//
// Ensure oldFunc has uses, else, there is nothing to specialize here.
// If oldFunc has IRKeepAlive, this code should be assumed to have a
// "dynamic" resource value.
if(result == SpecializeFuncResult::ThisFuncFailed && oldFunc->hasUses())
unspecializableFuncs->add(oldFunc);
return false;
}
Expand Down Expand Up @@ -315,6 +319,11 @@ struct ResourceOutputSpecializationPass
specializeCallSite(oldCall, newFunc, funcInfo);
}
specializedFuncs.add(oldFunc);

// Since we can no longer fail and we are replacing all `Func` uses, 'KeepAlive'
// can be removed from the oldFunc so DCE can it clean-up.
if(auto keepAliveDecoration = oldFunc->findDecoration<IRKeepAliveDecoration>())
keepAliveDecoration->removeAndDeallocate();
return true;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/library/precompiled-module-library-resource.slang
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ module "precompiled-module-library-resource";

public struct ResourceStruct {
public StructuredBuffer<int> buffer;

__init(StructuredBuffer<int> bufferIn)
{
buffer = bufferIn;
}
};

public int resource_in_parameter(StructuredBuffer<int> buffer)
Expand Down

0 comments on commit dc3f2d6

Please sign in to comment.