[PR #834] [MERGED] shader_recompiler: Add buffer offset calculation when swizzle is enabled. #1799

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

📋 Pull Request Information

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

Base: mainHead: buffer-swizzle-enable


📝 Commits (1)

  • 7233f51 shader_recompiler: Add buffer offset calculation when swizzle is enabled.

📊 Changes

6 files changed (+41 additions, -3 deletions)

View changed files

📝 src/shader_recompiler/backend/spirv/emit_spirv_instructions.h (+2 -0)
📝 src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp (+8 -0)
📝 src/shader_recompiler/ir/ir_emitter.cpp (+4 -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 (+24 -3)

📄 Description

Adds the swizzled buffer addressing offset calculation as described in the GPU reference documentation:

index_msb = index / const_index_stride
index_lsb = index % const_index_stride
offset_msb = offset / const_element_size
offset_lsb = offset % const_element_size

buffer_offset = (index_msb * const_stride + offset_msb * const_element_size) * const_index_stride
              + index_lsb * const_element_size + offset_lsb

For the purposes of this code, rewritten into index and offset parts as:

buffer_offset = index_msb * const_stride * const_index_stride + index_lsb * const_element_size
              + offset_msb * const_element_size * const_index_stride + offset_lsb

To support this calculation, IR instructions have been added for modulo operations.

This is used by CUSA02799 (The Witch and the Hundred Knight: Revival Edition); without it a fragment shader fails to compile on boot due to the assert.


🔄 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/834 **Author:** [@squidbus](https://github.com/squidbus) **Created:** 9/7/2024 **Status:** ✅ Merged **Merged:** 9/12/2024 **Merged by:** [@raphaelthegreat](https://github.com/raphaelthegreat) **Base:** `main` ← **Head:** `buffer-swizzle-enable` --- ### 📝 Commits (1) - [`7233f51`](https://github.com/shadps4-emu/shadPS4/commit/7233f51eec8f67a4cb151a1aeb03028f788532d4) shader_recompiler: Add buffer offset calculation when swizzle is enabled. ### 📊 Changes **6 files changed** (+41 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/shader_recompiler/backend/spirv/emit_spirv_instructions.h` (+2 -0) 📝 `src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp` (+8 -0) 📝 `src/shader_recompiler/ir/ir_emitter.cpp` (+4 -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` (+24 -3) </details> ### 📄 Description Adds the swizzled buffer addressing offset calculation as described in the GPU reference documentation: ``` index_msb = index / const_index_stride index_lsb = index % const_index_stride offset_msb = offset / const_element_size offset_lsb = offset % const_element_size buffer_offset = (index_msb * const_stride + offset_msb * const_element_size) * const_index_stride + index_lsb * const_element_size + offset_lsb ``` For the purposes of this code, rewritten into index and offset parts as: ``` buffer_offset = index_msb * const_stride * const_index_stride + index_lsb * const_element_size + offset_msb * const_element_size * const_index_stride + offset_lsb ``` To support this calculation, IR instructions have been added for modulo operations. This is used by CUSA02799 (The Witch and the Hundred Knight: Revival Edition); without it a fragment shader fails to compile on boot due to the assert. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:13:59 +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#1799
No description provided.