Clean up and some housekeeping

This commit is contained in:
sunshineinabox 2024-09-04 13:50:31 -07:00
parent 1fa1c7b01d
commit 2846e88a5d
6 changed files with 99 additions and 104 deletions

View file

@ -55,7 +55,9 @@ namespace Ryujinx.Graphics.GAL
public PolygonModeMask BiasEnable; public PolygonModeMask BiasEnable;
public float LineWidth; public bool AlphaToCoverageEnable;
public bool AlphaToOneEnable;
// TODO: Polygon mode. // TODO: Polygon mode.
public bool DepthClampEnable; public bool DepthClampEnable;
public bool RasterizerDiscard; public bool RasterizerDiscard;

View file

@ -709,8 +709,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{ {
DepthTestDescriptor descriptor = new( DepthTestDescriptor descriptor = new(
_state.State.DepthTestEnable, _state.State.DepthTestEnable,
_state.State.DepthWriteEnable, _state.State.DepthWriteEnable && _state.State.DepthTestEnable,
_state.State.DepthTestFunc); _state.State.DepthTestEnable ? _state.State.DepthTestFunc : default);
_pipeline.DepthTest = descriptor; _pipeline.DepthTest = descriptor;
_context.Renderer.Pipeline.SetDepthTest(descriptor); _context.Renderer.Pipeline.SetDepthTest(descriptor);
@ -1029,7 +1029,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
float width = _state.State.LineWidthSmooth; float width = _state.State.LineWidthSmooth;
bool smooth = _state.State.LineSmoothEnable; bool smooth = _state.State.LineSmoothEnable;
_pipeline.LineWidth = width;
_context.Renderer.Pipeline.SetLineParameters(width, smooth); _context.Renderer.Pipeline.SetLineParameters(width, smooth);
} }
@ -1391,6 +1390,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
bool alphaToCoverageEnable = (_state.State.MultisampleControl & 1) != 0; bool alphaToCoverageEnable = (_state.State.MultisampleControl & 1) != 0;
bool alphaToOneEnable = (_state.State.MultisampleControl & 0x10) != 0; bool alphaToOneEnable = (_state.State.MultisampleControl & 0x10) != 0;
_pipeline.AlphaToCoverageEnable = alphaToCoverageEnable;
_pipeline.AlphaToOneEnable = alphaToOneEnable;
_context.Renderer.Pipeline.SetMultisampleState(new MultisampleDescriptor( _context.Renderer.Pipeline.SetMultisampleState(new MultisampleDescriptor(
alphaToCoverageEnable, alphaToCoverageEnable,
_state.State.AlphaToCoverageDitherEnable, _state.State.AlphaToCoverageDitherEnable,

View file

@ -644,7 +644,8 @@ namespace Ryujinx.Graphics.Vulkan
var oldStencilTestEnable = _supportExtDynamic ? DynamicState.StencilTestEnable : _newState.StencilTestEnable; var oldStencilTestEnable = _supportExtDynamic ? DynamicState.StencilTestEnable : _newState.StencilTestEnable;
var oldDepthTestEnable = _supportExtDynamic ? DynamicState.DepthTestEnable : _newState.DepthTestEnable; var oldDepthTestEnable = _supportExtDynamic ? DynamicState.DepthTestEnable : _newState.DepthTestEnable;
var oldDepthWriteEnable = _supportExtDynamic ? DynamicState.DepthWriteEnable : _newState.DepthWriteEnable; var oldDepthWriteEnable = _supportExtDynamic ? DynamicState.DepthWriteEnable : _newState.DepthWriteEnable;
var oldTopology = _newState.Topology; var oldTopology = _supportExtDynamic ? DynamicState.Topology : _newState.Topology;
var oldTopologyClass = _newState.Topology;
var oldViewports = DynamicState.Viewports; var oldViewports = DynamicState.Viewports;
var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount; var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount;
@ -674,9 +675,9 @@ namespace Ryujinx.Graphics.Vulkan
if (_supportExtDynamic) if (_supportExtDynamic)
{ {
if (oldTopology != _newState.Topology.ConvertToClass()) if (oldTopologyClass != _newState.Topology)
{ {
_newState.Topology = oldTopology; _newState.Topology = oldTopologyClass;
} }
DynamicState.SetCullMode(oldCullMode); DynamicState.SetCullMode(oldCullMode);
@ -885,8 +886,8 @@ namespace Ryujinx.Graphics.Vulkan
else else
{ {
_newState.DepthTestEnable = depthTest.TestEnable; _newState.DepthTestEnable = depthTest.TestEnable;
_newState.DepthWriteEnable = depthTest.WriteEnable && depthTest.TestEnable; _newState.DepthWriteEnable = depthTest.WriteEnable;
_newState.DepthCompareOp = depthTest.TestEnable ? depthTest.Func.Convert() : default; _newState.DepthCompareOp = depthTest.Func.Convert();
} }
UpdatePassDepthStencil(); UpdatePassDepthStencil();
@ -901,7 +902,7 @@ namespace Ryujinx.Graphics.Vulkan
} }
else else
{ {
_newState.CullMode = enable ? face.Convert() : default; _newState.CullMode = enable ? face.Convert() : CullModeFlags.None;
} }
SignalStateChange(); SignalStateChange();
@ -1048,9 +1049,9 @@ namespace Ryujinx.Graphics.Vulkan
{ {
var newTopologyClass = vkTopology.ConvertToClass(); var newTopologyClass = vkTopology.ConvertToClass();
if ((_newState.Topology.ConvertToClass() != newTopologyClass)) if ((_newState.Topology != newTopologyClass))
{ {
_newState.Topology = vkTopology.ConvertToClass(); _newState.Topology = newTopologyClass;
} }
DynamicState.SetPrimitiveTopology(vkTopology); DynamicState.SetPrimitiveTopology(vkTopology);
@ -1075,7 +1076,7 @@ namespace Ryujinx.Graphics.Vulkan
_newState.PipelineLayout = internalProgram.PipelineLayout; _newState.PipelineLayout = internalProgram.PipelineLayout;
_newState.HasTessellationControlShader = internalProgram.HasTessellationControlShader; _newState.HasTessellationControlShader = internalProgram.HasTessellationControlShader;
_newState.StagesCount = (uint)stages.Length; _newState.StagesCount = internalProgram.IsCompute ? 1 : (uint)stages.Length;
stages.CopyTo(_newState.Stages.AsSpan()[..stages.Length]); stages.CopyTo(_newState.Stages.AsSpan()[..stages.Length]);
@ -1196,6 +1197,13 @@ namespace Ryujinx.Graphics.Vulkan
ClearScissor = regions[0]; ClearScissor = regions[0];
} }
if (!_supportExtDynamic)
{
_newState.ScissorsCount = (uint)count;
}
DynamicState.ScissorsCount = count;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
var region = regions[i]; var region = regions[i];
@ -1205,12 +1213,6 @@ namespace Ryujinx.Graphics.Vulkan
DynamicState.SetScissor(i, new Rect2D(offset, extent)); DynamicState.SetScissor(i, new Rect2D(offset, extent));
} }
DynamicState.ScissorsCount = count;
if (!_supportExtDynamic)
{
_newState.ScissorsCount = (uint)count;
}
SignalStateChange(); SignalStateChange();
} }
@ -1473,6 +1475,11 @@ 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++)
@ -1488,10 +1495,6 @@ namespace Ryujinx.Graphics.Vulkan
Clamp(viewport.DepthFar))); Clamp(viewport.DepthFar)));
} }
if (!_supportExtDynamic)
{
_newState.ViewportsCount = (uint)count;
}
SignalStateChange(); SignalStateChange();
} }

