1
1
use naga_oil:: compose:: { ComposableModuleDescriptor , Composer , NagaModuleDescriptor } ;
2
2
use wgcore:: composer:: ComposerExt ;
3
3
use wgcore:: kernel:: { KernelInvocationBuilder , KernelInvocationQueue } ;
4
- use wgcore:: shader:: Shader ;
5
4
use wgcore:: tensor:: GpuScalar ;
6
- use wgcore:: utils;
5
+ use wgcore:: { utils, Shader } ;
7
6
use wgebra:: WgSvd2 ;
8
7
use wgebra:: WgSvd3 ;
9
8
use wgpu:: { Buffer , BufferUsages , ComputePipeline , Device } ;
@@ -64,52 +63,15 @@ impl GpuRenderConfig {
64
63
}
65
64
}
66
65
67
- pub struct WgPrepVertexBuffer ( ComputePipeline ) ;
66
+ #[ derive( Shader ) ]
67
+ #[ shader( derive( WgParticle , WgGrid , WgSvd2 , WgSvd3 ) , composable = false ) ]
68
+ #[ cfg_attr( feature = "dim2" , shader( src = "prep_vertex_buffer2d.wgsl" ) ) ]
69
+ #[ cfg_attr( feature = "dim3" , shader( src = "prep_vertex_buffer3d.wgsl" ) ) ]
70
+ pub struct WgPrepVertexBuffer {
71
+ main : ComputePipeline ,
72
+ }
68
73
69
74
impl WgPrepVertexBuffer {
70
- #[ cfg( feature = "dim2" ) ]
71
- pub const SRC : & ' static str = include_str ! ( "./prep_vertex_buffer2d.wgsl" ) ;
72
- #[ cfg( feature = "dim2" ) ]
73
- pub const FILE_PATH : & ' static str = "prep_vertex_buffer2d.wgsl" ;
74
-
75
- #[ cfg( feature = "dim3" ) ]
76
- pub const SRC : & ' static str = include_str ! ( "./prep_vertex_buffer3d.wgsl" ) ;
77
- #[ cfg( feature = "dim3" ) ]
78
- pub const FILE_PATH : & ' static str = "prep_vertex_buffer3d.wgsl" ;
79
-
80
- pub fn new ( device : & Device ) -> Self {
81
- let module = Self :: composer ( )
82
- . make_naga_module ( NagaModuleDescriptor {
83
- source : Self :: SRC ,
84
- file_path : Self :: FILE_PATH ,
85
- ..Default :: default ( )
86
- } )
87
- . unwrap ( ) ;
88
- let g2p = utils:: load_module ( device, "main" , module. clone ( ) ) ;
89
- Self ( g2p)
90
- }
91
-
92
- pub fn compose ( composer : & mut Composer ) -> & mut Composer {
93
- WgParticle :: compose ( composer) ;
94
- WgGrid :: compose ( composer) ;
95
- WgSvd2 :: compose ( composer) ;
96
- WgSvd3 :: compose ( composer) ;
97
- composer
98
- . add_composable_module_once ( ComposableModuleDescriptor {
99
- source : Self :: SRC ,
100
- file_path : Self :: FILE_PATH ,
101
- ..Default :: default ( )
102
- } )
103
- . unwrap ( ) ;
104
- composer
105
- }
106
-
107
- pub fn composer ( ) -> Composer {
108
- let mut composer = Composer :: default ( ) ;
109
- Self :: compose ( & mut composer) ;
110
- composer
111
- }
112
-
113
75
pub fn queue < ' a > (
114
76
& ' a self ,
115
77
queue : & mut KernelInvocationQueue < ' a > ,
@@ -119,7 +81,7 @@ impl WgPrepVertexBuffer {
119
81
params : & GpuSimulationParams ,
120
82
vertex_buffer : & Buffer ,
121
83
) {
122
- KernelInvocationBuilder :: new ( queue, & self . 0 )
84
+ KernelInvocationBuilder :: new ( queue, & self . main )
123
85
. bind0 ( [
124
86
vertex_buffer,
125
87
particles. positions . buffer ( ) ,
@@ -132,5 +94,3 @@ impl WgPrepVertexBuffer {
132
94
. queue ( particles. positions . len ( ) . div_ceil ( 64 ) as u32 ) ;
133
95
}
134
96
}
135
-
136
- wgcore:: test_shader_compilation!( WgPrepVertexBuffer ) ;
0 commit comments