Skip to content

Commit

Permalink
Fix from hell
Browse files Browse the repository at this point in the history
  • Loading branch information
MCRcortex committed Nov 2, 2023
1 parent df5fe5b commit 191bc20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/me/cortex/nvidium/managers/SectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,17 @@ public void uploadChunkBuildResult(ChunkBuildOutput result) {

int terrainAddress;
{
//If the section had terrain data associated with it, free it
if ((terrainAddress = this.section2terrain.remove(sectionKey)) != -1) {
//Attempt to reuse the same memory
terrainAddress = this.section2terrain.get(sectionKey);
if (terrainAddress != -1 && !this.terrainAreana.canReuse(terrainAddress, output.quads())) {
this.section2terrain.remove(sectionKey);
this.terrainAreana.free(terrainAddress);
terrainAddress = -1;
}
if (terrainAddress == -1) {
terrainAddress = this.terrainAreana.allocQuads(output.quads());
}

terrainAddress = this.terrainAreana.allocQuads(output.quads());
this.section2terrain.put(sectionKey, terrainAddress);

long geometryUpload = terrainAreana.upload(uploadStream, terrainAddress);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/cortex/nvidium/util/BufferArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ public float getFragmentation() {
long expected = totalQuads * vertexFormatSize * 4;
return (float) ((double)expected/getMemoryUsed());
}

public boolean canReuse(int addr, int quads) {
return this.segments.getSize(addr) == quads;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public UploadingBufferStream(RenderDevice device, int frames, long size) {
segments.setLimit(size);
buffer = device.createClientMappedBuffer(size);//Fixes an off by one in the limit testing of the segment buffer
TickableManager.register(this);

//FIXME: this is a rediculous hack cause i cannot find the root issue
// it seems like the first time something is uploaded it borks completely
// or something, maybe its just some vertex data overruning or something
// cause if i dont do this the first 16 bytes are set to 0 when the stream gets uploaded
var dummy = device.createDeviceOnlyMappedBuffer(256);
this.getUpload(dummy, 0, 256);
this.commit();
dummy.delete();
}

private long caddr = -1;
Expand Down

0 comments on commit 191bc20

Please sign in to comment.