@@ -343,6 +343,117 @@ impl Frame {
343343 }
344344}
345345
346+ // ---------------------- Command Encoding Abstractions -----------------------
347+
348+ #[ derive( Debug ) ]
349+ /// Thin wrapper around `wgpu::CommandEncoder` with convenience helpers.
350+ pub struct CommandEncoder {
351+ raw : wgpu:: CommandEncoder ,
352+ }
353+
354+ impl CommandEncoder {
355+ /// Create a new command encoder with an optional label.
356+ pub fn new ( device : & wgpu:: Device , label : Option < & str > ) -> Self {
357+ let raw =
358+ device. create_command_encoder ( & wgpu:: CommandEncoderDescriptor { label } ) ;
359+ return Self { raw } ;
360+ }
361+
362+ /// Begin a render pass targeting a single color attachment with the provided
363+ /// load/store operations. Depth/stencil is not attached by this helper.
364+ pub fn begin_render_pass < ' view > (
365+ & ' view mut self ,
366+ label : Option < & str > ,
367+ view : & ' view wgpu:: TextureView ,
368+ ops : wgpu:: Operations < wgpu:: Color > ,
369+ ) -> RenderPass < ' view > {
370+ let color_attachment = wgpu:: RenderPassColorAttachment {
371+ view,
372+ resolve_target : None ,
373+ depth_slice : None ,
374+ ops,
375+ } ;
376+ let color_attachments = [ Some ( color_attachment) ] ;
377+ let pass = self . raw . begin_render_pass ( & wgpu:: RenderPassDescriptor {
378+ label,
379+ color_attachments : & color_attachments,
380+ depth_stencil_attachment : None ,
381+ timestamp_writes : None ,
382+ occlusion_query_set : None ,
383+ } ) ;
384+ return RenderPass { raw : pass } ;
385+ }
386+
387+ /// Finish recording and return the command buffer.
388+ pub fn finish ( self ) -> wgpu:: CommandBuffer {
389+ return self . raw . finish ( ) ;
390+ }
391+ }
392+
393+ #[ derive( Debug ) ]
394+ /// Wrapper around `wgpu::RenderPass<'_>` exposing the operations needed by the
395+ /// Lambda renderer without leaking raw `wgpu` types at the call sites.
396+ pub struct RenderPass < ' a > {
397+ raw : wgpu:: RenderPass < ' a > ,
398+ }
399+
400+ impl < ' a > RenderPass < ' a > {
401+ /// Set the active render pipeline.
402+ pub fn set_pipeline ( & mut self , pipeline : & wgpu:: RenderPipeline ) {
403+ self . raw . set_pipeline ( pipeline) ;
404+ }
405+
406+ /// Apply viewport state.
407+ pub fn set_viewport (
408+ & mut self ,
409+ x : f32 ,
410+ y : f32 ,
411+ width : f32 ,
412+ height : f32 ,
413+ min_depth : f32 ,
414+ max_depth : f32 ,
415+ ) {
416+ self
417+ . raw
418+ . set_viewport ( x, y, width, height, min_depth, max_depth) ;
419+ }
420+
421+ /// Apply scissor rectangle.
422+ pub fn set_scissor_rect ( & mut self , x : u32 , y : u32 , width : u32 , height : u32 ) {
423+ self . raw . set_scissor_rect ( x, y, width, height) ;
424+ }
425+
426+ /// Bind a group with optional dynamic offsets.
427+ pub fn set_bind_group (
428+ & mut self ,
429+ set : u32 ,
430+ group : & wgpu:: BindGroup ,
431+ dynamic_offsets : & [ u32 ] ,
432+ ) {
433+ self . raw . set_bind_group ( set, group, dynamic_offsets) ;
434+ }
435+
436+ /// Bind a vertex buffer slot.
437+ pub fn set_vertex_buffer ( & mut self , slot : u32 , buffer : & wgpu:: Buffer ) {
438+ self . raw . set_vertex_buffer ( slot, buffer. slice ( ..) ) ;
439+ }
440+
441+ /// Upload push constants.
442+ pub fn set_push_constants (
443+ & mut self ,
444+ stages : wgpu:: ShaderStages ,
445+ offset : u32 ,
446+ data : & [ u8 ] ,
447+ ) {
448+ self . raw . set_push_constants ( stages, offset, data) ;
449+ }
450+
451+ /// Issue a non-indexed draw over a vertex range.
452+ pub fn draw ( & mut self , vertices : std:: ops:: Range < u32 > ) {
453+ self . raw . draw ( vertices, 0 ..1 ) ;
454+ }
455+ }
456+
346457#[ derive( Debug , Clone ) ]
347458/// Builder for a `Gpu` (adapter, device, queue) with feature validation.
348459pub struct GpuBuilder {
0 commit comments