Skip to content

Commit

Permalink
Adds raw flag to instances of VertexBuffer and IndexBuffer flags to a…
Browse files Browse the repository at this point in the history
…llow binding to compute shaders.
  • Loading branch information
tebjan committed Jul 19, 2024
1 parent 9655f10 commit 665827a
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private object ExportModel(ICommandContext commandContext, ContentManager conten

var vbMap = new Dictionary<VertexBufferBinding, VertexBufferBinding>();
var sizeVertexBuffer = uniqueVB.Select(x => x.Buffer.GetSerializationData().Content.Length).Sum();
var vertexBuffer = new BufferData(BufferFlags.VertexBuffer, new byte[sizeVertexBuffer]);
var vertexBuffer = new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, new byte[sizeVertexBuffer]);
var vertexBufferSerializable = vertexBuffer.ToSerializableVersion();

var vertexBufferNextIndex = 0;
Expand Down Expand Up @@ -312,7 +312,7 @@ private object ExportModel(ICommandContext commandContext, ContentManager conten

if (uniqueIB.Count > 0)
{
var indexBuffer = new BufferData(BufferFlags.IndexBuffer, new byte[sizeIndexBuffer]);
var indexBuffer = new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, new byte[sizeIndexBuffer]);
var indexBufferSerializable = indexBuffer.ToSerializableVersion();
var indexBufferNextIndex = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ private static unsafe void ProcessMaterial(ContentManager manager, ICollection<E
MaterialIndex = matIndex
};

var vertexBuffer = new BufferData(BufferFlags.VertexBuffer, new byte[vertexArray.Length]);
var indexBuffer = new BufferData(BufferFlags.IndexBuffer, new byte[indexArray.Length]);
var vertexBuffer = new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, new byte[vertexArray.Length]);
var indexBuffer = new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, new byte[indexArray.Length]);

var vertexBufferSerializable = vertexBuffer.ToSerializableVersion();
var indexBufferSerializable = indexBuffer.ToSerializableVersion();
Expand Down
12 changes: 6 additions & 6 deletions sources/engine/Stride.Graphics/Buffer.Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static class Index
/// <returns>A index buffer</returns>
public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
{
return Buffer.New(device, size, BufferFlags.IndexBuffer, usage);
return Buffer.New(device, size, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage);
}

/// <summary>
Expand All @@ -53,7 +53,7 @@ public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage
/// <returns>A index buffer</returns>
public static Buffer<T> New<T>(GraphicsDevice device, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged
{
return Buffer.New<T>(device, 1, BufferFlags.IndexBuffer, usage);
return Buffer.New<T>(device, 1, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage);
}

/// <summary>
Expand All @@ -66,7 +66,7 @@ public static Buffer<T> New<T>(GraphicsDevice device, GraphicsResourceUsage usag
/// <returns>A index buffer</returns>
public static Buffer<T> New<T>(GraphicsDevice device, ref T value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
{
return Buffer.New(device, ref value, BufferFlags.IndexBuffer, usage);
return Buffer.New(device, ref value, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage);
}

/// <summary>
Expand All @@ -79,7 +79,7 @@ public static Buffer<T> New<T>(GraphicsDevice device, ref T value, GraphicsResou
/// <returns>A index buffer</returns>
public static Buffer<T> New<T>(GraphicsDevice device, T[] value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : unmanaged
{
return Buffer.New(device, value, BufferFlags.IndexBuffer, usage);
return Buffer.New(device, value, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage);
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public static Buffer<T> New<T>(GraphicsDevice device, T[] value, GraphicsResourc
/// <returns>A index buffer</returns>
public static Buffer New(GraphicsDevice device, byte[] value, bool is32BitIndex, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
{
return Buffer.New(device, value, is32BitIndex ? 4 : 2, BufferFlags.IndexBuffer, PixelFormat.None, usage);
return Buffer.New(device, value, is32BitIndex ? 4 : 2, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, PixelFormat.None, usage);
}

/// <summary>
Expand All @@ -104,7 +104,7 @@ public static Buffer New(GraphicsDevice device, byte[] value, bool is32BitIndex,
/// <returns>A index buffer</returns>
public static Buffer New(GraphicsDevice device, DataPointer value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
{
return Buffer.New(device, value, 0, BufferFlags.IndexBuffer, usage);
return Buffer.New(device, value, 0, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static unsafe void CompactHalf(ref VertexBufferBinding vertexBufferBindin
}
}

vertexBufferBinding = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer, newBufferData).ToSerializableVersion(), vertexDeclaration, vertexBufferBinding.Count);
vertexBufferBinding = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, newBufferData).ToSerializableVersion(), vertexDeclaration, vertexBufferBinding.Count);
}

private struct VertexElementConvertInfo
Expand Down
12 changes: 6 additions & 6 deletions sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static unsafe void RemoveIndexBuffer(this MeshDraw meshData)
}
}

meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer, newVertices).ToSerializableVersion(), vertexBuffer.Declaration, indexBuffer.Count);
meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, newVertices).ToSerializableVersion(), vertexBuffer.Declaration, indexBuffer.Count);
meshData.IndexBuffer = null;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ public static unsafe void GenerateIndexBuffer(this MeshDraw meshData, VertexDecl
Unsafe.CopyBlockUnaligned(vertexBufferDataCurrent, oldVertexBufferDataStart + oldVertexStride * vertices[i], (uint)newVertexStride);
vertexBufferDataCurrent += newVertexStride;
}
meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer, vertexBufferData).ToSerializableVersion(), declaration, indexMapping.Vertices.Length);
meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, vertexBufferData).ToSerializableVersion(), declaration, indexMapping.Vertices.Length);
}

