Skip to content

Commit

Permalink
Merge pull request #522 from smoogipoo/fix-d3d-vertex-strides
Browse files Browse the repository at this point in the history
Flush vertex bindings when vertex strides change
  • Loading branch information
peppy committed Feb 1, 2024
2 parents 8727cd2 + cda8a5f commit e72d4ae
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Veldrid/D3D11/D3D11CommandList.cs
Expand Up @@ -28,7 +28,7 @@ internal class D3D11CommandList : CommandList

private uint _numVertexBindings = 0;
private ID3D11Buffer[] _vertexBindings = new ID3D11Buffer[1];
private int[] _vertexStrides;
private int[] _vertexStrides = new int[1];
private int[] _vertexOffsets = new int[1];

// Cached pipeline State
Expand Down Expand Up @@ -122,7 +122,7 @@ private void ResetManagedState()
{
_numVertexBindings = 0;
Util.ClearArray(_vertexBindings);
_vertexStrides = null;
Util.ClearArray(_vertexStrides);
Util.ClearArray(_vertexOffsets);

_framebuffer = null;
Expand Down Expand Up @@ -311,14 +311,21 @@ private protected override void SetPipelineCore(Pipeline pipeline)
_context.PSSetShader(pixelShader);
}

_vertexStrides = d3dPipeline.VertexStrides;
if (_vertexStrides != null)
if (!Util.ArrayEqualsEquatable(_vertexStrides, d3dPipeline.VertexStrides))
{
int vertexStridesCount = _vertexStrides.Length;
Util.EnsureArrayMinimumSize(ref _vertexBindings, (uint)vertexStridesCount);
Util.EnsureArrayMinimumSize(ref _vertexOffsets, (uint)vertexStridesCount);
_vertexBindingsChanged = true;

if (d3dPipeline.VertexStrides != null)
{
Util.EnsureArrayMinimumSize(ref _vertexStrides, (uint)d3dPipeline.VertexStrides.Length);
d3dPipeline.VertexStrides.CopyTo(_vertexStrides, 0);
}
}

Util.EnsureArrayMinimumSize(ref _vertexStrides, 1);
Util.EnsureArrayMinimumSize(ref _vertexBindings, (uint)_vertexStrides.Length);
Util.EnsureArrayMinimumSize(ref _vertexOffsets, (uint)_vertexStrides.Length);

Util.EnsureArrayMinimumSize(ref _graphicsResourceSets, (uint)d3dPipeline.ResourceLayouts.Length);
Util.EnsureArrayMinimumSize(ref _invalidatedGraphicsResourceSets, (uint)d3dPipeline.ResourceLayouts.Length);
}
Expand Down

0 comments on commit e72d4ae

Please sign in to comment.