@@ -24,7 +24,7 @@ use amethyst::{
2424 pso,
2525 } ,
2626 mesh:: { AsAttribute , AsVertex , Color , TexCoord , VertexFormat } ,
27- shader:: { PathBufShaderInfo , Shader , ShaderKind , SourceLanguage , SpirvShader } ,
27+ shader:: { Shader , SpirvShader } ,
2828 texture:: TextureBuilder ,
2929 } ,
3030 submodules:: { DynamicIndexBuffer , DynamicVertexBuffer , TextureId , TextureSub } ,
@@ -36,17 +36,25 @@ use amethyst::{
3636 window:: Window ,
3737 winit:: Event ,
3838} ;
39+ use bumpalo:: { collections:: Vec as BumpVec , Bump } ;
40+
3941use derivative:: Derivative ;
4042use imgui:: { internal:: RawWrapper , DrawCmd , DrawCmdParams } ;
4143use std:: {
4244 borrow:: Cow ,
43- path:: PathBuf ,
4445 sync:: { Arc , Mutex } ,
4546} ;
4647
4748use crate :: ImguiContextWrapper ;
48- use imgui_winit_support:: { WinitPlatform } ;
49+ use imgui_winit_support:: WinitPlatform ;
50+
51+ #[ cfg( feature = "shader-compiler" ) ]
52+ use amethyst:: renderer:: rendy:: shader:: { PathBufShaderInfo , ShaderKind , SourceLanguage } ;
53+
54+ #[ cfg( feature = "shader-compiler" ) ]
55+ use std:: path:: PathBuf ;
4956
57+ #[ cfg( feature = "shader-compiler" ) ]
5058lazy_static:: lazy_static! {
5159 static ref VERTEX_SRC : SpirvShader = PathBufShaderInfo :: new(
5260 PathBuf :: from( concat!( env!( "CARGO_MANIFEST_DIR" ) , "/src/shaders/imgui.vert" ) ) ,
@@ -73,12 +81,25 @@ lazy_static::lazy_static! {
7381 ( * FRAGMENT_SRC ) . stage( ) ,
7482 "main" ,
7583 ) ;
84+ }
7685
77- static ref TIME : std:: sync:: Mutex <std:: time:: Instant > = std:: sync:: Mutex :: new( std:: time:: Instant :: now( ) ) ;
86+ #[ cfg( not( feature = "shader-compiler" ) ) ]
87+ lazy_static:: lazy_static! {
88+ static ref VERTEX : SpirvShader = SpirvShader :: new(
89+ include_bytes!( "../compiled/imgui.vert.spv" ) . to_vec( ) ,
90+ pso:: ShaderStageFlags :: VERTEX ,
91+ "main" ,
92+ ) ;
7893
79- //static ref SHADERS: ShaderSetBuilder = ShaderSetBuilder::default()
80- // .with_vertex(&*VERTEX).unwrap()
81- // .with_fragment(&*FRAGMENT).unwrap();
94+ static ref FRAGMENT : SpirvShader = SpirvShader :: new(
95+ include_bytes!( "../compiled/imgui.frag.spv" ) . to_vec( ) ,
96+ pso:: ShaderStageFlags :: FRAGMENT ,
97+ "main" ,
98+ ) ;
99+ }
100+
101+ lazy_static:: lazy_static! {
102+ static ref TIME : std:: sync:: Mutex <std:: time:: Instant > = std:: sync:: Mutex :: new( std:: time:: Instant :: now( ) ) ;
82103}
83104
84105#[ repr( transparent) ]
@@ -220,10 +241,8 @@ impl<B: Backend> RenderGroupDesc<B, World> for DrawImguiDesc {
220241 _buffers : Vec < NodeBuffer > ,
221242 _images : Vec < NodeImage > ,
222243 ) -> Result < Box < dyn RenderGroup < B , World > > , failure:: Error > {
223- let ( context_mutex, mut winit_events) = <(
224- ReadExpect < ' _ , Arc < Mutex < ImguiContextWrapper > > > ,
225- Write < ' _ , EventChannel < Event > > ,
226- ) >:: fetch ( world) ;
244+ let ( context_mutex, mut winit_events) =
245+ <( ReadExpect < ' _ , Arc < Mutex < ImguiContextWrapper > > > , Write < ' _ , EventChannel < Event > > ) >:: fetch ( world) ;
227246
228247 let context = & mut context_mutex. lock ( ) . unwrap ( ) . 0 ;
229248
@@ -251,6 +270,7 @@ impl<B: Backend> RenderGroupDesc<B, World> for DrawImguiDesc {
251270 batches : Default :: default ( ) ,
252271 imgui_textures,
253272 reader_id : winit_events. register_reader ( ) ,
273+ bump : Mutex :: new ( Bump :: default ( ) ) ,
254274 } ) )
255275 }
256276}
@@ -276,6 +296,7 @@ pub struct DrawImgui<B: Backend> {
276296 constant : ImguiPushConstant ,
277297 imgui_textures : Vec < Handle < Texture > > ,
278298 reader_id : ReaderId < Event > ,
299+ bump : Mutex < Bump > ,
279300}
280301
281302impl < B : Backend > DrawImgui < B > { }
@@ -297,6 +318,9 @@ impl<B: Backend> RenderGroup<B, World> for DrawImgui<B> {
297318 Read < ' _ , EventChannel < Event > > ,
298319 ) >:: fetch ( world) ;
299320
321+ let mut bump = self . bump . lock ( ) . unwrap ( ) ;
322+ bump. reset ( ) ;
323+
300324 let state = & mut context. lock ( ) . unwrap ( ) . 0 ;
301325
302326 for texture in & self . imgui_textures {
@@ -324,8 +348,8 @@ impl<B: Backend> RenderGroup<B, World> for DrawImgui<B> {
324348 & * ( imgui:: sys:: igGetDrawData ( ) as * mut imgui:: DrawData )
325349 } ;
326350
327- let mut vertices: Vec < ImguiArgs > = Vec :: with_capacity ( draw_data. total_vtx_count as usize ) ;
328- let mut indices: Vec < u16 > = Vec :: with_capacity ( draw_data. total_idx_count as usize ) ;
351+ let mut vertices: BumpVec < ImguiArgs > = BumpVec :: with_capacity_in ( draw_data. total_vtx_count as usize , & bump ) ;
352+ let mut indices: BumpVec < u16 > = BumpVec :: with_capacity_in ( draw_data. total_idx_count as usize , & bump ) ;
329353
330354 self . commands . reserve ( draw_data. draw_lists ( ) . count ( ) ) ;
331355
0 commit comments