summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2025-11-21 14:31:10 -0600
committeriwubcode <iwubcode@users.noreply.github.com>2025-11-21 14:31:10 -0600
commit2c646cec407786750441fc146bc9a1a6d8f57e5d (patch)
tree81b58fb627956184be3e6b7361329c3e391888ed /Source/Core/VideoCommon
parent1f083a60c99d68cbd48516afc4ec706a6b5cabd0 (diff)
VideoCommon: update ShaderAsset to use a vector of properties, this way we ensure the order of these properties match the order of the material
Diffstat (limited to 'Source/Core/VideoCommon')
-rw-r--r--Source/Core/VideoCommon/Assets/ShaderAsset.cpp35
-rw-r--r--Source/Core/VideoCommon/Assets/ShaderAsset.h8
2 files changed, 20 insertions, 23 deletions
diff --git a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
index ba30911a50..99c9ed4ab0 100644
--- a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
+++ b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
@@ -141,10 +141,9 @@ static bool ParseShaderValue(const CustomAssetLibrary::AssetID& asset_id,
return false;
}
-static bool
-ParseShaderProperties(const VideoCommon::CustomAssetLibrary::AssetID& asset_id,
- const picojson::array& properties_data,
- std::map<std::string, VideoCommon::ShaderProperty>* shader_properties)
+static bool ParseShaderProperties(const VideoCommon::CustomAssetLibrary::AssetID& asset_id,
+ const picojson::array& properties_data,
+ std::vector<ShaderProperty>* shader_properties)
{
if (!shader_properties) [[unlikely]]
return false;
@@ -211,12 +210,12 @@ ParseShaderProperties(const VideoCommon::CustomAssetLibrary::AssetID& asset_id,
asset_id);
return false;
}
- std::string code_name = code_name_iter->second.to_str();
+ property.name = code_name_iter->second.to_str();
const auto default_iter = property_data_obj.find("default");
if (default_iter != property_data_obj.end())
{
- if (!ParseShaderValue(asset_id, default_iter->second, code_name, type,
+ if (!ParseShaderValue(asset_id, default_iter->second, property.name, type,
&property.default_value))
{
return false;
@@ -227,7 +226,7 @@ ParseShaderProperties(const VideoCommon::CustomAssetLibrary::AssetID& asset_id,
property.default_value = ShaderProperty::GetDefaultValueFromTypeName(type);
}
- shader_properties->try_emplace(std::move(code_name), std::move(property));
+ shader_properties->push_back(std::move(property));
}
return true;
@@ -237,7 +236,7 @@ bool RasterSurfaceShaderData::FromJson(const VideoCommon::CustomAssetLibrary::As
const picojson::object& json, RasterSurfaceShaderData* data)
{
const auto parse_properties = [&](const char* name, std::string_view source,
- std::map<std::string, ShaderProperty>* properties) -> bool {
+ std::vector<ShaderProperty>* shader_properties) -> bool {
const auto properties_iter = json.find(name);
if (properties_iter == json.end())
{
@@ -252,7 +251,7 @@ bool RasterSurfaceShaderData::FromJson(const VideoCommon::CustomAssetLibrary::As
}
const auto& properties_array = properties_iter->second.get<picojson::array>();
- return ParseShaderProperties(asset_id, properties_array, properties)
+ return ParseShaderProperties(asset_id, properties_array, shader_properties);
};
const auto parse_samplers =
@@ -327,11 +326,10 @@ bool RasterSurfaceShaderData::FromJson(const VideoCommon::CustomAssetLibrary::As
void RasterSurfaceShaderData::ToJson(picojson::object& obj, const RasterSurfaceShaderData& data)
{
- const auto add_property = [](picojson::array* json_properties, const std::string& name,
- const ShaderProperty& property) {
+ const auto add_property = [](picojson::array* json_properties, const ShaderProperty& property) {
picojson::object json_property;
- json_property.emplace("code_name", name);
+ json_property.emplace("code_name", property.name);
json_property.emplace("description", property.description);
std::visit(overloaded{[&](s32 default_value) {
@@ -391,9 +389,9 @@ void RasterSurfaceShaderData::ToJson(picojson::object& obj, const RasterSurfaceS
};
picojson::array json_properties;
- for (const auto& [name, property] : data.uniform_properties)
+ for (const auto& property : data.uniform_properties)
{
- add_property(&json_properties, name, property);
+ add_property(&json_properties, property);
}
obj.emplace("properties", std::move(json_properties));
@@ -462,22 +460,21 @@ ShaderProperty::Value ShaderProperty::GetDefaultValueFromTypeName(std::string_vi
return Value{};
}
-void ShaderProperty::WriteAsShaderCode(ShaderCode& shader_source, std::string_view name,
- const ShaderProperty& property)
+void ShaderProperty::WriteAsShaderCode(ShaderCode& shader_source, const ShaderProperty& property)
{
const auto write_shader = [&](std::string_view type, u32 element_count) {
if (element_count == 1)
{
- shader_source.Write("{} {};\n", type, name);
+ shader_source.Write("{} {};\n", type, property.name);
}
else
{
- shader_source.Write("{}{} {};\n", type, element_count, name);
+ shader_source.Write("{}{} {};\n", type, element_count, property.name);
}
for (std::size_t i = element_count; i < 4; i++)
{
- shader_source.Write("{} {}_padding_{};\n", type, name, i + 1);
+ shader_source.Write("{} {}_padding_{};\n", type, property.name, i + 1);
}
};
std::visit(overloaded{[&](s32) { write_shader("int", 1); },
diff --git a/Source/Core/VideoCommon/Assets/ShaderAsset.h b/Source/Core/VideoCommon/Assets/ShaderAsset.h
index 6637b967fc..81631fa0b3 100644
--- a/Source/Core/VideoCommon/Assets/ShaderAsset.h
+++ b/Source/Core/VideoCommon/Assets/ShaderAsset.h
@@ -4,11 +4,11 @@
#pragma once
#include <array>
-#include <map>
#include <span>
#include <string>
#include <string_view>
#include <variant>
+#include <vector>
#include <picojson.h>
@@ -36,10 +36,10 @@ struct ShaderProperty
RGB, RGBA>;
static std::span<const std::string_view> GetValueTypeNames();
static Value GetDefaultValueFromTypeName(std::string_view name);
- static void WriteAsShaderCode(ShaderCode& shader_source, std::string_view name,
- const ShaderProperty& property);
+ static void WriteAsShaderCode(ShaderCode& shader_source, const ShaderProperty& property);
Value default_value;
+ std::string name;
std::string description;
};
@@ -53,7 +53,7 @@ struct RasterSurfaceShaderData
// shader expects to expose. The key is text
// expected to be in the shader code and the propery
// describes various details about the input
- std::map<std::string, ShaderProperty> uniform_properties;
+ std::vector<ShaderProperty> uniform_properties;
std::string vertex_source;
std::string pixel_source;