mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#pragma once
|
|
#include "EffectInfo.h"
|
|
#include "../ShaderEffectDesc.h"
|
|
#include <parallel_hashmap/phmap.h>
|
|
|
|
namespace Magpie {
|
|
|
|
class EffectsService {
|
|
public:
|
|
static EffectsService& Get() noexcept {
|
|
static EffectsService instance;
|
|
return instance;
|
|
}
|
|
|
|
EffectsService(const EffectsService&) = delete;
|
|
EffectsService(EffectsService&&) = delete;
|
|
|
|
winrt::fire_and_forget Initialize();
|
|
|
|
void Uninitialize();
|
|
|
|
const std::vector<EffectInfo>& GetEffects() noexcept;
|
|
|
|
const EffectInfo* GetEffect(std::string_view name) noexcept;
|
|
|
|
std::string SubmitCompileShaderEffectTask(
|
|
std::string_view effectName,
|
|
const phmap::flat_hash_map<std::string, float>* inlineParams,
|
|
D3D_SHADER_MODEL shaderModel,
|
|
bool isFP16Enabled,
|
|
bool isAdvancedColorEnabled
|
|
) noexcept;
|
|
|
|
bool GetTaskResult(std::string taskKey, const ShaderEffectDesc* &effectDesc) noexcept;
|
|
|
|
private:
|
|
EffectsService() = default;
|
|
|
|
void _WaitForInitialize() noexcept;
|
|
|
|
std::vector<EffectInfo> _effects;
|
|
phmap::flat_hash_map<std::string_view, uint32_t> _effectsMap;
|
|
|
|
struct _ShaderEffectMemCacheItem {
|
|
ShaderEffectDesc effectDesc;
|
|
// UINT_MAX 表示尚未编译完成
|
|
uint32_t lastAccess = std::numeric_limits<uint32_t>::max();
|
|
};
|
|
phmap::flat_hash_map<std::string, _ShaderEffectMemCacheItem> _shaderEffectCache;
|
|
|
|
std::atomic<bool> _initialized = false;
|
|
bool _initializedCache = false;
|
|
};
|
|
|
|
}
|