summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2024-06-01 23:21:04 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2024-06-01 23:21:04 -0500
commitc2bc2ccd23cfabc2a6d8ac0295fef7b669206e28 (patch)
tree4d083135411ba1e15ac96565a9e71c044a698312 /Source
parent46a89936ae0724bf087a228133f4bd7bd682da3a (diff)
VideoCommon: pull texture sampler out of texture cache so that it can be used in other places in the future
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.cpp17
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.h7
-rw-r--r--Source/Core/VideoCommon/VertexManagerBase.cpp14
3 files changed, 26 insertions, 12 deletions
diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp
index 7184ea725e..5ef7d3fc98 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.cpp
+++ b/Source/Core/VideoCommon/TextureCacheBase.cpp
@@ -1012,8 +1012,8 @@ static bool IsAnisostropicEnhancementSafe(const TexMode0& tm0)
return !(tm0.min_filter == FilterMode::Near && tm0.mag_filter == FilterMode::Near);
}
-static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
- bool has_arbitrary_mips)
+SamplerState TextureCacheBase::GetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
+ bool has_arbitrary_mips)
{
const TexMode0& tm0 = bpmem.tex.GetUnit(index).texMode0;
@@ -1073,13 +1073,11 @@ static void SetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
state.tm0.anisotropic_filtering = false;
}
- g_gfx->SetSamplerState(index, state);
- auto& system = Core::System::GetInstance();
- auto& pixel_shader_manager = system.GetPixelShaderManager();
- pixel_shader_manager.SetSamplerState(index, state.tm0.hex, state.tm1.hex);
+ return state;
}
-void TextureCacheBase::BindTextures(BitSet32 used_textures)
+void TextureCacheBase::BindTextures(BitSet32 used_textures,
+ const std::array<SamplerState, 8>& samplers)
{
auto& system = Core::System::GetInstance();
auto& pixel_shader_manager = system.GetPixelShaderManager();
@@ -1091,8 +1089,9 @@ void TextureCacheBase::BindTextures(BitSet32 used_textures)
g_gfx->SetTexture(i, tentry->texture.get());
pixel_shader_manager.SetTexDims(i, tentry->native_width, tentry->native_height);
- const float custom_tex_scale = tentry->GetWidth() / float(tentry->native_width);
- SetSamplerState(i, custom_tex_scale, tentry->is_custom_tex, tentry->has_arbitrary_mips);
+ auto& state = samplers[i];
+ g_gfx->SetSamplerState(i, state);
+ pixel_shader_manager.SetSamplerState(i, state.tm0.hex, state.tm1.hex);
}
}
diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h
index 998ff446d9..1a06fa671a 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.h
+++ b/Source/Core/VideoCommon/TextureCacheBase.h
@@ -33,6 +33,7 @@
class AbstractFramebuffer;
class AbstractStagingTexture;
class PointerWrap;
+struct SamplerState;
struct VideoConfig;
namespace VideoCommon
@@ -282,7 +283,7 @@ public:
RcTcacheEntry GetXFBTexture(u32 address, u32 width, u32 height, u32 stride,
MathUtil::Rectangle<int>* display_rect);
- virtual void BindTextures(BitSet32 used_textures);
+ virtual void BindTextures(BitSet32 used_textures, const std::array<SamplerState, 8>& samplers);
void CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstFormat, u32 width, u32 height,
u32 dstStride, bool is_depth_copy,
const MathUtil::Rectangle<int>& srcRect, bool isIntensity,
@@ -308,6 +309,10 @@ public:
static bool AllCopyFilterCoefsNeeded(const std::array<u32, 3>& coefficients);
static bool CopyFilterCanOverflow(const std::array<u32, 3>& coefficients);
+ // Get a new sampler state
+ static SamplerState GetSamplerState(u32 index, float custom_tex_scale, bool custom_tex,
+ bool has_arbitrary_mips);
+
protected:
// Decodes the specified data to the GPU texture specified by entry.
// Returns false if the configuration is not supported.
diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp
index b51cfa19e0..02edb56d35 100644
--- a/Source/Core/VideoCommon/VertexManagerBase.cpp
+++ b/Source/Core/VideoCommon/VertexManagerBase.cpp
@@ -563,13 +563,19 @@ void VertexManagerBase::Flush()
const auto used_textures = UsedTextures();
std::vector<std::string> texture_names;
Common::SmallVector<u32, 8> texture_units;
+ std::array<SamplerState, 8> samplers;
if (!m_cull_all)
{
if (!g_ActiveConfig.bGraphicMods)
{
for (const u32 i : used_textures)
{
- g_texture_cache->Load(TextureInfo::FromStage(i));
+ const auto cache_entry = g_texture_cache->Load(TextureInfo::FromStage(i));
+ if (!cache_entry)
+ continue;
+ const float custom_tex_scale = cache_entry->GetWidth() / float(cache_entry->native_width);
+ samplers[i] = TextureCacheBase::GetSamplerState(
+ i, custom_tex_scale, cache_entry->is_custom_tex, cache_entry->has_arbitrary_mips);
}
}
else
@@ -585,6 +591,10 @@ void VertexManagerBase::Flush()
texture_names.push_back(cache_entry->texture_info_name);
texture_units.push_back(i);
}
+
+ const float custom_tex_scale = cache_entry->GetWidth() / float(cache_entry->native_width);
+ samplers[i] = TextureCacheBase::GetSamplerState(
+ i, custom_tex_scale, cache_entry->is_custom_tex, cache_entry->has_arbitrary_mips);
}
}
}
@@ -633,7 +643,7 @@ void VertexManagerBase::Flush()
// Texture loading can cause palettes to be applied (-> uniforms -> draws).
// Palette application does not use vertices, only a full-screen quad, so this is okay.
// Same with GPU texture decoding, which uses compute shaders.
- g_texture_cache->BindTextures(used_textures);
+ g_texture_cache->BindTextures(used_textures, samplers);
if (PerfQueryBase::ShouldEmulate())
g_perf_query->EnableQuery(bpmem.zcontrol.early_ztest ? PQG_ZCOMP_ZCOMPLOC : PQG_ZCOMP);