More work on fixing remaining hiz issues

This commit is contained in:
mcrcortex
2025-04-22 09:20:45 +10:00
parent 306951ebee
commit 07bb8e0475
2 changed files with 23 additions and 10 deletions

View File

@@ -3,6 +3,9 @@ package me.cortex.voxy.common.thread;
import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.Logger;
import me.cortex.voxy.common.util.Pair; import me.cortex.voxy.common.util.Pair;
import java.lang.invoke.VarHandle;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.Arrays; import java.util.Arrays;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -14,6 +17,12 @@ import java.util.function.Supplier;
//TODO: could also probably replace all of this with just VirtualThreads and a Executors.newThreadPerTaskExecutor with a fixed thread pool //TODO: could also probably replace all of this with just VirtualThreads and a Executors.newThreadPerTaskExecutor with a fixed thread pool
// it is probably better anyway // it is probably better anyway
public class ServiceThreadPool { public class ServiceThreadPool {
/*
private static final ThreadMXBean THREAD_BEAN = ManagementFactory.getThreadMXBean();
static {
THREAD_BEAN.setThreadCpuTimeEnabled(true);
}*/
private volatile boolean running = true; private volatile boolean running = true;
private Thread[] workers = new Thread[0]; private Thread[] workers = new Thread[0];
private final Semaphore jobCounter = new Semaphore(0); private final Semaphore jobCounter = new Semaphore(0);
@@ -189,6 +198,7 @@ public class ServiceThreadPool {
//Didnt consume the job, find a new job //Didnt consume the job, find a new job
continue; continue;
} }
//Consumed a job from the service, decrease weight by the amount //Consumed a job from the service, decrease weight by the amount
if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) { if (this.totalJobWeight.addAndGet(-service.weightPerJob)<0) {
throw new IllegalStateException("Total job weight is negative"); throw new IllegalStateException("Total job weight is negative");

View File

@@ -128,22 +128,25 @@ bool outsideFrustum() {
} }
bool isCulledByHiz() { bool isCulledByHiz() {
//if (minBB.z < 0) {//Minpoint is behind the camera, its always going to pass if (any(lessThan(minBB.xy, vec2(0)) && lessThan(vec2(1), maxBB.xy))) {
// return false;//Just cull it for now cause other culling isnt working, TODO: FIXME return false;
//} }
vec2 ssize = size * vec2(screenW, screenH); vec2 ssize = size * vec2(screenW, screenH);
float miplevel = log2(max(max(ssize.x, ssize.y),1)); float miplevel = log2(max(max(ssize.x, ssize.y),1));
miplevel = ceil(miplevel);
miplevel = ceil(miplevel);
//miplevel = clamp(miplevel, 0, 20); //miplevel = clamp(miplevel, 0, 20);
vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f; vec2 midpoint = (maxBB.xy + minBB.xy)*0.5f;
//TODO: maybe get rid of clamp //midpoint = clamp(midpoint, vec2(0), vec2(1));
//Todo: replace with some rasterization, e.g. especially for request back to cpu
//vec2 midpoint2 = clamp(midpoint, vec2(0), vec2(1)); float testAgainst = minBB.z;
vec2 midpoint2 = midpoint; //the *2.0f-1.0f converts from the 0->1 range to -1->1 range that depth is in (not having this causes tighter bounds, but causes culling issues in caves)
//the *2.0f-1.0f converts from the 0->1 range to -1->1 range that depth is in testAgainst = testAgainst*2.0f-1.0f;
bool culled = textureLod(hizDepthSampler, vec3(midpoint2, minBB.z*2.0f-1.0f), miplevel) < 0.0001f;//*0.5f+0.5f
bool culled = textureLod(hizDepthSampler, vec3(midpoint, testAgainst), miplevel) < 0.0001f;
//printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z); //printf("HiZ sample point: (%f,%f)@%f against %f", midpoint.x, midpoint.y, miplevel, minBB.z);
//if ((culled) && node22.lodLevel == 0) { //if ((culled) && node22.lodLevel == 0) {
// printf("HiZ sample point: (%f,%f)@%f against %f, value %f", midpoint.x, midpoint.y, miplevel, minBB.z, textureLod(hizDepthSampler, vec3(0.5f,0.5f, 0.000000001f), 9.0f)); // printf("HiZ sample point: (%f,%f)@%f against %f, value %f", midpoint.x, midpoint.y, miplevel, minBB.z, textureLod(hizDepthSampler, vec3(0.5f,0.5f, 0.000000001f), 9.0f));