veldrid-cursed

veldrid-cursed
120 Replies
Lyris the Kitori
Lyris the Kitori•3y ago
veldrid-cursed in this specific use case im only going to be mapping vertex and index buffers, so its just a sanity check @techpizza veldrid-cursed
TechPizza
TechPizza•3y ago
cursed-veldrid
Lyris the Kitori
Lyris the Kitori•3y ago
i can assume the buffer i allocate is continuous right?
Lyris the Kitori
Lyris the Kitori•3y ago
like i dont have to worry about pitch and other stuff? https://i.beyleyisnot.moe/JfnxIzw.png
TechPizza
TechPizza•3y ago
vertex and index buffers are onedimensional yes
Lyris the Kitori
Lyris the Kitori•3y ago
cool thx easiest class of my life
using System.Diagnostics;
using Furball.Vixie.Backends.Shared.Renderers;
using Veldrid;

namespace Furball.Vixie.Backends.Veldrid;

public class VeldridBufferMapper : BufferMapper {
private readonly VeldridBackend _backend;
private DeviceBuffer _buffer;

public unsafe void* Ptr;

public VeldridBufferMapper(VeldridBackend backend, uint byteSize, BufferUsage usage) {
this._backend = backend;

Debug.Assert((usage & ~(BufferUsage.IndexBuffer | BufferUsage.VertexBuffer)) == 0, "(usage & ~(BufferUsage.IndexBuffer | BufferUsage.VertexBuffer)) == 0");

BufferDescription desc = new(byteSize, BufferUsage.Dynamic | usage);
this._buffer = this._backend.ResourceFactory.CreateBuffer(ref desc);

this.SizeInBytes = byteSize;
}

public override unsafe void Map() {
MappedResource map = this._backend.GraphicsDevice.Map(this._buffer, MapMode.Write);

this.Ptr = (void*)map.Data;
}

public override void Unmap() {
this._backend.GraphicsDevice.Unmap(this._buffer);
}

public override unsafe void* Reserve(nuint byteCount) {
nuint ptr = (nuint)this.Ptr + this.ReservedBytes;

//If this reserve will push us over the limit, return nullptr
if (this.ReservedBytes + byteCount > this.SizeInBytes)
return null;

this.ReservedBytes += byteCount;

return (void*)ptr;
}

protected override void DisposeInternal() {
this._buffer.Dispose();
}
}
using System.Diagnostics;
using Furball.Vixie.Backends.Shared.Renderers;
using Veldrid;

namespace Furball.Vixie.Backends.Veldrid;

public class VeldridBufferMapper : BufferMapper {
private readonly VeldridBackend _backend;
private DeviceBuffer _buffer;

public unsafe void* Ptr;

public VeldridBufferMapper(VeldridBackend backend, uint byteSize, BufferUsage usage) {
this._backend = backend;

Debug.Assert((usage & ~(BufferUsage.IndexBuffer | BufferUsage.VertexBuffer)) == 0, "(usage & ~(BufferUsage.IndexBuffer | BufferUsage.VertexBuffer)) == 0");

BufferDescription desc = new(byteSize, BufferUsage.Dynamic | usage);
this._buffer = this._backend.ResourceFactory.CreateBuffer(ref desc);

this.SizeInBytes = byteSize;
}

public override unsafe void Map() {
MappedResource map = this._backend.GraphicsDevice.Map(this._buffer, MapMode.Write);

this.Ptr = (void*)map.Data;
}

public override void Unmap() {
this._backend.GraphicsDevice.Unmap(this._buffer);
}

public override unsafe void* Reserve(nuint byteCount) {
nuint ptr = (nuint)this.Ptr + this.ReservedBytes;

//If this reserve will push us over the limit, return nullptr
if (this.ReservedBytes + byteCount > this.SizeInBytes)
return null;

this.ReservedBytes += byteCount;

return (void*)ptr;
}

protected override void DisposeInternal() {
this._buffer.Dispose();
}
}
okay so once the mapper is full, should i copy the mapper buffer to a new buffer or just create a new buffer and tell the mapper to point to this new buffer is there a perf hit to the buffer being dynamic? if so, i should probably create new non-dynamic buffers and copy to them
TechPizza
TechPizza•3y ago
depends on backend and driver 🤡 just use dynamic
Lyris the Kitori
Lyris the Kitori•3y ago
alright so ill just create a new buffer when it gets full and stash the old buffer for rendering
TechPizza
TechPizza•3y ago
yes please
Lyris the Kitori
Lyris the Kitori•3y ago
cool
Lyris the Kitori
Lyris the Kitori•3y ago
this should do the trick https://i.beyleyisnot.moe/J7V8yzA.png
Lyris the Kitori
Lyris the Kitori•3y ago
pass you the old buffer and create a new one should i do the same single texture system in veldrid too?
TechPizza
TechPizza•3y ago
hmm?
Lyris the Kitori
Lyris the Kitori•3y ago
since veldrid also covers GL i guess i should only bind a single texture at a time
TechPizza
TechPizza•3y ago
i think we deduced that the shader branching was not a problem or what now
Want results from more Discord servers?
Add your server