// Generate index buffer
Expand All @@ -97,7 +97,7 @@ public static unsafe void GenerateIndexBuffer(this MeshDraw meshData, VertexDecl
fixed (byte* indexBufferDataStart = &indexBufferData[0])
{
Unsafe.CopyBlockUnaligned(indexBufferDataStart, indexDataStart, (uint)indexBufferData.Length);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer, indexBufferData).ToSerializableVersion(), true, indexMapping.Indices.Length);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indexBufferData).ToSerializableVersion(), true, indexMapping.Indices.Length);
}
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public static unsafe bool CompactIndexBuffer(this MeshDraw meshData)
*indexBufferDataPtr++ = (ushort)*oldIndexBufferDataPtr++;
}

meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer, indexBufferData).ToSerializableVersion(), false, indexCount);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indexBufferData).ToSerializableVersion(), false, indexCount);
}

return true;
Expand Down Expand Up @@ -289,7 +289,7 @@ public static unsafe void GenerateIndexBufferAEN(this MeshDraw meshData)
Unsafe.CopyBlockUnaligned(indexBufferDataStart, indexDataStart, (uint)indexBufferData.Length);
}

meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer, indexBufferData).ToSerializableVersion(), true, triangleCount * 12);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indexBufferData).ToSerializableVersion(), true, triangleCount * 12);
meshData.DrawCount = meshData.IndexBuffer.Count;
meshData.PrimitiveType = PrimitiveType.PatchList.ControlPointCount(12);
}
Expand Down Expand Up @@ -492,7 +492,7 @@ public static bool ReverseWindingOrder(this MeshDraw meshData)
if (!GetReversedWindingOrder(meshData, out newIndexBuffer))
return false;

meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer, newIndexBuffer).ToSerializableVersion(), meshData.IndexBuffer.Is32Bit, meshData.IndexBuffer.Count);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, newIndexBuffer).ToSerializableVersion(), meshData.IndexBuffer.Is32Bit, meshData.IndexBuffer.Count);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions sources/engine/Stride.Rendering/Extensions/MergeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static unsafe MeshDraw MergeDrawData(IList<MeshDraw> meshDrawDatas, bool
result.VertexBuffers = new VertexBufferBinding[]
{
new VertexBufferBinding(
new BufferData(BufferFlags.VertexBuffer, destBufferData).ToSerializableVersion(),
new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, destBufferData).ToSerializableVersion(),
firstVertexBuffer.Declaration,
totalVertexCount,
firstVertexBuffer.Stride),
Expand Down Expand Up @@ -104,7 +104,7 @@ public static unsafe MeshDraw MergeDrawData(IList<MeshDraw> meshDrawDatas, bool
// Allocate index buffer
destBufferData = new byte[(use32BitIndex ? sizeof(uint) : sizeof(ushort)) * totalIndexCount];
result.IndexBuffer = new IndexBufferBinding(
new BufferData(BufferFlags.IndexBuffer, destBufferData).ToSerializableVersion(),
new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, destBufferData).ToSerializableVersion(),
use32BitIndex,
totalIndexCount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static unsafe void SortMeshPolygons(this MeshDraw meshData, Vector3 viewD
newIndexBufferPointer += polyIndicesSize;
}
}
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer, newIndexBufferData).ToSerializableVersion(), oldIndexBuffer.Is32Bit, oldIndexBuffer.Count);
meshData.IndexBuffer = new IndexBufferBinding(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, newIndexBufferData).ToSerializableVersion(), oldIndexBuffer.Is32Bit, oldIndexBuffer.Count);
}
}
}
4 changes: 2 additions & 2 deletions sources/engine/Stride.Rendering/Extensions/SplitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static unsafe List<MeshDraw> SplitMesh(MeshDraw meshDrawData, bool can32b
}

