Debian Codegraph @

Source/Core/VideoCommon/Resources/CustomResourceManager.h

raw symbols SCIP
1 // Copyright 2025 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <map>
7 #include <memory>
8
9 #include "Common/HookableEvent.h"
10 #include "Common/WorkQueueThread.h"
11
12 #include "VideoCommon/AbstractTexture.h"
13 #include "VideoCommon/Assets/CustomAssetCache.h"
14 #include "VideoCommon/AsyncShaderCompiler.h"
15 #include "VideoCommon/Resources/MaterialResource.h"
16 #include "VideoCommon/Resources/ShaderResource.h"
17 #include "VideoCommon/Resources/TextureAndSamplerResource.h"
18 #include "VideoCommon/Resources/TextureDataResource.h"
19 #include "VideoCommon/Resources/TexturePool.h"
20
21 namespace VideoCommon
22 {
23 class CustomResourceManager
24 {
25 public:
26 void Initialize();
27 void Shutdown();
28
29 void Reset();
30
31 // Request that an asset be reloaded
32 void MarkAssetDirty(const CustomAssetLibrary::AssetID& asset_id);
33
34 void XFBTriggered();
35 void SetHostConfig(const ShaderHostConfig& host_config);
36
37 TextureDataResource*
38 GetTextureDataFromAsset(const CustomAssetLibrary::AssetID& asset_id,
39 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
40 MaterialResource*
41 GetDrawMaterialFromAsset(const CustomAssetLibrary::AssetID& asset_id,
42 const GXPipelineUid& pipeline_uid,
43 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
44 MaterialResource*
45 GetPostProcessingMaterialFromAsset(const CustomAssetLibrary::AssetID& asset_id,
46 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
47
48 ShaderResource* GetShaderFromAsset(const CustomAssetLibrary::AssetID& asset_id,
49 std::size_t shader_key,
50 const std::optional<GXPipelineUid>& pipeline_uid,
51 const std::string& preprocessor_settings,
52 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
53
54 TextureAndSamplerResource*
55 GetTextureAndSamplerFromAsset(const CustomAssetLibrary::AssetID& asset_id,
56 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
57
58 private:
59 Resource::ResourceContext
60 CreateResourceContext(const CustomAssetLibrary::AssetID& asset_id,
61 std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
62 CustomAssetCache m_asset_cache;
63 TexturePool m_texture_pool;
64 Common::AsyncWorkThreadSP m_worker_thread;
65 std::unique_ptr<AsyncShaderCompiler> m_async_shader_compiler;
66
67 using PipelineIdToMaterial = std::map<std::size_t, std::unique_ptr<MaterialResource>>;
68 std::map<CustomAssetLibrary::AssetID, PipelineIdToMaterial> m_draw_material_resources;
69
70 using ShaderKeyToShader = std::map<std::size_t, std::unique_ptr<ShaderResource>>;
71 std::map<CustomAssetLibrary::AssetID, ShaderKeyToShader> m_shader_resources;
72
73 std::map<CustomAssetLibrary::AssetID, std::unique_ptr<TextureDataResource>>
74 m_texture_data_resources;
75
76 std::map<CustomAssetLibrary::AssetID, std::unique_ptr<TextureAndSamplerResource>>
77 m_texture_sampler_resources;
78
79 std::map<CustomAssetLibrary::AssetID, std::unique_ptr<MaterialResource>>
80 m_postprocessing_material_resources;
81
82 ShaderHostConfig m_host_config;
83
84 Common::EventHook m_xfb_event;
85
86 std::unique_ptr<AbstractTexture> m_invalid_transparent_texture;
87 std::unique_ptr<AbstractTexture> m_invalid_color_texture;
88 std::unique_ptr<AbstractTexture> m_invalid_cubemap_texture;
89 std::unique_ptr<AbstractTexture> m_invalid_array_texture;
90 };
91 } // namespace VideoCommon