Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to wgpu4k native #308

Merged
merged 16 commits into from
Feb 15, 2025

Conversation

ygdrasil-io
Copy link
Contributor

The Triangle and Rotating Cube examples are working on Mac and Windows. However, other examples are still crashing when loading files. This is a mistake on my part, and I will address it as soon as possible.

@ygdrasil-io ygdrasil-io changed the title sitch to wgpu4k native switch to wgpu4k native Feb 12, 2025
Replaced outdated WebGPU binding imports and memory handling with updated equivalents from the newer ffi and io.ygdrasil.wgpu packages. This improves compatibility, clarity, and ensures the code adheres to updated APIs. Additionally, refactored buffer handling for better performance and maintainability.
Replaced deprecated WebGPU bindings with the latest `ffi` and `io.ygdrasil.wgpu` imports, ensuring compliance with modern APIs. Refactored memory allocation logic to utilize `memoryScope` for improved efficiency, reducing boilerplate and ensuring cleaner code. Simplified resource creation logic for pipelines, textures, buffers, and bind groups to enhance maintainability and error handling.
Extracted and improved mapping logic for device and surface configurations into dedicated utility functions. Simplified code around device requests, texture capabilities, and memory allocation, ensuring better modularity and maintainability. Updated related enums and helper methods to support refined mapping and data handling.
This commit replaces the wgpu-ffm and wgpu-natives modules with the ygdrasil wgpu library for native interop. Corresponding imports, dependencies, and initialization were updated or removed. This change simplifies the build configuration and consolidates the usage of native bindings.
This commit eliminates unnecessary debug println statements across various descriptor mapper functions, improving code cleanliness and reducing noise. The removed debug logs included outputting objects like render pass descriptors, color attachments, and other mapping-related entities.
Replaces direct calls to `wgpuBufferRelease` with the `destroy` method for better consistency. Additionally, removes redundant `destroy` call in `Mesh.release` to streamline resource cleanup.
The `writeFloats` calls in `put` methods now utilize the buffer's current position, ensuring accurate data placement. This resolves potential issues with incorrect positioning during data writes and improves consistency in buffer operations.
Updated `writeShorts` and `writeInts` calls to include the missing destination offset parameter (`0uL`). This ensures proper data writing behavior and prevents potential runtime issues.
Replaces `MemoryAllocator` usage with a new `allocateBuffer` function, simplifying memory management. Fixes incorrect byte offset calculations in buffer read/write operations by properly accounting for element size. These changes improve code clarity and correctness.
The `destroy` method calls were unnecessary as `release` already handles resource cleanup. This simplifies the code and ensures consistency in resource management.
Replaced direct segment handling with the updated `handler` approach to enhance consistency and maintainability. Adjusted logic in `wgpuQueueWriteTexture`, `dataBuffer`, and `getMappedRange` to comply with the new handler structure. This simplifies buffer operations and aligns with recent API changes.
@ygdrasil-io ygdrasil-io force-pushed the feature/wgpu4k-native branch from 1d48282 to 1b729e8 Compare February 13, 2025 21:49
@ygdrasil-io ygdrasil-io marked this pull request as ready for review February 13, 2025 21:50
@LeHaine
Copy link
Member

LeHaine commented Feb 14, 2025

I'm not getting any crashes, which is good, but for some reason none of the 3D examples are rendering anything on the JVM (SimpleGltf, PBR, ModelInstancing, MipMaps). All of the 2D examples seem to render fine.

I spent a little time debugging but couldn't find the cause yet but can spend some more later this evening.

@ygdrasil-io
Copy link
Contributor Author

I only tried the sample with the preconfigured XML task in the examples folder. I will check.

This change organizes the run configurations by moving example-related configurations into a more appropriate "Examples" folder. It improves clarity and consistency within the project structure.
Replaced `MemoryBuffer` with `MemorySegment` for more efficient and modern memory management. Simplified buffer operations by leveraging direct `MemorySegment` methods, and removed redundant allocation utilities. This change improves code clarity and aligns with the latest memory management practices in Java.
@ygdrasil-io
Copy link
Contributor Author

@LeHaine The issue was coming from the Buffer. I have rolled back this part in the last commit.
This can be reworked later when introducing Android.

Removed redundant `destroy()` method, consolidating functionality within `release()`. This simplifies the code and eliminates unnecessary indirection. No functionality has been altered.
@LeHaine
Copy link
Member

LeHaine commented Feb 15, 2025

@ygdrasil-io My mistake. I thought I had those all saved in the run configuration. Not sure how I missed those not being there for so long.

I did pull and went through everything and it all seems to be working nicely now for me!

@LeHaine LeHaine merged commit 5c25fb2 into littlektframework:master Feb 15, 2025
1 check passed
@ygdrasil-io ygdrasil-io deleted the feature/wgpu4k-native branch February 15, 2025 13:18
@LeHaine
Copy link
Member

LeHaine commented Feb 15, 2025

Nice work and thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants