Code Review Suggestions

This commit is contained in:
sunshineinabox 2024-09-09 18:53:40 -07:00
parent 4a3b10fa9f
commit 01c6d5491e
5 changed files with 100 additions and 76 deletions

View file

@ -1,4 +1,5 @@
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.Memory;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader;
using Silk.NET.Vulkan; using Silk.NET.Vulkan;
@ -640,14 +641,32 @@ namespace Ryujinx.Graphics.Vulkan
{ {
if (texture is TextureView srcTexture) if (texture is TextureView srcTexture)
{ {
var oldCullMode = _supportExtDynamic ? DynamicState.CullMode : _newState.CullMode; CullModeFlags oldCullMode;
var oldStencilTestEnable = _supportExtDynamic ? DynamicState.StencilTestEnable : _newState.StencilTestEnable; bool oldStencilTestEnable;
var oldDepthTestEnable = _supportExtDynamic ? DynamicState.DepthTestEnable : _newState.DepthTestEnable; bool oldDepthTestEnable;
var oldDepthWriteEnable = _supportExtDynamic ? DynamicState.DepthWriteEnable : _newState.DepthWriteEnable; bool oldDepthWriteEnable;
var oldTopology = _supportExtDynamic ? DynamicState.Topology : _newState.Topology; Silk.NET.Vulkan.PrimitiveTopology oldTopology;
var oldTopologyClass = _newState.Topology; Array16<Silk.NET.Vulkan.Viewport> oldViewports = DynamicState.Viewports;
var oldViewports = DynamicState.Viewports; uint oldViewportsCount;
var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount;
if (_supportExtDynamic)
{
oldCullMode = DynamicState.CullMode;
oldStencilTestEnable = DynamicState.StencilTestEnable;
oldDepthTestEnable = DynamicState.DepthTestEnable;
oldDepthWriteEnable = DynamicState.DepthWriteEnable;
oldTopology = DynamicState.Topology;
oldViewportsCount = DynamicState.ViewportsCount;
}
else
{
oldCullMode = _newState.CullMode;
oldStencilTestEnable = _newState.StencilTestEnable;
oldDepthTestEnable = _newState.DepthTestEnable;
oldDepthWriteEnable = _newState.DepthWriteEnable;
oldTopology = _newState.Topology;
oldViewportsCount = _newState.ViewportsCount;
}
if (_supportExtDynamic) if (_supportExtDynamic)
{ {
@ -661,9 +680,9 @@ namespace Ryujinx.Graphics.Vulkan
_newState.StencilTestEnable = false; _newState.StencilTestEnable = false;
_newState.DepthTestEnable = false; _newState.DepthTestEnable = false;
_newState.DepthWriteEnable = false; _newState.DepthWriteEnable = false;
}
SignalStateChange(); SignalStateChange();
}
Gd.HelperShader.DrawTexture( Gd.HelperShader.DrawTexture(
Gd, Gd,
@ -673,13 +692,10 @@ namespace Ryujinx.Graphics.Vulkan
srcRegion, srcRegion,
dstRegion); dstRegion);
_newState.Topology = oldTopology;
if (_supportExtDynamic) if (_supportExtDynamic)
{ {
if (oldTopologyClass != _newState.Topology)
{
_newState.Topology = oldTopology;
}
DynamicState.SetCullMode(oldCullMode); DynamicState.SetCullMode(oldCullMode);
DynamicState.SetStencilTest(oldStencilTestEnable); DynamicState.SetStencilTest(oldStencilTestEnable);
DynamicState.SetDepthTestBool(oldDepthTestEnable, oldDepthWriteEnable); DynamicState.SetDepthTestBool(oldDepthTestEnable, oldDepthWriteEnable);
@ -692,7 +708,6 @@ namespace Ryujinx.Graphics.Vulkan
_newState.DepthTestEnable = oldDepthTestEnable; _newState.DepthTestEnable = oldDepthTestEnable;
_newState.DepthWriteEnable = oldDepthWriteEnable; _newState.DepthWriteEnable = oldDepthWriteEnable;
_newState.ViewportsCount = oldViewportsCount; _newState.ViewportsCount = oldViewportsCount;
_newState.Topology = oldTopology;
} }
DynamicState.SetViewports(ref oldViewports, oldViewportsCount); DynamicState.SetViewports(ref oldViewports, oldViewportsCount);
@ -832,7 +847,6 @@ namespace Ryujinx.Graphics.Vulkan
if (_supportExtDynamic2) if (_supportExtDynamic2)
{ {
DynamicState.SetDepthBiasEnable(depthBiasEnable); DynamicState.SetDepthBiasEnable(depthBiasEnable);
changed = true;
} }
else if (_newState.DepthBiasEnable != depthBiasEnable) else if (_newState.DepthBiasEnable != depthBiasEnable)
{ {
@ -843,7 +857,6 @@ namespace Ryujinx.Graphics.Vulkan
if (depthBiasEnable) if (depthBiasEnable)
{ {
DynamicState.SetDepthBias(factor, units, clamp); DynamicState.SetDepthBias(factor, units, clamp);
changed = true;
} }
if (changed) if (changed)
@ -888,10 +901,11 @@ namespace Ryujinx.Graphics.Vulkan
_newState.DepthTestEnable = depthTest.TestEnable; _newState.DepthTestEnable = depthTest.TestEnable;
_newState.DepthWriteEnable = depthTest.WriteEnable; _newState.DepthWriteEnable = depthTest.WriteEnable;
_newState.DepthCompareOp = depthTest.Func.Convert(); _newState.DepthCompareOp = depthTest.Func.Convert();
SignalStateChange();
} }
UpdatePassDepthStencil(); UpdatePassDepthStencil();
SignalStateChange();
} }
public void SetFaceCulling(bool enable, Face face) public void SetFaceCulling(bool enable, Face face)
@ -903,10 +917,10 @@ namespace Ryujinx.Graphics.Vulkan
else else
{ {
_newState.CullMode = enable ? face.Convert() : CullModeFlags.None; _newState.CullMode = enable ? face.Convert() : CullModeFlags.None;
}
SignalStateChange(); SignalStateChange();
} }
}
public void SetFrontFace(FrontFace frontFace) public void SetFrontFace(FrontFace frontFace)
{ {
@ -917,10 +931,10 @@ namespace Ryujinx.Graphics.Vulkan
else else
{ {
_newState.FrontFace = frontFace.Convert(); _newState.FrontFace = frontFace.Convert();
}
SignalStateChange(); SignalStateChange();
} }
}
public void SetImage(ShaderStage stage, int binding, ITexture image, Format imageFormat) public void SetImage(ShaderStage stage, int binding, ITexture image, Format imageFormat)
{ {
@ -962,8 +976,6 @@ namespace Ryujinx.Graphics.Vulkan
{ {
DynamicState.SetLineWidth(Gd.Capabilities.SupportsWideLines ? width : 1.0f); DynamicState.SetLineWidth(Gd.Capabilities.SupportsWideLines ? width : 1.0f);
} }
SignalStateChange();
} }
public void SetLogicOpState(bool enable, LogicalOp op) public void SetLogicOpState(bool enable, LogicalOp op)
@ -1007,9 +1019,9 @@ namespace Ryujinx.Graphics.Vulkan
else else
{ {
_newState.PatchControlPoints = (uint)vertices; _newState.PatchControlPoints = (uint)vertices;
}
SignalStateChange(); SignalStateChange();
}
// TODO: Default levels (likely needs emulation on shaders?) // TODO: Default levels (likely needs emulation on shaders?)
} }
@ -1033,10 +1045,11 @@ namespace Ryujinx.Graphics.Vulkan
else else
{ {
_newState.PrimitiveRestartEnable = enable; _newState.PrimitiveRestartEnable = enable;
SignalStateChange();
} }
// TODO: What to do about the index? // TODO: What to do about the index?
SignalStateChange();
} }
public void SetPrimitiveTopology(PrimitiveTopology topology) public void SetPrimitiveTopology(PrimitiveTopology topology)
@ -1045,19 +1058,12 @@ namespace Ryujinx.Graphics.Vulkan
var vkTopology = Gd.TopologyRemap(topology).Convert(); var vkTopology = Gd.TopologyRemap(topology).Convert();
_newState.Topology = vkTopology;
if (_supportExtDynamic) if (_supportExtDynamic)
{ {
if ((_newState.Topology != vkTopology))
{
_newState.Topology = vkTopology;
}
DynamicState.SetPrimitiveTopology(vkTopology); DynamicState.SetPrimitiveTopology(vkTopology);
} }
else
{
_newState.Topology = vkTopology;
}
SignalStateChange(); SignalStateChange();
} }
@ -1074,7 +1080,7 @@ namespace Ryujinx.Graphics.Vulkan
_newState.PipelineLayout = internalProgram.PipelineLayout; _newState.PipelineLayout = internalProgram.PipelineLayout;
_newState.HasTessellationControlShader = internalProgram.HasTessellationControlShader; _newState.HasTessellationControlShader = internalProgram.HasTessellationControlShader;
_newState.StagesCount = internalProgram.IsCompute ? 1 : (uint)stages.Length; _newState.StagesCount = (uint)stages.Length;
stages.CopyTo(_newState.Stages.AsSpan()[..stages.Length]); stages.CopyTo(_newState.Stages.AsSpan()[..stages.Length]);
@ -1104,15 +1110,16 @@ namespace Ryujinx.Graphics.Vulkan
public void SetRasterizerDiscard(bool discard) public void SetRasterizerDiscard(bool discard)
{ {
if (!_supportExtDynamic2) if (_supportExtDynamic2)
{
_newState.RasterizerDiscardEnable = discard;
}
else
{ {
DynamicState.SetRasterizerDiscard(discard); DynamicState.SetRasterizerDiscard(discard);
} }
else
{
_newState.RasterizerDiscardEnable = discard;
SignalStateChange(); SignalStateChange();
}
if (!discard && Gd.IsQualcommProprietary) if (!discard && Gd.IsQualcommProprietary)
{ {
@ -1195,11 +1202,6 @@ namespace Ryujinx.Graphics.Vulkan
ClearScissor = regions[0]; ClearScissor = regions[0];
} }
if (!_supportExtDynamic)
{
_newState.ScissorsCount = (uint)count;
}
DynamicState.ScissorsCount = count; DynamicState.ScissorsCount = count;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -1211,8 +1213,13 @@ namespace Ryujinx.Graphics.Vulkan
DynamicState.SetScissor(i, new Rect2D(offset, extent)); DynamicState.SetScissor(i, new Rect2D(offset, extent));
} }
if (!_supportExtDynamic)
{
_newState.ScissorsCount = (uint)count;
SignalStateChange(); SignalStateChange();
} }
}
public void SetStencilTest(StencilTestDescriptor stencilTest) public void SetStencilTest(StencilTestDescriptor stencilTest)
{ {
@ -1228,6 +1235,8 @@ namespace Ryujinx.Graphics.Vulkan
stencilTest.FrontDpFail.Convert(), stencilTest.FrontDpFail.Convert(),
stencilTest.FrontFunc.Convert(), stencilTest.FrontFunc.Convert(),
stencilTest.TestEnable); stencilTest.TestEnable);
UpdatePassDepthStencil();
} }
else else
{ {
@ -1240,6 +1249,9 @@ namespace Ryujinx.Graphics.Vulkan
_newState.StencilFrontDepthFailOp = stencilTest.FrontDpFail.Convert(); _newState.StencilFrontDepthFailOp = stencilTest.FrontDpFail.Convert();
_newState.StencilFrontCompareOp = stencilTest.FrontFunc.Convert(); _newState.StencilFrontCompareOp = stencilTest.FrontFunc.Convert();
_newState.StencilTestEnable = stencilTest.TestEnable; _newState.StencilTestEnable = stencilTest.TestEnable;
UpdatePassDepthStencil();
SignalStateChange();
} }
DynamicState.SetStencilMask((uint)stencilTest.BackFuncMask, DynamicState.SetStencilMask((uint)stencilTest.BackFuncMask,
@ -1248,9 +1260,6 @@ namespace Ryujinx.Graphics.Vulkan
(uint)stencilTest.FrontFuncMask, (uint)stencilTest.FrontFuncMask,
(uint)stencilTest.FrontMask, (uint)stencilTest.FrontMask,
(uint)stencilTest.FrontFuncRef); (uint)stencilTest.FrontFuncRef);
UpdatePassDepthStencil();
SignalStateChange();
} }
public void SetStorageBuffers(ReadOnlySpan<BufferAssignment> buffers) public void SetStorageBuffers(ReadOnlySpan<BufferAssignment> buffers)
@ -1472,11 +1481,6 @@ namespace Ryujinx.Graphics.Vulkan
return Math.Clamp(value, 0f, 1f); return Math.Clamp(value, 0f, 1f);
} }
if (!_supportExtDynamic)
{
_newState.ViewportsCount = (uint)count;
}
DynamicState.ViewportsCount = (uint)count; DynamicState.ViewportsCount = (uint)count;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -1492,8 +1496,13 @@ namespace Ryujinx.Graphics.Vulkan
Clamp(viewport.DepthFar))); Clamp(viewport.DepthFar)));
} }
if (!_supportExtDynamic)
{
_newState.ViewportsCount = (uint)count;
SignalStateChange(); SignalStateChange();
} }
}
public void SwapBuffer(Auto<DisposableBuffer> from, Auto<DisposableBuffer> to) public void SwapBuffer(Auto<DisposableBuffer> from, Auto<DisposableBuffer> to)
{ {
@ -1757,7 +1766,14 @@ namespace Ryujinx.Graphics.Vulkan
} }
// Stencil test being enabled doesn't necessarily mean a write, but it's not critical to check. // Stencil test being enabled doesn't necessarily mean a write, but it's not critical to check.
_passWritesDepthStencil |= _supportExtDynamic ? (DynamicState.DepthTestEnable && DynamicState.DepthWriteEnable) || DynamicState.StencilTestEnable : (_newState.DepthTestEnable && _newState.DepthWriteEnable) || _newState.StencilTestEnable; if (_supportExtDynamic)
{
_passWritesDepthStencil |= (DynamicState.DepthTestEnable && DynamicState.DepthWriteEnable) || DynamicState.StencilTestEnable;
}
else
{
_passWritesDepthStencil |= (_newState.DepthTestEnable && _newState.DepthWriteEnable) || _newState.StencilTestEnable;
}
} }
private bool RecreateGraphicsPipelineIfNeeded() private bool RecreateGraphicsPipelineIfNeeded()

