summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/GraphicsModSystem
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2025-05-01 22:14:00 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2025-06-06 19:20:25 -0500
commitd7de49ccf68aae6b3c12e35122435f30ea2f8533 (patch)
tree1922b717ea816776d76b12fdbe0b47ba22df5a2b /Source/Core/VideoCommon/GraphicsModSystem
parent5ec5db92400d25b35373b3e814976d3388dedc0a (diff)
Core / VideoCommon: Remove original custom asset loader
Diffstat (limited to 'Source/Core/VideoCommon/GraphicsModSystem')
-rw-r--r--Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp25
-rw-r--r--Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp237
-rw-r--r--Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h8
3 files changed, 5 insertions, 265 deletions
diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp
index 92c048860f..7366ad7ff7 100644
--- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp
+++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp
@@ -16,7 +16,6 @@
#include "Core/System.h"
#include "VideoCommon/AbstractGfx.h"
-#include "VideoCommon/Assets/CustomAssetLoader.h"
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
#include "VideoCommon/ShaderGenCommon.h"
#include "VideoCommon/TextureCacheBase.h"
@@ -98,28 +97,6 @@ CustomPipelineAction::CustomPipelineAction(
m_pipeline_passes.resize(m_passes_config.size());
}
-void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted* draw_started)
+void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted*)
{
- if (!draw_started) [[unlikely]]
- return;
-
- if (!draw_started->custom_pixel_shader) [[unlikely]]
- return;
-
- if (m_pipeline_passes.empty()) [[unlikely]]
- return;
-
- auto& loader = Core::System::GetInstance().GetCustomAssetLoader();
-
- // For now assume a single pass
- const auto& pass_config = m_passes_config[0];
- auto& pass = m_pipeline_passes[0];
-
- pass.UpdatePixelData(loader, m_library, draw_started->texture_units,
- pass_config.m_pixel_material_asset);
- CustomPixelShader custom_pixel_shader;
- custom_pixel_shader.custom_shader = pass.m_last_generated_shader_code.GetBuffer();
- custom_pixel_shader.material_uniform_block = pass.m_last_generated_material_code.GetBuffer();
- *draw_started->custom_pixel_shader = custom_pixel_shader;
- *draw_started->material_uniform_buffer = pass.m_material_data;
}
diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp
index b52df66e31..f211442e96 100644
--- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp
+++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.cpp
@@ -12,7 +12,6 @@
#include "Common/VariantUtil.h"
#include "VideoCommon/AbstractGfx.h"
-#include "VideoCommon/Assets/CustomAssetLoader.h"
namespace
{
@@ -172,238 +171,8 @@ std::vector<std::string> GlobalConflicts(std::string_view source)
} // namespace
-void CustomPipeline::UpdatePixelData(
- VideoCommon::CustomAssetLoader& loader,
- std::shared_ptr<VideoCommon::CustomAssetLibrary> library, std::span<const u32> texture_units,
- const VideoCommon::CustomAssetLibrary::AssetID& material_to_load)
+void CustomPipeline::UpdatePixelData(std::shared_ptr<VideoCommon::CustomAssetLibrary>,
+ std::span<const u32>,
+ const VideoCommon::CustomAssetLibrary::AssetID&)
{
- if (!m_pixel_material.m_asset || material_to_load != m_pixel_material.m_asset->GetAssetId())
- {
- m_pixel_material.m_asset = loader.LoadMaterial(material_to_load, library);
- }
-
- const auto material_data = m_pixel_material.m_asset->GetData();
- if (!material_data)
- {
- return;
- }
-
- std::size_t max_material_data_size = 0;
- if (m_pixel_material.m_asset->GetLastLoadedTime() > m_pixel_material.m_cached_write_time)
- {
- m_last_generated_material_code = ShaderCode{};
- m_pixel_material.m_cached_write_time = m_pixel_material.m_asset->GetLastLoadedTime();
- std::size_t texture_count = 0;
- for (const auto& property : material_data->properties)
- {
- max_material_data_size += VideoCommon::MaterialProperty::GetMemorySize(property);
- VideoCommon::MaterialProperty::WriteAsShaderCode(m_last_generated_material_code, property);
- if (std::holds_alternative<VideoCommon::CustomAssetLibrary::AssetID>(property.m_value))
- {
- texture_count++;
- }
- }
- m_material_data.resize(max_material_data_size);
- m_game_textures.resize(texture_count);
- }
-
- if (!m_pixel_shader.m_asset ||
- m_pixel_shader.m_asset->GetLastLoadedTime() > m_pixel_shader.m_cached_write_time ||
- material_data->shader_asset != m_pixel_shader.m_asset->GetAssetId())
- {
- m_pixel_shader.m_asset = loader.LoadPixelShader(material_data->shader_asset, library);
- m_pixel_shader.m_cached_write_time = m_pixel_shader.m_asset->GetLastLoadedTime();
-
- m_last_generated_shader_code = ShaderCode{};
- }
-
- const auto shader_data = m_pixel_shader.m_asset->GetData();
- if (!shader_data)
- {
- return;
- }
-
- if (shader_data->m_properties.size() != material_data->properties.size())
- {
- return;
- }
-
- u8* material_buffer = m_material_data.data();
- u32 sampler_index = 8;
- for (std::size_t index = 0; index < material_data->properties.size(); index++)
- {
- auto& property = material_data->properties[index];
- const auto shader_it = shader_data->m_properties.find(property.m_code_name);
- if (shader_it == shader_data->m_properties.end())
- {
- ERROR_LOG_FMT(VIDEO,
- "Custom pipeline, has material asset '{}' that uses a "
- "code name of '{}' but that can't be found on shader asset '{}'!",
- m_pixel_material.m_asset->GetAssetId(), property.m_code_name,
- m_pixel_shader.m_asset->GetAssetId());
- return;
- }
-
- if (auto* texture_asset_id =
- std::get_if<VideoCommon::CustomAssetLibrary::AssetID>(&property.m_value))
- {
- if (*texture_asset_id != "")
- {
- auto asset = loader.LoadGameTexture(*texture_asset_id, library);
- if (!asset)
- {
- return;
- }
-
- auto& texture_asset = m_game_textures[index];
- if (!texture_asset ||
- texture_asset->m_cached_asset.m_asset->GetLastLoadedTime() >
- texture_asset->m_cached_asset.m_cached_write_time ||
- *texture_asset_id != texture_asset->m_cached_asset.m_asset->GetAssetId())
- {
- if (!texture_asset)
- {
- texture_asset = CachedTextureAsset{};
- }
- const auto loaded_time = asset->GetLastLoadedTime();
- texture_asset->m_cached_asset = VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>{
- std::move(asset), loaded_time};
- texture_asset->m_texture.reset();
-
- if (std::holds_alternative<VideoCommon::ShaderProperty::Sampler2D>(
- shader_it->second.m_default))
- {
- texture_asset->m_sampler_code =
- fmt::format("SAMPLER_BINDING({}) uniform sampler2D samp_{};\n", sampler_index,
- property.m_code_name);
- texture_asset->m_define_code = fmt::format("#define HAS_{} 1\n", property.m_code_name);
- }
- else if (std::holds_alternative<VideoCommon::ShaderProperty::Sampler2DArray>(
- shader_it->second.m_default))
- {
- texture_asset->m_sampler_code =
- fmt::format("SAMPLER_BINDING({}) uniform sampler2DArray samp_{};\n", sampler_index,
- property.m_code_name);
- texture_asset->m_define_code = fmt::format("#define HAS_{} 1\n", property.m_code_name);
- }
- else if (std::holds_alternative<VideoCommon::ShaderProperty::SamplerCube>(
- shader_it->second.m_default))
- {
- texture_asset->m_sampler_code =
- fmt::format("SAMPLER_BINDING({}) uniform samplerCube samp_{};\n", sampler_index,
- property.m_code_name);
- texture_asset->m_define_code = fmt::format("#define HAS_{} 1\n", property.m_code_name);
- }
- }
-
- const auto texture_data = texture_asset->m_cached_asset.m_asset->GetData();
- if (!texture_data)
- {
- return;
- }
-
- if (texture_asset->m_texture)
- {
- g_gfx->SetTexture(sampler_index, texture_asset->m_texture.get());
- g_gfx->SetSamplerState(sampler_index, texture_data->m_sampler);
- }
- else
- {
- AbstractTextureType texture_type = AbstractTextureType::Texture_2DArray;
- if (std::holds_alternative<VideoCommon::ShaderProperty::SamplerCube>(
- shader_it->second.m_default))
- {
- texture_type = AbstractTextureType::Texture_CubeMap;
- }
- else if (std::holds_alternative<VideoCommon::ShaderProperty::Sampler2D>(
- shader_it->second.m_default))
- {
- texture_type = AbstractTextureType::Texture_2D;
- }
-
- if (texture_data->m_texture.m_slices.empty() ||
- texture_data->m_texture.m_slices[0].m_levels.empty())
- {
- return;
- }
-
- auto& first_slice = texture_data->m_texture.m_slices[0];
- const TextureConfig texture_config(
- first_slice.m_levels[0].width, first_slice.m_levels[0].height,
- static_cast<u32>(first_slice.m_levels.size()),
- static_cast<u32>(texture_data->m_texture.m_slices.size()), 1,
- first_slice.m_levels[0].format, 0, texture_type);
- texture_asset->m_texture = g_gfx->CreateTexture(
- texture_config, fmt::format("Custom shader texture '{}'", property.m_code_name));
- if (texture_asset->m_texture)
- {
- for (std::size_t slice_index = 0; slice_index < texture_data->m_texture.m_slices.size();
- slice_index++)
- {
- auto& slice = texture_data->m_texture.m_slices[slice_index];
- for (u32 level_index = 0; level_index < static_cast<u32>(slice.m_levels.size());
- ++level_index)
- {
- auto& level = slice.m_levels[level_index];
- texture_asset->m_texture->Load(level_index, level.width, level.height,
- level.row_length, level.data.data(),
- level.data.size(), static_cast<u32>(slice_index));
- }
- }
- }
- }
-
- sampler_index++;
- }
- }
- else
- {
- VideoCommon::MaterialProperty::WriteToMemory(material_buffer, property);
- }
- }
-
- if (m_last_generated_shader_code.GetBuffer().empty())
- {
- // Calculate shader details
- std::string color_shader_data =
- ReplaceAll(shader_data->m_shader_source, "custom_main", CUSTOM_PIXELSHADER_COLOR_FUNC);
- const auto global_conflicts = GlobalConflicts(color_shader_data);
- color_shader_data = ReplaceAll(color_shader_data, "\r\n", "\n");
- color_shader_data = ReplaceAll(color_shader_data, "{", "{{");
- color_shader_data = ReplaceAll(color_shader_data, "}", "}}");
- // First replace global conflicts with dummy strings
- // This avoids the problem where a shorter word
- // is in a longer word, ex two functions: 'execute' and 'execute_fast'
- for (std::size_t i = 0; i < global_conflicts.size(); i++)
- {
- const std::string& identifier = global_conflicts[i];
- color_shader_data =
- ReplaceAll(color_shader_data, identifier, fmt::format("_{0}_DOLPHIN_TEMP_{0}_", i));
- }
- // Now replace the temporaries with the actual value
- for (std::size_t i = 0; i < global_conflicts.size(); i++)
- {
- const std::string& identifier = global_conflicts[i];
- color_shader_data = ReplaceAll(color_shader_data, fmt::format("_{0}_DOLPHIN_TEMP_{0}_", i),
- fmt::format("{}_{{0}}", identifier));
- }
-
- for (const auto& game_texture : m_game_textures)
- {
- if (!game_texture)
- continue;
-
- m_last_generated_shader_code.Write("{}", game_texture->m_sampler_code);
- m_last_generated_shader_code.Write("{}", game_texture->m_define_code);
- }
-
- for (std::size_t i = 0; i < texture_units.size(); i++)
- {
- const auto& texture_unit = texture_units[i];
- m_last_generated_shader_code.Write(
- "#define TEX_COORD{} data.texcoord[data.texmap_to_texcoord_index[{}]].xy\n", i,
- texture_unit);
- }
- m_last_generated_shader_code.Write("{}", color_shader_data);
- }
}
diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h
index 83bc9f84e1..ea840ba911 100644
--- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h
+++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h
@@ -17,15 +17,9 @@
#include "VideoCommon/Assets/TextureAsset.h"
#include "VideoCommon/ShaderGenCommon.h"
-namespace VideoCommon
-{
-class CustomAssetLoader;
-}
-
struct CustomPipeline
{
- void UpdatePixelData(VideoCommon::CustomAssetLoader& loader,
- std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
+ void UpdatePixelData(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
std::span<const u32> texture_units,
const VideoCommon::CustomAssetLibrary::AssetID& material_to_load);