TextureCacheGLES: Also share the same sampler calculation for GLES.

This commit is contained in:
Henrik Rydgård 2020-09-13 22:48:44 +02:00
parent b81e0669e6
commit 9ea295093b
3 changed files with 27 additions and 68 deletions

View File

@ -115,78 +115,39 @@ static const GLuint MagFiltGL[2] = {
GL_LINEAR
};
// This should not have to be done per texture! OpenGL is silly yo
void TextureCacheGLES::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
int minFilt;
int magFilt;
bool sClamp;
bool tClamp;
float lodBias;
u8 maxLevel = (entry.status & TexCacheEntry::STATUS_BAD_MIPS) ? 0 : entry.maxLevel;
GETexLevelMode mode;
GetSamplingParams(minFilt, magFilt, sClamp, tClamp, lodBias, maxLevel, entry.addr, mode);
void TextureCacheGLES::ApplySamplingParams(const SamplerCacheKey &key) {
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
float minLod = 0.0f;
float maxLod = 0.0f;
if (maxLevel != 0) {
// TODO: What about a swap of autoMip mode?
if (true) {
if (mode == GE_TEXLEVEL_MODE_AUTO) {
minLod = 0.0f;
maxLod = (float)maxLevel;
} else if (mode == GE_TEXLEVEL_MODE_CONST) {
minLod = std::max(0.0f, std::min((float)maxLevel, lodBias));
maxLod = std::max(0.0f, std::min((float)maxLevel, lodBias));
} else { // mode == GE_TEXLEVEL_MODE_SLOPE) {
// It's incorrect to use the slope as a bias. Instead it should be passed
// into the shader directly as an explicit lod level, with the bias on top. For now, we just kill the
// lodBias in this mode, working around #9772.
#ifndef USING_GLES2
lodBias = 0.0f;
#endif
minLod = 0.0f;
maxLod = (float)maxLevel;
}
}
} else {
minLod = 0.0f;
maxLod = 0.0f;
}
float minLod = (float)key.minLevel / 256.0f;
float maxLod = (float)key.maxLevel / 256.0f;
float lodBias = (float)key.lodBias / 256.0f;
render_->SetTextureLod(0, minLod, maxLod, lodBias);
}
float aniso = 0.0f;
render_->SetTextureSampler(0, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);
int magKey = ((int)key.mipEnable << 2) | ((int)key.mipFilt << 1) | ((int)key.magFilt);
render_->SetTextureSampler(0,
key.sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, key.tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT,
MagFiltGL[magKey], key.minFilt ? GL_LINEAR : GL_NEAREST, aniso);
}
void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, bool forcePoint) {
SamplerCacheKey key;
UpdateSamplingParams(0, 0, key);
int minFilt;
int magFilt;
bool sClamp;
bool tClamp;
float lodBias;
GETexLevelMode mode;
GetSamplingParams(minFilt, magFilt, sClamp, tClamp, lodBias, 0, 0, mode);
minFilt &= 1; // framebuffers can't mipmap.
key.mipEnable = false; // framebuffers can't mipmap.
if (forcePoint) {
minFilt &= ~1;
magFilt &= ~1;
key.magFilt = false;
key.minFilt = false;
}
// Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case.
// This happens whether we have OES_texture_npot or not.
int w = gstate.getTextureWidth(0);
int h = gstate.getTextureHeight(0);
if (w != bufferWidth || h != bufferHeight) {
sClamp = true;
tClamp = true;
key.sClamp = true;
key.tClamp = true;
}
float aniso = 0.0f;
render_->SetTextureSampler(TEX_SLOT_PSP_TEXTURE, sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);
key.aniso = 0.0f;
ApplySamplingParams(key);
}
static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dstFmt, int numPixels) {
@ -289,7 +250,9 @@ void TextureCacheGLES::BindTexture(TexCacheEntry *entry) {
render_->BindTexture(0, entry->textureName);
lastBoundTexture = entry->textureName;
}
UpdateSamplingParams(*entry, false);
SamplerCacheKey key;
UpdateSamplingParams(entry->maxLevel, entry->addr, key);
ApplySamplingParams(key);
gstate_c.SetUseShaderDepal(false);
}
@ -650,7 +613,10 @@ void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry) {
// This will rebind it, but that's okay.
// Need to actually bind it now - it might only have gotten bound in the init phase.
render_->BindTexture(TEX_SLOT_PSP_TEXTURE, entry->textureName);
UpdateSamplingParams(*entry, true);
SamplerCacheKey key;
UpdateSamplingParams(entry->maxLevel, entry->addr, key);
ApplySamplingParams(key);
}
Draw::DataFormat TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {

View File

@ -75,7 +75,7 @@ protected:
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
private:
void UpdateSamplingParams(TexCacheEntry &entry, bool force);
void ApplySamplingParams(const SamplerCacheKey &key);
void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, Draw::DataFormat dstFmt);
Draw::DataFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;

View File

@ -440,24 +440,17 @@ static const VkFilter MagFiltVK[2] = {
};
void TextureCacheVulkan::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight, SamplerCacheKey &key) {
int minFilt;
int magFilt;
bool sClamp;
bool tClamp;
float lodBias;
GETexLevelMode mode;
GetSamplingParams(minFilt, magFilt, sClamp, tClamp, lodBias, 0, 0, mode);
UpdateSamplingParams(0, 0, key);
key.minFilt = minFilt & 1;
key.minFilt &= 1;
key.mipFilt = 0;
key.magFilt = magFilt & 1;
key.sClamp = sClamp;
key.tClamp = tClamp;
key.magFilt &= 1;
// Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case.
// This happens whether we have OES_texture_npot or not.
int w = gstate.getTextureWidth(0);
int h = gstate.getTextureHeight(0);
if (w != bufferWidth || h != bufferHeight) {
key.sClamp = true;
key.tClamp = true;