|
|
|
@ -80,12 +80,17 @@ async function init_wasm(state) {
@@ -80,12 +80,17 @@ async function init_wasm(state) {
|
|
|
|
|
'used': 0, |
|
|
|
|
'cap': initial |
|
|
|
|
}, |
|
|
|
|
'width': { |
|
|
|
|
'used': 0, |
|
|
|
|
'cap': initial |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
state.wasm.buffers['xs'].offset = state.wasm.exports.alloc_static(initial); |
|
|
|
|
state.wasm.buffers['ys'].offset = state.wasm.exports.alloc_static(initial); |
|
|
|
|
state.wasm.buffers['pressures'].offset = state.wasm.exports.alloc_static(initial); |
|
|
|
|
state.wasm.buffers['coords_from'].offset = state.wasm.exports.alloc_static(initial); |
|
|
|
|
state.wasm.buffers['width'].offset = state.wasm.exports.alloc_static(initial); |
|
|
|
|
|
|
|
|
|
const mem = state.wasm.memory.buffer; |
|
|
|
|
|
|
|
|
@ -97,6 +102,8 @@ async function init_wasm(state) {
@@ -97,6 +102,8 @@ async function init_wasm(state) {
|
|
|
|
|
mem, state.wasm.buffers['pressures'].offset); |
|
|
|
|
state.wasm.buffers['coords_from'].tv = tv_create_on(Uint32Array, initial / 4, |
|
|
|
|
mem, state.wasm.buffers['coords_from'].offset); |
|
|
|
|
state.wasm.buffers['width'].tv = tv_create_on(Uint32Array, initial / 4, |
|
|
|
|
mem, state.wasm.buffers['width'].offset); |
|
|
|
|
|
|
|
|
|
tv_add(state.wasm.buffers['coords_from'].tv, 0); |
|
|
|
|
state.wasm.buffers['coords_from'].used = 4; |
|
|
|
@ -108,6 +115,7 @@ function wasm_ensure_by(state, nstrokes, ncoords) {
@@ -108,6 +115,7 @@ function wasm_ensure_by(state, nstrokes, ncoords) {
|
|
|
|
|
const old_ys_offset = buffers['ys'].offset; |
|
|
|
|
const old_coords_from_offset = buffers['coords_from'].offset; |
|
|
|
|
const old_pressures_offset = buffers['pressures'].offset; |
|
|
|
|
const old_width_offset = buffers['width'].offset; |
|
|
|
|
|
|
|
|
|
let realloc = false; |
|
|
|
|
let coords_bytes = buffers['xs'].cap; |
|
|
|
@ -135,23 +143,31 @@ function wasm_ensure_by(state, nstrokes, ncoords) {
@@ -135,23 +143,31 @@ function wasm_ensure_by(state, nstrokes, ncoords) {
|
|
|
|
|
buffers['ys'].offset = state.wasm.exports.alloc_static(coords_bytes); |
|
|
|
|
buffers['pressures'].offset = state.wasm.exports.alloc_static(coords_bytes); |
|
|
|
|
buffers['coords_from'].offset = state.wasm.exports.alloc_static(stroke_bytes); |
|
|
|
|
buffers['width'].offset = state.wasm.exports.alloc_static(stroke_bytes); |
|
|
|
|
|
|
|
|
|
buffers['xs'].tv = tv_create_on(Float32Array, coords_bytes / 4, mem, buffers['xs'].offset); |
|
|
|
|
buffers['ys'].tv = tv_create_on(Float32Array, coords_bytes / 4, mem, buffers['ys'].offset); |
|
|
|
|
buffers['pressures'].tv = tv_create_on(Uint8Array, coords_bytes, mem, buffers['pressures'].offset); |
|
|
|
|
buffers['coords_from'].tv = tv_create_on(Uint32Array, stroke_bytes / 4, mem, buffers['coords_from'].offset); |
|
|
|
|
buffers['width'].tv = tv_create_on(Uint32Array, stroke_bytes / 4, mem, buffers['width'].offset); |
|
|
|
|
|
|
|
|
|
// TODO: this should have been automatic maybe?
|
|
|
|
|
buffers['xs'].tv.size = buffers['xs'].used / 4; |
|
|
|
|
buffers['ys'].tv.size = buffers['ys'].used / 4; |
|
|
|
|
buffers['pressures'].tv.size = buffers['pressures'].used; |
|
|
|
|
buffers['coords_from'].tv.size = buffers['coords_from'].used / 4; |
|
|
|
|
buffers['width'].tv.size = buffers['width'].used / 4; |
|
|
|
|
|
|
|
|
|
// TODO: this is SUS, should all the caps really be coords_bytes?
|
|
|
|
|
buffers['xs'].cap = buffers['ys'].cap = buffers['pressures'].cap = coords_bytes; |
|
|
|
|
buffers['coords_from'].cap = stroke_bytes; |
|
|
|
|
buffers['coords_from'].cap = buffers['width'].cap = stroke_bytes; |
|
|
|
|
|
|
|
|
|
const tmp = new Uint8Array(Math.max(coords_bytes, stroke_bytes)); |
|
|
|
|
|
|
|
|
|
// Copy from back to front (otherwise we will overwrite)
|
|
|
|
|
tmp.set(new Uint8Array(mem, old_width_offset, buffers['width'].used)); |
|
|
|
|
memv.set(new Uint8Array(tmp.buffer, 0, buffers['width'].used), buffers['width'].offset); |
|
|
|
|
|
|
|
|
|
tmp.set(new Uint8Array(mem, old_coords_from_offset, buffers['coords_from'].used)); |
|
|
|
|
memv.set(new Uint8Array(tmp.buffer, 0, buffers['coords_from'].used), buffers['coords_from'].offset); |
|
|
|
|
|
|
|
|
@ -180,6 +196,7 @@ async function do_lod(state, context) {
@@ -180,6 +196,7 @@ async function do_lod(state, context) {
|
|
|
|
|
const indices_per_thread = Math.floor(context.clipped_indices.size / state.wasm.workers.length); |
|
|
|
|
const offsets = { |
|
|
|
|
'coords_from': buffers['coords_from'].offset, |
|
|
|
|
'width': buffers['width'].offset, |
|
|
|
|
'xs': buffers['xs'].offset, |
|
|
|
|
'ys': buffers['ys'].offset, |
|
|
|
|
'pressures': buffers['pressures'].offset, |
|
|
|
|