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

fix: make sure matrix shader args with less than 4 rows are properly dumped and loaded

This commit is contained in:
Jan Laupetin
2026-03-07 00:33:27 +01:00
parent 2f12092773
commit 3aac05a516
3 changed files with 46 additions and 13 deletions

View File

@@ -58,8 +58,9 @@ namespace
{
techset::CommonShaderArgDestination commonDestination{};
bool isTransposed;
unsigned rowCount;
std::string errorMessage;
if (!FindDestinationForConstant(commonDestination, isTransposed, errorMessage, destination))
if (!FindDestinationForConstant(commonDestination, isTransposed, rowCount, errorMessage, destination))
{
if (!errorMessage.empty())
return result::Unexpected(std::move(errorMessage));
@@ -67,7 +68,7 @@ namespace
return result::Unexpected(std::format("Could not find constant shader input with name {}", destination.m_argument_name));
}
return AcceptShaderConstantArgument(commonDestination, isTransposed, codeConstSource, sourceIndex);
return AcceptShaderConstantArgument(commonDestination, isTransposed, rowCount, codeConstSource, sourceIndex);
}
result::Expected<NoResult, std::string> AcceptShaderSamplerArgument(const techset::CommonShaderArgCreatorDestination& destination,
@@ -91,8 +92,9 @@ namespace
{
techset::CommonShaderArgDestination commonDestination{};
bool isTransposed;
unsigned rowCount;
std::string errorMessage;
if (!FindDestinationForConstant(commonDestination, isTransposed, errorMessage, destination))
if (!FindDestinationForConstant(commonDestination, isTransposed, rowCount, errorMessage, destination))
{
if (!errorMessage.empty())
return result::Unexpected(std::move(errorMessage));
@@ -121,8 +123,9 @@ namespace
techset::CommonShaderArgDestination commonDestination{};
bool isTransposed;
unsigned rowCount;
std::string errorMessage;
if (!FindDestinationForConstant(commonDestination, isTransposed, errorMessage, destination))
if (!FindDestinationForConstant(commonDestination, isTransposed, rowCount, errorMessage, destination))
{
if (!errorMessage.empty())
return result::Unexpected(std::move(errorMessage));
@@ -191,6 +194,7 @@ namespace
protected:
result::Expected<NoResult, std::string> AcceptShaderConstantArgument(const techset::CommonShaderArgDestination& commonDestination,
const bool isTransposed,
const unsigned rowCount,
const techset::CommonCodeConstSource codeConstSource,
const unsigned sourceIndex)
{
@@ -207,7 +211,7 @@ namespace
techset::CommonShaderArgCodeConstValue value{
.m_index = 0,
.m_first_row = 0,
.m_row_count = isMatrix ? 4u : 1u,
.m_row_count = isMatrix ? rowCount : 1u,
};
if (isMatrix)
@@ -260,6 +264,7 @@ namespace
[[nodiscard]] virtual bool FindDestinationForConstant(techset::CommonShaderArgDestination& commonDestination,
bool& isTransposed,
unsigned& rowCount,
std::string& errorMessage,
const techset::CommonShaderArgCreatorDestination& input) = 0;
[[nodiscard]] virtual bool FindDestinationForSampler(techset::CommonShaderArgDestination& commonDestination,
@@ -316,6 +321,7 @@ namespace
[[nodiscard]] bool FindDestinationForConstant(techset::CommonShaderArgDestination& commonDestination,
bool& isTransposed,
unsigned& rowCount,
std::string& errorMessage,
const techset::CommonShaderArgCreatorDestination& input) override
{
@@ -402,6 +408,7 @@ namespace
[[nodiscard]] bool FindDestinationForConstant(techset::CommonShaderArgDestination& commonDestination,
bool& isTransposed,
unsigned& rowCount,
std::string& errorMessage,
const techset::CommonShaderArgCreatorDestination& input) override
{
@@ -448,6 +455,7 @@ namespace
commonDestination.dx11.m_size = variableElementSize;
commonDestination.dx11.m_buffer = bufferBinding->m_bind_point;
isTransposed = variableIterator->m_variable_class == d3d11::VariableClass::MATRIX_COLUMNS;
rowCount = variableIterator->m_row_count;
m_const_arg_added[usedConstantIndex] = true;
@@ -632,7 +640,7 @@ namespace
for (auto elementIndex = 0u; elementIndex < variableElementCount; elementIndex++)
{
commonDestination.dx11.m_location.constant_buffer_offset = variable.m_offset + variableElementSize * elementIndex;
auto result = AcceptShaderConstantArgument(commonDestination, isTransposed, *maybeCodeConst, elementIndex);
auto result = AcceptShaderConstantArgument(commonDestination, isTransposed, variable.m_row_count, *maybeCodeConst, elementIndex);
if (!result)
return std::move(result);
}