View file

@ -158,20 +158,16 @@ namespace Ryujinx.Graphics.Vulkan
var extendedDynamicState2 = gd.Capabilities.SupportsExtendedDynamicState2; var extendedDynamicState2 = gd.Capabilities.SupportsExtendedDynamicState2;
var extendedDynamicState = gd.Capabilities.SupportsExtendedDynamicState; var extendedDynamicState = gd.Capabilities.SupportsExtendedDynamicState;
var topology = extendedDynamicState ? gd.TopologyRemap(state.Topology).Convert().ConvertToClass() : gd.TopologyRemap(state.Topology).Convert();
PipelineState pipeline = new(); PipelineState pipeline = new();
pipeline.Initialize(gd.Capabilities, topology); pipeline.Initialize(gd.Capabilities);
// It is assumed that Dynamic State is enabled when this conversion is used. // It is assumed that Dynamic State is enabled when this conversion is used.
pipeline.DepthBoundsTestEnable = false; // Not implemented. pipeline.DepthBoundsTestEnable = false; // Not implemented.
pipeline.DepthClampEnable = state.DepthClampEnable; pipeline.DepthClampEnable = state.DepthClampEnable;
if (gd.Capabilities.SupportsDynamicAttachmentFeedbackLoop || !gd.Capabilities.SupportsAttachmentFeedbackLoop) pipeline.AlphaToCoverageEnable = state.AlphaToCoverageEnable;
{ pipeline.AlphaToOneEnable = state.AlphaToOneEnable;
pipeline.FeedbackLoopAspects = FeedbackLoopAspects.None;
}
pipeline.DepthMode = state.DepthMode == DepthMode.MinusOneToOne; pipeline.DepthMode = state.DepthMode == DepthMode.MinusOneToOne;
@ -179,55 +175,56 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.PolygonMode = PolygonMode.Fill; // Not implemented. pipeline.PolygonMode = PolygonMode.Fill; // Not implemented.
pipeline.PrimitiveRestartEnable = extendedDynamicState2.ExtendedDynamicState2 ? false : state.PrimitiveRestartEnable; pipeline.Topology = extendedDynamicState ? gd.TopologyRemap(state.Topology).Convert().ConvertToClass() : gd.TopologyRemap(state.Topology).Convert();
pipeline.RasterizerDiscardEnable = extendedDynamicState2.ExtendedDynamicState2 ? false : state.RasterizerDiscard;
pipeline.DepthBiasEnable = extendedDynamicState2.ExtendedDynamicState2 ? false : ((state.BiasEnable != 0) &&
(state.DepthBiasFactor != 0 && state.DepthBiasUnits != 0));
pipeline.PatchControlPoints = extendedDynamicState2.ExtendedDynamicState2PatchControlPoints ? 0 : state.PatchControlPoints;
pipeline.SamplesCount = (uint)state.SamplesCount;
pipeline.DepthTestEnable = !extendedDynamicState && state.DepthTest.TestEnable;
pipeline.DepthWriteEnable = !extendedDynamicState && state.DepthTest.WriteEnable && state.DepthTest.TestEnable;
if (!extendedDynamicState) if (!extendedDynamicState)
{ {
pipeline.DepthCompareOp = state.DepthTest.TestEnable ? state.DepthTest.Func.Convert() : default; pipeline.DepthCompareOp = state.DepthTest.Func.Convert();
pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : default; pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : CullModeFlags.None;
}
else
{
pipeline.DepthCompareOp = 0;
pipeline.CullMode = 0;
}
pipeline.FrontFace = extendedDynamicState ? 0 : state.FrontFace.Convert(); pipeline.DepthTestEnable = state.DepthTest.TestEnable;
pipeline.DepthWriteEnable = state.DepthTest.WriteEnable;
pipeline.FrontFace = state.FrontFace.Convert();
if (gd.Capabilities.SupportsMultiView) if (gd.Capabilities.SupportsMultiView)
{ {
pipeline.ScissorsCount = (uint)(extendedDynamicState ? 0 : Constants.MaxViewports); pipeline.ScissorsCount = Constants.MaxViewports;
pipeline.ViewportsCount = (uint)(extendedDynamicState ? 0 : Constants.MaxViewports); pipeline.ViewportsCount = Constants.MaxViewports;
} }
else else
{ {
pipeline.ScissorsCount = (uint)(extendedDynamicState ? 0 : 1); pipeline.ScissorsCount = 1;
pipeline.ViewportsCount = (uint)(extendedDynamicState ? 0 : 1); pipeline.ViewportsCount = 1;
} }
pipeline.StencilTestEnable = !extendedDynamicState && state.StencilTest.TestEnable; pipeline.StencilTestEnable = state.StencilTest.TestEnable;
pipeline.StencilFrontFailOp = extendedDynamicState ? 0 : state.StencilTest.FrontSFail.Convert(); pipeline.StencilFrontFailOp = state.StencilTest.FrontSFail.Convert();
pipeline.StencilFrontPassOp = extendedDynamicState ? 0 : state.StencilTest.FrontDpPass.Convert(); pipeline.StencilFrontPassOp = state.StencilTest.FrontDpPass.Convert();
pipeline.StencilFrontDepthFailOp = extendedDynamicState ? 0 : state.StencilTest.FrontDpFail.Convert(); pipeline.StencilFrontDepthFailOp = state.StencilTest.FrontDpFail.Convert();
pipeline.StencilFrontCompareOp = extendedDynamicState ? 0 : state.StencilTest.FrontFunc.Convert(); pipeline.StencilFrontCompareOp = state.StencilTest.FrontFunc.Convert();
pipeline.StencilBackFailOp = extendedDynamicState ? 0 : state.StencilTest.BackSFail.Convert(); pipeline.StencilBackFailOp = state.StencilTest.BackSFail.Convert();
pipeline.StencilBackPassOp = extendedDynamicState ? 0 : state.StencilTest.BackDpPass.Convert(); pipeline.StencilBackPassOp = state.StencilTest.BackDpPass.Convert();
pipeline.StencilBackDepthFailOp = extendedDynamicState ? 0 : state.StencilTest.BackDpFail.Convert(); pipeline.StencilBackDepthFailOp = state.StencilTest.BackDpFail.Convert();
pipeline.StencilBackCompareOp = extendedDynamicState ? 0 : state.StencilTest.BackFunc.Convert(); pipeline.StencilBackCompareOp = state.StencilTest.BackFunc.Convert();
}
pipeline.Topology = topology; if (!extendedDynamicState2.ExtendedDynamicState2)
{
pipeline.PrimitiveRestartEnable = state.PrimitiveRestartEnable;
pipeline.RasterizerDiscardEnable = state.RasterizerDiscard;
pipeline.DepthBiasEnable = ((state.BiasEnable != 0) &&
(state.DepthBiasFactor != 0 && state.DepthBiasUnits != 0));
}
if (!extendedDynamicState2.ExtendedDynamicState2PatchControlPoints)
{
pipeline.PatchControlPoints = state.PatchControlPoints;
}
pipeline.SamplesCount = (uint)state.SamplesCount;
pipeline.LogicOpEnable = state.LogicOpEnable; pipeline.LogicOpEnable = state.LogicOpEnable;
@ -337,17 +334,13 @@ namespace Ryujinx.Graphics.Vulkan
pipeline.Internal.AttachmentIntegerFormatMask = attachmentIntegerFormatMask; pipeline.Internal.AttachmentIntegerFormatMask = attachmentIntegerFormatMask;
pipeline.Internal.LogicOpsAllowed = attachmentCount == 0 || !allFormatsFloatOrSrgb; pipeline.Internal.LogicOpsAllowed = attachmentCount == 0 || !allFormatsFloatOrSrgb;
if (!extendedDynamicState2.ExtendedDynamicState2LogicOp)
{
bool logicOpEnable = state.LogicOpEnable && bool logicOpEnable = state.LogicOpEnable &&
(gd.Vendor == Vendor.Nvidia || pipeline.Internal.LogicOpsAllowed); (gd.Vendor == Vendor.Nvidia || pipeline.Internal.LogicOpsAllowed);
if (!extendedDynamicState2.ExtendedDynamicState2LogicOp)
{
pipeline.LogicOp = logicOpEnable ? state.LogicOp.Convert() : default; pipeline.LogicOp = logicOpEnable ? state.LogicOp.Convert() : default;
} }
else
{
pipeline.LogicOp = 0;
}
return pipeline; return pipeline;
} }

