Class: WGPU::BindGroup

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/pipeline/bind_group.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:, entries:) ⇒ BindGroup

Creates bindings between shader slots and GPU resources.

Parameters:

  • device (Device)

    owning device

  • layout (BindGroupLayout)

    layout the entries must match

  • entries (Array<Hash>)

    resource binding descriptors

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
39
40
41
42
43
44
# File 'lib/wgpu/pipeline/bind_group.rb', line 12

def initialize(device, label: nil, layout:, entries:)
  @device = device

  entries_array = entries.map { |e| create_entry(e) }
  entries_ptr = FFI::MemoryPointer.new(Native::BindGroupEntry, entries_array.size)
  entries_array.each_with_index do |entry, i|
    offset = i * Native::BindGroupEntry.size
    (entries_ptr + offset).put_bytes(0, entry.pointer.read_bytes(Native::BindGroupEntry.size))
  end

  desc = Native::BindGroupDescriptor.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
  desc[:layout] = layout.handle
  desc[:entry_count] = entries_array.size
  desc[:entries] = entries_ptr

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

  if @handle.null? || (error[:type] && error[:type] != :no_error)
    msg = error[:message] || "Failed to create bind group"
    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/bind_group.rb', line 5

def handle
  @handle
end

Instance Method Details

#releasevoid

This method returns an undefined value.

Releases the native bind group handle.

Calling this method more than once has no effect.



50
51
52
53
54
# File 'lib/wgpu/pipeline/bind_group.rb', line 50

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