@@ -7,47 +7,36 @@ use std::{env, fs};
77
88/// A compute shader written in Rust compiled with spirv-builder.
99pub struct RustComputeShader {
10- pub path : PathBuf ,
11- pub target : String ,
12- pub capabilities : Vec < spirv_builder:: Capability > ,
10+ pub builder : SpirvBuilder ,
1311}
1412
1513impl RustComputeShader {
16- pub fn new < P : Into < PathBuf > > ( path : P ) -> Self {
17- Self {
18- path : path. into ( ) ,
19- target : "spirv-unknown-vulkan1.1" . to_string ( ) ,
20- capabilities : Vec :: new ( ) ,
21- }
14+ pub fn new ( path : impl Into < PathBuf > ) -> Self {
15+ Self :: with_target ( path, "spirv-unknown-vulkan1.3" )
2216 }
2317
24- pub fn with_target < P : Into < PathBuf > > ( path : P , target : impl Into < String > ) -> Self {
18+ pub fn with_target ( path : impl Into < PathBuf > , target : impl Into < String > ) -> Self {
2519 Self {
26- path : path. into ( ) ,
27- target : target. into ( ) ,
28- capabilities : Vec :: new ( ) ,
20+ builder : SpirvBuilder :: new ( path. into ( ) , target)
21+ . release ( true )
22+ . multimodule ( false )
23+ . shader_panic_strategy ( spirv_builder:: ShaderPanicStrategy :: SilentExit )
24+ . preserve_bindings ( true ) ,
2925 }
3026 }
3127
3228 pub fn with_capability ( mut self , capability : spirv_builder:: Capability ) -> Self {
33- self . capabilities . push ( capability) ;
29+ self . builder . capabilities . push ( capability) ;
3430 self
3531 }
3632}
3733
3834impl SpirvShader for RustComputeShader {
3935 fn spirv_bytes ( & self ) -> anyhow:: Result < ( Vec < u8 > , String ) > {
40- let mut builder = SpirvBuilder :: new ( & self . path , & self . target )
41- . release ( true )
42- . multimodule ( false )
43- . shader_panic_strategy ( spirv_builder:: ShaderPanicStrategy :: SilentExit )
44- . preserve_bindings ( true ) ;
45-
46- for capability in & self . capabilities {
47- builder = builder. capability ( * capability) ;
48- }
49-
50- let artifact = builder. build ( ) . context ( "SpirvBuilder::build() failed" ) ?;
36+ let artifact = self
37+ . builder
38+ . build ( )
39+ . context ( "SpirvBuilder::build() failed" ) ?;
5140
5241 if artifact. entry_points . len ( ) != 1 {
5342 anyhow:: bail!(
0 commit comments