View file

@ -56,7 +56,7 @@ namespace Ryujinx.Graphics.Vulkan
private uint _patchControlPoints; private uint _patchControlPoints;
private PrimitiveTopology _topology; public PrimitiveTopology Topology;
private bool _primitiveRestartEnable; private bool _primitiveRestartEnable;
@ -122,7 +122,7 @@ namespace Ryujinx.Graphics.Vulkan
public void SetDepthTestBool(bool testEnable, bool writeEnable) public void SetDepthTestBool(bool testEnable, bool writeEnable)
{ {
DepthTestEnable = testEnable; DepthTestEnable = testEnable;
DepthWriteEnable = writeEnable && testEnable; DepthWriteEnable = writeEnable;
_dirty |= DirtyFlags.DepthTestBool; _dirty |= DirtyFlags.DepthTestBool;
} }
@ -228,7 +228,7 @@ namespace Ryujinx.Graphics.Vulkan
public void SetPrimitiveTopology(PrimitiveTopology primitiveTopology) public void SetPrimitiveTopology(PrimitiveTopology primitiveTopology)
{ {
_topology = primitiveTopology; Topology = primitiveTopology;
_dirty |= DirtyFlags.PrimitiveTopology; _dirty |= DirtyFlags.PrimitiveTopology;
} }
@ -478,15 +478,15 @@ namespace Ryujinx.Graphics.Vulkan
if (gd.Capabilities.SupportsPrimitiveTopologyListRestart) if (gd.Capabilities.SupportsPrimitiveTopologyListRestart)
{ {
topologySupportsRestart = gd.Capabilities.SupportsPrimitiveTopologyPatchListRestart || topologySupportsRestart = gd.Capabilities.SupportsPrimitiveTopologyPatchListRestart ||
_topology != PrimitiveTopology.PatchList; Topology != PrimitiveTopology.PatchList;
} }
else else
{ {
topologySupportsRestart = _topology == PrimitiveTopology.LineStrip || topologySupportsRestart = Topology == PrimitiveTopology.LineStrip ||
_topology == PrimitiveTopology.TriangleStrip || Topology == PrimitiveTopology.TriangleStrip ||
_topology == PrimitiveTopology.TriangleFan || Topology == PrimitiveTopology.TriangleFan ||
_topology == PrimitiveTopology.LineStripWithAdjacency || Topology == PrimitiveTopology.LineStripWithAdjacency ||
_topology == PrimitiveTopology.TriangleStripWithAdjacency; Topology == PrimitiveTopology.TriangleStripWithAdjacency;
} }
primitiveRestartEnable &= topologySupportsRestart; primitiveRestartEnable &= topologySupportsRestart;
@ -502,7 +502,7 @@ namespace Ryujinx.Graphics.Vulkan
private readonly void RecordPrimitiveTopology(VulkanRenderer gd, CommandBuffer commandBuffer) private readonly void RecordPrimitiveTopology(VulkanRenderer gd, CommandBuffer commandBuffer)
{ {
gd.ExtendedDynamicStateApi.CmdSetPrimitiveTopology(commandBuffer, _topology); gd.ExtendedDynamicStateApi.CmdSetPrimitiveTopology(commandBuffer, Topology);
} }
private readonly void RecordLogicOp(VulkanRenderer gd, CommandBuffer commandBuffer) private readonly void RecordLogicOp(VulkanRenderer gd, CommandBuffer commandBuffer)

