begin prep for offthread work
This commit is contained in:
@@ -66,8 +66,6 @@ public class ModelBakerySubsystem {
|
|||||||
}*/
|
}*/
|
||||||
//TimingStatistics.modelProcess.start();
|
//TimingStatistics.modelProcess.start();
|
||||||
if (this.blockIdCount.get() != 0) {
|
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
|
//Always do 1 iteration minimum
|
||||||
Integer i = this.blockIdQueue.poll();
|
Integer i = this.blockIdQueue.poll();
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@@ -90,8 +88,7 @@ public class ModelBakerySubsystem {
|
|||||||
this.factory.tick();
|
this.factory.tick();
|
||||||
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
while (!this.factory.resultJobs.isEmpty()) {
|
while (this.factory.processResult()) {
|
||||||
this.factory.resultJobs.poll().run();
|
|
||||||
if (totalBudget<(System.nanoTime()-start))
|
if (totalBudget<(System.nanoTime()-start))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public class ModelFactory {
|
|||||||
private final ModelStore storage;
|
private final ModelStore storage;
|
||||||
private final RawDownloadStream downstream = new RawDownloadStream(8*1024*1024);//8mb downstream
|
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;
|
private Object2IntMap<BlockState> customBlockStateIdMapping;
|
||||||
|
|
||||||
@@ -147,6 +147,17 @@ public class ModelFactory {
|
|||||||
this.customBlockStateIdMapping = mapping;
|
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) {
|
public boolean addEntry(int blockId) {
|
||||||
if (this.idMappings[blockId] != -1) {
|
if (this.idMappings[blockId] != -1) {
|
||||||
return false;
|
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
|
RawBakeResult result = new RawBakeResult(blockId, blockState);
|
||||||
int allocation = this.downstream.download(TOTAL_FACES_TEXTURE_SIZE, ptr -> {
|
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];
|
ColourDepthTextureData[] textureData = new ColourDepthTextureData[6];
|
||||||
|
{//Create texture data
|
||||||
|
long ptr = result.rawData.address;
|
||||||
final int FACE_SIZE = MODEL_TEXTURE_SIZE * MODEL_TEXTURE_SIZE;
|
final int FACE_SIZE = MODEL_TEXTURE_SIZE * MODEL_TEXTURE_SIZE;
|
||||||
for (int face = 0; face < 6; face++) {
|
for (int face = 0; face < 6; face++) {
|
||||||
long faceDataPtr = ptr + (FACE_SIZE * 4) * face * 2;
|
long faceDataPtr = ptr + (FACE_SIZE * 4) * face * 2;
|
||||||
@@ -194,15 +215,13 @@ public class ModelFactory {
|
|||||||
colour[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2));
|
colour[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2));
|
||||||
depth[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2) + 4);
|
depth[i] = MemoryUtil.memGetInt(faceDataPtr + (i * 4 * 2) + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
textureData[face] = new ColourDepthTextureData(colour, depth, MODEL_TEXTURE_SIZE, MODEL_TEXTURE_SIZE);
|
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
|
//This is
|
||||||
@@ -759,6 +778,9 @@ public class ModelFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void free() {
|
public void free() {
|
||||||
|
while (!this.rawBakeResults.isEmpty()) {
|
||||||
|
this.rawBakeResults.poll().rawData.free();
|
||||||
|
}
|
||||||
this.downstream.free();
|
this.downstream.free();
|
||||||
this.bakery.free();
|
this.bakery.free();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user