mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-21 12:13:03 +00:00
fix: auto creating dx9 shader args with too many elements
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Shader/D3D11ShaderAnalyser.h"
|
#include "Shader/D3D11ShaderAnalyser.h"
|
||||||
#include "Shader/D3D9ShaderAnalyser.h"
|
#include "Shader/D3D9ShaderAnalyser.h"
|
||||||
|
#include "Utils/Alignment.h"
|
||||||
#include "Utils/Djb2.h"
|
#include "Utils/Djb2.h"
|
||||||
#include "Utils/Logging/Log.h"
|
#include "Utils/Logging/Log.h"
|
||||||
|
|
||||||
@@ -422,19 +423,20 @@ namespace
|
|||||||
if (!constInfo)
|
if (!constInfo)
|
||||||
return result::Unexpected(std::format("Missing info for code const {}", shaderArg.m_name));
|
return result::Unexpected(std::format("Missing info for code const {}", shaderArg.m_name));
|
||||||
|
|
||||||
const auto variableElementCount = std::max<unsigned>(shaderArg.m_type_elements, 1);
|
const auto elementSize = ElementSizeForArg(shaderArg);
|
||||||
|
const auto elementCount = utils::Align(shaderArg.m_register_count, elementSize) / elementSize;
|
||||||
const auto infoArrayCount = std::max<unsigned>(constInfo->arrayCount, 1);
|
const auto infoArrayCount = std::max<unsigned>(constInfo->arrayCount, 1);
|
||||||
if (variableElementCount > infoArrayCount)
|
if (elementCount > infoArrayCount)
|
||||||
{
|
{
|
||||||
return result::Unexpected(std::format("Could not auto create argument for constant {} as it has more elements ({}) than the code constant ({})",
|
return result::Unexpected(std::format("Could not auto create argument for constant {} as it has more elements ({}) than the code constant ({})",
|
||||||
shaderArg.m_name,
|
shaderArg.m_name,
|
||||||
variableElementCount,
|
elementCount,
|
||||||
infoArrayCount));
|
infoArrayCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
techset::CommonShaderArgDestination commonDestination;
|
techset::CommonShaderArgDestination commonDestination;
|
||||||
const auto isTransposed = shaderArg.m_class == d3d9::ParameterClass::MATRIX_COLUMNS;
|
const auto isTransposed = shaderArg.m_class == d3d9::ParameterClass::MATRIX_COLUMNS;
|
||||||
for (auto elementIndex = 0u; elementIndex < variableElementCount; elementIndex++)
|
for (auto elementIndex = 0u; elementIndex < elementCount; elementIndex++)
|
||||||
{
|
{
|
||||||
commonDestination.dx9.m_destination_register = shaderArg.m_register_index + elementIndex;
|
commonDestination.dx9.m_destination_register = shaderArg.m_register_index + elementIndex;
|
||||||
auto result = AcceptShaderConstantArgument(commonDestination, isTransposed, shaderArg.m_register_count, *maybeCodeConst, elementIndex);
|
auto result = AcceptShaderConstantArgument(commonDestination, isTransposed, shaderArg.m_register_count, *maybeCodeConst, elementIndex);
|
||||||
@@ -448,6 +450,18 @@ namespace
|
|||||||
return NoResult{};
|
return NoResult{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static unsigned ElementSizeForArg(const d3d9::ShaderConstant& arg)
|
||||||
|
{
|
||||||
|
switch (arg.m_class)
|
||||||
|
{
|
||||||
|
case d3d9::ParameterClass::MATRIX_COLUMNS:
|
||||||
|
case d3d9::ParameterClass::MATRIX_ROWS:
|
||||||
|
return 4;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result::Expected<NoResult, std::string> AutoCreateSamplerArg(const d3d9::ShaderConstant& shaderArg)
|
result::Expected<NoResult, std::string> AutoCreateSamplerArg(const d3d9::ShaderConstant& shaderArg)
|
||||||
{
|
{
|
||||||
const auto maybeCodeSampler = m_common_code_source_infos.GetCodeSamplerSourceForAccessor(shaderArg.m_name);
|
const auto maybeCodeSampler = m_common_code_source_infos.GetCodeSamplerSourceForAccessor(shaderArg.m_name);
|
||||||
|
|||||||
Reference in New Issue
Block a user