Skip to content

Commit

Permalink
[d3d9] Clamp stage and type in [G,S]etTextureStageState
Browse files Browse the repository at this point in the history
This is what happens on the Nvidia D3D9 driver.
Dawn of Magic 2 calls SetTextureStageState with a
stage > 7 and expects that to succeed.
  • Loading branch information
K0bin committed Mar 2, 2023
1 parent 5609c5e commit cac9d86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3876,13 +3876,13 @@ namespace dxvk {
DWORD Stage,
D3D9TextureStageStateTypes Type,
DWORD Value) {
D3D9DeviceLock lock = LockDevice();

if (unlikely(Stage >= caps::TextureStageCount))
return D3DERR_INVALIDCALL;

// Clamp values instead of checking and returning INVALID_CALL
// Matches tests + Dawn of Magic 2 relies on it.
Stage = std::min(Stage, DWORD(7));
Type = std::min(Type, DXVK_TSS_CONSTANT);

if (unlikely(Type >= TextureStageStateCount))
return D3DERR_INVALIDCALL;
D3D9DeviceLock lock = LockDevice();

if (unlikely(ShouldRecord()))
return m_recorder->SetStateTextureStageState(Stage, Type, Value);
Expand Down
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_stateblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ namespace dxvk {
DWORD Stage,
D3D9TextureStageStateTypes Type,
DWORD Value) {
Stage = std::min(Stage, DWORD(7));
Type = std::min(Type, DXVK_TSS_CONSTANT);

m_state.textureStages[Stage][Type] = Value;

m_captures.flags.set(D3D9CapturedStateFlag::TextureStages);
Expand Down

0 comments on commit cac9d86

Please sign in to comment.