From 2814fa60bf6986ca03c81957e815dd15fc5591cf Mon Sep 17 00:00:00 2001 From: Gabriel A Date: Mon, 10 Jul 2023 23:32:31 -0300 Subject: [PATCH] Work around Adreno compute dispatch crash when changing grpahics state with a compute pipeline bound --- src/Ryujinx.Graphics.Vulkan/PipelineBase.cs | 46 ++++++++++++--------- src/Ryujinx.Graphics.Vulkan/PipelineFull.cs | 6 ++- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs index af3a27e55..488d68c47 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -1588,36 +1588,42 @@ namespace Ryujinx.Graphics.Vulkan DynamicState.ReplayIfDirty(Gd.Api, CommandBuffer); - if (_needsIndexBufferRebind && _indexBufferPattern == null) + // Setting graphics state with a compute pipeline bound crashes the Adreno driver. + if (pbp == PipelineBindPoint.Graphics) { - _indexBuffer.BindIndexBuffer(Gd, Cbs); - _needsIndexBufferRebind = false; - } + DynamicState.ReplayIfDirty(Gd.Api, CommandBuffer); - if (_needsTransformFeedbackBuffersRebind) - { - PauseTransformFeedbackInternal(); - - for (int i = 0; i < Constants.MaxTransformFeedbackBuffers; i++) + if (_needsIndexBufferRebind && _indexBufferPattern == null) { - _transformFeedbackBuffers[i].BindTransformFeedbackBuffer(Gd, Cbs, (uint)i); + _indexBuffer.BindIndexBuffer(Gd, Cbs); + _needsIndexBufferRebind = false; } - _needsTransformFeedbackBuffersRebind = false; - } - - if (_vertexBuffersDirty != 0) - { - while (_vertexBuffersDirty != 0) + if (_needsTransformFeedbackBuffersRebind) { - int i = BitOperations.TrailingZeroCount(_vertexBuffersDirty); + PauseTransformFeedbackInternal(); - _vertexBuffers[i].BindVertexBuffer(Gd, Cbs, (uint)i, ref _newState, _vertexBufferUpdater); + for (int i = 0; i < Constants.MaxTransformFeedbackBuffers; i++) + { + _transformFeedbackBuffers[i].BindTransformFeedbackBuffer(Gd, Cbs, (uint)i); + } - _vertexBuffersDirty &= ~(1UL << i); + _needsTransformFeedbackBuffersRebind = false; } - _vertexBufferUpdater.Commit(Cbs); + if (_vertexBuffersDirty != 0) + { + while (_vertexBuffersDirty != 0) + { + int i = BitOperations.TrailingZeroCount(_vertexBuffersDirty); + + _vertexBuffers[i].BindVertexBuffer(Gd, Cbs, (uint)i, ref _newState, _vertexBufferUpdater); + + _vertexBuffersDirty &= ~(1UL << i); + } + + _vertexBufferUpdater.Commit(Cbs); + } } if (_stateDirty || Pbp != pbp) diff --git a/src/Ryujinx.Graphics.Vulkan/PipelineFull.cs b/src/Ryujinx.Graphics.Vulkan/PipelineFull.cs index 24ca715fe..4be60c2e7 100644 --- a/src/Ryujinx.Graphics.Vulkan/PipelineFull.cs +++ b/src/Ryujinx.Graphics.Vulkan/PipelineFull.cs @@ -246,7 +246,11 @@ namespace Ryujinx.Graphics.Vulkan SignalCommandBufferChange(); - DynamicState.ReplayIfDirty(Gd.Api, CommandBuffer); + // Setting graphics state with a compute pipeline bound crashes the Adreno driver. + if (Pbp == PipelineBindPoint.Graphics) + { + DynamicState.ReplayIfDirty(Gd.Api, CommandBuffer); + } } public void FlushCommandsImpl()