Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(ww3d2): write the fixed-function texture stages out as HLSL

Olcay Seygan12d3dd9217ce
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txt
index 504447b14..2d029485c 100644
--- a/GeneralsMD/Code/CMakeLists.txt
+++ b/GeneralsMD/Code/CMakeLists.txt
@@ -196,6 +196,15 @@ set_target_properties(d3dx9runtime PROPERTIES CXX_STANDARD 17)
target_include_directories(d3dx9runtime PUBLIC ${WW}/WW3D2)
target_link_libraries(d3dx9runtime PUBLIC d3d9)
+# ---- ffshader -------------------------------------------------------------
+# The fixed-function texture stages written out as HLSL, phase 2's replacement for
+# combiners D3D11 does not have. Its own library because it is string building over
+# a description and nothing else: the test links this alone rather than all of WW3D2.
+add_library(ffshader STATIC ${WW}/WW3D2/ffshader.cpp)
+set_target_properties(ffshader PROPERTIES CXX_STANDARD 17)
+target_include_directories(ffshader PUBLIC ${WW}/WW3D2)
+target_link_libraries(ffshader PUBLIC d3d9)
+
# ---- ww3d2 (renderer core) ------------------------------------------------
# wwshade is header-only here on purpose: no .dsp links wwshade.lib and its
# shd*bump* sources need shdpp/NVASM-generated headers. Revisit at exe link.
@@ -604,6 +613,8 @@ add_lib_test(test_ww3d2 ww3d2 wwsaveload wwlib wwmath wwdebug)
target_include_directories(test_ww3d2 PRIVATE
${WW}/WW3D2 ${WW}/WWLib ${WW}/WWMath ${WW}/WWDebug ${WW}/WWSaveLoad ${WW}/Wwutil)
+add_lib_test(test_ffshader ffshader)
+
add_lib_test(test_wwdownload wwdownload)
target_include_directories(test_wwdownload PRIVATE ${WW}/WWDownload)
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
new file mode 100644
index 000000000..ea8853b10
--- /dev/null
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
@@ -0,0 +1,205 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ffshader.h"
+
+#include <stdio.h>
+
+// The texture factor and the sampler registers the generated shader expects the caller to have
+// filled. They are the constant register D3DRS_TEXTUREFACTOR is copied into and the stage samplers
+// the device already has bound, so nothing about how a draw is set up has to change.
+static const char * const TEXTURE_FACTOR_REGISTER = "c0";
+
+// D3DTA_SELECTMASK is the argument itself; the two flags above it are modifiers the device applies
+// to whatever the argument turned out to be.
+static const DWORD ARGUMENT_SELECT_MASK = D3DTA_SELECTMASK;
+
+// "current" is initialised to the diffuse colour, which is what the device gives D3DTA_CURRENT at
+// stage 0, so the two need no distinguishing here.
+static bool argument_expression(DWORD argument, std::string & expression)
+{
+ switch (argument & ARGUMENT_SELECT_MASK) {
+ case D3DTA_DIFFUSE: expression = "input.Diffuse"; break;
+ case D3DTA_CURRENT: expression = "current"; break;
+ case D3DTA_TEXTURE: expression = "texel"; break;
+ case D3DTA_TFACTOR: expression = "TextureFactor"; break;
+ case D3DTA_SPECULAR: expression = "input.Specular"; break;
+ default:
+ return false;
+ }
+
+ // Replicate first, complement second: that is the order the reference rasteriser applies them,
+ // so 1 - a.a and not (1 - a).a for an argument carrying both.
+ if ((argument & D3DTA_ALPHAREPLICATE) != 0) {
+ expression = "(" + expression + ").aaaa";
+ }
+ if ((argument & D3DTA_COMPLEMENT) != 0) {
+ expression = "(1.0 - " + expression + ")";
+ }
+ return true;
+}
+
+static bool operation_expression(DWORD operation, const std::string & argument0,
+ const std::string & argument1, const std::string & argument2, std::string & expression)
+{
+ switch (operation) {
+ case D3DTOP_SELECTARG1:
+ expression = argument1;
+ return true;
+ case D3DTOP_SELECTARG2:
+ expression = argument2;
+ return true;
+ case D3DTOP_MODULATE:
+ expression = "(" + argument1 + " * " + argument2 + ")";
+ return true;
+ case D3DTOP_MODULATE2X:
+ expression = "(" + argument1 + " * " + argument2 + " * 2.0)";
+ return true;
+ case D3DTOP_MODULATE4X:
+ expression = "(" + argument1 + " * " + argument2 + " * 4.0)";
+ return true;
+ case D3DTOP_ADD:
+ expression = "(" + argument1 + " + " + argument2 + ")";
+ return true;
+ case D3DTOP_ADDSIGNED:
+ expression = "(" + argument1 + " + " + argument2 + " - 0.5)";
+ return true;
+ case D3DTOP_SUBTRACT:
+ expression = "(" + argument1 + " - " + argument2 + ")";
+ return true;
+ case D3DTOP_MULTIPLYADD:
+ expression = "(" + argument0 + " + " + argument1 + " * " + argument2 + ")";
+ return true;
+ case D3DTOP_LERP:
+ expression = "lerp(" + argument2 + ", " + argument1 + ", " + argument0 + ")";
+ return true;
+ case D3DTOP_DOTPRODUCT3:
+ // The device works on signed values here and saturates the result into all four channels.
+ expression = "saturate(dot((" + argument1 + ").rgb * 2.0 - 1.0, ("
+ + argument2 + ").rgb * 2.0 - 1.0)).xxxx";
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool CombinerShader_Generate(const CombinerDescription & description, std::string & hlsl)
+{
+ if (description.StageCount == 0 || description.StageCount > MAXIMUM_COMBINER_STAGES) {
+ return false;
+ }
+
+ std::string body;
+ for (unsigned stage = 0; stage < description.StageCount; ++stage) {
+ const CombinerStage & source = description.Stages[stage];
+
+ char line[256];
+ if (source.TextureBound) {
+ // D3DTSS_TEXCOORDINDEX carries the generation mode in its high bits and the coordinate
+ // set in its low ones. Only the set is read here: every generation mode the game uses
+ // is a transform the vertex stage has already applied by the time a coordinate arrives.
+ const unsigned coordinate_set = source.TextureCoordinateIndex & 0xffff;
+ snprintf(line, sizeof(line), " texel = tex2D(Sampler%u, input.TexCoord%u);\n",
+ stage, coordinate_set);
+ }
+ else {
+ // What a stage with no texture bound gives D3DTA_TEXTURE is not something this can
+ // assert: the documentation does not say and reports of what hardware does disagree.
+ // Opaque white is the choice that makes MODULATE a no-op, which is what the call sites
+ // that leave a stage untextured appear to want, and one measured combination reads
+ // D3DTA_TEXTURE with nothing bound - SELECTARG1 on an untextured stage - so the two
+ // answers are distinguishable on screen. tree-check.ps1 settles it, not this comment.
+ snprintf(line, sizeof(line), " texel = float4(1.0, 1.0, 1.0, 1.0);\n");
+ }
+ body += line;
+
+ std::string colour_argument0, colour_argument1, colour_argument2;
+ std::string alpha_argument0, alpha_argument1, alpha_argument2;
+ if (!argument_expression(source.ColourArgument0, colour_argument0)
+ || !argument_expression(source.ColourArgument1, colour_argument1)
+ || !argument_expression(source.ColourArgument2, colour_argument2)
+ || !argument_expression(source.AlphaArgument0, alpha_argument0)
+ || !argument_expression(source.AlphaArgument1, alpha_argument1)
+ || !argument_expression(source.AlphaArgument2, alpha_argument2)) {
+ return false;
+ }
+
+ std::string colour_expression;
+ std::string alpha_expression;
+ if (!operation_expression(source.ColourOperation, colour_argument0, colour_argument1,
+ colour_argument2, colour_expression)
+ || !operation_expression(source.AlphaOperation, alpha_argument0, alpha_argument1,
+ alpha_argument2, alpha_expression)) {
+ return false;
+ }
+
+ body += " current.rgb = " + colour_expression + ".rgb;\n";
+ body += " current.a = " + alpha_expression + ".a;\n";
+ }
+
+ hlsl =
+ "// Generated from a fixed-function texture stage description. See ffshader.h.\n"
+ "sampler2D Sampler0 : register(s0);\n"
+ "sampler2D Sampler1 : register(s1);\n"
+ "float4 TextureFactor : register(";
+ hlsl += TEXTURE_FACTOR_REGISTER;
+ hlsl +=
+ ");\n"
+ "\n"
+ "struct Input\n"
+ "{\n"
+ " float4 Diffuse : COLOR0;\n"
+ " float4 Specular : COLOR1;\n"
+ " float2 TexCoord0 : TEXCOORD0;\n"
+ " float2 TexCoord1 : TEXCOORD1;\n"
+ "};\n"
+ "\n"
+ "float4 main(Input input) : COLOR\n"
+ "{\n"
+ " float4 texel;\n"
+ " float4 current = input.Diffuse;\n";
+ hlsl += body;
+ hlsl +=
+ " return current;\n"
+ "}\n";
+ return true;
+}
+
+std::string CombinerShader_Key(const CombinerDescription & description)
+{
+ std::string key;
+ char field[32];
+ snprintf(field, sizeof(field), "%u", description.StageCount);
+ key += field;
+
+ for (unsigned stage = 0; stage < description.StageCount; ++stage) {
+ const CombinerStage & source = description.Stages[stage];
+ snprintf(field, sizeof(field), ":%lu,%lu,%lu,%lu",
+ source.ColourOperation, source.ColourArgument0,
+ source.ColourArgument1, source.ColourArgument2);
+ key += field;
+ snprintf(field, sizeof(field), ",%lu,%lu,%lu,%lu",
+ source.AlphaOperation, source.AlphaArgument0,
+ source.AlphaArgument1, source.AlphaArgument2);
+ key += field;
+ snprintf(field, sizeof(field), ",%lu,%u",
+ source.TextureCoordinateIndex & 0xffff, source.TextureBound ? 1u : 0u);
+ key += field;
+ }
+ return key;
+}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h
new file mode 100644
index 000000000..6859f3fd8
--- /dev/null
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h
@@ -0,0 +1,78 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+** The fixed-function texture stages, written out as HLSL.
+**
+** D3D11 has no texture stage combiners, so RENDERER-ROADMAP.md's phase 2 has to say in a shader
+** what the stages were computing. -ffprobe counted what the game actually asks for across four
+** maps: 28 distinct combiner programs, never more than two stages, and a vocabulary of five
+** operations over four arguments. This turns one of those descriptions into the shader.
+**
+** It generates for D3D9 first, on purpose. A pixel shader on the existing device can be compared
+** against the fixed-function pipeline it replaces with tree-check.ps1, which turns the phase from
+** one untestable port into a generator that is proved against the real game before any of it is
+** carried to a second backend. Fog and the alpha test are not generated for that reason: D3D9
+** still applies both around a pixel shader, so leaving them alone keeps the comparison to the one
+** thing being replaced. D3D11 has neither and will want them here.
+*/
+
+#ifndef FFSHADER_H
+#define FFSHADER_H
+
+#include <d3d9.h>
+
+#include <string>
+
+// Two is what the game uses. The generator refuses a description with more rather than emitting a
+// shader nobody has compared against anything.
+const unsigned MAXIMUM_COMBINER_STAGES = 2;
+
+// One texture stage, in the terms D3D8 set it in. Arguments carry D3DTA_COMPLEMENT and
+// D3DTA_ALPHAREPLICATE the way the device does; the generator applies both.
+struct CombinerStage
+{
+ DWORD ColourOperation;
+ DWORD ColourArgument0;
+ DWORD ColourArgument1;
+ DWORD ColourArgument2;
+ DWORD AlphaOperation;
+ DWORD AlphaArgument0;
+ DWORD AlphaArgument1;
+ DWORD AlphaArgument2;
+ DWORD TextureCoordinateIndex;
+ bool TextureBound;
+};
+
+// What a draw asks the combiners to compute. Stages past StageCount are not read.
+struct CombinerDescription
+{
+ CombinerStage Stages[MAXIMUM_COMBINER_STAGES];
+ unsigned StageCount;
+};
+
+// The HLSL for one description, or false when the description names an operation or an argument
+// this does not generate. A refusal is not a failure: the caller keeps the fixed-function path for
+// that draw, which is the only reason an unmeasured operation is safe to meet at run time.
+bool CombinerShader_Generate(const CombinerDescription & description, std::string & hlsl);
+
+// The description two draws share iff they can share a compiled shader. Stages past StageCount are
+// zeroed, so two descriptions that differ only in a stage nobody reads compare equal.
+std::string CombinerShader_Key(const CombinerDescription & description);
+
+#endif
diff --git a/GeneralsMD/Code/Tests/test_ffshader.cpp b/GeneralsMD/Code/Tests/test_ffshader.cpp
new file mode 100644
index 000000000..f66a7e087
--- /dev/null
+++ b/GeneralsMD/Code/Tests/test_ffshader.cpp
@@ -0,0 +1,252 @@
+/*
+** Command & Conquer Generals Zero Hour(tm)
+** Copyright 2025 Electronic Arts Inc.
+**
+** This program is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation, either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// The combiner-to-HLSL generator. The descriptions here are the ones -ffprobe measured over Flash
+// Effect, Golden Oasis, ForgottenForestZH and Alpine Assault, not invented ones: a generator that
+// handles a case the game never asks for is worth nothing, and one that refuses a case it does ask
+// for silently keeps that draw on the fixed-function path.
+
+#include "test_harness.h"
+
+#include "ffshader.h"
+
+#include <string.h>
+
+static CombinerStage one_stage(DWORD colour_operation, DWORD colour_argument1,
+ DWORD colour_argument2, DWORD alpha_operation, DWORD alpha_argument1, DWORD alpha_argument2,
+ DWORD coordinate_index, bool texture_bound)
+{
+ CombinerStage stage;
+ memset(&stage, 0, sizeof(stage));
+ stage.ColourOperation = colour_operation;
+ stage.ColourArgument1 = colour_argument1;
+ stage.ColourArgument2 = colour_argument2;
+ stage.AlphaOperation = alpha_operation;
+ stage.AlphaArgument1 = alpha_argument1;
+ stage.AlphaArgument2 = alpha_argument2;
+ stage.TextureCoordinateIndex = coordinate_index;
+ stage.TextureBound = texture_bound;
+ return stage;
+}
+
+static bool contains(const std::string & text, const char * fragment)
+{
+ return text.find(fragment) != std::string::npos;
+}
+
+// 22.8% of every draw call measured: one stage, SELECTARG1 on the texture, coordinate set 2.
+TEST(ffshader_the_most_used_combination_selects_the_texture)
+{
+ CombinerDescription description;
+ description.StageCount = 1;
+ description.Stages[0] = one_stage(D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT, 131072 | 2, true);
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "texel = tex2D(Sampler0, input.TexCoord2)"));
+ CHECK(contains(hlsl, "current.rgb = texel.rgb"));
+ CHECK(contains(hlsl, "current.a = texel.a"));
+}
+
+// The second most used: MODULATE of the texture against the diffuse colour.
+TEST(ffshader_modulate_multiplies_texture_by_diffuse)
+{
+ CombinerDescription description;
+ description.StageCount = 1;
+ description.Stages[0] = one_stage(D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE,
+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 0, true);
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "(texel * input.Diffuse).rgb"));
+ CHECK(contains(hlsl, "(texel * input.Diffuse).a"));
+}
+
+// A stage with nothing bound still reads D3DTA_TEXTURE, and the generator has to put something
+// there. Opaque white is the answer being tried; this pins it so a change to it is deliberate.
+TEST(ffshader_an_unbound_stage_samples_opaque_white)
+{
+ CombinerDescription description;
+ description.StageCount = 1;
+ description.Stages[0] = one_stage(D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT, 0, false);
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "texel = float4(1.0, 1.0, 1.0, 1.0)"));
+ CHECK(!contains(hlsl, "tex2D"));
+}
+
+// The two-stage shroud pass: MULTIPLYADD against an alpha-replicated texture factor, then
+// DOTPRODUCT3. This is the only measured combination that uses either operation.
+TEST(ffshader_two_stages_with_multiplyadd_and_dotproduct)
+{
+ CombinerDescription description;
+ description.StageCount = 2;
+ description.Stages[0] = one_stage(D3DTOP_MULTIPLYADD, D3DTA_TEXTURE, D3DTA_TFACTOR | D3DTA_ALPHAREPLICATE,
+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 0, true);
+ description.Stages[0].ColourArgument0 = D3DTA_DIFFUSE;
+ description.Stages[1] = one_stage(D3DTOP_DOTPRODUCT3, D3DTA_CURRENT, D3DTA_TFACTOR,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT, 1, false);
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "(input.Diffuse + texel * (TextureFactor).aaaa)"));
+ CHECK(contains(hlsl, "saturate(dot("));
+}
+
+// A complemented argument is 1 - a, and an alpha-replicated one is a.aaaa. Both together replicate
+// first, which is the order the device applies them in.
+TEST(ffshader_argument_modifiers_replicate_before_complementing)
+{
+ CombinerDescription description;
+ description.StageCount = 1;
+ description.Stages[0] = one_stage(D3DTOP_SELECTARG1,
+ D3DTA_TEXTURE | D3DTA_ALPHAREPLICATE | D3DTA_COMPLEMENT, D3DTA_CURRENT,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT, D3DTA_CURRENT, 0, true);
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "(1.0 - (texel).aaaa).rgb"));
+ CHECK(contains(hlsl, "(1.0 - texel).a"));
+}
+
+// An operation the generator does not write has to be refused, not guessed at: the caller keeps
+// that draw on the fixed-function path, which is the only reason meeting one is safe.
+TEST(ffshader_refuses_an_operation_it_does_not_generate)
+{
+ CombinerDescription description;
+ description.StageCount = 1;
+ description.Stages[0] = one_stage(D3DTOP_BUMPENVMAP, D3DTA_TEXTURE, D3DTA_CURRENT,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT, 0, true);
+
+ std::string hlsl;
+ CHECK(!CombinerShader_Generate(description, hlsl));
+}
+
+TEST(ffshader_refuses_more_stages_than_the_game_uses)
+{
+ CombinerDescription description;
+ description.StageCount = MAXIMUM_COMBINER_STAGES + 1;
+ description.Stages[0] = one_stage(D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT,
+ D3DTOP_SELECTARG1, D3DTA_TEXTURE, D3DTA_CURRENT, 0, true);
+
+ std::string hlsl;
+ CHECK(!CombinerShader_Generate(description, hlsl));
+}
+
+// Two descriptions that differ only in a stage past StageCount are one shader, or the cache holds
+// a copy of the same program for every scrap of stale state a call site happened to leave behind.
+TEST(ffshader_the_key_ignores_stages_nobody_reads)
+{
+ CombinerDescription first;
+ first.StageCount = 1;
+ first.Stages[0] = one_stage(D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE,
+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 0, true);
+ first.Stages[1] = one_stage(D3DTOP_ADD, D3DTA_TFACTOR, D3DTA_CURRENT,
+ D3DTOP_ADD, D3DTA_TFACTOR, D3DTA_CURRENT, 1, true);
+
+ CombinerDescription second = first;
+ second.Stages[1] = one_stage(D3DTOP_SUBTRACT, D3DTA_DIFFUSE, D3DTA_CURRENT,
+ D3DTOP_SUBTRACT, D3DTA_DIFFUSE, D3DTA_CURRENT, 0, false);
+
+ CHECK_STR(CombinerShader_Key(first).c_str(), CombinerShader_Key(second).c_str());
+}
+
+// The coordinate generation mode rides in the high bits of D3DTSS_TEXCOORDINDEX and the coordinate
+// set in the low ones. Keying on the whole word would compile the same program twice.
+TEST(ffshader_the_key_reads_the_coordinate_set_not_the_generation_mode)
+{
+ CombinerDescription plain;
+ plain.StageCount = 1;
+ plain.Stages[0] = one_stage(D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE,
+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 1, true);
+
+ CombinerDescription generated = plain;
+ generated.Stages[0].TextureCoordinateIndex = 131072 | 1;
+
+ CHECK_STR(CombinerShader_Key(plain).c_str(), CombinerShader_Key(generated).c_str());
+}
+
+// Every distinct program -ffprobe found has to come out of the generator, or the fixed-function
+// path stays alive for the ones it refuses and D3D11 has nothing to run them on.
+TEST(ffshader_generates_every_measured_combination)
+{
+ struct MeasuredCombination
+ {
+ unsigned StageCount;
+ DWORD ColourOperation[MAXIMUM_COMBINER_STAGES];
+ DWORD ColourArgument1[MAXIMUM_COMBINER_STAGES];
+ DWORD ColourArgument2[MAXIMUM_COMBINER_STAGES];
+ DWORD AlphaOperation[MAXIMUM_COMBINER_STAGES];
+ DWORD AlphaArgument1[MAXIMUM_COMBINER_STAGES];
+ DWORD AlphaArgument2[MAXIMUM_COMBINER_STAGES];
+ };
+
+ // Taken from Run/ffprobe.txt over the four maps, deduplicated on the fields below.
+ static const MeasuredCombination MEASURED[] =
+ {
+ { 1, {D3DTOP_SELECTARG1}, {D3DTA_TEXTURE}, {D3DTA_CURRENT},
+ {D3DTOP_SELECTARG1}, {D3DTA_TEXTURE}, {D3DTA_CURRENT} },
+ { 1, {D3DTOP_MODULATE}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE},
+ {D3DTOP_MODULATE}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE} },
+ { 1, {D3DTOP_SELECTARG2}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE},
+ {D3DTOP_SELECTARG2}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE} },
+ { 1, {D3DTOP_MODULATE}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE},
+ {D3DTOP_SELECTARG1}, {D3DTA_TEXTURE}, {D3DTA_DIFFUSE} },
+ { 1, {D3DTOP_SELECTARG1}, {D3DTA_SPECULAR}, {D3DTA_DIFFUSE},
+ {D3DTOP_MODULATE}, {D3DTA_TEXTURE}, {D3DTA_SPECULAR} },
+ { 2, {D3DTOP_MULTIPLYADD, D3DTOP_DOTPRODUCT3},
+ {D3DTA_TEXTURE, D3DTA_CURRENT},
+ {D3DTA_TFACTOR | D3DTA_ALPHAREPLICATE, D3DTA_TFACTOR},
+ {D3DTOP_MODULATE, D3DTOP_SELECTARG1},
+ {D3DTA_TEXTURE, D3DTA_TEXTURE},
+ {D3DTA_DIFFUSE, D3DTA_CURRENT} },
+ { 2, {D3DTOP_MODULATE, D3DTOP_MODULATE},
+ {D3DTA_TEXTURE, D3DTA_TEXTURE},
+ {D3DTA_DIFFUSE, D3DTA_CURRENT},
+ {D3DTOP_MODULATE, D3DTOP_MODULATE},
+ {D3DTA_TEXTURE, D3DTA_TEXTURE},
+ {D3DTA_DIFFUSE, D3DTA_CURRENT} },
+ { 2, {D3DTOP_MODULATE, D3DTOP_MODULATE},
+ {D3DTA_TEXTURE, D3DTA_TEXTURE},
+ {D3DTA_DIFFUSE, D3DTA_CURRENT},
+ {D3DTOP_MODULATE, D3DTOP_SELECTARG2},
+ {D3DTA_TEXTURE, D3DTA_TEXTURE},
+ {D3DTA_DIFFUSE, D3DTA_CURRENT} }
+ };
+
+ const size_t measured_count = sizeof(MEASURED)/sizeof(MEASURED[0]);
+ for (size_t index = 0; index < measured_count; ++index) {
+ const MeasuredCombination & measured = MEASURED[index];
+ CombinerDescription description;
+ description.StageCount = measured.StageCount;
+ for (unsigned stage = 0; stage < measured.StageCount; ++stage) {
+ description.Stages[stage] = one_stage(measured.ColourOperation[stage],
+ measured.ColourArgument1[stage], measured.ColourArgument2[stage],
+ measured.AlphaOperation[stage], measured.AlphaArgument1[stage],
+ measured.AlphaArgument2[stage], stage, true);
+ }
+
+ std::string hlsl;
+ CHECK(CombinerShader_Generate(description, hlsl));
+ CHECK(contains(hlsl, "float4 main(Input input) : COLOR"));
+ CHECK(contains(hlsl, "return current;"));
+ }
+}