newMeshDrawData.VertexBuffers[vbIndex] = new VertexBufferBinding(
new BufferData(BufferFlags.VertexBuffer, newVertexBuffer).ToSerializableVersion(),
new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, newVertexBuffer).ToSerializableVersion(),
meshDrawData.VertexBuffers[vbIndex].Declaration,
splitInfo.UsedIndices.Count);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ public static unsafe List<MeshDraw> SplitMesh(MeshDraw meshDrawData, bool can32b
}

newMeshDrawData.IndexBuffer = new IndexBufferBinding(
new BufferData(BufferFlags.IndexBuffer, newIndexBuffer).ToSerializableVersion(),
new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, newIndexBuffer).ToSerializableVersion(),
false,
triangleCount * 3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static unsafe void GenerateTangentBinormal(this MeshDraw meshData)
indexCountArg: indexBufferBinding?.Count ?? 0);

// Replace new vertex buffer binding
meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer, result.VertexBuffer).ToSerializableVersion(), result.Layout, oldVertexBufferBinding.Count);
meshData.VertexBuffers[0] = new VertexBufferBinding(new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, result.VertexBuffer).ToSerializableVersion(), result.Layout, oldVertexBufferBinding.Count);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void Generate(IServiceRegistry services, Model model)
meshDraw.IndexBuffer = new IndexBufferBinding(Buffer.Index.New(graphicsDevice, indicesShort).RecreateWith(indicesShort), false, indices.Length);
if (needsTempDevice)
{
var indexData = BufferData.New(BufferFlags.IndexBuffer, indicesShort);
var indexData = BufferData.New(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indicesShort);
meshDraw.IndexBuffer = new IndexBufferBinding(indexData.ToSerializableVersion(), false, indices.Length);
}
}
Expand All @@ -174,15 +174,15 @@ public void Generate(IServiceRegistry services, Model model)
meshDraw.IndexBuffer = new IndexBufferBinding(Buffer.Index.New(graphicsDevice, indices).RecreateWith(indices), true, indices.Length);
if (needsTempDevice)
{
var indexData = BufferData.New(BufferFlags.IndexBuffer, indices);
var indexData = BufferData.New(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indices);
meshDraw.IndexBuffer = new IndexBufferBinding(indexData.ToSerializableVersion(), true, indices.Length);
}
}

meshDraw.VertexBuffers = new[] { new VertexBufferBinding(Buffer.New(graphicsDevice, vertexBuffer, BufferFlags.VertexBuffer).RecreateWith(vertexBuffer), layout, data.Vertices.Length) };
meshDraw.VertexBuffers = new[] { new VertexBufferBinding(Buffer.New(graphicsDevice, vertexBuffer, BufferFlags.VertexBuffer | BufferFlags.RawBuffer).RecreateWith(vertexBuffer), layout, data.Vertices.Length) };
if (needsTempDevice)
{
var vertexData = BufferData.New(BufferFlags.VertexBuffer, vertexBuffer);
var vertexData = BufferData.New(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, vertexBuffer);
meshDraw.VertexBuffers = new[] { new VertexBufferBinding(vertexData.ToSerializableVersion(), layout, data.Vertices.Length) };
}

Expand Down
4 changes: 2 additions & 2 deletions sources/tools/Stride.Importer.3D/MeshConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,8 @@ private unsafe MeshInfo ProcessMesh(Scene* scene, Silk.NET.Assimp.Mesh* mesh, Di

// Build the mesh data
var vertexDeclaration = new VertexDeclaration(vertexElements.ToArray());
var vertexBufferBinding = new VertexBufferBinding(GraphicsSerializerExtensions.ToSerializableVersion(new BufferData(BufferFlags.VertexBuffer, vertexBuffer)), vertexDeclaration, (int)mesh->MNumVertices, vertexDeclaration.VertexStride, 0);
var indexBufferBinding = new IndexBufferBinding(GraphicsSerializerExtensions.ToSerializableVersion(new BufferData(BufferFlags.IndexBuffer, indexBuffer)), is32BitIndex, (int)nbIndices, 0);
var vertexBufferBinding = new VertexBufferBinding(GraphicsSerializerExtensions.ToSerializableVersion(new BufferData(BufferFlags.VertexBuffer | BufferFlags.RawBuffer, vertexBuffer)), vertexDeclaration, (int)mesh->MNumVertices, vertexDeclaration.VertexStride, 0);
var indexBufferBinding = new IndexBufferBinding(GraphicsSerializerExtensions.ToSerializableVersion(new BufferData(BufferFlags.IndexBuffer | BufferFlags.RawBuffer, indexBuffer)), is32BitIndex, (int)nbIndices, 0);


drawData.VertexBuffers = new VertexBufferBinding[] { vertexBufferBinding };
Expand Down

0 comments on commit 665827a

Please sign in to comment.