mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 01:03:41 +01:00
softgpu: Remove offset from screenpos.
This simplifies tighter calculations, and reduces the common magnitudes we'll be dealing with.
This commit is contained in:
1 parent
7f505c0c23
commit
a66377fdf1
7 files changed
+33
-40
No files matched your search
@@ -155,13 +155,13 @@ static Vec3f ClipToScreen(const Vec4f& coords) {
|
||||
float z = coords.z * zScale / coords.w + zCenter;
|
||||
|
||||
// 16 = 0xFFFF / 4095.9375
|
||||
return Vec3f(x * 16, y * 16, z);
|
||||
return Vec3f(x * 16 - gstate.getOffsetX16(), y * 16 - gstate.getOffsetY16(), z);
|
||||
}
|
||||
|
||||
static Vec3f ScreenToDrawing(const Vec3f& coords) {
|
||||
Vec3f ret;
|
||||
ret.x = (coords.x - gstate.getOffsetX16()) * (1.0f / 16.0f);
|
||||
ret.y = (coords.y - gstate.getOffsetY16()) * (1.0f / 16.0f);
|
||||
ret.x = coords.x * (1.0f / 16.0f);
|
||||
ret.y = coords.y * (1.0f / 16.0f);
|
||||
ret.z = coords.z;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -188,13 +188,6 @@ void BinManager::UpdateState() {
|
||||
scissor_.x2 = screenScissorBR.x + 15;
|
||||
scissor_.y2 = screenScissorBR.y + 15;
|
||||
|
||||
// Our bin sizes are based on offset, so if that changes we have to flush.
|
||||
if (queueOffsetX_ != gstate.getOffsetX16() || queueOffsetY_ != gstate.getOffsetY16()) {
|
||||
Flush("offset");
|
||||
queueOffsetX_ = gstate.getOffsetX16();
|
||||
queueOffsetY_ = gstate.getOffsetY16();
|
||||
}
|
||||
|
||||
// If we're about to texture from something still pending (i.e. depth), flush.
|
||||
if (HasTextureWrite(state))
|
||||
Flush("tex");
|
||||
@@ -364,8 +357,8 @@ void BinManager::Drain() {
|
||||
int h2 = (queueRange_.y2 - queueRange_.y1 + 31) / 32;
|
||||
|
||||
// Always bin the entire possible range, but focus on the drawn area.
|
||||
ScreenCoords tl(queueOffsetX_, queueOffsetY_, 0);
|
||||
ScreenCoords br(queueOffsetX_ + 1024 * 16, queueOffsetY_ + 1024 * 16, 0);
|
||||
ScreenCoords tl(0, 0, 0);
|
||||
ScreenCoords br(1024 * 16, 1024 * 16, 0);
|
||||
|
||||
taskRanges_.clear();
|
||||
if (h2 >= 18 && w2 >= h2 * 4) {
|
||||
|
||||
@@ -234,8 +234,6 @@ private:
|
||||
BinCoords scissor_;
|
||||
BinItemQueue queue_;
|
||||
BinCoords queueRange_;
|
||||
int queueOffsetX_ = -1;
|
||||
int queueOffsetY_ = -1;
|
||||
SoftDirty dirty_ = SoftDirty::NONE;
|
||||
|
||||
int maxTasks_ = 1;
|
||||
|
||||
@@ -735,7 +735,7 @@ void DrawTriangleSlice(
|
||||
Vec4<int> w1 = w1_base;
|
||||
Vec4<int> w2 = w2_base;
|
||||
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(minX, curY, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(minX, curY);
|
||||
|
||||
int64_t rowMinX = minX, rowMaxX = maxX;
|
||||
e0.NarrowMinMaxX(w0, minX, rowMinX, rowMaxX);
|
||||
@@ -862,8 +862,8 @@ void DrawTriangleSlice(
|
||||
|
||||
#if !defined(SOFTGPU_MEMORY_TAGGING_DETAILED) && defined(SOFTGPU_MEMORY_TAGGING_BASIC)
|
||||
for (int y = minY; y <= maxY; y += 16) {
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(minX, y, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords pend = TransformUnit::ScreenToDrawing(maxX, y, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(minX, y);
|
||||
DrawingCoords pend = TransformUnit::ScreenToDrawing(maxX, y);
|
||||
uint32_t row = gstate.getFrameBufAddress() + p.y * pixelID.cached.framebufStride * bpp;
|
||||
NotifyMemInfo(MemBlockFlags::WRITE, row + p.x * bpp, (pend.x - p.x) * bpp, tag.c_str(), tag.size());
|
||||
|
||||
@@ -916,7 +916,7 @@ void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerSta
|
||||
if (!pixelID.clearMode)
|
||||
prim_color += Vec4<int>(sec_color, 0);
|
||||
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(pos, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(pos);
|
||||
u16 z = pos.z;
|
||||
|
||||
u8 fog = 255;
|
||||
@@ -943,8 +943,8 @@ void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerSta
|
||||
}
|
||||
|
||||
void ClearRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state) {
|
||||
DrawingCoords pprime = TransformUnit::ScreenToDrawing(range.x1, range.y1, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords pend = TransformUnit::ScreenToDrawing(range.x2, range.y2, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords pprime = TransformUnit::ScreenToDrawing(range.x1, range.y1);
|
||||
DrawingCoords pend = TransformUnit::ScreenToDrawing(range.x2, range.y2);
|
||||
auto &pixelID = state.pixelID;
|
||||
auto &samplerID = state.samplerID;
|
||||
|
||||
@@ -1209,7 +1209,7 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range
|
||||
|
||||
if (state.antialiasLines) {
|
||||
// TODO: This is a naive and wrong implementation.
|
||||
DrawingCoords p0 = TransformUnit::ScreenToDrawing(x, y, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords p0 = TransformUnit::ScreenToDrawing(x, y);
|
||||
s = ((float)p0.x + xinc / 32.0f) / 512.0f;
|
||||
t = ((float)p0.y + yinc / 32.0f) / 512.0f;
|
||||
|
||||
@@ -1224,7 +1224,7 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range
|
||||
prim_color += Vec4<int>(sec_color, 0);
|
||||
|
||||
PROFILE_THIS_SCOPE("draw_px");
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(x, y, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords p = TransformUnit::ScreenToDrawing(x, y);
|
||||
state.drawPixel(p.x, p.y, z, fog, ToVec4IntArg(prim_color), pixelID);
|
||||
|
||||
#if defined(SOFTGPU_MEMORY_TAGGING_DETAILED) || defined(SOFTGPU_MEMORY_TAGGING_BASIC)
|
||||
|
||||
@@ -88,12 +88,12 @@ void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &ran
|
||||
auto &pixelID = state.pixelID;
|
||||
auto &samplerID = state.samplerID;
|
||||
|
||||
DrawingCoords pos0 = TransformUnit::ScreenToDrawing(v0.screenpos, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords pos0 = TransformUnit::ScreenToDrawing(v0.screenpos);
|
||||
// Include the ending pixel based on its center, not start.
|
||||
DrawingCoords pos1 = TransformUnit::ScreenToDrawing(v1.screenpos + ScreenCoords(7, 7, 0), state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords pos1 = TransformUnit::ScreenToDrawing(v1.screenpos + ScreenCoords(7, 7, 0));
|
||||
|
||||
DrawingCoords scissorTL = TransformUnit::ScreenToDrawing(range.x1, range.y1, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords scissorBR = TransformUnit::ScreenToDrawing(range.x2, range.y2, state.screenOffsetX, state.screenOffsetY);
|
||||
DrawingCoords scissorTL = TransformUnit::ScreenToDrawing(range.x1, range.y1);
|
||||
DrawingCoords scissorBR = TransformUnit::ScreenToDrawing(range.x2, range.y2);
|
||||
|
||||
int z = v1.screenpos.z;
|
||||
int fog = 255;
|
||||
@@ -282,9 +282,9 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b
|
||||
if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && v0.texturecoords.x == 64.0f && v0.texturecoords.y == 16.0f && v1.texturecoords.x == 448.0f && v1.texturecoords.y == 240.0f) {
|
||||
// check for save/load dialog.
|
||||
if (!currentDialogActive) {
|
||||
if (v0.screenpos.x == 0x7100 && v0.screenpos.y == 0x7780 && v1.screenpos.x == 0x8f00 && v1.screenpos.y == 0x8880) {
|
||||
if (v0.screenpos.x + state.screenOffsetX == 0x7100 && v0.screenpos.y + state.screenOffsetY == 0x7780 && v1.screenpos.x + state.screenOffsetX == 0x8f00 && v1.screenpos.y + state.screenOffsetY == 0x8880) {
|
||||
g_DarkStalkerStretch = DSStretch::Wide;
|
||||
} else if (v0.screenpos.x == 0x7400 && v0.screenpos.y == 0x7780 && v1.screenpos.x == 0x8C00 && v1.screenpos.y == 0x8880) {
|
||||
} else if (v0.screenpos.x + state.screenOffsetX == 0x7400 && v0.screenpos.y + state.screenOffsetY == 0x7780 && v1.screenpos.x + state.screenOffsetX == 0x8C00 && v1.screenpos.y + state.screenOffsetY == 0x8880) {
|
||||
g_DarkStalkerStretch = DSStretch::Normal;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -125,7 +125,9 @@ static ScreenCoords ClipToScreenInternal(Vec3f scaled, const ClipCoords &coords,
|
||||
|
||||
// 16 = 0xFFFF / 4095.9375
|
||||
// Round up at 0.625 to the nearest subpixel.
|
||||
return ScreenCoords(scaled.x * 16.0f + 0.375f, scaled.y * 16.0f + 0.375f, scaled.z);
|
||||
int x = (int)(scaled.x * 16.0f + 0.375f - gstate.getOffsetX16());
|
||||
int y = (int)(scaled.y * 16.0f + 0.375f - gstate.getOffsetY16());
|
||||
return ScreenCoords(x, y, scaled.z);
|
||||
}
|
||||
|
||||
static inline ScreenCoords ClipToScreenInternal(const ClipCoords &coords, bool *outside_range_flag) {
|
||||
@@ -159,8 +161,8 @@ ScreenCoords TransformUnit::ClipToScreen(const ClipCoords &coords) {
|
||||
|
||||
ScreenCoords TransformUnit::DrawingToScreen(const DrawingCoords &coords, u16 z) {
|
||||
ScreenCoords ret;
|
||||
ret.x = (u32)coords.x * 16 + gstate.getOffsetX16();
|
||||
ret.y = (u32)coords.y * 16 + gstate.getOffsetY16();
|
||||
ret.x = (u32)coords.x * 16;
|
||||
ret.y = (u32)coords.y * 16;
|
||||
ret.z = z;
|
||||
return ret;
|
||||
}
|
||||
@@ -427,8 +429,8 @@ VertexData TransformUnit::ReadVertex(VertexReader &vreader, const TransformState
|
||||
if (state.enableLighting)
|
||||
Lighting::Process(vertex, worldpos, worldnormal, state.lightingState);
|
||||
} else {
|
||||
vertex.screenpos.x = (int)(pos[0] * 16) + state.screenOffsetX;
|
||||
vertex.screenpos.y = (int)(pos[1] * 16) + state.screenOffsetY;
|
||||
vertex.screenpos.x = (int)(pos[0] * 16);
|
||||
vertex.screenpos.y = (int)(pos[1] * 16);
|
||||
vertex.screenpos.z = pos[2];
|
||||
vertex.clippos.w = 1.f;
|
||||
vertex.fogdepth = 1.f;
|
||||
@@ -891,7 +893,7 @@ bool TransformUnit::GetCurrentSimpleVertices(int count, std::vector<GPUDebugVert
|
||||
float clipPos[4];
|
||||
Vec3ByMatrix44(clipPos, vert.pos.AsArray(), worldviewproj);
|
||||
ScreenCoords screenPos = ClipToScreen(clipPos);
|
||||
DrawingCoords drawPos = ScreenToDrawing(screenPos, gstate.getOffsetX16(), gstate.getOffsetY16());
|
||||
DrawingCoords drawPos = ScreenToDrawing(screenPos);
|
||||
|
||||
if (gstate.vertType & GE_VTYPE_TC_MASK) {
|
||||
vertices[i].u = vert.uv[0] * (float)gstate.getTextureWidth(0);
|
||||
|
||||
@@ -104,15 +104,15 @@ public:
|
||||
static ViewCoords WorldToView(const WorldCoords& coords);
|
||||
static ClipCoords ViewToClip(const ViewCoords& coords);
|
||||
static ScreenCoords ClipToScreen(const ClipCoords& coords);
|
||||
static inline DrawingCoords ScreenToDrawing(int x, int y, int offsetX, int offsetY) {
|
||||
static inline DrawingCoords ScreenToDrawing(int x, int y) {
|
||||
DrawingCoords ret;
|
||||
// When offset > coord, it correctly goes negative and force-scissors.
|
||||
ret.x = (x - offsetX) / 16;
|
||||
ret.y = (y - offsetY) / 16;
|
||||
// When offset > coord, this is negative and force-scissors.
|
||||
ret.x = x / 16;
|
||||
ret.y = y / 16;
|
||||
return ret;
|
||||
}
|
||||
static inline DrawingCoords ScreenToDrawing(const ScreenCoords &coords, int offsetX, int offsetY) {
|
||||
return ScreenToDrawing(coords.x, coords.y, offsetX, offsetY);
|
||||
static inline DrawingCoords ScreenToDrawing(const ScreenCoords &coords) {
|
||||
return ScreenToDrawing(coords.x, coords.y);
|
||||
}
|
||||
static ScreenCoords DrawingToScreen(const DrawingCoords &coords, u16 z);
|
||||
|
||||
|
||||
Reference in new issue
Block a user