render3d: scratch the frame uses is made with the state, not on first use
Render3dState's cam_planes, gpu_u_tmp, q_scratch, ov_nine_buf, the caster test's four points, ter_bw, ter_scr and water_saved default to their buffers (as ludic.anim's clip state does), so the lazy starts in cam_planes_update, gpu_tmp, terrain_height_smooth, ter_scratch, the water pass and gvk_startup_state go. q_euler makes its views of q_scratch once (guarded on the view now). Compiled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cd71da9330
commit
deb7c0d0c0
7 changed files with 13 additions and 22 deletions
|
|
@ -52,7 +52,6 @@ function cam_update(render3d_st: mut Render3dState) -> void {
|
|||
cam_planes_update(render3d_st)
|
||||
}
|
||||
function cam_planes_update(render3d_st: mut Render3dState) -> void {
|
||||
if render3d_st.cam_planes == null { render3d_st.cam_planes = floats(16) }
|
||||
let m = render3d_st.cam_vp_clean
|
||||
for p in 0 .. 4 {
|
||||
var r = 0
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ export state Render3dState {
|
|||
ac_oq_n: int = 0 # live entries; the array is kept and reused
|
||||
ac_oq_closed: bool = true
|
||||
ac_census_at: int = -2
|
||||
ac_lp0: floats = null
|
||||
ac_lpx: floats = null
|
||||
ac_lpy: floats = null
|
||||
ac_lpz: floats = null
|
||||
ac_lp0: floats = floats(3)
|
||||
ac_lpx: floats = floats(3)
|
||||
ac_lpy: floats = floats(3)
|
||||
ac_lpz: floats = floats(3)
|
||||
ac_cc_actors: int = 0
|
||||
ac_cc_draws: int = 0
|
||||
ac_cc_skinned: int = 0
|
||||
|
|
@ -43,7 +43,7 @@ export state Render3dState {
|
|||
cam_inv_vp_clean: floats = null
|
||||
cam_fwd: floats = null
|
||||
cam_right: floats = null
|
||||
cam_planes: floats = null
|
||||
cam_planes: floats = floats(16)
|
||||
day_on: bool = false
|
||||
day_hours: float = 0.0 # float bits, 0 .. 24
|
||||
day_light: float = 0.0 # 0 night .. 1 full day (float bits)
|
||||
|
|
@ -134,7 +134,7 @@ export state Render3dState {
|
|||
gpu_prog_ids: []int = null
|
||||
gpu_prog_keys: []string = null
|
||||
gpu_prog_cur: int = 0
|
||||
gpu_u_tmp: words = null
|
||||
gpu_u_tmp: words = words(4)
|
||||
gpu_cap_probed: bool = false
|
||||
gpu_cap_windows: bool = false # the advanced features exist on this platform at all
|
||||
gpu_cap_vulkan: bool = false # a Vulkan loader, an instance and a device
|
||||
|
|
@ -567,7 +567,7 @@ export state Render3dState {
|
|||
r3d_assets: string = "assets/polyhaven" # where the CC0 assets live
|
||||
r3d_root_found: bool = false
|
||||
r3d_prog_log: int = -1
|
||||
q_scratch: floats = null
|
||||
q_scratch: floats = floats(16)
|
||||
q_sy: floats = null # views of q_scratch's second, third and fourth
|
||||
q_sz: floats = null
|
||||
q_st: floats = null
|
||||
|
|
@ -692,7 +692,7 @@ export state Render3dState {
|
|||
stream_debug_n: int = 0
|
||||
stream_scratch: floats = null
|
||||
gvk_pipe_bufs: words = null # a pipeline's vertex buffers, while it is made
|
||||
ov_nine_buf: floats = null # ov_nine's corners and uvs
|
||||
ov_nine_buf: floats = floats(16) # ov_nine's corners and uvs
|
||||
gvk_ac: pointer = null # the VkAllocationCallbacks every create and destroy is given (R3D_ALLOC_VK=1)
|
||||
gvk_prime_b: words = null # buffers made since the frame began, read once so MoltenVK makes their
|
||||
gvk_prime_h: []long = null # Metal buffers now (gvk_prime), and their handles
|
||||
|
|
@ -807,10 +807,10 @@ export state Render3dState {
|
|||
ter_ortho_c: int = 3
|
||||
ter_h_scale: float = 0.0
|
||||
ter_o_scale: float = 0.0
|
||||
ter_bw: floats = null
|
||||
ter_bw: floats = floats(8)
|
||||
ter_wire: bool = false
|
||||
ter_printed: bool = false
|
||||
ter_scr: floats = null
|
||||
ter_scr: floats = floats(16)
|
||||
tex_w: int = 0 # the last decoded image
|
||||
tex_h: int = 0
|
||||
tex_channels: int = 0
|
||||
|
|
@ -837,7 +837,7 @@ export state Render3dState {
|
|||
water_on: bool = false
|
||||
water_refl: Target = null # the world mirrored in the surface, half resolution
|
||||
water_refl_div: int = 2 # R3D_REFLDIV overrides: 2 = half res, 4 = quarter
|
||||
water_saved: floats = null # the real camera's matrices, restored after the pass
|
||||
water_saved: floats = floats(16 * 4 + 3) # the real camera's matrices, restored after the pass
|
||||
water_saved_vp: floats = null # views of its second and third matrices
|
||||
water_saved_ivp: floats = null
|
||||
water_dumped: bool = false
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ function gpu_present(render3d_st: mut Render3dState) -> void { gvk_present(rende
|
|||
# the frame as it will be presented, to a binary PPM with the top row first; before gpu_present
|
||||
function gpu_screenshot(render3d_st: mut Render3dState, path: string) -> bool { return gvk_screenshot(render3d_st, path) }
|
||||
|
||||
function gpu_tmp(render3d_st: mut Render3dState) -> words { if render3d_st.gpu_u_tmp == null { render3d_st.gpu_u_tmp = words(4) }; return render3d_st.gpu_u_tmp }
|
||||
function gpu_tmp(render3d_st: mut Render3dState) -> words { return render3d_st.gpu_u_tmp }
|
||||
# float bits (IEEE singles in an int), like every other number in the renderer
|
||||
function u_f(render3d_st: mut Render3dState, loc: int, v: float) -> void { let t = gpu_tmp(render3d_st); t[0] = float_bits(v); gvk_u_set(render3d_st, loc, data_of(t), 4, 1) }
|
||||
function u_f2(render3d_st: mut Render3dState, loc: int, x: float, y: float) -> void { let t = gpu_tmp(render3d_st); t[0] = float_bits(x); t[1] = float_bits(y); gvk_u_set(render3d_st, loc, data_of(t), 8, 1) }
|
||||
|
|
|
|||
|
|
@ -763,12 +763,8 @@ function gvk_startup_state(render3d_st: mut Render3dState) -> void {
|
|||
for i in 0 .. 4096 { render3d_st.gvk_pc_last[i] = -1 }
|
||||
render3d_st.gg_rb = words(4); render3d_st.gg_cb = words(1); render3d_st.gg_bufs = words(3)
|
||||
render3d_st.gg_texs = words(3); render3d_st.gg_pr = words(48)
|
||||
if render3d_st.gpu_u_tmp == null { render3d_st.gpu_u_tmp = words(4) }
|
||||
if render3d_st.gpu_unit_2d == null {
|
||||
render3d_st.gpu_unit_2d = words(32)
|
||||
for i in 0 .. 32 { render3d_st.gpu_unit_2d[i] = -1 }
|
||||
}
|
||||
if render3d_st.cam_planes == null { render3d_st.cam_planes = floats(16) }
|
||||
if render3d_st.ov_nine_buf == null { render3d_st.ov_nine_buf = floats(16) }
|
||||
if render3d_st.ac_lp0 == null { render3d_st.ac_lp0 = floats(3); render3d_st.ac_lpx = floats(3); render3d_st.ac_lpy = floats(3); render3d_st.ac_lpz = floats(3) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@ function q_rotate(o: floats, q: floats, v: floats) -> void {
|
|||
}
|
||||
# pitch about X, yaw about Y, roll about Z, composed as yaw * pitch * roll
|
||||
function q_euler(render3d_st: mut Render3dState, o: floats, pitch: float, yaw: float, roll: float) -> void {
|
||||
if render3d_st.q_scratch == null {
|
||||
render3d_st.q_scratch = floats(16)
|
||||
if render3d_st.q_sy == null { # q_scratch is made with the state; its views once
|
||||
render3d_st.q_sy = view(render3d_st.q_scratch, 4, 4)
|
||||
render3d_st.q_sz = view(render3d_st.q_scratch, 8, 4)
|
||||
render3d_st.q_st = view(render3d_st.q_scratch, 12, 4)
|
||||
|
|
|
|||
|
|
@ -291,7 +291,6 @@ function terrain_height_fx(render3d_st: mut Render3dState, x: fixed, z: fixed) -
|
|||
function terrain_height_smooth(render3d_st: mut Render3dState, x: float, z: float) -> float {
|
||||
if render3d_st.ter_heights == null { return 0.0 }
|
||||
if render3d_st.ter_h_scale == 0.0 { render3d_st.ter_h_scale = float(TERRAIN_RES) / float(render3d_st.TERRAIN_HALF * 2) }
|
||||
if render3d_st.ter_bw == null { render3d_st.ter_bw = floats(8) }
|
||||
let scale = render3d_st.ter_h_scale
|
||||
let fx = (x - render3d_st.ter_ox + float(render3d_st.TERRAIN_HALF)) * scale - 0.5
|
||||
let fz = (z - render3d_st.ter_oz + float(render3d_st.TERRAIN_HALF)) * scale - 0.5
|
||||
|
|
@ -791,6 +790,5 @@ function terrain_reload(render3d_st: mut Render3dState, dem: string, emin: float
|
|||
}
|
||||
|
||||
function ter_scratch(render3d_st: mut Render3dState) -> floats {
|
||||
if render3d_st.ter_scr == null { render3d_st.ter_scr = floats(16) }
|
||||
return render3d_st.ter_scr
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ function water_reflection_pass(render3d_st: mut Render3dState) -> void {
|
|||
# this reflection is composited into is smaller than the drawable, and a reflection
|
||||
# rendered at the window's size would be paying for pixels the water never samples
|
||||
render3d_st.water_refl = target_new(render3d_st, render3d_st.post_w / render3d_st.water_refl_div, render3d_st.post_h / render3d_st.water_refl_div, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, true, GL_LINEAR)
|
||||
render3d_st.water_saved = floats(16 * 4 + 3)
|
||||
render3d_st.water_saved_vp = view(render3d_st.water_saved, 16, 16)
|
||||
render3d_st.water_saved_ivp = view(render3d_st.water_saved, 32, 16)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue