Vulkan: Use dynamic state for blend constants (#3793)
This commit is contained in:
parent
f70236f947
commit
9719b6a112
4 changed files with 36 additions and 16 deletions
|
@ -535,10 +535,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
vkBlend = new PipelineColorBlendAttachmentState();
|
vkBlend = new PipelineColorBlendAttachmentState();
|
||||||
}
|
}
|
||||||
|
|
||||||
_newState.BlendConstantR = blend.BlendConstant.Red;
|
DynamicState.SetBlendConstants(
|
||||||
_newState.BlendConstantG = blend.BlendConstant.Green;
|
blend.BlendConstant.Red,
|
||||||
_newState.BlendConstantB = blend.BlendConstant.Blue;
|
blend.BlendConstant.Green,
|
||||||
_newState.BlendConstantA = blend.BlendConstant.Alpha;
|
blend.BlendConstant.Blue,
|
||||||
|
blend.BlendConstant.Alpha);
|
||||||
|
|
||||||
SignalStateChange();
|
SignalStateChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,11 +135,6 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
|
|
||||||
// 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.BlendConstantA = state.BlendDescriptors[0].BlendConstant.Alpha;
|
|
||||||
pipeline.BlendConstantB = state.BlendDescriptors[0].BlendConstant.Blue;
|
|
||||||
pipeline.BlendConstantG = state.BlendDescriptors[0].BlendConstant.Green;
|
|
||||||
pipeline.BlendConstantR = state.BlendDescriptors[0].BlendConstant.Red;
|
|
||||||
|
|
||||||
pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : CullModeFlags.CullModeNone;
|
pipeline.CullMode = state.CullEnable ? state.CullMode.Convert() : CullModeFlags.CullModeNone;
|
||||||
|
|
||||||
pipeline.DepthBoundsTestEnable = false; // Not implemented.
|
pipeline.DepthBoundsTestEnable = false; // Not implemented.
|
||||||
|
|
|
@ -19,21 +19,34 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
private uint _frontWriteMask;
|
private uint _frontWriteMask;
|
||||||
private uint _frontReference;
|
private uint _frontReference;
|
||||||
|
|
||||||
|
private Array4<float> _blendConstants;
|
||||||
|
|
||||||
public int ViewportsCount;
|
public int ViewportsCount;
|
||||||
public Array16<Viewport> Viewports;
|
public Array16<Viewport> Viewports;
|
||||||
|
|
||||||
private enum DirtyFlags
|
private enum DirtyFlags
|
||||||
{
|
{
|
||||||
None = 0,
|
None = 0,
|
||||||
DepthBias = 1 << 0,
|
Blend = 1 << 0,
|
||||||
Scissor = 1 << 1,
|
DepthBias = 1 << 1,
|
||||||
Stencil = 1 << 2,
|
Scissor = 1 << 2,
|
||||||
Viewport = 1 << 3,
|
Stencil = 1 << 3,
|
||||||
All = DepthBias | Scissor | Stencil | Viewport
|
Viewport = 1 << 4,
|
||||||
|
All = Blend | DepthBias | Scissor | Stencil | Viewport
|
||||||
}
|
}
|
||||||
|
|
||||||
private DirtyFlags _dirty;
|
private DirtyFlags _dirty;
|
||||||
|
|
||||||
|
public void SetBlendConstants(float r, float g, float b, float a)
|
||||||
|
{
|
||||||
|
_blendConstants[0] = r;
|
||||||
|
_blendConstants[1] = g;
|
||||||
|
_blendConstants[2] = b;
|
||||||
|
_blendConstants[3] = a;
|
||||||
|
|
||||||
|
_dirty |= DirtyFlags.Blend;
|
||||||
|
}
|
||||||
|
|
||||||
public void SetDepthBias(float slopeFactor, float constantFactor, float clamp)
|
public void SetDepthBias(float slopeFactor, float constantFactor, float clamp)
|
||||||
{
|
{
|
||||||
_depthBiasSlopeFactor = slopeFactor;
|
_depthBiasSlopeFactor = slopeFactor;
|
||||||
|
@ -87,6 +100,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
|
|
||||||
public void ReplayIfDirty(Vk api, CommandBuffer commandBuffer)
|
public void ReplayIfDirty(Vk api, CommandBuffer commandBuffer)
|
||||||
{
|
{
|
||||||
|
if (_dirty.HasFlag(DirtyFlags.Blend))
|
||||||
|
{
|
||||||
|
RecordBlend(api, commandBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
if (_dirty.HasFlag(DirtyFlags.DepthBias))
|
if (_dirty.HasFlag(DirtyFlags.DepthBias))
|
||||||
{
|
{
|
||||||
RecordDepthBias(api, commandBuffer);
|
RecordDepthBias(api, commandBuffer);
|
||||||
|
@ -110,6 +128,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
_dirty = DirtyFlags.None;
|
_dirty = DirtyFlags.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void RecordBlend(Vk api, CommandBuffer commandBuffer)
|
||||||
|
{
|
||||||
|
api.CmdSetBlendConstants(commandBuffer, _blendConstants.AsSpan());
|
||||||
|
}
|
||||||
|
|
||||||
private void RecordDepthBias(Vk api, CommandBuffer commandBuffer)
|
private void RecordDepthBias(Vk api, CommandBuffer commandBuffer)
|
||||||
{
|
{
|
||||||
api.CmdSetDepthBias(commandBuffer, _depthBiasConstantFactor, _depthBiasClamp, _depthBiasSlopeFactor);
|
api.CmdSetDepthBias(commandBuffer, _depthBiasConstantFactor, _depthBiasClamp, _depthBiasSlopeFactor);
|
||||||
|
|
|
@ -499,7 +499,7 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
colorBlendState.BlendConstants[3] = BlendConstantA;
|
colorBlendState.BlendConstants[3] = BlendConstantA;
|
||||||
|
|
||||||
bool supportsExtDynamicState = gd.Capabilities.SupportsExtendedDynamicState;
|
bool supportsExtDynamicState = gd.Capabilities.SupportsExtendedDynamicState;
|
||||||
int dynamicStatesCount = supportsExtDynamicState ? 8 : 7;
|
int dynamicStatesCount = supportsExtDynamicState ? 9 : 8;
|
||||||
|
|
||||||
DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount];
|
DynamicState* dynamicStates = stackalloc DynamicState[dynamicStatesCount];
|
||||||
|
|
||||||
|
@ -510,10 +510,11 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
dynamicStates[4] = DynamicState.StencilCompareMask;
|
dynamicStates[4] = DynamicState.StencilCompareMask;
|
||||||
dynamicStates[5] = DynamicState.StencilWriteMask;
|
dynamicStates[5] = DynamicState.StencilWriteMask;
|
||||||
dynamicStates[6] = DynamicState.StencilReference;
|
dynamicStates[6] = DynamicState.StencilReference;
|
||||||
|
dynamicStates[7] = DynamicState.BlendConstants;
|
||||||
|
|
||||||
if (supportsExtDynamicState)
|
if (supportsExtDynamicState)
|
||||||
{
|
{
|
||||||
dynamicStates[7] = DynamicState.VertexInputBindingStrideExt;
|
dynamicStates[8] = DynamicState.VertexInputBindingStrideExt;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pipelineDynamicStateCreateInfo = new PipelineDynamicStateCreateInfo()
|
var pipelineDynamicStateCreateInfo = new PipelineDynamicStateCreateInfo()
|
||||||
|
|
Loading…
Reference in a new issue