Skip to content

Commit

Permalink
Finally got Metal working!!
Browse files Browse the repository at this point in the history
  • Loading branch information
MrScautHD committed Sep 22, 2024
1 parent 955c0be commit 10aee77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Bliss.Test/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Run() {
HasMainSwapchain = true,
SwapchainDepthFormat = null,
SyncToVerticalBlank = this.Settings.VSync,
ResourceBindingModel = ResourceBindingModel.Default,
ResourceBindingModel = ResourceBindingModel.Improved,
PreferDepthRangeZeroToOne = true,
PreferStandardClipSpaceYDirection = true,
SwapchainSrgbFormat = false
Expand Down
15 changes: 8 additions & 7 deletions src/Bliss/CSharp/Graphics/Pipelines/Buffers/SimpleBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Numerics;
using System.Runtime.InteropServices;
using Bliss.CSharp.Logging;
using Veldrid;

namespace Bliss.CSharp.Graphics.Pipelines.Buffers;
Expand Down Expand Up @@ -67,15 +67,16 @@ public SimpleBuffer(GraphicsDevice graphicsDevice, string name, uint size, Simpl
this.ShaderStages = stages;
this.Data = new T[size];

long dataSize = size * Marshal.SizeOf<T>();
long bufferSize = (dataSize / 16 + (dataSize % 16 > 0 ? 1 : 0)) * 16;

//uint alignment = graphicsDevice.UniformBufferMinOffsetAlignment; // More common requirement in Metal
//long dataSize = size * Marshal.SizeOf<T>();
//long bufferSize = (dataSize / 16 + (dataSize % 16 > 0 ? 1 : 0)) * 16;
//long bufferSize = (dataSize / alignment + (dataSize % alignment > 0 ? 1 : 0)) * alignment;

uint alignment = graphicsDevice.UniformBufferMinOffsetAlignment; // More common requirement in Metal
long dataSize = size * Marshal.SizeOf<T>();
long bufferSize = (dataSize / alignment + (dataSize % alignment > 0 ? 1 : 0)) * alignment;
Logger.Error(bufferSize + "");

this.DeviceBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription((uint) bufferSize, this.GetBufferUsage(bufferType)));
graphicsDevice.UpdateBuffer(this.DeviceBuffer, 0, ref this.Data[0], (uint) (this.Data.Length * Marshal.SizeOf<T>()));
this.DeviceBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription((uint) (bufferSize), this.GetBufferUsage(bufferType)));
this.DeviceBuffer.Name = name;

this.ResourceLayout = graphicsDevice.ResourceFactory.CreateResourceLayout(new ResourceLayoutDescription(new ResourceLayoutElementDescription(name, this.GetResourceKind(bufferType), stages)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void Begin(CommandList commandList, Matrix4x4? view = null, Matrix4x4? pr
//Matrix4x4 test = new Matrix4x4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
//UniformMatrix4 test2 = new UniformMatrix4(new Vector4(0.0125F, 0, 0, 0), new Vector4(0, 0.0222222F, 0,0) ,new Vector4(0,0, -0.01F, 0), new Vector4(0,0,0,1));

//this._projViewBuffer.SetValue(0, finalView * finalProj, true);
this._projViewBuffer.SetValue(0, finalView * finalProj, true);
this.DrawCallCount = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bliss/CSharp/Graphics/VertexTypes/PrimitiveVertex2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct PrimitiveVertex2D {
/// The color of the vertex.
/// </summary>
public Vector4 Color;

/// <summary>
/// Initializes a new instance of the <see cref="PrimitiveVertex2D"/> struct with the specified position and color values.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Bliss/content/shaders/primitive.vert
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ layout(set = 0, binding = 0) uniform ProjectionViewBuffer {
};

layout (location = 0) in vec2 vPosition;
layout (location = 1) in vec4 vColor;
layout (location = 1) in vec2 vPadding;
layout (location = 2) in vec4 vColor;

layout (location = 0) out vec4 fColor;

Expand Down

0 comments on commit 10aee77

Please sign in to comment.