mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-11 13:31:07 -04:00
Reduce raymarching pixel errors and add chunkmesh gpu memory usage to the debug menu.
This commit is contained in:
parent
0c3743fd02
commit
38601dc42c
@ -101,6 +101,7 @@ RayMarchResult rayMarching(vec3 startPosition, vec3 direction) { // TODO: Mipmap
|
|||||||
vec3 tDelta = 1/direction;
|
vec3 tDelta = 1/direction;
|
||||||
vec3 t2 = t1 + tDelta;
|
vec3 t2 = t1 + tDelta;
|
||||||
tDelta = abs(tDelta);
|
tDelta = abs(tDelta);
|
||||||
|
vec3 invTDelta = intBitsToFloat(floatBitsToInt(1.0) | modelSize)/tDelta;
|
||||||
vec3 tMax = max(t1, t2) - tDelta;
|
vec3 tMax = max(t1, t2) - tDelta;
|
||||||
if(direction.x == 0) tMax.x = 1.0/0.0;
|
if(direction.x == 0) tMax.x = 1.0/0.0;
|
||||||
if(direction.y == 0) tMax.y = 1.0/0.0;
|
if(direction.y == 0) tMax.y = 1.0/0.0;
|
||||||
@ -120,7 +121,7 @@ RayMarchResult rayMarching(vec3 startPosition, vec3 direction) { // TODO: Mipmap
|
|||||||
it++;
|
it++;
|
||||||
vec3 tNext = tMax + block*tDelta;
|
vec3 tNext = tMax + block*tDelta;
|
||||||
total_tMax = min(tNext.x, min(tNext.y, tNext.z));
|
total_tMax = min(tNext.x, min(tNext.y, tNext.z));
|
||||||
vec3 missingSteps = floor((total_tMax - tMax)/tDelta + 0.00001);
|
vec3 missingSteps = floor((total_tMax - tMax)*invTDelta);
|
||||||
voxelIndex += int(dot(missingSteps, stepInIndex));
|
voxelIndex += int(dot(missingSteps, stepInIndex));
|
||||||
tMax += missingSteps*tDelta;
|
tMax += missingSteps*tDelta;
|
||||||
if((voxelIndex & overflowMask) != 0)
|
if((voxelIndex & overflowMask) != 0)
|
||||||
|
@ -1141,11 +1141,14 @@ pub const LargeBuffer = struct {
|
|||||||
};
|
};
|
||||||
ssbo: SSBO,
|
ssbo: SSBO,
|
||||||
freeBlocks: std.ArrayList(Allocation),
|
freeBlocks: std.ArrayList(Allocation),
|
||||||
|
capacity: u32,
|
||||||
|
used: u32,
|
||||||
|
|
||||||
pub fn init(self: *LargeBuffer, allocator: Allocator, size: u31, binding: c_uint) !void {
|
pub fn init(self: *LargeBuffer, allocator: Allocator, size: u31, binding: c_uint) !void {
|
||||||
self.ssbo = SSBO.init();
|
self.ssbo = SSBO.init();
|
||||||
self.ssbo.createDynamicBuffer(size);
|
self.ssbo.createDynamicBuffer(size);
|
||||||
self.ssbo.bind(binding);
|
self.ssbo.bind(binding);
|
||||||
|
self.capacity = size;
|
||||||
|
|
||||||
self.freeBlocks = std.ArrayList(Allocation).init(allocator);
|
self.freeBlocks = std.ArrayList(Allocation).init(allocator);
|
||||||
try self.freeBlocks.append(.{.start = 0, .len = size});
|
try self.freeBlocks.append(.{.start = 0, .len = size});
|
||||||
@ -1157,6 +1160,7 @@ pub const LargeBuffer = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn alloc(self: *LargeBuffer, size: u31) !Allocation {
|
fn alloc(self: *LargeBuffer, size: u31) !Allocation {
|
||||||
|
self.used += size;
|
||||||
var smallestBlock: ?*Allocation = null;
|
var smallestBlock: ?*Allocation = null;
|
||||||
for(self.freeBlocks.items, 0..) |*block, i| {
|
for(self.freeBlocks.items, 0..) |*block, i| {
|
||||||
if(size == block.len) {
|
if(size == block.len) {
|
||||||
@ -1175,6 +1179,7 @@ pub const LargeBuffer = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn free(self: *LargeBuffer, _allocation: Allocation) !void {
|
pub fn free(self: *LargeBuffer, _allocation: Allocation) !void {
|
||||||
|
self.used -= _allocation.len;
|
||||||
var allocation = _allocation;
|
var allocation = _allocation;
|
||||||
if(allocation.len == 0) return;
|
if(allocation.len == 0) return;
|
||||||
for(self.freeBlocks.items, 0..) |*block, i| {
|
for(self.freeBlocks.items, 0..) |*block, i| {
|
||||||
@ -1198,6 +1203,7 @@ pub const LargeBuffer = struct {
|
|||||||
if(newSize == allocation.len) return;
|
if(newSize == allocation.len) return;
|
||||||
if(newSize < allocation.len) {
|
if(newSize < allocation.len) {
|
||||||
const diff = allocation.len - newSize;
|
const diff = allocation.len - newSize;
|
||||||
|
self.used -= diff;
|
||||||
// Check if there is a free block directly after:
|
// Check if there is a free block directly after:
|
||||||
for(self.freeBlocks.items) |*block| {
|
for(self.freeBlocks.items) |*block| {
|
||||||
if(allocation.start + allocation.len == block.start and block.len + allocation.len >= newSize) {
|
if(allocation.start + allocation.len == block.start and block.len + allocation.len >= newSize) {
|
||||||
@ -1211,10 +1217,11 @@ pub const LargeBuffer = struct {
|
|||||||
allocation.len -= diff;
|
allocation.len -= diff;
|
||||||
try self.freeBlocks.append(.{.start = allocation.start + allocation.len, .len = diff});
|
try self.freeBlocks.append(.{.start = allocation.start + allocation.len, .len = diff});
|
||||||
} else {
|
} else {
|
||||||
|
const diff = newSize - allocation.len;
|
||||||
|
self.used += diff;
|
||||||
// Check if the buffer can be extended without a problem:
|
// Check if the buffer can be extended without a problem:
|
||||||
for(self.freeBlocks.items, 0..) |*block, i| {
|
for(self.freeBlocks.items, 0..) |*block, i| {
|
||||||
if(allocation.start + allocation.len == block.start and block.len + allocation.len >= newSize) {
|
if(allocation.start + allocation.len == block.start and block.len + allocation.len >= newSize) {
|
||||||
const diff = newSize - allocation.len;
|
|
||||||
allocation.len += diff;
|
allocation.len += diff;
|
||||||
if(block.len != diff) {
|
if(block.len != diff) {
|
||||||
block.start += diff;
|
block.start += diff;
|
||||||
|
@ -35,6 +35,8 @@ fn flawedRender() !void {
|
|||||||
y += 8;
|
y += 8;
|
||||||
try draw.print("Queue size: {}", .{main.threadPool.loadList.size}, 0, y, 8, .left);
|
try draw.print("Queue size: {}", .{main.threadPool.loadList.size}, 0, y, 8, .left);
|
||||||
y += 8;
|
y += 8;
|
||||||
|
try draw.print("ChunkMesh memory: {} MiB / {} MiB (fragmentation: {})", .{main.chunk.meshing.faceBuffer.used >> 20, main.chunk.meshing.faceBuffer.capacity >> 20, main.chunk.meshing.faceBuffer.freeBlocks.items.len}, 0, y, 8, .left);
|
||||||
|
y += 8;
|
||||||
// TODO: biome
|
// TODO: biome
|
||||||
y += 8;
|
y += 8;
|
||||||
// TODO: packet loss
|
// TODO: packet loss
|
||||||
|
Loading…
x
Reference in New Issue
Block a user