1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-29 11:06:00 +00:00

Use Viewport and Scissor with count.

Topology Dynamic State is not working as intended. Need to add check to set correct Topology class. Circle back to this later. For now revert it.

Some minor fixes.
This commit is contained in:
sunshineinabox 2024-05-16 22:18:47 -07:00
parent 247adc0318
commit 8ca3b5a880
4 changed files with 73 additions and 73 deletions

View file

@ -693,9 +693,9 @@ 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 = _supportExtDynamic ? DynamicState. Topology : _newState.Topology; var oldTopology = _newState.Topology;
var oldViewports = DynamicState.Viewports; var oldViewports = DynamicState.Viewports;
var oldViewportsCount = _newState.ViewportsCount; var oldViewportsCount = _supportExtDynamic ? DynamicState.ViewportsCount : _newState.ViewportsCount;
if (_supportExtDynamic) if (_supportExtDynamic)
{ {
@ -726,7 +726,6 @@ namespace Ryujinx.Graphics.Vulkan
DynamicState.SetCullMode(oldCullMode); DynamicState.SetCullMode(oldCullMode);
DynamicState.SetStencilTest(oldStencilTestEnable); DynamicState.SetStencilTest(oldStencilTestEnable);
DynamicState.SetDepthTestBool(oldDepthTestEnable, oldDepthWriteEnable); DynamicState.SetDepthTestBool(oldDepthTestEnable, oldDepthWriteEnable);
DynamicState.SetPrimitiveTopology(oldTopology);
} }
else else
{ {
@ -734,12 +733,13 @@ namespace Ryujinx.Graphics.Vulkan
_newState.StencilTestEnable = oldStencilTestEnable; _newState.StencilTestEnable = oldStencilTestEnable;
_newState.DepthTestEnable = oldDepthTestEnable; _newState.DepthTestEnable = oldDepthTestEnable;
_newState.DepthWriteEnable = oldDepthWriteEnable; _newState.DepthWriteEnable = oldDepthWriteEnable;
_newState.Topology = oldTopology; _newState.ViewportsCount = oldViewportsCount;
} }
_newState.Topology = oldTopology;
DynamicState.SetViewports(ref oldViewports, oldViewportsCount); DynamicState.SetViewports(ref oldViewports, oldViewportsCount);
_newState.ViewportsCount = oldViewportsCount;
SignalStateChange(); SignalStateChange();
} }
} }
@ -1022,14 +1022,8 @@ namespace Ryujinx.Graphics.Vulkan
_topology = topology; _topology = topology;
var vkTopology = Gd.TopologyRemap(topology).Convert(); var vkTopology = Gd.TopologyRemap(topology).Convert();
if (_supportExtDynamic)
{ _newState.Topology = vkTopology;
DynamicState.SetPrimitiveTopology(vkTopology);
}
else
{
_newState.Topology = vkTopology;
}
SignalStateChange(); SignalStateChange();
} }
@ -1438,7 +1432,10 @@ namespace Ryujinx.Graphics.Vulkan
Clamp(viewport.DepthFar))); Clamp(viewport.DepthFar)));
} }
_newState.ViewportsCount = (uint)count; if (!_supportExtDynamic)
{
_newState.ViewportsCount = (uint)count;
}
SignalStateChange(); SignalStateChange();
} }

View file

