mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-25 05:54:57 +00:00
custom pipeline action...
This commit is contained in:
parent
7b70311a5f
commit
70e1ad3c94
2 changed files with 29 additions and 122 deletions
|
@ -7,24 +7,19 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <misc/cpp/imgui_stdlib.h>
|
#include <misc/cpp/imgui_stdlib.h>
|
||||||
|
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/JsonUtil.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/StringUtil.h"
|
|
||||||
#include "Common/VariantUtil.h"
|
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
|
|
||||||
#include "VideoCommon/AbstractGfx.h"
|
#include "VideoCommon/AbstractGfx.h"
|
||||||
#include "VideoCommon/Assets/CustomAssetLoader.h"
|
|
||||||
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
|
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
|
||||||
#include "VideoCommon/GraphicsModEditor/Controls/AssetDisplay.h"
|
#include "VideoCommon/GraphicsModEditor/Controls/AssetDisplay.h"
|
||||||
#include "VideoCommon/GraphicsModEditor/EditorEvents.h"
|
#include "VideoCommon/GraphicsModEditor/EditorEvents.h"
|
||||||
#include "VideoCommon/GraphicsModEditor/EditorMain.h"
|
#include "VideoCommon/GraphicsModEditor/EditorMain.h"
|
||||||
#include "VideoCommon/ShaderGenCommon.h"
|
#include "VideoCommon/GraphicsModSystem/Runtime/CustomResourceManager.h"
|
||||||
#include "VideoCommon/TextureCacheBase.h"
|
|
||||||
|
|
||||||
std::unique_ptr<CustomPipelineAction>
|
std::unique_ptr<CustomPipelineAction>
|
||||||
CustomPipelineAction::Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
CustomPipelineAction::Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||||
|
@ -36,58 +31,17 @@ std::unique_ptr<CustomPipelineAction>
|
||||||
CustomPipelineAction::Create(const picojson::value& json_data,
|
CustomPipelineAction::Create(const picojson::value& json_data,
|
||||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||||
{
|
{
|
||||||
std::vector<CustomPipelineAction::PipelinePassPassDescription> pipeline_passes;
|
const auto material_asset =
|
||||||
|
ReadStringFromJson(json_data.get<picojson::object>(), "material_asset");
|
||||||
|
|
||||||
const auto& passes_json = json_data.get("passes");
|
if (!material_asset)
|
||||||
if (passes_json.is<picojson::array>())
|
|
||||||
{
|
|
||||||
for (const auto& passes_json_val : passes_json.get<picojson::array>())
|
|
||||||
{
|
|
||||||
CustomPipelineAction::PipelinePassPassDescription pipeline_pass;
|
|
||||||
if (!passes_json_val.is<picojson::object>())
|
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(VIDEO,
|
ERROR_LOG_FMT(VIDEO,
|
||||||
"Failed to load custom pipeline action, 'passes' has an array value that "
|
"Failed to load custom pipeline action, 'material_asset' does not have a value");
|
||||||
"is not an object!");
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pass = passes_json_val.get<picojson::object>();
|
return std::make_unique<CustomPipelineAction>(std::move(library), std::move(*material_asset));
|
||||||
if (!pass.contains("pixel_material_asset"))
|
|
||||||
{
|
|
||||||
ERROR_LOG_FMT(VIDEO,
|
|
||||||
"Failed to load custom pipeline action, 'passes' value missing required "
|
|
||||||
"field 'pixel_material_asset'");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pixel_material_asset_json = pass["pixel_material_asset"];
|
|
||||||
if (!pixel_material_asset_json.is<std::string>())
|
|
||||||
{
|
|
||||||
ERROR_LOG_FMT(VIDEO, "Failed to load custom pipeline action, 'passes' field "
|
|
||||||
"'pixel_material_asset' is not a string!");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
pipeline_pass.m_pixel_material_asset = pixel_material_asset_json.to_str();
|
|
||||||
pipeline_passes.push_back(std::move(pipeline_pass));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pipeline_passes.empty())
|
|
||||||
{
|
|
||||||
ERROR_LOG_FMT(VIDEO, "Failed to load custom pipeline action, must specify at least one pass");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pipeline_passes.size() > 1)
|
|
||||||
{
|
|
||||||
ERROR_LOG_FMT(
|
|
||||||
VIDEO,
|
|
||||||
"Failed to load custom pipeline action, multiple passes are not currently supported");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_unique<CustomPipelineAction>(std::move(library), std::move(pipeline_passes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||||
|
@ -95,12 +49,10 @@ CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAs
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomPipelineAction::CustomPipelineAction(
|
CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
||||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
std::string material_asset)
|
||||||
std::vector<PipelinePassPassDescription> pass_descriptions)
|
: m_library(std::move(library)), m_material_asset(std::move(material_asset))
|
||||||
: m_library(std::move(library)), m_passes_config(std::move(pass_descriptions))
|
|
||||||
{
|
{
|
||||||
m_pipeline_passes.resize(m_passes_config.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted* draw_started)
|
void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted* draw_started)
|
||||||
|
@ -108,33 +60,21 @@ void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted* dra
|
||||||
if (!draw_started) [[unlikely]]
|
if (!draw_started) [[unlikely]]
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!draw_started->custom_pixel_shader) [[unlikely]]
|
if (!draw_started->material) [[unlikely]]
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (m_pipeline_passes.empty()) [[unlikely]]
|
if (m_material_asset.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& loader = Core::System::GetInstance().GetCustomAssetLoader();
|
auto& resource_manager = Core::System::GetInstance().GetCustomResourceManager();
|
||||||
|
*draw_started->material = resource_manager.GetMaterialFromAsset(m_material_asset, m_library,
|
||||||
// For now assume a single pass
|
draw_started->draw_data_view);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPipelineAction::DrawImGui()
|
void CustomPipelineAction::DrawImGui()
|
||||||
{
|
{
|
||||||
auto& editor = Core::System::GetInstance().GetGraphicsModEditor();
|
auto& editor = Core::System::GetInstance().GetGraphicsModEditor();
|
||||||
if (ImGui::CollapsingHeader("Custom pipeline", ImGuiTreeNodeFlags_DefaultOpen))
|
if (ImGui::CollapsingHeader("Custom pipeline", ImGuiTreeNodeFlags_DefaultOpen))
|
||||||
{
|
|
||||||
if (m_passes_config.size() == 1)
|
|
||||||
{
|
{
|
||||||
if (ImGui::BeginTable("CustomPipelineForm", 2))
|
if (ImGui::BeginTable("CustomPipelineForm", 2))
|
||||||
{
|
{
|
||||||
|
@ -142,32 +82,15 @@ void CustomPipelineAction::DrawImGui()
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::Text("Material");
|
ImGui::Text("Material");
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
if (GraphicsModEditor::Controls::AssetDisplay(
|
if (GraphicsModEditor::Controls::AssetDisplay("CustomPipelineActionMaterial",
|
||||||
"CustomPipelineActionMaterial", editor.GetEditorState(),
|
editor.GetEditorState(), &m_material_asset,
|
||||||
&m_passes_config[0].m_pixel_material_asset, GraphicsModEditor::Material))
|
GraphicsModEditor::RasterMaterial))
|
||||||
{
|
{
|
||||||
GraphicsModEditor::EditorEvents::ChangeOccurredEvent::Trigger();
|
GraphicsModEditor::EditorEvents::AssetReloadEvent::Trigger(m_material_asset);
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_passes_config.empty())
|
|
||||||
{
|
|
||||||
if (ImGui::Button("Add pass"))
|
|
||||||
{
|
|
||||||
m_passes_config.emplace_back();
|
|
||||||
m_pipeline_passes.emplace_back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Disable pass adding for now
|
|
||||||
ImGui::BeginDisabled();
|
|
||||||
ImGui::Button("Add pass");
|
|
||||||
ImGui::EndDisabled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomPipelineAction::SerializeToConfig(picojson::object* obj)
|
void CustomPipelineAction::SerializeToConfig(picojson::object* obj)
|
||||||
|
@ -176,15 +99,7 @@ void CustomPipelineAction::SerializeToConfig(picojson::object* obj)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& json_obj = *obj;
|
auto& json_obj = *obj;
|
||||||
|
json_obj["material_asset"] = picojson::value{m_material_asset};
|
||||||
picojson::array serialized_passes;
|
|
||||||
for (const auto& pass : m_passes_config)
|
|
||||||
{
|
|
||||||
picojson::object serialized_pass;
|
|
||||||
serialized_pass["pixel_material_asset"] = picojson::value{pass.m_pixel_material_asset};
|
|
||||||
serialized_passes.push_back(picojson::value{serialized_pass});
|
|
||||||
}
|
|
||||||
json_obj["passes"] = picojson::value{serialized_passes};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CustomPipelineAction::GetFactoryName() const
|
std::string CustomPipelineAction::GetFactoryName() const
|
||||||
|
|
|
@ -6,22 +6,15 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <picojson.h>
|
#include <picojson.h>
|
||||||
|
|
||||||
#include "VideoCommon/Assets/CustomAssetLibrary.h"
|
#include "VideoCommon/Assets/CustomAssetLibrary.h"
|
||||||
#include "VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h"
|
|
||||||
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h"
|
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h"
|
||||||
|
|
||||||
class CustomPipelineAction final : public GraphicsModAction
|
class CustomPipelineAction final : public GraphicsModAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
struct PipelinePassPassDescription
|
|
||||||
{
|
|
||||||
std::string m_pixel_material_asset;
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr std::string_view factory_name = "custom_pipeline";
|
static constexpr std::string_view factory_name = "custom_pipeline";
|
||||||
static std::unique_ptr<CustomPipelineAction>
|
static std::unique_ptr<CustomPipelineAction>
|
||||||
Create(const picojson::value& json_data,
|
Create(const picojson::value& json_data,
|
||||||
|
@ -30,7 +23,7 @@ public:
|
||||||
Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
|
Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
|
||||||
explicit CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
|
explicit CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
|
||||||
CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
||||||
std::vector<PipelinePassPassDescription> pass_descriptions);
|
std::string material_asset);
|
||||||
void OnDrawStarted(GraphicsModActionData::DrawStarted*) override;
|
void OnDrawStarted(GraphicsModActionData::DrawStarted*) override;
|
||||||
|
|
||||||
void DrawImGui() override;
|
void DrawImGui() override;
|
||||||
|
@ -39,6 +32,5 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> m_library;
|
std::shared_ptr<VideoCommon::CustomAssetLibrary> m_library;
|
||||||
std::vector<PipelinePassPassDescription> m_passes_config;
|
std::string m_material_asset;
|
||||||
std::vector<CustomPipeline> m_pipeline_passes;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue