mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-03-25 05:53:03 +00:00
chore: add unit tests for iw5 techsets
This commit is contained in:
@@ -0,0 +1,386 @@
|
|||||||
|
#include "Game/IW5/Techset/TechniqueCompilerIW5.h"
|
||||||
|
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "Game/IW5/Techset/PixelShaderLoaderIW5.h"
|
||||||
|
#include "Game/IW5/Techset/VertexDeclCompilerIW5.h"
|
||||||
|
#include "Game/IW5/Techset/VertexShaderLoaderIW5.h"
|
||||||
|
#include "OatTestPaths.h"
|
||||||
|
#include "SearchPath/MockSearchPath.h"
|
||||||
|
#include "Shader/ShaderCommon.h"
|
||||||
|
#include "Utils/MemoryManager.h"
|
||||||
|
#include "catch2/generators/catch_generators.hpp"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
using namespace Catch;
|
||||||
|
using namespace std::literals;
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
void GivenVertexShaderFile(const std::string& name, MockSearchPath& searchPath)
|
||||||
|
{
|
||||||
|
const auto filePath = oat::paths::GetTestDirectory() / "ObjCompilingTests/Game/IW5/Techset" / std::format("vs_{}.cso", name);
|
||||||
|
const auto fileSize = static_cast<size_t>(fs::file_size(filePath));
|
||||||
|
|
||||||
|
std::ifstream file(filePath, std::ios::binary);
|
||||||
|
REQUIRE(file.is_open());
|
||||||
|
|
||||||
|
std::string data(fileSize, '\0');
|
||||||
|
file.read(data.data(), fileSize);
|
||||||
|
REQUIRE(file.gcount() == static_cast<std::streamsize>(fileSize));
|
||||||
|
|
||||||
|
searchPath.AddFileData(shader::GetFileNameForVertexShaderAssetName(name), std::move(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GivenPixelShaderFile(const std::string& name, MockSearchPath& searchPath)
|
||||||
|
{
|
||||||
|
const auto filePath = oat::paths::GetTestDirectory() / "ObjCompilingTests/Game/IW5/Techset" / std::format("ps_{}.cso", name);
|
||||||
|
const auto fileSize = static_cast<size_t>(fs::file_size(filePath));
|
||||||
|
|
||||||
|
std::ifstream file(filePath, std::ios::binary);
|
||||||
|
REQUIRE(file.is_open());
|
||||||
|
|
||||||
|
std::string data(fileSize, '\0');
|
||||||
|
file.read(data.data(), fileSize);
|
||||||
|
REQUIRE(file.gcount() == static_cast<std::streamsize>(fileSize));
|
||||||
|
|
||||||
|
searchPath.AddFileData(shader::GetFileNameForPixelShaderAssetName(name), std::move(data));
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("TechniqueCompilerIW5", "[iw5][techset][compiler]")
|
||||||
|
{
|
||||||
|
|
||||||
|
Zone zone("MockZone", 0, GameId::IW5, GamePlatform::PC);
|
||||||
|
zone.Register();
|
||||||
|
|
||||||
|
MemoryManager memory;
|
||||||
|
AssetCreatorCollection creatorCollection(zone);
|
||||||
|
IgnoredAssetLookup ignoredAssetLookup;
|
||||||
|
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
|
||||||
|
MockSearchPath searchPath;
|
||||||
|
|
||||||
|
creatorCollection.AddAssetCreator(techset::CreateVertexDeclCompilerIW5(memory));
|
||||||
|
creatorCollection.AddAssetCreator(techset::CreateVertexShaderLoaderIW5(memory, searchPath));
|
||||||
|
creatorCollection.AddAssetCreator(techset::CreatePixelShaderLoaderIW5(memory, searchPath));
|
||||||
|
|
||||||
|
auto loader = techset::CreateTechniqueCompilerIW5(memory, zone, searchPath);
|
||||||
|
|
||||||
|
SECTION("Can compile simple technique")
|
||||||
|
{
|
||||||
|
const auto [inputName, inputData] = GENERATE(Catch::Generators::table<const char*, const char*>({
|
||||||
|
{"auto-create args", R"TECHNIQUE(
|
||||||
|
{
|
||||||
|
stateMap "passthrough";
|
||||||
|
|
||||||
|
vertexShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
}
|
||||||
|
)TECHNIQUE"},
|
||||||
|
{"manual args", R"TECHNIQUE(
|
||||||
|
{
|
||||||
|
stateMap "passthrough";
|
||||||
|
|
||||||
|
vertexShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
worldMatrix = constant.worldMatrix;
|
||||||
|
viewProjectionMatrix = constant.viewProjectionMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
}
|
||||||
|
)TECHNIQUE"},
|
||||||
|
}));
|
||||||
|
|
||||||
|
CAPTURE(inputName);
|
||||||
|
searchPath.AddFileData("techniques/zprepass.tech", inputData);
|
||||||
|
|
||||||
|
GivenVertexShaderFile("simple.hlsl", searchPath);
|
||||||
|
GivenPixelShaderFile("simple.hlsl", searchPath);
|
||||||
|
|
||||||
|
auto result = loader->CreateSubAsset("zprepass", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* assetInfo = reinterpret_cast<XAssetInfo<MaterialTechnique>*>(result.GetAssetInfo());
|
||||||
|
const auto* technique = assetInfo->Asset();
|
||||||
|
|
||||||
|
CHECK(technique->name == "zprepass"s);
|
||||||
|
|
||||||
|
CHECK(technique->flags == 0x204);
|
||||||
|
|
||||||
|
REQUIRE(technique->passCount == 1);
|
||||||
|
auto& pass = technique->passArray[0];
|
||||||
|
CHECK(pass.customSamplerFlags == 0);
|
||||||
|
|
||||||
|
REQUIRE(pass.vertexShader);
|
||||||
|
CHECK(pass.vertexShader->name == "simple.hlsl"s);
|
||||||
|
REQUIRE(pass.pixelShader);
|
||||||
|
CHECK(pass.pixelShader->name == "simple.hlsl"s);
|
||||||
|
|
||||||
|
REQUIRE(pass.vertexDecl);
|
||||||
|
auto& vertexDecl = *pass.vertexDecl;
|
||||||
|
CHECK(vertexDecl.name == "pp"s);
|
||||||
|
CHECK(vertexDecl.hasOptionalSource == false);
|
||||||
|
REQUIRE(vertexDecl.streamCount == 1);
|
||||||
|
CHECK(vertexDecl.routing.data[0].source == STREAM_SRC_POSITION);
|
||||||
|
CHECK(vertexDecl.routing.data[0].dest == STREAM_DST_POSITION);
|
||||||
|
|
||||||
|
REQUIRE(pass.perPrimArgCount == 1);
|
||||||
|
REQUIRE(pass.perObjArgCount == 1);
|
||||||
|
REQUIRE(pass.stableArgCount == 0);
|
||||||
|
CHECK(pass.args[0].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[0].dest == 4);
|
||||||
|
CHECK(pass.args[0].u.codeConst.index == CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0);
|
||||||
|
CHECK(pass.args[0].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[0].u.codeConst.rowCount == 4);
|
||||||
|
|
||||||
|
CHECK(pass.args[1].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[1].dest == 0);
|
||||||
|
CHECK(pass.args[1].u.codeConst.index == CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX);
|
||||||
|
CHECK(pass.args[1].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[1].u.codeConst.rowCount == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can compile advanced technique")
|
||||||
|
{
|
||||||
|
const auto [inputName, inputData] = GENERATE(Catch::Generators::table<const char*, const char*>({
|
||||||
|
{"auto-create args", R"TECHNIQUE(
|
||||||
|
{
|
||||||
|
stateMap "passthrough";
|
||||||
|
|
||||||
|
vertexShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanDisplacementSampler = material.oceanDisplacementMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
oceanEnvSampler = material.oceanEnvMap;
|
||||||
|
oceanDetailNormalSampler = material.oceanDetailNormalMap;
|
||||||
|
oceanHeightNormalSampler = material.oceanHeightNormalMap;
|
||||||
|
oceanFoamSampler = material.oceanFoamMap;
|
||||||
|
oceanUVAnimParmFoam = material.oceanUVAnimParmFoam;
|
||||||
|
envMapParms = material.envMapParms;
|
||||||
|
oceanFoamParms = material.oceanFoamParms;
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanUVAnimParmDetail1 = material.oceanUVAnimParmDetail1;
|
||||||
|
oceanUVAnimParmDetail0 = material.oceanUVAnimParmDetail0;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanMiscParms = material.oceanMiscParms;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
vertex.color[0] = code.color;
|
||||||
|
}
|
||||||
|
)TECHNIQUE"},
|
||||||
|
{"manual args", R"TECHNIQUE(
|
||||||
|
{
|
||||||
|
stateMap "passthrough";
|
||||||
|
|
||||||
|
vertexShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
worldMatrix = constant.worldMatrix;
|
||||||
|
viewProjectionMatrix = constant.viewProjectionMatrix;
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanDisplacementSampler = material.oceanDisplacementMap;
|
||||||
|
eyeOffset = constant.eyeOffset;
|
||||||
|
fogConsts = constant.fogConsts;
|
||||||
|
gameTime = constant.gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
oceanEnvSampler = material.oceanEnvMap;
|
||||||
|
oceanDetailNormalSampler = material.oceanDetailNormalMap;
|
||||||
|
oceanHeightNormalSampler = material.oceanHeightNormalMap;
|
||||||
|
oceanFoamSampler = material.oceanFoamMap;
|
||||||
|
fogColorLinear = constant.fogColorLinear;
|
||||||
|
gameTime = constant.gameTime;
|
||||||
|
oceanUVAnimParmFoam = material.oceanUVAnimParmFoam;
|
||||||
|
envMapParms = material.envMapParms;
|
||||||
|
oceanFoamParms = material.oceanFoamParms;
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanUVAnimParmDetail1 = material.oceanUVAnimParmDetail1;
|
||||||
|
oceanUVAnimParmDetail0 = material.oceanUVAnimParmDetail0;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanMiscParms = material.oceanMiscParms;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
vertex.color[0] = code.color;
|
||||||
|
}
|
||||||
|
)TECHNIQUE"},
|
||||||
|
}));
|
||||||
|
|
||||||
|
CAPTURE(inputName);
|
||||||
|
searchPath.AddFileData("techniques/example_lit_sun_shadow.tech", inputData);
|
||||||
|
|
||||||
|
GivenVertexShaderFile("advanced.hlsl", searchPath);
|
||||||
|
GivenPixelShaderFile("advanced.hlsl", searchPath);
|
||||||
|
|
||||||
|
auto result = loader->CreateSubAsset("example_lit_sun_shadow", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* assetInfo = reinterpret_cast<XAssetInfo<MaterialTechnique>*>(result.GetAssetInfo());
|
||||||
|
const auto* technique = assetInfo->Asset();
|
||||||
|
|
||||||
|
CHECK(technique->name == "example_lit_sun_shadow"s);
|
||||||
|
|
||||||
|
CHECK(technique->flags == 0);
|
||||||
|
|
||||||
|
REQUIRE(technique->passCount == 1);
|
||||||
|
auto& pass = technique->passArray[0];
|
||||||
|
CHECK(pass.customSamplerFlags == 0);
|
||||||
|
|
||||||
|
REQUIRE(pass.vertexShader);
|
||||||
|
CHECK(pass.vertexShader->name == "advanced.hlsl"s);
|
||||||
|
REQUIRE(pass.pixelShader);
|
||||||
|
CHECK(pass.pixelShader->name == "advanced.hlsl"s);
|
||||||
|
|
||||||
|
REQUIRE(pass.vertexDecl);
|
||||||
|
auto& vertexDecl = *pass.vertexDecl;
|
||||||
|
CHECK(vertexDecl.hasOptionalSource == false);
|
||||||
|
REQUIRE(vertexDecl.streamCount == 2);
|
||||||
|
CHECK(vertexDecl.routing.data[0].source == STREAM_SRC_POSITION);
|
||||||
|
CHECK(vertexDecl.routing.data[0].dest == STREAM_DST_POSITION);
|
||||||
|
CHECK(vertexDecl.routing.data[1].source == STREAM_SRC_COLOR);
|
||||||
|
CHECK(vertexDecl.routing.data[1].dest == STREAM_DST_COLOR_0);
|
||||||
|
|
||||||
|
REQUIRE(pass.perPrimArgCount == 1);
|
||||||
|
REQUIRE(pass.perObjArgCount == 1);
|
||||||
|
REQUIRE(pass.stableArgCount == 22);
|
||||||
|
|
||||||
|
CHECK(pass.args[0].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[0].dest == 4);
|
||||||
|
CHECK(pass.args[0].u.codeConst.index == CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0);
|
||||||
|
CHECK(pass.args[0].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[0].u.codeConst.rowCount == 4);
|
||||||
|
|
||||||
|
CHECK(pass.args[1].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[1].dest == 0);
|
||||||
|
CHECK(pass.args[1].u.codeConst.index == CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX);
|
||||||
|
CHECK(pass.args[1].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[1].u.codeConst.rowCount == 4);
|
||||||
|
|
||||||
|
CHECK(pass.args[2].type == MTL_ARG_MATERIAL_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[2].dest == 59);
|
||||||
|
CHECK(pass.args[2].u.nameHash == 0x470F6C9A);
|
||||||
|
|
||||||
|
CHECK(pass.args[3].type == MTL_ARG_MATERIAL_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[3].dest == 60);
|
||||||
|
CHECK(pass.args[3].u.nameHash == 0x470F6C9B);
|
||||||
|
|
||||||
|
CHECK(pass.args[4].type == MTL_ARG_MATERIAL_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[4].dest == 58);
|
||||||
|
CHECK(pass.args[4].u.nameHash == 0x9D5408FF);
|
||||||
|
|
||||||
|
CHECK(pass.args[5].type == MTL_ARG_MATERIAL_VERTEX_SAMPLER);
|
||||||
|
CHECK(pass.args[5].dest == 2);
|
||||||
|
CHECK(pass.args[5].u.nameHash == 0x29F357AD);
|
||||||
|
|
||||||
|
CHECK(pass.args[6].type == MTL_ARG_MATERIAL_PIXEL_SAMPLER);
|
||||||
|
CHECK(pass.args[6].dest == 5);
|
||||||
|
CHECK(pass.args[6].u.nameHash == 0x7D392967);
|
||||||
|
|
||||||
|
CHECK(pass.args[7].type == MTL_ARG_MATERIAL_PIXEL_SAMPLER);
|
||||||
|
CHECK(pass.args[7].dest == 7);
|
||||||
|
CHECK(pass.args[7].u.nameHash == 0x88792E38);
|
||||||
|
|
||||||
|
CHECK(pass.args[8].type == MTL_ARG_MATERIAL_PIXEL_SAMPLER);
|
||||||
|
CHECK(pass.args[8].dest == 4);
|
||||||
|
CHECK(pass.args[8].u.nameHash == 0x8CB95536);
|
||||||
|
|
||||||
|
CHECK(pass.args[9].type == MTL_ARG_MATERIAL_PIXEL_SAMPLER);
|
||||||
|
CHECK(pass.args[9].dest == 6);
|
||||||
|
CHECK(pass.args[9].u.nameHash == 0xC096573F);
|
||||||
|
|
||||||
|
CHECK(pass.args[10].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[10].dest == 10);
|
||||||
|
CHECK(pass.args[10].u.codeConst.index == CONST_SRC_CODE_EYEOFFSET);
|
||||||
|
CHECK(pass.args[10].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[10].u.codeConst.rowCount == 1);
|
||||||
|
|
||||||
|
CHECK(pass.args[11].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[11].dest == 21);
|
||||||
|
CHECK(pass.args[11].u.codeConst.index == CONST_SRC_CODE_FOG);
|
||||||
|
CHECK(pass.args[11].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[11].u.codeConst.rowCount == 1);
|
||||||
|
|
||||||
|
CHECK(pass.args[12].type == MTL_ARG_CODE_VERTEX_CONST);
|
||||||
|
CHECK(pass.args[12].dest == 22);
|
||||||
|
CHECK(pass.args[12].u.codeConst.index == CONST_SRC_CODE_GAMETIME);
|
||||||
|
CHECK(pass.args[12].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[12].u.codeConst.rowCount == 1);
|
||||||
|
|
||||||
|
CHECK(pass.args[13].type == MTL_ARG_CODE_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[13].dest == 0);
|
||||||
|
CHECK(pass.args[13].u.codeConst.index == CONST_SRC_CODE_FOG_COLOR_LINEAR);
|
||||||
|
CHECK(pass.args[13].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[13].u.codeConst.rowCount == 1);
|
||||||
|
|
||||||
|
CHECK(pass.args[14].type == MTL_ARG_CODE_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[14].dest == 3);
|
||||||
|
CHECK(pass.args[14].u.codeConst.index == CONST_SRC_CODE_GAMETIME);
|
||||||
|
CHECK(pass.args[14].u.codeConst.firstRow == 0);
|
||||||
|
CHECK(pass.args[14].u.codeConst.rowCount == 1);
|
||||||
|
|
||||||
|
CHECK(pass.args[15].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[15].dest == 9);
|
||||||
|
CHECK(pass.args[15].u.nameHash == 0x64E3AE5);
|
||||||
|
|
||||||
|
CHECK(pass.args[16].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[16].dest == 5);
|
||||||
|
CHECK(pass.args[16].u.nameHash == 0x3D9994DC);
|
||||||
|
|
||||||
|
CHECK(pass.args[17].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[17].dest == 22);
|
||||||
|
CHECK(pass.args[17].u.nameHash == 0x3FC0F1DE);
|
||||||
|
|
||||||
|
CHECK(pass.args[18].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[18].dest == 7);
|
||||||
|
CHECK(pass.args[18].u.nameHash == 0x470F6C9A);
|
||||||
|
|
||||||
|
CHECK(pass.args[19].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[19].dest == 8);
|
||||||
|
CHECK(pass.args[19].u.nameHash == 0x470F6C9B);
|
||||||
|
|
||||||
|
CHECK(pass.args[20].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[20].dest == 20);
|
||||||
|
CHECK(pass.args[20].u.nameHash == 0x6373ABA0);
|
||||||
|
|
||||||
|
CHECK(pass.args[21].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[21].dest == 11);
|
||||||
|
CHECK(pass.args[21].u.nameHash == 0x6373ABA1);
|
||||||
|
|
||||||
|
CHECK(pass.args[22].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[22].dest == 6);
|
||||||
|
CHECK(pass.args[22].u.nameHash == 0x9D5408FF);
|
||||||
|
|
||||||
|
CHECK(pass.args[23].type == MTL_ARG_MATERIAL_PIXEL_CONST);
|
||||||
|
CHECK(pass.args[23].dest == 21);
|
||||||
|
CHECK(pass.args[23].u.nameHash == 0xAA2E7C4F);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#include "Game/IW5/Techset/TechsetCompilerIW5.h"
|
||||||
|
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "SearchPath/MockSearchPath.h"
|
||||||
|
#include "Techset/TechsetCommon.h"
|
||||||
|
#include "Utils/TestMemoryManager.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <catch2/generators/catch_generators.hpp>
|
||||||
|
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
MaterialTechnique* GivenTechnique(const std::string& name, AssetCreationContext& context, MemoryManager& memory)
|
||||||
|
{
|
||||||
|
auto* technique = memory.Alloc<MaterialTechnique>();
|
||||||
|
technique->name = memory.Dup(name.c_str());
|
||||||
|
|
||||||
|
context.AddSubAsset<SubAssetTechnique>(name, technique);
|
||||||
|
|
||||||
|
return technique;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("TechsetCompilerIW5", "[techset][iw5][compiler]")
|
||||||
|
{
|
||||||
|
Zone zone("test", 0, GameId::IW5, GamePlatform::PC);
|
||||||
|
AssetCreatorCollection creators(zone);
|
||||||
|
IgnoredAssetLookup ignoredAssets;
|
||||||
|
AssetCreationContext context(zone, &creators, &ignoredAssets);
|
||||||
|
MockSearchPath searchPath;
|
||||||
|
TestMemoryManager memory;
|
||||||
|
const auto sut = techset::CreateTechsetCompilerIW5(memory, searchPath);
|
||||||
|
|
||||||
|
SECTION("Sets correct worldVertFormat")
|
||||||
|
{
|
||||||
|
const auto [techsetName, expectedWorldVertFormat] = GENERATE(Catch::Generators::table<const char*, MaterialWorldVertexFormat>({
|
||||||
|
{"default", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"effect_zeqqz943", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"lit_r0c0_t1c1n1", MTL_WORLDVERT_TEX_2_NRM_1},
|
||||||
|
{"lit_r0c0n0x0_b1c1n1s1v1", MTL_WORLDVERT_TEX_2_NRM_2},
|
||||||
|
{"lit_r0c0n0x0_b1c1n1s1v1_b2c2n2x2", MTL_WORLDVERT_TEX_3_NRM_3},
|
||||||
|
{"lit_sm_b0c0_b1c1_b2c2", MTL_WORLDVERT_TEX_3_NRM_1},
|
||||||
|
{"lit_sm_b0c0_b1c1n1x1_b2c2n2v2", MTL_WORLDVERT_TEX_3_NRM_2},
|
||||||
|
{"lit_sm_r0c0_b1c1_b2c2_b3c3", MTL_WORLDVERT_TEX_4_NRM_1},
|
||||||
|
{"lit_sm_r0c0n0_b1c1_b2c2n2v2_m3c3", MTL_WORLDVERT_TEX_4_NRM_2},
|
||||||
|
{"lit_sm_r0c0n0_b1c1n1s1", MTL_WORLDVERT_TEX_2_NRM_2},
|
||||||
|
{"lit_sm_r0c0n0s0_b1c1n1s1_b2c2n2", MTL_WORLDVERT_TEX_3_NRM_3},
|
||||||
|
{"lit_sm_r0c0n0x0_b1c1_b2c2n2s2", MTL_WORLDVERT_TEX_3_NRM_2},
|
||||||
|
{"lit_sm_r0c0n0x0_b1c1n1_b2c2n2s2v2", MTL_WORLDVERT_TEX_3_NRM_3},
|
||||||
|
{"lit_sm_r0c0n0x0_b1c1s1v1_m2c2_m3c3", MTL_WORLDVERT_TEX_4_NRM_1},
|
||||||
|
{"lit_sm_r0c0n0x0_b1c1v1_b2c2n2s2_m3c3", MTL_WORLDVERT_TEX_4_NRM_2},
|
||||||
|
{"lit_sm_r0c0s0_b1c1n1s1_m2c2", MTL_WORLDVERT_TEX_3_NRM_1},
|
||||||
|
{"lit_sm_r0c0x0_b1c1", MTL_WORLDVERT_TEX_2_NRM_1},
|
||||||
|
{"lit_sm_r0c0x0_b1c1n1s1_b2c2n2s2", MTL_WORLDVERT_TEX_3_NRM_2},
|
||||||
|
{"lit_sm_r0c0x0_m1c1_m2c2_m3c3", MTL_WORLDVERT_TEX_4_NRM_1},
|
||||||
|
{"lit_sm_t0c0n0_b1c1n1v1", MTL_WORLDVERT_TEX_2_NRM_2},
|
||||||
|
{"lit_sm_t0c0n0s0_b1c1n1_b2c2n2s2v2", MTL_WORLDVERT_TEX_3_NRM_3},
|
||||||
|
{"mc_lit_sm_r0c0d0_2213939z", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"wpc_lit_sm_b0c0s0_3f3q946z", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"wpc_lit_sm_r0c0n0s0o0_qj92q1f8", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"wpc_sw4_3d_burning_embers_nuketown_74j6971w", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
{"wpc_unlitdecalblend_add_j26wq580", MTL_WORLDVERT_TEX_1_NRM_1},
|
||||||
|
}));
|
||||||
|
|
||||||
|
CAPTURE(techsetName);
|
||||||
|
searchPath.AddFileData(techset::GetFileNameForTechsetName(techsetName), "");
|
||||||
|
|
||||||
|
const auto result = sut->CreateAsset(techsetName, context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* techset = static_cast<MaterialTechniqueSet*>(result.GetAssetInfo()->m_ptr);
|
||||||
|
CHECK(techset->worldVertFormat == expectedWorldVertFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can parse simple techset")
|
||||||
|
{
|
||||||
|
searchPath.AddFileData(techset::GetFileNameForTechsetName("simple"), R"TECHSET(
|
||||||
|
"depth prepass":
|
||||||
|
example_zprepass;
|
||||||
|
|
||||||
|
"lit":
|
||||||
|
example_lit;
|
||||||
|
)TECHSET");
|
||||||
|
|
||||||
|
auto* exampleZPrepass = GivenTechnique("example_zprepass", context, memory);
|
||||||
|
auto* exampleLit = GivenTechnique("example_lit", context, memory);
|
||||||
|
|
||||||
|
const auto result = sut->CreateAsset("simple", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* techset = static_cast<MaterialTechniqueSet*>(result.GetAssetInfo()->m_ptr);
|
||||||
|
CHECK(techset->name == "simple"s);
|
||||||
|
CHECK(techset->worldVertFormat == MTL_WORLDVERT_TEX_1_NRM_1);
|
||||||
|
|
||||||
|
size_t techniqueCount = 0;
|
||||||
|
for (auto* technique : techset->techniques)
|
||||||
|
{
|
||||||
|
if (technique)
|
||||||
|
techniqueCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(techniqueCount == 2);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_DEPTH_PREPASS] == exampleZPrepass);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_LIT] == exampleLit);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can parse techset with same technique used multiple times")
|
||||||
|
{
|
||||||
|
searchPath.AddFileData(techset::GetFileNameForTechsetName("simple"), R"TECHSET(
|
||||||
|
"depth prepass":
|
||||||
|
"build shadowmap depth":
|
||||||
|
example_zprepass;
|
||||||
|
|
||||||
|
"lit":
|
||||||
|
"lit sun":
|
||||||
|
"lit instanced spot shadow cucoloris dfog":
|
||||||
|
example_lit_sun;
|
||||||
|
)TECHSET");
|
||||||
|
|
||||||
|
auto* exampleZPrepass = GivenTechnique("example_zprepass", context, memory);
|
||||||
|
auto* exampleLitSun = GivenTechnique("example_lit_sun", context, memory);
|
||||||
|
|
||||||
|
const auto result = sut->CreateAsset("simple", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* techset = static_cast<MaterialTechniqueSet*>(result.GetAssetInfo()->m_ptr);
|
||||||
|
CHECK(techset->name == "simple"s);
|
||||||
|
CHECK(techset->worldVertFormat == MTL_WORLDVERT_TEX_1_NRM_1);
|
||||||
|
|
||||||
|
size_t techniqueCount = 0;
|
||||||
|
for (auto* technique : techset->techniques)
|
||||||
|
{
|
||||||
|
if (technique)
|
||||||
|
techniqueCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK(techniqueCount == 5);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_DEPTH_PREPASS] == exampleZPrepass);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_BUILD_SHADOWMAP_DEPTH] == exampleZPrepass);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_LIT] == exampleLitSun);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_LIT_SUN] == exampleLitSun);
|
||||||
|
CHECK(techset->techniques[TECHNIQUE_LIT_INSTANCED_SPOT_SHADOW_CUCOLORIS_DFOG] == exampleLitSun);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
#include "Game/IW5/Techset/VertexDeclCompilerIW5.h"
|
||||||
|
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "Utils/MemoryManager.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
using namespace Catch;
|
||||||
|
using namespace std::literals;
|
||||||
|
|
||||||
|
TEST_CASE("VertexDeclCompilerIW5", "[iw5][techset][compiler]")
|
||||||
|
{
|
||||||
|
Zone zone("MockZone", 0, GameId::IW5, GamePlatform::PC);
|
||||||
|
zone.Register();
|
||||||
|
|
||||||
|
MemoryManager memory;
|
||||||
|
AssetCreatorCollection creatorCollection(zone);
|
||||||
|
IgnoredAssetLookup ignoredAssetLookup;
|
||||||
|
AssetCreationContext context(zone, &creatorCollection, &ignoredAssetLookup);
|
||||||
|
|
||||||
|
auto loader = techset::CreateVertexDeclCompilerIW5(memory);
|
||||||
|
|
||||||
|
SECTION("Can create simple vertex decl")
|
||||||
|
{
|
||||||
|
auto result = loader->CreateAsset("pp", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* assetInfo = reinterpret_cast<XAssetInfo<MaterialVertexDeclaration>*>(result.GetAssetInfo());
|
||||||
|
const auto* decl = assetInfo->Asset();
|
||||||
|
|
||||||
|
CHECK(decl->name == "pp"s);
|
||||||
|
CHECK(decl->hasOptionalSource == false);
|
||||||
|
|
||||||
|
REQUIRE(decl->streamCount == 1);
|
||||||
|
CHECK(decl->routing.data[0].source == STREAM_SRC_POSITION);
|
||||||
|
CHECK(decl->routing.data[0].dest == STREAM_DST_POSITION);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can create advanced vertex decl")
|
||||||
|
{
|
||||||
|
auto result = loader->CreateAsset("pdcc1tt7t1t1n1n", context);
|
||||||
|
REQUIRE(result.HasBeenSuccessful());
|
||||||
|
|
||||||
|
const auto* assetInfo = reinterpret_cast<XAssetInfo<MaterialVertexDeclaration>*>(result.GetAssetInfo());
|
||||||
|
const auto* decl = assetInfo->Asset();
|
||||||
|
|
||||||
|
CHECK(decl->name == "pdcc1tt7t1t1n1n"s);
|
||||||
|
CHECK(decl->hasOptionalSource == true);
|
||||||
|
|
||||||
|
REQUIRE(decl->streamCount == 5);
|
||||||
|
CHECK(decl->routing.data[0].source == STREAM_SRC_POSITION);
|
||||||
|
CHECK(decl->routing.data[0].dest == STREAM_DST_DEPTH);
|
||||||
|
CHECK(decl->routing.data[1].source == STREAM_SRC_COLOR);
|
||||||
|
CHECK(decl->routing.data[1].dest == STREAM_DST_COLOR_1);
|
||||||
|
CHECK(decl->routing.data[2].source == STREAM_SRC_TANGENT);
|
||||||
|
CHECK(decl->routing.data[2].dest == STREAM_DST_TEXCOORD_7);
|
||||||
|
CHECK(decl->routing.data[3].source == STREAM_SRC_TEXCOORD_1);
|
||||||
|
CHECK(decl->routing.data[3].dest == STREAM_DST_TEXCOORD_1);
|
||||||
|
CHECK(decl->routing.data[4].source == STREAM_SRC_NORMAL_TRANSFORM_1);
|
||||||
|
CHECK(decl->routing.data[4].dest == STREAM_DST_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
test/ObjCompilingTests/Game/IW5/Techset/ps_advanced.hlsl.cso
Normal file
BIN
test/ObjCompilingTests/Game/IW5/Techset/ps_advanced.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjCompilingTests/Game/IW5/Techset/ps_simple.hlsl.cso
Normal file
BIN
test/ObjCompilingTests/Game/IW5/Techset/ps_simple.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjCompilingTests/Game/IW5/Techset/vs_advanced.hlsl.cso
Normal file
BIN
test/ObjCompilingTests/Game/IW5/Techset/vs_advanced.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjCompilingTests/Game/IW5/Techset/vs_simple.hlsl.cso
Normal file
BIN
test/ObjCompilingTests/Game/IW5/Techset/vs_simple.hlsl.cso
Normal file
Binary file not shown.
375
test/ObjWritingTests/Game/IW5/Techset/TechsetDumperIW5Test.cpp
Normal file
375
test/ObjWritingTests/Game/IW5/Techset/TechsetDumperIW5Test.cpp
Normal file
@@ -0,0 +1,375 @@
|
|||||||
|
#include "Game/IW5/Techset/TechsetDumperIW5.h"
|
||||||
|
|
||||||
|
#include "Asset/AssetRegistration.h"
|
||||||
|
#include "Game/IW5/IW5.h"
|
||||||
|
#include "OatTestPaths.h"
|
||||||
|
#include "SearchPath/MockOutputPath.h"
|
||||||
|
#include "SearchPath/MockSearchPath.h"
|
||||||
|
#include "Utils/MemoryManager.h"
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace IW5;
|
||||||
|
using namespace Catch;
|
||||||
|
using namespace std::literals;
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::string Trimmed(const std::string& input)
|
||||||
|
{
|
||||||
|
auto start = input.find_first_not_of(" \r\n");
|
||||||
|
if (start == std::string::npos)
|
||||||
|
start = 0;
|
||||||
|
|
||||||
|
auto end = input.find_last_not_of(" \r\n");
|
||||||
|
if (end == std::string::npos)
|
||||||
|
end = input.length();
|
||||||
|
else
|
||||||
|
end = end + 1;
|
||||||
|
|
||||||
|
return input.substr(start, end - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialVertexShader* GivenVertexShader(const std::string& name, MemoryManager& memory)
|
||||||
|
{
|
||||||
|
const auto filePath = oat::paths::GetTestDirectory() / "ObjWritingTests/Game/IW5/Techset" / std::format("vs_{}.cso", name);
|
||||||
|
const auto fileSize = static_cast<size_t>(fs::file_size(filePath));
|
||||||
|
|
||||||
|
std::ifstream file(filePath, std::ios::binary);
|
||||||
|
REQUIRE(file.is_open());
|
||||||
|
|
||||||
|
auto* shader = memory.Alloc<MaterialVertexShader>();
|
||||||
|
shader->name = memory.Dup(name.c_str());
|
||||||
|
shader->prog.loadDef.program = reinterpret_cast<unsigned*>(memory.Alloc<char>(fileSize));
|
||||||
|
shader->prog.loadDef.programSize = static_cast<decltype(GfxVertexShaderLoadDef::programSize)>(fileSize / 4u);
|
||||||
|
file.read(reinterpret_cast<char*>(shader->prog.loadDef.program), fileSize);
|
||||||
|
REQUIRE(file.gcount() == static_cast<std::streamsize>(fileSize));
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialPixelShader* GivenPixelShader(const std::string& name, MemoryManager& memory)
|
||||||
|
{
|
||||||
|
const auto filePath = oat::paths::GetTestDirectory() / "ObjWritingTests/Game/IW5/Techset" / std::format("ps_{}.cso", name);
|
||||||
|
const auto fileSize = static_cast<size_t>(fs::file_size(filePath));
|
||||||
|
|
||||||
|
std::ifstream file(filePath, std::ios::binary);
|
||||||
|
REQUIRE(file.is_open());
|
||||||
|
|
||||||
|
auto* shader = memory.Alloc<MaterialPixelShader>();
|
||||||
|
shader->name = memory.Dup(name.c_str());
|
||||||
|
shader->prog.loadDef.program = reinterpret_cast<unsigned*>(memory.Alloc<char>(fileSize));
|
||||||
|
shader->prog.loadDef.programSize = static_cast<decltype(GfxVertexShaderLoadDef::programSize)>(fileSize / 4u);
|
||||||
|
file.read(reinterpret_cast<char*>(shader->prog.loadDef.program), fileSize);
|
||||||
|
REQUIRE(file.gcount() == static_cast<std::streamsize>(fileSize));
|
||||||
|
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialTechnique* GivenDepthPrepassTechnique(MemoryManager& memory)
|
||||||
|
{
|
||||||
|
auto* technique = memory.Alloc<MaterialTechnique>();
|
||||||
|
technique->name = "example_zprepass";
|
||||||
|
technique->flags = 0x204;
|
||||||
|
technique->passCount = 1;
|
||||||
|
|
||||||
|
auto& pass = technique->passArray[0];
|
||||||
|
pass.perPrimArgCount = 1;
|
||||||
|
pass.perObjArgCount = 1;
|
||||||
|
pass.stableArgCount = 0;
|
||||||
|
pass.customSamplerFlags = 0;
|
||||||
|
|
||||||
|
pass.vertexShader = GivenVertexShader("simple.hlsl", memory);
|
||||||
|
pass.pixelShader = GivenPixelShader("simple.hlsl", memory);
|
||||||
|
|
||||||
|
pass.vertexDecl = memory.Alloc<MaterialVertexDeclaration>();
|
||||||
|
auto& vertexDecl = *pass.vertexDecl;
|
||||||
|
vertexDecl.name = "pp";
|
||||||
|
vertexDecl.streamCount = 1;
|
||||||
|
vertexDecl.hasOptionalSource = false;
|
||||||
|
vertexDecl.routing.data[0].source = STREAM_SRC_POSITION;
|
||||||
|
vertexDecl.routing.data[0].dest = STREAM_DST_POSITION;
|
||||||
|
|
||||||
|
pass.args = memory.Alloc<MaterialShaderArgument>(2);
|
||||||
|
pass.args[0].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[0].dest = 4;
|
||||||
|
pass.args[0].u.codeConst.index = CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0;
|
||||||
|
pass.args[0].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[0].u.codeConst.rowCount = 4;
|
||||||
|
|
||||||
|
pass.args[1].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[1].dest = 0;
|
||||||
|
pass.args[1].u.codeConst.index = CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX;
|
||||||
|
pass.args[1].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[1].u.codeConst.rowCount = 4;
|
||||||
|
|
||||||
|
return technique;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialTechnique* GivenLitTechnique(MemoryManager& memory)
|
||||||
|
{
|
||||||
|
auto* technique = memory.Alloc<MaterialTechnique>();
|
||||||
|
technique->name = "example_lit";
|
||||||
|
technique->flags = 0;
|
||||||
|
technique->passCount = 1;
|
||||||
|
|
||||||
|
auto& pass = technique->passArray[0];
|
||||||
|
pass.perPrimArgCount = 1;
|
||||||
|
pass.perObjArgCount = 1;
|
||||||
|
pass.stableArgCount = 22;
|
||||||
|
pass.customSamplerFlags = 0;
|
||||||
|
|
||||||
|
pass.vertexShader = GivenVertexShader("advanced.hlsl", memory);
|
||||||
|
pass.pixelShader = GivenPixelShader("advanced.hlsl", memory);
|
||||||
|
|
||||||
|
pass.vertexDecl = memory.Alloc<MaterialVertexDeclaration>();
|
||||||
|
auto& vertexDecl = *pass.vertexDecl;
|
||||||
|
vertexDecl.name = "ppcc0";
|
||||||
|
vertexDecl.streamCount = 2;
|
||||||
|
vertexDecl.hasOptionalSource = false;
|
||||||
|
vertexDecl.routing.data[0].source = STREAM_SRC_POSITION;
|
||||||
|
vertexDecl.routing.data[0].dest = STREAM_DST_POSITION;
|
||||||
|
vertexDecl.routing.data[1].source = STREAM_SRC_COLOR;
|
||||||
|
vertexDecl.routing.data[1].dest = STREAM_DST_COLOR_0;
|
||||||
|
|
||||||
|
pass.args = memory.Alloc<MaterialShaderArgument>(24);
|
||||||
|
pass.args[0].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[0].dest = 4;
|
||||||
|
pass.args[0].u.codeConst.index = CONST_SRC_CODE_TRANSPOSE_WORLD_MATRIX0;
|
||||||
|
pass.args[0].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[0].u.codeConst.rowCount = 4;
|
||||||
|
|
||||||
|
pass.args[1].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[1].dest = 0;
|
||||||
|
pass.args[1].u.codeConst.index = CONST_SRC_CODE_TRANSPOSE_VIEW_PROJECTION_MATRIX;
|
||||||
|
pass.args[1].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[1].u.codeConst.rowCount = 4;
|
||||||
|
|
||||||
|
pass.args[2].type = MTL_ARG_MATERIAL_VERTEX_CONST;
|
||||||
|
pass.args[2].dest = 59;
|
||||||
|
pass.args[2].u.nameHash = 0x470F6C9A;
|
||||||
|
|
||||||
|
pass.args[3].type = MTL_ARG_MATERIAL_VERTEX_CONST;
|
||||||
|
pass.args[3].dest = 60;
|
||||||
|
pass.args[3].u.nameHash = 0x470F6C9B;
|
||||||
|
|
||||||
|
pass.args[4].type = MTL_ARG_MATERIAL_VERTEX_CONST;
|
||||||
|
pass.args[4].dest = 58;
|
||||||
|
pass.args[4].u.nameHash = 0x9D5408FF;
|
||||||
|
|
||||||
|
pass.args[5].type = MTL_ARG_MATERIAL_VERTEX_SAMPLER;
|
||||||
|
pass.args[5].dest = 2;
|
||||||
|
pass.args[5].u.nameHash = 0x29F357AD;
|
||||||
|
|
||||||
|
pass.args[6].type = MTL_ARG_MATERIAL_PIXEL_SAMPLER;
|
||||||
|
pass.args[6].dest = 5;
|
||||||
|
pass.args[6].u.nameHash = 0x7D392967;
|
||||||
|
|
||||||
|
pass.args[7].type = MTL_ARG_MATERIAL_PIXEL_SAMPLER;
|
||||||
|
pass.args[7].dest = 7;
|
||||||
|
pass.args[7].u.nameHash = 0x88792E38;
|
||||||
|
|
||||||
|
pass.args[8].type = MTL_ARG_MATERIAL_PIXEL_SAMPLER;
|
||||||
|
pass.args[8].dest = 4;
|
||||||
|
pass.args[8].u.nameHash = 0x8CB95536;
|
||||||
|
|
||||||
|
pass.args[9].type = MTL_ARG_MATERIAL_PIXEL_SAMPLER;
|
||||||
|
pass.args[9].dest = 6;
|
||||||
|
pass.args[9].u.nameHash = 0xC096573F;
|
||||||
|
|
||||||
|
pass.args[10].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[10].dest = 10;
|
||||||
|
pass.args[10].u.codeConst.index = CONST_SRC_CODE_EYEOFFSET;
|
||||||
|
pass.args[10].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[10].u.codeConst.rowCount = 1;
|
||||||
|
|
||||||
|
pass.args[11].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[11].dest = 21;
|
||||||
|
pass.args[11].u.codeConst.index = CONST_SRC_CODE_FOG;
|
||||||
|
pass.args[11].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[11].u.codeConst.rowCount = 1;
|
||||||
|
|
||||||
|
pass.args[12].type = MTL_ARG_CODE_VERTEX_CONST;
|
||||||
|
pass.args[12].dest = 22;
|
||||||
|
pass.args[12].u.codeConst.index = CONST_SRC_CODE_GAMETIME;
|
||||||
|
pass.args[12].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[12].u.codeConst.rowCount = 1;
|
||||||
|
|
||||||
|
pass.args[13].type = MTL_ARG_CODE_PIXEL_CONST;
|
||||||
|
pass.args[13].dest = 0;
|
||||||
|
pass.args[13].u.codeConst.index = CONST_SRC_CODE_FOG_COLOR_LINEAR;
|
||||||
|
pass.args[13].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[13].u.codeConst.rowCount = 1;
|
||||||
|
|
||||||
|
pass.args[14].type = MTL_ARG_CODE_PIXEL_CONST;
|
||||||
|
pass.args[14].dest = 3;
|
||||||
|
pass.args[14].u.codeConst.index = CONST_SRC_CODE_GAMETIME;
|
||||||
|
pass.args[14].u.codeConst.firstRow = 0;
|
||||||
|
pass.args[14].u.codeConst.rowCount = 1;
|
||||||
|
|
||||||
|
pass.args[15].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[15].dest = 9;
|
||||||
|
pass.args[15].u.nameHash = 0x64E3AE5;
|
||||||
|
|
||||||
|
pass.args[16].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[16].dest = 5;
|
||||||
|
pass.args[16].u.nameHash = 0x3D9994DC;
|
||||||
|
|
||||||
|
pass.args[17].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[17].dest = 22;
|
||||||
|
pass.args[17].u.nameHash = 0x3FC0F1DE;
|
||||||
|
|
||||||
|
pass.args[18].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[18].dest = 7;
|
||||||
|
pass.args[18].u.nameHash = 0x470F6C9A;
|
||||||
|
|
||||||
|
pass.args[19].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[19].dest = 8;
|
||||||
|
pass.args[19].u.nameHash = 0x470F6C9B;
|
||||||
|
|
||||||
|
pass.args[20].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[20].dest = 20;
|
||||||
|
pass.args[20].u.nameHash = 0x6373ABA0;
|
||||||
|
|
||||||
|
pass.args[21].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[21].dest = 11;
|
||||||
|
pass.args[21].u.nameHash = 0x6373ABA1;
|
||||||
|
|
||||||
|
pass.args[22].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[22].dest = 6;
|
||||||
|
pass.args[22].u.nameHash = 0x9D5408FF;
|
||||||
|
|
||||||
|
pass.args[23].type = MTL_ARG_MATERIAL_PIXEL_CONST;
|
||||||
|
pass.args[23].dest = 21;
|
||||||
|
pass.args[23].u.nameHash = 0xAA2E7C4F;
|
||||||
|
|
||||||
|
return technique;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialTechniqueSet* GivenTechset(Zone& zone, MemoryManager& memory)
|
||||||
|
{
|
||||||
|
auto* techset = memory.Alloc<MaterialTechniqueSet>();
|
||||||
|
techset->name = "example_techset";
|
||||||
|
techset->worldVertFormat = MTL_WORLDVERT_TEX_4_NRM_2;
|
||||||
|
|
||||||
|
techset->techniques[TECHNIQUE_DEPTH_PREPASS] = GivenDepthPrepassTechnique(memory);
|
||||||
|
techset->techniques[TECHNIQUE_LIT] = GivenLitTechnique(memory);
|
||||||
|
|
||||||
|
zone.m_pools.AddAsset(std::make_unique<XAssetInfo<MaterialTechniqueSet>>(ASSET_TYPE_TECHNIQUE_SET, techset->name, techset));
|
||||||
|
return techset;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST_CASE("TechsetDumperIW5", "[iw5][techset][dumper]")
|
||||||
|
{
|
||||||
|
Zone zone("MockZone", 0, GameId::IW5, GamePlatform::PC);
|
||||||
|
zone.Register();
|
||||||
|
|
||||||
|
MemoryManager memory;
|
||||||
|
MockSearchPath mockObjPath;
|
||||||
|
MockOutputPath mockOutput;
|
||||||
|
AssetDumpingContext context(zone, "", mockOutput, mockObjPath, std::nullopt);
|
||||||
|
|
||||||
|
GivenTechset(zone, memory);
|
||||||
|
|
||||||
|
techset::DumperIW5 dumper(true);
|
||||||
|
|
||||||
|
SECTION("Can dump techset")
|
||||||
|
{
|
||||||
|
std::string expected(R"TECHSET(
|
||||||
|
"depth prepass":
|
||||||
|
example_zprepass;
|
||||||
|
|
||||||
|
"lit":
|
||||||
|
example_lit;
|
||||||
|
)TECHSET");
|
||||||
|
|
||||||
|
dumper.Dump(context);
|
||||||
|
|
||||||
|
const auto* file = mockOutput.GetMockedFile("techsets/example_techset.techset");
|
||||||
|
REQUIRE(file);
|
||||||
|
REQUIRE(Trimmed(file->AsString()) == Trimmed(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can dump simple technique")
|
||||||
|
{
|
||||||
|
std::string expected(R"TECHNIQUE(
|
||||||
|
// TECHNIQUE FLAGS: 0x4
|
||||||
|
// TECHNIQUE FLAGS: 0x200
|
||||||
|
{
|
||||||
|
stateMap "passthrough"; // TODO
|
||||||
|
|
||||||
|
vertexShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
// Omitted due to matching accessors: worldMatrix = constant.worldMatrix;
|
||||||
|
// Omitted due to matching accessors: viewProjectionMatrix = constant.viewProjectionMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "simple.hlsl"
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
}
|
||||||
|
)TECHNIQUE");
|
||||||
|
dumper.Dump(context);
|
||||||
|
|
||||||
|
const auto* file = mockOutput.GetMockedFile("techniques/example_zprepass.tech");
|
||||||
|
REQUIRE(file);
|
||||||
|
REQUIRE(Trimmed(file->AsString()) == Trimmed(expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("Can dump advanced technique")
|
||||||
|
{
|
||||||
|
std::string expected(R"TECHNIQUE(
|
||||||
|
{
|
||||||
|
stateMap "passthrough"; // TODO
|
||||||
|
|
||||||
|
vertexShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
// Omitted due to matching accessors: worldMatrix = constant.worldMatrix;
|
||||||
|
// Omitted due to matching accessors: viewProjectionMatrix = constant.viewProjectionMatrix;
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanDisplacementSampler = material.oceanDisplacementMap;
|
||||||
|
// Omitted due to matching accessors: eyeOffset = constant.eyeOffset;
|
||||||
|
// Omitted due to matching accessors: fogConsts = constant.fogConsts;
|
||||||
|
// Omitted due to matching accessors: gameTime = constant.gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixelShader 3.0 "advanced.hlsl"
|
||||||
|
{
|
||||||
|
oceanEnvSampler = material.oceanEnvMap;
|
||||||
|
oceanDetailNormalSampler = material.oceanDetailNormalMap;
|
||||||
|
oceanHeightNormalSampler = material.oceanHeightNormalMap;
|
||||||
|
oceanFoamSampler = material.oceanFoamMap;
|
||||||
|
// Omitted due to matching accessors: fogColorLinear = constant.fogColorLinear;
|
||||||
|
// Omitted due to matching accessors: gameTime = constant.gameTime;
|
||||||
|
oceanUVAnimParmFoam = material.oceanUVAnimParmFoam;
|
||||||
|
envMapParms = material.envMapParms;
|
||||||
|
oceanFoamParms = material.oceanFoamParms;
|
||||||
|
oceanUVAnimParmOctave0 = material.oceanUVAnimParmOctave0;
|
||||||
|
oceanUVAnimParmOctave1 = material.oceanUVAnimParmOctave1;
|
||||||
|
oceanUVAnimParmDetail1 = material.oceanUVAnimParmDetail1;
|
||||||
|
oceanUVAnimParmDetail0 = material.oceanUVAnimParmDetail0;
|
||||||
|
oceanAmplitude = material.oceanAmplitude;
|
||||||
|
oceanMiscParms = material.oceanMiscParms;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex.position = code.position;
|
||||||
|
vertex.color[0] = code.color;
|
||||||
|
}
|
||||||
|
)TECHNIQUE");
|
||||||
|
dumper.Dump(context);
|
||||||
|
|
||||||
|
const auto* file = mockOutput.GetMockedFile("techniques/example_lit.tech");
|
||||||
|
REQUIRE(file);
|
||||||
|
REQUIRE(Trimmed(file->AsString()) == Trimmed(expected));
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
test/ObjWritingTests/Game/IW5/Techset/ps_advanced.hlsl.cso
Normal file
BIN
test/ObjWritingTests/Game/IW5/Techset/ps_advanced.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjWritingTests/Game/IW5/Techset/ps_simple.hlsl.cso
Normal file
BIN
test/ObjWritingTests/Game/IW5/Techset/ps_simple.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjWritingTests/Game/IW5/Techset/vs_advanced.hlsl.cso
Normal file
BIN
test/ObjWritingTests/Game/IW5/Techset/vs_advanced.hlsl.cso
Normal file
Binary file not shown.
BIN
test/ObjWritingTests/Game/IW5/Techset/vs_simple.hlsl.cso
Normal file
BIN
test/ObjWritingTests/Game/IW5/Techset/vs_simple.hlsl.cso
Normal file
Binary file not shown.
Reference in New Issue
Block a user