From 4f7d2667b0b12c7d7a09dc1db00a4dbc16b51890 Mon Sep 17 00:00:00 2001 From: Anton Oreskin Date: Wed, 30 Sep 2026 02:24:29 +0200 Subject: [PATCH] Use GLFW v2 and Vulkan v3 in particles example --- .github/workflows/generate-and-test.yml | 12 ++++++------ examples/vulkan_particles/README.md | 8 ++++---- examples/vulkan_particles/fd_abi.v | 17 ++++------------- examples/vulkan_particles/swapchain.v | 8 +++----- examples/vulkan_particles/v.mod | 2 +- examples/vulkan_particles/window_smoke.v | 17 ++++++----------- 6 files changed, 24 insertions(+), 40 deletions(-) diff --git a/.github/workflows/generate-and-test.yml b/.github/workflows/generate-and-test.yml index fd340e0..fbfb29c 100644 --- a/.github/workflows/generate-and-test.yml +++ b/.github/workflows/generate-and-test.yml @@ -17,8 +17,8 @@ env: V3_COMMIT: f59b886d2564e37d8626d715236fdfa928e13dda V3_VC_COMMIT: 4598bc7e4894c154b27391e4442005fff2fbbd68 V3_TCC_COMMIT: d6e7ac1b1bcc98aed734a6ecbfa8509f24606c74 - VULKAN_REF: v2.0.0 - GLFW_COMMIT: 3d7c1ddacb7215a7bbeb5fef0d7a68c90ba392ed + VULKAN_REF: v3.2.0 + GLFW_REF: v2.0.0 jobs: generate-and-test: @@ -50,7 +50,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: antono2/glfw - ref: ${{ env.GLFW_COMMIT }} + ref: ${{ env.GLFW_REF }} path: .ci-modules/glfw - uses: prantlf/setup-v-action@92f20bea50d2c9931a28c96bb4997a3c7357baf0 # v4 with: @@ -90,7 +90,7 @@ jobs: run: | sudo apt-get install --yes libvulkan-dev libvulkan-volk-dev libglfw3-dev mesa-vulkan-drivers vulkan-validationlayers xauth xvfb test "$(git -C .ci-modules/vulkan describe --tags --exact-match)" = "$VULKAN_REF" - test "$(git -C .ci-modules/glfw rev-parse HEAD)" = "$GLFW_COMMIT" + test "$(git -C .ci-modules/glfw describe --tags --exact-match)" = "$GLFW_REF" install -d "$HOME/.vmodules/antono2/vulkan" "$HOME/.vmodules/antono2/glfw" cp -a .ci-modules/vulkan/. "$HOME/.vmodules/antono2/vulkan/" cp -a .ci-modules/glfw/. "$HOME/.vmodules/antono2/glfw/" @@ -247,7 +247,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: repository: antono2/glfw - ref: ${{ env.GLFW_COMMIT }} + ref: ${{ env.GLFW_REF }} path: .ci-modules/glfw - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: @@ -360,7 +360,7 @@ jobs: cp src/opencl.v src/convenience.v src/ownership.v src/program.v src/event.v src/image.v src/svm.v src/capabilities.v src/external_interop.v v.mod "$HOME/.vmodules/antono2/opencl/" mkdir -p "$HOME/.vmodules/antono2/opencl/include/CL" cp include/CL/opencl.h "$HOME/.vmodules/antono2/opencl/include/CL/" - v -cc gcc -d vulkan_fd_i32 -o "$RUNNER_TEMP/vulkan-particles" examples/vulkan_particles + v -cc gcc -o "$RUNNER_TEMP/vulkan-particles" examples/vulkan_particles required-checks: name: required-checks diff --git a/examples/vulkan_particles/README.md b/examples/vulkan_particles/README.md index e590645..94625c6 100644 --- a/examples/vulkan_particles/README.md +++ b/examples/vulkan_particles/README.md @@ -28,9 +28,9 @@ checked-in SPIR-V after editing GLSL with `./compile_shaders.sh`. Install the example-only V modules and Linux development packages before building from source: ```sh -v install antono2.opencl@v1.0.0 -v install antono2.vulkan@v2.0.0 -v install antono2.glfw +v install antono2.opencl@v1.0.1 +v install antono2.vulkan@v3.2.0 +v install antono2.glfw@v2.0.0 sudo apt install ocl-icd-opencl-dev libvulkan-dev libglfw3-dev ``` @@ -52,7 +52,7 @@ v -cc gcc run examples/vulkan_particles --particles=4096 v -cc tcc run examples/vulkan_particles --particles=4096 ``` -TinyCC requires `antono2.vulkan` v2.0.0 for its deep-bound Volk loader. +The pinned Vulkan release provides the deep-bound Volk loader used by TinyCC. ## Tested hardware diff --git a/examples/vulkan_particles/fd_abi.v b/examples/vulkan_particles/fd_abi.v index eee8db7..8d8784b 100644 --- a/examples/vulkan_particles/fd_abi.v +++ b/examples/vulkan_particles/fd_abi.v @@ -2,21 +2,12 @@ module main import antono2.vulkan as vk -// Vulkan registry revisions have described POSIX file descriptors as both -// C int and int32_t. These pointer types have the same ABI but distinct V -// types. Select the matching raw declaration in the dependency-master lane. +// Vulkan v3.2.0 exposes POSIX file descriptors as i32. C int has the same +// ABI here but is a distinct V type, so cast the pointer at this boundary. fn export_vk_memory_fd(device vk.Device, info &vk.MemoryGetFdInfoKHR, fd &int) vk.Result { - $if vulkan_fd_i32 ? { - return vk.get_memory_fd_khr(device, info, unsafe { &i32(fd) }) - } $else { - return vk.get_memory_fd_khr(device, info, fd) - } + return vk.get_memory_fd_khr(device, info, unsafe { &i32(fd) }) } fn export_vk_semaphore_fd(device vk.Device, info &vk.SemaphoreGetFdInfoKHR, fd &int) vk.Result { - $if vulkan_fd_i32 ? { - return vk.get_semaphore_fd_khr(device, info, unsafe { &i32(fd) }) - } $else { - return vk.get_semaphore_fd_khr(device, info, fd) - } + return vk.get_semaphore_fd_khr(device, info, unsafe { &i32(fd) }) } diff --git a/examples/vulkan_particles/swapchain.v b/examples/vulkan_particles/swapchain.v index 36375dc..6441b10 100644 --- a/examples/vulkan_particles/swapchain.v +++ b/examples/vulkan_particles/swapchain.v @@ -122,12 +122,10 @@ fn choose_extent(capabilities vk.SurfaceCapabilitiesKHR, window &glfw.Window) vk if capabilities.currentExtent.width != max_u32 { return capabilities.currentExtent } - mut width := i32(0) - mut height := i32(0) - glfw.get_framebuffer_size(window, &width, &height) + framebuffer := glfw.framebuffer_size(window) return vk.Extent2D{ - width: clamp_u32(u32(width), capabilities.minImageExtent.width, capabilities.maxImageExtent.width) - height: clamp_u32(u32(height), capabilities.minImageExtent.height, capabilities.maxImageExtent.height) + width: clamp_u32(u32(framebuffer.width), capabilities.minImageExtent.width, capabilities.maxImageExtent.width) + height: clamp_u32(u32(framebuffer.height), capabilities.minImageExtent.height, capabilities.maxImageExtent.height) } } diff --git a/examples/vulkan_particles/v.mod b/examples/vulkan_particles/v.mod index f80fc7c..276c56c 100644 --- a/examples/vulkan_particles/v.mod +++ b/examples/vulkan_particles/v.mod @@ -3,5 +3,5 @@ Module { description: 'OpenCL particle simulation with a Vulkan renderer' version: '0.1.0' license: 'MIT' - dependencies: ['antono2.opencl@v1.0.1', 'antono2.vulkan@v2.0.0', 'antono2.glfw'] + dependencies: ['antono2.opencl@v1.0.1', 'antono2.vulkan@v3.2.0', 'antono2.glfw@v2.0.0'] } diff --git a/examples/vulkan_particles/window_smoke.v b/examples/vulkan_particles/window_smoke.v index 845f697..e12fe51 100644 --- a/examples/vulkan_particles/window_smoke.v +++ b/examples/vulkan_particles/window_smoke.v @@ -33,11 +33,7 @@ fn window_device_loop(compute &Compute, particle_count usize, use_zero_copy bool return error('GLFW cannot find a Vulkan loader') } glfw.window_hint(glfw.client_api, glfw.no_api) - window := glfw.create_window(960, 640, 'Vulkan + OpenCL particles', unsafe { nil }, - unsafe { nil }) - if isnil(window) { - return error('GLFW window creation failed') - } + window := glfw.create_windowed(960, 640, 'Vulkan + OpenCL particles')! defer { glfw.destroy_window(window) } if vk.initialize_loader() != vk.Result.success { @@ -231,14 +227,13 @@ fn window_device_loop(compute &Compute, particle_count usize, use_zero_copy bool pipeline.destroy(device) frames.destroy(device) swapchain.destroy(device) - mut width := i32(0) - mut height := i32(0) - for width == 0 || height == 0 { - glfw.get_framebuffer_size(window, &width, &height) - if width == 0 || height == 0 { + for { + framebuffer := glfw.framebuffer_size(window) + if framebuffer.width > 0 && framebuffer.height > 0 { + break + } glfw.poll_events() time.sleep(16 * time.millisecond) - } } swapchain = create_swapchain(physical, device, surface, window)! frames = create_frame_resources(device, queue_family, &swapchain)!