Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #11300 from iwubcode/custom-shaders
VideoCommon: add a graphics mod action that allows you to modify the game's base rendering
  • Loading branch information
AdmiralCurtiss committed Aug 22, 2023
2 parents 3451cb1 + 5506121 commit dbe6a5f
Show file tree
Hide file tree
Showing 28 changed files with 2,576 additions and 80 deletions.
6 changes: 6 additions & 0 deletions Source/Core/DolphinLib.props
Expand Up @@ -663,15 +663,18 @@
<ClInclude Include="VideoCommon\GeometryShaderGen.h" />
<ClInclude Include="VideoCommon\GeometryShaderManager.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsMod.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsModAsset.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsModFeature.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsModGroup.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsTarget.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Config\GraphicsTargetGroup.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Constants.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\CustomPipelineAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\MoveAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\PrintAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\ScaleAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\Actions\SkipAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\CustomShaderCache.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\FBInfo.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModAction.h" />
<ClInclude Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModActionData.h" />
Expand Down Expand Up @@ -1276,14 +1279,17 @@
<ClCompile Include="VideoCommon\GeometryShaderGen.cpp" />
<ClCompile Include="VideoCommon\GeometryShaderManager.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsMod.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsModAsset.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsModFeature.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsModGroup.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsTarget.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Config\GraphicsTargetGroup.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\Actions\CustomPipelineAction.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\Actions\MoveAction.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\Actions\PrintAction.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\Actions\ScaleAction.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\Actions\SkipAction.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\CustomShaderCache.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\FBInfo.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModActionFactory.cpp" />
<ClCompile Include="VideoCommon\GraphicsModSystem\Runtime\GraphicsModManager.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/VideoCommon/CMakeLists.txt
Expand Up @@ -64,6 +64,8 @@ add_library(videocommon
GeometryShaderManager.h
GraphicsModSystem/Config/GraphicsMod.cpp
GraphicsModSystem/Config/GraphicsMod.h
GraphicsModSystem/Config/GraphicsModAsset.cpp
GraphicsModSystem/Config/GraphicsModAsset.h
GraphicsModSystem/Config/GraphicsModFeature.cpp
GraphicsModSystem/Config/GraphicsModFeature.h
GraphicsModSystem/Config/GraphicsModGroup.cpp
Expand All @@ -73,6 +75,8 @@ add_library(videocommon
GraphicsModSystem/Config/GraphicsTargetGroup.cpp
GraphicsModSystem/Config/GraphicsTargetGroup.h
GraphicsModSystem/Constants.h
GraphicsModSystem/Runtime/Actions/CustomPipelineAction.cpp
GraphicsModSystem/Runtime/Actions/CustomPipelineAction.h
GraphicsModSystem/Runtime/Actions/MoveAction.cpp
GraphicsModSystem/Runtime/Actions/MoveAction.h
GraphicsModSystem/Runtime/Actions/PrintAction.cpp
Expand All @@ -81,6 +85,8 @@ add_library(videocommon
GraphicsModSystem/Runtime/Actions/ScaleAction.h
GraphicsModSystem/Runtime/Actions/SkipAction.cpp
GraphicsModSystem/Runtime/Actions/SkipAction.h
GraphicsModSystem/Runtime/CustomShaderCache.cpp
GraphicsModSystem/Runtime/CustomShaderCache.h
GraphicsModSystem/Runtime/FBInfo.cpp
GraphicsModSystem/Runtime/FBInfo.h
GraphicsModSystem/Runtime/GraphicsModAction.h
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/VideoCommon/ConstantManager.h
Expand Up @@ -58,6 +58,8 @@ struct alignas(16) PixelShaderConstants
// For shader_framebuffer_fetch logic ops:
u32 logic_op_enable; // bool
LogicOp logic_op_mode;
// For custom shaders...
u32 time_ms;
};

struct alignas(16) VertexShaderConstants
Expand Down
21 changes: 21 additions & 0 deletions Source/Core/VideoCommon/GraphicsModSystem/Config/GraphicsMod.cpp
Expand Up @@ -178,6 +178,27 @@ bool GraphicsModConfig::DeserializeFromConfig(const picojson::value& value)
}
}

const auto& assets = value.get("assets");
if (assets.is<picojson::array>())
{
for (const auto& asset_val : assets.get<picojson::array>())
{
if (!asset_val.is<picojson::object>())
{
ERROR_LOG_FMT(
VIDEO, "Failed to load mod configuration file, specified asset is not a json object");
return false;
}
GraphicsModAssetConfig asset;
if (!asset.DeserializeFromConfig(asset_val.get<picojson::object>()))
{
return false;
}

m_assets.push_back(std::move(asset));
}
}

return true;
}

Expand Down
Expand Up @@ -9,6 +9,7 @@

#include <picojson.h>

#include "VideoCommon/GraphicsModSystem/Config/GraphicsModAsset.h"
#include "VideoCommon/GraphicsModSystem/Config/GraphicsModFeature.h"
#include "VideoCommon/GraphicsModSystem/Config/GraphicsTargetGroup.h"

Expand All @@ -30,6 +31,7 @@ struct GraphicsModConfig

std::vector<GraphicsTargetGroupConfig> m_groups;
std::vector<GraphicsModFeatureConfig> m_features;
std::vector<GraphicsModAssetConfig> m_assets;

static std::optional<GraphicsModConfig> Create(const std::string& file, Source source);
static std::optional<GraphicsModConfig> Create(const picojson::object* obj);
Expand Down
@@ -0,0 +1,52 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "VideoCommon/GraphicsModSystem/Config/GraphicsModAsset.h"

#include "Common/Logging/Log.h"

bool GraphicsModAssetConfig::DeserializeFromConfig(const picojson::object& obj)
{
auto name_iter = obj.find("name");
if (name_iter == obj.end())
{
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset has no name");
return false;
}
if (!name_iter->second.is<std::string>())
{
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset has a name "
"that is not a string");
return false;
}
m_name = name_iter->second.to_str();

auto data_iter = obj.find("data");
if (data_iter == obj.end())
{
ERROR_LOG_FMT(VIDEO, "Failed to load mod configuration file, specified asset '{}' has no data",
m_name);
return false;
}
if (!data_iter->second.is<picojson::object>())
{
ERROR_LOG_FMT(VIDEO,
"Failed to load mod configuration file, specified asset '{}' has data "
"that is not an object",
m_name);
return false;
}
for (const auto& [key, value] : data_iter->second.get<picojson::object>())
{
if (!value.is<std::string>())
{
ERROR_LOG_FMT(VIDEO,
"Failed to load mod configuration file, specified asset '{}' has data "
"with a value for key '{}' that is not a string",
m_name, key);
}
m_map[key] = value.to_str();
}

return true;
}
@@ -0,0 +1,18 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <string>

#include <picojson.h>

#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"

struct GraphicsModAssetConfig
{
std::string m_name;
VideoCommon::DirectFilesystemAssetLibrary::AssetMap m_map;

bool DeserializeFromConfig(const picojson::object& obj);
};

0 comments on commit dbe6a5f

Please sign in to comment.