Use device features to enable to disable LogicOp Extended Dynamic State
Improve index counting
This commit is contained in:
parent
b5574ac65f
commit
d5f9ed6a2e
6 changed files with 173 additions and 102 deletions
|
@ -84,8 +84,8 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
private bool _tfEnabled;
|
||||
private bool _tfActive;
|
||||
|
||||
private bool _supportExtDynamic;
|
||||
private bool _supportExtDynamic2;
|
||||
private readonly bool _supportExtDynamic;
|
||||
private readonly bool _supportExtDynamic2;
|
||||
|
||||
private readonly PipelineColorBlendAttachmentState[] _storedBlend;
|
||||
|
||||
|
@ -986,8 +986,16 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
public void SetLogicOpState(bool enable, LogicalOp op)
|
||||
{
|
||||
_newState.LogicOpEnable = enable;
|
||||
if (_supportExtDynamic2 && Gd.ExtendedLogicOp)
|
||||
{
|
||||
DynamicState.SetLogicOp(op.Convert());
|
||||
}
|
||||
else
|
||||
{
|
||||
_newState.LogicOp = op.Convert();
|
||||
}
|
||||
|
||||
_newState.LogicOpEnable = enable;
|
||||
|
||||
SignalStateChange();
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
private bool _discard;
|
||||
|
||||
private LogicOp _logicOp;
|
||||
|
||||
[Flags]
|
||||
private enum DirtyFlags
|
||||
{
|
||||
|
@ -66,9 +68,10 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
StencilTestEnable = 1 << 9,
|
||||
LineWidth = 1 << 10,
|
||||
RasterDiscard = 1 << 11,
|
||||
LogicOp = 1 << 12,
|
||||
Standard = Blend | DepthBias | Scissor | Stencil | Viewport | LineWidth,
|
||||
Extended = CullMode | FrontFace | DepthTestBool | DepthTestCompareOp | StencilTestEnable,
|
||||
Extended2 = RasterDiscard,
|
||||
Extended2 = RasterDiscard | LogicOp,
|
||||
}
|
||||
|
||||
private DirtyFlags _dirty;
|
||||
|
@ -209,6 +212,13 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
_dirty |= DirtyFlags.RasterDiscard;
|
||||
}
|
||||
|
||||
public void SetLogicOp(LogicOp op)
|
||||
{
|
||||
_logicOp = op;
|
||||
|
||||
_dirty |= DirtyFlags.LogicOp;
|
||||
}
|
||||
|
||||
public void ForceAllDirty(VulkanRenderer gd)
|
||||
{
|
||||
_dirty = DirtyFlags.Standard;
|
||||
|
@ -227,6 +237,11 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
_dirty &= ~DirtyFlags.LineWidth;
|
||||
}
|
||||
|
||||
if (!gd.ExtendedLogicOp)
|
||||
{
|
||||
_dirty &= ~DirtyFlags.LogicOp;
|
||||
}
|
||||
}
|
||||
|
||||
public void ReplayIfDirty(VulkanRenderer gd, CommandBuffer commandBuffer)
|
||||
|
@ -291,6 +306,11 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
RecordRasterizationDiscard(gd, commandBuffer);
|
||||
}
|
||||
|
||||
if (_dirty.HasFlag(DirtyFlags.RasterDiscard))
|
||||
{
|
||||
RecordLogicOp(gd, commandBuffer);
|
||||
}
|
||||
|
||||
_dirty = DirtyFlags.None;
|
||||
}
|
||||
|
||||
|
@ -370,33 +390,38 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
}
|
||||
}
|
||||
|
||||
private void RecordCullMode(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
private readonly void RecordCullMode(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
{
|
||||
api.CmdSetCullMode(commandBuffer, CullMode);
|
||||
}
|
||||
|
||||
private void RecordFrontFace(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
private readonly void RecordFrontFace(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
{
|
||||
api.CmdSetFrontFace(commandBuffer, FrontFace);
|
||||
}
|
||||
|
||||
private void RecordDepthTestBool(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
private readonly void RecordDepthTestBool(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
{
|
||||
api.CmdSetDepthTestEnable(commandBuffer, _depthtestEnable);
|
||||
api.CmdSetDepthWriteEnable(commandBuffer, _depthwriteEnable);
|
||||
}
|
||||
|
||||
private void RecordDepthTestCompareOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
private readonly void RecordDepthTestCompareOp(ExtExtendedDynamicState api, CommandBuffer commandBuffer)
|
||||
{
|
||||
api.CmdSetDepthCompareOp(commandBuffer, _depthCompareOp);
|
||||
}
|
||||
|
||||
private void RecordRasterizationDiscard(VulkanRenderer gd, CommandBuffer commandBuffer)
|
||||
private readonly void RecordRasterizationDiscard(VulkanRenderer gd, CommandBuffer commandBuffer)
|
||||
{
|
||||
gd.ExtendedDynamicState2Api.CmdSetRasterizerDiscardEnable(commandBuffer, _discard);
|
||||
}
|
||||
|
||||
private void RecordLineWidth(Vk api, CommandBuffer commandBuffer)
|
||||
private readonly void RecordLogicOp(VulkanRenderer gd, CommandBuffer commandBuffer)
|
||||
{
|
||||
gd.ExtendedDynamicState2Api.CmdSetLogicOp(commandBuffer, _logicOp);
|
||||
}
|
||||
|
||||
private readonly void RecordLineWidth(Vk api, CommandBuffer commandBuffer)
|
||||
{
|
||||
if (!OperatingSystem.IsMacOS())
|
||||
{
|
||||
|
|
|
@ -588,11 +588,15 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
{
|
||||
SType = StructureType.PipelineColorBlendStateCreateInfo,
|
||||
LogicOpEnable = LogicOpEnable,
|
||||
LogicOp = LogicOp,
|
||||
AttachmentCount = ColorBlendAttachmentStateCount,
|
||||
PAttachments = pColorBlendAttachmentState,
|
||||
};
|
||||
|
||||
if (!(supportsExtDynamicState2 && gd.ExtendedLogicOp))
|
||||
{
|
||||
colorBlendState.LogicOp = LogicOp;
|
||||
}
|
||||
|
||||
PipelineColorBlendAdvancedStateCreateInfoEXT colorBlendAdvancedState;
|
||||
|
||||
if (!AdvancedBlendSrcPreMultiplied ||
|
||||
|
@ -610,8 +614,29 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
colorBlendState.PNext = &colorBlendAdvancedState;
|
||||
}
|
||||
|
||||
int dynamicStatesCount = supportsExtDynamicState ? (isMoltenVk ? 18 : 19) : (isMoltenVk ? 7 : 8);
|
||||
int baseDynamicStatesCount = 7;
|
||||
int additionalDynamicStatesCount = 0;
|
||||
|
||||
if (!isMoltenVk)
|
||||
{
|
||||
baseDynamicStatesCount++;
|
||||
}
|
||||
|
||||
if (supportsExtDynamicState)
|
||||
{
|
||||
additionalDynamicStatesCount += isMoltenVk ? 11 : 12;
|
||||
}
|
||||
|
||||
if (supportsExtDynamicState2)
|
||||
{
|
||||
additionalDynamicStatesCount += 2;
|
||||
if (gd.ExtendedLogicOp)
|
||||
{
|
||||
additionalDynamicStatesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
int dynamicStatesCount = baseDynamicStatesCount + additionalDynamicStatesCount;
|
||||
DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount];
|
||||
|
||||
dynamicStates[0] = DynamicState.Viewport;
|
||||
|
@ -622,32 +647,39 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
dynamicStates[5] = DynamicState.StencilReference;
|
||||
dynamicStates[6] = DynamicState.BlendConstants;
|
||||
|
||||
int currentIndex = 7;
|
||||
|
||||
if (!isMoltenVk)
|
||||
{
|
||||
dynamicStates[7] = DynamicState.LineWidth;
|
||||
dynamicStates[currentIndex++] = DynamicState.LineWidth;
|
||||
}
|
||||
|
||||
if (supportsExtDynamicState)
|
||||
{
|
||||
int index = (isMoltenVk ? 7 : 8);
|
||||
if (!isMoltenVk) {
|
||||
dynamicStates[index++] = DynamicState.VertexInputBindingStrideExt;
|
||||
if (!isMoltenVk)
|
||||
{
|
||||
dynamicStates[currentIndex++] = DynamicState.VertexInputBindingStrideExt;
|
||||
}
|
||||
dynamicStates[index++] = DynamicState.CullModeExt;
|
||||
dynamicStates[index++] = DynamicState.FrontFaceExt;
|
||||
dynamicStates[index++] = DynamicState.DepthTestEnableExt;
|
||||
dynamicStates[index++] = DynamicState.DepthWriteEnableExt;
|
||||
dynamicStates[index++] = DynamicState.DepthCompareOpExt;
|
||||
dynamicStates[index++] = DynamicState.StencilTestEnableExt;
|
||||
dynamicStates[index++] = DynamicState.ViewportWithCountExt;
|
||||
dynamicStates[index++] = DynamicState.ScissorWithCountExt;
|
||||
dynamicStates[index] = DynamicState.StencilOpExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.CullModeExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.FrontFaceExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.DepthTestEnableExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.DepthWriteEnableExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.DepthCompareOpExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.StencilTestEnableExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.ViewportWithCountExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.ScissorWithCountExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.StencilOpExt;
|
||||
}
|
||||
|
||||
if (supportsExtDynamicState2)
|
||||
{
|
||||
dynamicStates[16] = DynamicState.DepthBiasEnableExt;
|
||||
dynamicStates[17] = DynamicState.RasterizerDiscardEnableExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.DepthBiasEnableExt;
|
||||
dynamicStates[currentIndex++] = DynamicState.RasterizerDiscardEnableExt;
|
||||
|
||||
if (gd.ExtendedLogicOp)
|
||||
{
|
||||
dynamicStates[currentIndex++] = DynamicState.LogicOpExt;
|
||||
}
|
||||
}
|
||||
|
||||
var pipelineDynamicStateCreateInfo = new PipelineDynamicStateCreateInfo
|
||||
|
|
|
@ -263,7 +263,7 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
return InvalidIndex;
|
||||
}
|
||||
|
||||
internal static Device CreateDevice(Vk api, VulkanPhysicalDevice physicalDevice, uint queueFamilyIndex, uint queueCount)
|
||||
internal static Device CreateDevice(Vk api, VulkanPhysicalDevice physicalDevice, uint queueFamilyIndex, uint queueCount, out bool extendedLogicOp)
|
||||
{
|
||||
if (queueCount > QueuesCount)
|
||||
{
|
||||
|
@ -460,6 +460,8 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
ExtendedDynamicState2PatchControlPoints = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2PatchControlPoints,
|
||||
};
|
||||
|
||||
extendedLogicOp = supportedFeaturesExtExtendedDynamicState2.ExtendedDynamicState2LogicOp;
|
||||
|
||||
pExtendedFeatures = &featuresExtendedDynamicState2;
|
||||
|
||||
var featuresVk11 = new PhysicalDeviceVulkan11Features
|
||||
|
|
|
@ -99,6 +99,8 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
public bool PreferThreading => true;
|
||||
|
||||
public bool ExtendedLogicOp;
|
||||
|
||||
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
|
||||
|
||||
public VulkanRenderer(Vk api, Func<Instance, Vk, SurfaceKHR> surfaceFunc, Func<string[]> requiredExtensionsFunc, string preferredGpuId)
|
||||
|
@ -454,7 +456,9 @@ namespace Ryujinx.Graphics.Vulkan
|
|||
|
||||
var queueFamilyIndex = VulkanInitialization.FindSuitableQueueFamily(Api, _physicalDevice, _surface, out uint maxQueueCount);
|
||||
|
||||
_device = VulkanInitialization.CreateDevice(Api, _physicalDevice, queueFamilyIndex, maxQueueCount);
|
||||
_device = VulkanInitialization.CreateDevice(Api, _physicalDevice, queueFamilyIndex, maxQueueCount, out bool extendedLogicOp);
|
||||
|
||||
ExtendedLogicOp = extendedLogicOp;
|
||||
|
||||
if (Api.TryGetDeviceExtension(_instance.Instance, _device, out KhrSwapchain swapchainApi))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue