VideoCommon: prepare graphics mods for custom shader material data

This commit is contained in:
iwubcode 2023-12-12 17:56:26 -06:00
parent 7b57a4a37d
commit b1d9e13d75
6 changed files with 19 additions and 5 deletions

View File

@ -5,6 +5,7 @@
#include <array> #include <array>
#include <optional> #include <optional>
#include <span>
#include <string_view> #include <string_view>
#include <vector> #include <vector>
@ -20,6 +21,7 @@ struct DrawStarted
u32 texture_unit; u32 texture_unit;
bool* skip; bool* skip;
std::optional<CustomPixelShader>* custom_pixel_shader; std::optional<CustomPixelShader>* custom_pixel_shader;
std::span<u8>* material_uniform_buffer;
}; };
struct EFB struct EFB

View File

@ -345,7 +345,8 @@ void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& hos
} }
void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type, void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
const ShaderHostConfig& host_config, bool bounding_box) const ShaderHostConfig& host_config, bool bounding_box,
const CustomPixelShaderContents& custom_details)
{ {
// dot product for integer vectors // dot product for integer vectors
out.Write("int idot(int3 x, int3 y)\n" out.Write("int idot(int3 x, int3 y)\n"
@ -426,6 +427,14 @@ void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
out.Write("}};\n"); out.Write("}};\n");
} }
if (!custom_details.shaders.empty() &&
!custom_details.shaders.back().material_uniform_block.empty())
{
out.Write("UBO_BINDING(std140, 3) uniform CustomShaderBlock {{\n");
out.Write("{}", custom_details.shaders.back().material_uniform_block);
out.Write("}} custom_uniforms;\n");
}
if (bounding_box) if (bounding_box)
{ {
out.Write("SSBO_BINDING(0) coherent buffer BBox {{\n" out.Write("SSBO_BINDING(0) coherent buffer BBox {{\n"
@ -907,7 +916,7 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos
// Stuff that is shared between ubershaders and pixelgen. // Stuff that is shared between ubershaders and pixelgen.
WriteBitfieldExtractHeader(out, api_type, host_config); WriteBitfieldExtractHeader(out, api_type, host_config);
WritePixelShaderCommonHeader(out, api_type, host_config, uid_data->bounding_box); WritePixelShaderCommonHeader(out, api_type, host_config, uid_data->bounding_box, custom_details);
// Custom shader details // Custom shader details
WriteCustomShaderStructDef(&out, uid_data->genMode_numtexgens); WriteCustomShaderStructDef(&out, uid_data->genMode_numtexgens);

View File

@ -165,7 +165,8 @@ ShaderCode GeneratePixelShaderCode(APIType api_type, const ShaderHostConfig& hos
const pixel_shader_uid_data* uid_data, const pixel_shader_uid_data* uid_data,
const CustomPixelShaderContents& custom_details); const CustomPixelShaderContents& custom_details);
void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type, void WritePixelShaderCommonHeader(ShaderCode& out, APIType api_type,
const ShaderHostConfig& host_config, bool bounding_box); const ShaderHostConfig& host_config, bool bounding_box,
const CustomPixelShaderContents& custom_details);
void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config, void ClearUnusedPixelShaderUidBits(APIType api_type, const ShaderHostConfig& host_config,
PixelShaderUid* uid); PixelShaderUid* uid);
PixelShaderUid GetPixelShaderUid(); PixelShaderUid GetPixelShaderUid();

View File

@ -334,6 +334,7 @@ constexpr std::string_view CUSTOM_PIXELSHADER_COLOR_FUNC = "customShaderColor";
struct CustomPixelShader struct CustomPixelShader
{ {
std::string custom_shader; std::string custom_shader;
std::string material_uniform_block;
bool operator==(const CustomPixelShader& other) const = default; bool operator==(const CustomPixelShader& other) const = default;
}; };

View File

@ -330,7 +330,7 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config,
out.Write("// {}\n", *uid_data); out.Write("// {}\n", *uid_data);
WriteBitfieldExtractHeader(out, api_type, host_config); WriteBitfieldExtractHeader(out, api_type, host_config);
WritePixelShaderCommonHeader(out, api_type, host_config, bounding_box); WritePixelShaderCommonHeader(out, api_type, host_config, bounding_box, custom_details);
WriteCustomShaderStructDef(&out, numTexgen); WriteCustomShaderStructDef(&out, numTexgen);
for (std::size_t i = 0; i < custom_details.shaders.size(); i++) for (std::size_t i = 0; i < custom_details.shaders.size(); i++)
{ {

View File

@ -603,7 +603,8 @@ void VertexManagerBase::Flush()
const std::string& texture_name = texture_names[i]; const std::string& texture_name = texture_names[i];
const u32 texture_unit = texture_units[i]; const u32 texture_unit = texture_units[i];
bool skip = false; bool skip = false;
GraphicsModActionData::DrawStarted draw_started{texture_unit, &skip, &custom_pixel_shader}; GraphicsModActionData::DrawStarted draw_started{texture_unit, &skip, &custom_pixel_shader,
&custom_pixel_shader_uniforms};
for (const auto& action : g_graphics_mod_manager->GetDrawStartedActions(texture_name)) for (const auto& action : g_graphics_mod_manager->GetDrawStartedActions(texture_name))
{ {
action->OnDrawStarted(&draw_started); action->OnDrawStarted(&draw_started);