Vita: Implement command batching
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c
index dae1211..fed4bb4 100644
--- a/src/render/vitagxm/SDL_render_vita_gxm.c
+++ b/src/render/vitagxm/SDL_render_vita_gxm.c
@@ -89,10 +89,6 @@ VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu
static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd);
-static int VITA_GXM_RenderDrawPoints(SDL_Renderer *renderer, const SDL_RenderCommand *cmd);
-
-static int VITA_GXM_RenderDrawLines(SDL_Renderer *renderer, const SDL_RenderCommand *cmd);
-
static int VITA_GXM_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
static int VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
@@ -462,10 +458,9 @@ VITA_GXM_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const
int color = data->drawstate.color;
- color_vertex *vertex = (color_vertex *)pool_memalign(
+ color_vertex *vertex = (color_vertex *)pool_malloc(
data,
- count * sizeof(color_vertex),
- sizeof(color_vertex)
+ count * sizeof(color_vertex)
);
cmd->data.draw.first = (size_t)vertex;
@@ -487,10 +482,9 @@ VITA_GXM_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const S
VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
int color = data->drawstate.color;
- color_vertex *vertex = (color_vertex *)pool_memalign(
+ color_vertex *vertex = (color_vertex *)pool_malloc(
data,
- (count-1) * 2 * sizeof(color_vertex),
- sizeof(color_vertex)
+ (count-1) * 2 * sizeof(color_vertex)
);
cmd->data.draw.first = (size_t)vertex;
@@ -526,10 +520,9 @@ VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu
if (texture) {
texture_vertex *vertices;
- vertices = (texture_vertex *)pool_memalign(
+ vertices = (texture_vertex *)pool_malloc(
data,
- count * sizeof(texture_vertex),
- sizeof(texture_vertex));
+ count * sizeof(texture_vertex));
if (!vertices) {
return -1;
@@ -567,10 +560,9 @@ VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Textu
} else {
color_vertex *vertices;
- vertices = (color_vertex *)pool_memalign(
+ vertices = (color_vertex *)pool_malloc(
data,
- count * sizeof(color_vertex),
- sizeof(color_vertex));
+ count * sizeof(color_vertex));
if (!vertices) {
return -1;
@@ -639,30 +631,6 @@ VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static int
-VITA_GXM_RenderDrawPoints(SDL_Renderer *renderer, const SDL_RenderCommand *cmd)
-{
- VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
-
- sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_POINT);
- sceGxmDraw(data->gxm_context, SCE_GXM_PRIMITIVE_POINTS, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, cmd->data.draw.count);
- sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_TRIANGLE_FILL);
-
- return 0;
-}
-
-static int
-VITA_GXM_RenderDrawLines(SDL_Renderer *renderer, const SDL_RenderCommand *cmd)
-{
- VITA_GXM_RenderData *data = (VITA_GXM_RenderData *) renderer->driverdata;
-
- sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_LINE);
- sceGxmDraw(data->gxm_context, SCE_GXM_PRIMITIVE_LINES, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, cmd->data.draw.count);
- sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_TRIANGLE_FILL);
- return 0;
-}
-
-
-static int
SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;
@@ -823,18 +791,6 @@ VITA_GXM_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *
break;
}
- case SDL_RENDERCMD_DRAW_POINTS: {
- SetDrawState(data, cmd);
- VITA_GXM_RenderDrawPoints(renderer, cmd);
- break;
- }
-
- case SDL_RENDERCMD_DRAW_LINES: {
- SetDrawState(data, cmd);
- VITA_GXM_RenderDrawLines(renderer, cmd);
- break;
- }
-
case SDL_RENDERCMD_FILL_RECTS: /* unused */
break;
@@ -844,19 +800,55 @@ VITA_GXM_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *
case SDL_RENDERCMD_COPY_EX: /* unused */
break;
+ case SDL_RENDERCMD_DRAW_POINTS:
+ case SDL_RENDERCMD_DRAW_LINES:
case SDL_RENDERCMD_GEOMETRY: {
- SDL_Texture *texture = cmd->data.draw.texture;
+ SDL_Texture *thistexture = cmd->data.draw.texture;
+ SDL_BlendMode thisblend = cmd->data.draw.blend;
+ const SDL_RenderCommandType thiscmdtype = cmd->command;
+ SDL_RenderCommand *finalcmd = cmd;
+ SDL_RenderCommand *nextcmd = cmd->next;
+ size_t count = cmd->data.draw.count;
int ret;
+ while (nextcmd != NULL) {
+ const SDL_RenderCommandType nextcmdtype = nextcmd->command;
+ if (nextcmdtype != thiscmdtype) {
+ break; /* can't go any further on this draw call, different render command up next. */
+ } else if (nextcmd->data.draw.texture != thistexture || nextcmd->data.draw.blend != thisblend) {
+ break; /* can't go any further on this draw call, different texture/blendmode copy up next. */
+ } else {
+ finalcmd = nextcmd; /* we can combine copy operations here. Mark this one as the furthest okay command. */
+ count += cmd->data.draw.count;
+ }
+ nextcmd = nextcmd->next;
+ }
- if (texture) {
+ if (thistexture) {
ret = SetCopyState(renderer, cmd);
} else {
ret = SetDrawState(data, cmd);
}
if (ret == 0) {
- sceGxmDraw(data->gxm_context, SCE_GXM_PRIMITIVE_TRIANGLES, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, cmd->data.draw.count);
+ int op = SCE_GXM_PRIMITIVE_TRIANGLES;
+
+ if (thiscmdtype == SDL_RENDERCMD_DRAW_POINTS) {
+ sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_POINT);
+ op = SCE_GXM_PRIMITIVE_POINTS;
+ } else if (thiscmdtype == SDL_RENDERCMD_DRAW_LINES) {
+ sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_LINE);
+ op = SCE_GXM_PRIMITIVE_LINES;
+ }
+
+ sceGxmDraw(data->gxm_context, op, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, count);
+
+ if (thiscmdtype == SDL_RENDERCMD_DRAW_POINTS || thiscmdtype == SDL_RENDERCMD_DRAW_LINES) {
+ sceGxmSetFrontPolygonMode(data->gxm_context, SCE_GXM_POLYGON_MODE_TRIANGLE_FILL);
+ }
+
}
+
+ cmd = finalcmd; /* skip any copy commands we just combined in here. */
break;
}