Class: WGPU::ComputePipeline

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/pipeline/compute_pipeline.rb,
sig/wgpu.rbs

Constant Summary

Constants included from NativeResource

NativeResource::GUARDED_METHOD_EXEMPTIONS

Instance Attribute Summary collapse

Attributes included from NativeResource

#label

Instance Method Summary collapse

Methods included from NativeResource

included, #inspect, #released?, #use

Constructor Details

#initialize(device, label: nil, layout:, compute:) ⇒ ComputePipeline

Creates a compute pipeline.

Parameters:

  • device (Device)

    owning device

  • layout (PipelineLayout, :auto, nil)

    pipeline layout

  • compute (Hash)

    programmable compute stage descriptor

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wgpu/pipeline/compute_pipeline.rb', line 12

def initialize(device, label: nil, layout:, compute:)
  @device = device
  desc, @pointers = build_descriptor(label:, layout:, compute:)

  device.push_error_scope(:validation)
  @handle = Native.wgpuDeviceCreateComputePipeline(device.handle, desc)
  error = device.pop_error_scope

  if @handle.null? || (error[:type] && error[:type] != :no_error)
    msg = error[:message] || "Failed to create compute pipeline"
    raise PipelineError, msg
  end
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.

Returns:

  • (Object)


5
6
7
# File 'lib/wgpu/pipeline/compute_pipeline.rb', line 5

def handle
  @handle
end

Instance Method Details

#get_bind_group_layout(index) ⇒ BindGroupLayout

Returns the bind group layout inferred or assigned at an index.

Parameters:

  • index (Integer)

    bind group index

  • (Integer)

Returns:

Raises:



30
31
32
33
34
# File 'lib/wgpu/pipeline/compute_pipeline.rb', line 30

def get_bind_group_layout(index)
  handle = Native.wgpuComputePipelineGetBindGroupLayout(@handle, index)
  raise PipelineError, "Failed to get bind group layout at index #{index}" if handle.null?
  BindGroupLayout.from_handle(handle, device: @device)
end

#releasevoid

This method returns an undefined value.

Releases the native compute pipeline handle.

Calling this method more than once has no effect.



40
41
42
43
44
# File 'lib/wgpu/pipeline/compute_pipeline.rb', line 40

def release
  return if @handle.null?
  Native.wgpuComputePipelineRelease(@handle)
  @handle = FFI::Pointer::NULL
end