2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-25 14:03:03 +00:00

chore: make sure iw5 can use its special vertex material samplers

This commit is contained in:
Jan Laupetin
2026-03-19 00:12:14 +01:00
parent a497efe67b
commit 2ba00acedd
3 changed files with 58 additions and 14 deletions

View File

@@ -33,7 +33,9 @@ namespace techset
enum class CommonTechniqueShaderType : std::uint8_t enum class CommonTechniqueShaderType : std::uint8_t
{ {
VERTEX, VERTEX,
PIXEL PIXEL,
COUNT
}; };
enum class CommonShaderValueType : std::uint8_t enum class CommonShaderValueType : std::uint8_t
@@ -47,7 +49,9 @@ namespace techset
// Value is set to a sampler from the material // Value is set to a sampler from the material
MATERIAL_SAMPLER, MATERIAL_SAMPLER,
// Value is set to a sampler generated in code // Value is set to a sampler generated in code
CODE_SAMPLER CODE_SAMPLER,
COUNT
}; };
constexpr bool IsConstValueType(const CommonShaderValueType valueType) constexpr bool IsConstValueType(const CommonShaderValueType valueType)

View File

@@ -12,6 +12,16 @@
namespace namespace
{ {
enum class ArgumentType : std::uint8_t
{
VERTEX_CONSTANT,
VERTEX_SAMPLER,
PIXEL_CONSTANT,
PIXEL_SAMPLER,
COUNT
};
const char* ShaderTypeName(const techset::CommonTechniqueShaderType shaderType) const char* ShaderTypeName(const techset::CommonTechniqueShaderType shaderType)
{ {
switch (shaderType) switch (shaderType)
@@ -20,6 +30,9 @@ namespace
return "vertex"; return "vertex";
case techset::CommonTechniqueShaderType::PIXEL: case techset::CommonTechniqueShaderType::PIXEL:
return "pixel"; return "pixel";
case techset::CommonTechniqueShaderType::COUNT:
assert(false);
break;
} }
return "<unknown>"; return "<unknown>";
@@ -36,6 +49,9 @@ namespace
case techset::CommonShaderValueType::CODE_SAMPLER: case techset::CommonShaderValueType::CODE_SAMPLER:
case techset::CommonShaderValueType::MATERIAL_SAMPLER: case techset::CommonShaderValueType::MATERIAL_SAMPLER:
return "sampler"; return "sampler";
case techset::CommonShaderValueType::COUNT:
assert(false);
break;
} }
return "<unknown>"; return "<unknown>";
@@ -47,11 +63,13 @@ namespace
explicit BaseCommonShaderArgCreator(techset::ITechniqueShaderLoader& shaderLoader, techset::CommonCodeSourceInfos& commonCodeSourceInfos) explicit BaseCommonShaderArgCreator(techset::ITechniqueShaderLoader& shaderLoader, techset::CommonCodeSourceInfos& commonCodeSourceInfos)
: m_shader_loader(shaderLoader), : m_shader_loader(shaderLoader),
m_common_code_source_infos(commonCodeSourceInfos), m_common_code_source_infos(commonCodeSourceInfos),
m_supported_argument_types(0),
m_shader_type(techset::CommonTechniqueShaderType::VERTEX), m_shader_type(techset::CommonTechniqueShaderType::VERTEX),
m_bin{}, m_bin{},
m_tech_flags(0), m_tech_flags(0),
m_sampler_flags(0) m_sampler_flags(0)
{ {
DetermineSupportedArgumentTypes();
} }
result::Expected<NoResult, std::string> EnterShader(const techset::CommonTechniqueShaderType shaderType, const std::string& name) override result::Expected<NoResult, std::string> EnterShader(const techset::CommonTechniqueShaderType shaderType, const std::string& name) override
@@ -307,21 +325,36 @@ namespace
return NoResult{}; return NoResult{};
} }
static bool IsArgumentTypeSupported(const techset::CommonShaderArgumentType& argumentType) [[nodiscard]] bool IsArgumentTypeSupported(const techset::CommonShaderArgumentType& argumentType) const
{ {
if (argumentType.m_shader_type == techset::CommonTechniqueShaderType::PIXEL) const auto mask = 1 << (std::to_underlying(argumentType.m_shader_type) * std::to_underlying(techset::CommonShaderValueType::COUNT)
return true; + std::to_underlying(argumentType.m_value_type));
switch (argumentType.m_value_type) return m_supported_argument_types & mask;
}
void DetermineSupportedArgumentTypes()
{ {
case techset::CommonShaderValueType::LITERAL_CONST: // Ensure we have enough bits for the flags
case techset::CommonShaderValueType::MATERIAL_CONST: static_assert(std::to_underlying(techset::CommonTechniqueShaderType::COUNT) * std::to_underlying(techset::CommonShaderValueType::COUNT)
case techset::CommonShaderValueType::CODE_CONST: <= sizeof(m_supported_argument_types) * 8);
return true;
case techset::CommonShaderValueType::MATERIAL_SAMPLER: m_supported_argument_types = 0;
case techset::CommonShaderValueType::CODE_SAMPLER: for (auto shaderType = 0u; shaderType < std::to_underlying(techset::CommonTechniqueShaderType::COUNT); shaderType++)
default: {
return false; for (auto valueType = 0u; valueType < std::to_underlying(techset::CommonShaderValueType::COUNT); valueType++)
{
techset::CommonShaderArgumentType argumentType{
.m_shader_type = static_cast<techset::CommonTechniqueShaderType>(shaderType),
.m_value_type = static_cast<techset::CommonShaderValueType>(valueType),
};
if (m_common_code_source_infos.GetArgumentTypeNumericValue(argumentType).has_value())
{
const auto flag = 1 << (shaderType * std::to_underlying(techset::CommonShaderValueType::COUNT) + valueType);
m_supported_argument_types |= flag;
}
}
} }
} }
@@ -340,6 +373,7 @@ namespace
techset::ITechniqueShaderLoader& m_shader_loader; techset::ITechniqueShaderLoader& m_shader_loader;
techset::CommonCodeSourceInfos& m_common_code_source_infos; techset::CommonCodeSourceInfos& m_common_code_source_infos;
std::uint16_t m_supported_argument_types;
techset::CommonTechniqueShaderType m_shader_type; techset::CommonTechniqueShaderType m_shader_type;
std::string m_shader_name; std::string m_shader_name;

View File

@@ -70,6 +70,9 @@ namespace
case techset::CommonShaderValueType::CODE_CONST: case techset::CommonShaderValueType::CODE_CONST:
return MTL_ARG_CODE_VERTEX_CONST; return MTL_ARG_CODE_VERTEX_CONST;
case techset::CommonShaderValueType::MATERIAL_SAMPLER: case techset::CommonShaderValueType::MATERIAL_SAMPLER:
#if defined(FEATURE_IW5)
return MTL_ARG_MATERIAL_VERTEX_SAMPLER;
#endif
case techset::CommonShaderValueType::CODE_SAMPLER: case techset::CommonShaderValueType::CODE_SAMPLER:
default: default:
assert(false); assert(false);
@@ -119,6 +122,9 @@ namespace
case techset::CommonShaderValueType::MATERIAL_SAMPLER: case techset::CommonShaderValueType::MATERIAL_SAMPLER:
argValue.nameHash = static_cast<decltype(MaterialArgumentDef::nameHash)>(commonArg.m_value.name_hash); argValue.nameHash = static_cast<decltype(MaterialArgumentDef::nameHash)>(commonArg.m_value.name_hash);
break; break;
case techset::CommonShaderValueType::COUNT:
assert(false);
break;
} }
} }