From 3595c32ae5f4f92ed8a9a717f0af942380d89d2a Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Tue, 22 Feb 2022 14:28:35 +0800 Subject: [PATCH] segmented render time display --- internal/igwrap/convert.go | 13 +++++++ internal/igwrap/wrap.go | 6 +-- internal/render/render_world_debuginfo.go | 47 +++++++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/internal/igwrap/convert.go b/internal/igwrap/convert.go index 920dcca..30a4300 100644 --- a/internal/igwrap/convert.go +++ b/internal/igwrap/convert.go @@ -1,6 +1,8 @@ package igwrap import ( + "math" + "edgaru089.ml/go/gl01/internal/util/itype" "github.com/inkyblackness/imgui-go/v4" ) @@ -20,6 +22,17 @@ func PackedColor(color itype.Vec4f) imgui.PackedColor { return imgui.PackedColorFromVec4(Vec4(color)) } +// UnpackedColor unpacks a color to RGBA. +func UnpackedColor(color imgui.PackedColor) itype.Vec4f { + r, g, b, a := color.RGBA() + return itype.Vec4f{ + float32(r) / float32(math.MaxUint32), + float32(g) / float32(math.MaxUint32), + float32(b) / float32(math.MaxUint32), + float32(a) / float32(math.MaxUint32), + } +} + // Vec2 converts itype.Vec2f to imgui.Vec2. func Vec2(v itype.Vec2f) imgui.Vec2 { return imgui.Vec2{X: v[0], Y: v[1]} diff --git a/internal/igwrap/wrap.go b/internal/igwrap/wrap.go index 2f1e4a2..8363c81 100644 --- a/internal/igwrap/wrap.go +++ b/internal/igwrap/wrap.go @@ -30,18 +30,18 @@ func Text(format string, a ...interface{}) { // It also fills the background of the text with half-transparant black, and takes care of the padding. func TextBackground(format string, a ...interface{}) { pad := Vec2f(imgui.CurrentStyle().ItemSpacing()) - TextBackgroundV(itype.Vec4f{0, 0, 0, 0.5}, pad, format, a...) + TextBackgroundV(PackedColor(itype.Vec4f{0, 0, 0, 0.5}), pad, format, a...) } // TextBackgroundV wraps imgui.Text to create a shortcut for fmt.Sprintf. // // It also fills the background of the text with the given color. -func TextBackgroundV(color itype.Vec4f, padding itype.Vec2f, format string, a ...interface{}) { +func TextBackgroundV(color imgui.PackedColor, padding itype.Vec2f, format string, a ...interface{}) { text := fmt.Sprintf(format, a...) orig := imgui.CursorScreenPos() size := imgui.CalcTextSize(text, false, 0) halfpad := padding.Multiply(0.5) - imgui.BackgroundDrawList().AddRectFilledV(orig.Minus(Vec2(halfpad)), orig.Plus(size).Plus(Vec2(halfpad)), PackedColor(color), 0, 0) + imgui.BackgroundDrawList().AddRectFilledV(orig.Minus(Vec2(halfpad)), orig.Plus(size).Plus(Vec2(halfpad)), color, 0, 0) imgui.Text(text) } diff --git a/internal/render/render_world_debuginfo.go b/internal/render/render_world_debuginfo.go index 773d34b..a830812 100644 --- a/internal/render/render_world_debuginfo.go +++ b/internal/render/render_world_debuginfo.go @@ -12,12 +12,35 @@ import ( "github.com/inkyblackness/imgui-go/v4" ) +const ( + timebarN = 700 + timebarScale = 160 +) + +var ( + colorset = [...]imgui.PackedColor{4289753676, 4283598045, 4285048917, 4283584196, 4289950337, 4284512403, 4291005402, 4287401100, 4285839820, 4291671396} + timebars [timebarN][]int // height of each bar set + timebari int +) + func (r *WorldRenderer) renderDebugInfo() { // Render information if igwrap.Begin("F3", nil, 0) { igwrap.TextBlank() igwrap.TextBackground("WorldRender: lastframe %.3fms", float64(io.Diagnostics.Times.Render.Nanoseconds())/float64(time.Millisecond)) + igwrap.TextBackground("TimeBars:") + pad := igwrap.Vec2f(imgui.CurrentStyle().ItemSpacing()) + imgui.SameLine() + igwrap.TextBackgroundV(colorset[0], pad, "Depthmap") + imgui.SameLine() + igwrap.TextBackgroundV(colorset[1], pad, "Geometry") + imgui.SameLine() + igwrap.TextBackgroundV(colorset[2], pad, "SSAO") + imgui.SameLine() + igwrap.TextBackgroundV(colorset[3], pad, "Lighting") + imgui.SameLine() + igwrap.TextBackgroundV(colorset[4], pad, "Postfx") isize := asset.WorldTextureAtlas.ImageSize igwrap.TextBackground("Texture Atlas Size: (%dx%d)", isize[0], isize[1]) @@ -36,6 +59,7 @@ func (r *WorldRenderer) renderDebugInfo() { imgui.End() } + // Draw Textures imgui.SetNextWindowPosV(imgui.Vec2{X: float32(r.lastDisplaySize[0]), Y: 0}, imgui.ConditionAlways, imgui.Vec2{X: 1, Y: 0}) if igwrap.Begin("Renderer Textures/Outputs", nil, igwrap.WindowFlagsOverlay) { imgui.PushStyleVarVec2(imgui.StyleVarItemSpacing, imgui.Vec2{}) @@ -53,4 +77,27 @@ func (r *WorldRenderer) renderDebugInfo() { imgui.End() } + // Push the next bar + timebars[timebari] = []int{ + int(io.Diagnostics.Times.RenderPasses.Depthmap.Nanoseconds() * timebarScale / 1000 / 1000), + int(io.Diagnostics.Times.RenderPasses.Geometry.Nanoseconds() * timebarScale / 1000 / 1000), + int(io.Diagnostics.Times.RenderPasses.SSAO.Nanoseconds() * timebarScale / 1000 / 1000), + int(io.Diagnostics.Times.RenderPasses.Lighting.Nanoseconds() * timebarScale / 1000 / 1000), + int(io.Diagnostics.Times.RenderPasses.Postfx.Nanoseconds() * timebarScale / 1000 / 1000), + } + timebari++ + if timebari >= len(timebars) { + timebari = 0 + } + + // Draw time bars + size := r.lastDisplaySize + dl := imgui.BackgroundDrawList() + for i, l := range timebars { + ex := 0 + for j, d := range l { + dl.AddLine(imgui.Vec2{X: float32(i), Y: float32(size[1] - ex - 1)}, imgui.Vec2{X: float32(i), Y: float32(size[1] - ex - d)}, colorset[j]) + ex += d + } + } }