@ -39,8 +39,6 @@ namespace Ryujinx.Graphics.Vulkan
public bool _depthwriteEnable; public bool _depthwriteEnable;
private CompareOp _depthCompareOp; private CompareOp _depthCompareOp;
public PrimitiveTopology Topology;
private Array4<float> _blendConstants; private Array4<float> _blendConstants;
public uint ViewportsCount; public uint ViewportsCount;
@ -63,10 +61,9 @@ namespace Ryujinx.Graphics.Vulkan
DepthTestBool = 1 << 7, DepthTestBool = 1 << 7,
DepthTestCompareOp = 1 << 8, DepthTestCompareOp = 1 << 8,
StencilTestEnable = 1 << 9, StencilTestEnable = 1 << 9,
Toplogy = 1 << 10, LineWidth = 1 << 10,
LineWidth = 1 << 11,
Standard = Blend | DepthBias | Scissor | Stencil | Viewport | LineWidth, Standard = Blend | DepthBias | Scissor | Stencil | Viewport | LineWidth,
Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnable | Toplogy, Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnable,
} }
private DirtyFlags _dirty; private DirtyFlags _dirty;
@ -112,13 +109,6 @@ namespace Ryujinx.Graphics.Vulkan
_dirty |= DirtyFlags.DepthTestCompareOp; _dirty |= DirtyFlags.DepthTestCompareOp;
} }
public void SetPrimitiveTopology(PrimitiveTopology topology)
{
Topology = topology;
_dirty |= DirtyFlags.Toplogy;
}
public void SetStencilOp(StencilOp backFailOp, public void SetStencilOp(StencilOp backFailOp,
StencilOp backPassOp, StencilOp backPassOp,
StencilOp backDepthFailOp, StencilOp backDepthFailOp,
@ -235,17 +225,17 @@ namespace Ryujinx.Graphics.Vulkan
if (_dirty.HasFlag(DirtyFlags.Scissor)) if (_dirty.HasFlag(DirtyFlags.Scissor))
{ {
RecordScissor(gd.Api, commandBuffer); RecordScissor(gd, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.Stencil)) if (_dirty.HasFlag(DirtyFlags.Stencil))
{ {
RecordStencil(gd.Api, commandBuffer); RecordStencil(gd, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.Viewport)) if (_dirty.HasFlag(DirtyFlags.Viewport))
{ {
RecordViewport(gd.Api, commandBuffer); RecordViewport(gd, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.CullMode)) if (_dirty.HasFlag(DirtyFlags.CullMode))
@ -273,11 +263,6 @@ namespace Ryujinx.Graphics.Vulkan
RecordStencilTestEnable(gd.ExtendedDynamicStateApi, commandBuffer); RecordStencilTestEnable(gd.ExtendedDynamicStateApi, commandBuffer);
} }
if (_dirty.HasFlag(DirtyFlags.Toplogy))
{
RecordPrimitiveTopology(gd.ExtendedDynamicStateApi, commandBuffer);
}
if (_dirty.HasFlag(DirtyFlags.LineWidth)) if (_dirty.HasFlag(DirtyFlags.LineWidth))
{ {
RecordLineWidth(gd.Api, commandBuffer); RecordLineWidth(gd.Api, commandBuffer);
@ -296,30 +281,40 @@ namespace Ryujinx.Graphics.Vulkan
api.CmdSetDepthBias(commandBuffer, _depthBiasConstantFactor, _depthBiasClamp, _depthBiasSlopeFactor); api.CmdSetDepthBias(commandBuffer, _depthBiasConstantFactor, _depthBiasClamp, _depthBiasSlopeFactor);
} }
private void RecordScissor(Vk api, CommandBuffer commandBuffer) private void RecordScissor(VulkanRenderer gd, CommandBuffer commandBuffer)
{ {
if (ScissorsCount != 0) if (ScissorsCount != 0)
{ {
api.CmdSetScissor(commandBuffer, 0, (uint)ScissorsCount, _scissors.AsSpan()); if (gd.Capabilities.SupportsExtendedDynamicState)
{
gd.ExtendedDynamicStateApi.CmdSetScissorWithCount(commandBuffer, (uint)ScissorsCount,
_scissors.AsSpan());
}
else
{
gd.Api.CmdSetScissor(commandBuffer, 0, (uint)ScissorsCount,
_scissors.AsSpan());
}
} }
} }
private readonly void RecordStencil(Vk api, CommandBuffer commandBuffer) private readonly void RecordStencil(VulkanRenderer gd, CommandBuffer commandBuffer)
{ {
if (_opToo) if (_opToo)
{ {
api.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceBackBit, _backfailop, _backpassop, gd.ExtendedDynamicStateApi.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceBackBit, _backfailop, _backpassop,
_backdepthfailop, _backcompareop); _backdepthfailop, _backcompareop);
api.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontfailop, _frontpassop, gd.ExtendedDynamicStateApi.CmdSetStencilOp(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontfailop, _frontpassop,
_frontdepthfailop, _frontcompareop); _frontdepthfailop, _frontcompareop);
} }
api.CmdSetStencilCompareMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backCompareMask); gd.Api.CmdSetStencilCompareMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backCompareMask);
api.CmdSetStencilWriteMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backWriteMask); gd.Api.CmdSetStencilWriteMask(commandBuffer, StencilFaceFlags.FaceBackBit, _backWriteMask);
api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceBackBit, _backReference); gd.Api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceBackBit, _backReference);
api.CmdSetStencilCompareMask(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontCompareMask); gd.Api.CmdSetStencilCompareMask(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontCompareMask);
api.CmdSetStencilWriteMask(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontWriteMask); gd.Api.CmdSetStencilWriteMask(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontWriteMask);
api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontReference); gd.Api.CmdSetStencilReference(commandBuffer, StencilFaceFlags.FaceFrontBit, _frontReference);
} }
private readonly void RecordStencilTestEnable(ExtExtendedDynamicState api, CommandBuffer commandBuffer) private readonly void RecordStencilTestEnable(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
@ -327,11 +322,23 @@ namespace Ryujinx.Graphics.Vulkan
api.CmdSetStencilTestEnable(commandBuffer, _stencilTestEnable); api.CmdSetStencilTestEnable(commandBuffer, _stencilTestEnable);
} }
private void RecordViewport(Vk api, CommandBuffer commandBuffer) private void RecordViewport(VulkanRenderer gd, CommandBuffer commandBuffer)
{ {
if (ViewportsCount != 0) if (ViewportsCount == 0)
{ {
api.CmdSetViewport(commandBuffer, 0, ViewportsCount, Viewports.AsSpan()); return;
}
if (gd.Capabilities.SupportsExtendedDynamicState)
{
gd.ExtendedDynamicStateApi.CmdSetViewportWithCount(commandBuffer, ViewportsCount,
Viewports.AsSpan());
}
else
{
gd.Api.CmdSetViewport(commandBuffer, 0, ViewportsCount,
Viewports.AsSpan());
} }
} }
@ -356,11 +363,6 @@ namespace Ryujinx.Graphics.Vulkan
api.CmdSetDepthCompareOp(commandBuffer, _depthCompareOp); api.CmdSetDepthCompareOp(commandBuffer, _depthCompareOp);
} }
private void RecordPrimitiveTopology(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
{
api.CmdSetPrimitiveTopology(commandBuffer, Topology);
}
private void RecordLineWidth(Vk api, CommandBuffer commandBuffer) private void RecordLineWidth(Vk api, CommandBuffer commandBuffer)
{ {
if (!OperatingSystem.IsMacOS()) if (!OperatingSystem.IsMacOS())

View file

@ -460,13 +460,9 @@ namespace Ryujinx.Graphics.Vulkan
{ {
SType = StructureType.PipelineInputAssemblyStateCreateInfo, SType = StructureType.PipelineInputAssemblyStateCreateInfo,
PrimitiveRestartEnable = primitiveRestartEnable, PrimitiveRestartEnable = primitiveRestartEnable,
Topology = Topology,
}; };
if (!supportsExtDynamicState)
{
inputAssemblyState.Topology = Topology;
}
var tessellationState = new PipelineTessellationStateCreateInfo var tessellationState = new PipelineTessellationStateCreateInfo
{ {
SType = StructureType.PipelineTessellationStateCreateInfo, SType = StructureType.PipelineTessellationStateCreateInfo,
@ -496,10 +492,14 @@ namespace Ryujinx.Graphics.Vulkan
var viewportState = new PipelineViewportStateCreateInfo var viewportState = new PipelineViewportStateCreateInfo
{ {
SType = StructureType.PipelineViewportStateCreateInfo, SType = StructureType.PipelineViewportStateCreateInfo,
ViewportCount = ViewportsCount,
ScissorCount = ScissorsCount,
}; };
if (!supportsExtDynamicState)
{
viewportState.ViewportCount = ViewportsCount;
viewportState.ScissorCount = ScissorsCount;
}
if (gd.Capabilities.SupportsDepthClipControl) if (gd.Capabilities.SupportsDepthClipControl)
{ {
var viewportDepthClipControlState = new PipelineViewportDepthClipControlCreateInfoEXT var viewportDepthClipControlState = new PipelineViewportDepthClipControlCreateInfoEXT
@ -604,7 +604,7 @@ namespace Ryujinx.Graphics.Vulkan
colorBlendState.PNext = &colorBlendAdvancedState; colorBlendState.PNext = &colorBlendAdvancedState;
} }
int dynamicStatesCount = supportsExtDynamicState ? (isMoltenVk ? 16 : 17) : (isMoltenVk ? 7 : 8); int dynamicStatesCount = supportsExtDynamicState ? (isMoltenVk ? 17 : 18) : (isMoltenVk ? 7 : 8);
DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount]; DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount];
@ -623,7 +623,7 @@ namespace Ryujinx.Graphics.Vulkan
if (supportsExtDynamicState) if (supportsExtDynamicState)
{ {
int index = 8; int index = (isMoltenVk ? 7 : 8);
if (!isMoltenVk) { if (!isMoltenVk) {
dynamicStates[index++] = DynamicState.VertexInputBindingStrideExt; dynamicStates[index++] = DynamicState.VertexInputBindingStrideExt;
} }
@ -633,7 +633,8 @@ namespace Ryujinx.Graphics.Vulkan
dynamicStates[index++] = DynamicState.DepthWriteEnableExt; dynamicStates[index++] = DynamicState.DepthWriteEnableExt;
dynamicStates[index++] = DynamicState.DepthCompareOpExt; dynamicStates[index++] = DynamicState.DepthCompareOpExt;
dynamicStates[index++] = DynamicState.StencilTestEnableExt; dynamicStates[index++] = DynamicState.StencilTestEnableExt;
dynamicStates[index++] = DynamicState.PrimitiveTopologyExt; dynamicStates[index++] = DynamicState.ViewportWithCountExt;
dynamicStates[index++] = DynamicState.ScissorWithCountExt;
dynamicStates[index] = DynamicState.StencilOpExt; dynamicStates[index] = DynamicState.StencilOpExt;
} }

View file

@ -22,12 +22,12 @@ namespace Ryujinx.Ava.UI.Helpers
{ {
return level switch return level switch
{ {
AvaLogLevel.Verbose => RyuLogger.Debug, AvaLogLevel.Verbose => RyuLogger.Trace,
AvaLogLevel.Debug => RyuLogger.Debug, AvaLogLevel.Debug => RyuLogger.Trace,
AvaLogLevel.Information => RyuLogger.Debug, AvaLogLevel.Information => RyuLogger.Trace,
AvaLogLevel.Warning => RyuLogger.Debug, AvaLogLevel.Warning => RyuLogger.Trace,
AvaLogLevel.Error => RyuLogger.Error, AvaLogLevel.Error => RyuLogger.Trace,
AvaLogLevel.Fatal => RyuLogger.Error, AvaLogLevel.Fatal => RyuLogger.Trace,
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null), _ => throw new ArgumentOutOfRangeException(nameof(level), level, null),
}; };
} }