Skip to content

Commit 234d2e2

Browse files
committed
[mlir][spirv] Enable WebGPU to use UnifyAliasedResourcePass
When targeting WebGPU, we also need to transcompile SPIR-V, into WGSL this time. We have similar limitations there like when targeting Metal or MoltenVK. Reviewed By: kuhar Differential Revision: https://reviews.llvm.org/D138735
1 parent e672f51 commit 234d2e2

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎mlir/lib/Dialect/SPIRV/Transforms/UnifyAliasedResourcePass.cpp‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,16 @@ void UnifyAliasedResourcePass::runOnOperation() {
549549
MLIRContext *context = &getContext();
550550

551551
if (getTargetEnvFn) {
552-
// This pass is actually only needed for targeting Apple GPUs via MoltenVK,
553-
// where we need to translate SPIR-V into MSL. The translation has
554-
// limitations.
555-
if (getTargetEnvFn(moduleOp).getVendorID() != spirv::Vendor::Apple)
552+
// This pass is only needed for targeting WebGPU, Metal, or layering Vulkan
553+
// on Metal via MoltenVK, where we need to translate SPIR-V into WGSL or
554+
// MSL. The translation has limitations.
555+
spirv::TargetEnvAttr targetEnv = getTargetEnvFn(moduleOp);
556+
spirv::ClientAPI clientAPI = targetEnv.getClientAPI();
557+
bool isVulkanOnAppleDevices =
558+
clientAPI == spirv::ClientAPI::Vulkan &&
559+
targetEnv.getVendorID() == spirv::Vendor::Apple;
560+
if (clientAPI != spirv::ClientAPI::WebGPU &&
561+
clientAPI != spirv::ClientAPI::Metal && !isVulkanOnAppleDevices)
556562
return;
557563
}
558564

0 commit comments

Comments
 (0)