Merge pull request #16009 from unknownbrackets/softgpu-colors

softgpu: Store vertex colors as packed RGBA8
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2022-09-12 08:34:03 +02:00
commit 9292fd84e2
8 files changed
+92 -72

No files matched your search

+2 -2
View File
@@ -166,7 +166,7 @@ void BinManager::UpdateState(bool throughMode) {
if (HasDirty(SoftDirty::PIXEL_ALL | SoftDirty::SAMPLER_ALL | SoftDirty::RAST_ALL)) {
if (states_.Full())
Flush("states");
stateIndex_ = (int)states_.Push(RasterizerState());
stateIndex_ = (uint16_t)states_.Push(RasterizerState());
ComputeRasterizerState(&states_[stateIndex_], throughMode);
states_[stateIndex_].samplerID.cached.clut = cluts_[clutIndex_].readable;
@@ -312,7 +312,7 @@ void BinManager::UpdateClut(const void *src) {
PROFILE_THIS_SCOPE("bin_clut");
if (cluts_.Full())
Flush("cluts");
clutIndex_ = (int)cluts_.Push(BinClut());
clutIndex_ = (uint16_t)cluts_.Push(BinClut());
memcpy(cluts_[clutIndex_].readable, src, sizeof(BinClut));
}
+4 -4
View File
@@ -24,7 +24,7 @@
struct BinWaitable;
class DrawBinItemsTask;
enum class BinItemType {
enum class BinItemType : uint8_t {
TRIANGLE,
CLEAR_RECT,
RECT,
@@ -48,7 +48,7 @@ struct BinCoords {
struct BinItem {
BinItemType type;
int stateIndex;
uint16_t stateIndex;
BinCoords range;
VertexData v0;
VertexData v1;
@@ -237,9 +237,9 @@ protected:
private:
BinStateQueue states_;
int stateIndex_;
BinClutQueue cluts_;
int clutIndex_;
uint16_t stateIndex_;
uint16_t clutIndex_;
BinCoords scissor_;
BinItemQueue queue_;
BinCoords queueRange_;
+38 -19
View File
@@ -79,6 +79,7 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) {
id->stencilTest = gstate.isStencilTestEnabled();
}
id->depthWrite = gstate.isDepthTestEnabled() && gstate.isDepthWriteEnabled();
id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS;
if (id->stencilTest) {
id->stencilTestRef = gstate.getStencilTestRef() & gstate.getStencilTestMask();
@@ -93,13 +94,6 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) {
if (gstate.FrameBufFormat() != GE_FORMAT_565 && gstate.getStencilOpZPass() <= GE_STENCILOP_DECR)
id->zPass = gstate.getStencilOpZPass();
// Always treat zPass/zFail the same if there's no depth test.
if (!gstate.isDepthTestEnabled() || gstate.getDepthTestFunction() == GE_COMP_ALWAYS)
id->zFail = id->zPass;
// And same for sFail if there's no stencil test.
if (id->StencilTestFunc() == GE_COMP_ALWAYS)
id->sFail = id->zPass;
// Normalize REPLACE 00 to ZERO, especially if using a mask.
if (gstate.getStencilTestRef() == 0) {
if (id->SFail() == GE_STENCILOP_REPLACE)
@@ -120,14 +114,27 @@ void ComputePixelFuncID(PixelFuncID *id, bool throughMode) {
id->zPass = GE_STENCILOP_ZERO;
}
// Turn off stencil testing if it's doing nothing.
if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) {
if (id->StencilTestFunc() == GE_COMP_ALWAYS)
// And same for sFail if there's no stencil test. Prefer KEEP, though.
if (id->StencilTestFunc() == GE_COMP_ALWAYS) {
if (id->DepthTestFunc() == GE_COMP_ALWAYS)
id->zFail = GE_STENCILOP_KEEP;
id->sFail = GE_STENCILOP_KEEP;
// Always doesn't need a mask.
id->stencilTestRef = gstate.getStencilTestRef();
id->hasStencilTestMask = false;
// Turn off stencil testing if it's doing nothing.
if (id->SFail() == GE_STENCILOP_KEEP && id->ZFail() == GE_STENCILOP_KEEP && id->ZPass() == GE_STENCILOP_KEEP) {
id->stencilTest = false;
id->stencilTestFunc = 0;
id->stencilTestRef = 0;
}
} else if (id->DepthTestFunc() == GE_COMP_ALWAYS) {
// Always treat zPass/zFail the same if there's no depth test.
id->zFail = id->zPass;
}
}
id->depthTestFunc = gstate.isDepthTestEnabled() ? gstate.getDepthTestFunction() : GE_COMP_ALWAYS;
id->alphaTestFunc = gstate.isAlphaTestEnabled() ? gstate.getAlphaTestFunction() : GE_COMP_ALWAYS;
if (id->AlphaTestFunc() != GE_COMP_ALWAYS) {
id->alphaTestRef = gstate.getAlphaTestRef() & gstate.getAlphaTestMask();
@@ -312,7 +319,8 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
}
if (id.hasStencilTestMask)
desc += "Msk";
desc += StringFromFormat("%02X:", id.stencilTestRef);
if (id.StencilTestFunc() != GE_COMP_ALWAYS || id.DepthTestFunc() != GE_COMP_ALWAYS)
desc += StringFromFormat("%02X:", id.stencilTestRef);
} else if (id.hasStencilTestMask || id.stencilTestRef != 0 || id.stencilTestFunc != 0) {
desc = "INVALID:" + desc;
}
@@ -333,13 +341,24 @@ std::string DescribePixelFuncID(const PixelFuncID &id) {
case GE_STENCILOP_INCR: desc += "ZTstFInc:"; break;
case GE_STENCILOP_DECR: desc += "ZTstFDec:"; break;
}
switch (id.ZPass()) {
case GE_STENCILOP_KEEP: break;
case GE_STENCILOP_ZERO: desc += "ZTstT0:"; break;
case GE_STENCILOP_REPLACE: desc += "ZTstTRpl:"; break;
case GE_STENCILOP_INVERT: desc += "ZTstTXor:"; break;
case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break;
case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break;
if (id.StencilTestFunc() == GE_COMP_ALWAYS && id.DepthTestFunc() == GE_COMP_ALWAYS) {
switch (id.ZPass()) {
case GE_STENCILOP_KEEP: break;
case GE_STENCILOP_ZERO: desc += "Zero:"; break;
case GE_STENCILOP_REPLACE: desc += StringFromFormat("Rpl%02X:", id.stencilTestRef); break;
case GE_STENCILOP_INVERT: desc += "Xor:"; break;
case GE_STENCILOP_INCR: desc += "Inc:"; break;
case GE_STENCILOP_DECR: desc += "Dec:"; break;
}
} else {
switch (id.ZPass()) {
case GE_STENCILOP_KEEP: break;
case GE_STENCILOP_ZERO: desc += "ZTstT0:"; break;
case GE_STENCILOP_REPLACE: desc += "ZTstTRpl:"; break;
case GE_STENCILOP_INVERT: desc += "ZTstTXor:"; break;
case GE_STENCILOP_INCR: desc += "ZTstTInc:"; break;
case GE_STENCILOP_DECR: desc += "ZTstTDec:"; break;
}
}
if (!id.stencilTest || id.clearMode) {
if (id.sFail != 0 || id.zFail != 0 || id.zPass != 0)
+4 -4
View File
@@ -276,12 +276,12 @@ void Process(VertexData &vertex, const WorldCoords &worldpos, const WorldCoords
}
if (state.setColor1) {
vertex.color0 = final_color.Clamp(0, 255);
vertex.color1 = specular_color.Clamp(0, 255).rgb();
vertex.color0 = final_color.Clamp(0, 255).ToRGBA();
vertex.color1 = specular_color.Clamp(0, 255).rgb().ToRGB();
} else if (state.addColor1) {
vertex.color0 = (final_color + specular_color).Clamp(0, 255);
vertex.color0 = (final_color + specular_color).Clamp(0, 255).ToRGBA();
} else {
vertex.color0 = final_color.Clamp(0, 255);
vertex.color0 = final_color.Clamp(0, 255).ToRGBA();
}
}
+27 -15
View File
@@ -721,6 +721,13 @@ void DrawTriangleSlice(
std::string ztag = StringFromFormat("DisplayListTZ_%08x", state.listPC);
#endif
const Vec4<int> v0_c0 = Vec4<int>::FromRGBA(v0.color0);
const Vec4<int> v1_c0 = Vec4<int>::FromRGBA(v1.color0);
const Vec4<int> v2_c0 = Vec4<int>::FromRGBA(v2.color0);
const Vec3<int> v0_c1 = Vec3<int>::FromRGB(v0.color1);
const Vec3<int> v1_c1 = Vec3<int>::FromRGB(v1.color1);
const Vec3<int> v2_c1 = Vec3<int>::FromRGB(v2.color1);
for (int64_t curY = minY; curY <= maxY; curY += SCREEN_SCALE_FACTOR * 2,
w0_base = e0.StepY(w0_base),
w1_base = e1.StepY(w1_base),
@@ -790,22 +797,22 @@ void DrawTriangleSlice(
if (!flatColor0) {
for (int i = 0; i < 4; ++i) {
if (mask[i] >= 0)
prim_color[i] = Interpolate(v0.color0, v1.color0, v2.color0, w0[i], w1[i], w2[i], wsum_recip[i]);
prim_color[i] = Interpolate(v0_c0, v1_c0, v2_c0, w0[i], w1[i], w2[i], wsum_recip[i]);
}
} else {
for (int i = 0; i < 4; ++i) {
prim_color[i] = v2.color0;
prim_color[i] = v2_c0;
}
}
Vec3<int> sec_color[4];
if (!flatColor1) {
for (int i = 0; i < 4; ++i) {
if (mask[i] >= 0)
sec_color[i] = Interpolate(v0.color1, v1.color1, v2.color1, w0[i], w1[i], w2[i], wsum_recip[i]);
sec_color[i] = Interpolate(v0_c1, v1_c1, v2_c1, w0[i], w1[i], w2[i], wsum_recip[i]);
}
} else {
for (int i = 0; i < 4; ++i) {
sec_color[i] = v2.color1;
sec_color[i] = v2_c1;
}
}
@@ -965,9 +972,10 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &
const Vec4f tto4(0.0f, 0.5f * stx.t(), 0.5f * sty.t(), 0.5f * stx.t() + 0.5f * sty.t());
ScreenCoords pprime(minX, minY, 0);
Vec4<int> fog = Vec4<int>::AssignToAll(ClampFogDepth(v1.fogdepth));
Vec4<int> z = Vec4<int>::AssignToAll(v1.screenpos.z);
Vec3<int> sec_color = v1.color1;
const Vec4<int> fog = Vec4<int>::AssignToAll(ClampFogDepth(v1.fogdepth));
const Vec4<int> z = Vec4<int>::AssignToAll(v1.screenpos.z);
const Vec4<int> c0 = Vec4<int>::FromRGBA(v1.color0);
const Vec3<int> sec_color = Vec3<int>::FromRGB(v1.color1);
if (state.pixelID.applyDepthRange) {
// We can bail early since the Z is flat.
@@ -997,7 +1005,7 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &
Vec4<int> prim_color[4];
for (int i = 0; i < 4; ++i) {
prim_color[i] = v1.color0;
prim_color[i] = c0;
}
if (state.pixelID.earlyZChecks) {
@@ -1073,8 +1081,8 @@ void DrawRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &
void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerState &state) {
ScreenCoords pos = v0.screenpos;
Vec4<int> prim_color = v0.color0;
Vec3<int> sec_color = v0.color1;
Vec4<int> prim_color = Vec4<int>::FromRGBA(v0.color0);
Vec3<int> sec_color = Vec3<int>::FromRGB(v0.color1);
auto &pixelID = state.pixelID;
auto &samplerID = state.samplerID;
@@ -1218,7 +1226,7 @@ void ClearRectangle(const VertexData &v0, const VertexData &v1, const BinCoords
keepOldMask |= pixelID.cached.colorWriteMask;
}
const u32 new_color = v1.color0.ToRGBA();
const u32 new_color = v1.color0;
u16 new_color16;
switch (pixelID.FBFormat()) {
case GE_FORMAT_565:
@@ -1343,6 +1351,10 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range
auto &samplerID = state.samplerID;
const bool interpolateColor = !state.shadeGouraud || (v0.color0 == v1.color0 && v0.color1 == v1.color1);
const Vec4<int> v0_c0 = Vec4<int>::FromRGBA(v0.color0);
const Vec4<int> v1_c0 = Vec4<int>::FromRGBA(v1.color0);
const Vec3<int> v0_c1 = Vec3<int>::FromRGB(v0.color1);
const Vec3<int> v1_c1 = Vec3<int>::FromRGB(v1.color1);
#if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC)
std::string tag = StringFromFormat("DisplayListL_%08x", state.listPC);
@@ -1375,11 +1387,11 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range
Vec4<int> prim_color;
Vec3<int> sec_color;
if (interpolateColor) {
prim_color = (v0.color0 * (steps - i) + v1.color0 * i) / steps1;
sec_color = (v0.color1 * (steps - i) + v1.color1 * i) / steps1;
prim_color = (v0_c0 * (steps - i) + v1_c0 * i) / steps1;
sec_color = (v0_c1 * (steps - i) + v1_c1 * i) / steps1;
} else {
prim_color = v1.color0;
sec_color = v1.color1;
prim_color = v1_c0;
sec_color = v1_c1;
}
u8 fog = 255;
+9 -8
View File
@@ -119,7 +119,7 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran
int z = v1.screenpos.z;
int fog = 255;
bool isWhite = v1.color0 == Vec4<int>(255, 255, 255, 255);
bool isWhite = v1.color0 == 0xFFFFFFFF;
if (state.enableTextures) {
// 1:1 (but with mirror support) texture mapping!
@@ -176,11 +176,12 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran
}
} else {
int t = t_start;
const Vec4<int> c0 = Vec4<int>::FromRGBA(v1.color0);
for (int y = pos0.y; y < pos1.y; y++) {
int s = s_start;
u16 *pixel = fb.Get16Ptr(pos0.x, y, pixelID.cached.framebufStride);
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v1.color0;
Vec4<int> prim_color = c0;
Vec4<int> tex_color = fetchFunc(s, t, texptr, texbufw, 0, state.samplerID);
prim_color = Vec4<int>(ModulateRGBA(ToVec4IntArg(prim_color), ToVec4IntArg(tex_color), state.samplerID));
if (prim_color.a() > 0) {
@@ -202,11 +203,12 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran
float tf_start = t_start * (1.0f / (float)(1 << state.samplerID.height0Shift));
float t = tf_start;
const Vec4<int> c0 = Vec4<int>::FromRGBA(v1.color0);
for (int y = pos0.y; y < pos1.y; y++) {
float s = sf_start;
// Not really that fast but faster than triangle.
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = state.nearest(s, t, xoff, yoff, ToVec4IntArg(v1.color0), &texptr, &texbufw, 0, 0, state.samplerID);
Vec4<int> prim_color = state.nearest(s, t, xoff, yoff, ToVec4IntArg(c0), &texptr, &texbufw, 0, 0, state.samplerID);
state.drawPixel(x, y, z, 255, ToVec4IntArg(prim_color), pixelID);
s += dsf;
}
@@ -227,21 +229,20 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran
AlphaTestIsNeedless(pixelID) &&
!pixelID.applyColorWriteMask &&
pixelID.FBFormat() == GE_FORMAT_5551) {
if (v1.color0.a() == 0)
if (Vec4<int>::FromRGBA(v1.color0).a() == 0)
return;
for (int y = pos0.y; y < pos1.y; y++) {
u16 *pixel = fb.Get16Ptr(pos0.x, y, pixelID.cached.framebufStride);
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v1.color0;
DrawSinglePixel5551(pixel, prim_color.ToRGBA(), pixelID);
DrawSinglePixel5551(pixel, v1.color0, pixelID);
pixel++;
}
}
} else {
const Vec4<int> prim_color = Vec4<int>::FromRGBA(v1.color0);
for (int y = pos0.y; y < pos1.y; y++) {
for (int x = pos0.x; x < pos1.x; x++) {
Vec4<int> prim_color = v1.color0;
state.drawPixel(x, y, z, fog, ToVec4IntArg(prim_color), pixelID);
}
}
@@ -311,7 +312,7 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b
// Afterwards, we also need to clear the actual destination. Can do a fast rectfill.
gstate.textureMapEnable &= ~1;
VertexData newV1 = v1;
newV1.color0 = Vec4<int>(0, 0, 0, 255);
newV1.color0 = 0xFF000000;
binner.AddSprite(v0, newV1);
gstate.textureMapEnable |= 1;
}
+3 -15
View File
@@ -317,24 +317,12 @@ VertexData TransformUnit::ReadVertex(VertexReader &vreader, const TransformState
}
if (vreader.hasColor0()) {
#ifdef _M_SSE
vreader.ReadColor0_8888((u8 *)vertex.color0.AsArray());
vertex.color0.ivec = _mm_unpacklo_epi8(vertex.color0.ivec, _mm_setzero_si128());
vertex.color0.ivec = _mm_unpacklo_epi16(vertex.color0.ivec, _mm_setzero_si128());
#else
float col[4];
vreader.ReadColor0(col);
vertex.color0 = Vec4<int>(col[0]*255, col[1]*255, col[2]*255, col[3]*255);
#endif
vreader.ReadColor0_8888((u8 *)&vertex.color0);
} else {
vertex.color0 = Vec4<int>::FromRGBA(gstate.getMaterialAmbientRGBA());
vertex.color0 = gstate.getMaterialAmbientRGBA();
}
#ifdef _M_SSE
vertex.color1 = _mm_setzero_si128();
#else
vertex.color1 = Vec3<int>(0, 0, 0);
#endif
vertex.color1 = 0;
if (state.enableTransform) {
WorldCoords worldpos;
+5 -5
View File
@@ -79,15 +79,15 @@ struct VertexData {
texturecoords = ::Lerp(a.texturecoords, b.texturecoords, t);
fogdepth = ::Lerp(a.fogdepth, b.fogdepth, t);
u16 t_int = (u16)(t*256);
color0 = LerpInt<Vec4<int>,256>(a.color0, b.color0, t_int);
color1 = LerpInt<Vec3<int>,256>(a.color1, b.color1, t_int);
u16 t_int = (u16)(t * 256);
color0 = LerpInt<Vec4<int>, 256>(Vec4<int>::FromRGBA(a.color0), Vec4<int>::FromRGBA(b.color0), t_int).ToRGBA();
color1 = LerpInt<Vec3<int>, 256>(Vec3<int>::FromRGB(a.color1), Vec3<int>::FromRGB(b.color1), t_int).ToRGB();
}
ClipCoords clippos;
Vec2<float> texturecoords;
Vec4<int> color0;
Vec3<int> color1;
uint32_t color0;
uint32_t color1;
ScreenCoords screenpos; // TODO: Shouldn't store this ?
float fogdepth;
};