Replies: 10 comments 9 replies
-
@epezent you mentioned on #254 that you did some tests with GPU acceleration for line plots (with some incredible results so far). How's it going? You need any help with that? I'm rather curious on how you managed to implement it |
Beta Was this translation helpful? Give feedback.
-
@marcizhu, @bear24rw I did a bit of rework on heatmaps. Mainly switching to using One thing I'm wondering is if there's a way we can combine void RenderHeatmap(int itemID,
void* data,
ImGuiDataType data_type,
int rows,
int cols,
float scale_min,
float scale_max,
const ImPlotPoint& bounds_min,
const ImPlotPoint& bounds_max,
bool logx,
bool logy,
bool reverse_y,
ImPlotColormap cmap,
ImDrawList& DrawList); I avoid template <typename T>
struct ImGuiDataTypeGetter { static const ImGuiDataType Value; };
template <> const ImGuiDataType ImGuiDataTypeGetter<float>::Value = ImGuiDataType_Float;
template <> const ImGuiDataType ImGuiDataTypeGetter<double>::Value = ImGuiDataType_Double;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImU8>::Value = ImGuiDataType_U8;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImS8>::Value = ImGuiDataType_S8;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImU16>::Value = ImGuiDataType_U16;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImS16>::Value = ImGuiDataType_S16;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImU32>::Value = ImGuiDataType_U32;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImS32>::Value = ImGuiDataType_S32;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImU64>::Value = ImGuiDataType_U64;
template <> const ImGuiDataType ImGuiDataTypeGetter<ImS64>::Value = ImGuiDataType_S64;
...
ImGuiDataType data_type = ImGuiDataTypeGetter<T>::Value; If you guys agree, @marcizhu can you make the change for us? |
Beta Was this translation helpful? Give feedback.
-
this might be useful: https://blog.mapbox.com/drawing-antialiased-lines-with-opengl-8766f34192dc i think the resulting shader code is available under the mapbox-gl repo. or i guess this fork prior to their non-oss license switch: https://github.com/maplibre/maplibre-gl-js |
Beta Was this translation helpful? Give feedback.
-
I have some very early results to share for GPU line rendering. My implementation is super naive at the moment, but I'm quite happy with the results so far. First, we basically get AA for free. Note the difference between ImPlot default lines, and GPU lines (note MSAA is disabled) Second, we get pretty good performance gains for high volumes of points (1M tested here). Here are results recorded on my laptop, using the integrated (Intel i7 9750H, UHD Graphics 630) and discrete (RTX 2080 Max-Q) GPUs.
GPU performance is currently bound by the number of lines because I'm making a call to |
Beta Was this translation helpful? Give feedback.
-
I now have all lines drawn to a plot batched into a single draw call. Now, 1M points render in about the same amount of time (~150 FPS) regardless of the number of lines. Not quite as impressive as the 430 FPS I posted above. That's because this comes at the expense of having to include line color in the vertex data ( Below are my current shader programs. I think I can get a little more out of the vertex shader by lumping the plot-to-pixel transform into the projection matrix on the CPU side. The geometry shader only draws 1-px thick lines for now, but I have a more general variant that can do thick lines for about the same cost. I explored mitering lines here, but it didn't seem necessary or worth the expense. line.vert #version 330 core
layout (location = 0) in vec2 Point;
layout (location = 1) in vec4 Color;
uniform mat4 ProjMtx;
uniform vec2 M;
uniform vec2 PltMin;
uniform vec2 PixMin;
out vec4 VertColor;
void main()
{
VertColor = Color;
vec2 pix = PixMin + M * (Point - PltMin);
gl_Position = ProjMtx * vec4(pix, 0.0, 1.0);
} line.geom #version 330 core
layout (lines) in;
layout (triangle_strip, max_vertices = 6) out;
uniform vec2 Scale;
in vec4 VertColor[];
out vec4 GeomColor;
void main()
{
vec2 p1 = gl_in[0].gl_Position.xy / Scale;
vec2 p2 = gl_in[1].gl_Position.xy / Scale;
vec2 v = p2 - p1;
vec2 n = normalize(v);
GeomColor = vec4(VertColor[0].rgb, 0);
gl_Position = vec4(vec2(p1.x + n.y, p1.y - n.x) * Scale, 0, 1);
EmitVertex();
GeomColor = vec4(VertColor[1].rgb, 0);
gl_Position = vec4(vec2(p2.x + n.y, p2.y - n.x) * Scale, 0, 1);
EmitVertex();
GeomColor = VertColor[0];
gl_Position = vec4(p1 * Scale, 0, 1);
EmitVertex();
GeomColor = VertColor[1];
gl_Position = vec4(p2 * Scale, 0, 1);
EmitVertex();
GeomColor = vec4(VertColor[0].rgb, 0);;
gl_Position = vec4(vec2(p1.x - n.y, p1.y + n.x) * Scale, 0, 1);
EmitVertex();
GeomColor = vec4(VertColor[1].rgb, 0);;
gl_Position = vec4(vec2(p2.x - n.y, p2.y + n.x) * Scale, 0, 1);
EmitVertex();
EndPrimitive();
} line.frag #version 330 core
out vec4 FragColor;
in vec4 GeomColor;
void main()
{
FragColor = GeomColor;
} |
Beta Was this translation helpful? Give feedback.
-
Sorry if this is a dumb question, but I see the heatmap GPU acceleration implementation in backends, but not @epezent 's line plots. Was this merged in at any point? It would be great to use, even if not perfect by any means (that speedup would be of exceptional use to me). |
Beta Was this translation helpful? Give feedback.
-
@epezent, first of all thank you for your amazing work on implot! I am curious about the status of the |
Beta Was this translation helpful? Give feedback.
-
@epezent, is there any chance that you could push the changes you made for the GPU-accelerated line plots to the I would be happy to help with further work on this (although sadly I don't have any OpenGL experience). |
Beta Was this translation helpful? Give feedback.
-
I'd love to contribute or assist in any way I can in regards to shader accelerated plots. |
Beta Was this translation helpful? Give feedback.
-
Hi, do you have any plans to sync |
Beta Was this translation helpful? Give feedback.
-
Continues discussions related to GPU backend rendering started in #254 and #219. Follow progress on backends branch.
@marcizhu, @bear24rw
Beta Was this translation helpful? Give feedback.
All reactions