GS: Reduce the number of divisions in shader copies.

Less cpu cycles/work.
This commit is contained in:
lightningterror
2026-02-24 00:03:44 +01:00
parent 1dea7c48e7
commit 7cf43515bb
4 changed files with 70 additions and 48 deletions
+23 -13
View File
@@ -1352,12 +1352,15 @@ void GSDevice11::DoStretchRect(GSTexture* sTex, const GSVector4& sRect, GSTextur
// ia
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
GSVertexPT1 vertices[] =
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const GSVertexPT1 vertices[] =
{
{GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)},
{GSVector4(right, top, 0.5f, 1.0f), GSVector2(sRect.z, sRect.y)},
@@ -1422,10 +1425,13 @@ void GSDevice11::PresentRect(GSTexture* sTex, const GSVector4& sRect, GSTexture*
// ia
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const GSVertexPT1 vertices[] =
{
@@ -1565,10 +1571,14 @@ void GSDevice11::DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rect
{
const GSVector4& sRect = rects[i].src_rect;
const GSVector4& dRect = rects[i].dst_rect;
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const u32 vstart = vcount;
verts[vcount++] = {GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)};
+15 -9
View File
@@ -1776,10 +1776,13 @@ void GSDevice12::DoMultiStretchRects(
const GSVector4& sRect = rects[i].src_rect;
const GSVector4& dRect = rects[i].dst_rect;
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const u32 vstart = vcount;
verts[vcount++] = {GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)};
@@ -1890,12 +1893,15 @@ void GSDevice12::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect,
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
// ia
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
GSVertexPT1 vertices[] = {
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const GSVertexPT1 vertices[] = {
{GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)},
{GSVector4(right, top, 0.5f, 1.0f), GSVector2(sRect.z, sRect.y)},
{GSVector4(left, bottom, 0.5f, 1.0f), GSVector2(sRect.x, sRect.w)},
+16 -17
View File
@@ -1660,20 +1660,15 @@ void GSDeviceOGL::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect
{
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
// Original code from DX
const float left = dRect.x * 2 / ds.x - 1.0f;
const float right = dRect.z * 2 / ds.x - 1.0f;
#if 0
const float top = 1.0f - dRect.y * 2 / ds.y;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
#else
// Opengl get some issues with the coordinate
// I flip top/bottom to fix scaling of the internal resolution
const float top = -1.0f + dRect.y * 2 / ds.y;
const float bottom = -1.0f + dRect.w * 2 / ds.y;
#endif
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
GSVertexPT1 vertices[] =
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = -1.0f + dRect.y * inv_y;
const float bottom = -1.0f + dRect.w * inv_y;
const GSVertexPT1 vertices[] =
{
{GSVector4(left , top , 0.0f, 0.0f) , GSVector2(sRect.x , sRect.y)} ,
{GSVector4(right , top , 0.0f, 0.0f) , GSVector2(sRect.z , sRect.y)} ,
@@ -1748,10 +1743,14 @@ void GSDeviceOGL::DoMultiStretchRects(const MultiStretchRect* rects, u32 num_rec
{
const GSVector4& sRect = rects[i].src_rect;
const GSVector4& dRect = rects[i].dst_rect;
const float left = dRect.x * 2 / ds.x - 1.0f;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float top = -1.0f + dRect.y * 2 / ds.y;
const float bottom = -1.0f + dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = -1.0f + dRect.y * inv_y;
const float bottom = -1.0f + dRect.w * inv_y;
const u32 vstart = vcount;
verts[vcount++] = { GSVector4(left , top , 0.0f, 0.0f) , GSVector2(sRect.x , sRect.y) };
+16 -9
View File
@@ -2943,10 +2943,14 @@ void GSDeviceVK::DoMultiStretchRects(
{
const GSVector4& sRect = rects[i].src_rect;
const GSVector4& dRect = rects[i].dst_rect;
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const u32 vstart = vcount;
verts[vcount++] = {GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)};
@@ -3074,12 +3078,15 @@ void GSDeviceVK::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect,
g_perfmon.Put(GSPerfMon::TextureCopies, 1);
// ia
const float left = dRect.x * 2 / ds.x - 1.0f;
const float top = 1.0f - dRect.y * 2 / ds.y;
const float right = dRect.z * 2 / ds.x - 1.0f;
const float bottom = 1.0f - dRect.w * 2 / ds.y;
const float inv_x = 2.0f / ds.x;
const float inv_y = 2.0f / ds.y;
GSVertexPT1 vertices[] = {
const float left = dRect.x * inv_x - 1.0f;
const float right = dRect.z * inv_x - 1.0f;
const float top = 1.0f - dRect.y * inv_y;
const float bottom = 1.0f - dRect.w * inv_y;
const GSVertexPT1 vertices[] = {
{GSVector4(left, top, 0.5f, 1.0f), GSVector2(sRect.x, sRect.y)},
{GSVector4(right, top, 0.5f, 1.0f), GSVector2(sRect.z, sRect.y)},
{GSVector4(left, bottom, 0.5f, 1.0f), GSVector2(sRect.x, sRect.w)},