samplerjit: Take texptr/bufw as arrays.

Prep for moving mip map sampling into linear.
This commit is contained in:
Unknown W. Brackets committed 2021-12-28 12:04:16 -08:00
1 parent 4864850b3b
commit a4558a5736
4 files changed
+33 -20

No files matched your search

+6 -8
View File
@@ -521,10 +521,8 @@ template <bool mayHaveMipLevels>
static inline Vec4IntResult SOFTRAST_CALL ApplyTexturing(Sampler::Funcs sampler, Vec4IntArg prim_color, float s, float t, int texlevel, int frac_texlevel, bool bilinear, u8 *texptr[], int texbufw[], int x, int y) {
Vec4<int> texcolor0;
Vec4<int> texcolor1;
const u8 *tptr0 = texptr[mayHaveMipLevels ? texlevel : 0];
int bufw0 = texbufw[mayHaveMipLevels ? texlevel : 0];
const u8 *tptr1 = texptr[mayHaveMipLevels ? texlevel + 1 : 0];
int bufw1 = texbufw[mayHaveMipLevels ? texlevel + 1 : 0];
const u8 **tptr0 = const_cast<const u8 **>(&texptr[mayHaveMipLevels ? texlevel : 0]);
const int *bufw0 = &texbufw[mayHaveMipLevels ? texlevel : 0];
if (!bilinear) {
int u[8] = { 0 }, v[8] = { 0 }; // 1.27.4 fixed point
@@ -535,14 +533,14 @@ static inline Vec4IntResult SOFTRAST_CALL ApplyTexturing(Sampler::Funcs sampler,
GetTexelCoordinates(texlevel + 1, s, t, u[1], v[1], x, y);
}
texcolor0 = Vec4<int>(sampler.nearest(u[0], v[0], tptr0, bufw0, mayHaveMipLevels ? texlevel : 0));
texcolor0 = Vec4<int>(sampler.nearest(u[0], v[0], tptr0[0], bufw0[0], mayHaveMipLevels ? texlevel : 0));
if (mayHaveMipLevels && frac_texlevel) {
texcolor1 = Vec4<int>(sampler.nearest(u[1], v[1], tptr1, bufw1, texlevel + 1));
texcolor1 = Vec4<int>(sampler.nearest(u[1], v[1], tptr0[1], bufw0[1], texlevel + 1));
}
} else {
texcolor0 = Vec4<int>(sampler.linear(s, t, x, y, prim_color, tptr0, bufw0, mayHaveMipLevels ? texlevel : 0, 0));
texcolor0 = Vec4<int>(sampler.linear(s, t, x, y, prim_color, tptr0, bufw0, mayHaveMipLevels ? texlevel : 0, mayHaveMipLevels ? frac_texlevel : 0));
if (mayHaveMipLevels && frac_texlevel) {
texcolor1 = Vec4<int>(sampler.linear(s, t, x, y, prim_color, tptr1, bufw1, texlevel + 1, frac_texlevel));
texcolor1 = Vec4<int>(sampler.linear(s, t, x, y, prim_color, tptr0 + 1, bufw0 + 1, texlevel + 1, frac_texlevel));
}
}
+3 -3
View File
@@ -39,7 +39,7 @@ extern u32 clut[4096];
namespace Sampler {
static Vec4IntResult SOFTRAST_CALL SampleNearest(int u, int v, const u8 *tptr, int bufw, int level);
static Vec4IntResult SOFTRAST_CALL SampleLinear(float s, float t, int x, int y, Vec4IntArg prim_color, const u8 *tptr, int bufw, int level, int levelFrac);
static Vec4IntResult SOFTRAST_CALL SampleLinear(float s, float t, int x, int y, Vec4IntArg prim_color, const u8 **tptr, const int *bufw, int level, int levelFrac);
std::mutex jitCacheLock;
SamplerJitCache *jitCache = nullptr;
@@ -557,11 +557,11 @@ static inline Vec4IntResult SOFTRAST_CALL GetTexelCoordinatesQuadT(int level, fl
return ApplyTexelClampQuadT(gstate.isTexCoordClampedT(), base_v, height);
}
static Vec4IntResult SOFTRAST_CALL SampleLinear(float s, float t, int x, int y, Vec4IntArg prim_color, const u8 *tptr, int bufw, int texlevel, int levelFrac) {
static Vec4IntResult SOFTRAST_CALL SampleLinear(float s, float t, int x, int y, Vec4IntArg prim_color, const u8 **tptr, const int *bufw, int texlevel, int levelFrac) {
int frac_u, frac_v;
const Vec4<int> u = GetTexelCoordinatesQuadS(texlevel, s, frac_u, x);
const Vec4<int> v = GetTexelCoordinatesQuadT(texlevel, t, frac_v, y);
Nearest4 c = SampleNearest<4>(u.AsArray(), v.AsArray(), tptr, bufw, texlevel);
Nearest4 c = SampleNearest<4>(u.AsArray(), v.AsArray(), tptr[0], bufw[0], texlevel);
Vec4<int> texcolor_tl = Vec4<int>::FromRGBA(c.v[0]);
Vec4<int> texcolor_tr = Vec4<int>::FromRGBA(c.v[1]);
+1 -1
View File
@@ -36,7 +36,7 @@ namespace Sampler {
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *NearestFunc)(int u, int v, const u8 *tptr, int bufw, int level);
NearestFunc GetNearestFunc();
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *LinearFunc)(float s, float t, int x, int y, Rasterizer::Vec4IntArg prim_color, const u8 *tptr, int bufw, int level, int levelFrac);
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *LinearFunc)(float s, float t, int x, int y, Rasterizer::Vec4IntArg prim_color, const u8 **tptr, const int *bufw, int level, int levelFrac);
LinearFunc GetLinearFunc();
struct Funcs {
+23 -8
View File
@@ -256,15 +256,27 @@ LinearFunc SamplerJitCache::CompileLinear(const SamplerID &id) {
return nullptr;
}
// Early exit on !srcPtr.
// Early exit on !srcPtr (either one.)
FixupBranch zeroSrc;
if (id.hasInvalidPtr) {
// TODO: Change when texptr is an array.
CMP(PTRBITS, R(R14), Imm8(0));
X64Reg srcReg = regCache_.Find(RegCache::GEN_ARG_TEXPTR);
if (id.hasAnyMips) {
X64Reg tempReg = regCache_.Alloc(RegCache::GEN_TEMP0);
MOV(64, R(tempReg), MDisp(srcReg, 0));
AND(64, R(tempReg), MDisp(srcReg, 8));
CMP(PTRBITS, R(tempReg), Imm8(0));
regCache_.Release(tempReg, RegCache::GEN_TEMP0);
} else {
CMP(PTRBITS, MatR(srcReg), Imm8(0));
}
FixupBranch nonZeroSrc = J_CC(CC_NZ);
PXOR(XMM0, R(XMM0));
zeroSrc = J(true);
SetJumpTarget(nonZeroSrc);
regCache_.Unlock(srcReg, RegCache::GEN_ARG_TEXPTR);
}
// TODO: Save color or put it somewhere... or reserve the reg?
@@ -307,9 +319,8 @@ LinearFunc SamplerJitCache::CompileLinear(const SamplerID &id) {
X64Reg srcReg = regCache_.Find(RegCache::GEN_ARG_TEXPTR);
X64Reg bufwReg = regCache_.Find(RegCache::GEN_ARG_BUFW);
// TODO: Change when texptr is an array.
MOV(64, R(srcArgReg), R(srcReg));
MOV(32, R(bufwArgReg), R(bufwReg));
MOV(64, R(srcArgReg), MDisp(srcReg, 0));
MOV(32, R(bufwArgReg), MDisp(bufwReg, 0));
// Leave level/levelFrac, we just always load from RAM on Windows and lock on POSIX.
regCache_.Unlock(srcReg, RegCache::GEN_ARG_TEXPTR);
regCache_.Unlock(bufwReg, RegCache::GEN_ARG_BUFW);
@@ -1471,7 +1482,9 @@ bool SamplerJitCache::Jit_PrepareDataOffsets(const SamplerID &id) {
} else {
if (!id.useStandardBufw || id.hasAnyMips) {
// Spread bufw into each lane.
MOVD_xmm(XMM2, R(R15));
X64Reg bufwReg = regCache_.Find(RegCache::GEN_ARG_BUFW);
MOVD_xmm(XMM2, MatR(bufwReg));
regCache_.Unlock(bufwReg, RegCache::GEN_ARG_BUFW);
PSHUFD(XMM2, R(XMM2), _MM_SHUFFLE(0, 0, 0, 0));
if (bits == 4)
@@ -1537,7 +1550,9 @@ bool SamplerJitCache::Jit_PrepareDataSwizzledOffsets(const SamplerID &id, int bi
if (!id.useStandardBufw || id.hasAnyMips) {
// Spread bufw into each lane.
MOVD_xmm(XMM2, R(R15));
X64Reg bufwReg = regCache_.Find(RegCache::GEN_ARG_BUFW);
MOVD_xmm(XMM2, MatR(bufwReg));
regCache_.Unlock(bufwReg, RegCache::GEN_ARG_BUFW);
PSHUFD(XMM2, R(XMM2), _MM_SHUFFLE(0, 0, 0, 0));
}