Skip to content

Commit b5d5b77

Browse files
committed
(D3D10/11/12/Vulkan) Function pointers for get_glyph and font_data
1 parent 7aed73f commit b5d5b77

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

gfx/drivers/d3d10.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,16 @@ static int d3d10_font_get_message_width(void* data,
901901
int delta_x = 0;
902902
const struct font_glyph* glyph_q = NULL;
903903
d3d10_font_t* font = (d3d10_font_t*)data;
904+
/* Hoist function pointer and data pointer out of the loop to avoid
905+
* repeated dependent loads through font->font_driver->get_glyph. */
906+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
907+
= font->font_driver->get_glyph;
908+
void *font_data = font->font_data;
904909

905910
if (!font)
906911
return 0;
907912

908-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
913+
glyph_q = get_glyph(font_data, '?');
909914

910915
for (i = 0; i < msg_len; i++)
911916
{
@@ -918,7 +923,7 @@ static int d3d10_font_get_message_width(void* data,
918923
i += skip - 1;
919924

920925
/* Do something smarter here ... */
921-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
926+
if (!(glyph = get_glyph(font_data, code)))
922927
if (!(glyph = glyph_q))
923928
continue;
924929

@@ -949,6 +954,11 @@ static void d3d10_font_render_line(
949954
const char* msg_end = msg + msg_len;
950955
int x = pre_x;
951956
int y = roundf((1.0 - pos_y) * height);
957+
/* Hoist function pointer and data pointer out of the loop to avoid
958+
* repeated dependent loads through font->font_driver->get_glyph. */
959+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
960+
= font->font_driver->get_glyph;
961+
void *font_data = font->font_data;
952962

953963
if (d3d10->sprites.offset + msg_len > (unsigned)d3d10->sprites.capacity)
954964
d3d10->sprites.offset = 0;
@@ -965,7 +975,7 @@ static void d3d10_font_render_line(
965975
{
966976
const struct font_glyph *glyph;
967977
uint32_t code = utf8_walk(&scan);
968-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
978+
if (!(glyph = get_glyph(font_data, code)))
969979
if (!(glyph = glyph_q))
970980
continue;
971981
width_accum += glyph->advance_x;
@@ -993,7 +1003,7 @@ static void d3d10_font_render_line(
9931003
i += skip - 1;
9941004

9951005
/* Do something smarter here ... */
996-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1006+
if (!(glyph = get_glyph(font_data, code)))
9971007
if (!(glyph = glyph_q))
9981008
continue;
9991009

gfx/drivers/d3d11.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,16 @@ static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_
10371037
int delta_x = 0;
10381038
const struct font_glyph* glyph_q = NULL;
10391039
d3d11_font_t* font = (d3d11_font_t*)data;
1040+
/* Hoist function pointer and data pointer out of the loop to avoid
1041+
* repeated dependent loads through font->font_driver->get_glyph. */
1042+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1043+
= font->font_driver->get_glyph;
1044+
void *font_data = font->font_data;
10401045

10411046
if (!font)
10421047
return 0;
10431048

1044-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
1049+
glyph_q = get_glyph(font_data, '?');
10451050

10461051
for (i = 0; i < msg_len; i++)
10471052
{
@@ -1054,7 +1059,7 @@ static int d3d11_font_get_message_width(void* data, const char* msg, size_t msg_
10541059
i += skip - 1;
10551060

10561061
/* Do something smarter here ... */
1057-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1062+
if (!(glyph = get_glyph(font_data, code)))
10581063
if (!(glyph = glyph_q))
10591064
continue;
10601065

gfx/drivers/d3d12.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,11 +1337,16 @@ static int d3d12_font_get_message_width(void* data,
13371337
int delta_x = 0;
13381338
const struct font_glyph* glyph_q = NULL;
13391339
d3d12_font_t* font = (d3d12_font_t*)data;
1340+
/* Hoist function pointer and data pointer out of the loop to avoid
1341+
* repeated dependent loads through font->font_driver->get_glyph. */
1342+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1343+
= font->font_driver->get_glyph;
1344+
void *font_data = font->font_data;
13401345

13411346
if (!font)
13421347
return 0;
13431348

1344-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
1349+
glyph_q = get_glyph(font_data, '?');
13451350

13461351
for (i = 0; i < msg_len; i++)
13471352
{
@@ -1354,7 +1359,7 @@ static int d3d12_font_get_message_width(void* data,
13541359
i += skip - 1;
13551360

13561361
/* Do something smarter here ... */
1357-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1362+
if (!(glyph = get_glyph(font_data, code)))
13581363
if (!(glyph = glyph_q))
13591364
continue;
13601365

@@ -1388,6 +1393,11 @@ static void d3d12_font_render_line(
13881393
d3d12_sprite_t* vbo_start = NULL;
13891394
int x = pre_x;
13901395
int y = roundf((1.0 - pos_y) * height);
1396+
/* Hoist function pointer and data pointer out of the loop to avoid
1397+
* repeated dependent loads through font->font_driver->get_glyph. */
1398+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1399+
= font->font_driver->get_glyph;
1400+
void *font_data = font->font_data;
13911401

13921402
if (d3d12->sprites.offset + msg_len > (unsigned)d3d12->sprites.capacity)
13931403
d3d12->sprites.offset = 0;
@@ -1415,7 +1425,7 @@ static void d3d12_font_render_line(
14151425
if (skip > 1)
14161426
i += skip - 1;
14171427

1418-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1428+
if (!(glyph = get_glyph(font_data, code)))
14191429
if (!(glyph = glyph_q))
14201430
continue;
14211431

gfx/drivers/vulkan.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,22 +1779,26 @@ static int vulkan_font_get_message_width(void *data, const char *msg,
17791779
vulkan_raster_t *font = (vulkan_raster_t*)data;
17801780
const char* msg_end = msg + msg_len;
17811781
int delta_x = 0;
1782+
/* Hoist function pointer and data pointer out of the loop to avoid
1783+
* repeated dependent loads through font->font_driver->get_glyph. */
1784+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1785+
= font->font_driver->get_glyph;
1786+
void *font_data = font->font_data;
17821787

17831788
if ( !font
17841789
|| !font->font_driver
17851790
|| !font->font_data )
17861791
return 0;
17871792

1788-
glyph_q = font->font_driver->get_glyph(font->font_data, '?');
1793+
glyph_q = get_glyph(font_data, '?');
17891794

17901795
while (msg < msg_end)
17911796
{
17921797
const struct font_glyph *glyph;
17931798
uint32_t code = utf8_walk(&msg);
17941799

17951800
/* Do something smarter here ... */
1796-
if (!(glyph = font->font_driver->get_glyph(
1797-
font->font_data, code)))
1801+
if (!(glyph = get_glyph(font_data, code)))
17981802
if (!(glyph = glyph_q))
17991803
continue;
18001804

@@ -1831,6 +1835,11 @@ static void vulkan_font_render_line(vk_t *vk,
18311835
int y = roundf((1.0f - pos_y) * vk->vp.height);
18321836
int delta_x = 0;
18331837
int delta_y = 0;
1838+
/* Hoist function pointer and data pointer out of the loop to avoid
1839+
* repeated dependent loads through font->font_driver->get_glyph. */
1840+
const struct font_glyph* (*get_glyph)(void*, uint32_t)
1841+
= font->font_driver->get_glyph;
1842+
void *font_data = font->font_data;
18341843

18351844
vk_color.r = color[0];
18361845
vk_color.g = color[1];
@@ -1850,7 +1859,7 @@ static void vulkan_font_render_line(vk_t *vk,
18501859
{
18511860
const struct font_glyph *glyph;
18521861
uint32_t code = utf8_walk(&scan);
1853-
if (!(glyph = font->font_driver->get_glyph(font->font_data, code)))
1862+
if (!(glyph = get_glyph(font_data, code)))
18541863
if (!(glyph = glyph_q))
18551864
continue;
18561865
width_accum += glyph->advance_x;
@@ -1869,8 +1878,7 @@ static void vulkan_font_render_line(vk_t *vk,
18691878
unsigned code = utf8_walk(&msg);
18701879

18711880
/* Do something smarter here ... */
1872-
if (!(glyph =
1873-
font->font_driver->get_glyph(font->font_data, code)))
1881+
if (!(glyph = get_glyph(font_data, code)))
18741882
if (!(glyph = glyph_q))
18751883
continue;
18761884

0 commit comments

Comments
 (0)