Module: WGPU::NativeResource
- Included in:
- Adapter, BindGroup, BindGroupLayout, Buffer, CanvasContext, CommandBuffer, CommandEncoder, ComputePass, ComputePipeline, Device, Instance, PipelineLayout, QuerySet, Queue, RenderBundle, RenderBundleEncoder, RenderPass, RenderPipeline, Sampler, ShaderModule, Surface, Texture, TextureView
- Defined in:
- lib/wgpu/native_resource.rb,
sig/wgpu.rbs
Defined Under Namespace
Modules: ClassMethods, Lifecycle
Constant Summary collapse
- GUARDED_METHOD_EXEMPTIONS =
[:initialize, :release, :released?, :handle, :label, :inspect].freeze
Instance Attribute Summary collapse
-
#label ⇒ String?
readonly
Returns the value of attribute label.
Class Method Summary collapse
-
.checked_handle(resource, expected_class:) ⇒ Object
Validates resource arguments before passing their handles to FFI.
- .included(base) ⇒ Object
Instance Method Summary collapse
-
#inspect ⇒ String
Returns a concise lifecycle-oriented representation.
-
#release ⇒ void
Releases the native handle and unregisters its leak-tracking entry.
-
#released? ⇒ Boolean
Reports whether the native handle has been released or is null.
-
#use {|resource| ... } ⇒ Object
Yields this wrapper and always releases it when the block exits.
Instance Attribute Details
#label ⇒ String? (readonly)
Returns the value of attribute label.
261 262 263 |
# File 'lib/wgpu/native_resource.rb', line 261 def label @label end |
Class Method Details
.checked_handle(resource, expected_class:) ⇒ Object
Validates resource arguments before passing their handles to FFI.
186 187 188 189 190 191 192 |
# File 'lib/wgpu/native_resource.rb', line 186 def self.checked_handle(resource, expected_class:) unless resource.is_a?(expected_class) raise TypeError, "expected #{expected_class}, got #{resource.class}" end resource.send(:ensure_not_released!) resource.handle end |
.included(base) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/wgpu/native_resource.rb', line 246 def self.included(base) guard = Module.new base.public_instance_methods(false).each do |method_name| next if GUARDED_METHOD_EXEMPTIONS.include?(method_name) guard.define_method(method_name) do |*args, **kwargs, &block| ensure_not_released! super(*args, **kwargs, &block) end end base.extend(ClassMethods) base.prepend(guard) base.prepend(Lifecycle) end |
Instance Method Details
#inspect ⇒ String
Returns a concise lifecycle-oriented representation.
292 293 294 295 |
# File 'lib/wgpu/native_resource.rb', line 292 def inspect label_text = @label ? " label=#{@label.inspect}" : "" "#<#{self.class}#{label_text} released=#{released?}>" end |
#release ⇒ void
This method returns an undefined value.
Releases the native handle and unregisters its leak-tracking entry.
104 |
# File 'sig/wgpu.rbs', line 104
def release: () -> void
|
#released? ⇒ Boolean
Reports whether the native handle has been released or is null.
265 266 267 268 269 270 271 |
# File 'lib/wgpu/native_resource.rb', line 265 def released? return true if @released return false unless instance_variable_defined?(:@handle) return true if @handle.nil? @handle.respond_to?(:null?) && @handle.null? end |
#use {|resource| ... } ⇒ Object
Yields this wrapper and always releases it when the block exits.
This is Ruby convenience API; WebGPU itself has no block-scoped resource primitive.
280 281 282 283 284 285 286 287 |
# File 'lib/wgpu/native_resource.rb', line 280 def use raise ArgumentError, "block is required" unless block_given? ensure_not_released! yield self ensure release if block_given? && !released? end |