@@ -314,13 +314,41 @@ void DeviceContextD3D11Impl::BindCacheResources(const ShaderResourceCacheD3D11&
314314 if (ShaderInd == PSInd && PsUavBindMode != PixelShaderUAVBindMode::Bind)
315315 PsUavBindMode = PixelShaderUAVBindMode::Keep;
316316
317- auto * d3d11UAVs = m_CommittedRes.d3d11UAVs [ShaderInd];
318- auto * d3d11UAVRes = m_CommittedRes.d3d11UAVResources [ShaderInd];
317+ ID3D11UnorderedAccessView* * d3d11UAVs = m_CommittedRes.d3d11UAVs [ShaderInd];
318+ ID3D11Resource** d3d11UAVRes = m_CommittedRes.d3d11UAVResources [ShaderInd];
319319 if (auto Slots = ResourceCache.BindResourceViews <D3D11_RESOURCE_RANGE_UAV>(ShaderInd, d3d11UAVs, d3d11UAVRes, BaseBindings))
320320 {
321321 if (ShaderInd == PSInd)
322322 {
323323 PsUavBindMode = PixelShaderUAVBindMode::Bind;
324+
325+ // In Direct3D11, a resource can only be bound as UAV once.
326+ // Check if any resource in the range is currently bound as compute shader UAV and unbind it.
327+ if (Uint8& NumCsUavSlots = m_CommittedRes.NumUAVs [CSInd])
328+ {
329+ ID3D11UnorderedAccessView** d3d11CsUAVs = m_CommittedRes.d3d11UAVs [CSInd];
330+ ID3D11Resource** d3d11CsUAVRes = m_CommittedRes.d3d11UAVResources [CSInd];
331+ for (Uint32 ps_slot = Slots.MinSlot ; ps_slot <= Slots.MaxSlot ; ++ps_slot)
332+ {
333+ if (ID3D11Resource* d3d11Res = d3d11UAVRes[ps_slot])
334+ {
335+ for (Uint32 cs_slot = 0 ; cs_slot < NumCsUavSlots; ++cs_slot)
336+ {
337+ if (d3d11CsUAVRes[cs_slot] == d3d11Res)
338+ {
339+ d3d11CsUAVs[cs_slot] = nullptr ;
340+ d3d11CsUAVRes[cs_slot] = nullptr ;
341+ m_pd3d11DeviceContext->CSSetUnorderedAccessViews (cs_slot, 1 , &d3d11CsUAVs[cs_slot], nullptr );
342+ }
343+ }
344+ }
345+ }
346+ while (NumCsUavSlots > 0 && d3d11CsUAVRes[NumCsUavSlots - 1 ] == nullptr )
347+ {
348+ VERIFY_EXPR (d3d11CsUAVs[NumCsUavSlots - 1 ] == nullptr );
349+ --NumCsUavSlots;
350+ }
351+ }
324352 }
325353 else if (ShaderInd == CSInd)
326354 {
0 commit comments