wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5ffe50ed02
commit
19fcf60599
459 changed files with 17862 additions and 17603 deletions
|
|
@ -13,98 +13,100 @@ program VkResources {
|
|||
property Marker { on: int = 1 }
|
||||
model Anchor { Marker }
|
||||
|
||||
var failures: int = 0
|
||||
unsafe function check(what: string, ok: bool) -> void {
|
||||
if ok { print(`vulkan: {what} ok`) } else { print(`vulkan: {what} FAILED`); failures += 1 }
|
||||
state VkResourcesState {
|
||||
failures: int = 0
|
||||
}
|
||||
unsafe function check(vk_resources_st: mut VkResourcesState, what: string, ok: bool) -> void {
|
||||
if ok { print(`vulkan: {what} ok`) } else { print(`vulkan: {what} FAILED`); vk_resources_st.failures += 1 }
|
||||
}
|
||||
|
||||
handler Boot phase Start {
|
||||
handler Boot(render3d_st: mut Render3dState, vk_resources_st: mut VkResourcesState) phase Start {
|
||||
spawn Anchor {}
|
||||
print(`vulkan: OpenGL names spliced (pixel scale {Gl.pixel_scale()})`)
|
||||
if not gvk_init() { print(`VKRES NONE: {gvk_why}`); quit() }
|
||||
if not gvk_init(render3d_st) { print(`VKRES NONE: {render3d_st.gvk_why}`); quit() }
|
||||
|
||||
# RGBA8 up and back, byte for byte
|
||||
let w = 64
|
||||
let h = 32
|
||||
let px = bytes(w * h * 4)
|
||||
for i in 0 .. w * h { px[i * 4] = i & 255; px[i * 4 + 1] = (i >> 8) & 255; px[i * 4 + 2] = (i * 7) & 255; px[i * 4 + 3] = 200 }
|
||||
let t1 = gvk_tex_new()
|
||||
check("RGBA8 storage with mips", gvk_tex_storage(t1, false, GL_RGBA8, w, h, 1, true))
|
||||
check("RGBA8 upload", gvk_tex_upload(t1, GL_RGBA8, w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE, px))
|
||||
check("RGBA8 mip chain (7 levels)", gvk_tex_levels[t1] == 7 and gvk_tex_mips(t1, w, h))
|
||||
let t1 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "RGBA8 storage with mips", gvk_tex_storage(render3d_st, t1, false, GL_RGBA8, w, h, 1, true))
|
||||
check(vk_resources_st, "RGBA8 upload", gvk_tex_upload(render3d_st, t1, GL_RGBA8, w, h, 1, GL_RGBA, GL_UNSIGNED_BYTE, px))
|
||||
check(vk_resources_st, "RGBA8 mip chain (7 levels)", render3d_st.gvk_tex_levels[t1] == 7 and gvk_tex_mips(render3d_st, t1, w, h))
|
||||
let back = bytes(w * h * 4)
|
||||
check("RGBA8 read-back call", gvk_tex_read(t1, GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, back))
|
||||
check(vk_resources_st, "RGBA8 read-back call", gvk_tex_read(render3d_st, t1, GL_RGBA8, w, h, GL_RGBA, GL_UNSIGNED_BYTE, back))
|
||||
var same = true
|
||||
for i in 0 .. w * h * 4 { if back[i] != px[i] { same = false } }
|
||||
check("RGBA8 read-back matches", same)
|
||||
check(vk_resources_st, "RGBA8 read-back matches", same)
|
||||
|
||||
# R32F, the terrain's height field path
|
||||
let hf = bytes(w * h * 4)
|
||||
for i in 0 .. w * h { Vk.put_i32(hf, i * 4, 0x40000000 + i) }
|
||||
let t2 = gvk_tex_new()
|
||||
check("R32F target", gvk_tex_storage(t2, false, GL_R32F, w, h, 1, false))
|
||||
check("R32F upload", gvk_tex_upload(t2, GL_R32F, w, h, 1, GL_RED, GL_FLOAT, hf))
|
||||
let t2 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "R32F target", gvk_tex_storage(render3d_st, t2, false, GL_R32F, w, h, 1, false))
|
||||
check(vk_resources_st, "R32F upload", gvk_tex_upload(render3d_st, t2, GL_R32F, w, h, 1, GL_RED, GL_FLOAT, hf))
|
||||
let hb = bytes(w * h * 4)
|
||||
check("R32F read-back call", gvk_tex_read(t2, GL_R32F, w, h, GL_RED, GL_FLOAT, hb))
|
||||
check(vk_resources_st, "R32F read-back call", gvk_tex_read(render3d_st, t2, GL_R32F, w, h, GL_RED, GL_FLOAT, hb))
|
||||
var hsame = true
|
||||
for i in 0 .. w * h * 4 { if hb[i] != hf[i] { hsame = false } }
|
||||
check("R32F read-back matches", hsame)
|
||||
check(vk_resources_st, "R32F read-back matches", hsame)
|
||||
|
||||
# RGB8 stored as RGBA, and an HDR image's float RGB into half floats
|
||||
let rgb = bytes(w * h * 3)
|
||||
for i in 0 .. w * h * 3 { rgb[i] = (i * 3) & 255 }
|
||||
let t3 = gvk_tex_new()
|
||||
check("SRGB8 expanded to RGBA", gvk_tex_storage(t3, false, GL_SRGB8, w, h, 1, true) and gvk_tex_upload(t3, GL_SRGB8, w, h, 1, GL_RGB, GL_UNSIGNED_BYTE, rgb))
|
||||
let t3 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "SRGB8 expanded to RGBA", gvk_tex_storage(render3d_st, t3, false, GL_SRGB8, w, h, 1, true) and gvk_tex_upload(render3d_st, t3, GL_SRGB8, w, h, 1, GL_RGB, GL_UNSIGNED_BYTE, rgb))
|
||||
let fl = bytes(w * h * 12)
|
||||
for i in 0 .. w * h * 3 { Vk.put_i32(fl, i * 4, 0x3FC00000) }
|
||||
let t4 = gvk_tex_new()
|
||||
check("RGB16F from floats (halved)", gvk_tex_storage(t4, false, GL_RGB16F, w, h, 1, true) and gvk_tex_upload(t4, GL_RGB16F, w, h, 1, GL_RGB, GL_FLOAT, fl))
|
||||
check("half of 1.5 is 0x3E00", gvk_half(0x3FC00000) == 0x3E00)
|
||||
let t4 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "RGB16F from floats (halved)", gvk_tex_storage(render3d_st, t4, false, GL_RGB16F, w, h, 1, true) and gvk_tex_upload(render3d_st, t4, GL_RGB16F, w, h, 1, GL_RGB, GL_FLOAT, fl))
|
||||
check(vk_resources_st, "half of 1.5 is 0x3E00", gvk_half(0x3FC00000) == 0x3E00)
|
||||
|
||||
# a 16-bit RGB PNG (a normal map): big-endian samples, swapped on upload, alpha filled opaque
|
||||
let n16 = bytes(w * h * 6)
|
||||
for i in 0 .. w * h * 3 { n16[i * 2] = (i >> 8) & 255; n16[i * 2 + 1] = i & 255 }
|
||||
let t7 = gvk_tex_new()
|
||||
gvk_unpack_swap = true
|
||||
check("RGB16 swapped upload", gvk_tex_storage(t7, false, GL_RGB16, w, h, 1, true) and gvk_tex_upload(t7, GL_RGB16, w, h, 1, GL_RGB, GL_UNSIGNED_SHORT, n16))
|
||||
gvk_unpack_swap = false
|
||||
let t7 = gvk_tex_new(render3d_st)
|
||||
render3d_st.gvk_unpack_swap = true
|
||||
check(vk_resources_st, "RGB16 swapped upload", gvk_tex_storage(render3d_st, t7, false, GL_RGB16, w, h, 1, true) and gvk_tex_upload(render3d_st, t7, GL_RGB16, w, h, 1, GL_RGB, GL_UNSIGNED_SHORT, n16))
|
||||
render3d_st.gvk_unpack_swap = false
|
||||
let b16 = bytes(w * h * 6)
|
||||
check("RGB16 read-back call", gvk_tex_read(t7, GL_RGB16, w, h, GL_RGB, GL_UNSIGNED_SHORT, b16))
|
||||
check(vk_resources_st, "RGB16 read-back call", gvk_tex_read(render3d_st, t7, GL_RGB16, w, h, GL_RGB, GL_UNSIGNED_SHORT, b16))
|
||||
var s16 = true
|
||||
for i in 0 .. w * h * 3 { if b16[i * 2] != (i & 255) or b16[i * 2 + 1] != ((i >> 8) & 255) { s16 = false } }
|
||||
check("RGB16 samples arrive little-endian", s16)
|
||||
check(vk_resources_st, "RGB16 samples arrive little-endian", s16)
|
||||
|
||||
# the shadow cascades: a depth array, and a render-sized half-float target with no pixels
|
||||
let t5 = gvk_tex_new()
|
||||
check("D32 array of 4", gvk_tex_storage(t5, true, GL_DEPTH_COMPONENT32F, 256, 256, 4, false))
|
||||
let t6 = gvk_tex_new()
|
||||
check("RGBA16F target", gvk_tex_storage(t6, false, GL_RGBA16F, 320, 180, 1, false))
|
||||
let t5 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "D32 array of 4", gvk_tex_storage(render3d_st, t5, true, GL_DEPTH_COMPONENT32F, 256, 256, 4, false))
|
||||
let t6 = gvk_tex_new(render3d_st)
|
||||
check(vk_resources_st, "RGBA16F target", gvk_tex_storage(render3d_st, t6, false, GL_RGBA16F, 320, 180, 1, false))
|
||||
|
||||
# the samplers the renderer asks for, and that asking twice returns the same one
|
||||
let s1 = gvk_sampler(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT, 0, 0x41800000)
|
||||
let s2 = gvk_sampler(GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 0)
|
||||
let s3 = gvk_sampler(GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER, GL_LEQUAL, 0)
|
||||
let s4 = gvk_sampler(GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 0)
|
||||
let again = gvk_sampler(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT, 0, 0x41800000)
|
||||
check("four samplers made", s1 != 0 and s2 != 0 and s3 != 0 and s4 != 0 and len(gvk_smp) == 4)
|
||||
check("a sampler asked for twice is one sampler", again == s1)
|
||||
let s1 = gvk_sampler(render3d_st, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT, 0, 0x41800000)
|
||||
let s2 = gvk_sampler(render3d_st, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 0)
|
||||
let s3 = gvk_sampler(render3d_st, GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_BORDER, GL_CLAMP_TO_BORDER, GL_LEQUAL, 0)
|
||||
let s4 = gvk_sampler(render3d_st, GL_NEAREST, GL_NEAREST, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, 0, 0)
|
||||
let again = gvk_sampler(render3d_st, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT, 0, 0x41800000)
|
||||
check(vk_resources_st, "four samplers made", s1 != 0 and s2 != 0 and s3 != 0 and s4 != 0 and len(render3d_st.gvk_smp) == 4)
|
||||
check(vk_resources_st, "a sampler asked for twice is one sampler", again == s1)
|
||||
|
||||
# a buffer filled, filled again smaller (kept), then larger (grown)
|
||||
let b = gvk_buf_new()
|
||||
let b = gvk_buf_new(render3d_st)
|
||||
let data = bytes(4096)
|
||||
for i in 0 .. 4096 { data[i] = i & 255 }
|
||||
check("buffer upload", gvk_buf_upload(b, 1024, data))
|
||||
let first = gvk_buf[b]
|
||||
check("a smaller upload keeps the buffer", gvk_buf_upload(b, 512, data) and gvk_buf[b] == first)
|
||||
check("a larger upload grows it", gvk_buf_upload(b, 4096, data) and gvk_buf_size[b] >= 4096)
|
||||
check(vk_resources_st, "buffer upload", gvk_buf_upload(render3d_st, b, 1024, data))
|
||||
let first = render3d_st.gvk_buf[b]
|
||||
check(vk_resources_st, "a smaller upload keeps the buffer", gvk_buf_upload(render3d_st, b, 512, data) and render3d_st.gvk_buf[b] == first)
|
||||
check(vk_resources_st, "a larger upload grows it", gvk_buf_upload(render3d_st, b, 4096, data) and render3d_st.gvk_buf_size[b] >= 4096)
|
||||
|
||||
for t in 1 .. 8 { gvk_tex_release(t) }
|
||||
gvk_buf_release(b)
|
||||
for i in 0 .. len(gvk_smp) { Vk.destroy_sampler(gvk_dev, gvk_smp[i], null) }
|
||||
print(`vulkan: {gvk_n_allocs} allocations left after freeing`)
|
||||
check("every allocation freed", gvk_n_allocs == 0)
|
||||
gvk_shutdown()
|
||||
if failures == 0 { print("VKRES OK") } else { print(`VKRES FAILED ({failures})`) }
|
||||
for t in 1 .. 8 { gvk_tex_release(render3d_st, t) }
|
||||
gvk_buf_release(render3d_st, b)
|
||||
for i in 0 .. len(render3d_st.gvk_smp) { Vk.destroy_sampler(render3d_st.gvk_dev, render3d_st.gvk_smp[i], null) }
|
||||
print(`vulkan: {render3d_st.gvk_n_allocs} allocations left after freeing`)
|
||||
check(vk_resources_st, "every allocation freed", render3d_st.gvk_n_allocs == 0)
|
||||
gvk_shutdown(render3d_st)
|
||||
if vk_resources_st.failures == 0 { print("VKRES OK") } else { print(`VKRES FAILED ({vk_resources_st.failures})`) }
|
||||
quit()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue