Class: WGPU::QuerySet

Inherits:
Object
  • Object
show all
Includes:
NativeResource
Defined in:
lib/wgpu/resources/query_set.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, type:, count:) ⇒ QuerySet

Creates a set of GPU queries.

Parameters:

  • device (Device)

    owning device

  • type (Symbol, Integer)

    query type

  • count (Integer)

    number of queries

Raises:



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

def initialize(device, label: nil, type:, count:)
  @device = device
  @count = Integer(count)
  type_value = Native::EnumHelper.coerce(Native::QueryType, type, name: "query type")
  @type = Native::QueryType[type_value]
  @destroyed = false

  desc = Native::QuerySetDescriptor.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[:type] = type_value
  desc[:count] = @count

  @handle = Native.wgpuDeviceCreateQuerySet(device.handle, desc)
  raise ResourceError, "Failed to create query set" if @handle.null?
end

Instance Attribute Details

#countInteger (readonly)

Returns the value of attribute count.

Returns:

  • (Integer)


5
6
7
# File 'lib/wgpu/resources/query_set.rb', line 5

def count
  @count
end

#handleObject (readonly)

Returns the value of attribute handle.

Returns:

  • (Object)


5
6
7
# File 'lib/wgpu/resources/query_set.rb', line 5

def handle
  @handle
end

#typeSymbol (readonly)

Returns the value of attribute type.

Returns:

  • (Symbol)


5
6
7
# File 'lib/wgpu/resources/query_set.rb', line 5

def type
  @type
end

Instance Method Details

#destroyvoid

This method returns an undefined value.

Destroys the query storage once.



38
39
40
41
42
43
# File 'lib/wgpu/resources/query_set.rb', line 38

def destroy
  return if @destroyed

  Native.wgpuQuerySetDestroy(@handle)
  @destroyed = true
end

#releasevoid

This method returns an undefined value.

Releases the native query set handle.

A query set destroyed through #destroy is only marked released because the pinned native implementation cannot safely release it afterward.



50
51
52
53
54
55
56
57
# File 'lib/wgpu/resources/query_set.rb', line 50

def release
  return if @handle.null?

  # Pinned wgpu-native v27 removes a destroyed query set from its storage;
  # calling Release afterward aborts inside Rust instead of being harmless.
  Native.wgpuQuerySetRelease(@handle) unless @destroyed
  @handle = FFI::Pointer::NULL
end