mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-09 11:41:35 -10:00
gfx/drivers: drop dead prim_to_d3d helpers in d3d8/d3d9_cg/d3d9_hlsl
Each of the three D3D fixed-pipeline drivers carries an identical
gfx_display_prim_to_d3d{8,9_cg,9_hlsl}_enum helper plus a caller-
side switch on draw->prim_type. Both are dead.
Every gfx_display_ctx_draw_t in the codebase sets prim_type to
GFX_DISPLAY_PRIM_TRIANGLESTRIP before invoking dispctx->draw. All
19 "prim_type =" assignments under gfx/, menu/, and gfx/widgets/
assign TRIANGLESTRIP -- never TRIANGLES, never NONE. Every local
declaration of the draw struct assigns prim_type before the draw
call (swept each one). At runtime the helper switch always hits
the TRIANGLESTRIP arm and the caller's per-call branch always
takes the tristrip path.
The dead non-tristrip branch was also buggy: it mapped TRIANGLES
to D3DPT_TRIANGLESTRIP (wrong primitive -- gl1/2/3 correctly map
it to GL_TRIANGLES) and used count = vertices (wrong formula for
DrawPrimitive, which takes PrimitiveCount; the right formula is
vertices/3). And the helpers' TODO/FIXME default returned zero,
which is not a legal D3DPRIMITIVETYPE value (the enum starts at
D3DPT_POINTLIST = 1) -- a debug runtime would reject the call.
Inline D3DPT_TRIANGLESTRIP at the DrawPrimitive site, drop the
helpers and the dead caller branches, drop the now-unused
D3DPRIMITIVETYPE locals. Document at each call site that this
assumes TRIANGLESTRIP and would need to grow back into a switch
if a future non-tristrip caller appears.
While here, harden d3d9_cg and d3d9_hlsl against vertices < 3.
Both used count = vertices - 2 unconditionally, which on an
unsigned subtraction with vertices < 2 wraps to a huge primitive
count and walks off the vertex buffer in the GPU. d3d8 already
had this guard; the d3d9 pair did not. No caller passes < 3
vertices today, but the same "no caller does this" reasoning is
what kept the dead switch alive, so add the guard symmetrically.
Net -38 lines. No behavioural change for any existing caller.
This commit is contained in:
1 parent
d483ed098b
commit
1ee88d08de
3 files changed
+43
-81
No files matched your search
+15
-35
@@ -657,23 +657,6 @@ static void *gfx_display_d3d8_get_default_mvp(void *data)
|
||||
return &id;
|
||||
}
|
||||
|
||||
static INT32 gfx_display_prim_to_d3d8_enum(
|
||||
enum gfx_display_prim_type prim_type)
|
||||
{
|
||||
switch (prim_type)
|
||||
{
|
||||
case GFX_DISPLAY_PRIM_TRIANGLES:
|
||||
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
|
||||
return D3DPT_TRIANGLESTRIP;
|
||||
case GFX_DISPLAY_PRIM_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO/FIXME - hack */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gfx_display_d3d8_blend_begin(void *data)
|
||||
{
|
||||
d3d8_video_t *d3d = (d3d8_video_t*)data;
|
||||
@@ -710,7 +693,6 @@ static void gfx_display_d3d8_draw(gfx_display_ctx_draw_t *draw,
|
||||
math_matrix_4x4 mop, m1, m2;
|
||||
LPDIRECT3DVERTEXBUFFER8 vbo;
|
||||
LPDIRECT3DDEVICE8 dev;
|
||||
D3DPRIMITIVETYPE type;
|
||||
unsigned start = 0;
|
||||
unsigned count = 0;
|
||||
d3d8_video_t *d3d = (d3d8_video_t*)data;
|
||||
@@ -1005,32 +987,30 @@ static void gfx_display_d3d8_draw(gfx_display_ctx_draw_t *draw,
|
||||
IDirect3DDevice8_SetTextureStageState(dev, 0,
|
||||
(D3DTEXTURESTAGESTATETYPE)D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
|
||||
|
||||
type = gfx_display_prim_to_d3d8_enum(draw->prim_type);
|
||||
start = d3d->menu_display.offset;
|
||||
|
||||
/* For tristrips, the primitive count is vertices - 2. Guard
|
||||
* against vertices < 3 which would underflow the unsigned
|
||||
/* Every caller in the codebase sets draw->prim_type to
|
||||
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, and the draw->coords vertices
|
||||
* are laid out as a strip. Hard-code D3DPT_TRIANGLESTRIP and the
|
||||
* (vertices - 2) primitive-count formula here. If a future
|
||||
* caller passes TRIANGLES or another primitive type, this site
|
||||
* will need to grow back into a switch -- but with no current
|
||||
* non-tristrip caller, the dead branch was just buggy: it mapped
|
||||
* TRIANGLES to D3DPT_TRIANGLESTRIP (the wrong type) and used
|
||||
* count = vertices (the wrong count formula for D3D, which
|
||||
* expects PrimitiveCount, not vertex count).
|
||||
*
|
||||
* Guard against vertices < 3 which would underflow the unsigned
|
||||
* subtraction and pass a huge primitive count to the GPU. */
|
||||
if (draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
|
||||
{
|
||||
if (draw->coords->vertices < 3)
|
||||
{
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
return;
|
||||
}
|
||||
count = draw->coords->vertices - 2;
|
||||
}
|
||||
else
|
||||
count = draw->coords->vertices;
|
||||
|
||||
if (count == 0)
|
||||
if (draw->coords->vertices < 3)
|
||||
{
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
return;
|
||||
}
|
||||
count = draw->coords->vertices - 2;
|
||||
|
||||
IDirect3DDevice8_BeginScene(dev);
|
||||
IDirect3DDevice8_DrawPrimitive(dev, type, start, count);
|
||||
IDirect3DDevice8_DrawPrimitive(dev, D3DPT_TRIANGLESTRIP, start, count);
|
||||
IDirect3DDevice8_EndScene(dev);
|
||||
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
|
||||
+14
-23
@@ -476,23 +476,6 @@ static const float d3d9_cg_tex_coords[8] = {
|
||||
1, 0
|
||||
};
|
||||
|
||||
static INT32 gfx_display_prim_to_d3d9_cg_enum(
|
||||
enum gfx_display_prim_type prim_type)
|
||||
{
|
||||
switch (prim_type)
|
||||
{
|
||||
case GFX_DISPLAY_PRIM_TRIANGLES:
|
||||
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
|
||||
return D3DPT_TRIANGLESTRIP;
|
||||
case GFX_DISPLAY_PRIM_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO/FIXME - hack */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gfx_display_d3d9_cg_blend_begin(void *data)
|
||||
{
|
||||
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
||||
@@ -672,7 +655,6 @@ static void gfx_display_d3d9_cg_draw(gfx_display_ctx_draw_t *draw,
|
||||
{
|
||||
unsigned i;
|
||||
LPDIRECT3DDEVICE9 dev;
|
||||
D3DPRIMITIVETYPE type;
|
||||
bool has_vertex_data;
|
||||
unsigned start = 0;
|
||||
unsigned count = 0;
|
||||
@@ -1038,13 +1020,22 @@ static void gfx_display_d3d9_cg_draw(gfx_display_ctx_draw_t *draw,
|
||||
|
||||
gfx_display_d3d9_cg_bind_texture(draw, d3d);
|
||||
|
||||
type = (D3DPRIMITIVETYPE)gfx_display_prim_to_d3d9_cg_enum(draw->prim_type);
|
||||
start = d3d->menu_display.offset;
|
||||
count = draw->coords->vertices -
|
||||
((draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
|
||||
? 2 : 0);
|
||||
|
||||
IDirect3DDevice9_DrawPrimitive(dev, type, start, count);
|
||||
/* Every caller in the codebase sets draw->prim_type to
|
||||
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, so the per-call switch on the
|
||||
* primitive type that used to live here was dead. See the
|
||||
* matching comment in d3d8.c's gfx_display_d3d8_draw for why we
|
||||
* also harden against vertices < 3 (the tristrip count formula
|
||||
* vertices - 2 underflows the unsigned subtraction otherwise). */
|
||||
if (draw->coords->vertices < 3)
|
||||
{
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
return;
|
||||
}
|
||||
count = draw->coords->vertices - 2;
|
||||
|
||||
IDirect3DDevice9_DrawPrimitive(dev, D3DPT_TRIANGLESTRIP, start, count);
|
||||
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
}
|
||||
|
||||
+14
-23
@@ -709,23 +709,6 @@ static const float d3d9_hlsl_tex_coords[8] = {
|
||||
|
||||
static LPDIRECT3DTEXTURE9 d3d9_hlsl_white_texture = NULL;
|
||||
|
||||
static INT32 gfx_display_prim_to_d3d9_hlsl_enum(
|
||||
enum gfx_display_prim_type prim_type)
|
||||
{
|
||||
switch (prim_type)
|
||||
{
|
||||
case GFX_DISPLAY_PRIM_TRIANGLES:
|
||||
case GFX_DISPLAY_PRIM_TRIANGLESTRIP:
|
||||
return D3DPT_TRIANGLESTRIP;
|
||||
case GFX_DISPLAY_PRIM_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO/FIXME - hack */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void gfx_display_d3d9_hlsl_blend_begin(void *data)
|
||||
{
|
||||
d3d9_video_t *d3d = (d3d9_video_t*)data;
|
||||
@@ -777,7 +760,6 @@ static void gfx_display_d3d9_hlsl_draw(gfx_display_ctx_draw_t *draw,
|
||||
{
|
||||
unsigned i;
|
||||
LPDIRECT3DDEVICE9 dev;
|
||||
D3DPRIMITIVETYPE type;
|
||||
bool has_vertex_data;
|
||||
unsigned start = 0;
|
||||
unsigned count = 0;
|
||||
@@ -1099,13 +1081,22 @@ static void gfx_display_d3d9_hlsl_draw(gfx_display_ctx_draw_t *draw,
|
||||
if (draw && draw->texture)
|
||||
gfx_display_d3d9_bind_texture(draw, d3d);
|
||||
|
||||
type = (D3DPRIMITIVETYPE)gfx_display_prim_to_d3d9_hlsl_enum(draw->prim_type);
|
||||
start = d3d->menu_display.offset;
|
||||
count = draw->coords->vertices -
|
||||
((draw->prim_type == GFX_DISPLAY_PRIM_TRIANGLESTRIP)
|
||||
? 2 : 0);
|
||||
|
||||
IDirect3DDevice9_DrawPrimitive(dev, type, start, count);
|
||||
/* Every caller in the codebase sets draw->prim_type to
|
||||
* GFX_DISPLAY_PRIM_TRIANGLESTRIP, so the per-call switch on the
|
||||
* primitive type that used to live here was dead. See the
|
||||
* matching comment in d3d8.c's gfx_display_d3d8_draw for why we
|
||||
* also harden against vertices < 3 (the tristrip count formula
|
||||
* vertices - 2 underflows the unsigned subtraction otherwise). */
|
||||
if (draw->coords->vertices < 3)
|
||||
{
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
return;
|
||||
}
|
||||
count = draw->coords->vertices - 2;
|
||||
|
||||
IDirect3DDevice9_DrawPrimitive(dev, D3DPT_TRIANGLESTRIP, start, count);
|
||||
|
||||
d3d->menu_display.offset += draw->coords->vertices;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user