Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions sources/engine/Stride.Graphics/IndirectDrawingArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Stride contributors (https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using Stride.Core.Serialization;
using Stride.Core.Serialization.Serializers;

namespace Stride.Graphics
{
public class IndirectDrawingArgs
{
/// <summary>
/// Creates an instance of <see cref="IndirectDrawingArgs"/> for DrawAuto with a stream-out vertex buffer.
/// </summary>
public IndirectDrawingArgs()
{
DrawAuto = true;
}

/// <summary>
/// Creates an instance of <see cref="IndirectDrawingArgs"/> for DrawIndirect with a buffer containing the draw arguments.
/// </summary>
public IndirectDrawingArgs(Buffer argumentBuffer, int alignedByteOffset = 0)
{
if (argumentBuffer == null) throw new ArgumentNullException("argmentBuffer");
ArgumentBuffer = argumentBuffer;
AlignedByteOffset = alignedByteOffset;
}

public readonly bool DrawAuto;
public readonly Buffer ArgumentBuffer;
public readonly int AlignedByteOffset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ public override void PrepareEffectPermutations(RenderDrawContext context)
var oldMeshDraw = renderMesh.ActiveMeshDraw;
tessellationMeshDraw = new MeshDraw
{
VertexBuffers = oldMeshDraw.VertexBuffers,
IndexBuffer = oldMeshDraw.IndexBuffer,
PrimitiveType = tessellationState.Method.GetPrimitiveType(),
DrawCount = oldMeshDraw.DrawCount,
StartLocation = oldMeshDraw.StartLocation,
PrimitiveType = tessellationState.Method.GetPrimitiveType(),
VertexBuffers = oldMeshDraw.VertexBuffers,
IndexBuffer = oldMeshDraw.IndexBuffer,
IndirectDrawing = oldMeshDraw.IndirectDrawing,
};

// adapt the primitive type and index buffer to the tessellation used
Expand Down
3 changes: 3 additions & 0 deletions sources/engine/Stride.Rendering/Rendering/MeshDraw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ public class MeshDraw
public VertexBufferBinding[] VertexBuffers;

public IndexBufferBinding IndexBuffer;

[DataMemberIgnore]
public IndirectDrawingArgs IndirectDrawing;
}
}
46 changes: 37 additions & 9 deletions sources/engine/Stride.Rendering/Rendering/MeshRenderFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,47 @@ public override void Draw(RenderDrawContext context, RenderView renderView, Rend
commandList.SetDescriptorSets(0, descriptorSetsLocal);

// Draw
if (drawData.IndexBuffer == null)
if (drawData.IndexBuffer is null)
{
if (renderMesh.InstanceCount > 0)
commandList.DrawInstanced(drawData.DrawCount, renderMesh.InstanceCount, drawData.StartLocation);
else
commandList.Draw(drawData.DrawCount, drawData.StartLocation);
if (drawData.IndirectDrawing is null) //direct drawing
{
if (renderMesh.InstanceCount > 0)
commandList.DrawInstanced(drawData.DrawCount, renderMesh.InstanceCount, drawData.StartLocation);
else
commandList.Draw(drawData.DrawCount, drawData.StartLocation);
}
else // indirect drawing
{
if (drawData.IndirectDrawing.DrawAuto)
{
commandList.DrawAuto();
}
else
{
commandList.DrawInstanced(drawData.IndirectDrawing.ArgumentBuffer, drawData.IndirectDrawing.AlignedByteOffset);
}
}
}
else
{
if (renderMesh.InstanceCount > 0)
commandList.DrawIndexedInstanced(drawData.DrawCount, renderMesh.InstanceCount, drawData.StartLocation);
else
commandList.DrawIndexed(drawData.DrawCount, drawData.StartLocation);
if (drawData.IndirectDrawing is null) //direct drawing
{
if (renderMesh.InstanceCount > 0)
commandList.DrawIndexedInstanced(drawData.DrawCount, renderMesh.InstanceCount, drawData.StartLocation);
else
commandList.DrawIndexed(drawData.DrawCount, drawData.StartLocation);
}
else // indirect drawing
{
if (drawData.IndirectDrawing.DrawAuto)
{
// throw exception? DrawAuto should not have an index buffer, as it always comes from the stream out stage
}
else
{
commandList.DrawIndexedInstanced(drawData.IndirectDrawing.ArgumentBuffer, drawData.IndirectDrawing.AlignedByteOffset);
}
}
}
}
}
Expand Down