Skip to content

Commit

Permalink
More speed
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Oct 27, 2019
1 parent bbbd7f8 commit eb53609
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 28 deletions.
89 changes: 61 additions & 28 deletions GPU/Software/Rasterizer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1287,26 +1287,26 @@ void DrawTriangleSlice(
} }
} }



// Through mode, with the specific Darkstalker settings. // Through mode, with the specific Darkstalker settings.
inline void DrawSinglePixel5551(const DrawingCoords &p, const Vec4<int> &color_in) { inline void DrawSinglePixel5551(const DrawingCoords &p, const Vec4<int> &color_in) {
Vec4<int> prim_color = color_in; if (color_in.a() == 0)
if (prim_color.a() == 0)
return; return;


const u32 old_color = GetPixelColor(p.x, p.y); u16 *pixel = fb.Get16Ptr(p.x, p.y, gstate.FrameBufStride());
u32 new_color;

u8 stencil = GetPixelStencil(p.x, p.y);


const Vec4<int> dst = Vec4<int>::FromRGBA(old_color); u32 new_color;
Vec3<int> blended = AlphaBlendingResult(prim_color, dst); if (color_in.a() == 255) {
const u32 old_color = RGBA5551ToRGBA8888(*pixel);
const Vec4<int> dst = Vec4<int>::FromRGBA(old_color);
Vec3<int> blended = AlphaBlendingResult(color_in, dst);
// ToRGB() always automatically clamps.
new_color = blended.ToRGB();
} else {
new_color = color_in.ToRGBA() & 0xFFFFFF;
}


// ToRGB() always automatically clamps. new_color |= (*pixel & 0x8000) ? 0xff000000 : 0x00000000;
new_color = blended.ToRGB(); *pixel = RGBA8888ToRGBA5551(new_color);
new_color |= stencil << 24;
new_color = (new_color & ~gstate.getColorMask()) | (old_color & gstate.getColorMask());
SetPixelColor(p.x, p.y, new_color);
} }


static inline Vec4<int> ModulateRGBA(const Vec4<int>& prim_color, const Vec4<int>& texcolor) { static inline Vec4<int> ModulateRGBA(const Vec4<int>& prim_color, const Vec4<int>& texcolor) {
Expand Down Expand Up @@ -1339,7 +1339,6 @@ static inline Vec4<int> ModulateRGBA(const Vec4<int>& prim_color, const Vec4<int


} }



void DrawSprite(const VertexData& v0, const VertexData& v1) { void DrawSprite(const VertexData& v0, const VertexData& v1) {
const u8 *texptr = nullptr; const u8 *texptr = nullptr;


Expand All @@ -1361,6 +1360,8 @@ void DrawSprite(const VertexData& v0, const VertexData& v1) {
int z = pos0.z; int z = pos0.z;
float fog = 1.0f; float fog = 1.0f;


bool isWhite = v0.color0 == Vec4<int>(255, 255, 255, 255);

if (gstate.isTextureMapEnabled()) { if (gstate.isTextureMapEnabled()) {
// 1:1 (but with mirror support) texture mapping! // 1:1 (but with mirror support) texture mapping!
int s_start = v0.texturecoords.x; int s_start = v0.texturecoords.x;
Expand Down Expand Up @@ -1399,18 +1400,27 @@ void DrawSprite(const VertexData& v0, const VertexData& v1) {
gstate.isAlphaBlendEnabled() && gstate.isAlphaBlendEnabled() &&
gstate.isTextureAlphaUsed() && gstate.isTextureAlphaUsed() &&
gstate.getTextureFunction() == GE_TEXFUNC_MODULATE && gstate.getTextureFunction() == GE_TEXFUNC_MODULATE &&
gstate.getColorMask() == 0x000000 &&
gstate.FrameBufFormat() == GE_FORMAT_5551) { gstate.FrameBufFormat() == GE_FORMAT_5551) {
int t = t_start; int t = t_start;
for (int y = pos0.y; y < pos1.y; y++) { for (int y = pos0.y; y < pos1.y; y++) {
int s = s_start; int s = s_start;
// Not really that fast but faster than triangle. if (isWhite) {
for (int x = pos0.x; x < pos1.x; x++) { for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v0.color0; Vec4<int> tex_color = Vec4<int>::FromRGBA(nearestFunc(s, t, texptr, texbufw, 0));
Vec4<int> tex_color = Vec4<int>::FromRGBA(nearestFunc(s, t, texptr, texbufw, 0)); DrawingCoords pos(x, y, z);
prim_color = ModulateRGBA(prim_color, tex_color); DrawSinglePixel5551(pos, tex_color);
DrawingCoords pos(x, y, z); s += ds;
DrawSinglePixel5551(pos, prim_color); }
s += ds; } else {
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v0.color0;
Vec4<int> tex_color = Vec4<int>::FromRGBA(nearestFunc(s, t, texptr, texbufw, 0));
prim_color = ModulateRGBA(prim_color, tex_color);
DrawingCoords pos(x, y, z);
DrawSinglePixel5551(pos, prim_color);
s += ds;
}
} }
t += dt; t += dt;
} }
Expand All @@ -1435,11 +1445,34 @@ void DrawSprite(const VertexData& v0, const VertexData& v1) {
if (pos1.y > scissorBR.y) pos1.y = scissorBR.y; if (pos1.y > scissorBR.y) pos1.y = scissorBR.y;
if (pos0.x < scissorTL.x) pos0.x = scissorTL.x; if (pos0.x < scissorTL.x) pos0.x = scissorTL.x;
if (pos0.y < scissorTL.y) pos0.y = scissorTL.y; if (pos0.y < scissorTL.y) pos0.y = scissorTL.y;
for (int y = pos0.y; y < pos1.y; y++) { if (!gstate.isStencilTestEnabled() &&
for (int x = pos0.x; x < pos1.x; x++) { !gstate.isDepthTestEnabled() &&
Vec4<int> prim_color = v0.color0; !gstate.isLogicOpEnabled() &&
DrawingCoords pos(x, y, z); !gstate.isColorTestEnabled() &&
DrawSinglePixel<false>(pos, (u16)z, fog, prim_color); !gstate.isDitherEnabled() &&
gstate.isAlphaTestEnabled() &&
gstate.getAlphaTestRef() == 0 &&
gstate.getAlphaTestMask() == 0xFF &&
gstate.isAlphaBlendEnabled() &&
gstate.isTextureAlphaUsed() &&
gstate.getTextureFunction() == GE_TEXFUNC_MODULATE &&
gstate.getColorMask() == 0x000000 &&
gstate.FrameBufFormat() == GE_FORMAT_5551) {

for (int y = pos0.y; y < pos1.y; y++) {
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v0.color0;
DrawingCoords pos(x, y, z);
DrawSinglePixel5551(pos, prim_color);
}
}
} else {
for (int y = pos0.y; y < pos1.y; y++) {
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v0.color0;
DrawingCoords pos(x, y, z);
DrawSinglePixel<false>(pos, (u16)z, fog, prim_color);
}
} }
} }
} }
Expand Down
4 changes: 4 additions & 0 deletions GPU/Software/SoftGpu.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ struct FormatBuffer {
inline u32 Get32(int x, int y, int stride) { inline u32 Get32(int x, int y, int stride) {
return as32[x + y * stride]; return as32[x + y * stride];
} }

inline u16 *Get16Ptr(int x, int y, int stride) {
return &as16[x + y * stride];
}
}; };


class SoftwareDrawEngine; class SoftwareDrawEngine;
Expand Down

0 comments on commit eb53609

Please sign in to comment.