Merge pull request #22428 from hrydgard/sampler-jit-invalid-ptr

SoftGPU: Leave textures with an invalid level address to the generic sampler
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-10-05 14:34:12 -06:00
commit 797eb80b17
5 files changed
+13 -78

No files matched your search

+9 -3
View File
@@ -163,6 +163,12 @@ void SamplerJitCache::Flush() {
compileQueue_.clear();
}
// A texture level whose address isn't valid has no pointer, and the generic samplers read its texels as zero
// (then apply the texture function). The JIT leaves those to them.
static bool CanJit(const SamplerID &id) {
return g_Config.bSoftwareRenderingJit && !id.hasInvalidPtr;
}
NearestFunc SamplerJitCache::GetByID(const SamplerID &id, size_t key, BinManager *binner) {
std::unique_lock<std::mutex> guard(jitCacheLock);
@@ -201,7 +207,7 @@ NearestFunc SamplerJitCache::GetByID(const SamplerID &id, size_t key, BinManager
}
NearestFunc SamplerJitCache::GetNearest(const SamplerID &id, BinManager *binner) {
if (!g_Config.bSoftwareRenderingJit)
if (!CanJit(id))
return nullptr;
const size_t key = std::hash<SamplerID>()(id);
@@ -214,7 +220,7 @@ NearestFunc SamplerJitCache::GetNearest(const SamplerID &id, BinManager *binner)
}
LinearFunc SamplerJitCache::GetLinear(const SamplerID &id, BinManager *binner) {
if (!g_Config.bSoftwareRenderingJit)
if (!CanJit(id))
return nullptr;
const size_t key = std::hash<SamplerID>()(id);
@@ -227,7 +233,7 @@ LinearFunc SamplerJitCache::GetLinear(const SamplerID &id, BinManager *binner) {
}
FetchFunc SamplerJitCache::GetFetch(const SamplerID &id, BinManager *binner) {
if (!g_Config.bSoftwareRenderingJit)
if (!CanJit(id))
return nullptr;
const size_t key = std::hash<SamplerID>()(id);
-74
View File
@@ -60,21 +60,6 @@ FetchFunc SamplerJitCache::CompileFetch(const SamplerID &id) {
stackLevelOffset_ = -1;
#endif
// Early exit on !srcPtr.
FixupBranch zeroSrc;
if (id.hasInvalidPtr) {
X64Reg srcReg = regCache_.Find(RegCache::GEN_ARG_TEXPTR);
CMP(PTRBITS, R(srcReg), Imm8(0));
regCache_.Unlock(srcReg, RegCache::GEN_ARG_TEXPTR);
FixupBranch nonZeroSrc = J_CC(CC_NZ);
X64Reg vecResultReg = regCache_.Find(RegCache::VEC_RESULT);
PXOR(vecResultReg, R(vecResultReg));
regCache_.Unlock(vecResultReg, RegCache::VEC_RESULT);
zeroSrc = J(true);
SetJumpTarget(nonZeroSrc);
}
// This reads the pixel data into resultReg from the args.
if (!Jit_ReadTextureFormat(id)) {
regCache_.Reset(false);
@@ -108,9 +93,6 @@ FetchFunc SamplerJitCache::CompileFetch(const SamplerID &id) {
regCache_.Unlock(vecResultReg, RegCache::VEC_RESULT);
Describe("Init");
if (id.hasInvalidPtr) {
SetJumpTarget(zeroSrc);
}
RET();
@@ -214,30 +196,6 @@ NearestFunc SamplerJitCache::CompileNearest(const SamplerID &id) {
regCache_.Unlock(resultReg, RegCache::GEN_RESULT);
regCache_.ForceRetain(RegCache::GEN_RESULT);
// Early exit on !srcPtr (either one.)
FixupBranch zeroSrc;
if (id.hasInvalidPtr) {
Describe("NullCheck");
X64Reg srcReg = regCache_.Find(RegCache::GEN_ARG_TEXPTR_PTR);
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_PTR);
}
auto loadPtrs = [&](bool level1) {
X64Reg bufwReg = regCache_.Alloc(RegCache::GEN_ARG_BUFW);
X64Reg bufwPtrReg = regCache_.Find(RegCache::GEN_ARG_BUFW_PTR);
@@ -419,10 +377,6 @@ NearestFunc SamplerJitCache::CompileNearest(const SamplerID &id) {
return nullptr;
}
if (id.hasInvalidPtr) {
SetJumpTarget(zeroSrc);
}
POP(R12);
POP(R13);
POP(R14);
@@ -618,30 +572,6 @@ LinearFunc SamplerJitCache::CompileLinear(const SamplerID &id) {
// Our first goal is to convert S/T and X/Y into U/V and frac_u/frac_v.
success = success && Jit_GetTexelCoordsQuad(id);
// Early exit on !srcPtr (either one.)
FixupBranch zeroSrc;
if (id.hasInvalidPtr) {
Describe("NullCheck");
X64Reg srcReg = regCache_.Find(RegCache::GEN_ARG_TEXPTR_PTR);
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_PTR);
}
auto prepareDataOffsets = [&](RegCache::Purpose uPurpose, RegCache::Purpose vPurpose, bool level1) {
X64Reg uReg = regCache_.Find(uPurpose);
X64Reg vReg = regCache_.Find(vPurpose);
@@ -882,10 +812,6 @@ LinearFunc SamplerJitCache::CompileLinear(const SamplerID &id) {
return nullptr;
}
if (id.hasInvalidPtr) {
SetJumpTarget(zeroSrc);
}
const u8 *start = WriteFinalizedEpilog();
regCache_.Reset(true);
return (LinearFunc)start;
+1
View File
@@ -289,6 +289,7 @@ tests_good = [
"gpu/texmtx/prims",
"gpu/texmtx/source",
"gpu/texmtx/uvs",
"gpu/textures/mipinvalid",
"gpu/textures/mipmap",
"gpu/textures/rotate",
"gpu/textures/size",
+2
View File
@@ -65,6 +65,8 @@ static bool TestSamplerJit() {
SamplerID id;
memset(&id, 0, sizeof(id));
id.fullKey = rng.R32();
// Textures with an invalid level address are left to the generic samplers.
id.hasInvalidPtr = false;
id.cached.clut = clut;
for (int i = 0; i < 8; ++i) {