11use mygraphics_shaders:: ShaderConstants ;
22use wgpu:: {
3- ColorTargetState , ColorWrites , Device , FragmentState , FrontFace , MultisampleState , PolygonMode ,
4- PrimitiveState , PrimitiveTopology , RenderPass , RenderPipeline , RenderPipelineDescriptor ,
5- ShaderStages , TextureFormat , VertexState , include_spirv,
3+ ColorTargetState , ColorWrites , Device , FragmentState , FrontFace , MultisampleState ,
4+ PipelineLayoutDescriptor , PolygonMode , PrimitiveState , PrimitiveTopology , PushConstantRange ,
5+ RenderPass , RenderPipeline , RenderPipelineDescriptor , ShaderModuleDescriptorPassthrough ,
6+ ShaderRuntimeChecks , ShaderStages , TextureFormat , VertexState ,
67} ;
78
89pub struct MyRenderPipeline {
@@ -11,14 +12,44 @@ pub struct MyRenderPipeline {
1112
1213impl MyRenderPipeline {
1314 pub fn new ( device : & Device , out_format : TextureFormat ) -> anyhow:: Result < Self > {
14- let module = device. create_shader_module ( include_spirv ! ( env!( "SHADER_SPV_PATH" ) ) ) ;
15+ // Workaround in wgpu 27.0.1 where the macro expansion of `include_spirv_raw!` doesn't compile
16+ // see https://github.com/gfx-rs/wgpu/pull/8250
17+ // let module = unsafe {
18+ // device.create_shader_module_passthrough(include_spirv_raw!(env!("SHADER_SPV_PATH")))
19+ // };
20+ let module = unsafe {
21+ device. create_shader_module_passthrough ( ShaderModuleDescriptorPassthrough {
22+ label : Some ( env ! ( "SHADER_SPV_PATH" ) ) ,
23+ entry_point : "" . to_owned ( ) ,
24+ num_workgroups : ( 0 , 0 , 0 ) ,
25+ runtime_checks : ShaderRuntimeChecks :: unchecked ( ) ,
26+ spirv : Some ( wgpu:: util:: make_spirv_raw ( include_bytes ! ( env!(
27+ "SHADER_SPV_PATH"
28+ ) ) ) ) ,
29+ dxil : None ,
30+ msl : None ,
31+ hlsl : None ,
32+ glsl : None ,
33+ wgsl : None ,
34+ } )
35+ } ;
36+
37+ let layout = device. create_pipeline_layout ( & PipelineLayoutDescriptor {
38+ label : Some ( "MyRenderPipeline layout" ) ,
39+ bind_group_layouts : & [ ] ,
40+ push_constant_ranges : & [ PushConstantRange {
41+ stages : ShaderStages :: VERTEX_FRAGMENT ,
42+ range : 0 ..size_of :: < ShaderConstants > ( ) as u32 ,
43+ } ] ,
44+ } ) ;
45+
1546 Ok ( Self {
1647 pipeline : device. create_render_pipeline ( & RenderPipelineDescriptor {
1748 label : Some ( "MyRenderPipeline" ) ,
18- layout : None ,
49+ layout : Some ( & layout ) ,
1950 vertex : VertexState {
2051 module : & module,
21- entry_point : None ,
52+ entry_point : Some ( "main_vs" ) ,
2253 compilation_options : Default :: default ( ) ,
2354 buffers : & [ ] ,
2455 } ,
@@ -35,7 +66,7 @@ impl MyRenderPipeline {
3566 multisample : MultisampleState :: default ( ) ,
3667 fragment : Some ( FragmentState {
3768 module : & module,
38- entry_point : None ,
69+ entry_point : Some ( "main_fs" ) ,
3970 compilation_options : Default :: default ( ) ,
4071 targets : & [ Some ( ColorTargetState {
4172 format : out_format,
0 commit comments