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
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.
249 250 251 |
# File 'lib/wgpu/native_resource.rb', line 249 def label @label end |
Class Method Details
.included(base) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/wgpu/native_resource.rb', line 234 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.
280 281 282 283 |
# File 'lib/wgpu/native_resource.rb', line 280 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.
253 254 255 256 257 258 259 |
# File 'lib/wgpu/native_resource.rb', line 253 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.
268 269 270 271 272 273 274 275 |
# File 'lib/wgpu/native_resource.rb', line 268 def use raise ArgumentError, "block is required" unless block_given? ensure_not_released! yield self ensure release if block_given? && !released? end |