wgpu 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bbbaca4a43bec5b75eef13a782fd6effed0764d28c236918f21423ceab570c3c
4
+ data.tar.gz: e3d50d0335f0195fde48d9cbb157da88c399ddbc6a53ca52f60b2526436cced4
5
+ SHA512:
6
+ metadata.gz: 30330a5b4071440c99efc0f33feda10ef375a8905bd67997b586e655cd0c7bcddda1f74e1f023efc7050756a2e6a0639f6dc2df83ecb8c9136a9b9e9fb8b7a88
7
+ data.tar.gz: d950a6fac08c63226ef07a659f99b80deaf522722a6bc5790e948548f42cc74e6e7b3d3d715d03332adab72b914127afde44776c1df1709f049903942d91bcdf
data/LICENSE-APACHE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Yudai Takada
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
data/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yudai Takada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # WGPU Ruby
2
+
3
+ Ruby bindings for [WebGPU](https://www.w3.org/TR/webgpu/) via [wgpu-native](https://github.com/gfx-rs/wgpu-native).
4
+
5
+ ## Features
6
+
7
+ - Complete WebGPU API bindings using Ruby-FFI
8
+ - GPU compute shaders (GPGPU)
9
+ - Cross-platform support (macOS, Linux, Windows)
10
+ - Automatic wgpu-native library download on gem install
11
+
12
+ ## Requirements
13
+
14
+ - Ruby 3.0+
15
+ - Supported platforms:
16
+ - macOS (x86_64, arm64)
17
+ - Linux (x86_64, aarch64)
18
+ - Windows (x86_64)
19
+
20
+ ## Installation
21
+
22
+ Add to your Gemfile:
23
+
24
+ ```ruby
25
+ gem 'wgpu'
26
+ ```
27
+
28
+ Then run:
29
+
30
+ ```bash
31
+ bundle install
32
+ ```
33
+
34
+ Or install directly:
35
+
36
+ ```bash
37
+ gem install wgpu
38
+ ```
39
+
40
+ The wgpu-native library is automatically downloaded from GitHub Releases during installation.
41
+
42
+ ### Custom wgpu-native Build
43
+
44
+ To use a custom build of wgpu-native:
45
+
46
+ ```bash
47
+ export WGPU_LIB_PATH=/path/to/libwgpu_native.so
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ### Basic Setup
53
+
54
+ ```ruby
55
+ require 'wgpu'
56
+
57
+ instance = WGPU::Instance.new
58
+ adapter = instance.request_adapter(power_preference: :high_performance)
59
+ device = adapter.request_device
60
+ queue = device.queue
61
+
62
+ puts "Using: #{adapter.info[:device]} (#{adapter.info[:backend_type]})"
63
+ ```
64
+
65
+ ### Compute Shader Example
66
+
67
+ ```ruby
68
+ require 'wgpu'
69
+
70
+ shader_code = <<~WGSL
71
+ @group(0) @binding(0) var<storage, read_write> data: array<f32>;
72
+
73
+ @compute @workgroup_size(64)
74
+ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
75
+ data[id.x] = data[id.x] * 2.0;
76
+ }
77
+ WGSL
78
+
79
+ instance = WGPU::Instance.new
80
+ adapter = instance.request_adapter
81
+ device = adapter.request_device
82
+ queue = device.queue
83
+
84
+ # Create buffer with initial data
85
+ input_data = (0...256).map(&:to_f)
86
+ buffer = device.create_buffer(
87
+ size: input_data.size * 4,
88
+ usage: [:storage, :copy_src, :copy_dst],
89
+ mapped_at_creation: true
90
+ )
91
+ buffer.mapped_range.write_floats(input_data)
92
+ buffer.unmap
93
+
94
+ # Create shader and pipeline
95
+ shader = device.create_shader_module(code: shader_code)
96
+
97
+ bind_group_layout = device.create_bind_group_layout(
98
+ entries: [{ binding: 0, visibility: :compute, buffer: { type: :storage } }]
99
+ )
100
+
101
+ bind_group = device.create_bind_group(
102
+ layout: bind_group_layout,
103
+ entries: [{ binding: 0, buffer: buffer, offset: 0, size: buffer.size }]
104
+ )
105
+
106
+ pipeline_layout = device.create_pipeline_layout(bind_group_layouts: [bind_group_layout])
107
+ pipeline = device.create_compute_pipeline(
108
+ layout: pipeline_layout,
109
+ compute: { module: shader, entry_point: "main" }
110
+ )
111
+
112
+ # Execute compute pass
113
+ encoder = device.create_command_encoder
114
+ pass = encoder.begin_compute_pass
115
+ pass.set_pipeline(pipeline)
116
+ pass.set_bind_group(0, bind_group)
117
+ pass.dispatch_workgroups(input_data.size / 64)
118
+ pass.end_pass
119
+ queue.submit([encoder.finish])
120
+
121
+ # Read results
122
+ result = queue.read_buffer(buffer, device: device)
123
+ output_data = result.unpack("f*")
124
+
125
+ puts output_data[0, 10].inspect
126
+ # => [0.0, 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0]
127
+ ```
128
+
129
+ ## Examples
130
+
131
+ See the `examples/` directory for more complete examples:
132
+
133
+ - `01_adapter_info.rb` - Query GPU adapter information
134
+ - `02_compute_basic.rb` - Basic compute shader
135
+ - `03_buffer_operations.rb` - Buffer read/write operations
136
+ - `04_matrix_multiply.rb` - GPU matrix multiplication
137
+ - `05_image_blur.rb` - Image processing with box filter
138
+ - `06_parallel_reduction.rb` - Parallel sum reduction
139
+
140
+ Run an example:
141
+
142
+ ```bash
143
+ bundle exec ruby examples/02_compute_basic.rb
144
+ ```
145
+
146
+ ## API Overview
147
+
148
+ ### Core Objects
149
+
150
+ | Class | Description |
151
+ |-------|-------------|
152
+ | `WGPU::Instance` | Entry point for WebGPU |
153
+ | `WGPU::Adapter` | Represents a GPU adapter |
154
+ | `WGPU::Device` | Logical device for GPU operations |
155
+ | `WGPU::Queue` | Command submission queue |
156
+
157
+ ### Resources
158
+
159
+ | Class | Description |
160
+ |-------|-------------|
161
+ | `WGPU::Buffer` | GPU buffer for data storage |
162
+ | `WGPU::Texture` | GPU texture |
163
+ | `WGPU::TextureView` | View into a texture |
164
+ | `WGPU::Sampler` | Texture sampling configuration |
165
+
166
+ ### Pipeline
167
+
168
+ | Class | Description |
169
+ |-------|-------------|
170
+ | `WGPU::ShaderModule` | Compiled WGSL shader |
171
+ | `WGPU::ComputePipeline` | Compute shader pipeline |
172
+ | `WGPU::RenderPipeline` | Render pipeline |
173
+ | `WGPU::BindGroup` | Resource bindings for shaders |
174
+ | `WGPU::BindGroupLayout` | Layout definition for bind groups |
175
+ | `WGPU::PipelineLayout` | Pipeline layout definition |
176
+
177
+ ### Commands
178
+
179
+ | Class | Description |
180
+ |-------|-------------|
181
+ | `WGPU::CommandEncoder` | Records GPU commands |
182
+ | `WGPU::CommandBuffer` | Encoded commands ready to submit |
183
+ | `WGPU::ComputePass` | Compute pass encoder |
184
+ | `WGPU::RenderPass` | Render pass encoder |
185
+
186
+ ## Development
187
+
188
+ ```bash
189
+ git clone https://github.com/ydah/wgpu-ruby.git
190
+ cd wgpu-ruby
191
+ bundle install
192
+ bundle exec rake spec
193
+ ```
194
+
195
+ ## Contributing
196
+
197
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/wgpu-ruby.
198
+
199
+ ## License
200
+
201
+ Licensed under either of
202
+
203
+ - [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
204
+ - [MIT License](http://opensource.org/licenses/MIT)
205
+
206
+ at your option.
207
+
208
+ ## References
209
+
210
+ - [WebGPU Specification](https://www.w3.org/TR/webgpu/)
211
+ - [WGSL Specification](https://www.w3.org/TR/WGSL/)
212
+ - [wgpu-native](https://github.com/gfx-rs/wgpu-native)
213
+ - [wgpu (Rust)](https://github.com/gfx-rs/wgpu)
data/ext/wgpu/Makefile ADDED
@@ -0,0 +1,7 @@
1
+ .PHONY: install clean
2
+
3
+ install:
4
+ @echo "wgpu-native is ready"
5
+
6
+ clean:
7
+ @echo "Nothing to clean"
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ WGPU_VERSION = "v27.0.4.0"
8
+ GITHUB_RELEASE_URL = "https://github.com/gfx-rs/wgpu-native/releases/download/#{WGPU_VERSION}"
9
+
10
+ PLATFORM_MAP = {
11
+ /x86_64-linux/ => { file: "wgpu-linux-x86_64-release.zip", lib: "libwgpu_native.so" },
12
+ /aarch64-linux/ => { file: "wgpu-linux-aarch64-release.zip", lib: "libwgpu_native.so" },
13
+ /x86_64-darwin/ => { file: "wgpu-macos-x86_64-release.zip", lib: "libwgpu_native.dylib" },
14
+ /arm64-darwin/ => { file: "wgpu-macos-aarch64-release.zip", lib: "libwgpu_native.dylib" },
15
+ /mingw|mswin/ => { file: "wgpu-windows-x86_64-msvc-release.zip", lib: "wgpu_native.dll" }
16
+ }.freeze
17
+
18
+ def detect_platform
19
+ PLATFORM_MAP.each do |pattern, info|
20
+ return info if RUBY_PLATFORM =~ pattern
21
+ end
22
+ abort "Unsupported platform: #{RUBY_PLATFORM}\nSupported: #{PLATFORM_MAP.keys.map(&:inspect).join(", ")}"
23
+ end
24
+
25
+ def cache_dir
26
+ File.join(Dir.home, ".cache", "wgpu-ruby", WGPU_VERSION)
27
+ end
28
+
29
+ def windows?
30
+ RUBY_PLATFORM =~ /mingw|mswin/
31
+ end
32
+
33
+ def curl_available?
34
+ if windows?
35
+ system("where curl >nul 2>&1")
36
+ else
37
+ system("which curl >/dev/null 2>&1")
38
+ end
39
+ end
40
+
41
+ def download_with_curl(url, dest)
42
+ system("curl", "-fsSL", "-o", dest, url)
43
+ end
44
+
45
+ def download_with_ruby(url, dest, redirects = 5)
46
+ raise "Too many redirects" if redirects == 0
47
+
48
+ uri = URI.parse(url)
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ http.use_ssl = (uri.scheme == "https")
51
+ http.open_timeout = 10
52
+ http.read_timeout = 120
53
+
54
+ request = Net::HTTP::Get.new(uri.request_uri)
55
+
56
+ http.request(request) do |response|
57
+ case response
58
+ when Net::HTTPRedirection
59
+ download_with_ruby(response["location"], dest, redirects - 1)
60
+ when Net::HTTPSuccess
61
+ File.open(dest, "wb") do |file|
62
+ response.read_body { |chunk| file.write(chunk) }
63
+ end
64
+ else
65
+ return false
66
+ end
67
+ end
68
+ true
69
+ end
70
+
71
+ def download_file(url, dest)
72
+ return if curl_available? && download_with_curl(url, dest)
73
+ return if download_with_ruby(url, dest)
74
+
75
+ abort "Download failed: #{url}"
76
+ end
77
+
78
+ def extract_with_rubyzip(zip_path, dest_dir)
79
+ require "zip"
80
+ Zip::File.open(zip_path) do |zip_file|
81
+ zip_file.each do |entry|
82
+ dest_path = File.join(dest_dir, entry.name)
83
+ FileUtils.mkdir_p(File.dirname(dest_path))
84
+ entry.extract(dest_path) { true }
85
+ end
86
+ end
87
+ true
88
+ rescue LoadError
89
+ false
90
+ end
91
+
92
+ def extract_with_powershell(zip_path, dest_dir)
93
+ return false unless windows?
94
+
95
+ system("powershell", "-Command", "Expand-Archive -Force -Path '#{zip_path}' -DestinationPath '#{dest_dir}'")
96
+ end
97
+
98
+ def extract_with_unzip(zip_path, dest_dir)
99
+ system("unzip", "-o", "-q", zip_path, "-d", dest_dir)
100
+ end
101
+
102
+ def extract_zip(zip_path, dest_dir)
103
+ return if extract_with_rubyzip(zip_path, dest_dir)
104
+ return if windows? && extract_with_powershell(zip_path, dest_dir)
105
+ return if extract_with_unzip(zip_path, dest_dir)
106
+
107
+ abort "Failed to extract zip. Please install 'rubyzip' gem."
108
+ end
109
+
110
+ def lib_dir
111
+ File.join(cache_dir, "lib")
112
+ end
113
+
114
+ def download_wgpu_native
115
+ platform = detect_platform
116
+ lib_path = File.join(lib_dir, platform[:lib])
117
+
118
+ if File.exist?(lib_path)
119
+ puts "wgpu-native already cached at #{lib_path}"
120
+ return lib_path
121
+ end
122
+
123
+ FileUtils.mkdir_p(cache_dir)
124
+
125
+ url = "#{GITHUB_RELEASE_URL}/#{platform[:file]}"
126
+ zip_path = File.join(cache_dir, platform[:file])
127
+
128
+ puts "Downloading wgpu-native #{WGPU_VERSION} from GitHub..."
129
+ puts " URL: #{url}"
130
+ download_file(url, zip_path)
131
+
132
+ puts "Extracting to #{cache_dir}..."
133
+ extract_zip(zip_path, cache_dir)
134
+
135
+ FileUtils.rm_f(zip_path)
136
+
137
+ unless File.exist?(lib_path)
138
+ abort "Failed to find #{platform[:lib]} after extraction"
139
+ end
140
+
141
+ puts "wgpu-native installed successfully!"
142
+ lib_path
143
+ end
144
+
145
+ if ENV["WGPU_LIB_PATH"]
146
+ puts "Using custom wgpu-native from WGPU_LIB_PATH: #{ENV["WGPU_LIB_PATH"]}"
147
+ else
148
+ download_wgpu_native
149
+ end
150
+
151
+ File.write("Makefile", <<~MAKEFILE)
152
+ .PHONY: install clean
153
+
154
+ install:
155
+ \t@echo "wgpu-native is ready"
156
+
157
+ clean:
158
+ \t@echo "Nothing to clean"
159
+ MAKEFILE
160
+
161
+ puts "Done!"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WGPU
4
+ class CommandBuffer
5
+ attr_reader :handle
6
+
7
+ def initialize(handle)
8
+ @handle = handle
9
+ end
10
+
11
+ def release
12
+ return if @handle.null?
13
+ Native.wgpuCommandBufferRelease(@handle)
14
+ @handle = FFI::Pointer::NULL
15
+ end
16
+ end
17
+ end