Class: WGPU::RenderPass
- Inherits:
-
Object
- Object
- WGPU::RenderPass
- Includes:
- NativeResource
- Defined in:
- lib/wgpu/commands/render_pass.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_occlusion_query(query_index) ⇒ void
Begins an occlusion query for subsequent draw calls.
-
#draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) ⇒ void
Records a non-indexed draw.
-
#draw_indexed(index_count, instance_count: 1, first_index: 0, base_vertex: 0, first_instance: 0) ⇒ void
Records an indexed draw.
-
#draw_indexed_indirect(buffer, offset: 0) ⇒ void
Draws using indexed arguments stored in a buffer.
-
#draw_indirect(buffer, offset: 0) ⇒ void
Draws using non-indexed arguments stored in a buffer.
-
#end ⇒ void
Ends the pass.
-
#end_occlusion_query ⇒ void
Ends the active occlusion query.
-
#end_pass ⇒ void
Ends the pass if it has not already ended.
-
#ended? ⇒ Boolean
Reports whether the pass has ended.
-
#execute_bundles(bundles) ⇒ void
Executes pre-recorded render bundles.
-
#initialize(encoder, label: nil, color_attachments:, depth_stencil_attachment: nil, occlusion_query_set: nil, timestamp_writes: nil, max_draw_count: nil) ⇒ RenderPass
constructor
Begins a render pass owned by the command encoder.
-
#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 pass encoder handle.
-
#set_bind_group(index, bind_group, dynamic_offsets: []) ⇒ void
Binds a resource group for subsequent draws.
-
#set_blend_constant(r: 0.0, g: 0.0, b: 0.0, a: 1.0) ⇒ void
Sets the constant color used by blend factors.
-
#set_index_buffer(buffer, format, offset: 0, size: nil) ⇒ void
Binds an index buffer for indexed draws.
-
#set_pipeline(pipeline) ⇒ void
Selects the render pipeline used by subsequent draws.
-
#set_scissor_rect(x, y, width, height) ⇒ void
Restricts rasterization to a rectangular region.
-
#set_stencil_reference(reference) ⇒ void
Sets the stencil reference used by subsequent draw calls.
-
#set_vertex_buffer(slot, buffer, offset: 0, size: nil) ⇒ void
Binds a vertex buffer to a slot.
-
#set_viewport(x, y, width, height, min_depth: 0.0, max_depth: 1.0) ⇒ void
Sets the viewport used by subsequent draw calls.
Methods included from NativeResource
included, #inspect, #released?, #use
Constructor Details
#initialize(encoder, label: nil, color_attachments:, depth_stencil_attachment: nil, occlusion_query_set: nil, timestamp_writes: nil, max_draw_count: nil) ⇒ RenderPass
Begins a render pass owned by the command encoder.
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 |
# File 'lib/wgpu/commands/render_pass.rb', line 16 def initialize(encoder, label: nil, color_attachments:, depth_stencil_attachment: nil, occlusion_query_set: nil, timestamp_writes: nil, max_draw_count: nil) @encoder = encoder @pointers = [] @max_draw_count = max_draw_count @ended = false desc = Native::RenderPassDescriptor.new desc[:next_in_chain] = nil setup_label(desc, label) = () desc[:color_attachment_count] = .size desc[:color_attachments] = if ds_ptr = () desc[:depth_stencil_attachment] = ds_ptr else desc[:depth_stencil_attachment] = nil end desc[:occlusion_query_set] = occlusion_query_set&.handle if ts = Native::RenderPassTimestampWrites.new ts[:query_set] = .fetch(:query_set).handle ts[:beginning_of_pass_write_index] = [:beginning_of_pass_write_index] || 0xFFFFFFFF ts[:end_of_pass_write_index] = [:end_of_pass_write_index] || 0xFFFFFFFF @pointers << ts desc[:timestamp_writes] = ts.to_ptr else desc[:timestamp_writes] = nil end @handle = Native.wgpuCommandEncoderBeginRenderPass(encoder.handle, desc) raise CommandError, "Failed to begin render pass" if @handle.null? end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wgpu/commands/render_pass.rb', line 5 def handle @handle end |
Instance Method Details
#begin_occlusion_query(query_index) ⇒ void
This method returns an undefined value.
Begins an occlusion query for subsequent draw calls.
191 192 193 |
# File 'lib/wgpu/commands/render_pass.rb', line 191 def begin_occlusion_query(query_index) Native.wgpuRenderPassEncoderBeginOcclusionQuery(@handle, query_index) end |
#draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) ⇒ void
This method returns an undefined value.
Records a non-indexed draw.
100 101 102 |
# File 'lib/wgpu/commands/render_pass.rb', line 100 def draw(vertex_count, instance_count: 1, first_vertex: 0, first_instance: 0) Native.wgpuRenderPassEncoderDraw(@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.
106 107 108 |
# File 'lib/wgpu/commands/render_pass.rb', line 106 def draw_indexed(index_count, instance_count: 1, first_index: 0, base_vertex: 0, first_instance: 0) Native.wgpuRenderPassEncoderDrawIndexed(@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.
Draws using indexed arguments stored in a buffer.
172 173 174 |
# File 'lib/wgpu/commands/render_pass.rb', line 172 def draw_indexed_indirect(buffer, offset: 0) Native.wgpuRenderPassEncoderDrawIndexedIndirect(@handle, buffer.handle, offset) end |
#draw_indirect(buffer, offset: 0) ⇒ void
This method returns an undefined value.
Draws using non-indexed arguments stored in a buffer.
163 164 165 |
# File 'lib/wgpu/commands/render_pass.rb', line 163 def draw_indirect(buffer, offset: 0) Native.wgpuRenderPassEncoderDrawIndirect(@handle, buffer.handle, offset) end |
#end ⇒ void
This method returns an undefined value.
Ends the pass.
245 246 247 |
# File 'lib/wgpu/commands/render_pass.rb', line 245 def end end_pass end |
#end_occlusion_query ⇒ void
This method returns an undefined value.
Ends the active occlusion query.
198 199 200 |
# File 'lib/wgpu/commands/render_pass.rb', line 198 def end_occlusion_query Native.wgpuRenderPassEncoderEndOcclusionQuery(@handle) end |
#end_pass ⇒ void
This method returns an undefined value.
Ends the pass if it has not already ended.
235 236 237 238 239 240 241 |
# File 'lib/wgpu/commands/render_pass.rb', line 235 def end_pass return if @ended Native.wgpuRenderPassEncoderEnd(@handle) @ended = true @encoder.send(:pass_ended, self) end |
#ended? ⇒ Boolean
Reports whether the pass has ended.
251 252 253 |
# File 'lib/wgpu/commands/render_pass.rb', line 251 def ended? @ended end |
#execute_bundles(bundles) ⇒ void
This method returns an undefined value.
Executes pre-recorded render bundles.
180 181 182 183 184 185 |
# File 'lib/wgpu/commands/render_pass.rb', line 180 def execute_bundles(bundles) bundle_handles = bundles.map(&:handle) bundles_ptr = FFI::MemoryPointer.new(:pointer, bundle_handles.size) bundles_ptr.write_array_of_pointer(bundle_handles) Native.wgpuRenderPassEncoderExecuteBundles(@handle, bundle_handles.size, bundles_ptr) end |
#insert_debug_marker(label) ⇒ void
This method returns an undefined value.
Inserts a labeled point in GPU debugging tools.
225 226 227 228 229 230 231 |
# File 'lib/wgpu/commands/render_pass.rb', line 225 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.wgpuRenderPassEncoderInsertDebugMarker(@handle, label_view) end |
#pop_debug_group ⇒ void
This method returns an undefined value.
Ends the most recently pushed debug group.
217 218 219 |
# File 'lib/wgpu/commands/render_pass.rb', line 217 def pop_debug_group Native.wgpuRenderPassEncoderPopDebugGroup(@handle) end |
#push_debug_group(label) ⇒ void
This method returns an undefined value.
Starts a labeled group in GPU debugging tools.
206 207 208 209 210 211 212 |
# File 'lib/wgpu/commands/render_pass.rb', line 206 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.wgpuRenderPassEncoderPushDebugGroup(@handle, label_view) end |
#release ⇒ void
This method returns an undefined value.
Releases the native render pass encoder handle.
Calling this method more than once has no effect.
259 260 261 262 263 |
# File 'lib/wgpu/commands/render_pass.rb', line 259 def release return if @handle.null? Native.wgpuRenderPassEncoderRelease(@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 draws.
65 66 67 68 69 70 71 72 73 |
# File 'lib/wgpu/commands/render_pass.rb', line 65 def set_bind_group(index, bind_group, dynamic_offsets: []) if dynamic_offsets.empty? Native.wgpuRenderPassEncoderSetBindGroup(@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.wgpuRenderPassEncoderSetBindGroup(@handle, index, bind_group.handle, dynamic_offsets.size, offsets_ptr) end end |
#set_blend_constant(r: 0.0, g: 0.0, b: 0.0, a: 1.0) ⇒ void
This method returns an undefined value.
Sets the constant color used by blend factors.
141 142 143 144 145 146 147 148 |
# File 'lib/wgpu/commands/render_pass.rb', line 141 def set_blend_constant(r: 0.0, g: 0.0, b: 0.0, a: 1.0) color = Native::Color.new color[:r] = r color[:g] = g color[:b] = b color[:a] = a Native.wgpuRenderPassEncoderSetBlendConstant(@handle, color.to_ptr) end |
#set_index_buffer(buffer, format, offset: 0, size: nil) ⇒ void
This method returns an undefined value.
Binds an index buffer for indexed draws.
92 93 94 95 96 |
# File 'lib/wgpu/commands/render_pass.rb', line 92 def set_index_buffer(buffer, format, offset: 0, size: nil) size ||= buffer.size - offset format_value = Native::EnumHelper.coerce(Native::IndexFormat, format, name: "index format") Native.wgpuRenderPassEncoderSetIndexBuffer(@handle, buffer.handle, format_value, offset, size) end |
#set_pipeline(pipeline) ⇒ void
This method returns an undefined value.
Selects the render pipeline used by subsequent draws.
56 57 58 |
# File 'lib/wgpu/commands/render_pass.rb', line 56 def set_pipeline(pipeline) Native.wgpuRenderPassEncoderSetPipeline(@handle, pipeline.handle) end |
#set_scissor_rect(x, y, width, height) ⇒ void
This method returns an undefined value.
Restricts rasterization to a rectangular region.
130 131 132 |
# File 'lib/wgpu/commands/render_pass.rb', line 130 def set_scissor_rect(x, y, width, height) Native.wgpuRenderPassEncoderSetScissorRect(@handle, x, y, width, height) end |
#set_stencil_reference(reference) ⇒ void
This method returns an undefined value.
Sets the stencil reference used by subsequent draw calls.
154 155 156 |
# File 'lib/wgpu/commands/render_pass.rb', line 154 def set_stencil_reference(reference) Native.wgpuRenderPassEncoderSetStencilReference(@handle, reference) end |
#set_vertex_buffer(slot, buffer, offset: 0, size: nil) ⇒ void
This method returns an undefined value.
Binds a vertex buffer to a slot.
81 82 83 84 |
# File 'lib/wgpu/commands/render_pass.rb', line 81 def set_vertex_buffer(slot, buffer, offset: 0, size: nil) size ||= buffer.size - offset Native.wgpuRenderPassEncoderSetVertexBuffer(@handle, slot, buffer.handle, offset, size) end |
#set_viewport(x, y, width, height, min_depth: 0.0, max_depth: 1.0) ⇒ void
This method returns an undefined value.
Sets the viewport used by subsequent draw calls.
119 120 121 |
# File 'lib/wgpu/commands/render_pass.rb', line 119 def (x, y, width, height, min_depth: 0.0, max_depth: 1.0) Native.wgpuRenderPassEncoderSetViewport(@handle, x, y, width, height, min_depth, max_depth) end |