View file

@ -82,7 +82,7 @@ namespace Ryujinx.Graphics.Vulkan
PrimitiveTopology = 1 << 16, PrimitiveTopology = 1 << 16,
DepthBiasEnable = 1 << 17, DepthBiasEnable = 1 << 17,
Standard = Blend | DepthBias | Scissor | Stencil | Viewport | FeedbackLoop, Standard = Blend | DepthBias | Scissor | Stencil | Viewport | FeedbackLoop,
Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnableandStencilOp | PrimitiveTopology, Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnableAndStencilOp | PrimitiveTopology,
Extended2 = RasterDiscard | PrimitiveRestart | DepthBiasEnable, Extended2 = RasterDiscard | PrimitiveRestart | DepthBiasEnable,
} }
@ -131,9 +131,16 @@ namespace Ryujinx.Graphics.Vulkan
_dirty |= DirtyFlags.DepthTestCompareOp; _dirty |= DirtyFlags.DepthTestCompareOp;
} }
public void SetStencilTestandOp(StencilOp backFailOp, StencilOp backPassOp, StencilOp backDepthFailOp, public void SetStencilTestandOp(
CompareOp backCompareOp, StencilOp frontFailOp, StencilOp frontPassOp, StencilOp frontDepthFailOp, StencilOp backFailOp,
CompareOp frontCompareOp, bool stencilTestEnable) StencilOp backPassOp,
StencilOp backDepthFailOp,
CompareOp backCompareOp,
StencilOp frontFailOp,
StencilOp frontPassOp,
StencilOp frontDepthFailOp,
CompareOp frontCompareOp,
bool stencilTestEnable)
{ {
_backFailOp = backFailOp; _backFailOp = backFailOp;
_backPassOp = backPassOp; _backPassOp = backPassOp;
@ -146,18 +153,22 @@ namespace Ryujinx.Graphics.Vulkan
StencilTestEnable = stencilTestEnable; StencilTestEnable = stencilTestEnable;
_dirty |= DirtyFlags.StencilTestEnableandStencilOp; _dirty |= DirtyFlags.StencilTestEnableAndStencilOp;
} }
public void SetStencilTest(bool stencilTestEnable) public void SetStencilTest(bool stencilTestEnable)
{ {
StencilTestEnable = stencilTestEnable; StencilTestEnable = stencilTestEnable;
_dirty |= DirtyFlags.StencilTestEnableandStencilOp; _dirty |= DirtyFlags.StencilTestEnableAndStencilOp;
} }
public void SetStencilMask(uint backCompareMask, uint backWriteMask, uint backReference, public void SetStencilMask(uint backCompareMask,
uint frontCompareMask, uint frontWriteMask, uint frontReference) uint backWriteMask,
uint backReference,
uint frontCompareMask,
uint frontWriteMask,
uint frontReference)
{ {
_backCompareMask = backCompareMask; _backCompareMask = backCompareMask;
_backWriteMask = backWriteMask; _backWriteMask = backWriteMask;
@ -324,9 +335,9 @@ namespace Ryujinx.Graphics.Vulkan
RecordDepthTestCompareOp(gd.ExtendedDynamicStateApi, commandBuffer); RecordDepthTestCompareOp(gd.ExtendedDynamicStateApi, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.StencilTestEnableandStencilOp)) if (_dirty.HasFlag(DirtyFlags.StencilTestEnableAndStencilOp))
{ {
RecordStencilTestandOp(gd.ExtendedDynamicStateApi, commandBuffer); RecordStencilTestAndOp(gd.ExtendedDynamicStateApi, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.LineWidth)) if (_dirty.HasFlag(DirtyFlags.LineWidth))

View file

@ -258,8 +258,6 @@ namespace Ryujinx.Graphics.Vulkan
private bool _supportsFeedBackLoopDynamicState; private bool _supportsFeedBackLoopDynamicState;
private uint _blendEnables; private uint _blendEnables;
public void Initialize(HardwareCapabilities capabilities) public void Initialize(HardwareCapabilities capabilities)
{ {
HasTessellationControlShader = false; HasTessellationControlShader = false;

View file

@ -492,10 +492,8 @@ namespace Ryujinx.Graphics.Vulkan
{ {
SType = StructureType.PhysicalDeviceExtendedDynamicState2FeaturesExt, SType = StructureType.PhysicalDeviceExtendedDynamicState2FeaturesExt,
PNext = pExtendedFeatures, PNext = pExtendedFeatures,
ExtendedDynamicState2 = ExtendedDynamicState2 = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2,
supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2, ExtendedDynamicState2LogicOp = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2LogicOp,
ExtendedDynamicState2LogicOp =
supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2LogicOp,
ExtendedDynamicState2PatchControlPoints = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints, ExtendedDynamicState2PatchControlPoints = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints,
}; };

View file

@ -423,6 +423,7 @@ namespace Ryujinx.Graphics.Vulkan
properties.Limits.FramebufferStencilSampleCounts; properties.Limits.FramebufferStencilSampleCounts;
// Temporarily disable this, can be added back at a later date, make it easy to re-enable. // Temporarily disable this, can be added back at a later date, make it easy to re-enable.
// Disabled because currently causing Device Lost error on nVidia.
featuresExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints = false; featuresExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints = false;
Capabilities = new HardwareCapabilities( Capabilities = new HardwareCapabilities(