mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-23 06:17:07 +00:00
fix(techset): write complete Direct3D 9 shader bytecode (#1004)
* fix(techset): write Direct3D 9 shader bytecode bounds * chore: extract shader dumping tests into separate sections --------- Co-authored-by: Jan Laupetin <[email protected]>
This commit is contained in:
co-authored by
Jan Laupetin
parent
6ca37c43fa
commit
2547516e39
@@ -64,7 +64,7 @@ namespace
|
||||
shaderFile->write(pixelShader.prog.loadDef.program, pixelShader.prog.loadDef.programSize);
|
||||
#else
|
||||
shaderFile->write(reinterpret_cast<const char*>(pixelShader.prog.loadDef.program),
|
||||
static_cast<std::streamsize>(pixelShader.prog.loadDef.programSize) * sizeof(GfxPixelShaderLoadDef::program));
|
||||
static_cast<std::streamsize>(pixelShader.prog.loadDef.programSize) * sizeof(*pixelShader.prog.loadDef.program));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace
|
||||
shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize);
|
||||
#else
|
||||
shaderFile->write(reinterpret_cast<const char*>(vertexShader.prog.loadDef.program),
|
||||
static_cast<std::streamsize>(vertexShader.prog.loadDef.programSize) * sizeof(GfxVertexShaderLoadDef::program));
|
||||
static_cast<std::streamsize>(vertexShader.prog.loadDef.programSize) * sizeof(*vertexShader.prog.loadDef.program));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace IW3;
|
||||
using namespace Catch;
|
||||
@@ -233,6 +234,23 @@ namespace
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MaterialTechniqueSet>>(ASSET_TYPE_TECHNIQUE_SET, techset->name, techset));
|
||||
return techset;
|
||||
}
|
||||
|
||||
void EnsureDumpedShaderMatchesInputData(const MockOutputPath& output, const std::string& fileName)
|
||||
{
|
||||
const auto* dumpedFile = output.GetMockedFile(std::format("shader_bin/{}", fileName));
|
||||
REQUIRE(dumpedFile);
|
||||
|
||||
const auto inputFilePath = oat::paths::GetTestDirectory() / "ObjWritingTests/Game/IW3/Techset" / fileName;
|
||||
std::ifstream inputFileStream(inputFilePath, std::ios::binary);
|
||||
REQUIRE(inputFileStream.is_open());
|
||||
|
||||
const auto inputDataSize = static_cast<size_t>(fs::file_size(inputFilePath));
|
||||
std::vector<std::uint8_t> inputData(inputDataSize);
|
||||
inputFileStream.read(reinterpret_cast<char*>(inputData.data()), static_cast<std::streamsize>(inputData.size()));
|
||||
REQUIRE(inputFileStream.gcount() == static_cast<std::streamsize>(inputData.size()));
|
||||
REQUIRE(dumpedFile->m_data.size() == inputData.size());
|
||||
REQUIRE(std::memcmp(dumpedFile->m_data.data(), inputData.data(), inputData.size()) == 0);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("TechsetDumperIW3", "[iw3][techset][dumper]")
|
||||
@@ -335,4 +353,13 @@ TEST_CASE("TechsetDumperIW3", "[iw3][techset][dumper]")
|
||||
REQUIRE(file);
|
||||
REQUIRE(Trimmed(file->AsString()) == Trimmed(expected));
|
||||
}
|
||||
|
||||
SECTION("Can dump shaders")
|
||||
{
|
||||
dumper.Dump(context);
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "vs_simple.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "ps_simple.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "vs_advanced.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "ps_advanced.hlsl.cso");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,6 +409,23 @@ namespace
|
||||
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MaterialTechniqueSet>>(ASSET_TYPE_TECHNIQUE_SET, techset->name, techset));
|
||||
return techset;
|
||||
}
|
||||
|
||||
void EnsureDumpedShaderMatchesInputData(const MockOutputPath& output, const std::string& fileName)
|
||||
{
|
||||
const auto* dumpedFile = output.GetMockedFile(std::format("shader_bin/{}", fileName));
|
||||
REQUIRE(dumpedFile);
|
||||
|
||||
const auto inputFilePath = oat::paths::GetTestDirectory() / "ObjWritingTests/Game/T5/Techset" / fileName;
|
||||
std::ifstream inputFileStream(inputFilePath, std::ios::binary);
|
||||
REQUIRE(inputFileStream.is_open());
|
||||
|
||||
const auto inputDataSize = static_cast<size_t>(fs::file_size(inputFilePath));
|
||||
std::vector<std::uint8_t> inputData(inputDataSize);
|
||||
inputFileStream.read(reinterpret_cast<char*>(inputData.data()), static_cast<std::streamsize>(inputData.size()));
|
||||
REQUIRE(inputFileStream.gcount() == static_cast<std::streamsize>(inputData.size()));
|
||||
REQUIRE(dumpedFile->m_data.size() == inputData.size());
|
||||
REQUIRE(std::memcmp(dumpedFile->m_data.data(), inputData.data(), inputData.size()) == 0);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("TechsetDumperT5", "[t5][techset][dumper]")
|
||||
@@ -546,4 +563,13 @@ TEST_CASE("TechsetDumperT5", "[t5][techset][dumper]")
|
||||
REQUIRE(file);
|
||||
REQUIRE(Trimmed(file->AsString()) == Trimmed(expected));
|
||||
}
|
||||
|
||||
SECTION("Can dump shaders")
|
||||
{
|
||||
dumper.Dump(context);
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "vs_simple.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "ps_simple.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "vs_advanced.hlsl.cso");
|
||||
EnsureDumpedShaderMatchesInputData(mockOutput, "ps_advanced.hlsl.cso");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user