Skip to content
Permalink
Browse files

[Graphics] D3D11: Begin/End were not reentrant because of how Query w…

…ere used (#427 #428)
  • Loading branch information
xen2 committed Apr 9, 2019
1 parent 0029ebe commit f60d8bba0c38704361699fd735beb4205230e160
Showing with 8 additions and 3 deletions.
  1. +8 −3 sources/engine/Xenko.Graphics/Direct3D/GraphicsDevice.Direct3D.cs
@@ -20,8 +20,8 @@ public partial class GraphicsDevice

private Device nativeDevice;
private DeviceContext nativeDeviceContext;
private readonly Queue<Query> disjointQueries = new Queue<Query>();
private Query currentDisjointQuery;
private readonly Queue<Query> disjointQueries = new Queue<Query>(4);
private readonly Stack<Query> currentDisjointQueries = new Stack<Query>(2);

internal GraphicsProfile RequestedProfile;

@@ -113,6 +113,8 @@ public void Begin()
FrameTriangleCount = 0;
FrameDrawCalls = 0;

Query currentDisjointQuery;

// Try to read back the oldest disjoint query and reuse it. If not ready, create a new one.
if (disjointQueries.Count > 0 && NativeDeviceContext.GetData(disjointQueries.Peek(), out QueryDataTimestampDisjoint result))
{
@@ -125,7 +127,7 @@ public void Begin()
currentDisjointQuery = new Query(NativeDevice, disjointQueryDiscription);
}

disjointQueries.Enqueue(currentDisjointQuery);
currentDisjointQueries.Push(currentDisjointQuery);
NativeDeviceContext.Begin(currentDisjointQuery);
}

@@ -142,7 +144,10 @@ public void EnableProfile(bool enabledFlag)
/// </summary>
public void End()
{
// If this fails, it means Begin()/End() don't match, something is very wrong
var currentDisjointQuery = currentDisjointQueries.Pop();
NativeDeviceContext.End(currentDisjointQuery);
disjointQueries.Enqueue(currentDisjointQuery);
}

/// <summary>

0 comments on commit f60d8bb

Please sign in to comment.
You can’t perform that action at this time.