Skip to content

Terrain shader: avoid FXC loop-variable redefinition in fogAt - #196

Open
MyriadColors wants to merge 2 commits into
bssth:masterfrom
MyriadColors:fix/terrain-hlsl-fxc-scope
Open

MyriadColors wants to merge 2 commits into
bssth:masterfrom
MyriadColors:fix/terrain-hlsl-fxc-scope

Conversation

@MyriadColors

Copy link
Copy Markdown

The Issue

Commit 01f7cff added fogAt() to kTerrainHlsl with a for (int k = 0; ...) loop followed by float2 k = ... in the same function body. Under FXC (D3DCompile targeting vs_5_1/ps_5_1 on Windows' default DXBC backend), for-loop variables leak into the enclosing scope, causing terrain.hlsl to fail at runtime with error X3003: redefinition of 'k'.

What it changes

Rename float2 k to float2 v in fogAt() (matching Renderer.cpp's fogAt), clean up nested k shadowing in PSTerrain(), and add a Windows-only D3DCompile CTest (tests/shader_compile_test.cpp) covering all 10 embedded HLSL entry points so windows-x64 CI catches future FXC regressions.

How it was checked

  • [ x ] ctest --test-dir build\Release passes
  • [ x ] game results unchanged: an AI autoplay with a fixed seed gives the same per-turn checksums as before (or the change fixes what made them differ)
  • [ x ] original saves still load

Fair Warning

I've made this commit using Gemini Neon, I know this might be offputting, but this is a small bugfix Im sure this wont be a huge problem. But tell me if you need more assurances

autoplay_log.txt

Commit 01f7cff added fogAt() to kTerrainHlsl with a for (int k = 0; ...) loop followed by float2 k = ... in the same function body. Under FXC (D3DCompile targeting vs_5_1/ps_5_1 on Windows' default DXBC backend), for-loop variables leak into the enclosing scope, causing terrain.hlsl to fail at runtime with error X3003: redefinition of 'k'.

Rename float2 k to float2 v in fogAt() (matching Renderer.cpp's fogAt), clean up nested k shadowing in PSTerrain(), and add a Windows-only D3DCompile CTest (tests/shader_compile_test.cpp) covering all 10 embedded HLSL entry points so windows-x64 CI catches future FXC regressions.
Match <name>[] = R"hlsl( directly so comment mentions of shader constant names cannot mis-extract another literal, bail out immediately if any literal extraction fails, include <iterator> explicitly for std::size, and note that the entry table mirrors tools/shaders/gen_msl.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant