Class: WGPU::RenderPipeline

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/pipeline/render_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:, vertex:, primitive: {}, depth_stencil: nil, multisample: {}, fragment: nil) ⇒ RenderPipeline

Creates a render pipeline.

Parameters:

  • device (Device)

    owning device

  • layout (PipelineLayout, :auto, nil)

    pipeline layout

  • vertex (Hash)

    programmable vertex stage descriptor

  • fragment (Hash, nil) (defaults to: nil)

    optional fragment stage descriptor

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/wgpu/pipeline/render_pipeline.rb', line 13

def initialize(device, label: nil, layout:, vertex:, primitive: {}, depth_stencil: nil, multisample: {}, fragment: nil)
  @device = device
  desc, @pointers = build_descriptor(
    label:,
    layout:,
    vertex:,
    primitive:,
    depth_stencil:,
    multisample:,
    fragment:
  )

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

  if @handle.null? || (error[:type] && error[:type] != :no_error)
    msg = error[:message] || "Failed to create render 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/render_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:



39
40
41
42
43
# File 'lib/wgpu/pipeline/render_pipeline.rb', line 39

def get_bind_group_layout(index)
  handle = Native.wgpuRenderPipelineGetBindGroupLayout(@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 render pipeline handle.

Calling this method more than once has no effect.



49
50
51
52
53
# File 'lib/wgpu/pipeline/render_pipeline.rb', line 49

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