[PR #1762] [MERGED] shader_recompiler: Emulate unnormalized sampler coordinates in shader. #2285

Closed
opened 2026-02-27 21:15:53 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/1762
Author: @squidbus
Created: 12/13/2024
Status: Merged
Merged: 12/13/2024
Merged by: @raphaelthegreat

Base: mainHead: unnorm


📝 Commits (2)

  • cb7c049 shader_recompiler: Emulate unnormalized sampler coordinates in shader.
  • d303a4d Address review comments.

📊 Changes

10 files changed (+78 additions, -12 deletions)

View changed files

📝 src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp (+8 -0)
📝 src/shader_recompiler/backend/spirv/emit_spirv_instructions.h (+2 -0)
📝 src/shader_recompiler/frontend/translate/vector_memory.cpp (+1 -0)
📝 src/shader_recompiler/ir/ir_emitter.cpp (+14 -0)
📝 src/shader_recompiler/ir/ir_emitter.h (+1 -0)
📝 src/shader_recompiler/ir/opcodes.inc (+2 -0)
📝 src/shader_recompiler/ir/passes/resource_tracking_pass.cpp (+31 -10)
📝 src/shader_recompiler/ir/reg.h (+2 -1)
📝 src/shader_recompiler/specialization.h (+16 -0)
📝 src/video_core/texture_cache/sampler.cpp (+1 -1)

📄 Description

Vulkan imposes a number of restrictions on samplers with unnormalizedCoordinates = true. In most cases seeing force_unnormalized used by games, these restrictions seem to be violated, using address modes, compare ops, LOD levels, and sampling instructions that are not allowed.

Instead, emulate unnormalized coordinates in shaders by querying the dimensions and dividing the unnormalized coordinates to turn them into normalized coordinates. This also allows us to implement the unnormalized per-instruction flag.

Used by some shaders in CUSA16404 and CUSA05637.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/1762 **Author:** [@squidbus](https://github.com/squidbus) **Created:** 12/13/2024 **Status:** ✅ Merged **Merged:** 12/13/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `unnorm` --- ### 📝 Commits (2) - [`cb7c049`](https://github.com/shadps4-emu/shadPS4/commit/cb7c049e265d1b688e43516371a412cc57eab069) shader_recompiler: Emulate unnormalized sampler coordinates in shader. - [`d303a4d`](https://github.com/shadps4-emu/shadPS4/commit/d303a4d5ca5b8a049c5f749fd72ef9e61accc476) Address review comments. ### 📊 Changes **10 files changed** (+78 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/backend/spirv/emit_spirv_floating_point.cpp` (+8 -0) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_instructions.h` (+2 -0) 📝 `src/shader_recompiler/frontend/translate/vector_memory.cpp` (+1 -0) 📝 `src/shader_recompiler/ir/ir_emitter.cpp` (+14 -0) 📝 `src/shader_recompiler/ir/ir_emitter.h` (+1 -0) 📝 `src/shader_recompiler/ir/opcodes.inc` (+2 -0) 📝 `src/shader_recompiler/ir/passes/resource_tracking_pass.cpp` (+31 -10) 📝 `src/shader_recompiler/ir/reg.h` (+2 -1) 📝 `src/shader_recompiler/specialization.h` (+16 -0) 📝 `src/video_core/texture_cache/sampler.cpp` (+1 -1) </details> ### 📄 Description Vulkan [imposes a number of restrictions](https://registry.khronos.org/vulkan/specs/latest/man/html/VkSamplerCreateInfo.html) on samplers with `unnormalizedCoordinates = true`. In most cases seeing `force_unnormalized` used by games, these restrictions seem to be violated, using address modes, compare ops, LOD levels, and sampling instructions that are not allowed. Instead, emulate unnormalized coordinates in shaders by querying the dimensions and dividing the unnormalized coordinates to turn them into normalized coordinates. This also allows us to implement the unnormalized per-instruction flag. Used by some shaders in CUSA16404 and CUSA05637. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:15:53 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#2285
No description provided.