Render regions, disabled by default
This commit is contained in:
+36
-6
@@ -100,8 +100,9 @@ let pending_destroy: GPUBuffer[] = [];
|
||||
// switches for finding out what a frame costs, see the f3 performance window. msaa is changed at the start of the next
|
||||
// frame. split_passes gives each section (see gpu_section) passes of its own so the gpu times them apart, which costs
|
||||
// a little since every pass loads and stores the render targets. uncapped starts frames back to back instead of with
|
||||
// the display's refresh, see the game loop in main.ts
|
||||
export const render_debug = { msaa: false, split_passes: false, uncapped: false };
|
||||
// the display's refresh, see the game loop in main.ts. render_regions draws terrain by region, see
|
||||
// ClientLevel.use_render_regions
|
||||
export const render_debug = { msaa: false, split_passes: false, uncapped: false, render_regions: false };
|
||||
// what was drawn, for the last whole frame
|
||||
export interface RenderStats {
|
||||
draw_calls: number;
|
||||
@@ -539,7 +540,9 @@ export function flush_batch() {
|
||||
|
||||
// what's bound for terrain draws in the current pass, so drawing hundreds of chunks doesn't bind the same things
|
||||
// again for each one. cleared whenever the pipeline changes
|
||||
let terrain_binds: { slot: number; texture: GPUTexture; index_buffer: GPUBuffer } | undefined;
|
||||
let terrain_binds:
|
||||
| { slot: number; texture: GPUTexture; index_buffer: GPUBuffer; vertex_buffer: GPUBuffer }
|
||||
| undefined;
|
||||
|
||||
// draws quads first to first + quad_count of a chunk mesh (4 vertices each). without an index buffer the quads are
|
||||
// drawn in order
|
||||
@@ -578,9 +581,11 @@ export function draw_terrain(
|
||||
if (terrain_binds?.index_buffer !== index_buffer) {
|
||||
render_pass.setIndexBuffer(index_buffer, "uint32");
|
||||
}
|
||||
terrain_binds = { slot: uniform_slot, texture: current_texture, index_buffer };
|
||||
if (terrain_binds?.vertex_buffer !== vertex_buffer) {
|
||||
render_pass.setVertexBuffer(0, vertex_buffer);
|
||||
}
|
||||
terrain_binds = { slot: uniform_slot, texture: current_texture, index_buffer, vertex_buffer };
|
||||
|
||||
render_pass.setVertexBuffer(0, vertex_buffer);
|
||||
render_pass.drawIndexed(quad_count * 6, 1, first * 6);
|
||||
frame_stats.draw_calls += 1;
|
||||
frame_stats.quads[layer] += quad_count;
|
||||
@@ -618,7 +623,13 @@ export function draw_instances(
|
||||
}
|
||||
|
||||
// copies data into part of a buffer made with create_vertex_buffer, from data's first to last element
|
||||
export function write_buffer(buffer: GPUBuffer, byte_offset: number, data: Float32Array, first: number, count: number) {
|
||||
export function write_buffer(
|
||||
buffer: GPUBuffer,
|
||||
byte_offset: number,
|
||||
data: Float32Array | Uint8Array<ArrayBuffer>,
|
||||
first: number,
|
||||
count: number,
|
||||
) {
|
||||
device.queue.writeBuffer(buffer, byte_offset, data, first, count);
|
||||
}
|
||||
|
||||
@@ -636,6 +647,25 @@ export function create_vertex_buffer(vertices: Float32Array<ArrayBuffer> | Uint8
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// an empty vertex buffer of size bytes that copy_buffer can copy from and to
|
||||
export function create_copyable_vertex_buffer(size: number): GPUBuffer {
|
||||
return device.createBuffer({
|
||||
size: Math.max(4, size),
|
||||
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC,
|
||||
});
|
||||
}
|
||||
|
||||
// copies ranges of from into to on the gpu, as from offset, to offset and size in bytes, three numbers each. the copies
|
||||
// happen before any later draw or write_buffer
|
||||
export function copy_buffer(from: GPUBuffer, to: GPUBuffer, ranges: number[]) {
|
||||
if (ranges.length === 0) return;
|
||||
const copies = device.createCommandEncoder();
|
||||
for (let i = 0; i < ranges.length; i += 3) {
|
||||
copies.copyBufferToBuffer(from, ranges[i], to, ranges[i + 1], ranges[i + 2]);
|
||||
}
|
||||
device.queue.submit([copies.finish()]);
|
||||
}
|
||||
|
||||
export function create_index_buffer(indices: Uint32Array): GPUBuffer {
|
||||
const buffer = device.createBuffer({
|
||||
size: Math.max(4, indices.byteLength),
|
||||
|
||||
Reference in New Issue
Block a user