BLF: Perf: Divide by 6 the amount of verts sent to the GPU.
This means smaller imm buffer usage. This does not reduce the number of drawcalls. This uses geometry shader which is slow for the GPU but given we are really CPU bound on this case, it should not matter. A perfect implementation would: - Set the glyph coord in a bufferTexture and just send the glyph ID to the GPU to read the bufferTexture. - Use GWN_draw_primitive and draw 2*strllen triangle and just retrieve the glyph ID and color based on gl_VertexID / 6. - Stream fixed size buffer that the Driver can discard quickly but this is the same as improving IMM directly.
This commit is contained in:
parent
c48b6fae9a
commit
7144fdf285
|
@ -579,9 +579,9 @@ static void blf_draw_gl__start(FontBLF *font)
|
|||
|
||||
#ifndef BLF_STANDALONE
|
||||
Gwn_VertFormat *format = immVertexFormat();
|
||||
unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
||||
unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
|
||||
unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
|
||||
unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
||||
unsigned int texCoord = GWN_vertformat_attr_add(format, "tex", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
|
||||
unsigned int color = GWN_vertformat_attr_add(format, "col", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
|
||||
|
||||
BLI_assert(pos == BLF_POS_ID);
|
||||
BLI_assert(texCoord == BLF_COORD_ID);
|
||||
|
|
|
@ -188,7 +188,7 @@ static unsigned int verts_needed(const FontBLF *font, const char *str, size_t le
|
|||
quad_ct += 25; /* 5x5 kernel */
|
||||
}
|
||||
|
||||
return length * quad_ct * 6;
|
||||
return length * quad_ct; /* Only one vert per quad */
|
||||
}
|
||||
|
||||
static void blf_font_draw_ex(
|
||||
|
@ -211,7 +211,7 @@ static void blf_font_draw_ex(
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GWN_PRIM_TRIS, verts_needed(font, str, len));
|
||||
immBeginAtMost(GWN_PRIM_POINTS, verts_needed(font, str, len));
|
||||
/* at most because some glyphs might be clipped & not drawn */
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
|
@ -258,7 +258,7 @@ static void blf_font_draw_ascii_ex(
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GWN_PRIM_TRIS, verts_needed(font, str, len));
|
||||
immBeginAtMost(GWN_PRIM_POINTS, verts_needed(font, str, len));
|
||||
|
||||
while ((c = *(str++)) && len--) {
|
||||
BLI_assert(c < 128);
|
||||
|
@ -298,7 +298,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
|
|||
|
||||
blf_font_ensure_ascii_table(font);
|
||||
|
||||
immBeginAtMost(GWN_PRIM_TRIS, verts_needed(font, str, len));
|
||||
immBeginAtMost(GWN_PRIM_POINTS, verts_needed(font, str, len));
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
|
||||
|
|
|
@ -318,31 +318,11 @@ void blf_glyph_free(GlyphBLF *g)
|
|||
|
||||
static void blf_texture_draw(const unsigned char color[4], float uv[2][2], float dx, float y1, float dx1, float y2)
|
||||
{
|
||||
/* First triangle. */
|
||||
immAttrib2f(BLF_COORD_ID, uv[0][0], uv[0][1]);
|
||||
immSkipAttrib(BLF_COLOR_ID); /* skip color of most vertices */
|
||||
immVertex2f(BLF_POS_ID, dx, y1);
|
||||
|
||||
immAttrib2f(BLF_COORD_ID, uv[0][0], uv[1][1]);
|
||||
immSkipAttrib(BLF_COLOR_ID);
|
||||
immVertex2f(BLF_POS_ID, dx, y2);
|
||||
|
||||
immAttrib2f(BLF_COORD_ID, uv[1][0], uv[1][1]);
|
||||
immAttrib4ubv(BLF_COLOR_ID, color); /* set color of provoking vertex */
|
||||
immVertex2f(BLF_POS_ID, dx1, y2);
|
||||
|
||||
/* Second triangle. */
|
||||
immAttrib2f(BLF_COORD_ID, uv[0][0], uv[0][1]);
|
||||
immSkipAttrib(BLF_COLOR_ID); /* skip color of most vertices */
|
||||
immVertex2f(BLF_POS_ID, dx, y1);
|
||||
|
||||
immAttrib2f(BLF_COORD_ID, uv[1][0], uv[1][1]);
|
||||
immSkipAttrib(BLF_COLOR_ID);
|
||||
immVertex2f(BLF_POS_ID, dx1, y2);
|
||||
|
||||
immAttrib2f(BLF_COORD_ID, uv[1][0], uv[0][1]);
|
||||
immAttrib4ubv(BLF_COLOR_ID, color); /* set color of provoking vertex */
|
||||
immVertex2f(BLF_POS_ID, dx1, y1);
|
||||
/* Only one vertex per glyph, geometry shader expand it into a quad. */
|
||||
/* TODO Get rid of Geom Shader because it's not optimal AT ALL for the GPU */
|
||||
immAttrib4ubv(BLF_COLOR_ID, color);
|
||||
immAttrib4fv(BLF_COORD_ID, (float *)uv);
|
||||
immVertex4f(BLF_POS_ID, dx, y1, dx1, y2);
|
||||
}
|
||||
|
||||
static void blf_texture5_draw(const unsigned char color_in[4], float uv[2][2], float x1, float y1, float x2, float y2)
|
||||
|
|
|
@ -203,6 +203,7 @@ data_to_c_simple(shaders/gpu_shader_edges_overlay_geom.glsl SRC)
|
|||
data_to_c_simple(shaders/gpu_shader_edges_overlay_simple_geom.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_edges_overlay_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_text_geom.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_keyframe_diamond_vert.glsl SRC)
|
||||
data_to_c_simple(shaders/gpu_shader_keyframe_diamond_frag.glsl SRC)
|
||||
|
|
|
@ -135,6 +135,7 @@ extern char datatoc_gpu_shader_edges_overlay_geom_glsl[];
|
|||
extern char datatoc_gpu_shader_edges_overlay_simple_geom_glsl[];
|
||||
extern char datatoc_gpu_shader_edges_overlay_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_text_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_text_geom_glsl[];
|
||||
extern char datatoc_gpu_shader_text_frag_glsl[];
|
||||
extern char datatoc_gpu_shader_keyframe_diamond_vert_glsl[];
|
||||
extern char datatoc_gpu_shader_keyframe_diamond_frag_glsl[];
|
||||
|
@ -649,7 +650,9 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
|
|||
[GPU_SHADER_SMOKE_FIRE] = { datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl },
|
||||
[GPU_SHADER_SMOKE_COBA] = { datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl },
|
||||
|
||||
[GPU_SHADER_TEXT] = { datatoc_gpu_shader_text_vert_glsl, datatoc_gpu_shader_text_frag_glsl },
|
||||
[GPU_SHADER_TEXT] = { datatoc_gpu_shader_text_vert_glsl,
|
||||
datatoc_gpu_shader_text_frag_glsl,
|
||||
datatoc_gpu_shader_text_geom_glsl },
|
||||
[GPU_SHADER_KEYFRAME_DIAMOND] = { datatoc_gpu_shader_keyframe_diamond_vert_glsl,
|
||||
datatoc_gpu_shader_keyframe_diamond_frag_glsl },
|
||||
[GPU_SHADER_EDGES_FRONT_BACK_PERSP] = { datatoc_gpu_shader_edges_front_back_persp_vert_glsl,
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
layout(points) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
||||
in vec4 pos_rect[];
|
||||
in vec4 tex_rect[];
|
||||
in vec4 color[];
|
||||
|
||||
flat out vec4 color_flat;
|
||||
noperspective out vec2 texCoord_interp;
|
||||
|
||||
void main()
|
||||
{
|
||||
color_flat = color[0];
|
||||
gl_Position.zw = vec2(0.0, 1.0);
|
||||
|
||||
gl_Position.xy = pos_rect[0].xy;
|
||||
texCoord_interp = tex_rect[0].xw;
|
||||
EmitVertex();
|
||||
|
||||
gl_Position.xy = pos_rect[0].zy;
|
||||
texCoord_interp = tex_rect[0].zw;
|
||||
EmitVertex();
|
||||
|
||||
gl_Position.xy = pos_rect[0].xw;
|
||||
texCoord_interp = tex_rect[0].xy;
|
||||
EmitVertex();
|
||||
|
||||
gl_Position.xy = pos_rect[0].zw;
|
||||
texCoord_interp = tex_rect[0].zy;
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
|
@ -1,16 +1,23 @@
|
|||
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
|
||||
in vec2 pos;
|
||||
in vec2 texCoord;
|
||||
in vec4 color;
|
||||
flat out vec4 color_flat;
|
||||
noperspective out vec2 texCoord_interp;
|
||||
in vec4 pos; /* rect */
|
||||
in vec4 tex; /* rect */
|
||||
in vec4 col;
|
||||
|
||||
out vec4 pos_rect;
|
||||
out vec4 tex_rect;
|
||||
out vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
|
||||
/* This won't work for real 3D ModelViewProjectionMatrix. */
|
||||
vec2 v1 = (ModelViewProjectionMatrix * vec4(pos.xy, 0.0, 1.0)).xy;
|
||||
vec2 v2 = (ModelViewProjectionMatrix * vec4(pos.zw, 0.0, 1.0)).xy;
|
||||
|
||||
color_flat = color;
|
||||
texCoord_interp = texCoord;
|
||||
pos_rect.xy = min(v1, v2);
|
||||
pos_rect.zw = max(v1, v2);
|
||||
|
||||
tex_rect = tex;
|
||||
color = col;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue