فهرست منبع

app: add debug info to replace draw calls API

darkfi 1 سال پیش
والد
کامیت
f1981d8d65

+ 42 - 19
bin/app/src/gfx/mod.rs

@@ -270,17 +270,18 @@ impl GfxDrawMesh {
         self,
         textures: &HashMap<GfxTextureId, miniquad::TextureId>,
         buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
+        debug_str: &'static str
     ) -> Option<DrawMesh> {
         let vertex_buffer_id = self.vertex_buffer.id;
         let index_buffer_id = self.index_buffer.id;
         let buffers_keep_alive = [self.vertex_buffer, self.index_buffer];
         let texture = match self.texture {
-            Some(gfx_texture) => Self::try_get_texture(textures, gfx_texture),
+            Some(gfx_texture) => Self::try_get_texture(textures, gfx_texture, debug_str),
             None => None,
         };
         Some(DrawMesh {
-            vertex_buffer: Self::try_get_buffer(buffers, vertex_buffer_id)?,
-            index_buffer: Self::try_get_buffer(buffers, index_buffer_id)?,
+            vertex_buffer: Self::try_get_buffer(buffers, vertex_buffer_id, debug_str)?,
+            index_buffer: Self::try_get_buffer(buffers, index_buffer_id, debug_str)?,
             buffers_keep_alive,
             texture,
             num_elements: self.num_elements,
@@ -290,11 +291,12 @@ impl GfxDrawMesh {
     fn try_get_texture(
         textures: &HashMap<GfxTextureId, miniquad::TextureId>,
         gfx_texture: ManagedTexturePtr,
+        debug_str: &'static str
     ) -> Option<(ManagedTexturePtr, miniquad::TextureId)> {
         let gfx_texture_id = gfx_texture.id;
 
         let Some(mq_texture_id) = textures.get(&gfx_texture_id) else {
-            error!(target: "gfx", "Serious error: missing texture ID={gfx_texture_id}");
+            error!(target: "gfx", "Serious error: missing texture ID={gfx_texture_id}, debug={debug_str}");
             error!(target: "gfx", "Dumping textures:");
             for (gfx_texture_id, texture_id) in textures {
                 error!(target: "gfx", "{gfx_texture_id} => {texture_id:?}");
@@ -310,9 +312,10 @@ impl GfxDrawMesh {
     fn try_get_buffer(
         buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
         gfx_buffer_id: GfxBufferId,
+        debug_str: &'static str
     ) -> Option<miniquad::BufferId> {
         let Some(mq_buffer_id) = buffers.get(&gfx_buffer_id) else {
-            error!(target: "gfx", "Serious error: missing buffer ID={gfx_buffer_id}");
+            error!(target: "gfx", "Serious error: missing buffer ID={gfx_buffer_id}, debug={debug_str}");
             error!(target: "gfx", "Dumping buffers:");
             for (gfx_buffer_id, buffer_id) in buffers {
                 error!(target: "gfx", "{gfx_buffer_id} => {buffer_id:?}");
@@ -340,13 +343,14 @@ impl GfxDrawInstruction {
         self,
         textures: &HashMap<GfxTextureId, miniquad::TextureId>,
         buffers: &HashMap<GfxBufferId, miniquad::BufferId>,
+        debug_str: &'static str
     ) -> Option<DrawInstruction> {
         let instr = match self {
             Self::SetScale(scale) => DrawInstruction::SetScale(scale),
             Self::Move(off) => DrawInstruction::Move(off),
             Self::SetPos(pos) => DrawInstruction::SetPos(pos),
             Self::ApplyView(view) => DrawInstruction::ApplyView(view),
-            Self::Draw(mesh) => DrawInstruction::Draw(mesh.compile(textures, buffers)?),
+            Self::Draw(mesh) => DrawInstruction::Draw(mesh.compile(textures, buffers, debug_str)?),
             Self::EnableDebug => DrawInstruction::EnableDebug,
         };
         Some(instr)
@@ -358,6 +362,23 @@ pub struct GfxDrawCall {
     pub instrs: Vec<GfxDrawInstruction>,
     pub dcs: Vec<u64>,
     pub z_index: u32,
+    pub debug_str: &'static str
+}
+
+impl GfxDrawCall {
+    pub fn new(
+        instrs: Vec<GfxDrawInstruction>,
+        dcs: Vec<u64>,
+        z_index: u32,
+        debug_str: &'static str
+    ) -> Self {
+        Self {
+            instrs,
+            dcs,
+            z_index,
+            debug_str
+        }
+    }
 }
 
 impl GfxDrawCall {
@@ -371,7 +392,7 @@ impl GfxDrawCall {
             instrs: self
                 .instrs
                 .into_iter()
-                .map(|i| i.compile(textures, buffers))
+                .map(|i| i.compile(textures, buffers, self.debug_str))
                 .collect::<Option<Vec<_>>>()?,
             dcs: self.dcs,
             z_index: self.z_index,
@@ -579,7 +600,7 @@ impl<'a> RenderContext<'a> {
     }
 }
 
-#[derive(Clone, Debug)]
+#[derive(Clone)]
 pub enum GraphicsMethod {
     NewTexture((u16, u16, Vec<u8>, GfxTextureId)),
     DeleteTexture((GfxTextureId, DebugTag)),
@@ -589,6 +610,19 @@ pub enum GraphicsMethod {
     ReplaceDrawCalls { timest: u64, dcs: Vec<(u64, GfxDrawCall)> },
 }
 
+impl std::fmt::Debug for GraphicsMethod {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        match self {
+            Self::NewTexture(_) => write!(f, "NewTexture"),
+            Self::DeleteTexture(_) => write!(f, "DeleteTexture"),
+            Self::NewVertexBuffer(_) => write!(f, "NewVertexBuffer"),
+            Self::NewIndexBuffer(_) => write!(f, "NewIndexBuffer"),
+            Self::DeleteBuffer(_) => write!(f, "DeleteBuffer"),
+            Self::ReplaceDrawCalls { timest: _, dcs: _ } => write!(f, "ReplaceDrawCalls"),
+        }
+    }
+}
+
 struct EventChannel<T> {
     sender: async_channel::Sender<T>,
     recvr: async_channel::Receiver<T>,
@@ -1047,17 +1081,6 @@ impl EventHandler for Stage {
         let god = GOD.get().unwrap();
         god.stop_app();
     }
-
-    fn force_reload(&mut self) {
-        t!("force_reload");
-        let god = GOD.get().unwrap();
-        god.stop_app();
-        //god.start_app();
-        drop(god);
-        self.clear();
-        *self = Self::new();
-        t!("force_reload [DONE]");
-    }
 }
 
 pub fn run_gui() {

+ 26 - 23
bin/app/src/ui/chatedit.rs

@@ -1011,15 +1011,16 @@ impl ChatEdit {
         let draw_main = vec![
             (
                 self.content_dc_key,
-                GfxDrawCall {
-                    instrs: content_instrs,
-                    dcs: vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
-                    z_index: 0,
-                },
+                GfxDrawCall::new(
+                    content_instrs,
+                    vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
+                    0,
+                    "chatedit_content"
+                ),
             ),
             (
                 self.phone_select_handle_dc_key,
-                GfxDrawCall { instrs: phone_sel_instrs, dcs: vec![], z_index: 1 },
+                GfxDrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel_scroll")
             ),
         ];
         self.render_api.replace_draw_calls(timest, draw_main);
@@ -1029,7 +1030,7 @@ impl ChatEdit {
         let timest = unixtime();
         let instrs = self.get_cursor_instrs().await;
         let draw_calls =
-            vec![(self.cursor_dc_key, GfxDrawCall { instrs, dcs: vec![], z_index: 2 })];
+            vec![(self.cursor_dc_key, GfxDrawCall::new(instrs, vec![], 2, "curs_redr"))];
         self.render_api.replace_draw_calls(timest, draw_calls);
     }
 
@@ -1038,10 +1039,10 @@ impl ChatEdit {
         let sel_instrs = self.regen_select_mesh().await;
         let phone_sel_instrs = self.regen_phone_select_handle_mesh().await;
         let draw_calls = vec![
-            (self.select_dc_key, GfxDrawCall { instrs: sel_instrs, dcs: vec![], z_index: 0 }),
+            (self.select_dc_key, GfxDrawCall::new(sel_instrs, vec![], 0, "chatedit_sel")),
             (
                 self.phone_select_handle_dc_key,
-                GfxDrawCall { instrs: phone_sel_instrs, dcs: vec![], z_index: 1 },
+                GfxDrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel_redraw_sel"),
             ),
         ];
         self.render_api.replace_draw_calls(timest, draw_calls);
@@ -1232,29 +1233,31 @@ impl ChatEdit {
             draw_calls: vec![
                 (
                     self.root_dc_key,
-                    GfxDrawCall {
-                        instrs: vec![GfxDrawInstruction::Move(rect.pos())],
-                        dcs: vec![self.content_dc_key, self.phone_select_handle_dc_key],
-                        z_index: self.z_index.get(),
-                    },
+                    GfxDrawCall::new(
+                        vec![GfxDrawInstruction::Move(rect.pos())],
+                        vec![self.content_dc_key, self.phone_select_handle_dc_key],
+                        self.z_index.get(),
+                        "chatedit_root"
+                    ),
                 ),
                 (
                     self.content_dc_key,
-                    GfxDrawCall {
-                        instrs: content_instrs,
-                        dcs: vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
-                        z_index: 0,
-                    },
+                    GfxDrawCall::new(
+                        content_instrs,
+                        vec![self.text_dc_key, self.cursor_dc_key, self.select_dc_key],
+                        0,
+                        "chatedit_content"
+                    ),
                 ),
-                (self.select_dc_key, GfxDrawCall { instrs: sel_instrs, dcs: vec![], z_index: 0 }),
-                (self.text_dc_key, GfxDrawCall { instrs: txt_instrs, dcs: vec![], z_index: 1 }),
+                (self.select_dc_key, GfxDrawCall::new(sel_instrs, vec![], 0, "chatedit_sel")),
+                (self.text_dc_key, GfxDrawCall::new(txt_instrs, vec![], 1, "chatedit_text")),
                 (
                     self.cursor_dc_key,
-                    GfxDrawCall { instrs: cursor_instrs, dcs: vec![], z_index: 2 },
+                    GfxDrawCall::new(cursor_instrs, vec![], 2, "chatedit_curs"),
                 ),
                 (
                     self.phone_select_handle_dc_key,
-                    GfxDrawCall { instrs: phone_sel_instrs, dcs: vec![], z_index: 1 },
+                    GfxDrawCall::new(phone_sel_instrs, vec![], 1, "chatedit_phone_sel"),
                 ),
             ],
         }

+ 2 - 2
bin/app/src/ui/chatview/mod.rs

@@ -702,7 +702,7 @@ impl ChatView {
         instrs.append(&mut mesh_instrs);
 
         let draw_calls =
-            vec![(self.dc_key, GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() })];
+            vec![(self.dc_key, GfxDrawCall::new(instrs, vec![], self.z_index.get(), "chatview"))];
 
         self.render_api.replace_draw_calls(timest, draw_calls);
         t!("ChatView::redraw_cached() DONE [trace_id={trace_id}]");
@@ -854,7 +854,7 @@ impl UIObject for ChatView {
             key: self.dc_key,
             draw_calls: vec![(
                 self.dc_key,
-                GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
+                GfxDrawCall::new(instrs, vec![], self.z_index.get(), "chatview")
             )],
         })
     }

+ 8 - 7
bin/app/src/ui/editbox/mod.rs

@@ -1191,7 +1191,7 @@ impl EditBox {
 
         let draw_calls = vec![(
             self.cursor_dc_key,
-            GfxDrawCall { instrs: cursor_instrs, dcs: vec![], z_index: self.z_index.get() },
+            GfxDrawCall::new(cursor_instrs, vec![], self.z_index.get(), "editbox_curs_redr")
         )];
 
         self.render_api.replace_draw_calls(timest, draw_calls);
@@ -1240,18 +1240,19 @@ impl EditBox {
             draw_calls: vec![
                 (
                     self.text_dc_key,
-                    GfxDrawCall {
-                        instrs: vec![
+                    GfxDrawCall::new(
+                        vec![
                             GfxDrawInstruction::Move(rect.pos()),
                             GfxDrawInstruction::Draw(text_mesh),
                         ],
-                        dcs: vec![self.cursor_dc_key],
-                        z_index: self.z_index.get(),
-                    },
+                        vec![self.cursor_dc_key],
+                        self.z_index.get(),
+                        "editbox_txt"
+                    ),
                 ),
                 (
                     self.cursor_dc_key,
-                    GfxDrawCall { instrs: cursor_instrs, dcs: vec![], z_index: self.z_index.get() },
+                    GfxDrawCall::new(cursor_instrs, vec![], self.z_index.get(), "editbox_curs")
                 ),
             ],
         })

+ 1 - 1
bin/app/src/ui/emoji_picker/mod.rs

@@ -268,7 +268,7 @@ impl EmojiPicker {
             key: self.dc_key,
             draw_calls: vec![(
                 self.dc_key,
-                GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
+                GfxDrawCall::new(instrs, vec![], self.z_index.get(), "emoji")
             )],
         })
     }

+ 6 - 5
bin/app/src/ui/image.rs

@@ -172,14 +172,15 @@ impl Image {
             key: self.dc_key,
             draw_calls: vec![(
                 self.dc_key,
-                GfxDrawCall {
-                    instrs: vec![
+                GfxDrawCall::new(
+                    vec![
                         GfxDrawInstruction::Move(rect.pos()),
                         GfxDrawInstruction::Draw(mesh),
                     ],
-                    dcs: vec![],
-                    z_index: self.z_index.get(),
-                },
+                    vec![],
+                    self.z_index.get(),
+                    "img"
+                ),
             )],
         })
     }

+ 6 - 5
bin/app/src/ui/layer.rs

@@ -140,11 +140,12 @@ impl Layer {
             }
         }
 
-        let dc = GfxDrawCall {
-            instrs: vec![GfxDrawInstruction::ApplyView(rect)],
-            dcs: child_calls,
-            z_index: self.z_index.get(),
-        };
+        let dc = GfxDrawCall::new(
+            vec![GfxDrawInstruction::ApplyView(rect)],
+            child_calls,
+            self.z_index.get(),
+            "layer"
+        );
         draw_calls.push((self.dc_key, dc));
         Some(DrawUpdate { key: self.dc_key, draw_calls })
     }

+ 1 - 1
bin/app/src/ui/text.rs

@@ -166,7 +166,7 @@ impl Text {
             key: self.dc_key,
             draw_calls: vec![(
                 self.dc_key,
-                GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
+                GfxDrawCall::new(instrs, vec![], self.z_index.get(), "text")
             )],
         })
     }

+ 1 - 1
bin/app/src/ui/vector_art/mod.rs

@@ -151,7 +151,7 @@ impl VectorArt {
             key: self.dc_key,
             draw_calls: vec![(
                 self.dc_key,
-                GfxDrawCall { instrs, dcs: vec![], z_index: self.z_index.get() },
+                GfxDrawCall::new(instrs, vec![], self.z_index.get(), "vecart")
             )],
         })
     }

+ 6 - 5
bin/app/src/ui/win.rs

@@ -442,11 +442,12 @@ impl Window {
             child_calls.push(draw_update.key);
         }
 
-        let dc = GfxDrawCall {
-            instrs: vec![GfxDrawInstruction::SetScale(self.scale.get())],
-            dcs: child_calls,
-            z_index: 0,
-        };
+        let dc = GfxDrawCall::new(
+            vec![GfxDrawInstruction::SetScale(self.scale.get())],
+            child_calls,
+            0,
+            "win"
+        );
         draw_calls.push((0, dc));
         //t!("  => {:?}", draw_calls);