Class: WGPU::CommandEncoder
- Inherits:
-
Object
- Object
- WGPU::CommandEncoder
- Includes:
- NativeResource
- Defined in:
- lib/wgpu/commands/command_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
-
#begin_compute_pass(label: nil, timestamp_writes: nil) {|pass| ... } ⇒ ComputePass, Object
Begins a compute pass, optionally yielding it for scoped recording.
-
#begin_render_pass(color_attachments:, depth_stencil_attachment: nil, occlusion_query_set: nil, timestamp_writes: nil, max_draw_count: nil, label: nil) {|pass| ... } ⇒ RenderPass, Object
Begins a render pass, optionally yielding it for scoped recording.
-
#clear_buffer(buffer, offset: 0, size: nil) ⇒ void
Clears a byte range in a buffer to zero.
-
#copy_buffer_to_buffer(source:, source_offset: 0, destination:, destination_offset: 0, size:) ⇒ void
Copies bytes between buffers.
-
#copy_buffer_to_texture(source:, destination:, copy_size:) ⇒ void
Copies buffer data into a texture region.
-
#copy_texture_to_buffer(source:, destination:, copy_size:) ⇒ void
Copies a texture region into a buffer.
-
#copy_texture_to_texture(source:, destination:, copy_size:) ⇒ void
Copies one texture region into another texture.
-
#finish(label: nil) ⇒ CommandBuffer
Finishes recording and returns a command buffer.
-
#initialize(device, label: nil) ⇒ CommandEncoder
constructor
Creates an encoder for commands submitted to a device queue.
-
#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 command encoder handle.
-
#resolve_query_set(query_set:, first_query:, query_count:, destination:, destination_offset:) ⇒ void
Resolves query results into a destination buffer.
-
#write_timestamp(query_set, query_index) ⇒ void
Writes a GPU timestamp to a query set.
Methods included from NativeResource
included, #inspect, #released?, #use
Constructor Details
#initialize(device, label: nil) ⇒ CommandEncoder
Creates an encoder for commands submitted to a device queue.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wgpu/commands/command_encoder.rb', line 11 def initialize(device, label: nil) @device = device @finished = false @active_pass = nil desc = Native::CommandEncoderDescriptor.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 @handle = Native.wgpuDeviceCreateCommandEncoder(device.handle, desc) raise CommandError, "Failed to create command encoder" if @handle.null? end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wgpu/commands/command_encoder.rb', line 5 def handle @handle end |
Instance Method Details
#begin_compute_pass(arg0) ⇒ ComputePass #begin_compute_pass ⇒ void
Begins a compute pass, optionally yielding it for scoped recording.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wgpu/commands/command_encoder.rb', line 36 def begin_compute_pass(label: nil, timestamp_writes: nil) ensure_can_begin_pass! pass = ComputePass.new(self, label: label, timestamp_writes: ) @active_pass = pass return pass unless block_given? begin yield pass ensure begin pass.end_pass unless pass.ended? ensure pass.release pass_ended(pass) end end end |
#begin_render_pass(arg0) ⇒ RenderPass #begin_render_pass ⇒ void
Begins a render pass, optionally yielding it for scoped recording.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/wgpu/commands/command_encoder.rb', line 58 def begin_render_pass(color_attachments:, depth_stencil_attachment: nil, occlusion_query_set: nil, timestamp_writes: nil, max_draw_count: nil, label: nil) ensure_can_begin_pass! pass = RenderPass.new(self, color_attachments: , depth_stencil_attachment: , occlusion_query_set: occlusion_query_set, timestamp_writes: , max_draw_count: max_draw_count, label: label ) @active_pass = pass return pass unless block_given? begin yield pass ensure begin pass.end_pass unless pass.ended? ensure pass.release pass_ended(pass) end end end |
#clear_buffer(buffer, offset: 0, size: nil) ⇒ void
This method returns an undefined value.
Clears a byte range in a buffer to zero.
222 223 224 225 226 |
# File 'lib/wgpu/commands/command_encoder.rb', line 222 def clear_buffer(buffer, offset: 0, size: nil) raise CommandError, "Encoder already finished" if @finished size ||= buffer.size - offset Native.wgpuCommandEncoderClearBuffer(@handle, buffer.handle, offset, size) end |
#copy_buffer_to_buffer(source:, source_offset: 0, destination:, destination_offset: 0, size:) ⇒ void
This method returns an undefined value.
Copies bytes between buffers.
85 86 87 88 89 90 91 92 93 |
# File 'lib/wgpu/commands/command_encoder.rb', line 85 def copy_buffer_to_buffer(source:, source_offset: 0, destination:, destination_offset: 0, size:) raise CommandError, "Encoder already finished" if @finished Native.wgpuCommandEncoderCopyBufferToBuffer( @handle, source.handle, source_offset, destination.handle, destination_offset, size ) end |
#copy_buffer_to_texture(source:, destination:, copy_size:) ⇒ void
This method returns an undefined value.
Copies buffer data into a texture region.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/wgpu/commands/command_encoder.rb', line 100 def copy_buffer_to_texture(source:, destination:, copy_size:) raise CommandError, "Encoder already finished" if @finished size = Native::Extent3D.new size[:width] = copy_size[:width] || copy_size[0] size[:height] = copy_size[:height] || copy_size[1] || 1 size[:depth_or_array_layers] = copy_size[:depth_or_array_layers] || copy_size[2] || 1 src = Native::ImageCopyBuffer.new src[:layout][:offset] = source[:offset] || 0 src[:layout][:bytes_per_row] = source[:bytes_per_row] src[:layout][:rows_per_image] = source[:rows_per_image] || size[:height] src[:buffer] = source[:buffer].handle dst = Native::ImageCopyTexture.new dst[:texture] = destination[:texture].handle dst[:mip_level] = destination[:mip_level] || 0 dst[:origin][:x] = destination.dig(:origin, :x) || 0 dst[:origin][:y] = destination.dig(:origin, :y) || 0 dst[:origin][:z] = destination.dig(:origin, :z) || 0 dst[:aspect] = Native::EnumHelper.coerce( Native::TextureAspect, destination[:aspect] || :all, name: "texture aspect" ) Native.wgpuCommandEncoderCopyBufferToTexture(@handle, src, dst, size) end |
#copy_texture_to_buffer(source:, destination:, copy_size:) ⇒ void
This method returns an undefined value.
Copies a texture region into a buffer.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/wgpu/commands/command_encoder.rb', line 134 def copy_texture_to_buffer(source:, destination:, copy_size:) raise CommandError, "Encoder already finished" if @finished size = Native::Extent3D.new size[:width] = copy_size[:width] || copy_size[0] size[:height] = copy_size[:height] || copy_size[1] || 1 size[:depth_or_array_layers] = copy_size[:depth_or_array_layers] || copy_size[2] || 1 src = Native::ImageCopyTexture.new src[:texture] = source[:texture].handle src[:mip_level] = source[:mip_level] || 0 src[:origin][:x] = source.dig(:origin, :x) || 0 src[:origin][:y] = source.dig(:origin, :y) || 0 src[:origin][:z] = source.dig(:origin, :z) || 0 src[:aspect] = Native::EnumHelper.coerce( Native::TextureAspect, source[:aspect] || :all, name: "texture aspect" ) dst = Native::ImageCopyBuffer.new dst[:layout][:offset] = destination[:offset] || 0 dst[:layout][:bytes_per_row] = destination[:bytes_per_row] dst[:layout][:rows_per_image] = destination[:rows_per_image] || size[:height] dst[:buffer] = destination[:buffer].handle Native.wgpuCommandEncoderCopyTextureToBuffer(@handle, src, dst, size) end |
#copy_texture_to_texture(source:, destination:, copy_size:) ⇒ void
This method returns an undefined value.
Copies one texture region into another texture.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/wgpu/commands/command_encoder.rb', line 168 def copy_texture_to_texture(source:, destination:, copy_size:) raise CommandError, "Encoder already finished" if @finished src = Native::ImageCopyTexture.new src[:texture] = source[:texture].handle src[:mip_level] = source[:mip_level] || 0 src[:origin][:x] = source.dig(:origin, :x) || 0 src[:origin][:y] = source.dig(:origin, :y) || 0 src[:origin][:z] = source.dig(:origin, :z) || 0 src[:aspect] = Native::EnumHelper.coerce( Native::TextureAspect, source[:aspect] || :all, name: "source texture aspect" ) dst = Native::ImageCopyTexture.new dst[:texture] = destination[:texture].handle dst[:mip_level] = destination[:mip_level] || 0 dst[:origin][:x] = destination.dig(:origin, :x) || 0 dst[:origin][:y] = destination.dig(:origin, :y) || 0 dst[:origin][:z] = destination.dig(:origin, :z) || 0 dst[:aspect] = Native::EnumHelper.coerce( Native::TextureAspect, destination[:aspect] || :all, name: "destination texture aspect" ) size = Native::Extent3D.new size[:width] = copy_size[:width] || copy_size[0] size[:height] = copy_size[:height] || copy_size[1] || 1 size[:depth_or_array_layers] = copy_size[:depth_or_array_layers] || copy_size[2] || 1 Native.wgpuCommandEncoderCopyTextureToTexture(@handle, src, dst, size) end |
#finish(label: nil) ⇒ CommandBuffer
Finishes recording and returns a command buffer.
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/wgpu/commands/command_encoder.rb', line 272 def finish(label: nil) raise CommandError, "Encoder already finished" if @finished if @active_pass && !@active_pass.ended? raise CommandError, "Cannot finish command encoder while a pass is active" end @finished = true desc = nil if label desc = Native::CommandBufferDescriptor.new desc[:next_in_chain] = nil label_ptr = FFI::MemoryPointer.from_string(label) desc[:label][:data] = label_ptr desc[:label][:length] = label.bytesize end buffer_handle = Native.wgpuCommandEncoderFinish(@handle, desc) raise CommandError, "Failed to finish command encoder" if buffer_handle.null? CommandBuffer.new(buffer_handle, device: @device) end |
#insert_debug_marker(label) ⇒ void
This method returns an undefined value.
Inserts a labeled point in GPU debugging tools.
259 260 261 262 263 264 265 266 |
# File 'lib/wgpu/commands/command_encoder.rb', line 259 def insert_debug_marker(label) raise CommandError, "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.wgpuCommandEncoderInsertDebugMarker(@handle, label_view) end |
#pop_debug_group ⇒ void
This method returns an undefined value.
Ends the most recently pushed debug group.
251 252 253 254 |
# File 'lib/wgpu/commands/command_encoder.rb', line 251 def pop_debug_group raise CommandError, "Encoder already finished" if @finished Native.wgpuCommandEncoderPopDebugGroup(@handle) end |
#push_debug_group(label) ⇒ void
This method returns an undefined value.
Starts a labeled group in GPU debugging tools.
240 241 242 243 244 245 246 247 |
# File 'lib/wgpu/commands/command_encoder.rb', line 240 def push_debug_group(label) raise CommandError, "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.wgpuCommandEncoderPushDebugGroup(@handle, label_view) end |
#release ⇒ void
This method returns an undefined value.
Releases the native command encoder handle.
Calling this method more than once has no effect.
298 299 300 301 302 |
# File 'lib/wgpu/commands/command_encoder.rb', line 298 def release return if @handle.null? Native.wgpuCommandEncoderRelease(@handle) @handle = FFI::Pointer::NULL end |
#resolve_query_set(query_set:, first_query:, query_count:, destination:, destination_offset:) ⇒ void
This method returns an undefined value.
Resolves query results into a destination buffer.
205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/wgpu/commands/command_encoder.rb', line 205 def resolve_query_set(query_set:, first_query:, query_count:, destination:, destination_offset:) raise CommandError, "Encoder already finished" if @finished Native.wgpuCommandEncoderResolveQuerySet( @handle, query_set.handle, first_query, query_count, destination.handle, destination_offset ) end |
#write_timestamp(query_set, query_index) ⇒ void
This method returns an undefined value.
Writes a GPU timestamp to a query set.
232 233 234 235 |
# File 'lib/wgpu/commands/command_encoder.rb', line 232 def (query_set, query_index) raise CommandError, "Encoder already finished" if @finished Native.wgpuCommandEncoderWriteTimestamp(@handle, query_set.handle, query_index) end |