Unify TextureCache ::StartFrame as much as possible.

Tiny optimization avoiding a Vulkan pool reset on most frames.
This commit is contained in:
Henrik Rydgård 2023-02-25 23:20:41 +01:00
parent 4c45f8a4b0
commit 3dc47c7fef
8 changed files with 26 additions and 75 deletions

View file

@ -139,7 +139,22 @@ TextureCacheCommon::~TextureCacheCommon() {
}
void TextureCacheCommon::StartFrame() {
ForgetLastTexture();
textureShaderCache_->Decimate();
timesInvalidatedAllThisFrame_ = 0;
replacementTimeThisFrame_ = 0.0;
if (texelsScaledThisFrame_) {
VERBOSE_LOG(G3D, "Scaled %d texels", texelsScaledThisFrame_);
}
texelsScaledThisFrame_ = 0;
if (clearCacheNextFrame_) {
Clear(true);
clearCacheNextFrame_ = false;
} else {
Decimate(false);
}
}
// Produces a signed 1.23.8 value.

View file

@ -185,25 +185,6 @@ void TextureCacheD3D11::ForgetLastTexture() {
context_->PSSetShaderResources(0, 4, nullTex);
}
void TextureCacheD3D11::StartFrame() {
TextureCacheCommon::StartFrame();
lastBoundTexture = INVALID_TEX;
timesInvalidatedAllThisFrame_ = 0;
replacementTimeThisFrame_ = 0.0;
if (texelsScaledThisFrame_) {
// INFO_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_);
}
texelsScaledThisFrame_ = 0;
if (clearCacheNextFrame_) {
Clear(true);
clearCacheNextFrame_ = false;
} else {
Decimate();
}
}
void TextureCacheD3D11::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) {
const u32 clutBaseBytes = clutBase * (clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16));
// Technically, these extra bytes weren't loaded, but hopefully it was loaded earlier.

View file

@ -46,8 +46,6 @@ public:
TextureCacheD3D11(Draw::DrawContext *draw, Draw2D *draw2D);
~TextureCacheD3D11();
void StartFrame() override;
void SetFramebufferManager(FramebufferManagerD3D11 *fbManager);
void ForgetLastTexture() override;

View file

@ -154,22 +154,8 @@ void TextureCacheDX9::ApplySamplingParams(const SamplerCacheKey &key) {
void TextureCacheDX9::StartFrame() {
TextureCacheCommon::StartFrame();
lastBoundTexture = nullptr;
timesInvalidatedAllThisFrame_ = 0;
replacementTimeThisFrame_ = 0.0;
if (texelsScaledThisFrame_) {
VERBOSE_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_);
}
texelsScaledThisFrame_ = 0;
if (clearCacheNextFrame_) {
Clear(true);
clearCacheNextFrame_ = false;
} else {
Decimate();
}
if (gstate_c.Use(GPU_USE_ANISOTROPY)) {
// Just take the opportunity to set the global aniso level here, once per frame.
DWORD aniso = 1 << g_Config.iAnisotropyLevel;
DWORD anisotropyLevel = aniso > maxAnisotropyLevel ? maxAnisotropyLevel : aniso;
device_->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, anisotropyLevel);

View file

@ -143,10 +143,6 @@ static void ConvertColors(void *dstBuf, const void *srcBuf, Draw::DataFormat dst
void TextureCacheGLES::StartFrame() {
TextureCacheCommon::StartFrame();
ForgetLastTexture();
timesInvalidatedAllThisFrame_ = 0;
replacementTimeThisFrame_ = 0.0;
GLRenderManager *renderManager = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
if (!lowMemoryMode_ && renderManager->SawOutOfMemory()) {
lowMemoryMode_ = true;
@ -159,17 +155,6 @@ void TextureCacheGLES::StartFrame() {
host->NotifyUserMessage(err->T("Warning: Video memory FULL, switching to slow caching mode"), 2.0f);
}
}
if (texelsScaledThisFrame_) {
VERBOSE_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_);
}
texelsScaledThisFrame_ = 0;
if (clearCacheNextFrame_) {
Clear(true);
clearCacheNextFrame_ = false;
} else {
Decimate();
}
}
void TextureCacheGLES::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) {

View file

@ -327,27 +327,8 @@ static const VkFilter MagFiltVK[2] = {
void TextureCacheVulkan::StartFrame() {
TextureCacheCommon::StartFrame();
textureShaderCache_->Decimate();
timesInvalidatedAllThisFrame_ = 0;
texelsScaledThisFrame_ = 0;
replacementTimeThisFrame_ = 0.0;
if (clearCacheNextFrame_) {
Clear(true);
clearCacheNextFrame_ = false;
} else {
int slabPressureLimit = TEXCACHE_SLAB_PRESSURE;
if (g_Config.iTexScalingLevel > 1) {
// Since textures are 2D maybe we should square this, but might get too non-aggressive.
slabPressureLimit *= g_Config.iTexScalingLevel;
}
// TODO: Use some indication from VMA.
// Maybe see https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/staying_within_budget.html#staying_within_budget_querying_for_budget .
Decimate(false);
}
// TODO: For low memory detection, maybe use some indication from VMA.
// Maybe see https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/staying_within_budget.html#staying_within_budget_querying_for_budget .
computeShaderManager_.BeginFrame();
}

View file

@ -52,8 +52,7 @@ VkShaderModule CompileShaderModule(VulkanContext *vulkan, VkShaderStageFlagBits
}
}
VulkanComputeShaderManager::VulkanComputeShaderManager(VulkanContext *vulkan) : vulkan_(vulkan), pipelines_(8) {
}
VulkanComputeShaderManager::VulkanComputeShaderManager(VulkanContext *vulkan) : vulkan_(vulkan), pipelines_(8) {}
VulkanComputeShaderManager::~VulkanComputeShaderManager() {}
void VulkanComputeShaderManager::InitDeviceObjects(Draw::DrawContext *draw) {
@ -96,6 +95,7 @@ void VulkanComputeShaderManager::InitDeviceObjects(Draw::DrawContext *draw) {
for (int i = 0; i < ARRAY_SIZE(frameData_); i++) {
frameData_[i].descPool.Create(vulkan_, dp, dpTypes);
frameData_[i].descPoolUsed = false;
}
VkPushConstantRange push = {};
@ -137,6 +137,7 @@ void VulkanComputeShaderManager::DestroyDeviceObjects() {
VkDescriptorSet VulkanComputeShaderManager::GetDescriptorSet(VkImageView image, VkBuffer buffer, VkDeviceSize offset, VkDeviceSize range, VkBuffer buffer2, VkDeviceSize offset2, VkDeviceSize range2) {
int curFrame = vulkan_->GetCurFrame();
FrameData &frameData = frameData_[curFrame];
frameData.descPoolUsed = true;
VkDescriptorSet desc = frameData.descPool.Allocate(1, &descriptorSetLayout_, "compute_descset");
_assert_(desc != VK_NULL_HANDLE);
@ -206,5 +207,8 @@ VkPipeline VulkanComputeShaderManager::GetPipeline(VkShaderModule cs) {
void VulkanComputeShaderManager::BeginFrame() {
int curFrame = vulkan_->GetCurFrame();
FrameData &frame = frameData_[curFrame];
frame.descPool.Reset();
if (frame.descPoolUsed) {
frame.descPool.Reset();
frame.descPoolUsed = false;
}
}

View file

@ -77,6 +77,7 @@ private:
}
VulkanDescSetPool descPool;
bool descPoolUsed = false;
};
FrameData frameData_[VulkanContext::MAX_INFLIGHT_FRAMES];