Class: WGPU::ComputePass

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/commands/compute_pass.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(encoder, label: nil, timestamp_writes: nil) ⇒ ComputePass

Begins a compute pass owned by the command encoder.

Parameters:

  • encoder (CommandEncoder)

    owning encoder

  • label (String, nil) (defaults to: nil)

    optional debug label

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

    beginning and ending timestamp query settings

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/wgpu/commands/compute_pass.rb', line 12

def initialize(encoder, label: nil, timestamp_writes: nil)
  @encoder = encoder
  @ended = false
  desc = Native::ComputePassDescriptor.new
  desc[:next_in_chain] = nil
  if label
    label_ptr = FFI::MemoryPointer.from_string(label)
    desc[:label][:data] = label_ptr
    desc[:label][:length] = label.bytesize
  else
    desc[:label][:data] = nil
    desc[:label][:length] = 0
  end
  @timestamp_writes = nil
  if timestamp_writes
    @timestamp_writes = Native::ComputePassTimestampWrites.new
    @timestamp_writes[:query_set] = timestamp_writes.fetch(:query_set).handle
    @timestamp_writes[:beginning_of_pass_write_index] = timestamp_writes[:beginning_of_pass_write_index] || 0xFFFFFFFF
    @timestamp_writes[:end_of_pass_write_index] = timestamp_writes[:end_of_pass_write_index] || 0xFFFFFFFF
    desc[:timestamp_writes] = @timestamp_writes.to_ptr
  else
    desc[:timestamp_writes] = nil
  end

  @handle = Native.wgpuCommandEncoderBeginComputePass(encoder.handle, desc)
  raise CommandError, "Failed to begin compute pass" if @handle.null?
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.

Returns:

  • (Object)


5
6
7
# File 'lib/wgpu/commands/compute_pass.rb', line 5

def handle
  @handle
end

Instance Method Details

#dispatch_workgroups(x, y = 1, z = 1) ⇒ void

This method returns an undefined value.

Dispatches a three-dimensional compute workgroup grid.

Parameters:

  • x (Integer)

    workgroup count on the x axis

  • y (Integer) (defaults to: 1)

    workgroup count on the y axis

  • z (Integer) (defaults to: 1)

    workgroup count on the z axis

  • (Integer)
  • (Integer)
  • (Integer)


67
68
69
# File 'lib/wgpu/commands/compute_pass.rb', line 67

def dispatch_workgroups(x, y = 1, z = 1)
  Native.wgpuComputePassEncoderDispatchWorkgroups(@handle, x, y, z)
end

#dispatch_workgroups_indirect(buffer, offset: 0) ⇒ void

This method returns an undefined value.

Dispatches workgroups using arguments read from a buffer.

Parameters:

  • buffer (Buffer)

    indirect argument buffer

  • offset (Integer) (defaults to: 0)

    byte offset of the arguments

  • (Buffer)
  • offset: (Integer) (defaults to: 0)


75
76
77
# File 'lib/wgpu/commands/compute_pass.rb', line 75

def dispatch_workgroups_indirect(buffer, offset: 0)
  Native.wgpuComputePassEncoderDispatchWorkgroupsIndirect(@handle, buffer.handle, offset)
end

#endvoid

This method returns an undefined value.

Ends the pass.



122
123
124
# File 'lib/wgpu/commands/compute_pass.rb', line 122

def end
  end_pass
end

#end_passvoid

This method returns an undefined value.

Ends the pass if it has not already ended.



112
113
114
115
116
117
118
# File 'lib/wgpu/commands/compute_pass.rb', line 112

def end_pass
  return if @ended

  Native.wgpuComputePassEncoderEnd(@handle)
  @ended = true
  @encoder.send(:pass_ended, self)
end

#ended?Boolean

Reports whether the pass has ended.

Returns:

  • (Boolean)


128
129
130
# File 'lib/wgpu/commands/compute_pass.rb', line 128

def ended?
  @ended
end

#insert_debug_marker(label) ⇒ void

This method returns an undefined value.

Inserts a labeled point in GPU debugging tools.

Parameters:

  • label (String)

    marker label

  • (String)


102
103
104
105
106
107
108
# File 'lib/wgpu/commands/compute_pass.rb', line 102

def insert_debug_marker(label)
  label_view = Native::StringView.new
  label_ptr = FFI::MemoryPointer.from_string(label)
  label_view[:data] = label_ptr
  label_view[:length] = label.bytesize
  Native.wgpuComputePassEncoderInsertDebugMarker(@handle, label_view)
end

#pop_debug_groupvoid

This method returns an undefined value.

Ends the most recently pushed debug group.



94
95
96
# File 'lib/wgpu/commands/compute_pass.rb', line 94

def pop_debug_group
  Native.wgpuComputePassEncoderPopDebugGroup(@handle)
end

#push_debug_group(label) ⇒ void

This method returns an undefined value.

Starts a labeled group in GPU debugging tools.

Parameters:

  • label (String)

    group label

  • (String)


83
84
85
86
87
88
89
# File 'lib/wgpu/commands/compute_pass.rb', line 83

def push_debug_group(label)
  label_view = Native::StringView.new
  label_ptr = FFI::MemoryPointer.from_string(label)
  label_view[:data] = label_ptr
  label_view[:length] = label.bytesize
  Native.wgpuComputePassEncoderPushDebugGroup(@handle, label_view)
end

#releasevoid

This method returns an undefined value.

Releases the native compute pass encoder handle.

Calling this method more than once has no effect.



136
137
138
139
140
# File 'lib/wgpu/commands/compute_pass.rb', line 136

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

#set_bind_group(index, bind_group, dynamic_offsets: []) ⇒ void

This method returns an undefined value.

Binds a resource group for subsequent dispatches.

Parameters:

  • index (Integer)

    bind group index

  • bind_group (BindGroup)

    group to bind

  • dynamic_offsets (Array<Integer>) (defaults to: [])

    dynamic buffer offsets

  • (Integer)
  • (BindGroup)
  • dynamic_offsets: (Array[Integer]) (defaults to: [])


52
53
54
55
56
57
58
59
60
# File 'lib/wgpu/commands/compute_pass.rb', line 52

def set_bind_group(index, bind_group, dynamic_offsets: [])
  if dynamic_offsets.empty?
    Native.wgpuComputePassEncoderSetBindGroup(@handle, index, bind_group.handle, 0, nil)
  else
    offsets_ptr = FFI::MemoryPointer.new(:uint32, dynamic_offsets.size)
    offsets_ptr.write_array_of_uint32(dynamic_offsets)
    Native.wgpuComputePassEncoderSetBindGroup(@handle, index, bind_group.handle, dynamic_offsets.size, offsets_ptr)
  end
end

#set_pipeline(pipeline) ⇒ void

This method returns an undefined value.

Selects the compute pipeline used by subsequent dispatches.

Parameters:



43
44
45
# File 'lib/wgpu/commands/compute_pass.rb', line 43

def set_pipeline(pipeline)
  Native.wgpuComputePassEncoderSetPipeline(@handle, pipeline.handle)
end