Skip to content

Commit

Permalink
GS/SW: Remove redundant code generator classes
Browse files Browse the repository at this point in the history
Makes space for ARM64.
  • Loading branch information
stenzek committed May 4, 2024
1 parent e48c68d commit 8d9c89a
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 270 deletions.
4 changes: 0 additions & 4 deletions pcsx2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,9 @@ set(pcsx2GSSourcesUnshared
GS/Renderers/Common/GSVertexTraceFMM.cpp
GS/Renderers/HW/GSRendererHWMultiISA.cpp
GS/Renderers/SW/GSDrawScanline.cpp
GS/Renderers/SW/GSDrawScanlineCodeGenerator.cpp
GS/Renderers/SW/GSDrawScanlineCodeGenerator.all.cpp
GS/Renderers/SW/GSRasterizer.cpp
GS/Renderers/SW/GSRendererSW.cpp
GS/Renderers/SW/GSSetupPrimCodeGenerator.cpp
GS/Renderers/SW/GSSetupPrimCodeGenerator.all.cpp
)

Expand Down Expand Up @@ -532,14 +530,12 @@ set(pcsx2GSHeaders
GS/Renderers/HW/GSTextureCache.h
GS/Renderers/HW/GSTextureReplacements.h
GS/Renderers/HW/GSVertexHW.h
GS/Renderers/SW/GSDrawScanlineCodeGenerator.h
GS/Renderers/SW/GSDrawScanlineCodeGenerator.all.h
GS/Renderers/SW/GSDrawScanline.h
GS/Renderers/SW/GSNewCodeGenerator.h
GS/Renderers/SW/GSRasterizer.h
GS/Renderers/SW/GSRendererSW.h
GS/Renderers/SW/GSScanlineEnvironment.h
GS/Renderers/SW/GSSetupPrimCodeGenerator.h
GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h
GS/Renderers/SW/GSTextureCacheSW.h
GS/Renderers/SW/GSVertexSW.h
Expand Down
13 changes: 10 additions & 3 deletions pcsx2/GS/Renderers/Common/GSFunctionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,26 @@ class GSCodeGeneratorFunctionMap : public GSFunctionMap<KEY, VALUE>
}
else
{
HostSys::BeginCodeWrite();

u8* code_ptr = GSCodeReserve::ReserveMemory(MAX_SIZE);
CG cg(key, code_ptr, MAX_SIZE);
pxAssert(cg.getSize() < MAX_SIZE);
cg.Generate();
pxAssert(cg.GetSize() < MAX_SIZE);

#if 0
fprintf(stderr, "%s Location:%p Size:%zu Key:%llx\n", m_name.c_str(), code_ptr, cg.getSize(), (u64)key);
GSScanlineSelector sel(key);
sel.Print();
#endif

GSCodeReserve::CommitMemory(cg.getSize());
const u32 size = static_cast<u32>(cg.GetSize());
GSCodeReserve::CommitMemory(size);

HostSys::EndCodeWrite();
HostSys::FlushInstructionCache(code_ptr, static_cast<u32>(size));

ret = (VALUE)cg.getCode();
ret = (VALUE)cg.GetCode();

m_cgmap[key] = ret;
}
Expand Down
60 changes: 60 additions & 0 deletions pcsx2/GS/Renderers/SW/GSDrawScanline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "common/Console.h"

#include <fstream>

// Comment to disable all dynamic code generation.
#define ENABLE_JIT_RASTERIZER

Expand Down Expand Up @@ -36,6 +38,64 @@ GSDrawScanline::~GSDrawScanline()
DevCon.WriteLn("SW JIT generated %zu bytes of code", used);
}

bool GSDrawScanline::ShouldUseCDrawScanline(u64 key)
{
static std::map<u64, bool> s_use_c_draw_scanline;
static std::mutex s_use_c_draw_scanline_mutex;

static const char* const fname = getenv("USE_C_DRAW_SCANLINE");
if (!fname)
return false;

std::lock_guard<std::mutex> l(s_use_c_draw_scanline_mutex);

if (s_use_c_draw_scanline.empty())
{
std::ifstream file(fname);
if (file)
{
for (std::string str; std::getline(file, str);)
{
u64 key;
char yn;
if (sscanf(str.c_str(), "%" PRIx64 " %c", &key, &yn) == 2)
{
if (yn != 'Y' && yn != 'N' && yn != 'y' && yn != 'n')
Console.Warning("Failed to parse %s: Not y/n", str.c_str());
s_use_c_draw_scanline[key] = (yn == 'Y' || yn == 'y') ? true : false;
}
else
{
Console.Warning("Failed to process line %s", str.c_str());
}
}
}
}

auto idx = s_use_c_draw_scanline.find(key);
if (idx == s_use_c_draw_scanline.end())
{
s_use_c_draw_scanline[key] = false;
// Rewrite file
FILE* file = fopen(fname, "w");
if (file)
{
for (const auto& pair : s_use_c_draw_scanline)
{
fprintf(file, "%016" PRIX64 " %c %s\n", pair.first, pair.second ? 'Y' : 'N', GSScanlineSelector(pair.first).to_string().c_str());
}
fclose(file);
}
else
{
Console.Warning("Failed to write C draw scanline usage config: %s", strerror(errno));
}
return false;
}

return idx->second;
}

void GSDrawScanline::BeginDraw(const GSRasterizerData& data, GSScanlineLocalData& local)
{
const GSScanlineGlobalData& global = data.global;
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/GS/Renderers/SW/GSDrawScanline.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
#pragma once

#include "GS/GSState.h"
#include "GS/Renderers/SW/GSSetupPrimCodeGenerator.h"
#include "GS/Renderers/SW/GSDrawScanlineCodeGenerator.h"
#include "GS/Renderers/SW/GSSetupPrimCodeGenerator.all.h"
#include "GS/Renderers/SW/GSDrawScanlineCodeGenerator.all.h"

struct GSScanlineLocalData;

MULTI_ISA_UNSHARED_START

class GSRasterizerData;

class GSSetupPrimCodeGenerator;
class GSDrawScanlineCodeGenerator;

class GSDrawScanline : public GSVirtualAlignedClass<32>
{
friend GSSetupPrimCodeGenerator;
Expand All @@ -25,6 +22,9 @@ class GSDrawScanline : public GSVirtualAlignedClass<32>
GSDrawScanline();
~GSDrawScanline() override;

/// Debug override for disabling scanline JIT on a key basis.
static bool ShouldUseCDrawScanline(u64 key);

/// Function pointer types which we call back into.
using SetupPrimPtr = void(*)(const GSVertexSW* vertex, const u16* index, const GSVertexSW& dscan, GSScanlineLocalData& local);
using DrawScanlinePtr = void(*)(int pixels, int left, int top, const GSVertexSW& scan, GSScanlineLocalData& local);
Expand Down
Loading

0 comments on commit 8d9c89a

Please sign in to comment.