mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-05-13 16:01:56 -04:00
VideoCommon: update CustomPipelineAction to get a Material when an EFB is received
This commit is contained in:
@@ -3,7 +3,11 @@
|
||||
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h"
|
||||
|
||||
#include "Common/JsonUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Core/System.h"
|
||||
|
||||
#include "VideoCommon/Resources/CustomResourceManager.h"
|
||||
|
||||
std::unique_ptr<CustomPipelineAction>
|
||||
CustomPipelineAction::Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||
@@ -15,58 +19,16 @@ std::unique_ptr<CustomPipelineAction>
|
||||
CustomPipelineAction::Create(const picojson::value& json_data,
|
||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||
{
|
||||
std::vector<CustomPipelineAction::PipelinePassPassDescription> pipeline_passes;
|
||||
auto material_asset = ReadStringFromJson(json_data.get<picojson::object>(), "material_asset");
|
||||
|
||||
const auto& passes_json = json_data.get("passes");
|
||||
if (passes_json.is<picojson::array>())
|
||||
if (!material_asset)
|
||||
{
|
||||
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,
|
||||
"Failed to load custom pipeline action, 'passes' has an array value that "
|
||||
"is not an object!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pass = passes_json_val.get<picojson::object>();
|
||||
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");
|
||||
ERROR_LOG_FMT(VIDEO,
|
||||
"Failed to load custom pipeline action, 'material_asset' does not have a value");
|
||||
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));
|
||||
return std::make_unique<CustomPipelineAction>(std::move(library), std::move(*material_asset));
|
||||
}
|
||||
|
||||
CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library)
|
||||
@@ -74,14 +36,26 @@ CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAs
|
||||
{
|
||||
}
|
||||
|
||||
CustomPipelineAction::CustomPipelineAction(
|
||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
||||
std::vector<PipelinePassPassDescription> pass_descriptions)
|
||||
: m_library(std::move(library)), m_passes_config(std::move(pass_descriptions))
|
||||
CustomPipelineAction::CustomPipelineAction(std::shared_ptr<VideoCommon::CustomAssetLibrary> library,
|
||||
std::string material_asset)
|
||||
: m_library(std::move(library)), m_material_asset(std::move(material_asset))
|
||||
{
|
||||
m_pipeline_passes.resize(m_passes_config.size());
|
||||
}
|
||||
|
||||
void CustomPipelineAction::OnDrawStarted(GraphicsModActionData::DrawStarted*)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void CustomPipelineAction::AfterEFB(GraphicsModActionData::PostEFB* post_efb)
|
||||
{
|
||||
if (!post_efb) [[unlikely]]
|
||||
return;
|
||||
|
||||
if (m_material_asset.empty())
|
||||
return;
|
||||
|
||||
auto& resource_manager = Core::System::GetInstance().GetCustomResourceManager();
|
||||
post_efb->material =
|
||||
resource_manager.GetPostProcessingMaterialFromAsset(m_material_asset, m_library);
|
||||
}
|
||||
|
||||
@@ -6,22 +6,15 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <picojson.h>
|
||||
|
||||
#include "VideoCommon/Assets/CustomAssetLibrary.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/CustomPipeline.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModAction.h"
|
||||
|
||||
class CustomPipelineAction final : public GraphicsModAction
|
||||
{
|
||||
public:
|
||||
struct PipelinePassPassDescription
|
||||
{
|
||||
std::string m_pixel_material_asset;
|
||||
};
|
||||
|
||||
static constexpr std::string_view factory_name = "custom_pipeline";
|
||||
static std::unique_ptr<CustomPipelineAction>
|
||||
Create(const picojson::value& json_data,
|
||||
@@ -30,11 +23,11 @@ public:
|
||||
Create(std::shared_ptr<VideoCommon::CustomAssetLibrary> library);
|
||||
explicit 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 AfterEFB(GraphicsModActionData::PostEFB*) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<VideoCommon::CustomAssetLibrary> m_library;
|
||||
std::vector<PipelinePassPassDescription> m_passes_config;
|
||||
std::vector<CustomPipeline> m_pipeline_passes;
|
||||
std::string m_material_asset;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user