diff --git a/lib/HLSL/DxilGenerationPass.cpp b/lib/HLSL/DxilGenerationPass.cpp index fb3e557ca..e6eb648fe 100644 --- a/lib/HLSL/DxilGenerationPass.cpp +++ b/lib/HLSL/DxilGenerationPass.cpp @@ -846,6 +846,8 @@ void DxilGenerationPass::AddCreateHandleForPhiNodeAndSelect(OP *hlslOP) { UpdateHandleOperands(Res, handleMap, nonUniformOps); } + bool bIsLib = m_pHLModule->GetShaderModel()->IsLib(); + // ResClass and ResID must be uniform. // Try to merge res class, res id into imm. while (1) { @@ -866,7 +868,7 @@ void DxilGenerationPass::AddCreateHandleForPhiNodeAndSelect(OP *hlslOP) { } if (!bUpdated) { - if (!nonUniformOps.empty()) { + if (!nonUniformOps.empty() && !bIsLib) { for (Instruction *I : nonUniformOps) { // Non uniform res class or res id. FT->getContext().emitError(I, kResourceMapErrorMsg); diff --git a/tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl b/tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl new file mode 100644 index 000000000..7d43b2e3d --- /dev/null +++ b/tools/clang/test/CodeGenHLSL/shader-compat-suite/lib_res_sel.hlsl @@ -0,0 +1,13 @@ +// RUN: %dxc -T lib_6_1 %s | FileCheck %s + +// Make sure select resource works for lib profile. +// CHECK: call %dx.types.Handle @dx.op.createHandle( + +RWStructuredBuffer buf0; +RWStructuredBuffer buf1; + + +void Store(bool bBufX, float2 v, uint idx) { + RWStructuredBuffer buf = bBufX ? buf0: buf1; + buf[idx] = v; +} \ No newline at end of file