View file

@ -258,7 +258,7 @@ namespace Ryujinx.Graphics.Vulkan
private bool _supportsFeedBackLoopDynamicState; private bool _supportsFeedBackLoopDynamicState;
public void Initialize(HardwareCapabilities capabilities, PrimitiveTopology topology = default) public void Initialize(HardwareCapabilities capabilities)
{ {
HasTessellationControlShader = false; HasTessellationControlShader = false;
Stages = new NativeArray<PipelineShaderStageCreateInfo>(Constants.MaxShaderStages); Stages = new NativeArray<PipelineShaderStageCreateInfo>(Constants.MaxShaderStages);
@ -267,7 +267,6 @@ namespace Ryujinx.Graphics.Vulkan
AdvancedBlendDstPreMultiplied = true; AdvancedBlendDstPreMultiplied = true;
AdvancedBlendOverlap = BlendOverlapEXT.UncorrelatedExt; AdvancedBlendOverlap = BlendOverlapEXT.UncorrelatedExt;
SamplesCount = 1;
DepthMode = true; DepthMode = true;
PolygonMode = PolygonMode.Fill; PolygonMode = PolygonMode.Fill;
@ -277,14 +276,8 @@ namespace Ryujinx.Graphics.Vulkan
_supportsExtDynamicState2 = capabilities.SupportsExtendedDynamicState2; _supportsExtDynamicState2 = capabilities.SupportsExtendedDynamicState2;
_supportsFeedBackLoopDynamicState = capabilities.SupportsDynamicAttachmentFeedbackLoop; _supportsFeedBackLoopDynamicState = capabilities.SupportsDynamicAttachmentFeedbackLoop;
if (!capabilities.SupportsAttachmentFeedbackLoop)
{
FeedbackLoopAspects = FeedbackLoopAspects.None;
}
if (_supportsExtDynamicState) if (_supportsExtDynamicState)
{ {
Topology = topology;
StencilFrontFailOp = 0; StencilFrontFailOp = 0;
StencilFrontPassOp = 0; StencilFrontPassOp = 0;
StencilFrontDepthFailOp = 0; StencilFrontDepthFailOp = 0;
@ -312,7 +305,6 @@ namespace Ryujinx.Graphics.Vulkan
PrimitiveRestartEnable = false; PrimitiveRestartEnable = false;
DepthBiasEnable = false; DepthBiasEnable = false;
RasterizerDiscardEnable = false; RasterizerDiscardEnable = false;
}
if (_supportsExtDynamicState2.ExtendedDynamicState2LogicOp) if (_supportsExtDynamicState2.ExtendedDynamicState2LogicOp)
{ {
@ -324,6 +316,7 @@ namespace Ryujinx.Graphics.Vulkan
PatchControlPoints = 0; PatchControlPoints = 0;
} }
} }
}
public unsafe Auto<DisposablePipeline> CreateComputePipeline( public unsafe Auto<DisposablePipeline> CreateComputePipeline(
VulkanRenderer gd, VulkanRenderer gd,
@ -531,8 +524,11 @@ namespace Ryujinx.Graphics.Vulkan
if (!gd.Capabilities.SupportsExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints) if (!gd.Capabilities.SupportsExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints)
{ {
tessellationState.SType = StructureType.PipelineTessellationStateCreateInfo; tessellationState = new PipelineTessellationStateCreateInfo
tessellationState.PatchControlPoints = PatchControlPoints; {
SType = StructureType.PipelineTessellationStateCreateInfo,
PatchControlPoints = PatchControlPoints,
};
} }
uint blendEnables = 0; uint blendEnables = 0;