veldrid-cursed

veldrid-cursed
120 Replies
Lyris the Kitori
Lyris the KitoriOP•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 KitoriOP•3y ago
i can assume the buffer i allocate is continuous right?
Lyris the Kitori
Lyris the KitoriOP•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 KitoriOP•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 KitoriOP•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 KitoriOP•3y ago
cool
Lyris the Kitori
Lyris the KitoriOP•3y ago
this should do the trick https://i.beyleyisnot.moe/J7V8yzA.png
Lyris the Kitori
Lyris the KitoriOP•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 KitoriOP•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
Lyris the Kitori
Lyris the KitoriOP•3y ago
oh so i should readd all that multitexture code :^) thats hopefully simple
TechPizza
TechPizza•3y ago
well if it worked in instancing i dont see why it wouldnt work here
Lyris the Kitori
Lyris the KitoriOP•3y ago
a
TechPizza
TechPizza•3y ago
Kai would need to test on amd but amd only bitched about the attribute locations right
Lyris the Kitori
Lyris the KitoriOP•3y ago
seemingly yea okay multitexture is back lemme run the same benchmark hovering around 5-6k fps 2k higher than single texture
TechPizza
TechPizza•3y ago
at least we now know that branching is likely ok when
Lyris the Kitori
Lyris the KitoriOP•3y ago
im sure its Fine i also am in a perfect position to do bindless opengl once i get veldrid and DX11 up and running ive heard complete DSA OpenGL is actually a p decent upgrade from standard opengl i wanna give it a shot sometime
TechPizza
TechPizza•3y ago
sounds like writing more backends for naught but oh well
Lyris the Kitori
Lyris the KitoriOP•3y ago
idk it just seems like fun sometime :^) something for a rainy day okay got the basic veldrid buffer system down, time to create the pipeline
Lyris the Kitori
Lyris the KitoriOP•3y ago
https://i.beyleyisnot.moe/grJuLA.png now i just gotta write the shaders
Lyris the Kitori
Lyris the KitoriOP•3y ago
time for it to shit itself immediately
Lyris the Kitori
Lyris the KitoriOP•3y ago
so im missing a quad and 2 tris on the pentagon
Lyris the Kitori
Lyris the KitoriOP•3y ago
probably the indices are wrong https://i.beyleyisnot.moe/VrQtwzc.png
Lyris the Kitori
Lyris the KitoriOP•3y ago
somehow
Lyris the Kitori
Lyris the KitoriOP•3y ago
i think i found a bug in veldrid unmapping resources just doesnt work in GL
Lyris the Kitori
Lyris the KitoriOP•3y ago
nevermind i was changing buffers and not unmapping/mapping somehow vulkan was fine with it idk how
Lyris the Kitori
Lyris the KitoriOP•3y ago
what does this mean and why does it only happen on GL https://i.beyleyisnot.moe/5u9YREY.png
TechPizza
TechPizza•3y ago
not sure also which veldrid version are you using
Lyris the Kitori
Lyris the KitoriOP•3y ago
normal
TechPizza
TechPizza•3y ago
i don't see a normal version on nuget 🙃
Lyris the Kitori
Lyris the KitoriOP•3y ago
No description
TechPizza
TechPizza•3y ago
ugh i think that's the latest one yes
Lyris the Kitori
Lyris the KitoriOP•3y ago
back to trying to debug veldrid gl thisi s pain
Lyris the Kitori
Lyris the KitoriOP•3y ago
veldrid vulkan works literally perfectly which is whats so confusing to me https://i.beyleyisnot.moe/H6jz2gw.png
Lyris the Kitori
Lyris the KitoriOP•3y ago
some quads are just missing for no reasonhttps://i.beyleyisnot.moe/ow2N4n8.png
TechPizza
TechPizza•3y ago
time to enable the vulkan debug layers? i can also test it if it's in github
Lyris the Kitori
Lyris the KitoriOP•3y ago
actually wait looking into renderdoc there should not be that many draw calls https://i.beyleyisnot.moe/Na1dRUc.png
Lyris the Kitori
Lyris the KitoriOP•3y ago
i think my buffer size logic is fucked gimme a min
Lyris the Kitori
Lyris the KitoriOP•3y ago
Lyris the Kitori
Lyris the KitoriOP•3y ago
why is it only batching 6 quads tf
TechPizza
TechPizza•3y ago
¯\_(ツ)_/¯
Lyris the Kitori
Lyris the KitoriOP•3y ago
ah i was creating the buffers too small cus i was forgetting to multiply by the size of the structures i just pushed to gh if you want to try
TechPizza
TechPizza•3y ago
you should probably assert the buffer size after mapping to see if things fit :)
Lyris the Kitori
Lyris the KitoriOP•3y ago
https://i.beyleyisnot.moe/SPIvqfM.png the things are there in renderdoc, weird that they arent drawing
TechPizza
TechPizza•3y ago
or use Spans actually
Lyris the Kitori
Lyris the KitoriOP•3y ago
probably ye
TechPizza
TechPizza•3y ago
that's a new one
No description
Lyris the Kitori
Lyris the KitoriOP•3y ago
uh oh that doesnt look healthy
TechPizza
TechPizza•3y ago
ok so cursed thing renderdoc says that the shader you are using is the internal imgui shader from veldrid
Lyris the Kitori
Lyris the KitoriOP•3y ago
the fuck that should not be possible in the slightest
TechPizza
TechPizza•3y ago
it may be renderdoc getting confused
Lyris the Kitori
Lyris the KitoriOP•3y ago
it likes to do that do you want me to send you my renderdoc capture
TechPizza
TechPizza•3y ago
nah ok so vulkan works fine
Lyris the Kitori
Lyris the KitoriOP•3y ago
can you try dx it might give better debugging results
TechPizza
TechPizza•3y ago
i can in fact not try dx11
No description
Lyris the Kitori
Lyris the KitoriOP•3y ago
this is a true Direct X Elevent Moment
TechPizza
TechPizza•3y ago
also veldrid is bugged and mellinoe still has not fixed it
Lyris the Kitori
Lyris the KitoriOP•3y ago
true i had to modify my arch install a bit to even get it to work at all for me
TechPizza
TechPizza•3y ago
ok so after looking for 30min the only thing i saw was that RendererVeldrid has different vertex element names than the glsl but correcting them changed nothing pain
Lyris the Kitori
Lyris the KitoriOP•3y ago
nightmare.
TechPizza
TechPizza•3y ago
i have discovered that the first draw call is the only one who has issues on opengl oh
Lyris the Kitori
Lyris the KitoriOP•3y ago
huh oh?
TechPizza
TechPizza•3y ago
i think it's because the buffer is mapped opengl cannot draw from mapped buffers
Lyris the Kitori
Lyris the KitoriOP•3y ago
oh but i unmap them
TechPizza
TechPizza•3y ago
i'm happy that it took me 40min to figure this out 😑
Lyris the Kitori
Lyris the KitoriOP•3y ago
so do i have to copy the data out into unmappable buffers?
TechPizza
TechPizza•3y ago
nah you just have to unmap them
Lyris the Kitori
Lyris the KitoriOP•3y ago
i do at least i should be
TechPizza
TechPizza•3y ago
hmm yeah looks correct idfk nope they are still mapped i can see it through the debugger phew i thought i'm going insane wait i think this is giga cursed hmm maybe not
Lyris the Kitori
Lyris the KitoriOP•3y ago
you think
Lyris the Kitori
Lyris the KitoriOP•3y ago
i'm 100% unmapping
No description
Lyris the Kitori
Lyris the KitoriOP•3y ago
there's no way for me to not unmap
TechPizza
TechPizza•3y ago
debuggar aint lyin
Lyris the Kitori
Lyris the KitoriOP•3y ago
No description
TechPizza
TechPizza•3y ago
me rn
Lyris the Kitori
Lyris the KitoriOP•3y ago
maybe a bug in veldrid?
TechPizza
TechPizza•3y ago
doubt
Lyris the Kitori
Lyris the KitoriOP•3y ago
going through my logic, every map is matched with an unmap also why is only the first one still mapped what? i'm double mapping on the first one
TechPizza
TechPizza•3y ago
yeah that is it
TechPizza
TechPizza•3y ago
boom works
Lyris the Kitori
Lyris the KitoriOP•3y ago
aaaa
TechPizza
TechPizza•3y ago
i should add that to my fork
throw if vertex or index buffer is mapped
Lyris the Kitori
Lyris the KitoriOP•3y ago
can i switch to your fork how much trouble would that be
TechPizza
TechPizza•3y ago
don't bother yet i will make it a nuget sooon
Lyris the Kitori
Lyris the KitoriOP•3y ago
cool
TechPizza
TechPizza•3y ago
god this took forever i'll just blame mellinoe to cope in advance
Lyris the Kitori
Lyris the KitoriOP•3y ago
i have been pouring over the code for 4 hours i was in the bank earlier STILL thinking about why tf it's not working
TechPizza
TechPizza•3y ago
i also get stuck up with annoyances for days
Lyris the Kitori
Lyris the KitoriOP•3y ago
at least it's solved now?
TechPizza
TechPizza•3y ago
it did render everything, i count that as a win lol
Lyris the Kitori
Lyris the KitoriOP•3y ago
i'm gonna cry myself to sleep now even though it's 5pm i hate opengl
TechPizza
TechPizza•3y ago
oh? difficult day?
Lyris the Kitori
Lyris the KitoriOP•3y ago
no just opengl
TechPizza
TechPizza•3y ago
💯 great i restart VS and now all symbols have to reload
Lyris the Kitori
Lyris the KitoriOP•3y ago
bruhhh
TechPizza
TechPizza•3y ago
from the symbol servers what is this shit
Lyris the Kitori
Lyris the KitoriOP•3y ago
even worse
TechPizza
TechPizza•3y ago
who killed my cache
Lyris the Kitori
Lyris the KitoriOP•3y ago
opengl
TechPizza
TechPizza•3y ago
alright i'll go to bed, and leave you with the cursed opengl stuff
Lyris the Kitori
Lyris the KitoriOP•3y ago
aight cya
Lyris the Kitori
Lyris the KitoriOP•3y ago
pog cant wait to be able to move over to the fork
Lyris the Kitori
Lyris the KitoriOP•3y ago
why tf is it flashing white randomly in renderdoc the draw claims to not be white anywhere, but for SOME reason its white just randomly flashing white had to take 20 captures just to get a rednerdoc capture of it and it aint even helping pain
TechPizza
TechPizza•3y ago
hehe
TechPizza
TechPizza•3y ago
No description
Lyris the Kitori
Lyris the KitoriOP•3y ago
lmao
Want results from more Discord servers?
Add your server