begin prep for offthread work
This commit is contained in:
@@ -66,8 +66,6 @@ public class ModelBakerySubsystem {
|
||||
}*/
|
||||
//TimingStatistics.modelProcess.start();
|
||||
if (this.blockIdCount.get() != 0) {
|
||||
long budget = Math.min(totalBudget-150_000, totalBudget-(this.factory.resultJobs.size()*10_000L))-150_000;
|
||||
|
||||
//Always do 1 iteration minimum
|
||||
Integer i = this.blockIdQueue.poll();
|
||||
int j = 0;
|
||||
@@ -90,8 +88,7 @@ public class ModelBakerySubsystem {
|
||||
this.factory.tick();
|
||||
|
||||
long start = System.nanoTime();
|
||||
while (!this.factory.resultJobs.isEmpty()) {
|
||||
this.factory.resultJobs.poll().run();
|
||||
while (this.factory.processResult()) {
|
||||
if (totalBudget<(System.nanoTime()-start))
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ModelFactory {
|
||||
private final ModelStore storage;
|
||||
private final RawDownloadStream downstream = new RawDownloadStream(8*1024*1024);//8mb downstream
|
||||
|
||||
public final Deque<Runnable> resultJobs = new ArrayDeque<>();
|
||||
private final Deque<RawBakeResult> rawBakeResults = new ArrayDeque<>();
|
||||
|
||||
private Object2IntMap<BlockState> customBlockStateIdMapping;
|
||||
|
||||
@@ -147,6 +147,17 @@ public class ModelFactory {
|
||||
this.customBlockStateIdMapping = mapping;
|
||||
}
|
||||
|
||||
private record RawBakeResult(int blockId, BlockState blockState, MemoryBuffer rawData) {
|
||||
public RawBakeResult(int blockId, BlockState blockState) {
|
||||
this(blockId, blockState, new MemoryBuffer(MODEL_TEXTURE_SIZE*MODEL_TEXTURE_SIZE*2*4*6));
|
||||
}
|
||||
|
||||
public RawBakeResult cpyBuf(long ptr) {
|
||||
this.rawData.cpyFrom(ptr);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addEntry(int blockId) {
|
||||
if (this.idMappings[blockId] != -1) {
|
||||
return false;
|
||||
@@ -179,9 +190,19 @@ public class ModelFactory {
|
||||
}
|
||||
}
|
||||
|
||||
int TOTAL_FACES_TEXTURE_SIZE = MODEL_TEXTURE_SIZE*MODEL_TEXTURE_SIZE*2*4*6;// since both depth and colour are packed together, 6 faces, 4 bytes per pixel
|
||||
int allocation = this.downstream.download(TOTAL_FACES_TEXTURE_SIZE, ptr -> {
|
||||
RawBakeResult result = new RawBakeResult(blockId, blockState);
|
||||
int allocation = this.downstream.download(MODEL_TEXTURE_SIZE*MODEL_TEXTURE_SIZE*2*4*6, ptr -> this.rawBakeResults.add(result.cpyBuf(ptr)));
|
||||
this.bakery.renderToStream(blockState, this.downstream.getBufferId(), allocation);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean processResult() {
|
||||
if (this.rawBakeResults.isEmpty())
|
||||
return false;
|
||||
var result = this.rawBakeResults.poll();
|
||||
ColourDepthTextureData[] textureData = new ColourDepthTextureData[6];
|
||||
{//Create texture data
|
||||
long ptr = result.rawData.address;
|
||||
final int FACE_SIZE = MODEL_TEXTURE_SIZE * MODEL_TEXTURE_SIZE;
|
||||
for (int face = 0; face < 6; face++) {
|
||||
long faceDataPtr = ptr + (FACE_SIZE * 4) * face * 2;
|
||||
@@ -194,15 +215,13 @@ public class ModelFactory {
|
||||
colour[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2));
|
||||
depth[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2) + 4);
|
||||
}
|
||||
|
||||
textureData[face] = new ColourDepthTextureData(colour, depth, MODEL_TEXTURE_SIZE, MODEL_TEXTURE_SIZE);
|
||||
}
|
||||
this.resultJobs.add(()->processTextureBakeResult(blockId, blockState, textureData));
|
||||
});
|
||||
this.bakery.renderToStream(blockState, this.downstream.getBufferId(), allocation);
|
||||
return true;
|
||||
}
|
||||
|
||||
result.rawData.free();
|
||||
this.processTextureBakeResult(result.blockId, result.blockState, textureData);
|
||||
return !this.rawBakeResults.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
//This is
|
||||
@@ -759,6 +778,9 @@ public class ModelFactory {
|
||||
}
|
||||
|
||||
public void free() {
|
||||
while (!this.rawBakeResults.isEmpty()) {
|
||||
this.rawBakeResults.poll().rawData.free();
|
||||
}
|
||||
this.downstream.free();
|
||||
this.bakery.free();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user