Class: WGPU::RenderBundleEncoder
- Inherits:
-
Object
- Object
- WGPU::RenderBundleEncoder
- Includes:
- NativeResource
- Defined in:
- lib/wgpu/commands/render_bundle_encoder.rb,
sig/wgpu.rbs
Constant Summary
Constants included from NativeResource
NativeResource::GUARDED_METHOD_EXEMPTIONS
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Attributes included from NativeResource
Instance Method Summary collapse
-
#draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) ⇒ void
Records a non-indexed draw in the bundle.
-
#draw_indexed(index_count, instance_count: 1, first_index: 0, base_vertex: 0, first_instance: 0) ⇒ void
Records an indexed draw in the bundle.
-
#draw_indexed_indirect(buffer, offset: 0) ⇒ void
Records an indexed draw using buffer arguments.
-
#draw_indirect(buffer, offset: 0) ⇒ void
Records a non-indexed draw using buffer arguments.
-
#finish(label: nil) ⇒ RenderBundle
Finishes recording and creates an immutable render bundle.
-
#initialize(device, color_formats:, depth_stencil_format: nil, sample_count: 1, depth_read_only: false, stencil_read_only: false, label: nil) ⇒ RenderBundleEncoder
constructor
Creates an encoder for reusable render commands.
-
#insert_debug_marker(label) ⇒ void
Inserts a labeled point in GPU debugging tools.
-
#pop_debug_group ⇒ void
Ends the most recently pushed debug group.
-
#push_debug_group(label) ⇒ void
Starts a labeled group in GPU debugging tools.
-
#release ⇒ void
Releases the native render bundle encoder handle.
-
#set_bind_group(index, bind_group, dynamic_offsets: nil) ⇒ void
Binds a resource group for subsequent bundle draws.
-
#set_index_buffer(buffer, format: :uint32, offset: 0, size: nil) ⇒ void
Binds an index buffer for indexed bundle draws.
-
#set_pipeline(pipeline) ⇒ void
Selects the pipeline used by subsequent bundle draws.
-
#set_vertex_buffer(slot, buffer, offset: 0, size: nil) ⇒ void
Binds a vertex buffer to a slot.
Methods included from NativeResource
included, #inspect, #released?, #use
Constructor Details
#initialize(device, color_formats:, depth_stencil_format: nil, sample_count: 1, depth_read_only: false, stencil_read_only: false, label: nil) ⇒ RenderBundleEncoder
Creates an encoder for reusable render commands.
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 45 46 47 48 49 50 51 52 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 16 def initialize(device, color_formats:, depth_stencil_format: nil, sample_count: 1, depth_read_only: false, stencil_read_only: false, label: nil) @device = device @finished = false desc = Native::RenderBundleEncoderDescriptor.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 formats = Array(color_formats).map do |format| Native::EnumHelper.coerce(Native::TextureFormat, format, name: "color format") end @formats_ptr = FFI::MemoryPointer.new(:uint32, formats.size) @formats_ptr.write_array_of_uint32(formats) desc[:color_format_count] = formats.size desc[:color_formats] = @formats_ptr desc[:depth_stencil_format] = Native::EnumHelper.coerce( Native::TextureFormat, depth_stencil_format || :undefined, name: "depth stencil format" ) desc[:sample_count] = sample_count desc[:depth_read_only] = depth_read_only ? 1 : 0 desc[:stencil_read_only] = stencil_read_only ? 1 : 0 @handle = Native.wgpuDeviceCreateRenderBundleEncoder(device.handle, desc) raise RenderBundleError, "Failed to create render bundle encoder" if @handle.null? end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 5 def handle @handle end |
Instance Method Details
#draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) ⇒ void
This method returns an undefined value.
Records a non-indexed draw in the bundle.
106 107 108 109 110 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 106 def draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderDraw(@handle, vertex_count, instance_count, first_vertex, first_instance) end |
#draw_indexed(index_count, instance_count: 1, first_index: 0, base_vertex: 0, first_instance: 0) ⇒ void
This method returns an undefined value.
Records an indexed draw in the bundle.
114 115 116 117 118 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 114 def draw_indexed(index_count, instance_count: 1, first_index: 0, base_vertex: 0, first_instance: 0) raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderDrawIndexed(@handle, index_count, instance_count, first_index, base_vertex, first_instance) end |
#draw_indexed_indirect(buffer, offset: 0) ⇒ void
This method returns an undefined value.
Records an indexed draw using buffer arguments.
134 135 136 137 138 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 134 def draw_indexed_indirect(buffer, offset: 0) raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderDrawIndexedIndirect(@handle, buffer.handle, offset) end |
#draw_indirect(buffer, offset: 0) ⇒ void
This method returns an undefined value.
Records a non-indexed draw using buffer arguments.
124 125 126 127 128 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 124 def draw_indirect(buffer, offset: 0) raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderDrawIndirect(@handle, buffer.handle, offset) end |
#finish(label: nil) ⇒ RenderBundle
Finishes recording and creates an immutable render bundle.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 178 def finish(label: nil) raise RenderBundleError, "Encoder already finished" if @finished @finished = true desc = nil if label desc = Native::RenderBundleDescriptor.new desc[:next_in_chain] = nil label_ptr = FFI::MemoryPointer.from_string(label) desc[:label][:data] = label_ptr desc[:label][:length] = label.bytesize end bundle_handle = Native.wgpuRenderBundleEncoderFinish(@handle, desc) raise RenderBundleError, "Failed to finish render bundle encoder" if bundle_handle.null? RenderBundle.new(bundle_handle, device: @device) end |
#insert_debug_marker(label) ⇒ void
This method returns an undefined value.
Inserts a labeled point in GPU debugging tools.
164 165 166 167 168 169 170 171 172 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 164 def insert_debug_marker(label) raise RenderBundleError, "Encoder already finished" if @finished label_view = Native::StringView.new label_ptr = FFI::MemoryPointer.from_string(label) label_view[:data] = label_ptr label_view[:length] = label.bytesize Native.wgpuRenderBundleEncoderInsertDebugMarker(@handle, label_view) end |
#pop_debug_group ⇒ void
This method returns an undefined value.
Ends the most recently pushed debug group.
155 156 157 158 159 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 155 def pop_debug_group raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderPopDebugGroup(@handle) end |
#push_debug_group(label) ⇒ void
This method returns an undefined value.
Starts a labeled group in GPU debugging tools.
143 144 145 146 147 148 149 150 151 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 143 def push_debug_group(label) raise RenderBundleError, "Encoder already finished" if @finished label_view = Native::StringView.new label_ptr = FFI::MemoryPointer.from_string(label) label_view[:data] = label_ptr label_view[:length] = label.bytesize Native.wgpuRenderBundleEncoderPushDebugGroup(@handle, label_view) end |
#release ⇒ void
This method returns an undefined value.
Releases the native render bundle encoder handle.
Calling this method more than once has no effect.
202 203 204 205 206 207 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 202 def release return if @handle.null? Native.wgpuRenderBundleEncoderRelease(@handle) @handle = FFI::Pointer::NULL end |
#set_bind_group(index, bind_group, dynamic_offsets: nil) ⇒ void
This method returns an undefined value.
Binds a resource group for subsequent bundle draws.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 69 def set_bind_group(index, bind_group, dynamic_offsets: nil) raise RenderBundleError, "Encoder already finished" if @finished if dynamic_offsets && !dynamic_offsets.empty? offsets_ptr = FFI::MemoryPointer.new(:uint32, dynamic_offsets.size) offsets_ptr.write_array_of_uint32(dynamic_offsets) Native.wgpuRenderBundleEncoderSetBindGroup(@handle, index, bind_group.handle, dynamic_offsets.size, offsets_ptr) else Native.wgpuRenderBundleEncoderSetBindGroup(@handle, index, bind_group.handle, 0, nil) end end |
#set_index_buffer(buffer, format: :uint32, offset: 0, size: nil) ⇒ void
This method returns an undefined value.
Binds an index buffer for indexed bundle draws.
96 97 98 99 100 101 102 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 96 def set_index_buffer(buffer, format: :uint32, offset: 0, size: nil) raise RenderBundleError, "Encoder already finished" if @finished size ||= buffer.size - offset format_value = Native::EnumHelper.coerce(Native::IndexFormat, format, name: "index format") Native.wgpuRenderBundleEncoderSetIndexBuffer(@handle, buffer.handle, format_value, offset, size) end |
#set_pipeline(pipeline) ⇒ void
This method returns an undefined value.
Selects the pipeline used by subsequent bundle draws.
58 59 60 61 62 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 58 def set_pipeline(pipeline) raise RenderBundleError, "Encoder already finished" if @finished Native.wgpuRenderBundleEncoderSetPipeline(@handle, pipeline.handle) end |
#set_vertex_buffer(slot, buffer, offset: 0, size: nil) ⇒ void
This method returns an undefined value.
Binds a vertex buffer to a slot.
85 86 87 88 89 90 |
# File 'lib/wgpu/commands/render_bundle_encoder.rb', line 85 def set_vertex_buffer(slot, buffer, offset: 0, size: nil) raise RenderBundleError, "Encoder already finished" if @finished size ||= buffer.size - offset Native.wgpuRenderBundleEncoderSetVertexBuffer(@handle, slot, buffer.handle, offset, size) end |