From 665827ab967d1ca1cf3ee58346fa89fa0d1a52be Mon Sep 17 00:00:00 2001 From: tebjan Date: Wed, 3 Jul 2024 15:09:35 +0200 Subject: [PATCH] Adds raw flag to instances of VertexBuffer and IndexBuffer flags to allow binding to compute shaders. --- .../Stride.Assets.Models/ImportModelCommand.Model.cs | 4 ++-- .../Stride.Assets.Models/PrefabModelAssetCompiler.cs | 4 ++-- sources/engine/Stride.Graphics/Buffer.Index.cs | 12 ++++++------ .../Extensions/HalfBufferExtensions.cs | 2 +- .../Stride.Rendering/Extensions/IndexExtensions.cs | 12 ++++++------ .../Stride.Rendering/Extensions/MergeExtensions.cs | 4 ++-- .../Extensions/PolySortExtensions.cs | 2 +- .../Stride.Rendering/Extensions/SplitExtensions.cs | 4 ++-- .../Stride.Rendering/Extensions/TNBExtensions.cs | 2 +- .../ProceduralModels/PrimitiveProceduralModelBase.cs | 8 ++++---- sources/tools/Stride.Importer.3D/MeshConverter.cs | 4 ++-- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/sources/engine/Stride.Assets.Models/ImportModelCommand.Model.cs b/sources/engine/Stride.Assets.Models/ImportModelCommand.Model.cs index c63f463e9e..4921367746 100644 --- a/sources/engine/Stride.Assets.Models/ImportModelCommand.Model.cs +++ b/sources/engine/Stride.Assets.Models/ImportModelCommand.Model.cs @@ -282,7 +282,7 @@ private object ExportModel(ICommandContext commandContext, ContentManager conten var vbMap = new Dictionary(); 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; @@ -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; diff --git a/sources/engine/Stride.Assets.Models/PrefabModelAssetCompiler.cs b/sources/engine/Stride.Assets.Models/PrefabModelAssetCompiler.cs index 05423d3d1e..4a7d0df7f6 100644 --- a/sources/engine/Stride.Assets.Models/PrefabModelAssetCompiler.cs +++ b/sources/engine/Stride.Assets.Models/PrefabModelAssetCompiler.cs @@ -263,8 +263,8 @@ private static unsafe void ProcessMaterial(ContentManager manager, ICollectionA index buffer 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); } /// @@ -53,7 +53,7 @@ public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage /// A index buffer public static Buffer New(GraphicsDevice device, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : unmanaged { - return Buffer.New(device, 1, BufferFlags.IndexBuffer, usage); + return Buffer.New(device, 1, BufferFlags.IndexBuffer | BufferFlags.RawBuffer, usage); } /// @@ -66,7 +66,7 @@ public static Buffer New(GraphicsDevice device, GraphicsResourceUsage usag /// A index buffer public static Buffer New(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); } /// @@ -79,7 +79,7 @@ public static Buffer New(GraphicsDevice device, ref T value, GraphicsResou /// A index buffer public static Buffer New(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); } /// @@ -92,7 +92,7 @@ public static Buffer New(GraphicsDevice device, T[] value, GraphicsResourc /// A index buffer 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); } /// @@ -104,7 +104,7 @@ public static Buffer New(GraphicsDevice device, byte[] value, bool is32BitIndex, /// A index buffer 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); } } } diff --git a/sources/engine/Stride.Rendering/Extensions/HalfBufferExtensions.cs b/sources/engine/Stride.Rendering/Extensions/HalfBufferExtensions.cs index 55553683f5..6a448efb61 100644 --- a/sources/engine/Stride.Rendering/Extensions/HalfBufferExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/HalfBufferExtensions.cs @@ -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 diff --git a/sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs b/sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs index 7dba87f285..f6d5578f9f 100644 --- a/sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/IndexExtensions.cs @@ -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; } @@ -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 @@ -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); } } @@ -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; @@ -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); } @@ -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; } diff --git a/sources/engine/Stride.Rendering/Extensions/MergeExtensions.cs b/sources/engine/Stride.Rendering/Extensions/MergeExtensions.cs index 9dbcf0cc5b..0dc4598b34 100644 --- a/sources/engine/Stride.Rendering/Extensions/MergeExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/MergeExtensions.cs @@ -76,7 +76,7 @@ public static unsafe MeshDraw MergeDrawData(IList 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), @@ -104,7 +104,7 @@ public static unsafe MeshDraw MergeDrawData(IList 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); diff --git a/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs b/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs index 1610284892..bc4642e0d2 100644 --- a/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/PolySortExtensions.cs @@ -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); } } } diff --git a/sources/engine/Stride.Rendering/Extensions/SplitExtensions.cs b/sources/engine/Stride.Rendering/Extensions/SplitExtensions.cs index 33c4eeae9a..e9113cd1a3 100644 --- a/sources/engine/Stride.Rendering/Extensions/SplitExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/SplitExtensions.cs @@ -131,7 +131,7 @@ public static unsafe List 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); } @@ -159,7 +159,7 @@ public static unsafe List 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); diff --git a/sources/engine/Stride.Rendering/Extensions/TNBExtensions.cs b/sources/engine/Stride.Rendering/Extensions/TNBExtensions.cs index ffb1c4b7ef..a4ed61e4ac 100644 --- a/sources/engine/Stride.Rendering/Extensions/TNBExtensions.cs +++ b/sources/engine/Stride.Rendering/Extensions/TNBExtensions.cs @@ -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); } } } diff --git a/sources/engine/Stride.Rendering/Rendering/ProceduralModels/PrimitiveProceduralModelBase.cs b/sources/engine/Stride.Rendering/Rendering/ProceduralModels/PrimitiveProceduralModelBase.cs index 6fcc88cb6c..2589b37b24 100644 --- a/sources/engine/Stride.Rendering/Rendering/ProceduralModels/PrimitiveProceduralModelBase.cs +++ b/sources/engine/Stride.Rendering/Rendering/ProceduralModels/PrimitiveProceduralModelBase.cs @@ -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); } } @@ -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) }; } diff --git a/sources/tools/Stride.Importer.3D/MeshConverter.cs b/sources/tools/Stride.Importer.3D/MeshConverter.cs index 9d9ebc5bfa..8d816841d9 100644 --- a/sources/tools/Stride.Importer.3D/MeshConverter.cs +++ b/sources/tools/Stride.Importer.3D/MeshConverter.cs @@ -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 };