Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3d9] Clamp stage and type in [G,S]etTextureStageState #3272

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,13 +2304,8 @@ namespace dxvk {
if (unlikely(pValue == nullptr))
return D3DERR_INVALIDCALL;

*pValue = 0;

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

if (unlikely(dxvkType >= TextureStageStateCount))
return D3DERR_INVALIDCALL;
Stage = std::min(Stage, DWORD(caps::TextureStageCount - 1));
dxvkType = std::min(dxvkType, D3D9TextureStageStateTypes(DXVK_TSS_COUNT - 1));

*pValue = m_state.textureStages[Stage][dxvkType];

Expand Down Expand Up @@ -3876,13 +3871,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(caps::TextureStageCount - 1));
Type = std::min(Type, D3D9TextureStageStateTypes(DXVK_TSS_COUNT - 1));

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(caps::TextureStageCount - 1));
Type = std::min(Type, D3D9TextureStageStateTypes(DXVK_TSS_COUNT - 1));

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

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